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