blob: d9fb8e74e631d7e019e9d61fb30a04412b3c3be9 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/* New Hydra driver using generic 8390 core */
2/* Based on old hydra driver by Topi Kanerva (topi@susanna.oulu.fi) */
3
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. */
7
8/* Peter De Schrijver (p2@mind.be) */
9/* Oldenburg 2000 */
10
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. */
14
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>
27
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>
33
34#include "8390.h"
35
36#define NE_EN0_DCFG (0x0e*2)
37
38#define NESM_START_PG 0x0 /* First page of TX buffer */
39#define NESM_STOP_PG 0x40 /* Last page +1 of RX ring */
40
41#define HYDRA_NIC_BASE 0xffe1
42#define HYDRA_ADDRPROM 0xffc0
43#define HYDRA_VERSION "v3.0alpha"
44
45#define WORDSWAP(a) ((((a)>>8)&0xff) | ((a)<<8))
46
47
48static int __devinit hydra_init_one(struct zorro_dev *z,
49 const struct zorro_device_id *ent);
50static int __devinit hydra_init(struct zorro_dev *z);
51static int hydra_open(struct net_device *dev);
52static int hydra_close(struct net_device *dev);
53static void hydra_reset_8390(struct net_device *dev);
54static void hydra_get_8390_hdr(struct net_device *dev,
55 struct e8390_pkt_hdr *hdr, int ring_page);
56static void hydra_block_input(struct net_device *dev, int count,
57 struct sk_buff *skb, int ring_offset);
58static void hydra_block_output(struct net_device *dev, int count,
59 const unsigned char *buf, int start_page);
60static void __devexit hydra_remove_one(struct zorro_dev *z);
61
62static struct zorro_device_id hydra_zorro_tbl[] __devinitdata = {
63 { ZORRO_PROD_HYDRA_SYSTEMS_AMIGANET },
64 { 0 }
65};
66
67static struct zorro_driver hydra_driver = {
68 .name = "hydra",
69 .id_table = hydra_zorro_tbl,
70 .probe = hydra_init_one,
71 .remove = __devexit_p(hydra_remove_one),
72};
73
74static int __devinit hydra_init_one(struct zorro_dev *z,
75 const struct zorro_device_id *ent)
76{
77 int err;
78
79 if (!request_mem_region(z->resource.start, 0x10000, "Hydra"))
80 return -EBUSY;
81 if ((err = hydra_init(z))) {
82 release_mem_region(z->resource.start, 0x10000);
83 return -EBUSY;
84 }
85 return 0;
86}
87
88static int __devinit hydra_init(struct zorro_dev *z)
89{
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;
95 int j;
96 int err;
97
98 static u32 hydra_offsets[16] = {
99 0x00, 0x02, 0x04, 0x06, 0x08, 0x0a, 0x0c, 0x0e,
100 0x10, 0x12, 0x14, 0x16, 0x18, 0x1a, 0x1c, 0x1e,
101 };
102
103 dev = alloc_ei_netdev();
104 if (!dev)
105 return -ENOMEM;
106 SET_MODULE_OWNER(dev);
107
108 for(j = 0; j < ETHER_ADDR_LEN; j++)
109 dev->dev_addr[j] = *((u8 *)(board + HYDRA_ADDRPROM + 2*j));
110
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;
115
116 dev->base_addr = ioaddr;
117 dev->irq = IRQ_AMIGA_PORTS;
118
119 /* Install the Interrupt handler */
120 if (request_irq(IRQ_AMIGA_PORTS, ei_interrupt, SA_SHIRQ, "Hydra Ethernet",
121 dev)) {
122 free_netdev(dev);
123 return -EAGAIN;
124 }
125
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;
131
132 ei_status.rx_start_page = start_page + TX_PAGES;
133
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;
143#endif
144
145 NS8390_init(dev, 0);
146
147 err = register_netdev(dev);
148 if (err) {
149 free_irq(IRQ_AMIGA_PORTS, dev);
150 free_netdev(dev);
151 return err;
152 }
153
154 zorro_set_drvdata(z, dev);
155
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],
160 dev->dev_addr[5]);
161
162 return 0;
163}
164
165static int hydra_open(struct net_device *dev)
166{
167 ei_open(dev);
168 return 0;
169}
170
171static int hydra_close(struct net_device *dev)
172{
173 if (ei_debug > 1)
174 printk(KERN_DEBUG "%s: Shutting down ethercard.\n", dev->name);
175 ei_close(dev);
176 return 0;
177}
178
179static void hydra_reset_8390(struct net_device *dev)
180{
181 printk(KERN_INFO "Hydra hw reset not there\n");
182}
183
184static void hydra_get_8390_hdr(struct net_device *dev,
185 struct e8390_pkt_hdr *hdr, int ring_page)
186{
187 int nic_base = dev->base_addr;
188 short *ptrs;
189 unsigned long hdr_start= (nic_base-HYDRA_NIC_BASE) +
190 ((ring_page - NESM_START_PG)<<8);
191 ptrs = (short *)hdr;
192
193 *(ptrs++) = z_readw(hdr_start);
194 *((short *)hdr) = WORDSWAP(*((short *)hdr));
195 hdr_start += 2;
196 *(ptrs++) = z_readw(hdr_start);
197 *((short *)hdr+1) = WORDSWAP(*((short *)hdr+1));
198}
199
200static void hydra_block_input(struct net_device *dev, int count,
201 struct sk_buff *skb, int ring_offset)
202{
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);
206
207 if (count&1)
208 count++;
209
210 if (xfer_start+count > mem_base + (NESM_STOP_PG<<8)) {
211 int semi_count = (mem_base + (NESM_STOP_PG<<8)) - xfer_start;
212
213 z_memcpy_fromio(skb->data,xfer_start,semi_count);
214 count -= semi_count;
215 z_memcpy_fromio(skb->data+semi_count, mem_base, count);
216 } else
217 z_memcpy_fromio(skb->data, xfer_start,count);
218
219}
220
221static void hydra_block_output(struct net_device *dev, int count,
222 const unsigned char *buf, int start_page)
223{
224 unsigned long nic_base = dev->base_addr;
225 unsigned long mem_base = nic_base - HYDRA_NIC_BASE;
226
227 if (count&1)
228 count++;
229
230 z_memcpy_toio(mem_base+((start_page - NESM_START_PG)<<8), buf, count);
231}
232
233static void __devexit hydra_remove_one(struct zorro_dev *z)
234{
235 struct net_device *dev = zorro_get_drvdata(z);
236
237 unregister_netdev(dev);
238 free_irq(IRQ_AMIGA_PORTS, dev);
239 release_mem_region(ZTWO_PADDR(dev->base_addr)-HYDRA_NIC_BASE, 0x10000);
240 free_netdev(dev);
241}
242
243static int __init hydra_init_module(void)
244{
Bjorn Helgaas33d86752006-03-25 03:07:20 -0800245 return zorro_register_driver(&hydra_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246}
247
248static void __exit hydra_cleanup_module(void)
249{
250 zorro_unregister_driver(&hydra_driver);
251}
252
253module_init(hydra_init_module);
254module_exit(hydra_cleanup_module);
255
256MODULE_LICENSE("GPL");