Exemple #1
0
static int __init znet_probe (void)
{
	int i;
	struct netidblk *netinfo;
	struct znet_private *znet;
	struct net_device *dev;
	char *p;
	int err = -ENOMEM;

	/* This code scans the region 0xf0000 to 0xfffff for a "NETIDBLK". */
	for(p = (char *)phys_to_virt(0xf0000); p < (char *)phys_to_virt(0x100000); p++)
		if (*p == 'N'  &&  strncmp(p, "NETIDBLK", 8) == 0)
			break;

	if (p >= (char *)phys_to_virt(0x100000)) {
		if (znet_debug > 1)
			printk(KERN_INFO "No Z-Note ethernet adaptor found.\n");
		return -ENODEV;
	}

	dev = alloc_etherdev(sizeof(struct znet_private));
	if (!dev)
		return -ENOMEM;

	znet = netdev_priv(dev);

	netinfo = (struct netidblk *)p;
	dev->base_addr = netinfo->iobase1;
	dev->irq = netinfo->irq1;

	/* The station address is in the "netidblk" at 0x0f0000. */
	for (i = 0; i < 6; i++)
		dev->dev_addr[i] = netinfo->netid[i];

	printk(KERN_INFO "%s: ZNET at %#3lx, %pM"
	       ", using IRQ %d DMA %d and %d.\n",
	       dev->name, dev->base_addr, dev->dev_addr,
	       dev->irq, netinfo->dma1, netinfo->dma2);

	if (znet_debug > 1) {
		printk(KERN_INFO "%s: vendor '%16.16s' IRQ1 %d IRQ2 %d DMA1 %d DMA2 %d.\n",
		       dev->name, netinfo->vendor,
		       netinfo->irq1, netinfo->irq2,
		       netinfo->dma1, netinfo->dma2);
		printk(KERN_INFO "%s: iobase1 %#x size %d iobase2 %#x size %d net type %2.2x.\n",
		       dev->name, netinfo->iobase1, netinfo->iosize1,
		       netinfo->iobase2, netinfo->iosize2, netinfo->nettype);
	}

	if (znet_debug > 0)
		printk(KERN_INFO "%s", version);

	znet->rx_dma = netinfo->dma1;
	znet->tx_dma = netinfo->dma2;
	spin_lock_init(&znet->lock);
	znet->sia_base = 0xe6;	/* Magic address for the 82501 SIA */
	znet->sia_size = 2;
	/* maz: Despite the '593 being advertised above as using a
	 * single 8bits I/O port, this driver does many 16bits
	 * access. So set io_size accordingly */
	znet->io_size  = 2;

	if (!(znet->rx_start = kmalloc (DMA_BUF_SIZE, GFP_KERNEL | GFP_DMA)))
		goto free_dev;
	if (!(znet->tx_start = kmalloc (DMA_BUF_SIZE, GFP_KERNEL | GFP_DMA)))
		goto free_rx;

	if (!dma_page_eq (znet->rx_start, znet->rx_start + (RX_BUF_SIZE/2-1)) ||
	    !dma_page_eq (znet->tx_start, znet->tx_start + (TX_BUF_SIZE/2-1))) {
		printk (KERN_WARNING "tx/rx crossing DMA frontiers, giving up\n");
		goto free_tx;
	}

	znet->rx_end = znet->rx_start + RX_BUF_SIZE/2;
	znet->tx_buf_len = TX_BUF_SIZE/2;
	znet->tx_end = znet->tx_start + znet->tx_buf_len;

	/* The ZNET-specific entries in the device structure. */
	dev->netdev_ops = &znet_netdev_ops;
	dev->watchdog_timeo = TX_TIMEOUT;
	err = register_netdev(dev);
	if (err)
		goto free_tx;
	znet_dev = dev;
	return 0;

 free_tx:
	kfree(znet->tx_start);
 free_rx:
	kfree(znet->rx_start);
 free_dev:
	free_netdev(dev);
	return err;
}
Exemple #2
0
int znet_probe(struct device *dev)
{
	int i;
	struct netidblk *netinfo;
	char *p;

	/* This code scans the region 0xf0000 to 0xfffff for a "NETIDBLK". */
	for(p = (char *)0xf0000; p < (char *)0x100000; p++)
		if (*p == 'N'  &&  strncmp(p, "NETIDBLK", 8) == 0)
			break;

	if (p >= (char *)0x100000) {
		if (znet_debug > 1)
			printk(KERN_INFO "No Z-Note ethernet adaptor found.\n");
		return ENODEV;
	}
	netinfo = (struct netidblk *)p;
	dev->base_addr = netinfo->iobase1;
	dev->irq = netinfo->irq1;

	printk(KERN_INFO "%s: ZNET at %#3lx,", dev->name, dev->base_addr);

	/* The station address is in the "netidblk" at 0x0f0000. */
	for (i = 0; i < 6; i++)
		printk(" %2.2x", dev->dev_addr[i] = netinfo->netid[i]);

	printk(", using IRQ %d DMA %d and %d.\n", dev->irq, netinfo->dma1,
		netinfo->dma2);

	if (znet_debug > 1) {
		printk(KERN_INFO "%s: vendor '%16.16s' IRQ1 %d IRQ2 %d DMA1 %d DMA2 %d.\n",
			   dev->name, netinfo->vendor,
			   netinfo->irq1, netinfo->irq2,
			   netinfo->dma1, netinfo->dma2);
		printk(KERN_INFO "%s: iobase1 %#x size %d iobase2 %#x size %d net type %2.2x.\n",
			   dev->name, netinfo->iobase1, netinfo->iosize1,
			   netinfo->iobase2, netinfo->iosize2, netinfo->nettype);
	}

	if (znet_debug > 0)
		printk("%s%s", KERN_INFO, version);

	dev->priv = (void *) &zn;
	zn.rx_dma = netinfo->dma1;
	zn.tx_dma = netinfo->dma2;

	/* These should never fail.  You can't add devices to a sealed box! */
	if (request_irq(dev->irq, &znet_interrupt, 0, "ZNet")
		|| request_dma(zn.rx_dma,"ZNet rx")
		|| request_dma(zn.tx_dma,"ZNet tx")) {
		printk(KERN_WARNING "%s: Not opened -- resource busy?!?\n", dev->name);
		return EBUSY;
	}
	irq2dev_map[dev->irq] = dev;

	/* Allocate buffer memory.	We can cross a 128K boundary, so we
	   must be careful about the allocation.  It's easiest to waste 8K. */
	if (dma_page_eq(dma_buffer1, &dma_buffer1[RX_BUF_SIZE/2-1]))
	  zn.rx_start = dma_buffer1;
	else 
	  zn.rx_start = dma_buffer2;

	if (dma_page_eq(dma_buffer3, &dma_buffer3[RX_BUF_SIZE/2-1]))
	  zn.tx_start = dma_buffer3;
	else
	  zn.tx_start = dma_buffer2;
	zn.rx_end = zn.rx_start + RX_BUF_SIZE/2;
	zn.tx_buf_len = TX_BUF_SIZE/2;
	zn.tx_end = zn.tx_start + zn.tx_buf_len;

	/* The ZNET-specific entries in the device structure. */
	dev->open = &znet_open;
	dev->hard_start_xmit = &znet_send_packet;
	dev->stop = &znet_close;
	dev->get_stats	= net_get_stats;
	dev->set_multicast_list = &set_multicast_list;

	/* Fill in the 'dev' with ethernet-generic values. */
	ether_setup(dev);

	return 0;
}