2 * drivers/net/can/softing/softing_main.c
6 * - Kurt Van Dijck, EIA Electronics
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the version 2 of the GNU General Public License
10 * as published by the Free Software Foundation
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include <linux/module.h>
23 #include <linux/init.h>
24 #include <linux/device.h>
25 #include <linux/firmware.h>
26 #include <linux/interrupt.h>
27 #include <linux/mutex.h>
32 /* this is the worst thing on the softing API
33 * 2 busses are driven together, I don't know how
34 * to recover a single of them.
35 * Therefore, when one bus is modified, the other
38 void softing_flush_echo_skb(struct softing_priv *priv)
40 can_close_cleanup(priv->netdev);
42 priv->tx.echo_put = 0;
43 priv->tx.echo_get = 0;
46 /*softing_unlocked_tx_run:*/
47 /*trigger the tx queue-ing*/
48 /*no locks are grabbed, so be sure to have the spin spinlock*/
49 static int netdev_start_xmit(struct sk_buff *skb, struct net_device *dev)
51 struct softing_priv *priv = (struct softing_priv *)netdev_priv(dev);
52 struct softing *card = priv->card;
63 spin_lock(&card->spin);
66 spin_lock_bh(&card->spin);
72 if (netif_carrier_ok(priv->netdev) <= 0) {
76 if (card->tx.pending >= TXMAX) {
80 if (priv->tx.pending >= CAN_ECHO_SKB_MAX) {
84 fifo_wr = card->dpram.tx->wr;
85 if (fifo_wr == card->dpram.tx->rd) {
90 memcpy(&msg, skb->data, sizeof(msg));
91 ptr = &card->dpram.tx->fifo[fifo_wr][0];
93 if (msg.can_id & CAN_RTR_FLAG)
95 if (msg.can_id & CAN_EFF_FLAG)
100 *ptr++ = msg.can_dlc;
101 *ptr++ = (msg.can_id >> 0);
102 *ptr++ = (msg.can_id >> 8);
103 if (msg.can_id & CAN_EFF_FLAG) {
104 *ptr++ = (msg.can_id >> 16);
105 *ptr++ = (msg.can_id >> 24);
107 /*increment 1, not 2 as you might think */
110 if (!(msg.can_id & CAN_RTR_FLAG))
111 memcpy_toio(ptr, &msg.data[0], msg.can_dlc);
113 sizeof(card->dpram.tx->fifo) /
114 sizeof(card->dpram.tx->fifo[0]))
116 card->dpram.tx->wr = fifo_wr;
120 can_put_echo_skb(skb, dev, priv->tx.echo_put);
122 if (priv->tx.echo_put >= CAN_ECHO_SKB_MAX)
123 priv->tx.echo_put = 0;
124 /* clear pointer, so don't erase later */
128 spin_unlock_bh(&card->spin);
130 spin_unlock(&card->spin);
131 if (card->tx.pending >= TXMAX) {
132 struct softing_priv *bus;
134 for (j = 0; j < card->nbus; ++j) {
138 netif_stop_queue(bus->netdev);
142 /* free skb, if not handled by the driver */
148 static int softing_dev_svc_once(struct softing *card)
151 struct softing_priv *bus;
153 struct can_frame msg;
155 unsigned int fifo_rd;
156 unsigned int cnt = 0;
157 struct net_device_stats *stats;
159 memset(&msg, 0, sizeof(msg));
160 if (card->dpram.rx->lost_msg) {
162 card->dpram.rx->lost_msg = 0;
164 msg.can_id = CAN_ERR_FLAG | CAN_ERR_CRTL;
165 msg.can_dlc = CAN_ERR_DLC;
166 msg.data[1] = CAN_ERR_CRTL_RX_OVERFLOW;
167 /*service to both busses, we don't know which one generated */
168 for (j = 0; j < card->nbus; ++j) {
172 if (!netif_carrier_ok(bus->netdev))
174 ++bus->can.can_stats.data_overrun;
175 skb = dev_alloc_skb(sizeof(msg));
178 skb->dev = bus->netdev;
179 skb->protocol = htons(ETH_P_CAN);
180 skb->ip_summed = CHECKSUM_UNNECESSARY;
181 memcpy(skb_put(skb, sizeof(msg)), &msg, sizeof(msg));
183 dev_kfree_skb_irq(skb);
185 memset(&msg, 0, sizeof(msg));
189 fifo_rd = card->dpram.rx->rd;
191 sizeof(card->dpram.rx->fifo) / sizeof(card->dpram.rx->fifo[0]))
193 if (card->dpram.rx->wr != fifo_rd) {
199 ptr = &card->dpram.rx->fifo[fifo_rd][0];
203 /*not quite usefull, probably the card has got out */
204 mod_alert("got cmd 0x%02x, I suspect the card is lost"
207 /*mod_trace("0x%02x", cmd);*/
212 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,23)
213 stats = can_get_stats(bus->netdev);
215 stats = &bus->netdev->stats;
222 msg.can_id = CAN_ERR_FLAG;
223 msg.can_dlc = CAN_ERR_DLC;
226 can_state = CAN_STATE_BUS_OFF;
227 msg.can_id |= CAN_ERR_BUSOFF;
229 } else if (state & 0x60) {
230 can_state = CAN_STATE_BUS_PASSIVE;
231 msg.can_id |= CAN_ERR_BUSERROR;
234 can_state = CAN_STATE_ACTIVE;
240 card->dpram.info->bus_state = state;
242 card->dpram.info->bus_state2 = state;
249 /*msg.time = */ softing_time2usec(card, tmp);
250 /*trigger dual port RAM */
252 card->dpram.rx->rd = fifo_rd;
253 /*update internal status */
254 if (can_state != bus->can.state) {
255 bus->can.state = can_state;
257 bus->can.can_stats.error_passive += 1;
259 bus->can.can_stats.bus_error += 1;
261 /*trigger socketcan */
263 /* this calls can_close_cleanup() */
264 softing_flush_echo_skb(bus);
265 can_bus_off(bus->netdev);
266 netif_stop_queue(bus->netdev);
268 if ((state == CAN_STATE_BUS_OFF)
269 || (state == CAN_STATE_BUS_PASSIVE)) {
270 skb = dev_alloc_skb(sizeof(msg));
273 skb->dev = bus->netdev;
274 skb->protocol = htons(ETH_P_CAN);
275 skb->ip_summed = CHECKSUM_UNNECESSARY;
276 memcpy(skb_put(skb, sizeof(msg)), &msg,
279 dev_kfree_skb_irq(skb);
283 msg.can_id |= CAN_RTR_FLAG;
284 /* acknowledge, was tx msg
285 * no real tx flag to set
289 msg.can_dlc = *ptr++;
293 msg.can_id |= CAN_EFF_FLAG;
301 msg.can_id |= (ptr[0] << 0) | (ptr[1] << 8);
309 /*msg.time = */ softing_time2usec(card, tmp);
310 memcpy_fromio(&msg.data[0], ptr, 8);
312 /*trigger dual port RAM */
314 card->dpram.rx->rd = fifo_rd;
317 can_get_echo_skb(bus->netdev, bus->tx.echo_get);
319 if (bus->tx.echo_get >= CAN_ECHO_SKB_MAX)
320 bus->tx.echo_get = 0;
323 if (card->tx.pending)
325 stats->tx_packets += 1;
326 stats->tx_bytes += msg.can_dlc;
328 stats->rx_packets += 1;
329 stats->rx_bytes += msg.can_dlc;
330 bus->netdev->last_rx = jiffies;
331 skb = dev_alloc_skb(sizeof(msg));
333 skb->dev = bus->netdev;
334 skb->protocol = htons(ETH_P_CAN);
335 skb->ip_summed = CHECKSUM_UNNECESSARY;
336 memcpy(skb_put(skb, sizeof(msg)), &msg,
339 dev_kfree_skb_irq(skb);
348 static void softing_dev_svc(unsigned long param)
350 struct softing *card = (struct softing *)param;
351 struct softing_priv *bus;
355 spin_lock(&card->spin);
356 while (softing_dev_svc_once(card) > 0)
357 ++card->irq.svc_count;
358 /*resume tx queue's */
359 offset = card->tx.last_bus;
360 for (j = 0; j < card->nbus; ++j) {
361 if (card->tx.pending >= TXMAX)
363 bus = card->bus[(j + offset) % card->nbus];
364 if (netif_carrier_ok(bus->netdev))
365 netif_wake_queue(bus->netdev);
367 spin_unlock(&card->spin);
370 static void card_seems_down(struct softing *card)
372 /* free interrupt, but probably
373 * in wrong (interrupt) context
374 if (card->irq.requested) {
375 free_irq(card->irq.nr, card);
376 card->irq.requested = 0;
380 mod_alert("I think the card is vanished");
384 irqreturn_t dev_interrupt_shared(int irq, void *dev_id)
386 struct softing *card = (struct softing *)dev_id;
388 ir = card->dpram.virt[0xe02];
389 card->dpram.virt[0xe02] = 0;
390 if (card->dpram.rx->rd == 0xffff) {
391 card_seems_down(card);
395 tasklet_schedule(&card->irq.bh);
397 } else if (ir == 0x10) {
405 irqreturn_t dev_interrupt_nshared(int irq, void *dev_id)
407 struct softing *card = (struct softing *)dev_id;
408 unsigned char irq_host;
409 irq_host = card->dpram.irq->to_host;
410 /* make sure we have a copy, before clearing the variable in DPRAM */
412 card->dpram.irq->to_host = 0;
413 /* make sure we cleared it */
415 mod_trace("0x%02x", irq_host);
416 if (card->dpram.rx->rd == 0xffff) {
417 card_seems_down(card);
420 tasklet_schedule(&card->irq.bh);
424 static int netdev_open(struct net_device *ndev)
426 struct softing_priv *priv = netdev_priv(ndev);
427 struct softing *card = priv->card;
431 mod_trace("%s", ndev->name);
432 /* determine and set bittime */
433 ret = can_set_bittiming(ndev);
436 if (mutex_lock_interruptible(&card->fw.lock))
441 , (card->bus[0] == priv) ? 1 : -1
442 , (card->bus[1] == priv) ? 1 : -1);
443 mutex_unlock(&card->fw.lock);
446 netif_start_queue(ndev);
450 static int netdev_stop(struct net_device *ndev)
452 struct softing_priv *priv = netdev_priv(ndev);
453 struct softing *card = priv->card;
456 mod_trace("%s", ndev->name);
457 netif_stop_queue(ndev);
458 netif_carrier_off(ndev);
459 softing_flush_echo_skb(priv);
460 can_close_cleanup(ndev);
461 if (mutex_lock_interruptible(&card->fw.lock))
466 , (card->bus[0] == priv) ? 0 : -1
467 , (card->bus[1] == priv) ? 0 : -1);
468 mutex_unlock(&card->fw.lock);
474 static int candev_get_state(struct net_device *ndev, enum can_state *state)
476 struct softing_priv *priv = netdev_priv(ndev);
477 mod_trace("%s", ndev->name);
478 if (priv->netdev->flags & IFF_UP)
479 *state = CAN_STATE_STOPPED;
480 else if (priv->can.state == CAN_STATE_STOPPED)
481 *state = CAN_STATE_STOPPED;
483 *state = CAN_STATE_ACTIVE;
487 static int candev_set_mode(struct net_device *ndev, enum can_mode mode)
489 struct softing_priv *priv = netdev_priv(ndev);
490 struct softing *card = priv->card;
491 mod_trace("%s %u", ndev->name, mode);
494 /*recovery from busoff? */
495 if (mutex_lock_interruptible(&card->fw.lock))
497 softing_reinit(card, -1, -1);
498 mutex_unlock(&card->fw.lock);
507 /*assume the card->lock is held*/
509 int softing_card_irq(struct softing *card, int enable)
513 if (card->irq.requested && card->irq.nr) {
514 free_irq(card->irq.nr, card);
515 card->irq.requested = 0;
519 if (!card->irq.requested && (card->irq.nr)) {
520 irqreturn_t(*fn) (int, void *);
522 flags = IRQF_DISABLED | IRQF_SHARED;/*| IRQF_TRIGGER_LOW; */
523 fn = dev_interrupt_nshared;
524 if (card->desc->generation >= 2)
525 fn = dev_interrupt_shared;
526 ret = request_irq(card->irq.nr, fn, flags, card->id.name, card);
528 mod_alert("%s, request_irq(%u) failed"
529 , card->id.name, card->irq.nr
533 card->irq.requested = 1;
538 static void shutdown_card(struct softing *card)
541 mod_trace("%s", card->id.name);
542 if (mutex_lock_interruptible(&card->fw.lock))
543 /* return -ERESTARTSYS*/;
547 if (card->irq.requested && card->irq.nr) {
548 free_irq(card->irq.nr, card);
549 card->irq.requested = 0;
552 if (card->fn.enable_irq)
553 card->fn.enable_irq(card, 0);
555 card->fn.reset(card, 1);
557 mutex_unlock(&card->fw.lock);
558 tasklet_kill(&card->irq.bh);
561 static int boot_card(struct softing *card)
563 mod_trace("%s", card->id.name);
564 if (mutex_lock_interruptible(&card->fw.lock))
567 mutex_unlock(&card->fw.lock);
572 if (card->fn.enable_irq)
573 card->fn.enable_irq(card, 1);
576 card->fn.reset(card, 1);
578 if (card->dpram.virt) {
580 static const unsigned char stream[]
581 = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, };
582 unsigned char back[sizeof(stream)];
583 for (lp = card->dpram.virt;
584 &lp[sizeof(stream)] <= card->dpram.end;
585 lp += sizeof(stream)) {
586 memcpy_toio(lp, stream, sizeof(stream));
589 memcpy_fromio(back, lp, sizeof(stream));
591 if (memcmp(back, stream, sizeof(stream))) {
592 char line[3 * sizeof(stream)
593 / sizeof(stream[0]) + 1];
595 unsigned char *addr = lp;
596 for (lp = back; lp < &back[sizeof(stream)
597 / sizeof(stream[0])]; ++lp)
598 pline += sprintf(pline, " %02x", *lp);
600 mod_alert("write to dpram failed at 0x%p, %s"
605 /*fill dpram with 0x55 */
606 /*for (lp = card->dpram.virt; lp <= card->dpram.end; ++lp) {
613 /*load boot firmware */
614 if (softing_load_fw(card->desc->boot.fw, card, card->dpram.virt,
616 card->desc->boot.offs -
617 card->desc->boot.addr))
619 /*load load firmware */
620 if (softing_load_fw(card->desc->load.fw, card, card->dpram.virt,
622 card->desc->load.offs -
623 card->desc->load.addr))
627 card->fn.reset(card, 0);
628 if (softing_bootloader_command(card, 0, "card boot"))
630 if (softing_load_app_fw(card->desc->app.fw, card))
633 card->dpram.info->reset_rcv_fifo = 0;
634 card->dpram.info->reset = 1;
636 if (softing_fct_cmd(card, 99, 0x55, "sync-a"))
638 if (softing_fct_cmd(card, 99, 0xaa, "sync-a"))
641 if (softing_fct_cmd(card, 0, 0, "reset_chip"))
644 if (softing_fct_cmd(card, 43, 0, "get_serial_number"))
647 (u16) card->dpram.fct->param[1] +
648 (((u16) card->dpram.fct->param[2]) << 16);
650 if (softing_fct_cmd(card, 12, 0, "get_version"))
652 card->id.fw = (u16) card->dpram.fct->param[1];
653 card->id.hw = (u16) card->dpram.fct->param[2];
654 card->id.lic = (u16) card->dpram.fct->param[3];
655 card->id.chip[0] = (u16) card->dpram.fct->param[4];
656 card->id.chip[1] = (u16) card->dpram.fct->param[5];
658 mod_info("%s, card booted, "
659 "serial %u, fw %u, hw %u, lic %u, chip (%u,%u)",
660 card->id.name, card->id.serial, card->id.fw, card->id.hw,
661 card->id.lic, card->id.chip[0], card->id.chip[1]);
664 mutex_unlock(&card->fw.lock);
668 if (card->fn.enable_irq)
669 card->fn.enable_irq(card, 0);
671 card->fn.reset(card, 1);
672 mutex_unlock(&card->fw.lock);
678 /* Because the struct softing may be used by pcmcia devices
679 * as well as pci devices, * we have no clue how to get
680 * from a struct device * towards the struct softing *.
681 * It may go over a pci_device->priv or over a pcmcia_device->priv.
682 * Therefore, provide the struct softing pointer within the attribute.
683 * Then we don't need driver/bus specific things in these attributes
685 struct softing_attribute {
686 struct device_attribute dev;
687 ssize_t (*show) (struct softing *card, char *buf);
688 ssize_t (*store)(struct softing *card, const char *buf, size_t count);
689 struct softing *card;
692 static ssize_t rd_card_attr(struct device *dev, struct device_attribute *attr
694 struct softing_attribute *cattr
695 = container_of(attr, struct softing_attribute, dev);
696 return cattr->show ? cattr->show(cattr->card, buf) : 0;
698 static ssize_t wr_card_attr(struct device *dev, struct device_attribute *attr
699 , const char *buf, size_t count) {
700 struct softing_attribute *cattr
701 = container_of(attr, struct softing_attribute, dev);
702 return cattr->store ? cattr->store(cattr->card, buf, count) : 0;
705 #define declare_attr(_name, _mode, _show, _store) { \
708 .name = __stringify(_name), \
711 .show = rd_card_attr, \
712 .store = wr_card_attr, \
718 #define CARD_SHOW(name, member) \
719 static ssize_t show_##name(struct softing *card, char *buf) { \
720 return sprintf(buf, "%u\n", card->member); \
722 CARD_SHOW(serial , id.serial);
723 CARD_SHOW(firmware , id.fw);
724 CARD_SHOW(hardware , id.hw);
725 CARD_SHOW(license , id.lic);
726 CARD_SHOW(freq , id.freq);
727 CARD_SHOW(txpending , tx.pending);
729 static const struct softing_attribute card_attr_proto [] = {
730 declare_attr(serial , 0444, show_serial , 0),
731 declare_attr(firmware , 0444, show_firmware , 0),
732 declare_attr(hardware , 0444, show_hardware , 0),
733 declare_attr(license , 0444, show_license , 0),
734 declare_attr(freq , 0444, show_freq , 0),
735 declare_attr(txpending , 0644, show_txpending , 0),
738 static int mk_card_sysfs(struct softing *card)
743 size = sizeof(card_attr_proto)/sizeof(card_attr_proto[0]);
744 card->attr = kmalloc((size+1)*sizeof(card->attr[0]), GFP_KERNEL);
746 goto attr_mem_failed;
747 memcpy(card->attr, card_attr_proto, size * sizeof(card->attr[0]));
748 memset(&card->attr[size], 0, sizeof(card->attr[0]));
750 card->grp = kmalloc((size+1)*sizeof(card->grp [0]), GFP_KERNEL);
754 for (j = 0; j < size; ++j) {
755 card->attr[j].card = card;
756 card->grp[j] = &card->attr[j].dev.attr;
757 if (!card->attr[j].show)
758 card->attr[j].dev.attr.mode &= ~(S_IRUGO);
759 if (!card->attr[j].store)
760 card->attr[j].dev.attr.mode &= ~(S_IWUGO);
763 card->sysfs.name = "softing";
764 card->sysfs.attrs = card->grp;
765 if (sysfs_create_group(&card->dev->kobj, &card->sysfs) < 0)
777 static void rm_card_sysfs(struct softing *card)
779 sysfs_remove_group(&card->dev->kobj, &card->sysfs);
784 static ssize_t show_chip(struct device *dev
785 , struct device_attribute *attr, char *buf)
787 struct net_device *ndev = to_net_dev(dev);
788 struct softing_priv *priv = netdev2softing(ndev);
789 return sprintf(buf, "%i\n", priv->chip);
792 static ssize_t show_output(struct device *dev
793 , struct device_attribute *attr, char *buf)
795 struct net_device *ndev = to_net_dev(dev);
796 struct softing_priv *priv = netdev2softing(ndev);
797 return sprintf(buf, "0x%02x\n", priv->output);
800 static ssize_t store_output(struct device *dev
801 , struct device_attribute *attr
802 , const char *buf, size_t count)
804 struct net_device *ndev = to_net_dev(dev);
805 struct softing_priv *priv = netdev2softing(ndev);
806 struct softing *card = priv->card;
808 u8 v = simple_strtoul(buf, NULL, 10) & 0xFFU;
810 if (mutex_lock_interruptible(&card->fw.lock))
812 if (ndev->flags & IFF_UP) {
814 /* we will need a restart */
815 for (j = 0; j < card->nbus; ++j) {
816 if (j == priv->index)
819 if (card->bus[j]->netdev->flags & IFF_UP) {
820 mutex_unlock(&card->fw.lock);
825 softing_reinit(card, -1, -1);
829 mutex_unlock(&card->fw.lock);
833 * the latest softing cards support sleep mode too
836 static const DEVICE_ATTR(chip, S_IRUGO, show_chip, 0);
837 static const DEVICE_ATTR(output, S_IRUGO | S_IWUSR, show_output, store_output);
839 static const struct attribute *const netdev_sysfs_entries [] = {
840 &dev_attr_chip .attr,
841 &dev_attr_output .attr,
844 static const struct attribute_group netdev_sysfs = {
846 .attrs = (struct attribute **)netdev_sysfs_entries,
849 static int mk_netdev_sysfs(struct softing_priv *priv)
851 if (!priv->netdev->dev.kobj.sd) {
852 mod_alert("sysfs_create_group would fail");
855 return sysfs_create_group(&priv->netdev->dev.kobj, &netdev_sysfs);
857 static void rm_netdev_sysfs(struct softing_priv *priv)
859 sysfs_remove_group(&priv->netdev->dev.kobj, &netdev_sysfs);
862 static struct softing_priv *mk_netdev(struct softing *card, u16 chip_id)
864 struct net_device *ndev;
865 struct softing_priv *priv;
867 ndev = alloc_candev(sizeof(*priv));
869 mod_alert("alloc_candev failed");
872 priv = netdev_priv(ndev);
875 memcpy(&priv->btr_const, &softing_btr_const, sizeof(priv->btr_const));
876 priv->btr_const.brp_max = card->desc->max_brp;
877 priv->btr_const.sjw_max = card->desc->max_sjw;
878 priv->can.bittiming_const = &priv->btr_const;
879 priv->can.bittiming.clock = 8000000;
880 priv->chip = chip_id;
881 priv->output = softing_default_output(card, priv);
882 SET_NETDEV_DEV(ndev, card->dev);
884 ndev->flags |= IFF_ECHO;
885 ndev->open = netdev_open;
886 ndev->stop = netdev_stop;
887 ndev->hard_start_xmit = netdev_start_xmit;
888 priv->can.do_get_state = candev_get_state;
889 priv->can.do_set_mode = candev_set_mode;
894 static void rm_netdev(struct softing_priv *priv)
896 free_candev(priv->netdev);
899 static int reg_netdev(struct softing_priv *priv)
902 netif_carrier_off(priv->netdev);
903 ret = register_netdev(priv->netdev);
905 mod_alert("%s, register failed", priv->card->id.name);
908 ret = mk_netdev_sysfs(priv);
910 mod_alert("%s, sysfs failed", priv->card->id.name);
915 unregister_netdev(priv->netdev);
920 static void unreg_netdev(struct softing_priv *priv)
922 rm_netdev_sysfs(priv);
923 unregister_netdev(priv->netdev);
926 void rm_softing(struct softing *card)
930 /*first, disable card*/
933 for (j = 0; j < card->nbus; ++j) {
934 unreg_netdev(card->bus[j]);
935 rm_netdev(card->bus[j]);
940 iounmap(card->dpram.virt);
942 EXPORT_SYMBOL(rm_softing);
944 int mk_softing(struct softing *card)
948 /* try_module_get(THIS_MODULE); */
949 mutex_init(&card->fw.lock);
950 spin_lock_init(&card->spin);
951 tasklet_init(&card->irq.bh, softing_dev_svc, (unsigned long)card);
953 card->desc = softing_lookup_desc(card->id.manf, card->id.prod);
955 mod_alert("0x%04x:0x%04x not supported\n", card->id.manf,
959 card->id.name = card->desc->name;
960 mod_trace("can (%s)", card->id.name);
962 card->dpram.virt = ioremap(card->dpram.phys, card->dpram.size);
963 if (!card->dpram.virt) {
964 mod_alert("dpram ioremap failed\n");
968 card->dpram.size = card->desc->dpram_size;
969 card->dpram.end = &card->dpram.virt[card->dpram.size];
970 /*initialize_board */
971 card->dpram.rx = (struct softing_rx *)&card->dpram.virt[0x0000];
972 card->dpram.tx = (struct softing_tx *)&card->dpram.virt[0x0400];
973 card->dpram.fct = (struct softing_fct *)&card->dpram.virt[0x0300];
974 card->dpram.info = (struct softing_info *)&card->dpram.virt[0x0330];
975 card->dpram.command = (unsigned short *)&card->dpram.virt[0x07e0];
976 card->dpram.receipt = (unsigned short *)&card->dpram.virt[0x07f0];
977 card->dpram.irq = (struct softing_irq *)&card->dpram.virt[0x07fe];
981 card->fn.reset(card, 1);
982 if (boot_card(card)) {
983 mod_alert("%s, failed to boot", card->id.name);
987 /*only now, the chip's are known */
988 card->id.freq = card->desc->freq * 1000000UL;
990 if (mk_card_sysfs(card)) {
991 mod_alert("%s, sysfs failed", card->id.name);
995 if (card->nbus > (sizeof(card->bus) / sizeof(card->bus[0]))) {
996 card->nbus = sizeof(card->bus) / sizeof(card->bus[0]);
997 mod_alert("%s, going for %u busses", card->id.name, card->nbus);
1000 for (j = 0; j < card->nbus; ++j) {
1001 card->bus[j] = mk_netdev(card, card->id.chip[j]);
1002 if (!card->bus[j]) {
1003 mod_alert("%s: failed to make can[%i]", card->id.name,
1007 card->bus[j]->index = j;
1009 for (j = 0; j < card->nbus; ++j) {
1010 if (reg_netdev(card->bus[j])) {
1011 mod_alert("%s: failed to register can[%i]",
1016 mod_trace("card initialised");
1020 for (j = 0; j < card->nbus; ++j)
1021 unreg_netdev(card->bus[j]);
1023 for (j = 0; j < card->nbus; ++j) {
1025 rm_netdev(card->bus[j]);
1027 rm_card_sysfs(card);
1029 shutdown_card(card);
1031 iounmap(card->dpram.virt);
1032 card->dpram.virt = 0;
1033 card->dpram.end = 0;
1036 tasklet_kill(&card->irq.bh);
1039 EXPORT_SYMBOL(mk_softing);
1041 static int __init mod_start(void)
1047 static void __exit mod_stop(void)
1052 module_init(mod_start);
1053 module_exit(mod_stop);
1055 MODULE_DESCRIPTION("socketcan softing driver");
1056 MODULE_AUTHOR("Kurt Van Dijck <kurt.van.dijck@eia.be>");
1057 MODULE_LICENSE("GPL");
1059 int softing_debug = 1;
1060 EXPORT_SYMBOL(softing_debug);
1061 module_param(softing_debug, int , S_IRUGO | S_IWUSR | S_IWGRP);
1062 MODULE_PARM_DESC(softing_debug, "trace softing functions");