[PATCH] DVB core update
[linux-2.6/history.git] / drivers / net / hydra.c
blob45640b23027b95c6dc2ca92173e48edb7cb3ff97
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) */
9 /* Oldenburg 2000 */
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>
27 #include <asm/bitops.h>
28 #include <asm/io.h>
29 #include <asm/irq.h>
30 #include <asm/amigaints.h>
31 #include <asm/amigahw.h>
32 #include <linux/zorro.h>
34 #include "8390.h"
36 #define NE_BASE (dev->base_addr)
37 #define NE_CMD (0x00*2)
39 #define NE_EN0_ISR (0x07*2)
40 #define NE_EN0_DCFG (0x0e*2)
42 #define NE_EN0_RSARLO (0x08*2)
43 #define NE_EN0_RSARHI (0x09*2)
44 #define NE_EN0_RCNTLO (0x0a*2)
45 #define NE_EN0_RXCR (0x0c*2)
46 #define NE_EN0_TXCR (0x0d*2)
47 #define NE_EN0_RCNTHI (0x0b*2)
48 #define NE_EN0_IMR (0x0f*2)
50 #define NESM_START_PG 0x0 /* First page of TX buffer */
51 #define NESM_STOP_PG 0x40 /* Last page +1 of RX ring */
53 #define HYDRA_NIC_BASE 0xffe1
54 #define HYDRA_ADDRPROM 0xffc0
55 #define HYDRA_VERSION "v3.0alpha"
57 #define WORDSWAP(a) ((((a)>>8)&0xff) | ((a)<<8))
59 #ifdef MODULE
60 static struct net_device *root_hydra_dev;
61 #endif
63 static int __init hydra_probe(void);
64 static int hydra_init(unsigned long board);
65 static int hydra_open(struct net_device *dev);
66 static int hydra_close(struct net_device *dev);
67 static void hydra_reset_8390(struct net_device *dev);
68 static void hydra_get_8390_hdr(struct net_device *dev,
69 struct e8390_pkt_hdr *hdr, int ring_page);
70 static void hydra_block_input(struct net_device *dev, int count,
71 struct sk_buff *skb, int ring_offset);
72 static void hydra_block_output(struct net_device *dev, int count,
73 const unsigned char *buf, int start_page);
74 static void __exit hydra_cleanup(void);
76 static int __init hydra_probe(void)
78 struct zorro_dev *z = NULL;
79 unsigned long board;
80 int err = -ENODEV;
82 while ((z = zorro_find_device(ZORRO_PROD_HYDRA_SYSTEMS_AMIGANET, z))) {
83 board = z->resource.start;
84 if (!request_mem_region(board, 0x10000, "Hydra"))
85 continue;
86 if ((err = hydra_init(ZTWO_VADDR(board)))) {
87 release_mem_region(board, 0x10000);
88 return err;
90 err = 0;
93 if (err == -ENODEV)
94 printk("No Hydra ethernet card found.\n");
96 return err;
99 int __init hydra_init(unsigned long board)
101 struct net_device *dev;
102 unsigned long ioaddr = board+HYDRA_NIC_BASE;
103 const char *name = NULL;
104 int start_page, stop_page;
105 int j;
107 static u32 hydra_offsets[16] = {
108 0x00, 0x02, 0x04, 0x06, 0x08, 0x0a, 0x0c, 0x0e,
109 0x10, 0x12, 0x14, 0x16, 0x18, 0x1a, 0x1c, 0x1e,
112 dev = init_etherdev(NULL, 0);
113 if (!dev)
114 return -ENOMEM;
115 SET_MODULE_OWNER(dev);
117 for(j = 0; j < ETHER_ADDR_LEN; j++)
118 dev->dev_addr[j] = *((u8 *)(board + HYDRA_ADDRPROM + 2*j));
120 /* We must set the 8390 for word mode. */
121 z_writeb(0x4b, ioaddr + NE_EN0_DCFG);
122 start_page = NESM_START_PG;
123 stop_page = NESM_STOP_PG;
125 dev->base_addr = ioaddr;
126 dev->irq = IRQ_AMIGA_PORTS;
128 /* Install the Interrupt handler */
129 if (request_irq(IRQ_AMIGA_PORTS, ei_interrupt, SA_SHIRQ, "Hydra Ethernet",
130 dev))
131 return -EAGAIN;
133 /* Allocate dev->priv and fill in 8390 specific dev fields. */
134 if (ethdev_init(dev)) {
135 printk("Unable to get memory for dev->priv.\n");
136 return -ENOMEM;
139 name = "NE2000";
141 printk("%s: hydra at 0x%08lx, address %02x:%02x:%02x:%02x:%02x:%02x (hydra.c " HYDRA_VERSION ")\n", dev->name, ZTWO_PADDR(board),
142 dev->dev_addr[0], dev->dev_addr[1], dev->dev_addr[2],
143 dev->dev_addr[3], dev->dev_addr[4], dev->dev_addr[5]);
145 ei_status.name = name;
146 ei_status.tx_start_page = start_page;
147 ei_status.stop_page = stop_page;
148 ei_status.word16 = 1;
149 ei_status.bigendian = 1;
151 ei_status.rx_start_page = start_page + TX_PAGES;
153 ei_status.reset_8390 = &hydra_reset_8390;
154 ei_status.block_input = &hydra_block_input;
155 ei_status.block_output = &hydra_block_output;
156 ei_status.get_8390_hdr = &hydra_get_8390_hdr;
157 ei_status.reg_offset = hydra_offsets;
158 dev->open = &hydra_open;
159 dev->stop = &hydra_close;
160 #ifdef MODULE
161 ei_status.priv = (unsigned long)root_hydra_dev;
162 root_hydra_dev = dev;
163 #endif
164 NS8390_init(dev, 0);
165 return 0;
168 static int hydra_open(struct net_device *dev)
170 ei_open(dev);
171 return 0;
174 static int hydra_close(struct net_device *dev)
176 if (ei_debug > 1)
177 printk("%s: Shutting down ethercard.\n", dev->name);
178 ei_close(dev);
179 return 0;
182 static void hydra_reset_8390(struct net_device *dev)
184 printk("Hydra hw reset not there\n");
187 static void hydra_get_8390_hdr(struct net_device *dev,
188 struct e8390_pkt_hdr *hdr, int ring_page)
190 int nic_base = dev->base_addr;
191 short *ptrs;
192 unsigned long hdr_start= (nic_base-HYDRA_NIC_BASE) +
193 ((ring_page - NESM_START_PG)<<8);
194 ptrs = (short *)hdr;
196 *(ptrs++) = z_readw(hdr_start);
197 *((short *)hdr) = WORDSWAP(*((short *)hdr));
198 hdr_start += 2;
199 *(ptrs++) = z_readw(hdr_start);
200 *((short *)hdr+1) = WORDSWAP(*((short *)hdr+1));
203 static void hydra_block_input(struct net_device *dev, int count,
204 struct sk_buff *skb, int ring_offset)
206 unsigned long nic_base = dev->base_addr;
207 unsigned long mem_base = nic_base - HYDRA_NIC_BASE;
208 unsigned long xfer_start = mem_base + ring_offset - (NESM_START_PG<<8);
210 if (count&1)
211 count++;
213 if (xfer_start+count > mem_base + (NESM_STOP_PG<<8)) {
214 int semi_count = (mem_base + (NESM_STOP_PG<<8)) - xfer_start;
216 z_memcpy_fromio(skb->data,xfer_start,semi_count);
217 count -= semi_count;
218 z_memcpy_fromio(skb->data+semi_count, mem_base, count);
219 } else
220 z_memcpy_fromio(skb->data, xfer_start,count);
224 static void hydra_block_output(struct net_device *dev, int count,
225 const unsigned char *buf, int start_page)
227 unsigned long nic_base = dev->base_addr;
228 unsigned long mem_base = nic_base - HYDRA_NIC_BASE;
230 if (count&1)
231 count++;
233 z_memcpy_toio(mem_base+((start_page - NESM_START_PG)<<8), buf, count);
236 static void __exit hydra_cleanup(void)
238 #ifdef MODULE
239 struct net_device *dev, *next;
241 while ((dev = root_hydra_dev)) {
242 next = (struct net_device *)(ei_status.priv);
243 unregister_netdev(dev);
244 free_irq(IRQ_AMIGA_PORTS, dev);
245 release_mem_region(ZTWO_PADDR(dev->base_addr)-HYDRA_NIC_BASE, 0x10000);
246 kfree(dev);
247 root_hydra_dev = next;
249 #endif
252 module_init(hydra_probe);
253 module_exit(hydra_cleanup);
254 MODULE_LICENSE("GPL");