arcnet.c
来自「linux 内核源代码」· C语言 代码 · 共 1,123 行 · 第 1/3 页
C
1,123 行
lp->last_timeout = jiffies; } if (lp->cur_tx == -1) netif_wake_queue(dev);}/* * The typical workload of the driver: Handle the network interface * interrupts. Establish which device needs attention, and call the correct * chipset interrupt handler. */irqreturn_t arcnet_interrupt(int irq, void *dev_id){ struct net_device *dev = dev_id; struct arcnet_local *lp; int recbuf, status, diagstatus, didsomething, boguscount; int retval = IRQ_NONE; BUGMSG(D_DURING, "\n"); BUGMSG(D_DURING, "in arcnet_interrupt\n"); lp = dev->priv; BUG_ON(!lp); spin_lock(&lp->lock); /* * RESET flag was enabled - if device is not running, we must clear it right * away (but nothing else). */ if (!netif_running(dev)) { if (ASTATUS() & RESETflag) ACOMMAND(CFLAGScmd | RESETclear); AINTMASK(0); spin_unlock(&lp->lock); return IRQ_HANDLED; } BUGMSG(D_DURING, "in arcnet_inthandler (status=%Xh, intmask=%Xh)\n", ASTATUS(), lp->intmask); boguscount = 5; do { status = ASTATUS(); diagstatus = (status >> 8) & 0xFF; BUGMSG(D_DEBUG, "%s: %d: %s: status=%x\n", __FILE__,__LINE__,__FUNCTION__,status); didsomething = 0; /* * RESET flag was enabled - card is resetting and if RX is * disabled, it's NOT because we just got a packet. * * The card is in an undefined state. Clear it out and start over. */ if (status & RESETflag) { BUGMSG(D_NORMAL, "spurious reset (status=%Xh)\n", status); arcnet_close(dev); arcnet_open(dev); /* get out of the interrupt handler! */ break; } /* * RX is inhibited - we must have received something. Prepare to * receive into the next buffer. * * We don't actually copy the received packet from the card until * after the transmit handler runs (and possibly launches the next * tx); this should improve latency slightly if we get both types * of interrupts at once. */ recbuf = -1; if (status & lp->intmask & NORXflag) { recbuf = lp->cur_rx; BUGMSG(D_DURING, "Buffer #%d: receive irq (status=%Xh)\n", recbuf, status); lp->cur_rx = get_arcbuf(dev); if (lp->cur_rx != -1) { BUGMSG(D_DURING, "enabling receive to buffer #%d\n", lp->cur_rx); ACOMMAND(RXcmd | (lp->cur_rx << 3) | RXbcasts); } didsomething++; } if((diagstatus & EXCNAKflag)) { BUGMSG(D_DURING, "EXCNAK IRQ (diagstat=%Xh)\n", diagstatus); ACOMMAND(NOTXcmd); /* disable transmit */ lp->excnak_pending = 1; ACOMMAND(EXCNAKclear); lp->intmask &= ~(EXCNAKflag); didsomething++; } /* a transmit finished, and we're interested in it. */ if ((status & lp->intmask & TXFREEflag) || lp->timed_out) { lp->intmask &= ~(TXFREEflag|EXCNAKflag); BUGMSG(D_DURING, "TX IRQ (stat=%Xh)\n", status); if (lp->cur_tx != -1 && !lp->timed_out) { if(!(status & TXACKflag)) { if (lp->lasttrans_dest != 0) { BUGMSG(D_EXTRA, "transmit was not acknowledged! " "(status=%Xh, dest=%02Xh)\n", status, lp->lasttrans_dest); lp->stats.tx_errors++; lp->stats.tx_carrier_errors++; } else { BUGMSG(D_DURING, "broadcast was not acknowledged; that's normal " "(status=%Xh, dest=%02Xh)\n", status, lp->lasttrans_dest); } } if (lp->outgoing.proto && lp->outgoing.proto->ack_tx) { int ackstatus; if(status & TXACKflag) ackstatus=2; else if(lp->excnak_pending) ackstatus=1; else ackstatus=0; lp->outgoing.proto ->ack_tx(dev, ackstatus); } } if (lp->cur_tx != -1) release_arcbuf(dev, lp->cur_tx); lp->cur_tx = -1; lp->timed_out = 0; didsomething++; /* send another packet if there is one */ go_tx(dev); /* continue a split packet, if any */ if (lp->outgoing.proto && lp->outgoing.proto->continue_tx) { int txbuf = get_arcbuf(dev); if (txbuf != -1) { if (lp->outgoing.proto->continue_tx(dev, txbuf)) { /* that was the last segment */ lp->stats.tx_bytes += lp->outgoing.skb->len; if(!lp->outgoing.proto->ack_tx) { dev_kfree_skb_irq(lp->outgoing.skb); lp->outgoing.proto = NULL; } } lp->next_tx = txbuf; } } /* inform upper layers of idleness, if necessary */ if (lp->cur_tx == -1) netif_wake_queue(dev); } /* now process the received packet, if any */ if (recbuf != -1) { BUGLVL(D_RX) arcnet_dump_packet(dev, recbuf, "rx irq", 0); arcnet_rx(dev, recbuf); release_arcbuf(dev, recbuf); didsomething++; } if (status & lp->intmask & RECONflag) { ACOMMAND(CFLAGScmd | CONFIGclear); lp->stats.tx_carrier_errors++; BUGMSG(D_RECON, "Network reconfiguration detected (status=%Xh)\n", status); /* MYRECON bit is at bit 7 of diagstatus */ if(diagstatus & 0x80) BUGMSG(D_RECON,"Put out that recon myself\n"); /* is the RECON info empty or old? */ if (!lp->first_recon || !lp->last_recon || jiffies - lp->last_recon > HZ * 10) { if (lp->network_down) BUGMSG(D_NORMAL, "reconfiguration detected: cabling restored?\n"); lp->first_recon = lp->last_recon = jiffies; lp->num_recons = lp->network_down = 0; BUGMSG(D_DURING, "recon: clearing counters.\n"); } else { /* add to current RECON counter */ lp->last_recon = jiffies; lp->num_recons++; BUGMSG(D_DURING, "recon: counter=%d, time=%lds, net=%d\n", lp->num_recons, (lp->last_recon - lp->first_recon) / HZ, lp->network_down); /* if network is marked up; * and first_recon and last_recon are 60+ apart; * and the average no. of recons counted is * > RECON_THRESHOLD/min; * then print a warning message. */ if (!lp->network_down && (lp->last_recon - lp->first_recon) <= HZ * 60 && lp->num_recons >= RECON_THRESHOLD) { lp->network_down = 1; BUGMSG(D_NORMAL, "many reconfigurations detected: cabling problem?\n"); } else if (!lp->network_down && lp->last_recon - lp->first_recon > HZ * 60) { /* reset counters if we've gone for over a minute. */ lp->first_recon = lp->last_recon; lp->num_recons = 1; } } } else if (lp->network_down && jiffies - lp->last_recon > HZ * 10) { if (lp->network_down) BUGMSG(D_NORMAL, "cabling restored?\n"); lp->first_recon = lp->last_recon = 0; lp->num_recons = lp->network_down = 0; BUGMSG(D_DURING, "not recon: clearing counters anyway.\n"); } if(didsomething) { retval |= IRQ_HANDLED; } } while (--boguscount && didsomething); BUGMSG(D_DURING, "arcnet_interrupt complete (status=%Xh, count=%d)\n", ASTATUS(), boguscount); BUGMSG(D_DURING, "\n"); AINTMASK(0); udelay(1); AINTMASK(lp->intmask); spin_unlock(&lp->lock); return retval;}/* * This is a generic packet receiver that calls arcnet??_rx depending on the * protocol ID found. */static void arcnet_rx(struct net_device *dev, int bufnum){ struct arcnet_local *lp = dev->priv; struct archdr pkt; struct arc_rfc1201 *soft; int length, ofs; soft = &pkt.soft.rfc1201; lp->hw.copy_from_card(dev, bufnum, 0, &pkt, sizeof(ARC_HDR_SIZE)); if (pkt.hard.offset[0]) { ofs = pkt.hard.offset[0]; length = 256 - ofs; } else { ofs = pkt.hard.offset[1]; length = 512 - ofs; } /* get the full header, if possible */ if (sizeof(pkt.soft) <= length) lp->hw.copy_from_card(dev, bufnum, ofs, soft, sizeof(pkt.soft)); else { memset(&pkt.soft, 0, sizeof(pkt.soft)); lp->hw.copy_from_card(dev, bufnum, ofs, soft, length); } BUGMSG(D_DURING, "Buffer #%d: received packet from %02Xh to %02Xh " "(%d+4 bytes)\n", bufnum, pkt.hard.source, pkt.hard.dest, length); lp->stats.rx_packets++; lp->stats.rx_bytes += length + ARC_HDR_SIZE; /* call the right receiver for the protocol */ if (arc_proto_map[soft->proto]->is_ip) { BUGLVL(D_PROTO) { struct ArcProto *oldp = arc_proto_map[lp->default_proto[pkt.hard.source]], *newp = arc_proto_map[soft->proto]; if (oldp != newp) { BUGMSG(D_PROTO, "got protocol %02Xh; encap for host %02Xh is now '%c'" " (was '%c')\n", soft->proto, pkt.hard.source, newp->suffix, oldp->suffix); } } /* broadcasts will always be done with the last-used encap. */ lp->default_proto[0] = soft->proto; /* in striking contrast, the following isn't a hack. */ lp->default_proto[pkt.hard.source] = soft->proto; } /* call the protocol-specific receiver. */ arc_proto_map[soft->proto]->rx(dev, bufnum, &pkt, length);}/* * Get the current statistics. This may be called with the card open or * closed. */static struct net_device_stats *arcnet_get_stats(struct net_device *dev){ struct arcnet_local *lp = dev->priv; return &lp->stats;}static void null_rx(struct net_device *dev, int bufnum, struct archdr *pkthdr, int length){ BUGMSG(D_PROTO, "rx: don't know how to deal with proto %02Xh from host %02Xh.\n", pkthdr->soft.rfc1201.proto, pkthdr->hard.source);}static int null_build_header(struct sk_buff *skb, struct net_device *dev, unsigned short type, uint8_t daddr){ struct arcnet_local *lp = dev->priv; BUGMSG(D_PROTO, "tx: can't build header for encap %02Xh; load a protocol driver.\n", lp->default_proto[daddr]); /* always fails */ return 0;}/* the "do nothing" prepare_tx function warns that there's nothing to do. */static int null_prepare_tx(struct net_device *dev, struct archdr *pkt, int length, int bufnum){ struct arcnet_local *lp = dev->priv; struct arc_hardware newpkt; BUGMSG(D_PROTO, "tx: no encap for this host; load a protocol driver.\n"); /* send a packet to myself -- will never get received, of course */ newpkt.source = newpkt.dest = dev->dev_addr[0]; /* only one byte of actual data (and it's random) */ newpkt.offset[0] = 0xFF; lp->hw.copy_to_card(dev, bufnum, 0, &newpkt, ARC_HDR_SIZE); return 1; /* done */}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?