Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* mac8390.c: New driver for 8390-based Nubus (or Nubus-alike) |
| 2 | Ethernet cards on Linux */ |
| 3 | /* Based on the former daynaport.c driver, by Alan Cox. Some code |
| 4 | taken from or inspired by skeleton.c by Donald Becker, acenic.c by |
| 5 | Jes Sorensen, and ne2k-pci.c by Donald Becker and Paul Gortmaker. |
| 6 | |
| 7 | This software may be used and distributed according to the terms of |
| 8 | the GNU Public License, incorporated herein by reference. */ |
| 9 | |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10 | /* 2000-02-28: support added for Dayna and Kinetics cards by |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | A.G.deWijn@phys.uu.nl */ |
| 12 | /* 2000-04-04: support added for Dayna2 by bart@etpmod.phys.tue.nl */ |
| 13 | /* 2001-04-18: support for DaynaPort E/LC-M by rayk@knightsmanor.org */ |
| 14 | /* 2001-05-15: support for Cabletron ported from old daynaport driver |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 15 | * and fixed access to Sonic Sys card which masquerades as a Farallon |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | * by rayk@knightsmanor.org */ |
Finn Thain | 2964db0 | 2007-05-01 22:32:54 +0200 | [diff] [blame] | 17 | /* 2002-12-30: Try to support more cards, some clues from NetBSD driver */ |
| 18 | /* 2003-12-26: Make sure Asante cards always work. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | |
Joe Perches | 18c0019 | 2010-01-04 11:53:01 +0000 | [diff] [blame] | 20 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 21 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | #include <linux/module.h> |
| 23 | #include <linux/kernel.h> |
| 24 | #include <linux/types.h> |
| 25 | #include <linux/fcntl.h> |
| 26 | #include <linux/interrupt.h> |
| 27 | #include <linux/ptrace.h> |
| 28 | #include <linux/ioport.h> |
| 29 | #include <linux/nubus.h> |
| 30 | #include <linux/in.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | #include <linux/string.h> |
| 32 | #include <linux/errno.h> |
| 33 | #include <linux/init.h> |
| 34 | #include <linux/netdevice.h> |
| 35 | #include <linux/etherdevice.h> |
| 36 | #include <linux/skbuff.h> |
| 37 | #include <linux/bitops.h> |
Joe Perches | 8e4d969 | 2010-01-04 11:53:02 +0000 | [diff] [blame] | 38 | #include <linux/io.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | |
| 40 | #include <asm/system.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | #include <asm/dma.h> |
| 42 | #include <asm/hwtest.h> |
| 43 | #include <asm/macints.h> |
| 44 | |
Al Viro | 8c6270f | 2006-10-10 00:19:36 +0100 | [diff] [blame] | 45 | static char version[] = |
Joe Perches | 18c0019 | 2010-01-04 11:53:01 +0000 | [diff] [blame] | 46 | "v0.4 2001-05-15 David Huggins-Daines <dhd@debian.org> and others\n"; |
Al Viro | 8c6270f | 2006-10-10 00:19:36 +0100 | [diff] [blame] | 47 | |
| 48 | #define EI_SHIFT(x) (ei_local->reg_offset[x]) |
Joe Perches | 8e4d969 | 2010-01-04 11:53:02 +0000 | [diff] [blame] | 49 | #define ei_inb(port) in_8(port) |
| 50 | #define ei_outb(val, port) out_8(port, val) |
| 51 | #define ei_inb_p(port) in_8(port) |
| 52 | #define ei_outb_p(val, port) out_8(port, val) |
Al Viro | 8c6270f | 2006-10-10 00:19:36 +0100 | [diff] [blame] | 53 | |
| 54 | #include "lib8390.c" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | |
| 56 | #define WD_START_PG 0x00 /* First page of TX buffer */ |
| 57 | #define CABLETRON_RX_START_PG 0x00 /* First page of RX buffer */ |
| 58 | #define CABLETRON_RX_STOP_PG 0x30 /* Last page +1 of RX ring */ |
Joe Perches | 8e4d969 | 2010-01-04 11:53:02 +0000 | [diff] [blame] | 59 | #define CABLETRON_TX_START_PG CABLETRON_RX_STOP_PG |
| 60 | /* First page of TX buffer */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | |
Joe Perches | 8e4d969 | 2010-01-04 11:53:02 +0000 | [diff] [blame] | 62 | /* |
| 63 | * Unfortunately it seems we have to hardcode these for the moment |
| 64 | * Shouldn't the card know about this? |
| 65 | * Does anyone know where to read it off the card? |
| 66 | * Do we trust the data provided by the card? |
| 67 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | |
| 69 | #define DAYNA_8390_BASE 0x80000 |
| 70 | #define DAYNA_8390_MEM 0x00000 |
| 71 | |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 72 | #define CABLETRON_8390_BASE 0x90000 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | #define CABLETRON_8390_MEM 0x00000 |
| 74 | |
Finn Thain | 2964db0 | 2007-05-01 22:32:54 +0200 | [diff] [blame] | 75 | #define INTERLAN_8390_BASE 0xE0000 |
| 76 | #define INTERLAN_8390_MEM 0xD0000 |
| 77 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | enum mac8390_type { |
| 79 | MAC8390_NONE = -1, |
| 80 | MAC8390_APPLE, |
| 81 | MAC8390_ASANTE, |
Finn Thain | 2964db0 | 2007-05-01 22:32:54 +0200 | [diff] [blame] | 82 | MAC8390_FARALLON, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | MAC8390_CABLETRON, |
| 84 | MAC8390_DAYNA, |
| 85 | MAC8390_INTERLAN, |
| 86 | MAC8390_KINETICS, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | }; |
| 88 | |
Joe Perches | 8e4d969 | 2010-01-04 11:53:02 +0000 | [diff] [blame] | 89 | static const char *cardname[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | "apple", |
| 91 | "asante", |
| 92 | "farallon", |
| 93 | "cabletron", |
| 94 | "dayna", |
| 95 | "interlan", |
| 96 | "kinetics", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | }; |
| 98 | |
Joe Perches | 8e4d969 | 2010-01-04 11:53:02 +0000 | [diff] [blame] | 99 | static const int word16[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | 1, /* apple */ |
| 101 | 1, /* asante */ |
| 102 | 1, /* farallon */ |
| 103 | 1, /* cabletron */ |
| 104 | 0, /* dayna */ |
| 105 | 1, /* interlan */ |
| 106 | 0, /* kinetics */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | }; |
| 108 | |
| 109 | /* on which cards do we use NuBus resources? */ |
Joe Perches | 8e4d969 | 2010-01-04 11:53:02 +0000 | [diff] [blame] | 110 | static const int useresources[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | 1, /* apple */ |
| 112 | 1, /* asante */ |
| 113 | 1, /* farallon */ |
| 114 | 0, /* cabletron */ |
| 115 | 0, /* dayna */ |
| 116 | 0, /* interlan */ |
| 117 | 0, /* kinetics */ |
Finn Thain | 2964db0 | 2007-05-01 22:32:54 +0200 | [diff] [blame] | 118 | }; |
| 119 | |
| 120 | enum mac8390_access { |
| 121 | ACCESS_UNKNOWN = 0, |
| 122 | ACCESS_32, |
| 123 | ACCESS_16, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | }; |
| 125 | |
Joe Perches | 8e4d969 | 2010-01-04 11:53:02 +0000 | [diff] [blame] | 126 | extern int mac8390_memtest(struct net_device *dev); |
| 127 | static int mac8390_initdev(struct net_device *dev, struct nubus_dev *ndev, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | enum mac8390_type type); |
| 129 | |
Joe Perches | 8e4d969 | 2010-01-04 11:53:02 +0000 | [diff] [blame] | 130 | static int mac8390_open(struct net_device *dev); |
| 131 | static int mac8390_close(struct net_device *dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | static void mac8390_no_reset(struct net_device *dev); |
Finn Thain | 2964db0 | 2007-05-01 22:32:54 +0200 | [diff] [blame] | 133 | static void interlan_reset(struct net_device *dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | |
Finn Thain | 2964db0 | 2007-05-01 22:32:54 +0200 | [diff] [blame] | 135 | /* Sane (32-bit chunk memory read/write) - Some Farallon and Apple do this*/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | static void sane_get_8390_hdr(struct net_device *dev, |
| 137 | struct e8390_pkt_hdr *hdr, int ring_page); |
Joe Perches | 8e4d969 | 2010-01-04 11:53:02 +0000 | [diff] [blame] | 138 | static void sane_block_input(struct net_device *dev, int count, |
| 139 | struct sk_buff *skb, int ring_offset); |
| 140 | static void sane_block_output(struct net_device *dev, int count, |
| 141 | const unsigned char *buf, const int start_page); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | |
| 143 | /* dayna_memcpy to and from card */ |
| 144 | static void dayna_memcpy_fromcard(struct net_device *dev, void *to, |
| 145 | int from, int count); |
| 146 | static void dayna_memcpy_tocard(struct net_device *dev, int to, |
| 147 | const void *from, int count); |
| 148 | |
| 149 | /* Dayna - Dayna/Kinetics use this */ |
| 150 | static void dayna_get_8390_hdr(struct net_device *dev, |
| 151 | struct e8390_pkt_hdr *hdr, int ring_page); |
| 152 | static void dayna_block_input(struct net_device *dev, int count, |
| 153 | struct sk_buff *skb, int ring_offset); |
| 154 | static void dayna_block_output(struct net_device *dev, int count, |
| 155 | const unsigned char *buf, int start_page); |
| 156 | |
Joe Perches | 8e4d969 | 2010-01-04 11:53:02 +0000 | [diff] [blame] | 157 | #define memcpy_fromio(a, b, c) memcpy((a), (void *)(b), (c)) |
| 158 | #define memcpy_toio(a, b, c) memcpy((void *)(a), (b), (c)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | |
| 160 | /* Slow Sane (16-bit chunk memory read/write) Cabletron uses this */ |
| 161 | static void slow_sane_get_8390_hdr(struct net_device *dev, |
| 162 | struct e8390_pkt_hdr *hdr, int ring_page); |
| 163 | static void slow_sane_block_input(struct net_device *dev, int count, |
| 164 | struct sk_buff *skb, int ring_offset); |
| 165 | static void slow_sane_block_output(struct net_device *dev, int count, |
| 166 | const unsigned char *buf, int start_page); |
| 167 | static void word_memcpy_tocard(void *tp, const void *fp, int count); |
| 168 | static void word_memcpy_fromcard(void *tp, const void *fp, int count); |
| 169 | |
Adrian Bunk | 909fa88 | 2008-06-10 01:23:39 +0300 | [diff] [blame] | 170 | static enum mac8390_type __init mac8390_ident(struct nubus_dev *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | { |
Finn Thain | 2964db0 | 2007-05-01 22:32:54 +0200 | [diff] [blame] | 172 | switch (dev->dr_sw) { |
Joe Perches | 3507640 | 2010-01-04 11:52:59 +0000 | [diff] [blame] | 173 | case NUBUS_DRSW_3COM: |
| 174 | switch (dev->dr_hw) { |
| 175 | case NUBUS_DRHW_APPLE_SONIC_NB: |
| 176 | case NUBUS_DRHW_APPLE_SONIC_LC: |
| 177 | case NUBUS_DRHW_SONNET: |
| 178 | return MAC8390_NONE; |
Finn Thain | 2964db0 | 2007-05-01 22:32:54 +0200 | [diff] [blame] | 179 | break; |
Joe Perches | 3507640 | 2010-01-04 11:52:59 +0000 | [diff] [blame] | 180 | default: |
| 181 | return MAC8390_APPLE; |
| 182 | break; |
| 183 | } |
| 184 | break; |
Finn Thain | 2964db0 | 2007-05-01 22:32:54 +0200 | [diff] [blame] | 185 | |
Joe Perches | 3507640 | 2010-01-04 11:52:59 +0000 | [diff] [blame] | 186 | case NUBUS_DRSW_APPLE: |
| 187 | switch (dev->dr_hw) { |
| 188 | case NUBUS_DRHW_ASANTE_LC: |
| 189 | return MAC8390_NONE; |
Finn Thain | 2964db0 | 2007-05-01 22:32:54 +0200 | [diff] [blame] | 190 | break; |
Joe Perches | 3507640 | 2010-01-04 11:52:59 +0000 | [diff] [blame] | 191 | case NUBUS_DRHW_CABLETRON: |
| 192 | return MAC8390_CABLETRON; |
| 193 | break; |
| 194 | default: |
| 195 | return MAC8390_APPLE; |
| 196 | break; |
| 197 | } |
| 198 | break; |
Finn Thain | 2964db0 | 2007-05-01 22:32:54 +0200 | [diff] [blame] | 199 | |
Joe Perches | 3507640 | 2010-01-04 11:52:59 +0000 | [diff] [blame] | 200 | case NUBUS_DRSW_ASANTE: |
| 201 | return MAC8390_ASANTE; |
| 202 | break; |
Finn Thain | 2964db0 | 2007-05-01 22:32:54 +0200 | [diff] [blame] | 203 | |
Joe Perches | 3507640 | 2010-01-04 11:52:59 +0000 | [diff] [blame] | 204 | case NUBUS_DRSW_TECHWORKS: |
| 205 | case NUBUS_DRSW_DAYNA2: |
| 206 | case NUBUS_DRSW_DAYNA_LC: |
| 207 | if (dev->dr_hw == NUBUS_DRHW_CABLETRON) |
| 208 | return MAC8390_CABLETRON; |
| 209 | else |
| 210 | return MAC8390_APPLE; |
| 211 | break; |
Finn Thain | 2964db0 | 2007-05-01 22:32:54 +0200 | [diff] [blame] | 212 | |
Joe Perches | 3507640 | 2010-01-04 11:52:59 +0000 | [diff] [blame] | 213 | case NUBUS_DRSW_FARALLON: |
| 214 | return MAC8390_FARALLON; |
| 215 | break; |
Finn Thain | 2964db0 | 2007-05-01 22:32:54 +0200 | [diff] [blame] | 216 | |
Joe Perches | 3507640 | 2010-01-04 11:52:59 +0000 | [diff] [blame] | 217 | case NUBUS_DRSW_KINETICS: |
| 218 | switch (dev->dr_hw) { |
| 219 | case NUBUS_DRHW_INTERLAN: |
| 220 | return MAC8390_INTERLAN; |
Finn Thain | 2964db0 | 2007-05-01 22:32:54 +0200 | [diff] [blame] | 221 | break; |
Joe Perches | 3507640 | 2010-01-04 11:52:59 +0000 | [diff] [blame] | 222 | default: |
| 223 | return MAC8390_KINETICS; |
| 224 | break; |
| 225 | } |
| 226 | break; |
Finn Thain | 2964db0 | 2007-05-01 22:32:54 +0200 | [diff] [blame] | 227 | |
Joe Perches | 3507640 | 2010-01-04 11:52:59 +0000 | [diff] [blame] | 228 | case NUBUS_DRSW_DAYNA: |
Joe Perches | 8e4d969 | 2010-01-04 11:53:02 +0000 | [diff] [blame] | 229 | /* |
| 230 | * These correspond to Dayna Sonic cards |
| 231 | * which use the macsonic driver |
| 232 | */ |
Joe Perches | 3507640 | 2010-01-04 11:52:59 +0000 | [diff] [blame] | 233 | if (dev->dr_hw == NUBUS_DRHW_SMC9194 || |
Joe Perches | 8e4d969 | 2010-01-04 11:53:02 +0000 | [diff] [blame] | 234 | dev->dr_hw == NUBUS_DRHW_INTERLAN) |
Joe Perches | 3507640 | 2010-01-04 11:52:59 +0000 | [diff] [blame] | 235 | return MAC8390_NONE; |
| 236 | else |
| 237 | return MAC8390_DAYNA; |
| 238 | break; |
Finn Thain | 2964db0 | 2007-05-01 22:32:54 +0200 | [diff] [blame] | 239 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 240 | return MAC8390_NONE; |
| 241 | } |
| 242 | |
Adrian Bunk | 909fa88 | 2008-06-10 01:23:39 +0300 | [diff] [blame] | 243 | static enum mac8390_access __init mac8390_testio(volatile unsigned long membase) |
Finn Thain | 2964db0 | 2007-05-01 22:32:54 +0200 | [diff] [blame] | 244 | { |
| 245 | unsigned long outdata = 0xA5A0B5B0; |
| 246 | unsigned long indata = 0x00000000; |
| 247 | /* Try writing 32 bits */ |
Joe Perches | 5c7fffd | 2010-01-04 11:53:00 +0000 | [diff] [blame] | 248 | memcpy(membase, &outdata, 4); |
Finn Thain | 2964db0 | 2007-05-01 22:32:54 +0200 | [diff] [blame] | 249 | /* Now compare them */ |
| 250 | if (memcmp((char *)&outdata, (char *)membase, 4) == 0) |
| 251 | return ACCESS_32; |
| 252 | /* Write 16 bit output */ |
Joe Perches | 5c7fffd | 2010-01-04 11:53:00 +0000 | [diff] [blame] | 253 | word_memcpy_tocard(membase, &outdata, 4); |
Finn Thain | 2964db0 | 2007-05-01 22:32:54 +0200 | [diff] [blame] | 254 | /* Now read it back */ |
Joe Perches | 5c7fffd | 2010-01-04 11:53:00 +0000 | [diff] [blame] | 255 | word_memcpy_fromcard(&indata, membase, 4); |
Finn Thain | 2964db0 | 2007-05-01 22:32:54 +0200 | [diff] [blame] | 256 | if (outdata == indata) |
| 257 | return ACCESS_16; |
| 258 | return ACCESS_UNKNOWN; |
| 259 | } |
| 260 | |
Adrian Bunk | 909fa88 | 2008-06-10 01:23:39 +0300 | [diff] [blame] | 261 | static int __init mac8390_memsize(unsigned long membase) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 262 | { |
| 263 | unsigned long flags; |
| 264 | int i, j; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 265 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 266 | local_irq_save(flags); |
| 267 | /* Check up to 32K in 4K increments */ |
| 268 | for (i = 0; i < 8; i++) { |
Joe Perches | 8e4d969 | 2010-01-04 11:53:02 +0000 | [diff] [blame] | 269 | volatile unsigned short *m = (unsigned short *)(membase + (i * 0x1000)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 270 | |
| 271 | /* Unwriteable - we have a fully decoded card and the |
| 272 | RAM end located */ |
| 273 | if (hwreg_present(m) == 0) |
| 274 | break; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 275 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 276 | /* write a distinctive byte */ |
| 277 | *m = 0xA5A0 | i; |
| 278 | /* check that we read back what we wrote */ |
| 279 | if (*m != (0xA5A0 | i)) |
| 280 | break; |
| 281 | |
| 282 | /* check for partial decode and wrap */ |
| 283 | for (j = 0; j < i; j++) { |
Joe Perches | 8e4d969 | 2010-01-04 11:53:02 +0000 | [diff] [blame] | 284 | volatile unsigned short *p = (unsigned short *)(membase + (j * 0x1000)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 285 | if (*p != (0xA5A0 | j)) |
| 286 | break; |
Joe Perches | 8e4d969 | 2010-01-04 11:53:02 +0000 | [diff] [blame] | 287 | } |
| 288 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 289 | local_irq_restore(flags); |
Joe Perches | 8e4d969 | 2010-01-04 11:53:02 +0000 | [diff] [blame] | 290 | /* |
| 291 | * in any case, we stopped once we tried one block too many, |
| 292 | * or once we reached 32K |
| 293 | */ |
| 294 | return i * 0x1000; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 295 | } |
| 296 | |
Joe Perches | f6de7ac | 2010-01-04 11:53:03 +0000 | [diff] [blame] | 297 | static bool __init mac8390_init(struct net_device *dev, struct nubus_dev *ndev, |
| 298 | enum mac8390_type cardtype) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 299 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 300 | struct nubus_dir dir; |
| 301 | struct nubus_dirent ent; |
| 302 | int offset; |
Joe Perches | f6de7ac | 2010-01-04 11:53:03 +0000 | [diff] [blame] | 303 | volatile unsigned short *i; |
| 304 | |
Geert Uytterhoeven | 51f5300 | 2010-01-09 23:00:32 -0800 | [diff] [blame] | 305 | printk_once(KERN_INFO pr_fmt("%s"), version); |
Joe Perches | f6de7ac | 2010-01-04 11:53:03 +0000 | [diff] [blame] | 306 | |
| 307 | dev->irq = SLOT2IRQ(ndev->board->slot); |
| 308 | /* This is getting to be a habit */ |
| 309 | dev->base_addr = (ndev->board->slot_addr | |
| 310 | ((ndev->board->slot & 0xf) << 20)); |
| 311 | |
| 312 | /* |
| 313 | * Get some Nubus info - we will trust the card's idea |
| 314 | * of where its memory and registers are. |
| 315 | */ |
| 316 | |
| 317 | if (nubus_get_func_dir(ndev, &dir) == -1) { |
| 318 | pr_err("%s: Unable to get Nubus functional directory for slot %X!\n", |
| 319 | dev->name, ndev->board->slot); |
| 320 | return false; |
| 321 | } |
| 322 | |
| 323 | /* Get the MAC address */ |
| 324 | if (nubus_find_rsrc(&dir, NUBUS_RESID_MAC_ADDRESS, &ent) == -1) { |
| 325 | pr_info("%s: Couldn't get MAC address!\n", dev->name); |
| 326 | return false; |
| 327 | } |
| 328 | |
| 329 | nubus_get_rsrc_mem(dev->dev_addr, &ent, 6); |
| 330 | |
| 331 | if (useresources[cardtype] == 1) { |
| 332 | nubus_rewinddir(&dir); |
| 333 | if (nubus_find_rsrc(&dir, NUBUS_RESID_MINOR_BASEOS, |
| 334 | &ent) == -1) { |
| 335 | pr_err("%s: Memory offset resource for slot %X not found!\n", |
| 336 | dev->name, ndev->board->slot); |
| 337 | return false; |
| 338 | } |
| 339 | nubus_get_rsrc_mem(&offset, &ent, 4); |
| 340 | dev->mem_start = dev->base_addr + offset; |
| 341 | /* yes, this is how the Apple driver does it */ |
| 342 | dev->base_addr = dev->mem_start + 0x10000; |
| 343 | nubus_rewinddir(&dir); |
| 344 | if (nubus_find_rsrc(&dir, NUBUS_RESID_MINOR_LENGTH, |
| 345 | &ent) == -1) { |
| 346 | pr_info("%s: Memory length resource for slot %X not found, probing\n", |
| 347 | dev->name, ndev->board->slot); |
| 348 | offset = mac8390_memsize(dev->mem_start); |
| 349 | } else { |
| 350 | nubus_get_rsrc_mem(&offset, &ent, 4); |
| 351 | } |
| 352 | dev->mem_end = dev->mem_start + offset; |
| 353 | } else { |
| 354 | switch (cardtype) { |
| 355 | case MAC8390_KINETICS: |
| 356 | case MAC8390_DAYNA: /* it's the same */ |
| 357 | dev->base_addr = (int)(ndev->board->slot_addr + |
| 358 | DAYNA_8390_BASE); |
| 359 | dev->mem_start = (int)(ndev->board->slot_addr + |
| 360 | DAYNA_8390_MEM); |
| 361 | dev->mem_end = dev->mem_start + |
| 362 | mac8390_memsize(dev->mem_start); |
| 363 | break; |
| 364 | case MAC8390_INTERLAN: |
| 365 | dev->base_addr = (int)(ndev->board->slot_addr + |
| 366 | INTERLAN_8390_BASE); |
| 367 | dev->mem_start = (int)(ndev->board->slot_addr + |
| 368 | INTERLAN_8390_MEM); |
| 369 | dev->mem_end = dev->mem_start + |
| 370 | mac8390_memsize(dev->mem_start); |
| 371 | break; |
| 372 | case MAC8390_CABLETRON: |
| 373 | dev->base_addr = (int)(ndev->board->slot_addr + |
| 374 | CABLETRON_8390_BASE); |
| 375 | dev->mem_start = (int)(ndev->board->slot_addr + |
| 376 | CABLETRON_8390_MEM); |
| 377 | /* The base address is unreadable if 0x00 |
| 378 | * has been written to the command register |
| 379 | * Reset the chip by writing E8390_NODMA + |
| 380 | * E8390_PAGE0 + E8390_STOP just to be |
| 381 | * sure |
| 382 | */ |
| 383 | i = (void *)dev->base_addr; |
| 384 | *i = 0x21; |
| 385 | dev->mem_end = dev->mem_start + |
| 386 | mac8390_memsize(dev->mem_start); |
| 387 | break; |
| 388 | |
| 389 | default: |
| 390 | pr_err("Card type %s is unsupported, sorry\n", |
| 391 | ndev->board->name); |
| 392 | return false; |
| 393 | } |
| 394 | } |
| 395 | |
| 396 | return true; |
| 397 | } |
| 398 | |
| 399 | struct net_device * __init mac8390_probe(int unit) |
| 400 | { |
| 401 | struct net_device *dev; |
| 402 | struct nubus_dev *ndev = NULL; |
| 403 | int err = -ENODEV; |
| 404 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 405 | static unsigned int slots; |
| 406 | |
| 407 | enum mac8390_type cardtype; |
| 408 | |
| 409 | /* probably should check for Nubus instead */ |
| 410 | |
| 411 | if (!MACH_IS_MAC) |
| 412 | return ERR_PTR(-ENODEV); |
| 413 | |
Finn Thain | 217cbfa | 2009-05-25 22:43:49 -0700 | [diff] [blame] | 414 | dev = ____alloc_ei_netdev(0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 415 | if (!dev) |
| 416 | return ERR_PTR(-ENOMEM); |
| 417 | |
| 418 | if (unit >= 0) |
| 419 | sprintf(dev->name, "eth%d", unit); |
| 420 | |
Joe Perches | 8e4d969 | 2010-01-04 11:53:02 +0000 | [diff] [blame] | 421 | while ((ndev = nubus_find_type(NUBUS_CAT_NETWORK, NUBUS_TYPE_ETHERNET, |
| 422 | ndev))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 423 | /* Have we seen it already? */ |
Joe Perches | f6de7ac | 2010-01-04 11:53:03 +0000 | [diff] [blame] | 424 | if (slots & (1 << ndev->board->slot)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 425 | continue; |
Joe Perches | f6de7ac | 2010-01-04 11:53:03 +0000 | [diff] [blame] | 426 | slots |= 1 << ndev->board->slot; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 427 | |
Joe Perches | 8e4d969 | 2010-01-04 11:53:02 +0000 | [diff] [blame] | 428 | cardtype = mac8390_ident(ndev); |
| 429 | if (cardtype == MAC8390_NONE) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 430 | continue; |
| 431 | |
Joe Perches | f6de7ac | 2010-01-04 11:53:03 +0000 | [diff] [blame] | 432 | if (!mac8390_init(dev, ndev, cardtype)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 433 | continue; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 434 | |
| 435 | /* Do the nasty 8390 stuff */ |
| 436 | if (!mac8390_initdev(dev, ndev, cardtype)) |
| 437 | break; |
| 438 | } |
| 439 | |
| 440 | if (!ndev) |
| 441 | goto out; |
| 442 | err = register_netdev(dev); |
| 443 | if (err) |
| 444 | goto out; |
| 445 | return dev; |
| 446 | |
| 447 | out: |
| 448 | free_netdev(dev); |
| 449 | return ERR_PTR(err); |
| 450 | } |
| 451 | |
| 452 | #ifdef MODULE |
| 453 | MODULE_AUTHOR("David Huggins-Daines <dhd@debian.org> and others"); |
| 454 | MODULE_DESCRIPTION("Macintosh NS8390-based Nubus Ethernet driver"); |
| 455 | MODULE_LICENSE("GPL"); |
| 456 | |
| 457 | /* overkill, of course */ |
| 458 | static struct net_device *dev_mac8390[15]; |
| 459 | int init_module(void) |
| 460 | { |
| 461 | int i; |
| 462 | for (i = 0; i < 15; i++) { |
| 463 | struct net_device *dev = mac8390_probe(-1); |
| 464 | if (IS_ERR(dev)) |
| 465 | break; |
| 466 | dev_mac890[i] = dev; |
| 467 | } |
| 468 | if (!i) { |
Joe Perches | 18c0019 | 2010-01-04 11:53:01 +0000 | [diff] [blame] | 469 | pr_notice("No useable cards found, driver NOT installed.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 470 | return -ENODEV; |
| 471 | } |
| 472 | return 0; |
| 473 | } |
| 474 | |
| 475 | void cleanup_module(void) |
| 476 | { |
| 477 | int i; |
| 478 | for (i = 0; i < 15; i++) { |
| 479 | struct net_device *dev = dev_mac890[i]; |
| 480 | if (dev) { |
| 481 | unregister_netdev(dev); |
| 482 | free_netdev(dev); |
| 483 | } |
| 484 | } |
| 485 | } |
| 486 | |
| 487 | #endif /* MODULE */ |
| 488 | |
Stephen Hemminger | ca17584 | 2008-12-02 15:00:28 -0800 | [diff] [blame] | 489 | static const struct net_device_ops mac8390_netdev_ops = { |
| 490 | .ndo_open = mac8390_open, |
| 491 | .ndo_stop = mac8390_close, |
Finn Thain | 217cbfa | 2009-05-25 22:43:49 -0700 | [diff] [blame] | 492 | .ndo_start_xmit = __ei_start_xmit, |
| 493 | .ndo_tx_timeout = __ei_tx_timeout, |
| 494 | .ndo_get_stats = __ei_get_stats, |
| 495 | .ndo_set_multicast_list = __ei_set_multicast_list, |
Stephen Hemminger | ca17584 | 2008-12-02 15:00:28 -0800 | [diff] [blame] | 496 | .ndo_validate_addr = eth_validate_addr, |
Stephen Hemminger | fe96aaa | 2009-01-09 11:13:14 +0000 | [diff] [blame] | 497 | .ndo_set_mac_address = eth_mac_addr, |
Stephen Hemminger | ca17584 | 2008-12-02 15:00:28 -0800 | [diff] [blame] | 498 | .ndo_change_mtu = eth_change_mtu, |
| 499 | #ifdef CONFIG_NET_POLL_CONTROLLER |
Finn Thain | 4e0168f | 2009-05-28 02:05:53 +0000 | [diff] [blame] | 500 | .ndo_poll_controller = __ei_poll, |
Stephen Hemminger | ca17584 | 2008-12-02 15:00:28 -0800 | [diff] [blame] | 501 | #endif |
| 502 | }; |
| 503 | |
Joe Perches | 8e4d969 | 2010-01-04 11:53:02 +0000 | [diff] [blame] | 504 | static int __init mac8390_initdev(struct net_device *dev, |
| 505 | struct nubus_dev *ndev, |
| 506 | enum mac8390_type type) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 507 | { |
Joe Perches | 8e4d969 | 2010-01-04 11:53:02 +0000 | [diff] [blame] | 508 | static u32 fwrd4_offsets[16] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 509 | 0, 4, 8, 12, |
| 510 | 16, 20, 24, 28, |
| 511 | 32, 36, 40, 44, |
| 512 | 48, 52, 56, 60 |
| 513 | }; |
Joe Perches | 8e4d969 | 2010-01-04 11:53:02 +0000 | [diff] [blame] | 514 | static u32 back4_offsets[16] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 515 | 60, 56, 52, 48, |
| 516 | 44, 40, 36, 32, |
| 517 | 28, 24, 20, 16, |
| 518 | 12, 8, 4, 0 |
| 519 | }; |
Joe Perches | 8e4d969 | 2010-01-04 11:53:02 +0000 | [diff] [blame] | 520 | static u32 fwrd2_offsets[16] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 521 | 0, 2, 4, 6, |
| 522 | 8, 10, 12, 14, |
| 523 | 16, 18, 20, 22, |
| 524 | 24, 26, 28, 30 |
| 525 | }; |
| 526 | |
Finn Thain | 2964db0 | 2007-05-01 22:32:54 +0200 | [diff] [blame] | 527 | int access_bitmode = 0; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 528 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 529 | /* Now fill in our stuff */ |
Stephen Hemminger | ca17584 | 2008-12-02 15:00:28 -0800 | [diff] [blame] | 530 | dev->netdev_ops = &mac8390_netdev_ops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 531 | |
| 532 | /* GAR, ei_status is actually a macro even though it looks global */ |
| 533 | ei_status.name = cardname[type]; |
| 534 | ei_status.word16 = word16[type]; |
| 535 | |
| 536 | /* Cabletron's TX/RX buffers are backwards */ |
| 537 | if (type == MAC8390_CABLETRON) { |
Joe Perches | 8e4d969 | 2010-01-04 11:53:02 +0000 | [diff] [blame] | 538 | ei_status.tx_start_page = CABLETRON_TX_START_PG; |
| 539 | ei_status.rx_start_page = CABLETRON_RX_START_PG; |
| 540 | ei_status.stop_page = CABLETRON_RX_STOP_PG; |
| 541 | ei_status.rmem_start = dev->mem_start; |
| 542 | ei_status.rmem_end = dev->mem_start + CABLETRON_RX_STOP_PG*256; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 543 | } else { |
Joe Perches | 8e4d969 | 2010-01-04 11:53:02 +0000 | [diff] [blame] | 544 | ei_status.tx_start_page = WD_START_PG; |
| 545 | ei_status.rx_start_page = WD_START_PG + TX_PAGES; |
| 546 | ei_status.stop_page = (dev->mem_end - dev->mem_start)/256; |
| 547 | ei_status.rmem_start = dev->mem_start + TX_PAGES*256; |
| 548 | ei_status.rmem_end = dev->mem_end; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 549 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 550 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 551 | /* Fill in model-specific information and functions */ |
Joe Perches | 3507640 | 2010-01-04 11:52:59 +0000 | [diff] [blame] | 552 | switch (type) { |
Finn Thain | 2964db0 | 2007-05-01 22:32:54 +0200 | [diff] [blame] | 553 | case MAC8390_FARALLON: |
| 554 | case MAC8390_APPLE: |
Joe Perches | 3507640 | 2010-01-04 11:52:59 +0000 | [diff] [blame] | 555 | switch (mac8390_testio(dev->mem_start)) { |
| 556 | case ACCESS_UNKNOWN: |
Joe Perches | 18c0019 | 2010-01-04 11:53:01 +0000 | [diff] [blame] | 557 | pr_info("Don't know how to access card memory!\n"); |
Joe Perches | 3507640 | 2010-01-04 11:52:59 +0000 | [diff] [blame] | 558 | return -ENODEV; |
| 559 | break; |
Finn Thain | 2964db0 | 2007-05-01 22:32:54 +0200 | [diff] [blame] | 560 | |
Joe Perches | 3507640 | 2010-01-04 11:52:59 +0000 | [diff] [blame] | 561 | case ACCESS_16: |
| 562 | /* 16 bit card, register map is reversed */ |
| 563 | ei_status.reset_8390 = &mac8390_no_reset; |
| 564 | ei_status.block_input = &slow_sane_block_input; |
| 565 | ei_status.block_output = &slow_sane_block_output; |
| 566 | ei_status.get_8390_hdr = &slow_sane_get_8390_hdr; |
| 567 | ei_status.reg_offset = back4_offsets; |
| 568 | break; |
Finn Thain | 2964db0 | 2007-05-01 22:32:54 +0200 | [diff] [blame] | 569 | |
Joe Perches | 3507640 | 2010-01-04 11:52:59 +0000 | [diff] [blame] | 570 | case ACCESS_32: |
| 571 | /* 32 bit card, register map is reversed */ |
| 572 | ei_status.reset_8390 = &mac8390_no_reset; |
| 573 | ei_status.block_input = &sane_block_input; |
| 574 | ei_status.block_output = &sane_block_output; |
| 575 | ei_status.get_8390_hdr = &sane_get_8390_hdr; |
| 576 | ei_status.reg_offset = back4_offsets; |
| 577 | access_bitmode = 1; |
| 578 | break; |
Finn Thain | 2964db0 | 2007-05-01 22:32:54 +0200 | [diff] [blame] | 579 | } |
| 580 | break; |
| 581 | |
| 582 | case MAC8390_ASANTE: |
| 583 | /* Some Asante cards pass the 32 bit test |
| 584 | * but overwrite system memory when run at 32 bit. |
| 585 | * so we run them all at 16 bit. |
| 586 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 587 | ei_status.reset_8390 = &mac8390_no_reset; |
| 588 | ei_status.block_input = &slow_sane_block_input; |
| 589 | ei_status.block_output = &slow_sane_block_output; |
| 590 | ei_status.get_8390_hdr = &slow_sane_get_8390_hdr; |
| 591 | ei_status.reg_offset = back4_offsets; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 592 | break; |
Finn Thain | 2964db0 | 2007-05-01 22:32:54 +0200 | [diff] [blame] | 593 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 594 | case MAC8390_CABLETRON: |
| 595 | /* 16 bit card, register map is short forward */ |
| 596 | ei_status.reset_8390 = &mac8390_no_reset; |
| 597 | ei_status.block_input = &slow_sane_block_input; |
| 598 | ei_status.block_output = &slow_sane_block_output; |
| 599 | ei_status.get_8390_hdr = &slow_sane_get_8390_hdr; |
| 600 | ei_status.reg_offset = fwrd2_offsets; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 601 | break; |
Finn Thain | 2964db0 | 2007-05-01 22:32:54 +0200 | [diff] [blame] | 602 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 603 | case MAC8390_DAYNA: |
| 604 | case MAC8390_KINETICS: |
Finn Thain | 2964db0 | 2007-05-01 22:32:54 +0200 | [diff] [blame] | 605 | /* 16 bit memory, register map is forward */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 606 | /* dayna and similar */ |
| 607 | ei_status.reset_8390 = &mac8390_no_reset; |
| 608 | ei_status.block_input = &dayna_block_input; |
| 609 | ei_status.block_output = &dayna_block_output; |
| 610 | ei_status.get_8390_hdr = &dayna_get_8390_hdr; |
| 611 | ei_status.reg_offset = fwrd4_offsets; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 612 | break; |
Finn Thain | 2964db0 | 2007-05-01 22:32:54 +0200 | [diff] [blame] | 613 | |
| 614 | case MAC8390_INTERLAN: |
| 615 | /* 16 bit memory, register map is forward */ |
| 616 | ei_status.reset_8390 = &interlan_reset; |
| 617 | ei_status.block_input = &slow_sane_block_input; |
| 618 | ei_status.block_output = &slow_sane_block_output; |
| 619 | ei_status.get_8390_hdr = &slow_sane_get_8390_hdr; |
Joe Perches | 8e4d969 | 2010-01-04 11:53:02 +0000 | [diff] [blame] | 620 | ei_status.reg_offset = fwrd4_offsets; |
| 621 | break; |
Finn Thain | 2964db0 | 2007-05-01 22:32:54 +0200 | [diff] [blame] | 622 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 623 | default: |
Joe Perches | 18c0019 | 2010-01-04 11:53:01 +0000 | [diff] [blame] | 624 | pr_err("Card type %s is unsupported, sorry\n", |
| 625 | ndev->board->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 626 | return -ENODEV; |
| 627 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 628 | |
Al Viro | 8c6270f | 2006-10-10 00:19:36 +0100 | [diff] [blame] | 629 | __NS8390_init(dev, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 630 | |
| 631 | /* Good, done, now spit out some messages */ |
Joe Perches | 18c0019 | 2010-01-04 11:53:01 +0000 | [diff] [blame] | 632 | pr_info("%s: %s in slot %X (type %s)\n", |
| 633 | dev->name, ndev->board->name, ndev->board->slot, |
| 634 | cardname[type]); |
| 635 | pr_info("MAC %pM IRQ %d, %d KB shared memory at %#lx, %d-bit access.\n", |
| 636 | dev->dev_addr, dev->irq, |
| 637 | (unsigned int)(dev->mem_end - dev->mem_start) >> 10, |
| 638 | dev->mem_start, access_bitmode ? 32 : 16); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 639 | return 0; |
| 640 | } |
| 641 | |
| 642 | static int mac8390_open(struct net_device *dev) |
| 643 | { |
Al Viro | 8c6270f | 2006-10-10 00:19:36 +0100 | [diff] [blame] | 644 | __ei_open(dev); |
| 645 | if (request_irq(dev->irq, __ei_interrupt, 0, "8390 Ethernet", dev)) { |
Joe Perches | 18c0019 | 2010-01-04 11:53:01 +0000 | [diff] [blame] | 646 | pr_info("%s: unable to get IRQ %d.\n", dev->name, dev->irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 647 | return -EAGAIN; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 648 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 649 | return 0; |
| 650 | } |
| 651 | |
| 652 | static int mac8390_close(struct net_device *dev) |
| 653 | { |
| 654 | free_irq(dev->irq, dev); |
Al Viro | 8c6270f | 2006-10-10 00:19:36 +0100 | [diff] [blame] | 655 | __ei_close(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 656 | return 0; |
| 657 | } |
| 658 | |
| 659 | static void mac8390_no_reset(struct net_device *dev) |
| 660 | { |
| 661 | ei_status.txing = 0; |
| 662 | if (ei_debug > 1) |
Joe Perches | 18c0019 | 2010-01-04 11:53:01 +0000 | [diff] [blame] | 663 | pr_info("reset not supported\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 664 | } |
| 665 | |
Finn Thain | 2964db0 | 2007-05-01 22:32:54 +0200 | [diff] [blame] | 666 | static void interlan_reset(struct net_device *dev) |
| 667 | { |
Joe Perches | 8e4d969 | 2010-01-04 11:53:02 +0000 | [diff] [blame] | 668 | unsigned char *target = nubus_slot_addr(IRQ2SLOT(dev->irq)); |
Finn Thain | 2964db0 | 2007-05-01 22:32:54 +0200 | [diff] [blame] | 669 | if (ei_debug > 1) |
Joe Perches | 18c0019 | 2010-01-04 11:53:01 +0000 | [diff] [blame] | 670 | pr_info("Need to reset the NS8390 t=%lu...", jiffies); |
Finn Thain | 2964db0 | 2007-05-01 22:32:54 +0200 | [diff] [blame] | 671 | ei_status.txing = 0; |
| 672 | target[0xC0000] = 0; |
| 673 | if (ei_debug > 1) |
Joe Perches | 18c0019 | 2010-01-04 11:53:01 +0000 | [diff] [blame] | 674 | pr_cont("reset complete\n"); |
Finn Thain | 2964db0 | 2007-05-01 22:32:54 +0200 | [diff] [blame] | 675 | } |
| 676 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 677 | /* dayna_memcpy_fromio/dayna_memcpy_toio */ |
| 678 | /* directly from daynaport.c by Alan Cox */ |
Joe Perches | 8e4d969 | 2010-01-04 11:53:02 +0000 | [diff] [blame] | 679 | static void dayna_memcpy_fromcard(struct net_device *dev, void *to, int from, |
| 680 | int count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 681 | { |
Al Viro | 09cc07a | 2006-01-12 01:06:21 -0800 | [diff] [blame] | 682 | volatile unsigned char *ptr; |
Joe Perches | 8e4d969 | 2010-01-04 11:53:02 +0000 | [diff] [blame] | 683 | unsigned char *target = to; |
| 684 | from <<= 1; /* word, skip overhead */ |
| 685 | ptr = (unsigned char *)(dev->mem_start+from); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 686 | /* Leading byte? */ |
Joe Perches | 8e4d969 | 2010-01-04 11:53:02 +0000 | [diff] [blame] | 687 | if (from & 2) { |
Al Viro | 09cc07a | 2006-01-12 01:06:21 -0800 | [diff] [blame] | 688 | *target++ = ptr[-1]; |
| 689 | ptr += 2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 690 | count--; |
| 691 | } |
Joe Perches | 8e4d969 | 2010-01-04 11:53:02 +0000 | [diff] [blame] | 692 | while (count >= 2) { |
Al Viro | 09cc07a | 2006-01-12 01:06:21 -0800 | [diff] [blame] | 693 | *(unsigned short *)target = *(unsigned short volatile *)ptr; |
| 694 | ptr += 4; /* skip cruft */ |
| 695 | target += 2; |
Joe Perches | 8e4d969 | 2010-01-04 11:53:02 +0000 | [diff] [blame] | 696 | count -= 2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 697 | } |
| 698 | /* Trailing byte? */ |
Joe Perches | 8e4d969 | 2010-01-04 11:53:02 +0000 | [diff] [blame] | 699 | if (count) |
Al Viro | 09cc07a | 2006-01-12 01:06:21 -0800 | [diff] [blame] | 700 | *target = *ptr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 701 | } |
| 702 | |
Joe Perches | 8e4d969 | 2010-01-04 11:53:02 +0000 | [diff] [blame] | 703 | static void dayna_memcpy_tocard(struct net_device *dev, int to, |
| 704 | const void *from, int count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 705 | { |
| 706 | volatile unsigned short *ptr; |
Joe Perches | 8e4d969 | 2010-01-04 11:53:02 +0000 | [diff] [blame] | 707 | const unsigned char *src = from; |
| 708 | to <<= 1; /* word, skip overhead */ |
| 709 | ptr = (unsigned short *)(dev->mem_start+to); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 710 | /* Leading byte? */ |
Joe Perches | 8e4d969 | 2010-01-04 11:53:02 +0000 | [diff] [blame] | 711 | if (to & 2) { /* avoid a byte write (stomps on other data) */ |
Al Viro | 09cc07a | 2006-01-12 01:06:21 -0800 | [diff] [blame] | 712 | ptr[-1] = (ptr[-1]&0xFF00)|*src++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 713 | ptr++; |
| 714 | count--; |
| 715 | } |
Joe Perches | 8e4d969 | 2010-01-04 11:53:02 +0000 | [diff] [blame] | 716 | while (count >= 2) { |
| 717 | *ptr++ = *(unsigned short *)src; /* Copy and */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 718 | ptr++; /* skip cruft */ |
Al Viro | 09cc07a | 2006-01-12 01:06:21 -0800 | [diff] [blame] | 719 | src += 2; |
Joe Perches | 8e4d969 | 2010-01-04 11:53:02 +0000 | [diff] [blame] | 720 | count -= 2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 721 | } |
| 722 | /* Trailing byte? */ |
Joe Perches | 8e4d969 | 2010-01-04 11:53:02 +0000 | [diff] [blame] | 723 | if (count) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 724 | /* card doesn't like byte writes */ |
Joe Perches | 8e4d969 | 2010-01-04 11:53:02 +0000 | [diff] [blame] | 725 | *ptr = (*ptr & 0x00FF) | (*src << 8); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 726 | } |
| 727 | } |
| 728 | |
| 729 | /* sane block input/output */ |
| 730 | static void sane_get_8390_hdr(struct net_device *dev, |
| 731 | struct e8390_pkt_hdr *hdr, int ring_page) |
| 732 | { |
| 733 | unsigned long hdr_start = (ring_page - WD_START_PG)<<8; |
| 734 | memcpy_fromio((void *)hdr, (char *)dev->mem_start + hdr_start, 4); |
| 735 | /* Fix endianness */ |
| 736 | hdr->count = swab16(hdr->count); |
| 737 | } |
| 738 | |
| 739 | static void sane_block_input(struct net_device *dev, int count, |
| 740 | struct sk_buff *skb, int ring_offset) |
| 741 | { |
| 742 | unsigned long xfer_base = ring_offset - (WD_START_PG<<8); |
| 743 | unsigned long xfer_start = xfer_base + dev->mem_start; |
| 744 | |
| 745 | if (xfer_start + count > ei_status.rmem_end) { |
| 746 | /* We must wrap the input move. */ |
| 747 | int semi_count = ei_status.rmem_end - xfer_start; |
Joe Perches | 8e4d969 | 2010-01-04 11:53:02 +0000 | [diff] [blame] | 748 | memcpy_fromio(skb->data, (char *)dev->mem_start + xfer_base, |
| 749 | semi_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 750 | count -= semi_count; |
Joe Perches | 8e4d969 | 2010-01-04 11:53:02 +0000 | [diff] [blame] | 751 | memcpy_toio(skb->data + semi_count, |
| 752 | (char *)ei_status.rmem_start, count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 753 | } else { |
Joe Perches | 8e4d969 | 2010-01-04 11:53:02 +0000 | [diff] [blame] | 754 | memcpy_fromio(skb->data, (char *)dev->mem_start + xfer_base, |
| 755 | count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 756 | } |
| 757 | } |
| 758 | |
| 759 | static void sane_block_output(struct net_device *dev, int count, |
| 760 | const unsigned char *buf, int start_page) |
| 761 | { |
| 762 | long shmem = (start_page - WD_START_PG)<<8; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 763 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 764 | memcpy_toio((char *)dev->mem_start + shmem, buf, count); |
| 765 | } |
| 766 | |
| 767 | /* dayna block input/output */ |
Joe Perches | 8e4d969 | 2010-01-04 11:53:02 +0000 | [diff] [blame] | 768 | static void dayna_get_8390_hdr(struct net_device *dev, |
| 769 | struct e8390_pkt_hdr *hdr, int ring_page) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 770 | { |
| 771 | unsigned long hdr_start = (ring_page - WD_START_PG)<<8; |
| 772 | |
Joe Perches | 5c7fffd | 2010-01-04 11:53:00 +0000 | [diff] [blame] | 773 | dayna_memcpy_fromcard(dev, hdr, hdr_start, 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 774 | /* Fix endianness */ |
Joe Perches | 8e4d969 | 2010-01-04 11:53:02 +0000 | [diff] [blame] | 775 | hdr->count = (hdr->count & 0xFF) << 8 | (hdr->count >> 8); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 776 | } |
| 777 | |
Joe Perches | 8e4d969 | 2010-01-04 11:53:02 +0000 | [diff] [blame] | 778 | static void dayna_block_input(struct net_device *dev, int count, |
| 779 | struct sk_buff *skb, int ring_offset) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 780 | { |
| 781 | unsigned long xfer_base = ring_offset - (WD_START_PG<<8); |
| 782 | unsigned long xfer_start = xfer_base+dev->mem_start; |
| 783 | |
| 784 | /* Note the offset math is done in card memory space which is word |
| 785 | per long onto our space. */ |
| 786 | |
Joe Perches | 8e4d969 | 2010-01-04 11:53:02 +0000 | [diff] [blame] | 787 | if (xfer_start + count > ei_status.rmem_end) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 788 | /* We must wrap the input move. */ |
| 789 | int semi_count = ei_status.rmem_end - xfer_start; |
| 790 | dayna_memcpy_fromcard(dev, skb->data, xfer_base, semi_count); |
| 791 | count -= semi_count; |
| 792 | dayna_memcpy_fromcard(dev, skb->data + semi_count, |
| 793 | ei_status.rmem_start - dev->mem_start, |
| 794 | count); |
Joe Perches | 8e4d969 | 2010-01-04 11:53:02 +0000 | [diff] [blame] | 795 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 796 | dayna_memcpy_fromcard(dev, skb->data, xfer_base, count); |
| 797 | } |
| 798 | } |
| 799 | |
Joe Perches | 8e4d969 | 2010-01-04 11:53:02 +0000 | [diff] [blame] | 800 | static void dayna_block_output(struct net_device *dev, int count, |
| 801 | const unsigned char *buf, |
| 802 | int start_page) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 803 | { |
| 804 | long shmem = (start_page - WD_START_PG)<<8; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 805 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 806 | dayna_memcpy_tocard(dev, shmem, buf, count); |
| 807 | } |
| 808 | |
| 809 | /* Cabletron block I/O */ |
Joe Perches | 8e4d969 | 2010-01-04 11:53:02 +0000 | [diff] [blame] | 810 | static void slow_sane_get_8390_hdr(struct net_device *dev, |
| 811 | struct e8390_pkt_hdr *hdr, |
| 812 | int ring_page) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 813 | { |
| 814 | unsigned long hdr_start = (ring_page - WD_START_PG)<<8; |
Joe Perches | 5c7fffd | 2010-01-04 11:53:00 +0000 | [diff] [blame] | 815 | word_memcpy_fromcard(hdr, (char *)dev->mem_start + hdr_start, 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 816 | /* Register endianism - fix here rather than 8390.c */ |
| 817 | hdr->count = (hdr->count&0xFF)<<8|(hdr->count>>8); |
| 818 | } |
| 819 | |
Joe Perches | 8e4d969 | 2010-01-04 11:53:02 +0000 | [diff] [blame] | 820 | static void slow_sane_block_input(struct net_device *dev, int count, |
| 821 | struct sk_buff *skb, int ring_offset) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 822 | { |
| 823 | unsigned long xfer_base = ring_offset - (WD_START_PG<<8); |
| 824 | unsigned long xfer_start = xfer_base+dev->mem_start; |
| 825 | |
Joe Perches | 8e4d969 | 2010-01-04 11:53:02 +0000 | [diff] [blame] | 826 | if (xfer_start + count > ei_status.rmem_end) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 827 | /* We must wrap the input move. */ |
| 828 | int semi_count = ei_status.rmem_end - xfer_start; |
Joe Perches | 5c7fffd | 2010-01-04 11:53:00 +0000 | [diff] [blame] | 829 | word_memcpy_fromcard(skb->data, |
| 830 | (char *)dev->mem_start + xfer_base, |
| 831 | semi_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 832 | count -= semi_count; |
| 833 | word_memcpy_fromcard(skb->data + semi_count, |
| 834 | (char *)ei_status.rmem_start, count); |
Joe Perches | 8e4d969 | 2010-01-04 11:53:02 +0000 | [diff] [blame] | 835 | } else { |
Joe Perches | 5c7fffd | 2010-01-04 11:53:00 +0000 | [diff] [blame] | 836 | word_memcpy_fromcard(skb->data, |
| 837 | (char *)dev->mem_start + xfer_base, count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 838 | } |
| 839 | } |
| 840 | |
Joe Perches | 8e4d969 | 2010-01-04 11:53:02 +0000 | [diff] [blame] | 841 | static void slow_sane_block_output(struct net_device *dev, int count, |
| 842 | const unsigned char *buf, int start_page) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 843 | { |
| 844 | long shmem = (start_page - WD_START_PG)<<8; |
| 845 | |
| 846 | word_memcpy_tocard((char *)dev->mem_start + shmem, buf, count); |
| 847 | } |
| 848 | |
| 849 | static void word_memcpy_tocard(void *tp, const void *fp, int count) |
| 850 | { |
| 851 | volatile unsigned short *to = tp; |
| 852 | const unsigned short *from = fp; |
| 853 | |
| 854 | count++; |
Joe Perches | 8e4d969 | 2010-01-04 11:53:02 +0000 | [diff] [blame] | 855 | count /= 2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 856 | |
Joe Perches | 8e4d969 | 2010-01-04 11:53:02 +0000 | [diff] [blame] | 857 | while (count--) |
| 858 | *to++ = *from++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 859 | } |
| 860 | |
| 861 | static void word_memcpy_fromcard(void *tp, const void *fp, int count) |
| 862 | { |
| 863 | unsigned short *to = tp; |
| 864 | const volatile unsigned short *from = fp; |
| 865 | |
| 866 | count++; |
Joe Perches | 8e4d969 | 2010-01-04 11:53:02 +0000 | [diff] [blame] | 867 | count /= 2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 868 | |
Joe Perches | 8e4d969 | 2010-01-04 11:53:02 +0000 | [diff] [blame] | 869 | while (count--) |
| 870 | *to++ = *from++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 871 | } |
| 872 | |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 873 | |