1 /* New Hydra driver using generic 8390 core */
2 /* Based on old hydra driver by Topi Kanerva (topi@susanna.oulu.fi) */
4 /* This file is subject to the terms and conditions of the GNU General */
5 /* Public License. See the file COPYING in the main directory of the */
6 /* Linux distribution for more details. */
8 /* Peter De Schrijver (p2@mind.be) */
11 /* The Amiganet is a Zorro-II board made by Hydra Systems. It contains a */
12 /* NS8390 NIC (network interface controller) clone, 16 or 64K on-board RAM */
13 /* and 10BASE-2 (thin coax) and AUI connectors. */
15 #include <linux/module.h>
16 #include <linux/kernel.h>
17 #include <linux/string.h>
18 #include <linux/errno.h>
19 #include <linux/ioport.h>
20 #include <linux/slab.h>
21 #include <linux/interrupt.h>
22 #include <linux/netdevice.h>
23 #include <linux/etherdevice.h>
24 #include <linux/skbuff.h>
25 #include <linux/init.h>
26 #include <linux/bitops.h>
30 #include <asm/amigaints.h>
31 #include <asm/amigahw.h>
32 #include <linux/zorro.h>
36 #define NE_EN0_DCFG (0x0e*2)
38 #define NESM_START_PG 0x0 /* First page of TX buffer */
39 #define NESM_STOP_PG 0x40 /* Last page +1 of RX ring */
41 #define HYDRA_NIC_BASE 0xffe1
42 #define HYDRA_ADDRPROM 0xffc0
43 #define HYDRA_VERSION "v3.0alpha"
45 #define WORDSWAP(a) ((((a)>>8)&0xff) | ((a)<<8))
48 static int __devinit hydra_init_one(struct zorro_dev *z,
49 const struct zorro_device_id *ent);
50 static int __devinit hydra_init(struct zorro_dev *z);
51 static int hydra_open(struct net_device *dev);
52 static int hydra_close(struct net_device *dev);
53 static void hydra_reset_8390(struct net_device *dev);
54 static void hydra_get_8390_hdr(struct net_device *dev,
55 struct e8390_pkt_hdr *hdr, int ring_page);
56 static void hydra_block_input(struct net_device *dev, int count,
57 struct sk_buff *skb, int ring_offset);
58 static void hydra_block_output(struct net_device *dev, int count,
59 const unsigned char *buf, int start_page);
60 static void __devexit hydra_remove_one(struct zorro_dev *z);
62 static struct zorro_device_id hydra_zorro_tbl[] __devinitdata = {
63 { ZORRO_PROD_HYDRA_SYSTEMS_AMIGANET },
67 static struct zorro_driver hydra_driver = {
69 .id_table = hydra_zorro_tbl,
70 .probe = hydra_init_one,
71 .remove = __devexit_p(hydra_remove_one),
74 static int __devinit hydra_init_one(struct zorro_dev *z,
75 const struct zorro_device_id *ent)
79 if (!request_mem_region(z->resource.start, 0x10000, "Hydra"))
81 if ((err = hydra_init(z))) {
82 release_mem_region(z->resource.start, 0x10000);
88 static int __devinit hydra_init(struct zorro_dev *z)
90 struct net_device *dev;
91 unsigned long board = ZTWO_VADDR(z->resource.start);
92 unsigned long ioaddr = board+HYDRA_NIC_BASE;
93 const char name[] = "NE2000";
94 int start_page, stop_page;
98 static u32 hydra_offsets[16] = {
99 0x00, 0x02, 0x04, 0x06, 0x08, 0x0a, 0x0c, 0x0e,
100 0x10, 0x12, 0x14, 0x16, 0x18, 0x1a, 0x1c, 0x1e,
103 dev = alloc_ei_netdev();
106 SET_MODULE_OWNER(dev);
108 for(j = 0; j < ETHER_ADDR_LEN; j++)
109 dev->dev_addr[j] = *((u8 *)(board + HYDRA_ADDRPROM + 2*j));
111 /* We must set the 8390 for word mode. */
112 z_writeb(0x4b, ioaddr + NE_EN0_DCFG);
113 start_page = NESM_START_PG;
114 stop_page = NESM_STOP_PG;
116 dev->base_addr = ioaddr;
117 dev->irq = IRQ_AMIGA_PORTS;
119 /* Install the Interrupt handler */
120 if (request_irq(IRQ_AMIGA_PORTS, ei_interrupt, SA_SHIRQ, "Hydra Ethernet",
126 ei_status.name = name;
127 ei_status.tx_start_page = start_page;
128 ei_status.stop_page = stop_page;
129 ei_status.word16 = 1;
130 ei_status.bigendian = 1;
132 ei_status.rx_start_page = start_page + TX_PAGES;
134 ei_status.reset_8390 = &hydra_reset_8390;
135 ei_status.block_input = &hydra_block_input;
136 ei_status.block_output = &hydra_block_output;
137 ei_status.get_8390_hdr = &hydra_get_8390_hdr;
138 ei_status.reg_offset = hydra_offsets;
139 dev->open = &hydra_open;
140 dev->stop = &hydra_close;
141 #ifdef CONFIG_NET_POLL_CONTROLLER
142 dev->poll_controller = ei_poll;
147 err = register_netdev(dev);
149 free_irq(IRQ_AMIGA_PORTS, dev);
154 zorro_set_drvdata(z, dev);
156 printk(KERN_INFO "%s: Hydra at 0x%08lx, address "
157 "%02x:%02x:%02x:%02x:%02x:%02x (hydra.c " HYDRA_VERSION ")\n",
158 dev->name, z->resource.start, dev->dev_addr[0], dev->dev_addr[1],
159 dev->dev_addr[2], dev->dev_addr[3], dev->dev_addr[4],
165 static int hydra_open(struct net_device *dev)
171 static int hydra_close(struct net_device *dev)
174 printk(KERN_DEBUG "%s: Shutting down ethercard.\n", dev->name);
179 static void hydra_reset_8390(struct net_device *dev)
181 printk(KERN_INFO "Hydra hw reset not there\n");
184 static void hydra_get_8390_hdr(struct net_device *dev,
185 struct e8390_pkt_hdr *hdr, int ring_page)
187 int nic_base = dev->base_addr;
189 unsigned long hdr_start= (nic_base-HYDRA_NIC_BASE) +
190 ((ring_page - NESM_START_PG)<<8);
193 *(ptrs++) = z_readw(hdr_start);
194 *((short *)hdr) = WORDSWAP(*((short *)hdr));
196 *(ptrs++) = z_readw(hdr_start);
197 *((short *)hdr+1) = WORDSWAP(*((short *)hdr+1));
200 static void hydra_block_input(struct net_device *dev, int count,
201 struct sk_buff *skb, int ring_offset)
203 unsigned long nic_base = dev->base_addr;
204 unsigned long mem_base = nic_base - HYDRA_NIC_BASE;
205 unsigned long xfer_start = mem_base + ring_offset - (NESM_START_PG<<8);
210 if (xfer_start+count > mem_base + (NESM_STOP_PG<<8)) {
211 int semi_count = (mem_base + (NESM_STOP_PG<<8)) - xfer_start;
213 z_memcpy_fromio(skb->data,xfer_start,semi_count);
215 z_memcpy_fromio(skb->data+semi_count, mem_base, count);
217 z_memcpy_fromio(skb->data, xfer_start,count);
221 static void hydra_block_output(struct net_device *dev, int count,
222 const unsigned char *buf, int start_page)
224 unsigned long nic_base = dev->base_addr;
225 unsigned long mem_base = nic_base - HYDRA_NIC_BASE;
230 z_memcpy_toio(mem_base+((start_page - NESM_START_PG)<<8), buf, count);
233 static void __devexit hydra_remove_one(struct zorro_dev *z)
235 struct net_device *dev = zorro_get_drvdata(z);
237 unregister_netdev(dev);
238 free_irq(IRQ_AMIGA_PORTS, dev);
239 release_mem_region(ZTWO_PADDR(dev->base_addr)-HYDRA_NIC_BASE, 0x10000);
243 static int __init hydra_init_module(void)
245 return zorro_module_init(&hydra_driver);
248 static void __exit hydra_cleanup_module(void)
250 zorro_unregister_driver(&hydra_driver);
253 module_init(hydra_init_module);
254 module_exit(hydra_cleanup_module);
256 MODULE_LICENSE("GPL");