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/sched.h>
18 #include <linux/string.h>
19 #include <linux/ptrace.h>
20 #include <linux/errno.h>
21 #include <linux/ioport.h>
22 #include <linux/slab.h>
23 #include <linux/interrupt.h>
24 #include <linux/netdevice.h>
25 #include <linux/etherdevice.h>
26 #include <linux/skbuff.h>
27 #include <linux/init.h>
29 #include <asm/bitops.h>
33 #include <asm/amigaints.h>
34 #include <asm/amigahw.h>
35 #include <linux/zorro.h>
39 #define NE_BASE (dev->base_addr)
40 #define NE_CMD (0x00*2)
42 #define NE_EN0_ISR (0x07*2)
43 #define NE_EN0_DCFG (0x0e*2)
45 #define NE_EN0_RSARLO (0x08*2)
46 #define NE_EN0_RSARHI (0x09*2)
47 #define NE_EN0_RCNTLO (0x0a*2)
48 #define NE_EN0_RXCR (0x0c*2)
49 #define NE_EN0_TXCR (0x0d*2)
50 #define NE_EN0_RCNTHI (0x0b*2)
51 #define NE_EN0_IMR (0x0f*2)
53 #define NESM_START_PG 0x0 /* First page of TX buffer */
54 #define NESM_STOP_PG 0x40 /* Last page +1 of RX ring */
56 #define HYDRA_NIC_BASE 0xffe1
57 #define HYDRA_ADDRPROM 0xffc0
58 #define HYDRA_VERSION "v3.0alpha"
60 #define WORDSWAP(a) ((((a)>>8)&0xff) | ((a)<<8))
63 static struct net_device *root_hydra_dev;
66 static int __init hydra_probe(void);
67 static int hydra_init(unsigned long board);
68 static int hydra_open(struct net_device *dev);
69 static int hydra_close(struct net_device *dev);
70 static void hydra_reset_8390(struct net_device *dev);
71 static void hydra_get_8390_hdr(struct net_device *dev,
72 struct e8390_pkt_hdr *hdr, int ring_page);
73 static void hydra_block_input(struct net_device *dev, int count,
74 struct sk_buff *skb, int ring_offset);
75 static void hydra_block_output(struct net_device *dev, int count,
76 const unsigned char *buf, int start_page);
77 static void __exit hydra_cleanup(void);
79 static int __init hydra_probe(void)
81 struct zorro_dev *z = NULL;
85 while ((z = zorro_find_device(ZORRO_PROD_HYDRA_SYSTEMS_AMIGANET, z))) {
86 board = z->resource.start;
87 if (!request_mem_region(board, 0x10000, "Hydra"))
89 if ((err = hydra_init(ZTWO_VADDR(board)))) {
90 release_mem_region(board, 0x10000);
97 printk("No Hydra ethernet card found.\n");
102 int __init hydra_init(unsigned long board)
104 struct net_device *dev;
105 unsigned long ioaddr = board+HYDRA_NIC_BASE;
106 const char *name = NULL;
107 int start_page, stop_page;
110 static u32 hydra_offsets[16] = {
111 0x00, 0x02, 0x04, 0x06, 0x08, 0x0a, 0x0c, 0x0e,
112 0x10, 0x12, 0x14, 0x16, 0x18, 0x1a, 0x1c, 0x1e,
115 dev = init_etherdev(NULL, 0);
118 SET_MODULE_OWNER(dev);
120 for(j = 0; j < ETHER_ADDR_LEN; j++)
121 dev->dev_addr[j] = *((u8 *)(board + HYDRA_ADDRPROM + 2*j));
123 /* We must set the 8390 for word mode. */
124 z_writeb(0x4b, ioaddr + NE_EN0_DCFG);
125 start_page = NESM_START_PG;
126 stop_page = NESM_STOP_PG;
128 dev->base_addr = ioaddr;
129 dev->irq = IRQ_AMIGA_PORTS;
131 /* Install the Interrupt handler */
132 if (request_irq(IRQ_AMIGA_PORTS, ei_interrupt, SA_SHIRQ, "Hydra Ethernet",
136 /* Allocate dev->priv and fill in 8390 specific dev fields. */
137 if (ethdev_init(dev)) {
138 printk("Unable to get memory for dev->priv.\n");
144 printk("%s: hydra at 0x%08lx, address %02x:%02x:%02x:%02x:%02x:%02x (hydra.c " HYDRA_VERSION ")\n", dev->name, ZTWO_PADDR(board),
145 dev->dev_addr[0], dev->dev_addr[1], dev->dev_addr[2],
146 dev->dev_addr[3], dev->dev_addr[4], dev->dev_addr[5]);
148 ei_status.name = name;
149 ei_status.tx_start_page = start_page;
150 ei_status.stop_page = stop_page;
151 ei_status.word16 = 1;
152 ei_status.bigendian = 1;
154 ei_status.rx_start_page = start_page + TX_PAGES;
156 ei_status.reset_8390 = &hydra_reset_8390;
157 ei_status.block_input = &hydra_block_input;
158 ei_status.block_output = &hydra_block_output;
159 ei_status.get_8390_hdr = &hydra_get_8390_hdr;
160 ei_status.reg_offset = hydra_offsets;
161 dev->open = &hydra_open;
162 dev->stop = &hydra_close;
164 ei_status.priv = (unsigned long)root_hydra_dev;
165 root_hydra_dev = dev;
171 static int hydra_open(struct net_device *dev)
177 static int hydra_close(struct net_device *dev)
180 printk("%s: Shutting down ethercard.\n", dev->name);
185 static void hydra_reset_8390(struct net_device *dev)
187 printk("Hydra hw reset not there\n");
190 static void hydra_get_8390_hdr(struct net_device *dev,
191 struct e8390_pkt_hdr *hdr, int ring_page)
193 int nic_base = dev->base_addr;
195 unsigned long hdr_start= (nic_base-HYDRA_NIC_BASE) +
196 ((ring_page - NESM_START_PG)<<8);
199 *(ptrs++) = z_readw(hdr_start);
200 *((short *)hdr) = WORDSWAP(*((short *)hdr));
202 *(ptrs++) = z_readw(hdr_start);
203 *((short *)hdr+1) = WORDSWAP(*((short *)hdr+1));
206 static void hydra_block_input(struct net_device *dev, int count,
207 struct sk_buff *skb, int ring_offset)
209 unsigned long nic_base = dev->base_addr;
210 unsigned long mem_base = nic_base - HYDRA_NIC_BASE;
211 unsigned long xfer_start = mem_base + ring_offset - (NESM_START_PG<<8);
216 if (xfer_start+count > mem_base + (NESM_STOP_PG<<8)) {
217 int semi_count = (mem_base + (NESM_STOP_PG<<8)) - xfer_start;
219 z_memcpy_fromio(skb->data,xfer_start,semi_count);
221 z_memcpy_fromio(skb->data+semi_count, mem_base, count);
223 z_memcpy_fromio(skb->data, xfer_start,count);
227 static void hydra_block_output(struct net_device *dev, int count,
228 const unsigned char *buf, int start_page)
230 unsigned long nic_base = dev->base_addr;
231 unsigned long mem_base = nic_base - HYDRA_NIC_BASE;
236 z_memcpy_toio(mem_base+((start_page - NESM_START_PG)<<8), buf, count);
239 static void __exit hydra_cleanup(void)
242 struct net_device *dev, *next;
244 while ((dev = root_hydra_dev)) {
245 next = (struct net_device *)(ei_status.priv);
246 unregister_netdev(dev);
247 free_irq(IRQ_AMIGA_PORTS, dev);
248 release_mem_region(ZTWO_PADDR(dev->base_addr)-HYDRA_NIC_BASE, 0x10000);
250 root_hydra_dev = next;
255 module_init(hydra_probe);
256 module_exit(hydra_cleanup);
257 MODULE_LICENSE("GPL");