📄 apne.c
字号:
ei_status.reset_8390 = &apne_reset_8390; ei_status.block_input = &apne_block_input; ei_status.block_output = &apne_block_output; ei_status.get_8390_hdr = &apne_get_8390_hdr; ei_status.reg_offset = pcmcia_offsets; dev->open = &apne_open; dev->stop = &apne_close; NS8390_init(dev, 0); pcmcia_ack_int(pcmcia_get_intreq()); /* ack PCMCIA int req */ pcmcia_enable_irq(); apne_owned = 1; return 0;}static intapne_open(struct device *dev){ ei_open(dev); MOD_INC_USE_COUNT; return 0;}static intapne_close(struct device *dev){ if (ei_debug > 1) printk("%s: Shutting down ethercard.\n", dev->name); ei_close(dev); MOD_DEC_USE_COUNT; return 0;}/* Hard reset the card. This used to pause for the same period that a 8390 reset command required, but that shouldn't be necessary. */static voidapne_reset_8390(struct device *dev){ unsigned long reset_start_time = jiffies; init_pcmcia(); if (ei_debug > 1) printk("resetting the 8390 t=%ld...", jiffies); writeb(readb(NE_BASE + NE_RESET), NE_BASE + NE_RESET); ei_status.txing = 0; ei_status.dmaing = 0; /* This check _should_not_ be necessary, omit eventually. */ while ((readb(NE_BASE+NE_EN0_ISR) & ENISR_RESET) == 0) if (jiffies - reset_start_time > 2*HZ/100) { printk("%s: ne_reset_8390() did not complete.\n", dev->name); break; } writeb(ENISR_RESET, NE_BASE + NE_EN0_ISR); /* Ack intr. */}/* Grab the 8390 specific header. Similar to the block_input routine, but we don't need to be concerned with ring wrap as the header will be at the start of a page, so we optimize accordingly. */static voidapne_get_8390_hdr(struct device *dev, struct e8390_pkt_hdr *hdr, int ring_page){ int nic_base = dev->base_addr; int cnt; char *ptrc; short *ptrs; /* This *shouldn't* happen. If it does, it's the last thing you'll see */ if (ei_status.dmaing) { printk("%s: DMAing conflict in ne_get_8390_hdr " "[DMAstat:%d][irqlock:%d][intr:%ld].\n", dev->name, ei_status.dmaing, ei_status.irqlock, dev->interrupt); return; } ei_status.dmaing |= 0x01; writeb(E8390_NODMA+E8390_PAGE0+E8390_START, nic_base+ NE_CMD); writeb(ENISR_RDC, nic_base + NE_EN0_ISR); writeb(sizeof(struct e8390_pkt_hdr), nic_base + NE_EN0_RCNTLO); writeb(0, nic_base + NE_EN0_RCNTHI); writeb(0, nic_base + NE_EN0_RSARLO); /* On page boundary */ writeb(ring_page, nic_base + NE_EN0_RSARHI); writeb(E8390_RREAD+E8390_START, nic_base + NE_CMD); if (ei_status.word16) { ptrs = (short*)hdr; for(cnt = 0; cnt < (sizeof(struct e8390_pkt_hdr)>>1); cnt++) *ptrs++ = readw(NE_BASE + NE_DATAPORT); } else { ptrc = (char*)hdr; for(cnt = 0; cnt < sizeof(struct e8390_pkt_hdr); cnt++) *ptrc++ = readb(NE_BASE + NE_DATAPORT); } writeb(ENISR_RDC, nic_base + NE_EN0_ISR); /* Ack intr. */ hdr->count = WORDSWAP(hdr->count); ei_status.dmaing &= ~0x01;}/* Block input and output, similar to the Crynwr packet driver. If you are porting to a new ethercard, look at the packet driver source for hints. The NEx000 doesn't share the on-board packet memory -- you have to put the packet out through the "remote DMA" dataport using writeb. */static voidapne_block_input(struct device *dev, int count, struct sk_buff *skb, int ring_offset){ int nic_base = dev->base_addr; char *buf = skb->data; char *ptrc; short *ptrs; int cnt; /* This *shouldn't* happen. If it does, it's the last thing you'll see */ if (ei_status.dmaing) { printk("%s: DMAing conflict in ne_block_input " "[DMAstat:%d][irqlock:%d][intr:%ld].\n", dev->name, ei_status.dmaing, ei_status.irqlock, dev->interrupt); return; } ei_status.dmaing |= 0x01; writeb(E8390_NODMA+E8390_PAGE0+E8390_START, nic_base+ NE_CMD); writeb(ENISR_RDC, nic_base + NE_EN0_ISR); writeb(count & 0xff, nic_base + NE_EN0_RCNTLO); writeb(count >> 8, nic_base + NE_EN0_RCNTHI); writeb(ring_offset & 0xff, nic_base + NE_EN0_RSARLO); writeb(ring_offset >> 8, nic_base + NE_EN0_RSARHI); writeb(E8390_RREAD+E8390_START, nic_base + NE_CMD); if (ei_status.word16) { ptrs = (short*)buf; for (cnt = 0; cnt < (count>>1); cnt++) *ptrs++ = readw(NE_BASE + NE_DATAPORT); if (count & 0x01) { buf[count-1] = readb(NE_BASE + NE_DATAPORT); } } else { ptrc = (char*)buf; for (cnt = 0; cnt < count; cnt++) *ptrc++ = readb(NE_BASE + NE_DATAPORT); } writeb(ENISR_RDC, nic_base + NE_EN0_ISR); /* Ack intr. */ ei_status.dmaing &= ~0x01;}static voidapne_block_output(struct device *dev, int count, const unsigned char *buf, const int start_page){ int nic_base = NE_BASE; unsigned long dma_start; char *ptrc; short *ptrs; int cnt; /* Round the count up for word writes. Do we need to do this? What effect will an odd byte count have on the 8390? I should check someday. */ if (ei_status.word16 && (count & 0x01)) count++; /* This *shouldn't* happen. If it does, it's the last thing you'll see */ if (ei_status.dmaing) { printk("%s: DMAing conflict in ne_block_output." "[DMAstat:%d][irqlock:%d][intr:%ld]\n", dev->name, ei_status.dmaing, ei_status.irqlock, dev->interrupt); return; } ei_status.dmaing |= 0x01; /* We should already be in page 0, but to be safe... */ writeb(E8390_PAGE0+E8390_START+E8390_NODMA, nic_base + NE_CMD); writeb(ENISR_RDC, nic_base + NE_EN0_ISR); /* Now the normal output. */ writeb(count & 0xff, nic_base + NE_EN0_RCNTLO); writeb(count >> 8, nic_base + NE_EN0_RCNTHI); writeb(0x00, nic_base + NE_EN0_RSARLO); writeb(start_page, nic_base + NE_EN0_RSARHI); writeb(E8390_RWRITE+E8390_START, nic_base + NE_CMD); if (ei_status.word16) { ptrs = (short*)buf; for (cnt = 0; cnt < count>>1; cnt++) writew(*ptrs++, NE_BASE+NE_DATAPORT); } else { ptrc = (char*)buf; for (cnt = 0; cnt < count; cnt++) writeb(*ptrc++, NE_BASE + NE_DATAPORT); } dma_start = jiffies; while ((readb(NE_BASE + NE_EN0_ISR) & ENISR_RDC) == 0) if (jiffies - dma_start > 2*HZ/100) { /* 20ms */ printk("%s: timeout waiting for Tx RDC.\n", dev->name); apne_reset_8390(dev); NS8390_init(dev,1); break; } writeb(ENISR_RDC, nic_base + NE_EN0_ISR); /* Ack intr. */ ei_status.dmaing &= ~0x01; return;}static void apne_interrupt(int irq, void *dev_id, struct pt_regs *regs){ unsigned char pcmcia_intreq; if (!(gayle.inten & GAYLE_IRQ_IRQ)) return; pcmcia_intreq = pcmcia_get_intreq(); if (!(pcmcia_intreq & GAYLE_IRQ_IRQ)) { pcmcia_ack_int(pcmcia_intreq); return; } if (ei_debug > 3) printk("pcmcia intreq = %x\n", pcmcia_intreq); pcmcia_disable_irq(); /* to get rid of the sti() within ei_interrupt */ ei_interrupt(irq, dev_id, regs); pcmcia_ack_int(pcmcia_get_intreq()); pcmcia_enable_irq();}#ifdef MODULEstatic char devicename[9] = {0, };static struct device apne_dev ={ devicename, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, apne_probe,};int init_module(void){ int err; if ((err = register_netdev(&apne_dev))) { if (err == -EIO) printk("No PCMCIA NEx000 ethernet card found.\n"); return (err); } lock_8390_module(); return (0);}void cleanup_module(void){ unregister_netdev(&apne_dev); pcmcia_disable_irq(); free_irq(IRQ_AMIGA_PORTS, &apne_dev); pcmcia_reset(); unlock_8390_module(); apne_owned = 0;}#endifstatic int init_pcmcia(void){ u_char config;#ifndef MANUAL_CONFIG u_char tuple[32]; int offset_len;#endif u_long offset; pcmcia_reset(); pcmcia_program_voltage(PCMCIA_0V); pcmcia_access_speed(PCMCIA_SPEED_250NS); pcmcia_write_enable();#ifdef MANUAL_CONFIG config = MANUAL_CONFIG;#else /* get and write config byte to enable IO port */ if (pcmcia_copy_tuple(CISTPL_CFTABLE_ENTRY, tuple, 32) < 3) return 0; config = tuple[2] & 0x3f;#endif#ifdef MANUAL_OFFSET offset = MANUAL_OFFSET;#else if (pcmcia_copy_tuple(CISTPL_CONFIG, tuple, 32) < 6) return 0; offset_len = (tuple[2] & 0x3) + 1; offset = 0; while(offset_len--) { offset = (offset << 8) | tuple[4+offset_len]; }#endif writeb(config, GAYLE_ATTRIBUTE+offset); return 1;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -