blob: 24724b4ad7096fc31ada3c8b0f4ff8078189f23e [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>
Linus Torvalds1da177e2005-04-16 15:20:36 -070020#include <linux/interrupt.h>
21#include <linux/netdevice.h>
22#include <linux/etherdevice.h>
23#include <linux/skbuff.h>
24#include <linux/init.h>
25#include <linux/bitops.h>
26
27#include <asm/io.h>
28#include <asm/irq.h>
29#include <asm/amigaints.h>
30#include <asm/amigahw.h>
31#include <linux/zorro.h>
32
Al Viro8c6270f2006-10-10 00:19:36 +010033#define EI_SHIFT(x) (ei_local->reg_offset[x])
34#define ei_inb(port) in_8(port)
35#define ei_outb(val,port) out_8(port,val)
36#define ei_inb_p(port) in_8(port)
37#define ei_outb_p(val,port) out_8(port,val)
38
39static const char version[] =
40 "8390.c:v1.10cvs 9/23/94 Donald Becker (becker@cesdis.gsfc.nasa.gov)\n";
41
42#include "lib8390.c"
Linus Torvalds1da177e2005-04-16 15:20:36 -070043
44#define NE_EN0_DCFG (0x0e*2)
45
46#define NESM_START_PG 0x0 /* First page of TX buffer */
47#define NESM_STOP_PG 0x40 /* Last page +1 of RX ring */
48
49#define HYDRA_NIC_BASE 0xffe1
50#define HYDRA_ADDRPROM 0xffc0
51#define HYDRA_VERSION "v3.0alpha"
52
53#define WORDSWAP(a) ((((a)>>8)&0xff) | ((a)<<8))
54
55
56static int __devinit hydra_init_one(struct zorro_dev *z,
57 const struct zorro_device_id *ent);
58static int __devinit hydra_init(struct zorro_dev *z);
59static int hydra_open(struct net_device *dev);
60static int hydra_close(struct net_device *dev);
61static void hydra_reset_8390(struct net_device *dev);
62static void hydra_get_8390_hdr(struct net_device *dev,
63 struct e8390_pkt_hdr *hdr, int ring_page);
64static void hydra_block_input(struct net_device *dev, int count,
65 struct sk_buff *skb, int ring_offset);
66static void hydra_block_output(struct net_device *dev, int count,
67 const unsigned char *buf, int start_page);
68static void __devexit hydra_remove_one(struct zorro_dev *z);
69
70static struct zorro_device_id hydra_zorro_tbl[] __devinitdata = {
71 { ZORRO_PROD_HYDRA_SYSTEMS_AMIGANET },
72 { 0 }
73};
74
75static struct zorro_driver hydra_driver = {
76 .name = "hydra",
77 .id_table = hydra_zorro_tbl,
78 .probe = hydra_init_one,
79 .remove = __devexit_p(hydra_remove_one),
80};
81
82static int __devinit hydra_init_one(struct zorro_dev *z,
83 const struct zorro_device_id *ent)
84{
85 int err;
86
87 if (!request_mem_region(z->resource.start, 0x10000, "Hydra"))
88 return -EBUSY;
89 if ((err = hydra_init(z))) {
90 release_mem_region(z->resource.start, 0x10000);
91 return -EBUSY;
92 }
93 return 0;
94}
95
Alexey Dobriyane4213002008-12-08 23:50:18 -080096static const struct net_device_ops hydra_netdev_ops = {
Stephen Hemminger5618f0d2008-12-03 22:10:10 -080097 .ndo_open = hydra_open,
98 .ndo_stop = hydra_close,
99
100 .ndo_start_xmit = ei_start_xmit,
101 .ndo_tx_timeout = ei_tx_timeout,
102 .ndo_get_stats = ei_get_stats,
103 .ndo_set_multicast_list = ei_set_multicast_list,
104 .ndo_validate_addr = eth_validate_addr,
Stephen Hemmingerfe96aaa2009-01-09 11:13:14 +0000105 .ndo_set_mac_address = eth_mac_addr,
Stephen Hemminger5618f0d2008-12-03 22:10:10 -0800106 .ndo_change_mtu = eth_change_mtu,
107#ifdef CONFIG_NET_POLL_CONTROLLER
108 .ndo_poll_controller = ei_poll,
109#endif
110};
111
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112static int __devinit hydra_init(struct zorro_dev *z)
113{
114 struct net_device *dev;
115 unsigned long board = ZTWO_VADDR(z->resource.start);
116 unsigned long ioaddr = board+HYDRA_NIC_BASE;
117 const char name[] = "NE2000";
118 int start_page, stop_page;
119 int j;
120 int err;
121
122 static u32 hydra_offsets[16] = {
123 0x00, 0x02, 0x04, 0x06, 0x08, 0x0a, 0x0c, 0x0e,
124 0x10, 0x12, 0x14, 0x16, 0x18, 0x1a, 0x1c, 0x1e,
125 };
126
Stephen Hemminger5618f0d2008-12-03 22:10:10 -0800127 dev = alloc_ei_netdev();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128 if (!dev)
129 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130
131 for(j = 0; j < ETHER_ADDR_LEN; j++)
132 dev->dev_addr[j] = *((u8 *)(board + HYDRA_ADDRPROM + 2*j));
133
134 /* We must set the 8390 for word mode. */
135 z_writeb(0x4b, ioaddr + NE_EN0_DCFG);
136 start_page = NESM_START_PG;
137 stop_page = NESM_STOP_PG;
138
139 dev->base_addr = ioaddr;
140 dev->irq = IRQ_AMIGA_PORTS;
141
142 /* Install the Interrupt handler */
Al Viro8c6270f2006-10-10 00:19:36 +0100143 if (request_irq(IRQ_AMIGA_PORTS, __ei_interrupt, IRQF_SHARED, "Hydra Ethernet",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144 dev)) {
145 free_netdev(dev);
146 return -EAGAIN;
147 }
148
149 ei_status.name = name;
150 ei_status.tx_start_page = start_page;
151 ei_status.stop_page = stop_page;
152 ei_status.word16 = 1;
153 ei_status.bigendian = 1;
154
155 ei_status.rx_start_page = start_page + TX_PAGES;
156
157 ei_status.reset_8390 = &hydra_reset_8390;
158 ei_status.block_input = &hydra_block_input;
159 ei_status.block_output = &hydra_block_output;
160 ei_status.get_8390_hdr = &hydra_get_8390_hdr;
161 ei_status.reg_offset = hydra_offsets;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162
Stephen Hemminger5618f0d2008-12-03 22:10:10 -0800163 dev->netdev_ops = &hydra_netdev_ops;
Al Viro8c6270f2006-10-10 00:19:36 +0100164 __NS8390_init(dev, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165
166 err = register_netdev(dev);
167 if (err) {
168 free_irq(IRQ_AMIGA_PORTS, dev);
169 free_netdev(dev);
170 return err;
171 }
172
173 zorro_set_drvdata(z, dev);
174
Randy Dunlapcf33ce12009-09-04 14:20:37 +0000175 printk(KERN_INFO "%s: Hydra at 0x%08llx, address "
Johannes Berge1749612008-10-27 15:59:26 -0700176 "%pM (hydra.c " HYDRA_VERSION ")\n",
Randy Dunlapcf33ce12009-09-04 14:20:37 +0000177 dev->name, (unsigned long long)z->resource.start, dev->dev_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178
179 return 0;
180}
181
182static int hydra_open(struct net_device *dev)
183{
Al Viro8c6270f2006-10-10 00:19:36 +0100184 __ei_open(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185 return 0;
186}
187
188static int hydra_close(struct net_device *dev)
189{
190 if (ei_debug > 1)
191 printk(KERN_DEBUG "%s: Shutting down ethercard.\n", dev->name);
Al Viro8c6270f2006-10-10 00:19:36 +0100192 __ei_close(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193 return 0;
194}
195
196static void hydra_reset_8390(struct net_device *dev)
197{
198 printk(KERN_INFO "Hydra hw reset not there\n");
199}
200
201static void hydra_get_8390_hdr(struct net_device *dev,
202 struct e8390_pkt_hdr *hdr, int ring_page)
203{
204 int nic_base = dev->base_addr;
205 short *ptrs;
206 unsigned long hdr_start= (nic_base-HYDRA_NIC_BASE) +
207 ((ring_page - NESM_START_PG)<<8);
208 ptrs = (short *)hdr;
209
210 *(ptrs++) = z_readw(hdr_start);
211 *((short *)hdr) = WORDSWAP(*((short *)hdr));
212 hdr_start += 2;
213 *(ptrs++) = z_readw(hdr_start);
214 *((short *)hdr+1) = WORDSWAP(*((short *)hdr+1));
215}
216
217static void hydra_block_input(struct net_device *dev, int count,
218 struct sk_buff *skb, int ring_offset)
219{
220 unsigned long nic_base = dev->base_addr;
221 unsigned long mem_base = nic_base - HYDRA_NIC_BASE;
222 unsigned long xfer_start = mem_base + ring_offset - (NESM_START_PG<<8);
223
224 if (count&1)
225 count++;
226
227 if (xfer_start+count > mem_base + (NESM_STOP_PG<<8)) {
228 int semi_count = (mem_base + (NESM_STOP_PG<<8)) - xfer_start;
229
230 z_memcpy_fromio(skb->data,xfer_start,semi_count);
231 count -= semi_count;
232 z_memcpy_fromio(skb->data+semi_count, mem_base, count);
233 } else
234 z_memcpy_fromio(skb->data, xfer_start,count);
235
236}
237
238static void hydra_block_output(struct net_device *dev, int count,
239 const unsigned char *buf, int start_page)
240{
241 unsigned long nic_base = dev->base_addr;
242 unsigned long mem_base = nic_base - HYDRA_NIC_BASE;
243
244 if (count&1)
245 count++;
246
247 z_memcpy_toio(mem_base+((start_page - NESM_START_PG)<<8), buf, count);
248}
249
250static void __devexit hydra_remove_one(struct zorro_dev *z)
251{
252 struct net_device *dev = zorro_get_drvdata(z);
253
254 unregister_netdev(dev);
255 free_irq(IRQ_AMIGA_PORTS, dev);
256 release_mem_region(ZTWO_PADDR(dev->base_addr)-HYDRA_NIC_BASE, 0x10000);
257 free_netdev(dev);
258}
259
260static int __init hydra_init_module(void)
261{
Bjorn Helgaas33d86752006-03-25 03:07:20 -0800262 return zorro_register_driver(&hydra_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263}
264
265static void __exit hydra_cleanup_module(void)
266{
267 zorro_unregister_driver(&hydra_driver);
268}
269
270module_init(hydra_init_module);
271module_exit(hydra_cleanup_module);
272
273MODULE_LICENSE("GPL");