aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/can/sja1000
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/net/can/sja1000')
-rw-r--r--drivers/net/can/sja1000/Kconfig12
-rw-r--r--drivers/net/can/sja1000/Makefile1
-rw-r--r--drivers/net/can/sja1000/ems_pci.c3
-rw-r--r--drivers/net/can/sja1000/kvaser_pci.c2
-rw-r--r--drivers/net/can/sja1000/plx_pci.c473
-rw-r--r--drivers/net/can/sja1000/sja1000.c64
-rw-r--r--drivers/net/can/sja1000/sja1000.h2
7 files changed, 529 insertions, 28 deletions
diff --git a/drivers/net/can/sja1000/Kconfig b/drivers/net/can/sja1000/Kconfig
index 4c674927f247..9e277d64a318 100644
--- a/drivers/net/can/sja1000/Kconfig
+++ b/drivers/net/can/sja1000/Kconfig
@@ -44,4 +44,16 @@ config CAN_KVASER_PCI
44 This driver is for the the PCIcanx and PCIcan cards (1, 2 or 44 This driver is for the the PCIcanx and PCIcan cards (1, 2 or
45 4 channel) from Kvaser (http://www.kvaser.com). 45 4 channel) from Kvaser (http://www.kvaser.com).
46 46
47config CAN_PLX_PCI
48 tristate "PLX90xx PCI-bridge based Cards"
49 depends on PCI
50 ---help---
51 This driver is for CAN interface cards based on
52 the PLX90xx PCI bridge.
53 Driver supports now:
54 - Adlink PCI-7841/cPCI-7841 card (http://www.adlinktech.com/)
55 - Adlink PCI-7841/cPCI-7841 SE card
56 - Marathon CAN-bus-PCI card (http://www.marathon.ru/)
57 - TEWS TECHNOLOGIES TPMC810 card (http://www.tews.com/)
58
47endif 59endif
diff --git a/drivers/net/can/sja1000/Makefile b/drivers/net/can/sja1000/Makefile
index 9d245ac03965..ce924553995d 100644
--- a/drivers/net/can/sja1000/Makefile
+++ b/drivers/net/can/sja1000/Makefile
@@ -8,5 +8,6 @@ obj-$(CONFIG_CAN_SJA1000_PLATFORM) += sja1000_platform.o
8obj-$(CONFIG_CAN_SJA1000_OF_PLATFORM) += sja1000_of_platform.o 8obj-$(CONFIG_CAN_SJA1000_OF_PLATFORM) += sja1000_of_platform.o
9obj-$(CONFIG_CAN_EMS_PCI) += ems_pci.o 9obj-$(CONFIG_CAN_EMS_PCI) += ems_pci.o
10obj-$(CONFIG_CAN_KVASER_PCI) += kvaser_pci.o 10obj-$(CONFIG_CAN_KVASER_PCI) += kvaser_pci.o
11obj-$(CONFIG_CAN_PLX_PCI) += plx_pci.o
11 12
12ccflags-$(CONFIG_CAN_DEBUG_DEVICES) := -DDEBUG 13ccflags-$(CONFIG_CAN_DEBUG_DEVICES) := -DDEBUG
diff --git a/drivers/net/can/sja1000/ems_pci.c b/drivers/net/can/sja1000/ems_pci.c
index fd04789d3370..5f53da0bc40c 100644
--- a/drivers/net/can/sja1000/ems_pci.c
+++ b/drivers/net/can/sja1000/ems_pci.c
@@ -22,6 +22,7 @@
22#include <linux/interrupt.h> 22#include <linux/interrupt.h>
23#include <linux/netdevice.h> 23#include <linux/netdevice.h>
24#include <linux/delay.h> 24#include <linux/delay.h>
25#include <linux/slab.h>
25#include <linux/pci.h> 26#include <linux/pci.h>
26#include <linux/can.h> 27#include <linux/can.h>
27#include <linux/can/dev.h> 28#include <linux/can/dev.h>
@@ -102,7 +103,7 @@ struct ems_pci_card {
102 103
103#define EMS_PCI_BASE_SIZE 4096 /* size of controller area */ 104#define EMS_PCI_BASE_SIZE 4096 /* size of controller area */
104 105
105static struct pci_device_id ems_pci_tbl[] = { 106static DEFINE_PCI_DEVICE_TABLE(ems_pci_tbl) = {
106 /* CPC-PCI v1 */ 107 /* CPC-PCI v1 */
107 {PCI_VENDOR_ID_SIEMENS, 0x2104, PCI_ANY_ID, PCI_ANY_ID,}, 108 {PCI_VENDOR_ID_SIEMENS, 0x2104, PCI_ANY_ID, PCI_ANY_ID,},
108 /* CPC-PCI v2 */ 109 /* CPC-PCI v2 */
diff --git a/drivers/net/can/sja1000/kvaser_pci.c b/drivers/net/can/sja1000/kvaser_pci.c
index 7dd7769b9713..441e776a7f59 100644
--- a/drivers/net/can/sja1000/kvaser_pci.c
+++ b/drivers/net/can/sja1000/kvaser_pci.c
@@ -109,7 +109,7 @@ struct kvaser_pci {
109#define KVASER_PCI_VENDOR_ID2 0x1a07 /* the PCI device and vendor IDs */ 109#define KVASER_PCI_VENDOR_ID2 0x1a07 /* the PCI device and vendor IDs */
110#define KVASER_PCI_DEVICE_ID2 0x0008 110#define KVASER_PCI_DEVICE_ID2 0x0008
111 111
112static struct pci_device_id kvaser_pci_tbl[] = { 112static DEFINE_PCI_DEVICE_TABLE(kvaser_pci_tbl) = {
113 {KVASER_PCI_VENDOR_ID1, KVASER_PCI_DEVICE_ID1, PCI_ANY_ID, PCI_ANY_ID,}, 113 {KVASER_PCI_VENDOR_ID1, KVASER_PCI_DEVICE_ID1, PCI_ANY_ID, PCI_ANY_ID,},
114 {KVASER_PCI_VENDOR_ID2, KVASER_PCI_DEVICE_ID2, PCI_ANY_ID, PCI_ANY_ID,}, 114 {KVASER_PCI_VENDOR_ID2, KVASER_PCI_DEVICE_ID2, PCI_ANY_ID, PCI_ANY_ID,},
115 { 0,} 115 { 0,}
diff --git a/drivers/net/can/sja1000/plx_pci.c b/drivers/net/can/sja1000/plx_pci.c
new file mode 100644
index 000000000000..4aff4070db96
--- /dev/null
+++ b/drivers/net/can/sja1000/plx_pci.c
@@ -0,0 +1,473 @@
1/*
2 * Copyright (C) 2008-2010 Pavel Cheblakov <P.B.Cheblakov@inp.nsk.su>
3 *
4 * Derived from the ems_pci.c driver:
5 * Copyright (C) 2007 Wolfgang Grandegger <wg@grandegger.com>
6 * Copyright (C) 2008 Markus Plessing <plessing@ems-wuensche.com>
7 * Copyright (C) 2008 Sebastian Haas <haas@ems-wuensche.com>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the version 2 of the GNU General Public License
11 * as published by the Free Software Foundation
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software Foundation,
20 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 */
22
23#include <linux/kernel.h>
24#include <linux/module.h>
25#include <linux/interrupt.h>
26#include <linux/netdevice.h>
27#include <linux/delay.h>
28#include <linux/slab.h>
29#include <linux/pci.h>
30#include <linux/can.h>
31#include <linux/can/dev.h>
32#include <linux/io.h>
33
34#include "sja1000.h"
35
36#define DRV_NAME "sja1000_plx_pci"
37
38MODULE_AUTHOR("Pavel Cheblakov <P.B.Cheblakov@inp.nsk.su>");
39MODULE_DESCRIPTION("Socket-CAN driver for PLX90xx PCI-bridge cards with "
40 "the SJA1000 chips");
41MODULE_SUPPORTED_DEVICE("Adlink PCI-7841/cPCI-7841, "
42 "Adlink PCI-7841/cPCI-7841 SE, "
43 "Marathon CAN-bus-PCI, "
44 "TEWS TECHNOLOGIES TPMC810");
45MODULE_LICENSE("GPL v2");
46
47#define PLX_PCI_MAX_CHAN 2
48
49struct plx_pci_card {
50 int channels; /* detected channels count */
51 struct net_device *net_dev[PLX_PCI_MAX_CHAN];
52 void __iomem *conf_addr;
53};
54
55#define PLX_PCI_CAN_CLOCK (16000000 / 2)
56
57/* PLX90xx registers */
58#define PLX_INTCSR 0x4c /* Interrupt Control/Status */
59#define PLX_CNTRL 0x50 /* User I/O, Direct Slave Response,
60 * Serial EEPROM, and Initialization
61 * Control register
62 */
63
64#define PLX_LINT1_EN 0x1 /* Local interrupt 1 enable */
65#define PLX_LINT2_EN (1 << 3) /* Local interrupt 2 enable */
66#define PLX_PCI_INT_EN (1 << 6) /* PCI Interrupt Enable */
67#define PLX_PCI_RESET (1 << 30) /* PCI Adapter Software Reset */
68
69/*
70 * The board configuration is probably following:
71 * RX1 is connected to ground.
72 * TX1 is not connected.
73 * CLKO is not connected.
74 * Setting the OCR register to 0xDA is a good idea.
75 * This means normal output mode, push-pull and the correct polarity.
76 */
77#define PLX_PCI_OCR (OCR_TX0_PUSHPULL | OCR_TX1_PUSHPULL)
78
79/*
80 * In the CDR register, you should set CBP to 1.
81 * You will probably also want to set the clock divider value to 7
82 * (meaning direct oscillator output) because the second SJA1000 chip
83 * is driven by the first one CLKOUT output.
84 */
85#define PLX_PCI_CDR (CDR_CBP | CDR_CLKOUT_MASK)
86
87/* SJA1000 Control Register in the BasicCAN Mode */
88#define REG_CR 0x00
89
90/* States of some SJA1000 registers after hardware reset in the BasicCAN mode*/
91#define REG_CR_BASICCAN_INITIAL 0x21
92#define REG_CR_BASICCAN_INITIAL_MASK 0xa1
93#define REG_SR_BASICCAN_INITIAL 0x0c
94#define REG_IR_BASICCAN_INITIAL 0xe0
95
96/* States of some SJA1000 registers after hardware reset in the PeliCAN mode*/
97#define REG_MOD_PELICAN_INITIAL 0x01
98#define REG_SR_PELICAN_INITIAL 0x3c
99#define REG_IR_PELICAN_INITIAL 0x00
100
101#define ADLINK_PCI_VENDOR_ID 0x144A
102#define ADLINK_PCI_DEVICE_ID 0x7841
103
104#define MARATHON_PCI_DEVICE_ID 0x2715
105
106#define TEWS_PCI_VENDOR_ID 0x1498
107#define TEWS_PCI_DEVICE_ID_TMPC810 0x032A
108
109static void plx_pci_reset_common(struct pci_dev *pdev);
110static void plx_pci_reset_marathon(struct pci_dev *pdev);
111
112struct plx_pci_channel_map {
113 u32 bar;
114 u32 offset;
115 u32 size; /* 0x00 - auto, e.g. length of entire bar */
116};
117
118struct plx_pci_card_info {
119 const char *name;
120 int channel_count;
121 u32 can_clock;
122 u8 ocr; /* output control register */
123 u8 cdr; /* clock divider register */
124
125 /* Parameters for mapping local configuration space */
126 struct plx_pci_channel_map conf_map;
127
128 /* Parameters for mapping the SJA1000 chips */
129 struct plx_pci_channel_map chan_map_tbl[PLX_PCI_MAX_CHAN];
130
131 /* Pointer to device-dependent reset function */
132 void (*reset_func)(struct pci_dev *pdev);
133};
134
135static struct plx_pci_card_info plx_pci_card_info_adlink __devinitdata = {
136 "Adlink PCI-7841/cPCI-7841", 2,
137 PLX_PCI_CAN_CLOCK, PLX_PCI_OCR, PLX_PCI_CDR,
138 {1, 0x00, 0x00}, { {2, 0x00, 0x80}, {2, 0x80, 0x80} },
139 &plx_pci_reset_common
140 /* based on PLX9052 */
141};
142
143static struct plx_pci_card_info plx_pci_card_info_adlink_se __devinitdata = {
144 "Adlink PCI-7841/cPCI-7841 SE", 2,
145 PLX_PCI_CAN_CLOCK, PLX_PCI_OCR, PLX_PCI_CDR,
146 {0, 0x00, 0x00}, { {2, 0x00, 0x80}, {2, 0x80, 0x80} },
147 &plx_pci_reset_common
148 /* based on PLX9052 */
149};
150
151static struct plx_pci_card_info plx_pci_card_info_marathon __devinitdata = {
152 "Marathon CAN-bus-PCI", 2,
153 PLX_PCI_CAN_CLOCK, PLX_PCI_OCR, PLX_PCI_CDR,
154 {0, 0x00, 0x00}, { {2, 0x00, 0x00}, {4, 0x00, 0x00} },
155 &plx_pci_reset_marathon
156 /* based on PLX9052 */
157};
158
159static struct plx_pci_card_info plx_pci_card_info_tews __devinitdata = {
160 "TEWS TECHNOLOGIES TPMC810", 2,
161 PLX_PCI_CAN_CLOCK, PLX_PCI_OCR, PLX_PCI_CDR,
162 {0, 0x00, 0x00}, { {2, 0x000, 0x80}, {2, 0x100, 0x80} },
163 &plx_pci_reset_common
164 /* based on PLX9030 */
165};
166
167static DEFINE_PCI_DEVICE_TABLE(plx_pci_tbl) = {
168 {
169 /* Adlink PCI-7841/cPCI-7841 */
170 ADLINK_PCI_VENDOR_ID, ADLINK_PCI_DEVICE_ID,
171 PCI_ANY_ID, PCI_ANY_ID,
172 PCI_CLASS_NETWORK_OTHER << 8, ~0,
173 (kernel_ulong_t)&plx_pci_card_info_adlink
174 },
175 {
176 /* Adlink PCI-7841/cPCI-7841 SE */
177 ADLINK_PCI_VENDOR_ID, ADLINK_PCI_DEVICE_ID,
178 PCI_ANY_ID, PCI_ANY_ID,
179 PCI_CLASS_COMMUNICATION_OTHER << 8, ~0,
180 (kernel_ulong_t)&plx_pci_card_info_adlink_se
181 },
182 {
183 /* Marathon CAN-bus-PCI card */
184 PCI_VENDOR_ID_PLX, MARATHON_PCI_DEVICE_ID,
185 PCI_ANY_ID, PCI_ANY_ID,
186 0, 0,
187 (kernel_ulong_t)&plx_pci_card_info_marathon
188 },
189 {
190 /* TEWS TECHNOLOGIES TPMC810 card */
191 TEWS_PCI_VENDOR_ID, TEWS_PCI_DEVICE_ID_TMPC810,
192 PCI_ANY_ID, PCI_ANY_ID,
193 0, 0,
194 (kernel_ulong_t)&plx_pci_card_info_tews
195 },
196 { 0,}
197};
198MODULE_DEVICE_TABLE(pci, plx_pci_tbl);
199
200static u8 plx_pci_read_reg(const struct sja1000_priv *priv, int port)
201{
202 return ioread8(priv->reg_base + port);
203}
204
205static void plx_pci_write_reg(const struct sja1000_priv *priv, int port, u8 val)
206{
207 iowrite8(val, priv->reg_base + port);
208}
209
210/*
211 * Check if a CAN controller is present at the specified location
212 * by trying to switch 'em from the Basic mode into the PeliCAN mode.
213 * Also check states of some registers in reset mode.
214 */
215static inline int plx_pci_check_sja1000(const struct sja1000_priv *priv)
216{
217 int flag = 0;
218
219 /*
220 * Check registers after hardware reset (the Basic mode)
221 * See states on p. 10 of the Datasheet.
222 */
223 if ((priv->read_reg(priv, REG_CR) & REG_CR_BASICCAN_INITIAL_MASK) ==
224 REG_CR_BASICCAN_INITIAL &&
225 (priv->read_reg(priv, REG_SR) == REG_SR_BASICCAN_INITIAL) &&
226 (priv->read_reg(priv, REG_IR) == REG_IR_BASICCAN_INITIAL))
227 flag = 1;
228
229 /* Bring the SJA1000 into the PeliCAN mode*/
230 priv->write_reg(priv, REG_CDR, CDR_PELICAN);
231
232 /*
233 * Check registers after reset in the PeliCAN mode.
234 * See states on p. 23 of the Datasheet.
235 */
236 if (priv->read_reg(priv, REG_MOD) == REG_MOD_PELICAN_INITIAL &&
237 priv->read_reg(priv, REG_SR) == REG_SR_PELICAN_INITIAL &&
238 priv->read_reg(priv, REG_IR) == REG_IR_PELICAN_INITIAL)
239 return flag;
240
241 return 0;
242}
243
244/*
245 * PLX90xx software reset
246 * Also LRESET# asserts and brings to reset device on the Local Bus (if wired).
247 * For most cards it's enough for reset the SJA1000 chips.
248 */
249static void plx_pci_reset_common(struct pci_dev *pdev)
250{
251 struct plx_pci_card *card = pci_get_drvdata(pdev);
252 u32 cntrl;
253
254 cntrl = ioread32(card->conf_addr + PLX_CNTRL);
255 cntrl |= PLX_PCI_RESET;
256 iowrite32(cntrl, card->conf_addr + PLX_CNTRL);
257 udelay(100);
258 cntrl ^= PLX_PCI_RESET;
259 iowrite32(cntrl, card->conf_addr + PLX_CNTRL);
260};
261
262/* Special reset function for Marathon card */
263static void plx_pci_reset_marathon(struct pci_dev *pdev)
264{
265 void __iomem *reset_addr;
266 int i;
267 int reset_bar[2] = {3, 5};
268
269 plx_pci_reset_common(pdev);
270
271 for (i = 0; i < 2; i++) {
272 reset_addr = pci_iomap(pdev, reset_bar[i], 0);
273 if (!reset_addr) {
274 dev_err(&pdev->dev, "Failed to remap reset "
275 "space %d (BAR%d)\n", i, reset_bar[i]);
276 } else {
277 /* reset the SJA1000 chip */
278 iowrite8(0x1, reset_addr);
279 udelay(100);
280 pci_iounmap(pdev, reset_addr);
281 }
282 }
283}
284
285static void plx_pci_del_card(struct pci_dev *pdev)
286{
287 struct plx_pci_card *card = pci_get_drvdata(pdev);
288 struct net_device *dev;
289 struct sja1000_priv *priv;
290 int i = 0;
291
292 for (i = 0; i < card->channels; i++) {
293 dev = card->net_dev[i];
294 if (!dev)
295 continue;
296
297 dev_info(&pdev->dev, "Removing %s\n", dev->name);
298 unregister_sja1000dev(dev);
299 priv = netdev_priv(dev);
300 if (priv->reg_base)
301 pci_iounmap(pdev, priv->reg_base);
302 free_sja1000dev(dev);
303 }
304
305 plx_pci_reset_common(pdev);
306
307 /*
308 * Disable interrupts from PCI-card (PLX90xx) and disable Local_1,
309 * Local_2 interrupts
310 */
311 iowrite32(0x0, card->conf_addr + PLX_INTCSR);
312
313 if (card->conf_addr)
314 pci_iounmap(pdev, card->conf_addr);
315
316 kfree(card);
317
318 pci_disable_device(pdev);
319 pci_set_drvdata(pdev, NULL);
320}
321
322/*
323 * Probe PLX90xx based device for the SJA1000 chips and register each
324 * available CAN channel to SJA1000 Socket-CAN subsystem.
325 */
326static int __devinit plx_pci_add_card(struct pci_dev *pdev,
327 const struct pci_device_id *ent)
328{
329 struct sja1000_priv *priv;
330 struct net_device *dev;
331 struct plx_pci_card *card;
332 struct plx_pci_card_info *ci;
333 int err, i;
334 u32 val;
335 void __iomem *addr;
336
337 ci = (struct plx_pci_card_info *)ent->driver_data;
338
339 if (pci_enable_device(pdev) < 0) {
340 dev_err(&pdev->dev, "Failed to enable PCI device\n");
341 return -ENODEV;
342 }
343
344 dev_info(&pdev->dev, "Detected \"%s\" card at slot #%i\n",
345 ci->name, PCI_SLOT(pdev->devfn));
346
347 /* Allocate card structures to hold addresses, ... */
348 card = kzalloc(sizeof(*card), GFP_KERNEL);
349 if (!card) {
350 dev_err(&pdev->dev, "Unable to allocate memory\n");
351 pci_disable_device(pdev);
352 return -ENOMEM;
353 }
354
355 pci_set_drvdata(pdev, card);
356
357 card->channels = 0;
358
359 /* Remap PLX90xx configuration space */
360 addr = pci_iomap(pdev, ci->conf_map.bar, ci->conf_map.size);
361 if (!addr) {
362 err = -ENOMEM;
363 dev_err(&pdev->dev, "Failed to remap configuration space "
364 "(BAR%d)\n", ci->conf_map.bar);
365 goto failure_cleanup;
366 }
367 card->conf_addr = addr + ci->conf_map.offset;
368
369 ci->reset_func(pdev);
370
371 /* Detect available channels */
372 for (i = 0; i < ci->channel_count; i++) {
373 struct plx_pci_channel_map *cm = &ci->chan_map_tbl[i];
374
375 dev = alloc_sja1000dev(0);
376 if (!dev) {
377 err = -ENOMEM;
378 goto failure_cleanup;
379 }
380
381 card->net_dev[i] = dev;
382 priv = netdev_priv(dev);
383 priv->priv = card;
384 priv->irq_flags = IRQF_SHARED;
385
386 dev->irq = pdev->irq;
387
388 /*
389 * Remap IO space of the SJA1000 chips
390 * This is device-dependent mapping
391 */
392 addr = pci_iomap(pdev, cm->bar, cm->size);
393 if (!addr) {
394 err = -ENOMEM;
395 dev_err(&pdev->dev, "Failed to remap BAR%d\n", cm->bar);
396 goto failure_cleanup;
397 }
398
399 priv->reg_base = addr + cm->offset;
400 priv->read_reg = plx_pci_read_reg;
401 priv->write_reg = plx_pci_write_reg;
402
403 /* Check if channel is present */
404 if (plx_pci_check_sja1000(priv)) {
405 priv->can.clock.freq = ci->can_clock;
406 priv->ocr = ci->ocr;
407 priv->cdr = ci->cdr;
408
409 SET_NETDEV_DEV(dev, &pdev->dev);
410
411 /* Register SJA1000 device */
412 err = register_sja1000dev(dev);
413 if (err) {
414 dev_err(&pdev->dev, "Registering device failed "
415 "(err=%d)\n", err);
416 free_sja1000dev(dev);
417 goto failure_cleanup;
418 }
419
420 card->channels++;
421
422 dev_info(&pdev->dev, "Channel #%d at 0x%p, irq %d "
423 "registered as %s\n", i + 1, priv->reg_base,
424 dev->irq, dev->name);
425 } else {
426 dev_err(&pdev->dev, "Channel #%d not detected\n",
427 i + 1);
428 free_sja1000dev(dev);
429 }
430 }
431
432 if (!card->channels) {
433 err = -ENODEV;
434 goto failure_cleanup;
435 }
436
437 /*
438 * Enable interrupts from PCI-card (PLX90xx) and enable Local_1,
439 * Local_2 interrupts from the SJA1000 chips
440 */
441 val = ioread32(card->conf_addr + PLX_INTCSR);
442 val |= PLX_LINT1_EN | PLX_LINT2_EN | PLX_PCI_INT_EN;
443 iowrite32(val, card->conf_addr + PLX_INTCSR);
444
445 return 0;
446
447failure_cleanup:
448 dev_err(&pdev->dev, "Error: %d. Cleaning Up.\n", err);
449
450 plx_pci_del_card(pdev);
451
452 return err;
453}
454
455static struct pci_driver plx_pci_driver = {
456 .name = DRV_NAME,
457 .id_table = plx_pci_tbl,
458 .probe = plx_pci_add_card,
459 .remove = plx_pci_del_card,
460};
461
462static int __init plx_pci_init(void)
463{
464 return pci_register_driver(&plx_pci_driver);
465}
466
467static void __exit plx_pci_exit(void)
468{
469 pci_unregister_driver(&plx_pci_driver);
470}
471
472module_init(plx_pci_init);
473module_exit(plx_pci_exit);
diff --git a/drivers/net/can/sja1000/sja1000.c b/drivers/net/can/sja1000/sja1000.c
index 16d2ecd2a3b7..145b1a731a53 100644
--- a/drivers/net/can/sja1000/sja1000.c
+++ b/drivers/net/can/sja1000/sja1000.c
@@ -130,8 +130,12 @@ static void set_normal_mode(struct net_device *dev)
130 /* check reset bit */ 130 /* check reset bit */
131 if ((status & MOD_RM) == 0) { 131 if ((status & MOD_RM) == 0) {
132 priv->can.state = CAN_STATE_ERROR_ACTIVE; 132 priv->can.state = CAN_STATE_ERROR_ACTIVE;
133 /* enable all interrupts */ 133 /* enable interrupts */
134 priv->write_reg(priv, REG_IER, IRQ_ALL); 134 if (priv->can.ctrlmode & CAN_CTRLMODE_BERR_REPORTING)
135 priv->write_reg(priv, REG_IER, IRQ_ALL);
136 else
137 priv->write_reg(priv, REG_IER,
138 IRQ_ALL & ~IRQ_BEI);
135 return; 139 return;
136 } 140 }
137 141
@@ -203,6 +207,17 @@ static int sja1000_set_bittiming(struct net_device *dev)
203 return 0; 207 return 0;
204} 208}
205 209
210static int sja1000_get_berr_counter(const struct net_device *dev,
211 struct can_berr_counter *bec)
212{
213 struct sja1000_priv *priv = netdev_priv(dev);
214
215 bec->txerr = priv->read_reg(priv, REG_TXERR);
216 bec->rxerr = priv->read_reg(priv, REG_RXERR);
217
218 return 0;
219}
220
206/* 221/*
207 * initialize SJA1000 chip: 222 * initialize SJA1000 chip:
208 * - reset chip 223 * - reset chip
@@ -249,6 +264,9 @@ static netdev_tx_t sja1000_start_xmit(struct sk_buff *skb,
249 uint8_t dreg; 264 uint8_t dreg;
250 int i; 265 int i;
251 266
267 if (can_dropped_invalid_skb(dev, skb))
268 return NETDEV_TX_OK;
269
252 netif_stop_queue(dev); 270 netif_stop_queue(dev);
253 271
254 fi = dlc = cf->can_dlc; 272 fi = dlc = cf->can_dlc;
@@ -293,17 +311,14 @@ static void sja1000_rx(struct net_device *dev)
293 uint8_t fi; 311 uint8_t fi;
294 uint8_t dreg; 312 uint8_t dreg;
295 canid_t id; 313 canid_t id;
296 uint8_t dlc;
297 int i; 314 int i;
298 315
299 skb = dev_alloc_skb(sizeof(struct can_frame)); 316 /* create zero'ed CAN frame buffer */
317 skb = alloc_can_skb(dev, &cf);
300 if (skb == NULL) 318 if (skb == NULL)
301 return; 319 return;
302 skb->dev = dev;
303 skb->protocol = htons(ETH_P_CAN);
304 320
305 fi = priv->read_reg(priv, REG_FI); 321 fi = priv->read_reg(priv, REG_FI);
306 dlc = fi & 0x0F;
307 322
308 if (fi & FI_FF) { 323 if (fi & FI_FF) {
309 /* extended frame format (EFF) */ 324 /* extended frame format (EFF) */
@@ -320,18 +335,15 @@ static void sja1000_rx(struct net_device *dev)
320 | (priv->read_reg(priv, REG_ID2) >> 5); 335 | (priv->read_reg(priv, REG_ID2) >> 5);
321 } 336 }
322 337
323 if (fi & FI_RTR) 338 if (fi & FI_RTR) {
324 id |= CAN_RTR_FLAG; 339 id |= CAN_RTR_FLAG;
340 } else {
341 cf->can_dlc = get_can_dlc(fi & 0x0F);
342 for (i = 0; i < cf->can_dlc; i++)
343 cf->data[i] = priv->read_reg(priv, dreg++);
344 }
325 345
326 cf = (struct can_frame *)skb_put(skb, sizeof(struct can_frame));
327 memset(cf, 0, sizeof(struct can_frame));
328 cf->can_id = id; 346 cf->can_id = id;
329 cf->can_dlc = dlc;
330 for (i = 0; i < dlc; i++)
331 cf->data[i] = priv->read_reg(priv, dreg++);
332
333 while (i < 8)
334 cf->data[i++] = 0;
335 347
336 /* release receive buffer */ 348 /* release receive buffer */
337 priv->write_reg(priv, REG_CMR, CMD_RRB); 349 priv->write_reg(priv, REG_CMR, CMD_RRB);
@@ -339,7 +351,7 @@ static void sja1000_rx(struct net_device *dev)
339 netif_rx(skb); 351 netif_rx(skb);
340 352
341 stats->rx_packets++; 353 stats->rx_packets++;
342 stats->rx_bytes += dlc; 354 stats->rx_bytes += cf->can_dlc;
343} 355}
344 356
345static int sja1000_err(struct net_device *dev, uint8_t isrc, uint8_t status) 357static int sja1000_err(struct net_device *dev, uint8_t isrc, uint8_t status)
@@ -351,15 +363,9 @@ static int sja1000_err(struct net_device *dev, uint8_t isrc, uint8_t status)
351 enum can_state state = priv->can.state; 363 enum can_state state = priv->can.state;
352 uint8_t ecc, alc; 364 uint8_t ecc, alc;
353 365
354 skb = dev_alloc_skb(sizeof(struct can_frame)); 366 skb = alloc_can_err_skb(dev, &cf);
355 if (skb == NULL) 367 if (skb == NULL)
356 return -ENOMEM; 368 return -ENOMEM;
357 skb->dev = dev;
358 skb->protocol = htons(ETH_P_CAN);
359 cf = (struct can_frame *)skb_put(skb, sizeof(struct can_frame));
360 memset(cf, 0, sizeof(struct can_frame));
361 cf->can_id = CAN_ERR_FLAG;
362 cf->can_dlc = CAN_ERR_DLC;
363 369
364 if (isrc & IRQ_DOI) { 370 if (isrc & IRQ_DOI) {
365 /* data overrun interrupt */ 371 /* data overrun interrupt */
@@ -446,6 +452,8 @@ static int sja1000_err(struct net_device *dev, uint8_t isrc, uint8_t status)
446 CAN_ERR_CRTL_TX_PASSIVE : 452 CAN_ERR_CRTL_TX_PASSIVE :
447 CAN_ERR_CRTL_RX_PASSIVE; 453 CAN_ERR_CRTL_RX_PASSIVE;
448 } 454 }
455 cf->data[6] = txerr;
456 cf->data[7] = rxerr;
449 } 457 }
450 458
451 priv->can.state = state; 459 priv->can.state = state;
@@ -526,7 +534,7 @@ static int sja1000_open(struct net_device *dev)
526 534
527 /* register interrupt handler, if not done by the device driver */ 535 /* register interrupt handler, if not done by the device driver */
528 if (!(priv->flags & SJA1000_CUSTOM_IRQ_HANDLER)) { 536 if (!(priv->flags & SJA1000_CUSTOM_IRQ_HANDLER)) {
529 err = request_irq(dev->irq, &sja1000_interrupt, priv->irq_flags, 537 err = request_irq(dev->irq, sja1000_interrupt, priv->irq_flags,
530 dev->name, (void *)dev); 538 dev->name, (void *)dev);
531 if (err) { 539 if (err) {
532 close_candev(dev); 540 close_candev(dev);
@@ -565,7 +573,8 @@ struct net_device *alloc_sja1000dev(int sizeof_priv)
565 struct net_device *dev; 573 struct net_device *dev;
566 struct sja1000_priv *priv; 574 struct sja1000_priv *priv;
567 575
568 dev = alloc_candev(sizeof(struct sja1000_priv) + sizeof_priv); 576 dev = alloc_candev(sizeof(struct sja1000_priv) + sizeof_priv,
577 SJA1000_ECHO_SKB_MAX);
569 if (!dev) 578 if (!dev)
570 return NULL; 579 return NULL;
571 580
@@ -575,6 +584,9 @@ struct net_device *alloc_sja1000dev(int sizeof_priv)
575 priv->can.bittiming_const = &sja1000_bittiming_const; 584 priv->can.bittiming_const = &sja1000_bittiming_const;
576 priv->can.do_set_bittiming = sja1000_set_bittiming; 585 priv->can.do_set_bittiming = sja1000_set_bittiming;
577 priv->can.do_set_mode = sja1000_set_mode; 586 priv->can.do_set_mode = sja1000_set_mode;
587 priv->can.do_get_berr_counter = sja1000_get_berr_counter;
588 priv->can.ctrlmode_supported = CAN_CTRLMODE_3_SAMPLES |
589 CAN_CTRLMODE_BERR_REPORTING;
578 590
579 if (sizeof_priv) 591 if (sizeof_priv)
580 priv->priv = (void *)priv + sizeof(struct sja1000_priv); 592 priv->priv = (void *)priv + sizeof(struct sja1000_priv);
diff --git a/drivers/net/can/sja1000/sja1000.h b/drivers/net/can/sja1000/sja1000.h
index 302d2c763ad7..97a622b9302f 100644
--- a/drivers/net/can/sja1000/sja1000.h
+++ b/drivers/net/can/sja1000/sja1000.h
@@ -50,6 +50,8 @@
50#include <linux/can/dev.h> 50#include <linux/can/dev.h>
51#include <linux/can/platform/sja1000.h> 51#include <linux/can/platform/sja1000.h>
52 52
53#define SJA1000_ECHO_SKB_MAX 1 /* the SJA1000 has one TX buffer object */
54
53#define SJA1000_MAX_IRQ 20 /* max. number of interrupts handled in ISR */ 55#define SJA1000_MAX_IRQ 20 /* max. number of interrupts handled in ISR */
54 56
55/* SJA1000 registers - manual section 6.4 (Pelican Mode) */ 57/* SJA1000 registers - manual section 6.4 (Pelican Mode) */