Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | #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 Viro | 8c6270f | 2006-10-10 00:19:36 +0100 | [diff] [blame] | 33 | #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 | |
| 39 | static 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | |
| 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 | |
Bill Pemberton | 4168ac0 | 2012-12-03 09:22:51 -0500 | [diff] [blame] | 56 | static int hydra_init_one(struct zorro_dev *z, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | const struct zorro_device_id *ent); |
Bill Pemberton | 4168ac0 | 2012-12-03 09:22:51 -0500 | [diff] [blame] | 58 | static int hydra_init(struct zorro_dev *z); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | static int hydra_open(struct net_device *dev); |
| 60 | static int hydra_close(struct net_device *dev); |
| 61 | static void hydra_reset_8390(struct net_device *dev); |
| 62 | static void hydra_get_8390_hdr(struct net_device *dev, |
| 63 | struct e8390_pkt_hdr *hdr, int ring_page); |
| 64 | static void hydra_block_input(struct net_device *dev, int count, |
| 65 | struct sk_buff *skb, int ring_offset); |
| 66 | static void hydra_block_output(struct net_device *dev, int count, |
| 67 | const unsigned char *buf, int start_page); |
Bill Pemberton | 4168ac0 | 2012-12-03 09:22:51 -0500 | [diff] [blame] | 68 | static void hydra_remove_one(struct zorro_dev *z); |
Matthew Whitehead | c45f812 | 2013-12-11 17:00:59 -0500 | [diff] [blame] | 69 | static u32 hydra_msg_enable; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | |
Bill Pemberton | 4168ac0 | 2012-12-03 09:22:51 -0500 | [diff] [blame] | 71 | static struct zorro_device_id hydra_zorro_tbl[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | { ZORRO_PROD_HYDRA_SYSTEMS_AMIGANET }, |
| 73 | { 0 } |
| 74 | }; |
Geert Uytterhoeven | bf54a2b | 2008-11-18 21:13:53 +0100 | [diff] [blame] | 75 | MODULE_DEVICE_TABLE(zorro, hydra_zorro_tbl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | |
| 77 | static struct zorro_driver hydra_driver = { |
| 78 | .name = "hydra", |
| 79 | .id_table = hydra_zorro_tbl, |
| 80 | .probe = hydra_init_one, |
Bill Pemberton | 4168ac0 | 2012-12-03 09:22:51 -0500 | [diff] [blame] | 81 | .remove = hydra_remove_one, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | }; |
| 83 | |
Bill Pemberton | 4168ac0 | 2012-12-03 09:22:51 -0500 | [diff] [blame] | 84 | static int hydra_init_one(struct zorro_dev *z, |
Greg Kroah-Hartman | 1dd06ae | 2012-12-06 14:30:56 +0000 | [diff] [blame] | 85 | const struct zorro_device_id *ent) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | { |
| 87 | int err; |
| 88 | |
| 89 | if (!request_mem_region(z->resource.start, 0x10000, "Hydra")) |
| 90 | return -EBUSY; |
| 91 | if ((err = hydra_init(z))) { |
| 92 | release_mem_region(z->resource.start, 0x10000); |
| 93 | return -EBUSY; |
| 94 | } |
| 95 | return 0; |
| 96 | } |
| 97 | |
Alexey Dobriyan | e421300 | 2008-12-08 23:50:18 -0800 | [diff] [blame] | 98 | static const struct net_device_ops hydra_netdev_ops = { |
Stephen Hemminger | 5618f0d | 2008-12-03 22:10:10 -0800 | [diff] [blame] | 99 | .ndo_open = hydra_open, |
| 100 | .ndo_stop = hydra_close, |
| 101 | |
Geert Uytterhoeven | 0b25e01 | 2011-05-12 09:11:39 +0000 | [diff] [blame] | 102 | .ndo_start_xmit = __ei_start_xmit, |
| 103 | .ndo_tx_timeout = __ei_tx_timeout, |
| 104 | .ndo_get_stats = __ei_get_stats, |
Jiri Pirko | afc4b13 | 2011-08-16 06:29:01 +0000 | [diff] [blame] | 105 | .ndo_set_rx_mode = __ei_set_multicast_list, |
Stephen Hemminger | 5618f0d | 2008-12-03 22:10:10 -0800 | [diff] [blame] | 106 | .ndo_validate_addr = eth_validate_addr, |
Geert Uytterhoeven | 0b25e01 | 2011-05-12 09:11:39 +0000 | [diff] [blame] | 107 | .ndo_set_mac_address = eth_mac_addr, |
Stephen Hemminger | 5618f0d | 2008-12-03 22:10:10 -0800 | [diff] [blame] | 108 | .ndo_change_mtu = eth_change_mtu, |
| 109 | #ifdef CONFIG_NET_POLL_CONTROLLER |
Geert Uytterhoeven | 0b25e01 | 2011-05-12 09:11:39 +0000 | [diff] [blame] | 110 | .ndo_poll_controller = __ei_poll, |
Stephen Hemminger | 5618f0d | 2008-12-03 22:10:10 -0800 | [diff] [blame] | 111 | #endif |
| 112 | }; |
| 113 | |
Bill Pemberton | 4168ac0 | 2012-12-03 09:22:51 -0500 | [diff] [blame] | 114 | static int hydra_init(struct zorro_dev *z) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | { |
| 116 | struct net_device *dev; |
Geert Uytterhoeven | 6112ea0 | 2011-01-09 11:03:43 +0100 | [diff] [blame] | 117 | unsigned long board = (unsigned long)ZTWO_VADDR(z->resource.start); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | unsigned long ioaddr = board+HYDRA_NIC_BASE; |
| 119 | const char name[] = "NE2000"; |
| 120 | int start_page, stop_page; |
| 121 | int j; |
| 122 | int err; |
Matthew Whitehead | c45f812 | 2013-12-11 17:00:59 -0500 | [diff] [blame] | 123 | struct ei_device *ei_local; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | |
| 125 | static u32 hydra_offsets[16] = { |
| 126 | 0x00, 0x02, 0x04, 0x06, 0x08, 0x0a, 0x0c, 0x0e, |
| 127 | 0x10, 0x12, 0x14, 0x16, 0x18, 0x1a, 0x1c, 0x1e, |
| 128 | }; |
| 129 | |
Geert Uytterhoeven | 0b25e01 | 2011-05-12 09:11:39 +0000 | [diff] [blame] | 130 | dev = ____alloc_ei_netdev(0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 | if (!dev) |
| 132 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | |
Joe Perches | 104bf3f | 2011-11-16 09:38:03 +0000 | [diff] [blame] | 134 | for (j = 0; j < ETH_ALEN; j++) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | dev->dev_addr[j] = *((u8 *)(board + HYDRA_ADDRPROM + 2*j)); |
| 136 | |
| 137 | /* We must set the 8390 for word mode. */ |
| 138 | z_writeb(0x4b, ioaddr + NE_EN0_DCFG); |
| 139 | start_page = NESM_START_PG; |
| 140 | stop_page = NESM_STOP_PG; |
| 141 | |
Matthew Whitehead | c45f812 | 2013-12-11 17:00:59 -0500 | [diff] [blame] | 142 | ei_local = netdev_priv(dev); |
| 143 | ei_local->msg_enable = hydra_msg_enable; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | dev->base_addr = ioaddr; |
| 145 | dev->irq = IRQ_AMIGA_PORTS; |
| 146 | |
| 147 | /* Install the Interrupt handler */ |
Al Viro | 8c6270f | 2006-10-10 00:19:36 +0100 | [diff] [blame] | 148 | if (request_irq(IRQ_AMIGA_PORTS, __ei_interrupt, IRQF_SHARED, "Hydra Ethernet", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | dev)) { |
| 150 | free_netdev(dev); |
| 151 | return -EAGAIN; |
| 152 | } |
| 153 | |
| 154 | ei_status.name = name; |
| 155 | ei_status.tx_start_page = start_page; |
| 156 | ei_status.stop_page = stop_page; |
| 157 | ei_status.word16 = 1; |
| 158 | ei_status.bigendian = 1; |
| 159 | |
| 160 | ei_status.rx_start_page = start_page + TX_PAGES; |
| 161 | |
Joe Perches | c061b18 | 2010-08-23 18:20:03 +0000 | [diff] [blame] | 162 | ei_status.reset_8390 = hydra_reset_8390; |
| 163 | ei_status.block_input = hydra_block_input; |
| 164 | ei_status.block_output = hydra_block_output; |
| 165 | ei_status.get_8390_hdr = hydra_get_8390_hdr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 166 | ei_status.reg_offset = hydra_offsets; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | |
Stephen Hemminger | 5618f0d | 2008-12-03 22:10:10 -0800 | [diff] [blame] | 168 | dev->netdev_ops = &hydra_netdev_ops; |
Al Viro | 8c6270f | 2006-10-10 00:19:36 +0100 | [diff] [blame] | 169 | __NS8390_init(dev, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | |
| 171 | err = register_netdev(dev); |
| 172 | if (err) { |
| 173 | free_irq(IRQ_AMIGA_PORTS, dev); |
| 174 | free_netdev(dev); |
| 175 | return err; |
| 176 | } |
| 177 | |
| 178 | zorro_set_drvdata(z, dev); |
| 179 | |
Geert Uytterhoeven | c274f29 | 2010-08-29 21:43:46 +0000 | [diff] [blame] | 180 | pr_info("%s: Hydra at %pR, address %pM (hydra.c " HYDRA_VERSION ")\n", |
| 181 | dev->name, &z->resource, dev->dev_addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 182 | |
| 183 | return 0; |
| 184 | } |
| 185 | |
| 186 | static int hydra_open(struct net_device *dev) |
| 187 | { |
Al Viro | 8c6270f | 2006-10-10 00:19:36 +0100 | [diff] [blame] | 188 | __ei_open(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | return 0; |
| 190 | } |
| 191 | |
| 192 | static int hydra_close(struct net_device *dev) |
| 193 | { |
Matthew Whitehead | c45f812 | 2013-12-11 17:00:59 -0500 | [diff] [blame] | 194 | struct ei_device *ei_local = netdev_priv(dev); |
| 195 | |
| 196 | netif_dbg(ei_local, ifdown, dev, "Shutting down ethercard.\n"); |
Al Viro | 8c6270f | 2006-10-10 00:19:36 +0100 | [diff] [blame] | 197 | __ei_close(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 198 | return 0; |
| 199 | } |
| 200 | |
| 201 | static void hydra_reset_8390(struct net_device *dev) |
| 202 | { |
Matthew Whitehead | c45f812 | 2013-12-11 17:00:59 -0500 | [diff] [blame] | 203 | netdev_info(dev, "Hydra hw reset not there\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 204 | } |
| 205 | |
| 206 | static void hydra_get_8390_hdr(struct net_device *dev, |
| 207 | struct e8390_pkt_hdr *hdr, int ring_page) |
| 208 | { |
| 209 | int nic_base = dev->base_addr; |
| 210 | short *ptrs; |
| 211 | unsigned long hdr_start= (nic_base-HYDRA_NIC_BASE) + |
| 212 | ((ring_page - NESM_START_PG)<<8); |
| 213 | ptrs = (short *)hdr; |
| 214 | |
| 215 | *(ptrs++) = z_readw(hdr_start); |
| 216 | *((short *)hdr) = WORDSWAP(*((short *)hdr)); |
| 217 | hdr_start += 2; |
| 218 | *(ptrs++) = z_readw(hdr_start); |
| 219 | *((short *)hdr+1) = WORDSWAP(*((short *)hdr+1)); |
| 220 | } |
| 221 | |
| 222 | static void hydra_block_input(struct net_device *dev, int count, |
| 223 | struct sk_buff *skb, int ring_offset) |
| 224 | { |
| 225 | unsigned long nic_base = dev->base_addr; |
| 226 | unsigned long mem_base = nic_base - HYDRA_NIC_BASE; |
| 227 | unsigned long xfer_start = mem_base + ring_offset - (NESM_START_PG<<8); |
| 228 | |
| 229 | if (count&1) |
| 230 | count++; |
| 231 | |
| 232 | if (xfer_start+count > mem_base + (NESM_STOP_PG<<8)) { |
| 233 | int semi_count = (mem_base + (NESM_STOP_PG<<8)) - xfer_start; |
| 234 | |
| 235 | z_memcpy_fromio(skb->data,xfer_start,semi_count); |
| 236 | count -= semi_count; |
| 237 | z_memcpy_fromio(skb->data+semi_count, mem_base, count); |
| 238 | } else |
| 239 | z_memcpy_fromio(skb->data, xfer_start,count); |
| 240 | |
| 241 | } |
| 242 | |
| 243 | static void hydra_block_output(struct net_device *dev, int count, |
| 244 | const unsigned char *buf, int start_page) |
| 245 | { |
| 246 | unsigned long nic_base = dev->base_addr; |
| 247 | unsigned long mem_base = nic_base - HYDRA_NIC_BASE; |
| 248 | |
| 249 | if (count&1) |
| 250 | count++; |
| 251 | |
| 252 | z_memcpy_toio(mem_base+((start_page - NESM_START_PG)<<8), buf, count); |
| 253 | } |
| 254 | |
Bill Pemberton | 4168ac0 | 2012-12-03 09:22:51 -0500 | [diff] [blame] | 255 | static void hydra_remove_one(struct zorro_dev *z) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 256 | { |
| 257 | struct net_device *dev = zorro_get_drvdata(z); |
| 258 | |
| 259 | unregister_netdev(dev); |
| 260 | free_irq(IRQ_AMIGA_PORTS, dev); |
| 261 | release_mem_region(ZTWO_PADDR(dev->base_addr)-HYDRA_NIC_BASE, 0x10000); |
| 262 | free_netdev(dev); |
| 263 | } |
| 264 | |
| 265 | static int __init hydra_init_module(void) |
| 266 | { |
Bjorn Helgaas | 33d8675 | 2006-03-25 03:07:20 -0800 | [diff] [blame] | 267 | return zorro_register_driver(&hydra_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 268 | } |
| 269 | |
| 270 | static void __exit hydra_cleanup_module(void) |
| 271 | { |
| 272 | zorro_unregister_driver(&hydra_driver); |
| 273 | } |
| 274 | |
| 275 | module_init(hydra_init_module); |
| 276 | module_exit(hydra_cleanup_module); |
| 277 | |
| 278 | MODULE_LICENSE("GPL"); |