44 #define VERSION "arcnet: v3.94 BETA 2007/02/08 - by Avery Pennarun et al.\n"
46 #include <linux/module.h>
47 #include <linux/types.h>
49 #include <linux/netdevice.h>
50 #include <linux/if_arp.h>
75 static struct ArcProto arc_proto_null =
81 .build_header = null_build_header,
82 .prepare_tx = null_prepare_tx,
106 const void *
saddr,
unsigned len);
107 static int arcnet_rebuild_header(
struct sk_buff *
skb);
110 static int debug = ARCNET_DEBUG;
114 static int __init arcnet_init(
void)
120 printk(
"arcnet loaded.\n");
125 "arcnet: * Read arcnet.txt for important release notes!\n"
127 "arcnet: * This is an ALPHA version! (Last stable release: v3.02) E-mail\n"
128 "arcnet: * me if you have any questions, comments, or bug reports.\n"
135 for (count = 0; count < 256; count++)
147 static
void __exit arcnet_exit(
void)
157 #if ARCNET_DEBUG_MAX & D_SKB
164 snprintf(hdr,
sizeof(hdr),
"%6s:%s skb->data:", dev->
name, desc);
166 16, 1, skb->
data, skb->
len,
true);
176 #if (ARCNET_DEBUG_MAX & (D_RX | D_TX))
178 char *desc,
int take_arcnet_lock)
180 struct arcnet_local *
lp = netdev_priv(dev);
182 unsigned long flags = 0;
191 lp->hw.copy_from_card(dev, bufnum, 0, buf, 512);
193 spin_unlock_irqrestore(&lp->lock, flags);
196 length = (buf[2] ? 256 : 512);
199 snprintf(hdr,
sizeof(hdr),
"%6s:%s packet dump:", dev->
name, desc);
201 16, 1, buf, length,
true);
206 #define arcnet_dump_packet(dev, bufnum, desc,take_arcnet_lock) do { } while (0)
227 for (count = 0; count < 256; count++) {
241 static void release_arcbuf(
struct net_device *dev,
int bufnum)
243 struct arcnet_local *lp = netdev_priv(dev);
246 lp->buf_queue[lp->first_free_buf++] = bufnum;
247 lp->first_free_buf %= 5;
250 BUGMSG(D_DURING,
"release_arcbuf: freed #%d; buffer queue is now: ",
252 for (i = lp->next_buf; i != lp->first_free_buf; i = (i+1) % 5)
253 BUGMSG2(D_DURING,
"#%d ", lp->buf_queue[i]);
254 BUGMSG2(D_DURING,
"\n");
265 struct arcnet_local *lp = netdev_priv(dev);
270 BUGMSG(D_NORMAL,
"get_arcbuf: overlap (%d)!\n",
271 lp->buf_lock.counter);
274 if (lp->next_buf >= 5)
277 if (lp->next_buf == lp->first_free_buf)
278 BUGMSG(D_NORMAL,
"get_arcbuf: BUG: no buffers are available??\n");
280 buf = lp->buf_queue[lp->next_buf++];
287 BUGMSG(D_DURING,
"get_arcbuf: got #%d; buffer queue is now: ", buf);
288 for (i = lp->next_buf; i != lp->first_free_buf; i = (i+1) % 5)
289 BUGMSG2(D_DURING,
"#%d ", lp->buf_queue[i]);
290 BUGMSG2(D_DURING,
"\n");
298 static int choose_mtu(
void)
300 int count, mtu = 65535;
303 for (count = 0; count < 256; count++) {
310 return mtu == 65535 ? XMTU : mtu;
313 static const struct header_ops arcnet_header_ops = {
314 .create = arcnet_header,
315 .rebuild = arcnet_rebuild_header,
326 static void arcdev_setup(
struct net_device *dev)
332 dev->
mtu = choose_mtu();
349 name && *name ? name :
"arc%d", arcdev_setup);
351 struct arcnet_local *lp = netdev_priv(dev);
368 struct arcnet_local *lp = netdev_priv(dev);
373 if (!try_module_get(lp->hw.owner))
377 BUGMSG(D_PROTO,
"protocol map (default is '%c'): ",
379 for (count = 0; count < 256; count++)
381 BUGMSG2(D_PROTO,
"\n");
385 BUGMSG(
D_INIT,
"arcnet_open: resetting card.\n");
394 newmtu = choose_mtu();
395 if (newmtu < dev->mtu)
398 BUGMSG(
D_INIT,
"arcnet_open: mtu: %d.\n", dev->
mtu);
401 memset(lp->default_proto, 0,
sizeof(lp->default_proto));
404 for (count = 0; count < 256; count++) {
406 lp->default_proto[0] =
count;
414 lp->next_buf = lp->first_free_buf = 0;
415 release_arcbuf(dev, 0);
416 release_arcbuf(dev, 1);
417 release_arcbuf(dev, 2);
418 release_arcbuf(dev, 3);
419 lp->cur_tx = lp->next_tx = -1;
422 lp->rfc1201.sequence = 1;
429 BUGMSG(D_NORMAL,
"WARNING! Station address 00 is reserved "
430 "for broadcasts!\n");
432 BUGMSG(D_NORMAL,
"WARNING! Station address FF may confuse "
433 "DOS networking programs!\n");
435 BUGMSG(D_DEBUG,
"%s: %d: %s\n",__FILE__,__LINE__,__func__);
437 BUGMSG(D_DEBUG,
"%s: %d: %s\n",__FILE__,__LINE__,__func__);
442 BUGMSG(D_DEBUG,
"%s: %d: %s\n",__FILE__,__LINE__,__func__);
449 BUGMSG(D_DEBUG,
"%s: %d: %s\n",__FILE__,__LINE__,__func__);
450 lp->intmask = NORXflag | RECONflag;
452 BUGMSG(D_DEBUG,
"%s: %d: %s\n",__FILE__,__LINE__,__func__);
454 netif_start_queue(dev);
459 module_put(lp->hw.owner);
467 struct arcnet_local *lp = netdev_priv(dev);
469 netif_stop_queue(dev);
479 module_put(lp->hw.owner);
486 const void *
saddr,
unsigned len)
488 const struct arcnet_local *lp = netdev_priv(dev);
490 struct ArcProto *
proto;
493 "create header from %d to %d; protocol %d (%Xh); size %u.\n",
494 saddr ? *(
uint8_t *) saddr : -1,
495 daddr ? *(
uint8_t *) daddr : -1,
498 if (skb->
len!=0 && len != skb->
len)
499 BUGMSG(D_NORMAL,
"arcnet_header: Yikes! skb->len(%d) != len(%d)!\n",
506 BUGMSG(D_DEBUG,
"arc_raw_proto used. proto='%c'\n",proto->suffix);
507 _daddr = daddr ? *(
uint8_t *) daddr : 0;
520 BUGMSG(D_NORMAL,
"arcnet_header: Yikes! diff (%d) is not 2!\n",
527 proto_num = lp->default_proto[_daddr];
529 BUGMSG(D_DURING,
"building header for %02Xh using protocol '%c'\n",
530 proto_num, proto->suffix);
532 BUGMSG(D_DURING,
"actually, let's use '%c' instead.\n",
537 return proto->build_header(skb, dev, type, _daddr);
546 static int arcnet_rebuild_header(
struct sk_buff *skb)
549 struct arcnet_local *lp = netdev_priv(dev);
553 struct ArcProto *
proto;
559 "rebuild_header: shouldn't be here! (hdrsize=%d)\n",
564 BUGMSG(D_DURING,
"rebuild header for protocol %Xh\n", type);
568 BUGMSG(D_DURING,
"rebuild header for ethernet protocol %Xh\n", type);
569 status =
arp_find(&daddr, skb) ? 1 : 0;
570 BUGMSG(D_DURING,
" rebuilt: dest is %d; protocol %Xh\n",
575 "I don't understand ethernet protocol %Xh addresses!\n", type);
576 dev->
stats.tx_errors++;
577 dev->
stats.tx_aborted_errors++;
586 proto->build_header(skb, dev, type, daddr);
597 struct arcnet_local *lp = netdev_priv(dev);
600 struct ArcProto *
proto;
606 "transmit requested (status=%Xh, txbufs=%d/%d, len=%d, protocol %x)\n",
613 BUGMSG(D_SKB_SIZE,
"skb: transmitting %d bytes to %02X\n",
615 BUGLVL(D_SKB) arcnet_dump_skb(dev, skb,
"tx");
619 BUGMSG(D_NORMAL,
"fixme: packet too large: compensating badly!\n");
625 netif_stop_queue(dev);
629 if(lp->next_tx == -1)
630 txbuf = get_arcbuf(dev);
635 if (proto->prepare_tx(dev, pkt, skb->
len, txbuf) &&
643 lp->outgoing.proto =
proto;
644 lp->outgoing.skb =
skb;
645 lp->outgoing.pkt = pkt;
649 if (proto->continue_tx &&
650 proto->continue_tx(dev, txbuf)) {
652 "bug! continue_tx finished the first time! "
653 "(proto='%c')\n", proto->suffix);
663 BUGMSG(D_DEBUG,
"%s: %d: %s, status: %x\n",__FILE__,__LINE__,__func__,
ASTATUS());
667 BUGMSG(D_DEBUG,
"%s: %d: %s\n",__FILE__,__LINE__,__func__);
668 lp->intmask |= TXFREEflag|EXCNAKflag;
670 BUGMSG(D_DEBUG,
"%s: %d: %s, status: %x\n",__FILE__,__LINE__,__func__,
ASTATUS());
672 spin_unlock_irqrestore(&lp->lock, flags);
686 struct arcnet_local *lp = netdev_priv(dev);
688 BUGMSG(D_DURING,
"go_tx: status=%Xh, intmask=%Xh, next_tx=%d, cur_tx=%d\n",
689 ASTATUS(), lp->intmask, lp->next_tx, lp->cur_tx);
691 if (lp->cur_tx != -1 || lp->next_tx == -1)
696 lp->cur_tx = lp->next_tx;
700 ACOMMAND(TXcmd | (lp->cur_tx << 3));
703 lp->lasttrans_dest = lp->lastload_dest;
704 lp->lastload_dest = 0;
705 lp->excnak_pending = 0;
706 lp->intmask |= TXFREEflag|EXCNAKflag;
716 struct arcnet_local *lp = netdev_priv(dev);
721 if (status & TXFREEflag) {
722 msg =
" - missed IRQ?";
725 dev->stats.tx_aborted_errors++;
727 ACOMMAND(NOTXcmd | (lp->cur_tx << 3));
729 dev->stats.tx_errors++;
733 lp->intmask |= TXFREEflag|EXCNAKflag;
736 spin_unlock_irqrestore(&lp->lock, flags);
739 BUGMSG(D_EXTRA,
"tx timed out%s (status=%Xh, intmask=%Xh, dest=%02Xh)\n",
740 msg, status, lp->intmask, lp->lasttrans_dest);
744 if (lp->cur_tx == -1)
745 netif_wake_queue(dev);
757 struct arcnet_local *lp;
758 int recbuf,
status, diagstatus, didsomething, boguscount;
761 BUGMSG(D_DURING,
"\n");
763 BUGMSG(D_DURING,
"in arcnet_interrupt\n");
765 lp = netdev_priv(dev);
768 spin_lock(&lp->lock);
774 if (!netif_running(dev)) {
778 spin_unlock(&lp->lock);
782 BUGMSG(D_DURING,
"in arcnet_inthandler (status=%Xh, intmask=%Xh)\n",
788 diagstatus = (status >> 8) & 0xFF;
790 BUGMSG(D_DEBUG,
"%s: %d: %s: status=%x\n",
791 __FILE__,__LINE__,__func__,status);
800 if (status & RESETflag) {
801 BUGMSG(D_NORMAL,
"spurious reset (status=%Xh)\n", status);
818 if (status & lp->intmask & NORXflag) {
820 BUGMSG(D_DURING,
"Buffer #%d: receive irq (status=%Xh)\n",
823 lp->cur_rx = get_arcbuf(dev);
824 if (lp->cur_rx != -1) {
825 BUGMSG(D_DURING,
"enabling receive to buffer #%d\n",
827 ACOMMAND(RXcmd | (lp->cur_rx << 3) | RXbcasts);
832 if((diagstatus & EXCNAKflag)) {
833 BUGMSG(D_DURING,
"EXCNAK IRQ (diagstat=%Xh)\n",
837 lp->excnak_pending = 1;
840 lp->intmask &= ~(EXCNAKflag);
846 if ((status & lp->intmask & TXFREEflag) || lp->timed_out) {
847 lp->intmask &= ~(TXFREEflag|EXCNAKflag);
849 BUGMSG(D_DURING,
"TX IRQ (stat=%Xh)\n", status);
851 if (lp->cur_tx != -1 && !lp->timed_out) {
852 if(!(status & TXACKflag)) {
853 if (lp->lasttrans_dest != 0) {
855 "transmit was not acknowledged! "
856 "(status=%Xh, dest=%02Xh)\n",
857 status, lp->lasttrans_dest);
858 dev->
stats.tx_errors++;
859 dev->
stats.tx_carrier_errors++;
862 "broadcast was not acknowledged; that's normal "
863 "(status=%Xh, dest=%02Xh)\n",
864 status, lp->lasttrans_dest);
868 if (lp->outgoing.proto &&
869 lp->outgoing.proto->ack_tx) {
871 if(status & TXACKflag)
873 else if(lp->excnak_pending)
879 ->ack_tx(dev, ackstatus);
882 if (lp->cur_tx != -1)
883 release_arcbuf(dev, lp->cur_tx);
893 if (lp->outgoing.proto && lp->outgoing.proto->continue_tx) {
894 int txbuf = get_arcbuf(dev);
896 if (lp->outgoing.proto->continue_tx(dev, txbuf)) {
898 dev->
stats.tx_bytes += lp->outgoing.skb->len;
899 if(!lp->outgoing.proto->ack_tx)
902 lp->outgoing.proto =
NULL;
909 if (lp->cur_tx == -1)
910 netif_wake_queue(dev);
916 arcnet_rx(dev, recbuf);
917 release_arcbuf(dev, recbuf);
921 if (status & lp->intmask & RECONflag) {
923 dev->
stats.tx_carrier_errors++;
925 BUGMSG(D_RECON,
"Network reconfiguration detected (status=%Xh)\n",
928 if(diagstatus & 0x80)
929 BUGMSG(D_RECON,
"Put out that recon myself\n");
932 if (!lp->first_recon || !lp->last_recon ||
934 if (lp->network_down)
935 BUGMSG(D_NORMAL,
"reconfiguration detected: cabling restored?\n");
936 lp->first_recon = lp->last_recon =
jiffies;
937 lp->num_recons = lp->network_down = 0;
939 BUGMSG(D_DURING,
"recon: clearing counters.\n");
944 BUGMSG(D_DURING,
"recon: counter=%d, time=%lds, net=%d\n",
946 (lp->last_recon - lp->first_recon) /
HZ,
955 if (!lp->network_down &&
956 (lp->last_recon - lp->first_recon) <=
HZ * 60 &&
957 lp->num_recons >= RECON_THRESHOLD) {
958 lp->network_down = 1;
959 BUGMSG(D_NORMAL,
"many reconfigurations detected: cabling problem?\n");
960 }
else if (!lp->network_down &&
961 lp->last_recon - lp->first_recon >
HZ * 60) {
963 lp->first_recon = lp->last_recon;
967 }
else if (lp->network_down &&
969 if (lp->network_down)
970 BUGMSG(D_NORMAL,
"cabling restored?\n");
971 lp->first_recon = lp->last_recon = 0;
972 lp->num_recons = lp->network_down = 0;
974 BUGMSG(D_DURING,
"not recon: clearing counters anyway.\n");
981 while (--boguscount && didsomething);
983 BUGMSG(D_DURING,
"arcnet_interrupt complete (status=%Xh, count=%d)\n",
985 BUGMSG(D_DURING,
"\n");
992 spin_unlock(&lp->lock);
1001 static void arcnet_rx(
struct net_device *dev,
int bufnum)
1003 struct arcnet_local *lp = netdev_priv(dev);
1008 soft = &pkt.soft.rfc1201;
1010 lp->hw.copy_from_card(dev, bufnum, 0, &pkt,
sizeof(
ARC_HDR_SIZE));
1011 if (pkt.hard.offset[0]) {
1012 ofs = pkt.hard.offset[0];
1015 ofs = pkt.hard.offset[1];
1020 if (
sizeof(pkt.soft) <= length)
1021 lp->hw.copy_from_card(dev, bufnum, ofs, soft,
sizeof(pkt.soft));
1023 memset(&pkt.soft, 0,
sizeof(pkt.soft));
1024 lp->hw.copy_from_card(dev, bufnum, ofs, soft, length);
1027 BUGMSG(D_DURING,
"Buffer #%d: received packet from %02Xh to %02Xh "
1029 bufnum, pkt.hard.source, pkt.hard.dest, length);
1031 dev->
stats.rx_packets++;
1043 "got protocol %02Xh; encap for host %02Xh is now '%c'"
1044 " (was '%c')\n", soft->
proto, pkt.hard.source,
1045 newp->suffix, oldp->suffix);
1050 lp->default_proto[0] = soft->
proto;
1053 lp->default_proto[pkt.hard.source] = soft->
proto;
1060 static void null_rx(
struct net_device *dev,
int bufnum,
1064 "rx: don't know how to deal with proto %02Xh from host %02Xh.\n",
1070 unsigned short type,
uint8_t daddr)
1072 struct arcnet_local *lp = netdev_priv(dev);
1075 "tx: can't build header for encap %02Xh; load a protocol driver.\n",
1076 lp->default_proto[daddr]);
1085 int length,
int bufnum)
1087 struct arcnet_local *lp = netdev_priv(dev);
1090 BUGMSG(D_PROTO,
"tx: no encap for this host; load a protocol driver.\n");
1093 newpkt.source = newpkt.dest = dev->
dev_addr[0];
1096 newpkt.offset[0] = 0xFF;
1098 lp->hw.copy_to_card(dev, bufnum, 0, &newpkt, ARC_HDR_SIZE);