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