sja1000.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637
  1. /*
  2. * sja1000.c - Philips SJA1000 network device driver
  3. *
  4. * Copyright (c) 2003 Matthias Brukner, Trajet Gmbh, Rebenring 33,
  5. * 38106 Braunschweig, GERMANY
  6. *
  7. * Copyright (c) 2002-2007 Volkswagen Group Electronic Research
  8. * All rights reserved.
  9. *
  10. * Redistribution and use in source and binary forms, with or without
  11. * modification, are permitted provided that the following conditions
  12. * are met:
  13. * 1. Redistributions of source code must retain the above copyright
  14. * notice, this list of conditions and the following disclaimer.
  15. * 2. Redistributions in binary form must reproduce the above copyright
  16. * notice, this list of conditions and the following disclaimer in the
  17. * documentation and/or other materials provided with the distribution.
  18. * 3. Neither the name of Volkswagen nor the names of its contributors
  19. * may be used to endorse or promote products derived from this software
  20. * without specific prior written permission.
  21. *
  22. * Alternatively, provided that this notice is retained in full, this
  23. * software may be distributed under the terms of the GNU General
  24. * Public License ("GPL") version 2, in which case the provisions of the
  25. * GPL apply INSTEAD OF those given above.
  26. *
  27. * The provided data structures and external interfaces from this code
  28. * are not restricted to be used by modules with a GPL compatible license.
  29. *
  30. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  31. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  32. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  33. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  34. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  35. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  36. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  37. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  38. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  39. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  40. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  41. * DAMAGE.
  42. *
  43. * Send feedback to <socketcan-users@lists.berlios.de>
  44. *
  45. */
  46. #include <linux/module.h>
  47. #include <linux/init.h>
  48. #include <linux/kernel.h>
  49. #include <linux/sched.h>
  50. #include <linux/types.h>
  51. #include <linux/fcntl.h>
  52. #include <linux/interrupt.h>
  53. #include <linux/ptrace.h>
  54. #include <linux/string.h>
  55. #include <linux/errno.h>
  56. #include <linux/netdevice.h>
  57. #include <linux/if_arp.h>
  58. #include <linux/if_ether.h>
  59. #include <linux/skbuff.h>
  60. #include <linux/delay.h>
  61. #include <linux/can.h>
  62. #include <linux/can/dev.h>
  63. #include <linux/can/error.h>
  64. #include <linux/can/dev.h>
  65. #include "sja1000.h"
  66. #define DRV_NAME "sja1000"
  67. MODULE_AUTHOR("Oliver Hartkopp <oliver.hartkopp@volkswagen.de>");
  68. MODULE_LICENSE("Dual BSD/GPL");
  69. MODULE_DESCRIPTION(DRV_NAME "CAN netdevice driver");
  70. static struct can_bittiming_const sja1000_bittiming_const = {
  71. .name = DRV_NAME,
  72. .tseg1_min = 1,
  73. .tseg1_max = 16,
  74. .tseg2_min = 1,
  75. .tseg2_max = 8,
  76. .sjw_max = 4,
  77. .brp_min = 1,
  78. .brp_max = 64,
  79. .brp_inc = 1,
  80. };
  81. static int sja1000_probe_chip(struct net_device *dev)
  82. {
  83. struct sja1000_priv *priv = netdev_priv(dev);
  84. if (priv->reg_base && (priv->read_reg(priv, 0) == 0xFF)) {
  85. printk(KERN_INFO "%s: probing @0x%lX failed\n",
  86. DRV_NAME, dev->base_addr);
  87. return 0;
  88. }
  89. return -1;
  90. }
  91. static void set_reset_mode(struct net_device *dev)
  92. {
  93. struct sja1000_priv *priv = netdev_priv(dev);
  94. unsigned char status = priv->read_reg(priv, REG_MOD);
  95. int i;
  96. /* disable interrupts */
  97. priv->write_reg(priv, REG_IER, IRQ_OFF);
  98. for (i = 0; i < 100; i++) {
  99. /* check reset bit */
  100. if (status & MOD_RM) {
  101. priv->can.state = CAN_STATE_STOPPED;
  102. return;
  103. }
  104. priv->write_reg(priv, REG_MOD, MOD_RM); /* reset chip */
  105. udelay(10);
  106. status = priv->read_reg(priv, REG_MOD);
  107. }
  108. dev_err(dev->dev.parent, "setting SJA1000 into reset mode failed!\n");
  109. }
  110. static void set_normal_mode(struct net_device *dev)
  111. {
  112. struct sja1000_priv *priv = netdev_priv(dev);
  113. unsigned char status = priv->read_reg(priv, REG_MOD);
  114. int i;
  115. for (i = 0; i < 100; i++) {
  116. /* check reset bit */
  117. if ((status & MOD_RM) == 0) {
  118. priv->can.state = CAN_STATE_ERROR_ACTIVE;
  119. /* enable all interrupts */
  120. priv->write_reg(priv, REG_IER, IRQ_ALL);
  121. return;
  122. }
  123. /* set chip to normal mode */
  124. priv->write_reg(priv, REG_MOD, 0x00);
  125. udelay(10);
  126. status = priv->read_reg(priv, REG_MOD);
  127. }
  128. dev_err(dev->dev.parent, "setting SJA1000 into normal mode failed!\n");
  129. }
  130. static void sja1000_start(struct net_device *dev)
  131. {
  132. struct sja1000_priv *priv = netdev_priv(dev);
  133. /* leave reset mode */
  134. if (priv->can.state != CAN_STATE_STOPPED)
  135. set_reset_mode(dev);
  136. /* Clear error counters and error code capture */
  137. priv->write_reg(priv, REG_TXERR, 0x0);
  138. priv->write_reg(priv, REG_RXERR, 0x0);
  139. priv->read_reg(priv, REG_ECC);
  140. /* leave reset mode */
  141. set_normal_mode(dev);
  142. }
  143. static int sja1000_set_mode(struct net_device *dev, enum can_mode mode)
  144. {
  145. struct sja1000_priv *priv = netdev_priv(dev);
  146. if (!priv->open_time)
  147. return -EINVAL;
  148. switch (mode) {
  149. case CAN_MODE_START:
  150. sja1000_start(dev);
  151. if (netif_queue_stopped(dev))
  152. netif_wake_queue(dev);
  153. break;
  154. default:
  155. return -EOPNOTSUPP;
  156. }
  157. return 0;
  158. }
  159. static int sja1000_set_bittiming(struct net_device *dev)
  160. {
  161. struct sja1000_priv *priv = netdev_priv(dev);
  162. struct can_bittiming *bt = &priv->can.bittiming;
  163. u8 btr0, btr1;
  164. btr0 = ((bt->brp - 1) & 0x3f) | (((bt->sjw - 1) & 0x3) << 6);
  165. btr1 = ((bt->prop_seg + bt->phase_seg1 - 1) & 0xf) |
  166. (((bt->phase_seg2 - 1) & 0x7) << 4);
  167. if (priv->can.ctrlmode & CAN_CTRLMODE_3_SAMPLES)
  168. btr1 |= 0x80;
  169. dev_info(dev->dev.parent,
  170. "setting BTR0=0x%02x BTR1=0x%02x\n", btr0, btr1);
  171. priv->write_reg(priv, REG_BTR0, btr0);
  172. priv->write_reg(priv, REG_BTR1, btr1);
  173. return 0;
  174. }
  175. /*
  176. * initialize SJA1000 chip:
  177. * - reset chip
  178. * - set output mode
  179. * - set baudrate
  180. * - enable interrupts
  181. * - start operating mode
  182. */
  183. static void chipset_init(struct net_device *dev)
  184. {
  185. struct sja1000_priv *priv = netdev_priv(dev);
  186. /* set clock divider and output control register */
  187. priv->write_reg(priv, REG_CDR, priv->cdr | CDR_PELICAN);
  188. /* set acceptance filter (accept all) */
  189. priv->write_reg(priv, REG_ACCC0, 0x00);
  190. priv->write_reg(priv, REG_ACCC1, 0x00);
  191. priv->write_reg(priv, REG_ACCC2, 0x00);
  192. priv->write_reg(priv, REG_ACCC3, 0x00);
  193. priv->write_reg(priv, REG_ACCM0, 0xFF);
  194. priv->write_reg(priv, REG_ACCM1, 0xFF);
  195. priv->write_reg(priv, REG_ACCM2, 0xFF);
  196. priv->write_reg(priv, REG_ACCM3, 0xFF);
  197. priv->write_reg(priv, REG_OCR, priv->ocr | OCR_MODE_NORMAL);
  198. }
  199. /*
  200. * transmit a CAN message
  201. * message layout in the sk_buff should be like this:
  202. * xx xx xx xx ff ll 00 11 22 33 44 55 66 77
  203. * [ can-id ] [flags] [len] [can data (up to 8 bytes]
  204. */
  205. static int sja1000_start_xmit(struct sk_buff *skb, struct net_device *dev)
  206. {
  207. struct sja1000_priv *priv = netdev_priv(dev);
  208. struct net_device_stats *stats = &dev->stats;
  209. struct can_frame *cf = (struct can_frame *)skb->data;
  210. uint8_t fi;
  211. uint8_t dlc;
  212. canid_t id;
  213. uint8_t dreg;
  214. int i;
  215. netif_stop_queue(dev);
  216. fi = dlc = cf->can_dlc;
  217. id = cf->can_id;
  218. if (id & CAN_RTR_FLAG)
  219. fi |= FI_RTR;
  220. if (id & CAN_EFF_FLAG) {
  221. fi |= FI_FF;
  222. dreg = EFF_BUF;
  223. priv->write_reg(priv, REG_FI, fi);
  224. priv->write_reg(priv, REG_ID1, (id & 0x1fe00000) >> (5 + 16));
  225. priv->write_reg(priv, REG_ID2, (id & 0x001fe000) >> (5 + 8));
  226. priv->write_reg(priv, REG_ID3, (id & 0x00001fe0) >> 5);
  227. priv->write_reg(priv, REG_ID4, (id & 0x0000001f) << 3);
  228. } else {
  229. dreg = SFF_BUF;
  230. priv->write_reg(priv, REG_FI, fi);
  231. priv->write_reg(priv, REG_ID1, (id & 0x000007f8) >> 3);
  232. priv->write_reg(priv, REG_ID2, (id & 0x00000007) << 5);
  233. }
  234. for (i = 0; i < dlc; i++)
  235. priv->write_reg(priv, dreg++, cf->data[i]);
  236. stats->tx_bytes += dlc;
  237. dev->trans_start = jiffies;
  238. can_put_echo_skb(skb, dev, 0);
  239. priv->write_reg(priv, REG_CMR, CMD_TR);
  240. return NETDEV_TX_OK;
  241. }
  242. static void sja1000_rx(struct net_device *dev)
  243. {
  244. struct sja1000_priv *priv = netdev_priv(dev);
  245. struct net_device_stats *stats = &dev->stats;
  246. struct can_frame *cf;
  247. struct sk_buff *skb;
  248. uint8_t fi;
  249. uint8_t dreg;
  250. canid_t id;
  251. uint8_t dlc;
  252. int i;
  253. skb = dev_alloc_skb(sizeof(struct can_frame));
  254. if (skb == NULL)
  255. return;
  256. skb->dev = dev;
  257. skb->protocol = htons(ETH_P_CAN);
  258. fi = priv->read_reg(priv, REG_FI);
  259. dlc = fi & 0x0F;
  260. if (fi & FI_FF) {
  261. /* extended frame format (EFF) */
  262. dreg = EFF_BUF;
  263. id = (priv->read_reg(priv, REG_ID1) << (5 + 16))
  264. | (priv->read_reg(priv, REG_ID2) << (5 + 8))
  265. | (priv->read_reg(priv, REG_ID3) << 5)
  266. | (priv->read_reg(priv, REG_ID4) >> 3);
  267. id |= CAN_EFF_FLAG;
  268. } else {
  269. /* standard frame format (SFF) */
  270. dreg = SFF_BUF;
  271. id = (priv->read_reg(priv, REG_ID1) << 3)
  272. | (priv->read_reg(priv, REG_ID2) >> 5);
  273. }
  274. if (fi & FI_RTR)
  275. id |= CAN_RTR_FLAG;
  276. cf = (struct can_frame *)skb_put(skb, sizeof(struct can_frame));
  277. memset(cf, 0, sizeof(struct can_frame));
  278. cf->can_id = id;
  279. cf->can_dlc = dlc;
  280. for (i = 0; i < dlc; i++)
  281. cf->data[i] = priv->read_reg(priv, dreg++);
  282. while (i < 8)
  283. cf->data[i++] = 0;
  284. /* release receive buffer */
  285. priv->write_reg(priv, REG_CMR, CMD_RRB);
  286. netif_rx(skb);
  287. dev->last_rx = jiffies;
  288. stats->rx_packets++;
  289. stats->rx_bytes += dlc;
  290. }
  291. static int sja1000_err(struct net_device *dev, uint8_t isrc, uint8_t status)
  292. {
  293. struct sja1000_priv *priv = netdev_priv(dev);
  294. struct net_device_stats *stats = &dev->stats;
  295. struct can_frame *cf;
  296. struct sk_buff *skb;
  297. enum can_state state = priv->can.state;
  298. uint8_t ecc, alc;
  299. skb = dev_alloc_skb(sizeof(struct can_frame));
  300. if (skb == NULL)
  301. return -ENOMEM;
  302. skb->dev = dev;
  303. skb->protocol = htons(ETH_P_CAN);
  304. cf = (struct can_frame *)skb_put(skb, sizeof(struct can_frame));
  305. memset(cf, 0, sizeof(struct can_frame));
  306. cf->can_id = CAN_ERR_FLAG;
  307. cf->can_dlc = CAN_ERR_DLC;
  308. if (isrc & IRQ_DOI) {
  309. /* data overrun interrupt */
  310. dev_dbg(dev->dev.parent, "data overrun interrupt\n");
  311. cf->can_id |= CAN_ERR_CRTL;
  312. cf->data[1] = CAN_ERR_CRTL_RX_OVERFLOW;
  313. stats->rx_over_errors++;
  314. stats->rx_errors++;
  315. priv->write_reg(priv, REG_CMR, CMD_CDO); /* clear bit */
  316. }
  317. if (isrc & IRQ_EI) {
  318. /* error warning interrupt */
  319. dev_dbg(dev->dev.parent, "error warning interrupt\n");
  320. if (status & SR_BS) {
  321. state = CAN_STATE_BUS_OFF;
  322. cf->can_id |= CAN_ERR_BUSOFF;
  323. can_bus_off(dev);
  324. } else if (status & SR_ES) {
  325. state = CAN_STATE_ERROR_WARNING;
  326. } else
  327. state = CAN_STATE_ERROR_ACTIVE;
  328. }
  329. if (isrc & IRQ_BEI) {
  330. /* bus error interrupt */
  331. priv->can.can_stats.bus_error++;
  332. stats->rx_errors++;
  333. ecc = priv->read_reg(priv, REG_ECC);
  334. cf->can_id |= CAN_ERR_PROT | CAN_ERR_BUSERROR;
  335. switch (ecc & ECC_MASK) {
  336. case ECC_BIT:
  337. cf->data[2] |= CAN_ERR_PROT_BIT;
  338. break;
  339. case ECC_FORM:
  340. cf->data[2] |= CAN_ERR_PROT_FORM;
  341. break;
  342. case ECC_STUFF:
  343. cf->data[2] |= CAN_ERR_PROT_STUFF;
  344. break;
  345. default:
  346. cf->data[2] |= CAN_ERR_PROT_UNSPEC;
  347. cf->data[3] = ecc & ECC_SEG;
  348. break;
  349. }
  350. /* Error occured during transmission? */
  351. if ((ecc & ECC_DIR) == 0)
  352. cf->data[2] |= CAN_ERR_PROT_TX;
  353. }
  354. if (isrc & IRQ_EPI) {
  355. /* error passive interrupt */
  356. dev_dbg(dev->dev.parent, "error passive interrupt\n");
  357. if (status & SR_ES)
  358. state = CAN_STATE_ERROR_PASSIVE;
  359. else
  360. state = CAN_STATE_ERROR_ACTIVE;
  361. }
  362. if (isrc & IRQ_ALI) {
  363. /* arbitration lost interrupt */
  364. dev_dbg(dev->dev.parent, "arbitration lost interrupt\n");
  365. alc = priv->read_reg(priv, REG_ALC);
  366. priv->can.can_stats.arbitration_lost++;
  367. stats->rx_errors++;
  368. cf->can_id |= CAN_ERR_LOSTARB;
  369. cf->data[0] = alc & 0x1f;
  370. }
  371. if (state != priv->can.state && (state == CAN_STATE_ERROR_WARNING ||
  372. state == CAN_STATE_ERROR_PASSIVE)) {
  373. uint8_t rxerr = priv->read_reg(priv, REG_RXERR);
  374. uint8_t txerr = priv->read_reg(priv, REG_TXERR);
  375. cf->can_id |= CAN_ERR_CRTL;
  376. if (state == CAN_STATE_ERROR_WARNING) {
  377. priv->can.can_stats.error_warning++;
  378. cf->data[1] = (txerr > rxerr) ?
  379. CAN_ERR_CRTL_TX_WARNING :
  380. CAN_ERR_CRTL_RX_WARNING;
  381. } else {
  382. priv->can.can_stats.error_passive++;
  383. cf->data[1] = (txerr > rxerr) ?
  384. CAN_ERR_CRTL_TX_PASSIVE :
  385. CAN_ERR_CRTL_RX_PASSIVE;
  386. }
  387. }
  388. priv->can.state = state;
  389. netif_rx(skb);
  390. dev->last_rx = jiffies;
  391. stats->rx_packets++;
  392. stats->rx_bytes += cf->can_dlc;
  393. return 0;
  394. }
  395. irqreturn_t sja1000_interrupt(int irq, void *dev_id)
  396. {
  397. struct net_device *dev = (struct net_device *)dev_id;
  398. struct sja1000_priv *priv = netdev_priv(dev);
  399. struct net_device_stats *stats = &dev->stats;
  400. uint8_t isrc, status;
  401. int n = 0;
  402. /* Shared interrupts and IRQ off? */
  403. if (priv->read_reg(priv, REG_IER) == IRQ_OFF)
  404. return IRQ_NONE;
  405. if (priv->pre_irq)
  406. priv->pre_irq(priv);
  407. while ((isrc = priv->read_reg(priv, REG_IR)) && (n < SJA1000_MAX_IRQ)) {
  408. n++;
  409. status = priv->read_reg(priv, REG_SR);
  410. if (isrc & IRQ_WUI)
  411. dev_warn(dev->dev.parent, "wakeup interrupt\n");
  412. if (isrc & IRQ_TI) {
  413. /* transmission complete interrupt */
  414. stats->tx_packets++;
  415. can_get_echo_skb(dev, 0);
  416. netif_wake_queue(dev);
  417. }
  418. if (isrc & IRQ_RI) {
  419. /* receive interrupt */
  420. while (status & SR_RBS) {
  421. sja1000_rx(dev);
  422. status = priv->read_reg(priv, REG_SR);
  423. }
  424. }
  425. if (isrc & (IRQ_DOI | IRQ_EI | IRQ_BEI | IRQ_EPI | IRQ_ALI)) {
  426. /* error interrupt */
  427. if (sja1000_err(dev, isrc, status))
  428. break;
  429. }
  430. }
  431. if (priv->post_irq)
  432. priv->post_irq(priv);
  433. if (n >= SJA1000_MAX_IRQ)
  434. dev_dbg(dev->dev.parent, "%d messages handled in ISR", n);
  435. return (n) ? IRQ_HANDLED : IRQ_NONE;
  436. }
  437. EXPORT_SYMBOL_GPL(sja1000_interrupt);
  438. static int sja1000_open(struct net_device *dev)
  439. {
  440. struct sja1000_priv *priv = netdev_priv(dev);
  441. int err;
  442. /* set chip into reset mode */
  443. set_reset_mode(dev);
  444. /* common open */
  445. err = open_candev(dev);
  446. if (err)
  447. return err;
  448. /* register interrupt handler, if not done by the device driver */
  449. if (!(priv->flags & SJA1000_CUSTOM_IRQ_HANDLER)) {
  450. err = request_irq(dev->irq, &sja1000_interrupt, priv->irq_flags,
  451. dev->name, (void *)dev);
  452. if (err) {
  453. close_candev(dev);
  454. return -EAGAIN;
  455. }
  456. }
  457. /* init and start chi */
  458. sja1000_start(dev);
  459. priv->open_time = jiffies;
  460. netif_start_queue(dev);
  461. return 0;
  462. }
  463. static int sja1000_close(struct net_device *dev)
  464. {
  465. struct sja1000_priv *priv = netdev_priv(dev);
  466. netif_stop_queue(dev);
  467. set_reset_mode(dev);
  468. if (!(priv->flags & SJA1000_CUSTOM_IRQ_HANDLER))
  469. free_irq(dev->irq, (void *)dev);
  470. close_candev(dev);
  471. priv->open_time = 0;
  472. return 0;
  473. }
  474. struct net_device *alloc_sja1000dev(int sizeof_priv)
  475. {
  476. struct net_device *dev;
  477. struct sja1000_priv *priv;
  478. dev = alloc_candev(sizeof(struct sja1000_priv) + sizeof_priv);
  479. if (!dev)
  480. return NULL;
  481. priv = netdev_priv(dev);
  482. priv->dev = dev;
  483. priv->can.bittiming_const = &sja1000_bittiming_const;
  484. priv->can.do_set_bittiming = sja1000_set_bittiming;
  485. priv->can.do_set_mode = sja1000_set_mode;
  486. if (sizeof_priv)
  487. priv->priv = (void *)priv + sizeof(struct sja1000_priv);
  488. return dev;
  489. }
  490. EXPORT_SYMBOL_GPL(alloc_sja1000dev);
  491. void free_sja1000dev(struct net_device *dev)
  492. {
  493. free_candev(dev);
  494. }
  495. EXPORT_SYMBOL_GPL(free_sja1000dev);
  496. static const struct net_device_ops sja1000_netdev_ops = {
  497. .ndo_open = sja1000_open,
  498. .ndo_stop = sja1000_close,
  499. .ndo_start_xmit = sja1000_start_xmit,
  500. };
  501. int register_sja1000dev(struct net_device *dev)
  502. {
  503. if (!sja1000_probe_chip(dev))
  504. return -ENODEV;
  505. dev->flags |= IFF_ECHO; /* we support local echo */
  506. dev->netdev_ops = &sja1000_netdev_ops;
  507. set_reset_mode(dev);
  508. chipset_init(dev);
  509. return register_candev(dev);
  510. }
  511. EXPORT_SYMBOL_GPL(register_sja1000dev);
  512. void unregister_sja1000dev(struct net_device *dev)
  513. {
  514. set_reset_mode(dev);
  515. unregister_candev(dev);
  516. }
  517. EXPORT_SYMBOL_GPL(unregister_sja1000dev);
  518. static __init int sja1000_init(void)
  519. {
  520. printk(KERN_INFO "%s CAN netdevice driver\n", DRV_NAME);
  521. return 0;
  522. }
  523. module_init(sja1000_init);
  524. static __exit void sja1000_exit(void)
  525. {
  526. printk(KERN_INFO "%s: driver removed\n", DRV_NAME);
  527. }
  528. module_exit(sja1000_exit);