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 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 25)
33 /* clear statistics */
34 #define strict_strtoul simple_strtoul
36 /* this is the worst thing on the softing API
37 * 2 busses are driven together, I don't know how
38 * to recover a single of them.
39 * Therefore, when one bus is modified, the other
42 void softing_flush_echo_skb(struct softing_priv *priv)
44 can_close_cleanup(priv->netdev);
46 priv->tx.echo_put = 0;
47 priv->tx.echo_get = 0;
50 /*softing_unlocked_tx_run:*/
51 /*trigger the tx queue-ing*/
52 /*no locks are grabbed, so be sure to have the spin spinlock*/
53 static int netdev_start_xmit(struct sk_buff *skb, struct net_device *dev)
55 struct softing_priv *priv = (struct softing_priv *)dev->priv;
56 struct softing *card = priv->card;
67 spin_lock(&card->spin);
70 spin_lock_bh(&card->spin);
76 if (netif_carrier_ok(priv->netdev) <= 0) {
80 if (card->tx.pending >= TXMAX) {
84 if (priv->tx.pending >= CAN_ECHO_SKB_MAX) {
88 fifo_wr = card->dpram.tx->wr;
89 if (fifo_wr == card->dpram.tx->rd) {
94 memcpy(&msg, skb->data, sizeof(msg));
95 ptr = &card->dpram.tx->fifo[fifo_wr][0];
97 if (msg.can_id & CAN_RTR_FLAG)
99 if (msg.can_id & CAN_EFF_FLAG)
104 *ptr++ = msg.can_dlc;
105 *ptr++ = (msg.can_id >> 0);
106 *ptr++ = (msg.can_id >> 8);
107 if (msg.can_id & CAN_EFF_FLAG) {
108 *ptr++ = (msg.can_id >> 16);
109 *ptr++ = (msg.can_id >> 24);
111 /*increment 1, not 2 as you might think */
114 if (!(msg.can_id & CAN_RTR_FLAG))
115 memcpy_toio(ptr, &msg.data[0], msg.can_dlc);
117 sizeof(card->dpram.tx->fifo) /
118 sizeof(card->dpram.tx->fifo[0]))
120 card->dpram.tx->wr = fifo_wr;
124 can_put_echo_skb(skb, dev, priv->tx.echo_put);
126 if (priv->tx.echo_put >= CAN_ECHO_SKB_MAX)
127 priv->tx.echo_put = 0;
128 /* clear pointer, so don't erase later */
132 spin_unlock_bh(&card->spin);
134 spin_unlock(&card->spin);
135 if (card->tx.pending >= TXMAX) {
136 struct softing_priv *bus;
138 for (j = 0; j < card->nbus; ++j) {
142 netif_stop_queue(bus->netdev);
146 /* free skb, if not handled by the driver */
152 static int softing_dev_svc_once(struct softing *card)
155 struct softing_priv *bus;
157 struct can_frame msg;
159 unsigned int fifo_rd;
160 unsigned int cnt = 0;
161 struct net_device_stats *stats;
163 memset(&msg, 0, sizeof(msg));
164 if (card->dpram.rx->lost_msg) {
166 card->dpram.rx->lost_msg = 0;
168 msg.can_id = CAN_ERR_FLAG | CAN_ERR_CRTL;
169 msg.can_dlc = CAN_ERR_DLC;
170 msg.data[1] = CAN_ERR_CRTL_RX_OVERFLOW;
171 /*service to both busses, we don't know which one generated */
172 for (j = 0; j < card->nbus; ++j) {
176 if (!netif_carrier_ok(bus->netdev))
178 ++bus->can.can_stats.data_overrun;
179 skb = dev_alloc_skb(sizeof(msg));
182 skb->dev = bus->netdev;
183 skb->protocol = htons(ETH_P_CAN);
184 skb->ip_summed = CHECKSUM_UNNECESSARY;
185 memcpy(skb_put(skb, sizeof(msg)), &msg, sizeof(msg));
187 dev_kfree_skb_irq(skb);
189 memset(&msg, 0, sizeof(msg));
193 fifo_rd = card->dpram.rx->rd;
195 sizeof(card->dpram.rx->fifo) / sizeof(card->dpram.rx->fifo[0]))
197 if (card->dpram.rx->wr != fifo_rd) {
203 ptr = &card->dpram.rx->fifo[fifo_rd][0];
207 /*not quite usefull, probably the card has got out */
208 mod_alert("got cmd 0x%02x, I suspect the card is lost"
211 /*mod_trace("0x%02x", cmd);*/
216 stats = bus->netdev->get_stats(bus->netdev);
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;
429 mod_trace("%s", ndev->name);
430 if (mutex_lock_interruptible(&card->fw.lock))
435 , (card->bus[0] == priv) ? 1 : -1
436 , (card->bus[1] == priv) ? 1 : -1);
437 mutex_unlock(&card->fw.lock);
440 netif_start_queue(ndev);
444 static int netdev_stop(struct net_device *ndev)
446 struct softing_priv *priv = netdev_priv(ndev);
447 struct softing *card = priv->card;
450 mod_trace("%s", ndev->name);
451 netif_stop_queue(ndev);
452 netif_carrier_off(ndev);
453 softing_flush_echo_skb(priv);
454 can_close_cleanup(ndev);
455 if (mutex_lock_interruptible(&card->fw.lock))
460 , (card->bus[0] == priv) ? 0 : -1
461 , (card->bus[1] == priv) ? 0 : -1);
462 mutex_unlock(&card->fw.lock);
468 #define out_of_range(x, min, max) (((x) < min) || ((x) > max))
470 static int candev_set_bittime(struct net_device *ndev, struct can_bittime *bt)
473 case CAN_BITTIME_STD:
474 /*SJW is test via max_sjw */
475 if (out_of_range(bt->std.sjw, 1, 4))
477 if (out_of_range(bt->std.phase_seg1 + bt->std.prop_seg, 1, 16))
479 if (out_of_range(bt->std.phase_seg2, 1, 8))
481 /*BRP is test via max_brp */
482 if (ndev->flags & IFF_UP)
485 case CAN_BITTIME_BTR:
487 mod_alert("%s, type %i not supported", ndev->name, bt->type);
494 static int candev_get_state(struct net_device *ndev, enum can_state *state)
496 struct softing_priv *priv = netdev_priv(ndev);
497 mod_trace("%s", ndev->name);
498 if (priv->netdev->flags & IFF_UP)
499 *state = CAN_STATE_STOPPED;
500 else if (priv->can.state == CAN_STATE_STOPPED)
501 *state = CAN_STATE_STOPPED;
503 *state = CAN_STATE_ACTIVE;
507 static int candev_set_mode(struct net_device *ndev, enum can_mode mode)
509 struct softing_priv *priv = netdev_priv(ndev);
510 struct softing *card = priv->card;
511 mod_trace("%s %u", ndev->name, mode);
514 /*recovery from busoff? */
515 if (mutex_lock_interruptible(&card->fw.lock))
517 softing_reinit(card, -1, -1);
518 mutex_unlock(&card->fw.lock);
527 /*assume the card->lock is held*/
529 int softing_card_irq(struct softing *card, int enable)
533 if (card->irq.requested && card->irq.nr) {
534 free_irq(card->irq.nr, card);
535 card->irq.requested = 0;
539 if (!card->irq.requested && (card->irq.nr)) {
540 irqreturn_t(*fn) (int, void *);
542 flags = IRQF_DISABLED; /*| IRQF_TRIGGER_LOW; */
543 fn = dev_interrupt_nshared;
544 if (card->irq.shared) {
545 flags |= IRQF_SHARED;
546 fn = dev_interrupt_shared;
548 ret = request_irq(card->irq.nr, fn, flags, card->id.name, card);
550 mod_alert("%s, request_irq(%u) failed, %s shared"
551 , card->id.name, card->irq.nr
552 , (card->irq.shared ? "" : "not")
556 card->irq.requested = 1;
561 static void shutdown_card(struct softing *card)
564 mod_trace("%s", card->id.name);
565 if (mutex_lock_interruptible(&card->fw.lock))
566 /* return -ERESTARTSYS*/;
570 if (card->irq.requested && card->irq.nr) {
571 free_irq(card->irq.nr, card);
572 card->irq.requested = 0;
575 if (card->fn.enable_irq)
576 card->fn.enable_irq(card, 0);
578 card->fn.reset(card, 1);
580 mutex_unlock(&card->fw.lock);
581 tasklet_kill(&card->irq.bh);
584 static int boot_card(struct softing *card)
586 mod_trace("%s", card->id.name);
587 if (mutex_lock_interruptible(&card->fw.lock))
590 mutex_unlock(&card->fw.lock);
595 if (card->fn.enable_irq)
596 card->fn.enable_irq(card, 1);
599 card->fn.reset(card, 1);
601 if (card->dpram.virt) {
603 static const unsigned char stream[]
604 = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, };
605 unsigned char back[sizeof(stream)];
606 for (lp = card->dpram.virt;
607 &lp[sizeof(stream)] <= card->dpram.end;
608 lp += sizeof(stream)) {
609 memcpy_toio(lp, stream, sizeof(stream));
612 memcpy_fromio(back, lp, sizeof(stream));
614 if (memcmp(back, stream, sizeof(stream))) {
615 char line[3 * sizeof(stream)
616 / sizeof(stream[0]) + 1];
618 unsigned char *addr = lp;
619 for (lp = back; lp < &back[sizeof(stream)
620 / sizeof(stream[0])]; ++lp)
621 pline += sprintf(pline, " %02x", *lp);
623 mod_alert("write to dpram failed at 0x%p, %s"
628 /*fill dpram with 0x55 */
629 /*for (lp = card->dpram.virt; lp <= card->dpram.end; ++lp) {
636 /*load boot firmware */
637 if (softing_load_fw(card->desc->boot.fw, card, card->dpram.virt,
639 card->desc->boot.offs -
640 card->desc->boot.addr))
642 /*load load firmware */
643 if (softing_load_fw(card->desc->load.fw, card, card->dpram.virt,
645 card->desc->load.offs -
646 card->desc->load.addr))
650 card->fn.reset(card, 0);
651 if (softing_bootloader_command(card, 0, "card boot"))
653 if (softing_load_app_fw(card->desc->app.fw, card))
656 card->dpram.info->reset_rcv_fifo = 0;
657 card->dpram.info->reset = 1;
659 if (softing_fct_cmd(card, 99, 0x55, "sync-a"))
661 if (softing_fct_cmd(card, 99, 0xaa, "sync-a"))
664 if (softing_fct_cmd(card, 0, 0, "reset_chip"))
667 if (softing_fct_cmd(card, 43, 0, "get_serial_number"))
670 (u16) card->dpram.fct->param[1] +
671 (((u16) card->dpram.fct->param[2]) << 16);
673 if (softing_fct_cmd(card, 12, 0, "get_version"))
675 card->id.fw = (u16) card->dpram.fct->param[1];
676 card->id.hw = (u16) card->dpram.fct->param[2];
677 card->id.lic = (u16) card->dpram.fct->param[3];
678 card->id.chip[0] = (u16) card->dpram.fct->param[4];
679 card->id.chip[1] = (u16) card->dpram.fct->param[5];
681 mod_info("%s, card booted, "
682 "serial %u, fw %u, hw %u, lic %u, chip (%u,%u)",
683 card->id.name, card->id.serial, card->id.fw, card->id.hw,
684 card->id.lic, card->id.chip[0], card->id.chip[1]);
687 mutex_unlock(&card->fw.lock);
691 if (card->fn.enable_irq)
692 card->fn.enable_irq(card, 0);
694 card->fn.reset(card, 1);
695 mutex_unlock(&card->fw.lock);
701 /* Because the struct softing may be used by pcmcia devices
702 * as well as pci devices, * we have no clue how to get
703 * from a struct device * towards the struct softing *.
704 * It may go over a pci_device->priv or over a pcmcia_device->priv.
705 * Therefore, provide the struct softing pointer within the attribute.
706 * Then we don't need driver/bus specific things in these attributes
708 struct softing_attribute {
709 struct device_attribute dev;
710 ssize_t (*show) (struct softing *card, char *buf);
711 ssize_t (*store)(struct softing *card, const char *buf, size_t count);
712 struct softing *card;
715 static ssize_t rd_card_attr(struct device *dev, struct device_attribute *attr
717 struct softing_attribute *cattr
718 = container_of(attr, struct softing_attribute, dev);
719 return cattr->show ? cattr->show(cattr->card, buf) : 0;
721 static ssize_t wr_card_attr(struct device *dev, struct device_attribute *attr
722 , const char *buf, size_t count) {
723 struct softing_attribute *cattr
724 = container_of(attr, struct softing_attribute, dev);
725 return cattr->store ? cattr->store(cattr->card, buf, count) : 0;
728 #define declare_attr(_name, _mode, _show, _store) { \
731 .name = __stringify(_name), \
734 .show = rd_card_attr, \
735 .store = wr_card_attr, \
741 #define CARD_SHOW(name, member) \
742 static ssize_t show_##name(struct softing *card, char *buf) { \
743 return sprintf(buf, "%u\n", card->member); \
745 CARD_SHOW(serial , id.serial);
746 CARD_SHOW(firmware , id.fw);
747 CARD_SHOW(hardware , id.hw);
748 CARD_SHOW(license , id.lic);
749 CARD_SHOW(freq , id.freq);
750 CARD_SHOW(txpending , tx.pending);
752 static const struct softing_attribute card_attr_proto [] = {
753 declare_attr(serial , 0644, show_serial , 0),
754 declare_attr(firmware , 0644, show_firmware , 0),
755 declare_attr(hardware , 0644, show_hardware , 0),
756 declare_attr(license , 0644, show_license , 0),
757 declare_attr(freq , 0644, show_freq , 0),
758 declare_attr(txpending , 0644, show_txpending , 0),
761 static int mk_card_sysfs(struct softing *card)
766 size = sizeof(card_attr_proto)/sizeof(card_attr_proto[0]);
767 card->attr = kmalloc((size+1)*sizeof(card->attr[0]), GFP_KERNEL);
769 goto attr_mem_failed;
770 memcpy(card->attr, card_attr_proto, size * sizeof(card->attr[0]));
771 memset(&card->attr[size], 0, sizeof(card->attr[0]));
773 card->grp = kmalloc((size+1)*sizeof(card->grp [0]), GFP_KERNEL);
777 for (j = 0; j < size; ++j) {
778 card->attr[j].card = card;
779 card->grp[j] = &card->attr[j].dev.attr;
780 if (!card->attr[j].show)
781 card->attr[j].dev.attr.mode &= ~(S_IRUGO);
782 if (!card->attr[j].store)
783 card->attr[j].dev.attr.mode &= ~(S_IWUGO);
786 card->sysfs.name = "softing";
787 card->sysfs.attrs = card->grp;
788 if (sysfs_create_group(&card->dev->kobj, &card->sysfs) < 0)
800 static void rm_card_sysfs(struct softing *card)
802 sysfs_remove_group(&card->dev->kobj, &card->sysfs);
807 static ssize_t show_chip(struct device *dev
808 , struct device_attribute *attr, char *buf)
810 struct net_device *ndev = to_net_dev(dev);
811 struct softing_priv *priv = netdev2softing(ndev);
812 return sprintf(buf, "%i\n", priv->chip);
815 static ssize_t show_output(struct device *dev
816 , struct device_attribute *attr, char *buf)
818 struct net_device *ndev = to_net_dev(dev);
819 struct softing_priv *priv = netdev2softing(ndev);
820 return sprintf(buf, "0x%02x\n", priv->output);
823 static ssize_t store_output(struct device *dev
824 , struct device_attribute *attr
825 , const char *buf, size_t count)
827 struct net_device *ndev = to_net_dev(dev);
828 struct softing_priv *priv = netdev2softing(ndev);
829 struct softing *card = priv->card;
831 int v = strict_strtol(buf, 0, 0);
833 if (mutex_lock_interruptible(&card->fw.lock))
835 if (ndev->flags & IFF_UP) {
837 /* we will need a restart */
838 for (j = 0; j < card->nbus; ++j) {
839 if (j == priv->index)
842 if (card->bus[j]->netdev->flags & IFF_UP) {
843 mutex_unlock(&card->fw.lock);
848 softing_reinit(card, -1, -1);
852 mutex_unlock(&card->fw.lock);
856 * the latest softing cards support sleep mode too
859 static const DEVICE_ATTR(chip, S_IRUGO, show_chip, 0);
860 static const DEVICE_ATTR(output, S_IRUGO | S_IWUSR, show_output, store_output);
862 static const struct attribute *const netdev_sysfs_entries [] = {
863 &dev_attr_chip .attr,
864 &dev_attr_output .attr,
867 static const struct attribute_group netdev_sysfs = {
869 .attrs = (struct attribute **)netdev_sysfs_entries,
872 static int mk_netdev_sysfs(struct softing_priv *priv)
874 if (!priv->netdev->dev.kobj.sd) {
875 mod_alert("sysfs_create_group would fail");
878 return sysfs_create_group(&priv->netdev->dev.kobj, &netdev_sysfs);
880 static void rm_netdev_sysfs(struct softing_priv *priv)
882 sysfs_remove_group(&priv->netdev->dev.kobj, &netdev_sysfs);
885 static struct softing_priv *mk_netdev(struct softing *card, u16 chip_id)
887 struct net_device *ndev;
888 struct softing_priv *priv;
890 ndev = alloc_candev(sizeof(*priv));
892 mod_alert("alloc_candev failed");
895 priv = netdev_priv(ndev);
898 priv->can.can_sys_clock = 8000000UL;
899 priv->can.max_brp = card->desc->max_brp;
900 priv->can.max_sjw = card->desc->max_sjw;
902 priv->chip = chip_id;
903 priv->output = softing_default_output(card, priv);
904 SET_NETDEV_DEV(ndev, card->dev);
906 ndev->flags |= IFF_ECHO;
907 ndev->open = netdev_open;
908 ndev->stop = netdev_stop;
909 ndev->hard_start_xmit = netdev_start_xmit;
910 priv->can.do_set_bittime = candev_set_bittime;
911 priv->can.do_get_state = candev_get_state;
912 priv->can.do_set_mode = candev_set_mode;
914 if (can_set_bitrate(ndev, 250000UL))
915 mod_alert("bitrate failed");
920 static void rm_netdev(struct softing_priv *priv)
922 free_candev(priv->netdev);
925 static int reg_netdev(struct softing_priv *priv)
928 netif_carrier_off(priv->netdev);
929 ret = register_netdev(priv->netdev);
931 mod_alert("%s, register failed", priv->card->id.name);
934 ret = mk_netdev_sysfs(priv);
936 mod_alert("%s, sysfs failed", priv->card->id.name);
941 unregister_netdev(priv->netdev);
946 static void unreg_netdev(struct softing_priv *priv)
948 rm_netdev_sysfs(priv);
949 unregister_netdev(priv->netdev);
952 void rm_softing(struct softing *card)
956 /*first, disable card*/
959 for (j = 0; j < card->nbus; ++j) {
960 unreg_netdev(card->bus[j]);
961 rm_netdev(card->bus[j]);
966 iounmap(card->dpram.virt);
968 EXPORT_SYMBOL(rm_softing);
970 int mk_softing(struct softing *card)
974 /* try_module_get(THIS_MODULE); */
975 mutex_init(&card->fw.lock);
976 spin_lock_init(&card->spin);
977 tasklet_init(&card->irq.bh, softing_dev_svc, (unsigned long)card);
979 card->desc = softing_lookup_desc(card->id.manf, card->id.prod);
981 mod_alert("0x%04x:0x%04x not supported\n", card->id.manf,
985 card->id.name = card->desc->name;
986 mod_trace("can (%s)", card->id.name);
988 card->dpram.virt = ioremap(card->dpram.phys, card->dpram.size);
989 if (!card->dpram.virt) {
990 mod_alert("dpram ioremap failed\n");
994 card->dpram.size = card->desc->dpram_size;
995 card->dpram.end = &card->dpram.virt[card->dpram.size];
996 /*initialize_board */
997 card->dpram.rx = (struct softing_rx *)&card->dpram.virt[0x0000];
998 card->dpram.tx = (struct softing_tx *)&card->dpram.virt[0x0400];
999 card->dpram.fct = (struct softing_fct *)&card->dpram.virt[0x0300];
1000 card->dpram.info = (struct softing_info *)&card->dpram.virt[0x0330];
1001 card->dpram.command = (unsigned short *)&card->dpram.virt[0x07e0];
1002 card->dpram.receipt = (unsigned short *)&card->dpram.virt[0x07f0];
1003 card->dpram.irq = (struct softing_irq *)&card->dpram.virt[0x07fe];
1007 card->fn.reset(card, 1);
1008 if (boot_card(card)) {
1009 mod_alert("%s, failed to boot", card->id.name);
1013 /*only now, the chip's are known */
1014 card->id.freq = card->desc->freq * 1000000UL;
1016 if (mk_card_sysfs(card)) {
1017 mod_alert("%s, sysfs failed", card->id.name);
1021 if (card->nbus > (sizeof(card->bus) / sizeof(card->bus[0]))) {
1022 card->nbus = sizeof(card->bus) / sizeof(card->bus[0]);
1023 mod_alert("%s, going for %u busses", card->id.name, card->nbus);
1026 for (j = 0; j < card->nbus; ++j) {
1027 card->bus[j] = mk_netdev(card, card->id.chip[j]);
1028 if (!card->bus[j]) {
1029 mod_alert("%s: failed to make can[%i]", card->id.name,
1033 card->bus[j]->index = j;
1035 for (j = 0; j < card->nbus; ++j) {
1036 if (reg_netdev(card->bus[j])) {
1037 mod_alert("%s: failed to register can[%i]",
1042 mod_trace("card initialised");
1046 for (j = 0; j < card->nbus; ++j)
1047 unreg_netdev(card->bus[j]);
1049 for (j = 0; j < card->nbus; ++j) {
1051 rm_netdev(card->bus[j]);
1053 rm_card_sysfs(card);
1055 shutdown_card(card);
1057 iounmap(card->dpram.virt);
1058 card->dpram.virt = 0;
1059 card->dpram.end = 0;
1062 tasklet_kill(&card->irq.bh);
1065 EXPORT_SYMBOL(mk_softing);
1067 static int __init mod_start(void)
1073 static void __exit mod_stop(void)
1078 module_init(mod_start);
1079 module_exit(mod_stop);
1081 MODULE_DESCRIPTION("socketcan softing driver");
1082 MODULE_AUTHOR("Kurt Van Dijck <kurt.van.dijck@eia.be>");
1083 MODULE_LICENSE("GPL");
1085 int softing_debug = 1;
1086 EXPORT_SYMBOL(softing_debug);
1087 module_param(softing_debug, int , S_IRUGO | S_IWUSR | S_IWGRP);
1088 MODULE_PARM_DESC(softing_debug, "trace softing functions");