📄 82596.c
字号:
int i; rtc[3] |= 0x80; for (i = 0; i < 6; i++) eth_addr[i] = rtc[i * 4 + 7]; /* Stored in RTC RAM at offset 1 */ rtc[3] = msr; dev->base_addr = BVME_I596_BASE; dev->irq = (unsigned) BVME_IRQ_I596; }#endif#ifdef CONFIG_APRICOT_INTEL int checksum = 0; int ioaddr = 0x300; /* this is easy the ethernet interface can only be at 0x300 */ /* first check nothing is already registered here */ if (check_region(ioaddr, I596_TOTAL_SIZE)) return ENODEV; for (i = 0; i < 8; i++) { eth_addr[i] = inb(ioaddr + 8 + i); checksum += eth_addr[i]; } /* checksum is a multiple of 0x100, got this wrong first time some machines have 0x100, some 0x200. The DOS driver doesn't even bother with the checksum */ if (checksum % 0x100) return ENODEV; /* Some other boards trip the checksum.. but then appear as ether address 0. Trap these - AC */ if (memcmp(eth_addr, "\x00\x00\x49", 3) != 0) return ENODEV; request_region(ioaddr, I596_TOTAL_SIZE, "i596"); dev->base_addr = ioaddr; dev->irq = 10;#endif ether_setup(dev); printk("%s: 82596 at %#3lx,", dev->name, dev->base_addr); for (i = 0; i < 6; i++) printk(" %2.2X", dev->dev_addr[i] = eth_addr[i]); printk(" IRQ %d.\n", dev->irq); if (i596_debug > 0) printk(version); /* The APRICOT-specific entries in the device structure. */ dev->open = &i596_open; dev->stop = &i596_close; dev->hard_start_xmit = &i596_start_xmit; dev->get_stats = &i596_get_stats; dev->set_multicast_list = &set_multicast_list; dev->mem_start = (int) kmalloc(sizeof(struct i596_private) + 0x0f, GFP_KERNEL); /* align for scp */ dev->priv = (void *) ((dev->mem_start + 0xf) & 0xfffffff0); lp = (struct i596_private *) dev->priv; if (i596_debug) printk("%s: lp at 0x%08lx, lp->scb at 0x%08lx\n" ,dev->name, (unsigned long) lp, (unsigned long) &lp->scb); memset((void *) lp, 0, sizeof(struct i596_private)); lp->scb.command = 0; lp->scb.cmd = (struct i596_cmd *) I596_NULL; lp->scb.rfd = (struct i596_rfd *) I596_NULL; return 0;}static void i596_interrupt(int irq, void *dev_id, struct pt_regs *regs){ struct device *dev = dev_id; struct i596_private *lp; short ioaddr; int boguscnt = 2000; unsigned short status, ack_cmd = 0;#ifdef CONFIG_BVME6000_NET if (MACH_IS_BVME6000) { if (*(char *) BVME_LOCAL_IRQ_STAT & BVME_ETHERR) { i596_error(BVME_IRQ_I596, NULL, NULL); return; } }#endif if (dev == NULL) { printk("i596_interrupt(): irq %d for unknown device.\n", irq); return; } if (i596_debug > 3) printk("%s: i596_interrupt(): irq %d\n", dev->name, irq); if (dev->interrupt) printk("%s: Re-entering the interrupt handler.\n", dev->name); dev->interrupt = 1; ioaddr = dev->base_addr; lp = (struct i596_private *) dev->priv; while (lp->scb.command) if (--boguscnt == 0) { printk("%s: i596 interrupt, timeout status %4.4x command %4.4x.\n", dev->name, lp->scb.status, lp->scb.command); break; } status = lp->scb.status; if (i596_debug > 4) printk("%s: i596 interrupt, status %4.4x.\n", dev->name, status); ack_cmd = status & 0xf000; if ((status & 0x8000) || (status & 0x2000)) { struct i596_cmd *ptr; if ((i596_debug > 4) && (status & 0x8000)) printk("%s: i596 interrupt completed command.\n", dev->name); if ((i596_debug > 4) && (status & 0x2000)) printk("%s: i596 interrupt command unit inactive %x.\n", dev->name, status & 0x0700); while ((lp->cmd_head != (struct i596_cmd *) I596_NULL) && (lp->cmd_head->status & STAT_C)) { ptr = lp->cmd_head; if (i596_debug > 2) printk("cmd_head->status = %04x, ->command = %04x\n", lp->cmd_head->status, lp->cmd_head->command); lp->cmd_head = WSWAPcmd(lp->cmd_head->next); lp->cmd_backlog--; switch ((ptr->command) & 0x7) { case CmdTx: { struct tx_cmd *tx_cmd = (struct tx_cmd *) ptr; struct sk_buff *skb = tx_cmd->skb; if ((ptr->status) & STAT_OK) { if (i596_debug > 2) print_eth(skb->data); } else { lp->stats.tx_errors++; if ((ptr->status) & 0x0020) lp->stats.collisions++; if (!((ptr->status) & 0x0040)) lp->stats.tx_heartbeat_errors++; if ((ptr->status) & 0x0400) lp->stats.tx_carrier_errors++; if ((ptr->status) & 0x0800) lp->stats.collisions++; if ((ptr->status) & 0x1000) lp->stats.tx_aborted_errors++; } dev_kfree_skb(skb); ptr->next = (struct i596_cmd *) I596_NULL; kfree(tx_cmd); break; } case CmdMulticastList: { ptr->next = (struct i596_cmd *) I596_NULL; kfree(ptr); break; } case CmdTDR: { unsigned long status = *((unsigned long *) (ptr + 1)); if (status & 0x8000) { if (i596_debug > 3) printk("%s: link ok.\n", dev->name); } else { if (status & 0x4000) printk("%s: Transceiver problem.\n", dev->name); if (status & 0x2000) printk("%s: Termination problem.\n", dev->name); if (status & 0x1000) printk("%s: Short circuit.\n", dev->name); if (i596_debug > 1) printk("%s: Time %ld.\n", dev->name, status & 0x07ff); } break; } case CmdConfigure: { ptr->next = (struct i596_cmd *) I596_NULL; /* Zap command so set_multicast_list() knows it is free */ ptr->command = 0; break; } default: ptr->next = (struct i596_cmd *) I596_NULL; } lp->last_cmd = jiffies; } ptr = lp->cmd_head; while ((ptr != (struct i596_cmd *) I596_NULL) && (ptr != lp->cmd_tail)) { ptr->command &= 0x1fff; ptr = WSWAPcmd(ptr->next); } if ((lp->cmd_head != (struct i596_cmd *) I596_NULL) && (dev->start)) ack_cmd |= CUC_START; lp->scb.cmd = WSWAPcmd(lp->cmd_head); } if ((status & 0x1000) || (status & 0x4000)) { if ((i596_debug > 4) && (status & 0x4000)) printk("%s: i596 interrupt received a frame.\n", dev->name); /* Only RX_START if stopped - RGH 07-07-96 */ if (status & 0x1000) { if (dev->start) ack_cmd |= RX_START; if (i596_debug > 1) printk("%s: i596 interrupt receive unit inactive %x.\n", dev->name, status & 0x00f0); } i596_rx(dev); } /* acknowledge the interrupt *//* COMMENTED OUT <<<<< if ((lp->scb.cmd != (struct i596_cmd *) I596_NULL) && (dev->start)) ack_cmd |= CUC_START; */ boguscnt = 1000; while (lp->scb.command) if (--boguscnt == 0) { printk("%s: i596 interrupt, timeout status %4.4x command %4.4x.\n", dev->name, lp->scb.status, lp->scb.command); break; } lp->scb.command = ack_cmd;#ifdef CONFIG_MVME16x_NET if (MACH_IS_MVME16x) { /* Ack the interrupt */ volatile unsigned char *pcc2 = (unsigned char *) 0xfff42000; pcc2[0x2a] |= 0x08; }#endif#ifdef CONFIG_BVME6000_NET if (MACH_IS_BVME6000) { volatile unsigned char *ethirq = (unsigned char *) BVME_ETHIRQ_REG; *ethirq = 1; *ethirq = 3; }#endif#ifdef CONFIG_APRICOT_INTEL (void) inb(ioaddr + 0x10); outb(4, ioaddr + 0xf);#endif CA(dev); if (i596_debug > 4) printk("%s: exiting interrupt.\n", dev->name); dev->interrupt = 0; return;}static int i596_close(struct device *dev){ struct i596_private *lp = (struct i596_private *) dev->priv; int boguscnt = 2000; unsigned long flags; dev->start = 0; dev->tbusy = 1; if (i596_debug > 1) printk("%s: Shutting down ethercard, status was %4.4x.\n", dev->name, lp->scb.status); save_flags(flags); cli(); while (lp->scb.command) if (--boguscnt == 0) { printk("%s: close1 timed out with status %4.4x, cmd %4.4x.\n", dev->name, lp->scb.status, lp->scb.command); break; } lp->scb.command = CUC_ABORT | RX_ABORT; CA(dev); boguscnt = 2000; while (lp->scb.command) if (--boguscnt == 0) { printk("%s: close2 timed out with status %4.4x, cmd %4.4x.\n", dev->name, lp->scb.status, lp->scb.command); break; } restore_flags(flags); i596_cleanup_cmd(lp);#ifdef CONFIG_MVME16x_NET if (MACH_IS_MVME16x) { volatile unsigned char *pcc2 = (unsigned char *) 0xfff42000; /* Disable all ints */ pcc2[0x28] = 1; pcc2[0x2a] = 0x40; pcc2[0x2b] = 0x40; /* Set snooping bits now! */ }#endif#ifdef CONFIG_BVME6000_NET if (MACH_IS_BVME6000) { volatile unsigned char *ethirq = (unsigned char *) BVME_ETHIRQ_REG; *ethirq = 1; }#endif free_irq(dev->irq, dev); remove_rx_bufs(dev); MOD_DEC_USE_COUNT; return 0;}static struct net_device_stats * i596_get_stats(struct device *dev){ struct i596_private *lp = (struct i596_private *) dev->priv; return &lp->stats;}/* * Set or clear the multicast filter for this adaptor. */static void set_multicast_list(struct device *dev){ struct i596_private *lp = (struct i596_private *) dev->priv; struct i596_cmd *cmd; int config = 0; if (i596_debug > 1) printk("%s: set multicast list, %d entries, promisc %s, allmulti %s\n", dev->name, dev->mc_count, dev->flags & IFF_PROMISC ? "ON" : "OFF", dev->flags & IFF_ALLMULTI ? "ON" : "OFF"); if ((dev->flags & IFF_PROMISC) && !(lp->i596_config[8] & 0x01)) { lp->i596_config[8] |= 0x01; config = 1; } if (!(dev->flags & IFF_PROMISC) && (lp->i596_config[8] & 0x01)) { lp->i596_config[8] &= ~0x01; config = 1; } if ((dev->flags & IFF_ALLMULTI) && (lp->i596_config[11] & 0x20)) { lp->i596_config[11] &= ~0x20; config = 1; } if (!(dev->flags & IFF_ALLMULTI) && !(lp->i596_config[11] & 0x20)) { lp->i596_config[11] |= 0x20; config = 1; } if (config) { if (lp->set_conf.command) printk("%s: config change request already queued\n", dev->name); else { lp->set_conf.command = CmdConfigure; i596_add_cmd(dev, &lp->set_conf); } } if (dev->mc_count > 0) { struct dev_mc_list *dmi; unsigned char *cp; cmd = (struct i596_cmd *) kmalloc(sizeof(struct i596_cmd) + 2 + dev->mc_count * 6, GFP_ATOMIC); if (cmd == NULL) { printk("%s: set_multicast Memory squeeze.\n", dev->name); return; } cmd->command = CmdMulticastList; *((unsigned short *) (cmd + 1)) = dev->mc_count * 6; cp = ((unsigned char *) (cmd + 1)) + 2; for (dmi = dev->mc_list; dmi != NULL; dmi = dmi->next) { memcpy(cp, dmi->dmi_addr, 6); if (i596_debug > 1) printk("%s: Adding address %02x:%02x:%02x:%02x:%02x:%02x\n", dev->name, *(cp + 0), *(cp + 1), *(cp + 2), *(cp + 3), *(cp + 4), *(cp + 5)); cp += 6; } if (i596_debug > 2) print_eth(((char *) (cmd + 1)) + 2); i596_add_cmd(dev, cmd); }}#ifdef HAVE_DEVLISTstatic unsigned int i596_portlist[] __initdata ={0x300, 0};struct netdev_entry i596_drv ={"apricot", i82596_probe, I596_TOTAL_SIZE, apricot_portlist};#endif#ifdef MODULEstatic char devicename[9] ={0,};static struct device dev_apricot ={ devicename, /* device name inserted by /linux/drivers/net/net_init.c */ 0, 0, 0, 0, 0x300, 10, 0, 0, 0, NULL, i82596_probe};static int io = 0x300;static int irq = 10;MODULE_PARM(irq, "i");int init_module(void){ dev_apricot.base_addr = io; dev_apricot.irq = irq; if (register_netdev(&dev_apricot) != 0) return -EIO; return 0;}void cleanup_module(void){ unregister_netdev(&dev_apricot); kfree((void *) dev_apricot.mem_start); dev_apricot.priv = NULL; /* If we don't do this, we can't re-insmod it later. */ release_region(dev_apricot.base_addr, I596_TOTAL_SIZE);}#endif /* MODULE *//* * Local variables: * compile-command: "gcc -D__KERNEL__ -I/usr/src/linux/net/inet -Wall -Wstrict-prototypes -O6 -m486 -c 82596.c" * End: */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -