static void alloc586(struct net_device *dev) { struct priv *p = netdev_priv(dev); ni_reset586(); mdelay(32); memset_io(p->iscp, 0, sizeof(struct iscp_struct)); memset_io(p->scp , 0, sizeof(struct scp_struct)); writel(make24(p->iscp), &p->scp->iscp); writeb(SYSBUSVAL, &p->scp->sysbus); writew(make16(p->scb), &p->iscp->scb_offset); writeb(1, &p->iscp->busy); ni_reset586(); ni_attn586(); mdelay(32); if (readb(&p->iscp->busy)) printk(KERN_ERR "%s: Init-Problems (alloc).\n", dev->name); p->reset = 0; memset_io(p->scb, 0, sizeof(struct scb_struct)); }
/****************************************************************** * set iscp at the right place, called by ni52_probe1 and open586. */ static void alloc586(struct net_device *dev) { struct priv *p = (struct priv *) dev->priv; ni_reset586(); DELAY(1); p->scp = (struct scp_struct *) (p->base + SCP_DEFAULT_ADDRESS); p->scb = (struct scb_struct *) isa_bus_to_virt(dev->mem_start); p->iscp = (struct iscp_struct *) ((char *)p->scp - sizeof(struct iscp_struct)); memset((char *) p->iscp,0,sizeof(struct iscp_struct)); memset((char *) p->scp ,0,sizeof(struct scp_struct)); p->scp->iscp = make24(p->iscp); p->scp->sysbus = SYSBUSVAL; p->iscp->scb_offset = make16(p->scb); p->iscp->busy = 1; ni_reset586(); ni_attn586(); DELAY(1); if(p->iscp->busy) printk("%s: Init-Problems (alloc).\n",dev->name); p->reseted = 0; memset((char *)p->scb,0,sizeof(struct scb_struct)); }
void alloc586(struct device *dev) { struct priv *p = (struct priv *) dev->priv; p->scp = (struct scp_struct *) (p->base + SCP_DEFAULT_ADDRESS); p->scb = (struct scb_struct *) (dev->mem_start); p->iscp = (struct iscp_struct *) ((char *)p->scp - sizeof(struct iscp_struct)); memset((char *) p->iscp,0,sizeof(struct iscp_struct)); memset((char *) p->scp ,0,sizeof(struct scp_struct)); p->scp->iscp = make24(p->iscp); p->scp->sysbus = SYSBUSVAL; p->iscp->scb_offset = make16(p->scb); p->iscp->busy = 1; ni_reset586(); ni_attn586(); #ifdef DEBUG DELAY(2); if(p->iscp->busy) printk("%s: Init-Problems (alloc).\n",dev->name); #endif memset((char *)p->scb,0,sizeof(struct scb_struct)); }
static int ni52_close(struct net_device *dev) { free_irq(dev->irq, dev); ni_reset586(); /* */ netif_stop_queue(dev); return 0; }
/********************************************** * close device */ static int ni52_close(struct net_device *dev) { free_irq(dev->irq, dev); ni_reset586(); /* the hard way to stop the receiver */ netif_stop_queue(dev); return 0; }
static int check586(struct device *dev,char *where,unsigned size) { struct priv *p = (struct priv *) dev->priv; char *iscp_addrs[2]; int i; p->base = (unsigned long) where + size - 0x01000000; p->memtop = where + size; p->scp = (struct scp_struct *)(p->base + SCP_DEFAULT_ADDRESS); memset((char *)p->scp,0, sizeof(struct scp_struct)); p->scp->sysbus = SYSBUSVAL; /* 1 = 8Bit-Bus */ iscp_addrs[0] = where; iscp_addrs[1]= (char *) p->scp - sizeof(struct iscp_struct); for(i=0;i<2;i++) { p->iscp = (struct iscp_struct *) iscp_addrs[i]; memset((char *)p->iscp,0, sizeof(struct iscp_struct)); p->scp->iscp = make24(p->iscp); p->iscp->busy = 1; ni_reset586(); ni_attn586(); DELAY(2); /* wait a while... */ if(p->iscp->busy) return 0; } return 1; }
static int ni52_close(struct device *dev) { free_irq(dev->irq); irq2dev_map[dev->irq] = 0; ni_reset586(); /* the hard way to stop the receiver */ dev->start = 0; dev->tbusy = 0; return 0; }
static int check_iscp(struct net_device *dev, void __iomem *addr) { struct iscp_struct __iomem *iscp = addr; struct priv *p = netdev_priv(dev); memset_io(iscp, 0, sizeof(struct iscp_struct)); writel(make24(iscp), &p->scp->iscp); writeb(1, &iscp->busy); ni_reset586(); ni_attn586(); mdelay(32); /* */ /* */ if (readb(&iscp->busy)) return 0; return 1; }
static int check_iscp(struct net_device *dev, void __iomem *addr) { struct iscp_struct __iomem *iscp = addr; struct priv *p = dev->priv; memset_io(iscp, 0, sizeof(struct iscp_struct)); writel(make24(iscp), &p->scp->iscp); writeb(1, &iscp->busy); ni_reset586(); ni_attn586(); mdelay(32); /* wait a while... */ /* i82586 clears 'busy' after successful init */ if (readb(&iscp->busy)) return 0; return 1; }
static int ni52_open(struct net_device *dev) { int ret; ni_disint(); alloc586(dev); init586(dev); startrecv586(dev); ni_enaint(); ret = request_irq(dev->irq, ni52_interrupt, 0, dev->name, dev); if (ret) { ni_reset586(); return ret; } netif_start_queue(dev); return 0; /* */ }
static void wait_for_scb_cmd(struct net_device *dev) { struct priv *p = netdev_priv(dev); int i; for (i = 0; i < 16384; i++) { if (readb(&p->scb->cmd_cuc) == 0) break; udelay(4); if (i == 16383) { printk(KERN_ERR "%s: scb_cmd timed out: %04x,%04x .. disabling i82586!!\n", dev->name, readb(&p->scb->cmd_cuc), readb(&p->scb->cus)); if (!p->reset) { p->reset = 1; ni_reset586(); } } } }
static int ni52_open(struct device *dev) { alloc586(dev); init586(dev); startrecv586(dev); if(request_irq(dev->irq, &ni52_interrupt,0,"ni52")) { ni_reset586(); return -EAGAIN; } irq2dev_map[dev->irq] = dev; dev->interrupt = 0; dev->tbusy = 0; dev->start = 1; return 0; /* most done by init */ }
/********************************************** * Check to see if there's an 82586 out there. */ static int check586(struct net_device *dev,char *where,unsigned size) { struct priv pb; struct priv *p = /* (struct priv *) dev->priv*/ &pb; char *iscp_addrs[2]; int i; p->base = (unsigned long) isa_bus_to_virt((unsigned long)where) + size - 0x01000000; p->memtop = isa_bus_to_virt((unsigned long)where) + size; p->scp = (struct scp_struct *)(p->base + SCP_DEFAULT_ADDRESS); memset((char *)p->scp,0, sizeof(struct scp_struct)); for(i=0;i<sizeof(struct scp_struct);i++) /* memory was writeable? */ if(((char *)p->scp)[i]) return 0; p->scp->sysbus = SYSBUSVAL; /* 1 = 8Bit-Bus, 0 = 16 Bit */ if(p->scp->sysbus != SYSBUSVAL) return 0; iscp_addrs[0] = isa_bus_to_virt((unsigned long)where); iscp_addrs[1]= (char *) p->scp - sizeof(struct iscp_struct); for(i=0;i<2;i++) { p->iscp = (struct iscp_struct *) iscp_addrs[i]; memset((char *)p->iscp,0, sizeof(struct iscp_struct)); p->scp->iscp = make24(p->iscp); p->iscp->busy = 1; ni_reset586(); ni_attn586(); DELAY(1); /* wait a while... */ if(p->iscp->busy) /* i82586 clears 'busy' after successful init */ return 0; } return 1; }
static int __init ni52_probe1(struct net_device *dev,int ioaddr) { int i, size, retval; if (!request_region(ioaddr, NI52_TOTAL_SIZE, dev->name)) return -EBUSY; if( !(inb(ioaddr+NI52_MAGIC1) == NI52_MAGICVAL1) || !(inb(ioaddr+NI52_MAGIC2) == NI52_MAGICVAL2)) { retval = -ENODEV; goto out; } for(i=0;i<ETH_ALEN;i++) dev->dev_addr[i] = inb(dev->base_addr+i); if(dev->dev_addr[0] != NI52_ADDR0 || dev->dev_addr[1] != NI52_ADDR1 || dev->dev_addr[2] != NI52_ADDR2) { retval = -ENODEV; goto out; } printk("%s: NI5210 found at %#3lx, ",dev->name,dev->base_addr); /* * check (or search) IO-Memory, 8K and 16K */ #ifdef MODULE size = dev->mem_end - dev->mem_start; if(size != 0x2000 && size != 0x4000) { printk("\n%s: Illegal memory size %d. Allowed is 0x2000 or 0x4000 bytes.\n",dev->name,size); retval = -ENODEV; goto out; } if(!check586(dev,(char *) dev->mem_start,size)) { printk("?memcheck, Can't find memory at 0x%lx with size %d!\n",dev->mem_start,size); retval = -ENODEV; goto out; } #else if(dev->mem_start != 0) /* no auto-mem-probe */ { size = 0x4000; /* check for 16K mem */ if(!check586(dev,(char *) dev->mem_start,size)) { size = 0x2000; /* check for 8K mem */ if(!check586(dev,(char *) dev->mem_start,size)) { printk("?memprobe, Can't find memory at 0x%lx!\n",dev->mem_start); retval = -ENODEV; goto out; } } } else { static long memaddrs[] = { 0xc8000,0xca000,0xcc000,0xce000,0xd0000,0xd2000, 0xd4000,0xd6000,0xd8000,0xda000,0xdc000, 0 }; for(i=0;;i++) { if(!memaddrs[i]) { printk("?memprobe, Can't find io-memory!\n"); retval = -ENODEV; goto out; } dev->mem_start = memaddrs[i]; size = 0x2000; /* check for 8K mem */ if(check586(dev,(char *)dev->mem_start,size)) /* 8K-check */ break; size = 0x4000; /* check for 16K mem */ if(check586(dev,(char *)dev->mem_start,size)) /* 16K-check */ break; } } dev->mem_end = dev->mem_start + size; /* set mem_end showed by 'ifconfig' */ #endif dev->priv = (void *) kmalloc(sizeof(struct priv),GFP_KERNEL); if(dev->priv == NULL) { printk("%s: Ooops .. can't allocate private driver memory.\n",dev->name); retval = -ENOMEM; goto out; } /* warning: we don't free it on errors */ memset((char *) dev->priv,0,sizeof(struct priv)); ((struct priv *) (dev->priv))->memtop = isa_bus_to_virt(dev->mem_start) + size; ((struct priv *) (dev->priv))->base = (unsigned long) isa_bus_to_virt(dev->mem_start) + size - 0x01000000; alloc586(dev); /* set number of receive-buffs according to memsize */ if(size == 0x2000) ((struct priv *) dev->priv)->num_recv_buffs = NUM_RECV_BUFFS_8; else ((struct priv *) dev->priv)->num_recv_buffs = NUM_RECV_BUFFS_16; printk("Memaddr: 0x%lx, Memsize: %d, ",dev->mem_start,size); if(dev->irq < 2) { unsigned long irq_mask; irq_mask = probe_irq_on(); ni_reset586(); ni_attn586(); mdelay(20); dev->irq = probe_irq_off(irq_mask); if(!dev->irq) { printk("?autoirq, Failed to detect IRQ line!\n"); kfree(dev->priv); dev->priv = NULL; retval = -EAGAIN; goto out; } printk("IRQ %d (autodetected).\n",dev->irq); } else { if(dev->irq == 2) dev->irq = 9; printk("IRQ %d (assigned and not checked!).\n",dev->irq); } dev->open = ni52_open; dev->stop = ni52_close; dev->get_stats = ni52_get_stats; dev->tx_timeout = ni52_timeout; dev->watchdog_timeo = HZ/20; dev->hard_start_xmit = ni52_send_packet; dev->set_multicast_list = set_multicast_list; dev->if_port = 0; ether_setup(dev); return 0; out: release_region(ioaddr, NI52_TOTAL_SIZE); return retval; }
static int __init ni52_probe1(struct net_device *dev, int ioaddr) { int i, size, retval; struct priv *priv = netdev_priv(dev); dev->base_addr = ioaddr; dev->irq = irq; dev->mem_start = memstart; dev->mem_end = memend; spin_lock_init(&priv->spinlock); if (!request_region(ioaddr, NI52_TOTAL_SIZE, DRV_NAME)) return -EBUSY; if (!(inb(ioaddr+NI52_MAGIC1) == NI52_MAGICVAL1) || !(inb(ioaddr+NI52_MAGIC2) == NI52_MAGICVAL2)) { retval = -ENODEV; goto out; } for (i = 0; i < ETH_ALEN; i++) dev->dev_addr[i] = inb(dev->base_addr+i); if (dev->dev_addr[0] != NI52_ADDR0 || dev->dev_addr[1] != NI52_ADDR1 || dev->dev_addr[2] != NI52_ADDR2) { retval = -ENODEV; goto out; } printk(KERN_INFO "%s: NI5210 found at %#3lx, ", dev->name, dev->base_addr); /* */ #ifdef MODULE size = dev->mem_end - dev->mem_start; if (size != 0x2000 && size != 0x4000) { printk("\n"); printk(KERN_ERR "%s: Invalid memory size %d. Allowed is 0x2000 or 0x4000 bytes.\n", dev->name, size); retval = -ENODEV; goto out; } if (!check586(dev, size)) { printk(KERN_ERR "?memcheck, Can't find memory at 0x%lx with size %d!\n", dev->mem_start, size); retval = -ENODEV; goto out; } #else if (dev->mem_start != 0) { /* */ size = 0x4000; /* */ if (!check586(dev, size)) { size = 0x2000; /* */ if (!check586(dev, size)) { printk(KERN_ERR "?memprobe, Can't find memory at 0x%lx!\n", dev->mem_start); retval = -ENODEV; goto out; } } } else { static const unsigned long memaddrs[] = { 0xc8000, 0xca000, 0xcc000, 0xce000, 0xd0000, 0xd2000, 0xd4000, 0xd6000, 0xd8000, 0xda000, 0xdc000, 0 }; for (i = 0;; i++) { if (!memaddrs[i]) { printk(KERN_ERR "?memprobe, Can't find io-memory!\n"); retval = -ENODEV; goto out; } dev->mem_start = memaddrs[i]; size = 0x2000; /* */ if (check586(dev, size)) /* */ break; size = 0x4000; /* */ if (check586(dev, size)) /* */ break; } } /* */ dev->mem_end = dev->mem_start + size; #endif alloc586(dev); /* */ if (size == 0x2000) priv->num_recv_buffs = NUM_RECV_BUFFS_8; else priv->num_recv_buffs = NUM_RECV_BUFFS_16; printk(KERN_DEBUG "Memaddr: 0x%lx, Memsize: %d, ", dev->mem_start, size); if (dev->irq < 2) { unsigned long irq_mask; irq_mask = probe_irq_on(); ni_reset586(); ni_attn586(); mdelay(20); dev->irq = probe_irq_off(irq_mask); if (!dev->irq) { printk("?autoirq, Failed to detect IRQ line!\n"); retval = -EAGAIN; iounmap(priv->mapped); goto out; } printk("IRQ %d (autodetected).\n", dev->irq); } else { if (dev->irq == 2) dev->irq = 9; printk("IRQ %d (assigned and not checked!).\n", dev->irq); } dev->netdev_ops = &ni52_netdev_ops; dev->watchdog_timeo = HZ/20; return 0; out: release_region(ioaddr, NI52_TOTAL_SIZE); return retval; }
static int ni52_probe1(struct device *dev,int ioaddr) { long memaddrs[] = { 0xd0000,0xd2000,0xd4000,0xd6000,0xd8000, 0 }; int i,size; for(i=0;i<ETH_ALEN;i++) dev->dev_addr[i] = inb(dev->base_addr+i); if(dev->dev_addr[0] != NI52_ADDR0 || dev->dev_addr[1] != NI52_ADDR1 || dev->dev_addr[2] != NI52_ADDR2) return ENODEV; printk("%s: Ni52 found at %#3x, ",dev->name,dev->base_addr); snarf_region(ioaddr,NI52_TOTAL_SIZE); dev->priv = (void *) kmalloc(sizeof(struct priv),GFP_KERNEL); /* warning: we don't free it on errors */ memset((char *) dev->priv,0,sizeof(struct priv)); /* * check (or search) IO-Memory, 8K and 16K */ if(dev->mem_start != 0) /* no auto-mem-probe */ { size = 0x4000; if(!check586(dev,(char *) dev->mem_start,size)) { size = 0x2000; if(!check586(dev,(char *) dev->mem_start,size)) { printk("?memprobe, Can't find memory at 0x%lx!\n",dev->mem_start); return ENODEV; } } } else { for(i=0;;i++) { if(!memaddrs[i]) { printk("?memprobe, Can't find io-memory!\n"); return ENODEV; } dev->mem_start = memaddrs[i]; size = 0x2000; if(check586(dev,(char *)dev->mem_start,size)) /* 8K-check */ break; size = 0x4000; if(check586(dev,(char *)dev->mem_start,size)) /* 16K-check */ break; } } ((struct priv *) (dev->priv))->base = dev->mem_start + size - 0x01000000; alloc586(dev); printk("Memaddr: 0x%lx, Memsize: %d, ",dev->mem_start,size); if(dev->irq < 2) { autoirq_setup(0); ni_reset586(); ni_attn586(); if(!(dev->irq = autoirq_report(2))) { printk("?autoirq, Failed to detect IRQ line!\n"); return 1; } } else if(dev->irq == 2) dev->irq = 9; printk("IRQ %d.\n",dev->irq); dev->open = &ni52_open; dev->stop = &ni52_close; dev->get_stats = &ni52_get_stats; dev->hard_start_xmit = &ni52_send_packet; dev->set_multicast_list = &set_multicast_list; dev->if_port = 0; ether_setup(dev); dev->tbusy = 0; dev->interrupt = 0; dev->start = 0; return 0; }