arcnet.c (00778f7cadd393630a23e83ffaf60b70fe460879) arcnet.c (05fcd31cc472c5da6416d3bc2ab25599bbb9331f)
1/*
2 * Linux ARCnet driver - device-independent routines
3 *
4 * Written 1997 by David Woodhouse.
5 * Written 1994-1999 by Avery Pennarun.
6 * Written 1999-2000 by Martin Mares <mj@ucw.cz>.
7 * Derived from skeleton.c by Donald Becker.
8 *

--- 37 unchanged lines hidden (view full) ---

46#include <linux/module.h>
47#include <linux/types.h>
48#include <linux/delay.h>
49#include <linux/netdevice.h>
50#include <linux/if_arp.h>
51#include <net/arp.h>
52#include <linux/init.h>
53#include <linux/jiffies.h>
1/*
2 * Linux ARCnet driver - device-independent routines
3 *
4 * Written 1997 by David Woodhouse.
5 * Written 1994-1999 by Avery Pennarun.
6 * Written 1999-2000 by Martin Mares <mj@ucw.cz>.
7 * Derived from skeleton.c by Donald Becker.
8 *

--- 37 unchanged lines hidden (view full) ---

46#include <linux/module.h>
47#include <linux/types.h>
48#include <linux/delay.h>
49#include <linux/netdevice.h>
50#include <linux/if_arp.h>
51#include <net/arp.h>
52#include <linux/init.h>
53#include <linux/jiffies.h>
54#include <linux/errqueue.h>
54
55#include <linux/leds.h>
56
57#include "arcdevice.h"
58#include "com9026.h"
59
60/* "do nothing" functions for protocol drivers */
61static void null_rx(struct net_device *dev, int bufnum,

--- 324 unchanged lines hidden (view full) ---

386 struct net_device *dev = (struct net_device *)data;
387
388 if (!netif_carrier_ok(dev)) {
389 netif_carrier_on(dev);
390 netdev_info(dev, "link up\n");
391 }
392}
393
55
56#include <linux/leds.h>
57
58#include "arcdevice.h"
59#include "com9026.h"
60
61/* "do nothing" functions for protocol drivers */
62static void null_rx(struct net_device *dev, int bufnum,

--- 324 unchanged lines hidden (view full) ---

387 struct net_device *dev = (struct net_device *)data;
388
389 if (!netif_carrier_ok(dev)) {
390 netif_carrier_on(dev);
391 netdev_info(dev, "link up\n");
392 }
393}
394
395static void arcnet_reply_tasklet(unsigned long data)
396{
397 struct arcnet_local *lp = (struct arcnet_local *)data;
398
399 struct sk_buff *ackskb, *skb;
400 struct sock_exterr_skb *serr;
401 struct sock *sk;
402 int ret;
403
404 local_irq_disable();
405 skb = lp->outgoing.skb;
406 if (!skb || !skb->sk) {
407 local_irq_enable();
408 return;
409 }
410
411 sock_hold(skb->sk);
412 sk = skb->sk;
413 ackskb = skb_clone_sk(skb);
414 sock_put(skb->sk);
415
416 if (!ackskb) {
417 local_irq_enable();
418 return;
419 }
420
421 serr = SKB_EXT_ERR(ackskb);
422 memset(serr, 0, sizeof(*serr));
423 serr->ee.ee_errno = ENOMSG;
424 serr->ee.ee_origin = SO_EE_ORIGIN_TXSTATUS;
425 serr->ee.ee_data = skb_shinfo(skb)->tskey;
426 serr->ee.ee_info = lp->reply_status;
427
428 /* finally erasing outgoing skb */
429 dev_kfree_skb(lp->outgoing.skb);
430 lp->outgoing.skb = NULL;
431
432 ackskb->dev = lp->dev;
433
434 ret = sock_queue_err_skb(sk, ackskb);
435 if (ret)
436 kfree_skb(ackskb);
437
438 local_irq_enable();
439};
440
394struct net_device *alloc_arcdev(const char *name)
395{
396 struct net_device *dev;
397
398 dev = alloc_netdev(sizeof(struct arcnet_local),
399 name && *name ? name : "arc%d", NET_NAME_UNKNOWN,
400 arcdev_setup);
401 if (dev) {
402 struct arcnet_local *lp = netdev_priv(dev);
403
441struct net_device *alloc_arcdev(const char *name)
442{
443 struct net_device *dev;
444
445 dev = alloc_netdev(sizeof(struct arcnet_local),
446 name && *name ? name : "arc%d", NET_NAME_UNKNOWN,
447 arcdev_setup);
448 if (dev) {
449 struct arcnet_local *lp = netdev_priv(dev);
450
451 lp->dev = dev;
404 spin_lock_init(&lp->lock);
405 init_timer(&lp->timer);
406 lp->timer.data = (unsigned long) dev;
407 lp->timer.function = arcnet_timer;
408 }
409
410 return dev;
411}

--- 19 unchanged lines hidden (view full) ---

431 if (BUGLVL(D_PROTO)) {
432 arc_printk(D_PROTO, dev, "protocol map (default is '%c'): ",
433 arc_proto_default->suffix);
434 for (count = 0; count < 256; count++)
435 arc_cont(D_PROTO, "%c", arc_proto_map[count]->suffix);
436 arc_cont(D_PROTO, "\n");
437 }
438
452 spin_lock_init(&lp->lock);
453 init_timer(&lp->timer);
454 lp->timer.data = (unsigned long) dev;
455 lp->timer.function = arcnet_timer;
456 }
457
458 return dev;
459}

--- 19 unchanged lines hidden (view full) ---

479 if (BUGLVL(D_PROTO)) {
480 arc_printk(D_PROTO, dev, "protocol map (default is '%c'): ",
481 arc_proto_default->suffix);
482 for (count = 0; count < 256; count++)
483 arc_cont(D_PROTO, "%c", arc_proto_map[count]->suffix);
484 arc_cont(D_PROTO, "\n");
485 }
486
487 tasklet_init(&lp->reply_tasklet, arcnet_reply_tasklet,
488 (unsigned long)lp);
489
439 arc_printk(D_INIT, dev, "arcnet_open: resetting card.\n");
440
441 /* try to put the card in a defined state - if it fails the first
442 * time, actually reset it.
443 */
444 error = -ENODEV;
445 if (lp->hw.reset(dev, 0) && lp->hw.reset(dev, 1))
446 goto out_module_put;

--- 75 unchanged lines hidden (view full) ---

522 struct arcnet_local *lp = netdev_priv(dev);
523
524 arcnet_led_event(dev, ARCNET_LED_EVENT_STOP);
525 del_timer_sync(&lp->timer);
526
527 netif_stop_queue(dev);
528 netif_carrier_off(dev);
529
490 arc_printk(D_INIT, dev, "arcnet_open: resetting card.\n");
491
492 /* try to put the card in a defined state - if it fails the first
493 * time, actually reset it.
494 */
495 error = -ENODEV;
496 if (lp->hw.reset(dev, 0) && lp->hw.reset(dev, 1))
497 goto out_module_put;

--- 75 unchanged lines hidden (view full) ---

573 struct arcnet_local *lp = netdev_priv(dev);
574
575 arcnet_led_event(dev, ARCNET_LED_EVENT_STOP);
576 del_timer_sync(&lp->timer);
577
578 netif_stop_queue(dev);
579 netif_carrier_off(dev);
580
581 tasklet_kill(&lp->reply_tasklet);
582
530 /* flush TX and disable RX */
531 lp->hw.intmask(dev, 0);
532 lp->hw.command(dev, NOTXcmd); /* stop transmit */
533 lp->hw.command(dev, NORXcmd); /* disable receive */
534 mdelay(1);
535
536 /* shut down the card */
537 lp->hw.close(dev);

--- 92 unchanged lines hidden (view full) ---

