]>
Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* New Hydra driver using generic 8390 core */ |
2 | /* Based on old hydra driver by Topi Kanerva ([email protected]) */ | |
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 ([email protected]) */ | |
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 | ||
8c6270f9 AV |
34 | #define EI_SHIFT(x) (ei_local->reg_offset[x]) |
35 | #define ei_inb(port) in_8(port) | |
36 | #define ei_outb(val,port) out_8(port,val) | |
37 | #define ei_inb_p(port) in_8(port) | |
38 | #define ei_outb_p(val,port) out_8(port,val) | |
39 | ||
40 | static const char version[] = | |
41 | "8390.c:v1.10cvs 9/23/94 Donald Becker ([email protected])\n"; | |
42 | ||
43 | #include "lib8390.c" | |
1da177e4 LT |
44 | |
45 | #define NE_EN0_DCFG (0x0e*2) | |
46 | ||
47 | #define NESM_START_PG 0x0 /* First page of TX buffer */ | |
48 | #define NESM_STOP_PG 0x40 /* Last page +1 of RX ring */ | |
49 | ||
50 | #define HYDRA_NIC_BASE 0xffe1 | |
51 | #define HYDRA_ADDRPROM 0xffc0 | |
52 | #define HYDRA_VERSION "v3.0alpha" | |
53 | ||
54 | #define WORDSWAP(a) ((((a)>>8)&0xff) | ((a)<<8)) | |
55 | ||
56 | ||
57 | static int __devinit hydra_init_one(struct zorro_dev *z, | |
58 | const struct zorro_device_id *ent); | |
59 | static int __devinit hydra_init(struct zorro_dev *z); | |
60 | static int hydra_open(struct net_device *dev); | |
61 | static int hydra_close(struct net_device *dev); | |
62 | static void hydra_reset_8390(struct net_device *dev); | |
63 | static void hydra_get_8390_hdr(struct net_device *dev, | |
64 | struct e8390_pkt_hdr *hdr, int ring_page); | |
65 | static void hydra_block_input(struct net_device *dev, int count, | |
66 | struct sk_buff *skb, int ring_offset); | |
67 | static void hydra_block_output(struct net_device *dev, int count, | |
68 | const unsigned char *buf, int start_page); | |
69 | static void __devexit hydra_remove_one(struct zorro_dev *z); | |
70 | ||
71 | static struct zorro_device_id hydra_zorro_tbl[] __devinitdata = { | |
72 | { ZORRO_PROD_HYDRA_SYSTEMS_AMIGANET }, | |
73 | { 0 } | |
74 | }; | |
75 | ||
76 | static struct zorro_driver hydra_driver = { | |
77 | .name = "hydra", | |
78 | .id_table = hydra_zorro_tbl, | |
79 | .probe = hydra_init_one, | |
80 | .remove = __devexit_p(hydra_remove_one), | |
81 | }; | |
82 | ||
83 | static int __devinit hydra_init_one(struct zorro_dev *z, | |
84 | const struct zorro_device_id *ent) | |
85 | { | |
86 | int err; | |
87 | ||
88 | if (!request_mem_region(z->resource.start, 0x10000, "Hydra")) | |
89 | return -EBUSY; | |
90 | if ((err = hydra_init(z))) { | |
91 | release_mem_region(z->resource.start, 0x10000); | |
92 | return -EBUSY; | |
93 | } | |
94 | return 0; | |
95 | } | |
96 | ||
97 | static int __devinit hydra_init(struct zorro_dev *z) | |
98 | { | |
99 | struct net_device *dev; | |
100 | unsigned long board = ZTWO_VADDR(z->resource.start); | |
101 | unsigned long ioaddr = board+HYDRA_NIC_BASE; | |
102 | const char name[] = "NE2000"; | |
103 | int start_page, stop_page; | |
104 | int j; | |
105 | int err; | |
106 | ||
107 | static u32 hydra_offsets[16] = { | |
108 | 0x00, 0x02, 0x04, 0x06, 0x08, 0x0a, 0x0c, 0x0e, | |
109 | 0x10, 0x12, 0x14, 0x16, 0x18, 0x1a, 0x1c, 0x1e, | |
110 | }; | |
111 | ||
8c6270f9 | 112 | dev = ____alloc_ei_netdev(0); |
1da177e4 LT |
113 | if (!dev) |
114 | return -ENOMEM; | |
1da177e4 LT |
115 | |
116 | for(j = 0; j < ETHER_ADDR_LEN; j++) | |
117 | dev->dev_addr[j] = *((u8 *)(board + HYDRA_ADDRPROM + 2*j)); | |
118 | ||
119 | /* We must set the 8390 for word mode. */ | |
120 | z_writeb(0x4b, ioaddr + NE_EN0_DCFG); | |
121 | start_page = NESM_START_PG; | |
122 | stop_page = NESM_STOP_PG; | |
123 | ||
124 | dev->base_addr = ioaddr; | |
125 | dev->irq = IRQ_AMIGA_PORTS; | |
126 | ||
127 | /* Install the Interrupt handler */ | |
8c6270f9 | 128 | if (request_irq(IRQ_AMIGA_PORTS, __ei_interrupt, IRQF_SHARED, "Hydra Ethernet", |
1da177e4 LT |
129 | dev)) { |
130 | free_netdev(dev); | |
131 | return -EAGAIN; | |
132 | } | |
133 | ||
134 | ei_status.name = name; | |
135 | ei_status.tx_start_page = start_page; | |
136 | ei_status.stop_page = stop_page; | |
137 | ei_status.word16 = 1; | |
138 | ei_status.bigendian = 1; | |
139 | ||
140 | ei_status.rx_start_page = start_page + TX_PAGES; | |
141 | ||
142 | ei_status.reset_8390 = &hydra_reset_8390; | |
143 | ei_status.block_input = &hydra_block_input; | |
144 | ei_status.block_output = &hydra_block_output; | |
145 | ei_status.get_8390_hdr = &hydra_get_8390_hdr; | |
146 | ei_status.reg_offset = hydra_offsets; | |
147 | dev->open = &hydra_open; | |
148 | dev->stop = &hydra_close; | |
149 | #ifdef CONFIG_NET_POLL_CONTROLLER | |
8c6270f9 | 150 | dev->poll_controller = __ei_poll; |
1da177e4 LT |
151 | #endif |
152 | ||
8c6270f9 | 153 | __NS8390_init(dev, 0); |
1da177e4 LT |
154 | |
155 | err = register_netdev(dev); | |
156 | if (err) { | |
157 | free_irq(IRQ_AMIGA_PORTS, dev); | |
158 | free_netdev(dev); | |
159 | return err; | |
160 | } | |
161 | ||
162 | zorro_set_drvdata(z, dev); | |
163 | ||
164 | printk(KERN_INFO "%s: Hydra at 0x%08lx, address " | |
165 | "%02x:%02x:%02x:%02x:%02x:%02x (hydra.c " HYDRA_VERSION ")\n", | |
166 | dev->name, z->resource.start, dev->dev_addr[0], dev->dev_addr[1], | |
167 | dev->dev_addr[2], dev->dev_addr[3], dev->dev_addr[4], | |
168 | dev->dev_addr[5]); | |
169 | ||
170 | return 0; | |
171 | } | |
172 | ||
173 | static int hydra_open(struct net_device *dev) | |
174 | { | |
8c6270f9 | 175 | __ei_open(dev); |
1da177e4 LT |
176 | return 0; |
177 | } | |
178 | ||
179 | static int hydra_close(struct net_device *dev) | |
180 | { | |
181 | if (ei_debug > 1) | |
182 | printk(KERN_DEBUG "%s: Shutting down ethercard.\n", dev->name); | |
8c6270f9 | 183 | __ei_close(dev); |
1da177e4 LT |
184 | return 0; |
185 | } | |
186 | ||
187 | static void hydra_reset_8390(struct net_device *dev) | |
188 | { | |
189 | printk(KERN_INFO "Hydra hw reset not there\n"); | |
190 | } | |
191 | ||
192 | static void hydra_get_8390_hdr(struct net_device *dev, | |
193 | struct e8390_pkt_hdr *hdr, int ring_page) | |
194 | { | |
195 | int nic_base = dev->base_addr; | |
196 | short *ptrs; | |
197 | unsigned long hdr_start= (nic_base-HYDRA_NIC_BASE) + | |
198 | ((ring_page - NESM_START_PG)<<8); | |
199 | ptrs = (short *)hdr; | |
200 | ||
201 | *(ptrs++) = z_readw(hdr_start); | |
202 | *((short *)hdr) = WORDSWAP(*((short *)hdr)); | |
203 | hdr_start += 2; | |
204 | *(ptrs++) = z_readw(hdr_start); | |
205 | *((short *)hdr+1) = WORDSWAP(*((short *)hdr+1)); | |
206 | } | |
207 | ||
208 | static void hydra_block_input(struct net_device *dev, int count, | |
209 | struct sk_buff *skb, int ring_offset) | |
210 | { | |
211 | unsigned long nic_base = dev->base_addr; | |
212 | unsigned long mem_base = nic_base - HYDRA_NIC_BASE; | |
213 | unsigned long xfer_start = mem_base + ring_offset - (NESM_START_PG<<8); | |
214 | ||
215 | if (count&1) | |
216 | count++; | |
217 | ||
218 | if (xfer_start+count > mem_base + (NESM_STOP_PG<<8)) { | |
219 | int semi_count = (mem_base + (NESM_STOP_PG<<8)) - xfer_start; | |
220 | ||
221 | z_memcpy_fromio(skb->data,xfer_start,semi_count); | |
222 | count -= semi_count; | |
223 | z_memcpy_fromio(skb->data+semi_count, mem_base, count); | |
224 | } else | |
225 | z_memcpy_fromio(skb->data, xfer_start,count); | |
226 | ||
227 | } | |
228 | ||
229 | static void hydra_block_output(struct net_device *dev, int count, | |
230 | const unsigned char *buf, int start_page) | |
231 | { | |
232 | unsigned long nic_base = dev->base_addr; | |
233 | unsigned long mem_base = nic_base - HYDRA_NIC_BASE; | |
234 | ||
235 | if (count&1) | |
236 | count++; | |
237 | ||
238 | z_memcpy_toio(mem_base+((start_page - NESM_START_PG)<<8), buf, count); | |
239 | } | |
240 | ||
241 | static void __devexit hydra_remove_one(struct zorro_dev *z) | |
242 | { | |
243 | struct net_device *dev = zorro_get_drvdata(z); | |
244 | ||
245 | unregister_netdev(dev); | |
246 | free_irq(IRQ_AMIGA_PORTS, dev); | |
247 | release_mem_region(ZTWO_PADDR(dev->base_addr)-HYDRA_NIC_BASE, 0x10000); | |
248 | free_netdev(dev); | |
249 | } | |
250 | ||
251 | static int __init hydra_init_module(void) | |
252 | { | |
33d8675e | 253 | return zorro_register_driver(&hydra_driver); |
1da177e4 LT |
254 | } |
255 | ||
256 | static void __exit hydra_cleanup_module(void) | |
257 | { | |
258 | zorro_unregister_driver(&hydra_driver); | |
259 | } | |
260 | ||
261 | module_init(hydra_init_module); | |
262 | module_exit(hydra_cleanup_module); | |
263 | ||
264 | MODULE_LICENSE("GPL"); |