630 spin_lock_irqsave(&lp->lock, flags);
631 lp->hw.intmask(dev, 0);
632 if (lp->next_tx == -1)
633 txbuf = get_arcbuf(dev);
634 else
635 txbuf = -1;
636
637 if (txbuf != -1) {
583 /* flush TX and disable RX */
584 lp->hw.intmask(dev, 0);
585 lp->hw.command(dev, NOTXcmd); /* stop transmit */
586 lp->hw.command(dev, NORXcmd); /* disable receive */
587 mdelay(1);
588
589 /* shut down the card */
590 lp->hw.close(dev);

--- 92 unchanged lines hidden (view full) ---

683 spin_lock_irqsave(&lp->lock, flags);
684 lp->hw.intmask(dev, 0);
685 if (lp->next_tx == -1)
686 txbuf = get_arcbuf(dev);
687 else
688 txbuf = -1;
689
690 if (txbuf != -1) {
691 lp->outgoing.skb = skb;
638 if (proto->prepare_tx(dev, pkt, skb->len, txbuf) &&
639 !proto->ack_tx) {
640 /* done right away and we don't want to acknowledge
641 * the package later - forget about it now
642 */
643 dev->stats.tx_bytes += skb->len;
692 if (proto->prepare_tx(dev, pkt, skb->len, txbuf) &&
693 !proto->ack_tx) {
694 /* done right away and we don't want to acknowledge
695 * the package later - forget about it now
696 */
697 dev->stats.tx_bytes += skb->len;
644 dev_kfree_skb(skb);
645 } else {
646 /* do it the 'split' way */
647 lp->outgoing.proto = proto;
648 lp->outgoing.skb = skb;
649 lp->outgoing.pkt = pkt;
650
651 if (proto->continue_tx &&
652 proto->continue_tx(dev, txbuf)) {

--- 98 unchanged lines hidden (view full) ---

751 * interrupts. Establish which device needs attention, and call the correct
752 * chipset interrupt handler.
753 */
754irqreturn_t arcnet_interrupt(int irq, void *dev_id)
755{
756 struct net_device *dev = dev_id;
757 struct arcnet_local *lp;
758 int recbuf, status, diagstatus, didsomething, boguscount;
698 } else {
699 /* do it the 'split' way */
700 lp->outgoing.proto = proto;
701 lp->outgoing.skb = skb;
702 lp->outgoing.pkt = pkt;
703
704 if (proto->continue_tx &&
705 proto->continue_tx(dev, txbuf)) {

--- 98 unchanged lines hidden (view full) ---

804 * interrupts. Establish which device needs attention, and call the correct
805 * chipset interrupt handler.
806 */
807irqreturn_t arcnet_interrupt(int irq, void *dev_id)
808{
809 struct net_device *dev = dev_id;
810 struct arcnet_local *lp;
811 int recbuf, status, diagstatus, didsomething, boguscount;
759 unsigned long flags;
760 int retval = IRQ_NONE;
761
762 arc_printk(D_DURING, dev, "\n");
763
764 arc_printk(D_DURING, dev, "in arcnet_interrupt\n");
765
766 lp = netdev_priv(dev);
767 BUG_ON(!lp);
768
812 int retval = IRQ_NONE;
813
814 arc_printk(D_DURING, dev, "\n");
815
816 arc_printk(D_DURING, dev, "in arcnet_interrupt\n");
817
818 lp = netdev_priv(dev);
819 BUG_ON(!lp);
820
769 spin_lock_irqsave(&lp->lock, flags);
821 spin_lock(&lp->lock);
770
771 /* RESET flag was enabled - if device is not running, we must
772 * clear it right away (but nothing else).
773 */
774 if (!netif_running(dev)) {
775 if (lp->hw.status(dev) & RESETflag)
776 lp->hw.command(dev, CFLAGScmd | RESETclear);
777 lp->hw.intmask(dev, 0);
822
823 /* RESET flag was enabled - if device is not running, we must
824 * clear it right away (but nothing else).
825 */
826 if (!netif_running(dev)) {
827 if (lp->hw.status(dev) & RESETflag)
828 lp->hw.command(dev, CFLAGScmd | RESETclear);
829 lp->hw.intmask(dev, 0);
778 spin_unlock_irqrestore(&lp->lock, flags);
830 spin_unlock(&lp->lock);
779 return retval;
780 }
781
782 arc_printk(D_DURING, dev, "in arcnet_inthandler (status=%Xh, intmask=%Xh)\n",
783 lp->hw.status(dev), lp->intmask);
784
785 boguscount = 5;
786 do {

--- 51 unchanged lines hidden (view full) ---

838
839 lp->hw.command(dev, EXCNAKclear);
840 lp->intmask &= ~(EXCNAKflag);
841 didsomething++;
842 }
843
844 /* a transmit finished, and we're interested in it. */
845 if ((status & lp->intmask & TXFREEflag) || lp->timed_out) {
831 return retval;
832 }
833
834 arc_printk(D_DURING, dev, "in arcnet_inthandler (status=%Xh, intmask=%Xh)\n",
835 lp->hw.status(dev), lp->intmask);
836
837 boguscount = 5;
838 do {

--- 51 unchanged lines hidden (view full) ---

890
891 lp->hw.command(dev, EXCNAKclear);
892 lp->intmask &= ~(EXCNAKflag);
893 didsomething++;
894 }
895
896 /* a transmit finished, and we're interested in it. */
897 if ((status & lp->intmask & TXFREEflag) || lp->timed_out) {
898 int ackstatus;
846 lp->intmask &= ~(TXFREEflag | EXCNAKflag);
847
899 lp->intmask &= ~(TXFREEflag | EXCNAKflag);
900
901 if (status & TXACKflag)
902 ackstatus = 2;
903 else if (lp->excnak_pending)
904 ackstatus = 1;
905 else
906 ackstatus = 0;
907
848 arc_printk(D_DURING, dev, "TX IRQ (stat=%Xh)\n",
849 status);
850
851 if (lp->cur_tx != -1 && !lp->timed_out) {
852 if (!(status & TXACKflag)) {
853 if (lp->lasttrans_dest != 0) {
854 arc_printk(D_EXTRA, dev,
855 "transmit was not acknowledged! (status=%Xh, dest=%02Xh)\n",

--- 6 unchanged lines hidden (view full) ---

862 "broadcast was not acknowledged; that's normal (status=%Xh, dest=%02Xh)\n",
863 status,
864 lp->lasttrans_dest);
865 }
866 }
867
868 if (lp->outgoing.proto &&
869 lp->outgoing.proto->ack_tx) {
908 arc_printk(D_DURING, dev, "TX IRQ (stat=%Xh)\n",
909 status);
910
911 if (lp->cur_tx != -1 && !lp->timed_out) {
912 if (!(status & TXACKflag)) {
913 if (lp->lasttrans_dest != 0) {
914 arc_printk(D_EXTRA, dev,
915 "transmit was not acknowledged! (status=%Xh, dest=%02Xh)\n",

--- 6 unchanged lines hidden (view full) ---

922 "broadcast was not acknowledged; that's normal (status=%Xh, dest=%02Xh)\n",
923 status,
924 lp->lasttrans_dest);
925 }
926 }
927
928 if (lp->outgoing.proto &&
929 lp->outgoing.proto->ack_tx) {
870 int ackstatus;
871
872 if (status & TXACKflag)
873 ackstatus = 2;
874 else if (lp->excnak_pending)
875 ackstatus = 1;
876 else
877 ackstatus = 0;
878
879 lp->outgoing.proto
880 ->ack_tx(dev, ackstatus);
881 }
930 lp->outgoing.proto
931 ->ack_tx(dev, ackstatus);
932 }
933 lp->reply_status = ackstatus;
934 tasklet_hi_schedule(&lp->reply_tasklet);
882 }
883 if (lp->cur_tx != -1)
884 release_arcbuf(dev, lp->cur_tx);
885
886 lp->cur_tx = -1;
887 lp->timed_out = 0;
888 didsomething++;
889

--- 104 unchanged lines hidden (view full) ---

994 arc_printk(D_DURING, dev, "arcnet_interrupt complete (status=%Xh, count=%d)\n",
995 lp->hw.status(dev), boguscount);
996 arc_printk(D_DURING, dev, "\n");
997
998 lp->hw.intmask(dev, 0);
999 udelay(1);
1000 lp->hw.intmask(dev, lp->intmask);
1001
935 }
936 if (lp->cur_tx != -1)
937 release_arcbuf(dev, lp->cur_tx);
938
939 lp->cur_tx = -1;
940 lp->timed_out = 0;
941 didsomething++;
942

--- 104 unchanged lines hidden (view full) ---

1047 arc_printk(D_DURING, dev, "arcnet_interrupt complete (status=%Xh, count=%d)\n",
1048 lp->hw.status(dev), boguscount);
1049 arc_printk(D_DURING, dev, "\n");
1050
1051 lp->hw.intmask(dev, 0);
1052 udelay(1);
1053 lp->hw.intmask(dev, lp->intmask);
1054
1002 spin_unlock_irqrestore(&lp->lock, flags);
1055 spin_unlock(&lp->lock);
1003 return retval;
1004}
1005EXPORT_SYMBOL(arcnet_interrupt);
1006
1007/* This is a generic packet receiver that calls arcnet??_rx depending on the
1008 * protocol ID found.
1009 */
1010static void arcnet_rx(struct net_device *dev, int bufnum)

--- 96 unchanged lines hidden ---
1056 return retval;
1057}
1058EXPORT_SYMBOL(arcnet_interrupt);
1059
1060/* This is a generic packet receiver that calls arcnet??_rx depending on the
1061 * protocol ID found.
1062 */
1063static void arcnet_rx(struct net_device *dev, int bufnum)

--- 96 unchanged lines hidden ---