blob: b9283901136e974a9ad4207cae898cb492207700 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/* 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 Garzik6aa20a22006-09-13 13:24:59 -040010/* 2000-02-28: support added for Dayna and Kinetics cards by
Linus Torvalds1da177e2005-04-16 15:20:36 -070011 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 Garzik6aa20a22006-09-13 13:24:59 -040015 * and fixed access to Sonic Sys card which masquerades as a Farallon
Linus Torvalds1da177e2005-04-16 15:20:36 -070016 * by rayk@knightsmanor.org */
Finn Thain2964db02007-05-01 22:32:54 +020017/* 2002-12-30: Try to support more cards, some clues from NetBSD driver */
18/* 2003-12-26: Make sure Asante cards always work. */
Linus Torvalds1da177e2005-04-16 15:20:36 -070019
Joe Perches18c00192010-01-04 11:53:01 +000020#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
21
Linus Torvalds1da177e2005-04-16 15:20:36 -070022#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 Torvalds1da177e2005-04-16 15:20:36 -070031#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 Perches8e4d9692010-01-04 11:53:02 +000038#include <linux/io.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070039
Linus Torvalds1da177e2005-04-16 15:20:36 -070040#include <asm/dma.h>
41#include <asm/hwtest.h>
42#include <asm/macints.h>
43
Al Viro8c6270f2006-10-10 00:19:36 +010044static char version[] =
Joe Perches18c00192010-01-04 11:53:01 +000045 "v0.4 2001-05-15 David Huggins-Daines <dhd@debian.org> and others\n";
Al Viro8c6270f2006-10-10 00:19:36 +010046
47#define EI_SHIFT(x) (ei_local->reg_offset[x])
Joe Perches8e4d9692010-01-04 11:53:02 +000048#define ei_inb(port) in_8(port)
49#define ei_outb(val, port) out_8(port, val)
50#define ei_inb_p(port) in_8(port)
51#define ei_outb_p(val, port) out_8(port, val)
Al Viro8c6270f2006-10-10 00:19:36 +010052
53#include "lib8390.c"
Linus Torvalds1da177e2005-04-16 15:20:36 -070054
55#define WD_START_PG 0x00 /* First page of TX buffer */
56#define CABLETRON_RX_START_PG 0x00 /* First page of RX buffer */
57#define CABLETRON_RX_STOP_PG 0x30 /* Last page +1 of RX ring */
Joe Perches8e4d9692010-01-04 11:53:02 +000058#define CABLETRON_TX_START_PG CABLETRON_RX_STOP_PG
59 /* First page of TX buffer */
Linus Torvalds1da177e2005-04-16 15:20:36 -070060
Joe Perches8e4d9692010-01-04 11:53:02 +000061/*
62 * Unfortunately it seems we have to hardcode these for the moment
63 * Shouldn't the card know about this?
64 * Does anyone know where to read it off the card?
65 * Do we trust the data provided by the card?
66 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070067
68#define DAYNA_8390_BASE 0x80000
69#define DAYNA_8390_MEM 0x00000
70
Jeff Garzik6aa20a22006-09-13 13:24:59 -040071#define CABLETRON_8390_BASE 0x90000
Linus Torvalds1da177e2005-04-16 15:20:36 -070072#define CABLETRON_8390_MEM 0x00000
73
Finn Thain2964db02007-05-01 22:32:54 +020074#define INTERLAN_8390_BASE 0xE0000
75#define INTERLAN_8390_MEM 0xD0000
76
Linus Torvalds1da177e2005-04-16 15:20:36 -070077enum mac8390_type {
78 MAC8390_NONE = -1,
79 MAC8390_APPLE,
80 MAC8390_ASANTE,
Finn Thain2964db02007-05-01 22:32:54 +020081 MAC8390_FARALLON,
Linus Torvalds1da177e2005-04-16 15:20:36 -070082 MAC8390_CABLETRON,
83 MAC8390_DAYNA,
84 MAC8390_INTERLAN,
85 MAC8390_KINETICS,
Linus Torvalds1da177e2005-04-16 15:20:36 -070086};
87
Joe Perches8e4d9692010-01-04 11:53:02 +000088static const char *cardname[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -070089 "apple",
90 "asante",
91 "farallon",
92 "cabletron",
93 "dayna",
94 "interlan",
95 "kinetics",
Linus Torvalds1da177e2005-04-16 15:20:36 -070096};
97
Joe Perches8e4d9692010-01-04 11:53:02 +000098static const int word16[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -070099 1, /* apple */
100 1, /* asante */
101 1, /* farallon */
102 1, /* cabletron */
103 0, /* dayna */
104 1, /* interlan */
105 0, /* kinetics */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106};
107
108/* on which cards do we use NuBus resources? */
Joe Perches8e4d9692010-01-04 11:53:02 +0000109static const int useresources[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110 1, /* apple */
111 1, /* asante */
112 1, /* farallon */
113 0, /* cabletron */
114 0, /* dayna */
115 0, /* interlan */
116 0, /* kinetics */
Finn Thain2964db02007-05-01 22:32:54 +0200117};
118
119enum mac8390_access {
120 ACCESS_UNKNOWN = 0,
121 ACCESS_32,
122 ACCESS_16,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123};
124
Joe Perches8e4d9692010-01-04 11:53:02 +0000125extern int mac8390_memtest(struct net_device *dev);
126static int mac8390_initdev(struct net_device *dev, struct nubus_dev *ndev,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127 enum mac8390_type type);
128
Joe Perches8e4d9692010-01-04 11:53:02 +0000129static int mac8390_open(struct net_device *dev);
130static int mac8390_close(struct net_device *dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131static void mac8390_no_reset(struct net_device *dev);
Finn Thain2964db02007-05-01 22:32:54 +0200132static void interlan_reset(struct net_device *dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133
Finn Thain2964db02007-05-01 22:32:54 +0200134/* Sane (32-bit chunk memory read/write) - Some Farallon and Apple do this*/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135static void sane_get_8390_hdr(struct net_device *dev,
136 struct e8390_pkt_hdr *hdr, int ring_page);
Joe Perches8e4d9692010-01-04 11:53:02 +0000137static void sane_block_input(struct net_device *dev, int count,
138 struct sk_buff *skb, int ring_offset);
139static void sane_block_output(struct net_device *dev, int count,
140 const unsigned char *buf, const int start_page);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141
142/* dayna_memcpy to and from card */
143static void dayna_memcpy_fromcard(struct net_device *dev, void *to,
144 int from, int count);
145static void dayna_memcpy_tocard(struct net_device *dev, int to,
146 const void *from, int count);
147
148/* Dayna - Dayna/Kinetics use this */
149static void dayna_get_8390_hdr(struct net_device *dev,
150 struct e8390_pkt_hdr *hdr, int ring_page);
151static void dayna_block_input(struct net_device *dev, int count,
152 struct sk_buff *skb, int ring_offset);
153static void dayna_block_output(struct net_device *dev, int count,
154 const unsigned char *buf, int start_page);
155
Joe Perches8e4d9692010-01-04 11:53:02 +0000156#define memcpy_fromio(a, b, c) memcpy((a), (void *)(b), (c))
157#define memcpy_toio(a, b, c) memcpy((void *)(a), (b), (c))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158
Geert Uytterhoeven7e364e92010-06-02 07:36:20 +0000159#define memcmp_withio(a, b, c) memcmp((a), (void *)(b), (c))
160
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161/* Slow Sane (16-bit chunk memory read/write) Cabletron uses this */
162static void slow_sane_get_8390_hdr(struct net_device *dev,
163 struct e8390_pkt_hdr *hdr, int ring_page);
164static void slow_sane_block_input(struct net_device *dev, int count,
165 struct sk_buff *skb, int ring_offset);
166static void slow_sane_block_output(struct net_device *dev, int count,
167 const unsigned char *buf, int start_page);
Geert Uytterhoeven7e364e92010-06-02 07:36:20 +0000168static void word_memcpy_tocard(unsigned long tp, const void *fp, int count);
169static void word_memcpy_fromcard(void *tp, unsigned long fp, int count);
Matthew Whiteheadc45f8122013-12-11 17:00:59 -0500170static u32 mac8390_msg_enable;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171
Adrian Bunk909fa882008-06-10 01:23:39 +0300172static enum mac8390_type __init mac8390_ident(struct nubus_dev *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173{
Finn Thain2964db02007-05-01 22:32:54 +0200174 switch (dev->dr_sw) {
Joe Perches35076402010-01-04 11:52:59 +0000175 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;
Joe Perches35076402010-01-04 11:52:59 +0000181 default:
182 return MAC8390_APPLE;
Joe Perches35076402010-01-04 11:52:59 +0000183 }
184 break;
Finn Thain2964db02007-05-01 22:32:54 +0200185
Joe Perches35076402010-01-04 11:52:59 +0000186 case NUBUS_DRSW_APPLE:
187 switch (dev->dr_hw) {
188 case NUBUS_DRHW_ASANTE_LC:
189 return MAC8390_NONE;
Joe Perches35076402010-01-04 11:52:59 +0000190 case NUBUS_DRHW_CABLETRON:
191 return MAC8390_CABLETRON;
Joe Perches35076402010-01-04 11:52:59 +0000192 default:
193 return MAC8390_APPLE;
Joe Perches35076402010-01-04 11:52:59 +0000194 }
195 break;
Finn Thain2964db02007-05-01 22:32:54 +0200196
Joe Perches35076402010-01-04 11:52:59 +0000197 case NUBUS_DRSW_ASANTE:
198 return MAC8390_ASANTE;
199 break;
Finn Thain2964db02007-05-01 22:32:54 +0200200
Joe Perches35076402010-01-04 11:52:59 +0000201 case NUBUS_DRSW_TECHWORKS:
202 case NUBUS_DRSW_DAYNA2:
203 case NUBUS_DRSW_DAYNA_LC:
204 if (dev->dr_hw == NUBUS_DRHW_CABLETRON)
205 return MAC8390_CABLETRON;
206 else
207 return MAC8390_APPLE;
208 break;
Finn Thain2964db02007-05-01 22:32:54 +0200209
Joe Perches35076402010-01-04 11:52:59 +0000210 case NUBUS_DRSW_FARALLON:
211 return MAC8390_FARALLON;
212 break;
Finn Thain2964db02007-05-01 22:32:54 +0200213
Joe Perches35076402010-01-04 11:52:59 +0000214 case NUBUS_DRSW_KINETICS:
215 switch (dev->dr_hw) {
216 case NUBUS_DRHW_INTERLAN:
217 return MAC8390_INTERLAN;
Joe Perches35076402010-01-04 11:52:59 +0000218 default:
219 return MAC8390_KINETICS;
Joe Perches35076402010-01-04 11:52:59 +0000220 }
221 break;
Finn Thain2964db02007-05-01 22:32:54 +0200222
Joe Perches35076402010-01-04 11:52:59 +0000223 case NUBUS_DRSW_DAYNA:
Joe Perches8e4d9692010-01-04 11:53:02 +0000224 /*
225 * These correspond to Dayna Sonic cards
226 * which use the macsonic driver
227 */
Joe Perches35076402010-01-04 11:52:59 +0000228 if (dev->dr_hw == NUBUS_DRHW_SMC9194 ||
Joe Perches8e4d9692010-01-04 11:53:02 +0000229 dev->dr_hw == NUBUS_DRHW_INTERLAN)
Joe Perches35076402010-01-04 11:52:59 +0000230 return MAC8390_NONE;
231 else
232 return MAC8390_DAYNA;
233 break;
Finn Thain2964db02007-05-01 22:32:54 +0200234 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235 return MAC8390_NONE;
236}
237
Adrian Bunk909fa882008-06-10 01:23:39 +0300238static enum mac8390_access __init mac8390_testio(volatile unsigned long membase)
Finn Thain2964db02007-05-01 22:32:54 +0200239{
240 unsigned long outdata = 0xA5A0B5B0;
241 unsigned long indata = 0x00000000;
242 /* Try writing 32 bits */
Geert Uytterhoeven7e364e92010-06-02 07:36:20 +0000243 memcpy_toio(membase, &outdata, 4);
Finn Thain2964db02007-05-01 22:32:54 +0200244 /* Now compare them */
Geert Uytterhoeven7e364e92010-06-02 07:36:20 +0000245 if (memcmp_withio(&outdata, membase, 4) == 0)
Finn Thain2964db02007-05-01 22:32:54 +0200246 return ACCESS_32;
247 /* Write 16 bit output */
Joe Perches5c7fffd2010-01-04 11:53:00 +0000248 word_memcpy_tocard(membase, &outdata, 4);
Finn Thain2964db02007-05-01 22:32:54 +0200249 /* Now read it back */
Joe Perches5c7fffd2010-01-04 11:53:00 +0000250 word_memcpy_fromcard(&indata, membase, 4);
Finn Thain2964db02007-05-01 22:32:54 +0200251 if (outdata == indata)
252 return ACCESS_16;
253 return ACCESS_UNKNOWN;
254}
255
Adrian Bunk909fa882008-06-10 01:23:39 +0300256static int __init mac8390_memsize(unsigned long membase)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257{
258 unsigned long flags;
259 int i, j;
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400260
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261 local_irq_save(flags);
262 /* Check up to 32K in 4K increments */
263 for (i = 0; i < 8; i++) {
Joe Perches8e4d9692010-01-04 11:53:02 +0000264 volatile unsigned short *m = (unsigned short *)(membase + (i * 0x1000));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265
266 /* Unwriteable - we have a fully decoded card and the
267 RAM end located */
268 if (hwreg_present(m) == 0)
269 break;
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400270
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271 /* write a distinctive byte */
272 *m = 0xA5A0 | i;
273 /* check that we read back what we wrote */
274 if (*m != (0xA5A0 | i))
275 break;
276
277 /* check for partial decode and wrap */
278 for (j = 0; j < i; j++) {
Joe Perches8e4d9692010-01-04 11:53:02 +0000279 volatile unsigned short *p = (unsigned short *)(membase + (j * 0x1000));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280 if (*p != (0xA5A0 | j))
281 break;
Joe Perches8e4d9692010-01-04 11:53:02 +0000282 }
283 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284 local_irq_restore(flags);
Joe Perches8e4d9692010-01-04 11:53:02 +0000285 /*
286 * in any case, we stopped once we tried one block too many,
287 * or once we reached 32K
288 */
289 return i * 0x1000;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290}
291
Joe Perchesf6de7ac2010-01-04 11:53:03 +0000292static bool __init mac8390_init(struct net_device *dev, struct nubus_dev *ndev,
293 enum mac8390_type cardtype)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295 struct nubus_dir dir;
296 struct nubus_dirent ent;
297 int offset;
Joe Perchesf6de7ac2010-01-04 11:53:03 +0000298 volatile unsigned short *i;
299
Geert Uytterhoeven51f53002010-01-09 23:00:32 -0800300 printk_once(KERN_INFO pr_fmt("%s"), version);
Joe Perchesf6de7ac2010-01-04 11:53:03 +0000301
302 dev->irq = SLOT2IRQ(ndev->board->slot);
303 /* This is getting to be a habit */
304 dev->base_addr = (ndev->board->slot_addr |
305 ((ndev->board->slot & 0xf) << 20));
306
307 /*
308 * Get some Nubus info - we will trust the card's idea
309 * of where its memory and registers are.
310 */
311
312 if (nubus_get_func_dir(ndev, &dir) == -1) {
313 pr_err("%s: Unable to get Nubus functional directory for slot %X!\n",
314 dev->name, ndev->board->slot);
315 return false;
316 }
317
318 /* Get the MAC address */
319 if (nubus_find_rsrc(&dir, NUBUS_RESID_MAC_ADDRESS, &ent) == -1) {
320 pr_info("%s: Couldn't get MAC address!\n", dev->name);
321 return false;
322 }
323
324 nubus_get_rsrc_mem(dev->dev_addr, &ent, 6);
325
326 if (useresources[cardtype] == 1) {
327 nubus_rewinddir(&dir);
328 if (nubus_find_rsrc(&dir, NUBUS_RESID_MINOR_BASEOS,
329 &ent) == -1) {
330 pr_err("%s: Memory offset resource for slot %X not found!\n",
331 dev->name, ndev->board->slot);
332 return false;
333 }
334 nubus_get_rsrc_mem(&offset, &ent, 4);
335 dev->mem_start = dev->base_addr + offset;
336 /* yes, this is how the Apple driver does it */
337 dev->base_addr = dev->mem_start + 0x10000;
338 nubus_rewinddir(&dir);
339 if (nubus_find_rsrc(&dir, NUBUS_RESID_MINOR_LENGTH,
340 &ent) == -1) {
341 pr_info("%s: Memory length resource for slot %X not found, probing\n",
342 dev->name, ndev->board->slot);
343 offset = mac8390_memsize(dev->mem_start);
344 } else {
345 nubus_get_rsrc_mem(&offset, &ent, 4);
346 }
347 dev->mem_end = dev->mem_start + offset;
348 } else {
349 switch (cardtype) {
350 case MAC8390_KINETICS:
351 case MAC8390_DAYNA: /* it's the same */
352 dev->base_addr = (int)(ndev->board->slot_addr +
353 DAYNA_8390_BASE);
354 dev->mem_start = (int)(ndev->board->slot_addr +
355 DAYNA_8390_MEM);
356 dev->mem_end = dev->mem_start +
357 mac8390_memsize(dev->mem_start);
358 break;
359 case MAC8390_INTERLAN:
360 dev->base_addr = (int)(ndev->board->slot_addr +
361 INTERLAN_8390_BASE);
362 dev->mem_start = (int)(ndev->board->slot_addr +
363 INTERLAN_8390_MEM);
364 dev->mem_end = dev->mem_start +
365 mac8390_memsize(dev->mem_start);
366 break;
367 case MAC8390_CABLETRON:
368 dev->base_addr = (int)(ndev->board->slot_addr +
369 CABLETRON_8390_BASE);
370 dev->mem_start = (int)(ndev->board->slot_addr +
371 CABLETRON_8390_MEM);
372 /* The base address is unreadable if 0x00
373 * has been written to the command register
374 * Reset the chip by writing E8390_NODMA +
375 * E8390_PAGE0 + E8390_STOP just to be
376 * sure
377 */
378 i = (void *)dev->base_addr;
379 *i = 0x21;
380 dev->mem_end = dev->mem_start +
381 mac8390_memsize(dev->mem_start);
382 break;
383
384 default:
385 pr_err("Card type %s is unsupported, sorry\n",
386 ndev->board->name);
387 return false;
388 }
389 }
390
391 return true;
392}
393
394struct net_device * __init mac8390_probe(int unit)
395{
396 struct net_device *dev;
397 struct nubus_dev *ndev = NULL;
398 int err = -ENODEV;
Matthew Whiteheadc45f8122013-12-11 17:00:59 -0500399 struct ei_device *ei_local;
Joe Perchesf6de7ac2010-01-04 11:53:03 +0000400
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401 static unsigned int slots;
402
403 enum mac8390_type cardtype;
404
405 /* probably should check for Nubus instead */
406
407 if (!MACH_IS_MAC)
408 return ERR_PTR(-ENODEV);
409
Finn Thain217cbfa2009-05-25 22:43:49 -0700410 dev = ____alloc_ei_netdev(0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411 if (!dev)
412 return ERR_PTR(-ENOMEM);
413
414 if (unit >= 0)
415 sprintf(dev->name, "eth%d", unit);
416
Joe Perches8e4d9692010-01-04 11:53:02 +0000417 while ((ndev = nubus_find_type(NUBUS_CAT_NETWORK, NUBUS_TYPE_ETHERNET,
418 ndev))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419 /* Have we seen it already? */
Joe Perchesf6de7ac2010-01-04 11:53:03 +0000420 if (slots & (1 << ndev->board->slot))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421 continue;
Joe Perchesf6de7ac2010-01-04 11:53:03 +0000422 slots |= 1 << ndev->board->slot;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423
Joe Perches8e4d9692010-01-04 11:53:02 +0000424 cardtype = mac8390_ident(ndev);
425 if (cardtype == MAC8390_NONE)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426 continue;
427
Joe Perchesf6de7ac2010-01-04 11:53:03 +0000428 if (!mac8390_init(dev, ndev, cardtype))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430
431 /* Do the nasty 8390 stuff */
432 if (!mac8390_initdev(dev, ndev, cardtype))
433 break;
434 }
435
436 if (!ndev)
437 goto out;
Matthew Whiteheadc45f8122013-12-11 17:00:59 -0500438
439 ei_local = netdev_priv(dev);
440 ei_local->msg_enable = mac8390_msg_enable;
441
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442 err = register_netdev(dev);
443 if (err)
444 goto out;
445 return dev;
446
447out:
448 free_netdev(dev);
449 return ERR_PTR(err);
450}
451
452#ifdef MODULE
453MODULE_AUTHOR("David Huggins-Daines <dhd@debian.org> and others");
454MODULE_DESCRIPTION("Macintosh NS8390-based Nubus Ethernet driver");
455MODULE_LICENSE("GPL");
456
Geert Uytterhoeven3a3a7f3b72015-09-29 10:24:02 +0200457static struct net_device *dev_mac8390;
458
459int __init init_module(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460{
Geert Uytterhoeven3a3a7f3b72015-09-29 10:24:02 +0200461 dev_mac8390 = mac8390_probe(-1);
462 if (IS_ERR(dev_mac8390)) {
463 pr_warn("mac8390: No card found\n");
464 return PTR_ERR(dev_mac8390);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465 }
466 return 0;
467}
468
Geert Uytterhoeven3a3a7f3b72015-09-29 10:24:02 +0200469void __exit cleanup_module(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470{
Geert Uytterhoeven3a3a7f3b72015-09-29 10:24:02 +0200471 unregister_netdev(dev_mac8390);
472 free_netdev(dev_mac8390);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473}
474
475#endif /* MODULE */
476
Stephen Hemmingerca175842008-12-02 15:00:28 -0800477static const struct net_device_ops mac8390_netdev_ops = {
478 .ndo_open = mac8390_open,
479 .ndo_stop = mac8390_close,
Finn Thain217cbfa2009-05-25 22:43:49 -0700480 .ndo_start_xmit = __ei_start_xmit,
481 .ndo_tx_timeout = __ei_tx_timeout,
482 .ndo_get_stats = __ei_get_stats,
Jiri Pirkoafc4b132011-08-16 06:29:01 +0000483 .ndo_set_rx_mode = __ei_set_multicast_list,
Stephen Hemmingerca175842008-12-02 15:00:28 -0800484 .ndo_validate_addr = eth_validate_addr,
Stephen Hemmingerfe96aaa2009-01-09 11:13:14 +0000485 .ndo_set_mac_address = eth_mac_addr,
Stephen Hemmingerca175842008-12-02 15:00:28 -0800486 .ndo_change_mtu = eth_change_mtu,
487#ifdef CONFIG_NET_POLL_CONTROLLER
Finn Thain4e0168f2009-05-28 02:05:53 +0000488 .ndo_poll_controller = __ei_poll,
Stephen Hemmingerca175842008-12-02 15:00:28 -0800489#endif
490};
491
Joe Perches8e4d9692010-01-04 11:53:02 +0000492static int __init mac8390_initdev(struct net_device *dev,
493 struct nubus_dev *ndev,
494 enum mac8390_type type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495{
Joe Perches8e4d9692010-01-04 11:53:02 +0000496 static u32 fwrd4_offsets[16] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497 0, 4, 8, 12,
498 16, 20, 24, 28,
499 32, 36, 40, 44,
500 48, 52, 56, 60
501 };
Joe Perches8e4d9692010-01-04 11:53:02 +0000502 static u32 back4_offsets[16] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503 60, 56, 52, 48,
504 44, 40, 36, 32,
505 28, 24, 20, 16,
506 12, 8, 4, 0
507 };
Joe Perches8e4d9692010-01-04 11:53:02 +0000508 static u32 fwrd2_offsets[16] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509 0, 2, 4, 6,
510 8, 10, 12, 14,
511 16, 18, 20, 22,
512 24, 26, 28, 30
513 };
514
Finn Thain2964db02007-05-01 22:32:54 +0200515 int access_bitmode = 0;
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400516
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517 /* Now fill in our stuff */
Stephen Hemmingerca175842008-12-02 15:00:28 -0800518 dev->netdev_ops = &mac8390_netdev_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519
520 /* GAR, ei_status is actually a macro even though it looks global */
521 ei_status.name = cardname[type];
522 ei_status.word16 = word16[type];
523
524 /* Cabletron's TX/RX buffers are backwards */
525 if (type == MAC8390_CABLETRON) {
Joe Perches8e4d9692010-01-04 11:53:02 +0000526 ei_status.tx_start_page = CABLETRON_TX_START_PG;
527 ei_status.rx_start_page = CABLETRON_RX_START_PG;
528 ei_status.stop_page = CABLETRON_RX_STOP_PG;
529 ei_status.rmem_start = dev->mem_start;
530 ei_status.rmem_end = dev->mem_start + CABLETRON_RX_STOP_PG*256;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531 } else {
Joe Perches8e4d9692010-01-04 11:53:02 +0000532 ei_status.tx_start_page = WD_START_PG;
533 ei_status.rx_start_page = WD_START_PG + TX_PAGES;
534 ei_status.stop_page = (dev->mem_end - dev->mem_start)/256;
535 ei_status.rmem_start = dev->mem_start + TX_PAGES*256;
536 ei_status.rmem_end = dev->mem_end;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537 }
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400538
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539 /* Fill in model-specific information and functions */
Joe Perches35076402010-01-04 11:52:59 +0000540 switch (type) {
Finn Thain2964db02007-05-01 22:32:54 +0200541 case MAC8390_FARALLON:
542 case MAC8390_APPLE:
Joe Perches35076402010-01-04 11:52:59 +0000543 switch (mac8390_testio(dev->mem_start)) {
544 case ACCESS_UNKNOWN:
Finn Thaind92222e2010-06-02 07:06:34 -0700545 pr_err("Don't know how to access card memory!\n");
Joe Perches35076402010-01-04 11:52:59 +0000546 return -ENODEV;
Finn Thain2964db02007-05-01 22:32:54 +0200547
Joe Perches35076402010-01-04 11:52:59 +0000548 case ACCESS_16:
549 /* 16 bit card, register map is reversed */
Joe Perchesc061b182010-08-23 18:20:03 +0000550 ei_status.reset_8390 = mac8390_no_reset;
551 ei_status.block_input = slow_sane_block_input;
552 ei_status.block_output = slow_sane_block_output;
553 ei_status.get_8390_hdr = slow_sane_get_8390_hdr;
Joe Perches35076402010-01-04 11:52:59 +0000554 ei_status.reg_offset = back4_offsets;
555 break;
Finn Thain2964db02007-05-01 22:32:54 +0200556
Joe Perches35076402010-01-04 11:52:59 +0000557 case ACCESS_32:
558 /* 32 bit card, register map is reversed */
Joe Perchesc061b182010-08-23 18:20:03 +0000559 ei_status.reset_8390 = mac8390_no_reset;
560 ei_status.block_input = sane_block_input;
561 ei_status.block_output = sane_block_output;
562 ei_status.get_8390_hdr = sane_get_8390_hdr;
Joe Perches35076402010-01-04 11:52:59 +0000563 ei_status.reg_offset = back4_offsets;
564 access_bitmode = 1;
565 break;
Finn Thain2964db02007-05-01 22:32:54 +0200566 }
567 break;
568
569 case MAC8390_ASANTE:
570 /* Some Asante cards pass the 32 bit test
571 * but overwrite system memory when run at 32 bit.
572 * so we run them all at 16 bit.
573 */
Joe Perchesc061b182010-08-23 18:20:03 +0000574 ei_status.reset_8390 = mac8390_no_reset;
575 ei_status.block_input = slow_sane_block_input;
576 ei_status.block_output = slow_sane_block_output;
577 ei_status.get_8390_hdr = slow_sane_get_8390_hdr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578 ei_status.reg_offset = back4_offsets;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579 break;
Finn Thain2964db02007-05-01 22:32:54 +0200580
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581 case MAC8390_CABLETRON:
582 /* 16 bit card, register map is short forward */
Joe Perchesc061b182010-08-23 18:20:03 +0000583 ei_status.reset_8390 = mac8390_no_reset;
584 ei_status.block_input = slow_sane_block_input;
585 ei_status.block_output = slow_sane_block_output;
586 ei_status.get_8390_hdr = slow_sane_get_8390_hdr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587 ei_status.reg_offset = fwrd2_offsets;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588 break;
Finn Thain2964db02007-05-01 22:32:54 +0200589
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590 case MAC8390_DAYNA:
591 case MAC8390_KINETICS:
Finn Thain2964db02007-05-01 22:32:54 +0200592 /* 16 bit memory, register map is forward */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593 /* dayna and similar */
Joe Perchesc061b182010-08-23 18:20:03 +0000594 ei_status.reset_8390 = mac8390_no_reset;
595 ei_status.block_input = dayna_block_input;
596 ei_status.block_output = dayna_block_output;
597 ei_status.get_8390_hdr = dayna_get_8390_hdr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598 ei_status.reg_offset = fwrd4_offsets;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599 break;
Finn Thain2964db02007-05-01 22:32:54 +0200600
601 case MAC8390_INTERLAN:
602 /* 16 bit memory, register map is forward */
Joe Perchesc061b182010-08-23 18:20:03 +0000603 ei_status.reset_8390 = interlan_reset;
604 ei_status.block_input = slow_sane_block_input;
605 ei_status.block_output = slow_sane_block_output;
606 ei_status.get_8390_hdr = slow_sane_get_8390_hdr;
Joe Perches8e4d9692010-01-04 11:53:02 +0000607 ei_status.reg_offset = fwrd4_offsets;
608 break;
Finn Thain2964db02007-05-01 22:32:54 +0200609
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610 default:
Joe Perches18c00192010-01-04 11:53:01 +0000611 pr_err("Card type %s is unsupported, sorry\n",
612 ndev->board->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613 return -ENODEV;
614 }
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400615
Al Viro8c6270f2006-10-10 00:19:36 +0100616 __NS8390_init(dev, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617
618 /* Good, done, now spit out some messages */
Joe Perches18c00192010-01-04 11:53:01 +0000619 pr_info("%s: %s in slot %X (type %s)\n",
620 dev->name, ndev->board->name, ndev->board->slot,
621 cardname[type]);
622 pr_info("MAC %pM IRQ %d, %d KB shared memory at %#lx, %d-bit access.\n",
623 dev->dev_addr, dev->irq,
624 (unsigned int)(dev->mem_end - dev->mem_start) >> 10,
625 dev->mem_start, access_bitmode ? 32 : 16);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626 return 0;
627}
628
629static int mac8390_open(struct net_device *dev)
630{
Finn Thain38454db2010-06-01 02:18:32 +0000631 int err;
632
Al Viro8c6270f2006-10-10 00:19:36 +0100633 __ei_open(dev);
Finn Thain38454db2010-06-01 02:18:32 +0000634 err = request_irq(dev->irq, __ei_interrupt, 0, "8390 Ethernet", dev);
635 if (err)
Finn Thaind92222e2010-06-02 07:06:34 -0700636 pr_err("%s: unable to get IRQ %d\n", dev->name, dev->irq);
Finn Thain38454db2010-06-01 02:18:32 +0000637 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700638}
639
640static int mac8390_close(struct net_device *dev)
641{
642 free_irq(dev->irq, dev);
Al Viro8c6270f2006-10-10 00:19:36 +0100643 __ei_close(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644 return 0;
645}
646
647static void mac8390_no_reset(struct net_device *dev)
648{
Matthew Whiteheadc45f8122013-12-11 17:00:59 -0500649 struct ei_device *ei_local = netdev_priv(dev);
650
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651 ei_status.txing = 0;
Matthew Whiteheadc45f8122013-12-11 17:00:59 -0500652 netif_info(ei_local, hw, dev, "reset not supported\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653}
654
Finn Thain2964db02007-05-01 22:32:54 +0200655static void interlan_reset(struct net_device *dev)
656{
Joe Perches8e4d9692010-01-04 11:53:02 +0000657 unsigned char *target = nubus_slot_addr(IRQ2SLOT(dev->irq));
Matthew Whiteheadc45f8122013-12-11 17:00:59 -0500658 struct ei_device *ei_local = netdev_priv(dev);
659
660 netif_info(ei_local, hw, dev, "Need to reset the NS8390 t=%lu...",
661 jiffies);
Finn Thain2964db02007-05-01 22:32:54 +0200662 ei_status.txing = 0;
663 target[0xC0000] = 0;
Matthew Whiteheadc45f8122013-12-11 17:00:59 -0500664 if (netif_msg_hw(ei_local))
Joe Perches18c00192010-01-04 11:53:01 +0000665 pr_cont("reset complete\n");
Finn Thain2964db02007-05-01 22:32:54 +0200666}
667
Linus Torvalds1da177e2005-04-16 15:20:36 -0700668/* dayna_memcpy_fromio/dayna_memcpy_toio */
669/* directly from daynaport.c by Alan Cox */
Joe Perches8e4d9692010-01-04 11:53:02 +0000670static void dayna_memcpy_fromcard(struct net_device *dev, void *to, int from,
671 int count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700672{
Al Viro09cc07a2006-01-12 01:06:21 -0800673 volatile unsigned char *ptr;
Joe Perches8e4d9692010-01-04 11:53:02 +0000674 unsigned char *target = to;
675 from <<= 1; /* word, skip overhead */
676 ptr = (unsigned char *)(dev->mem_start+from);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677 /* Leading byte? */
Joe Perches8e4d9692010-01-04 11:53:02 +0000678 if (from & 2) {
Al Viro09cc07a2006-01-12 01:06:21 -0800679 *target++ = ptr[-1];
680 ptr += 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681 count--;
682 }
Joe Perches8e4d9692010-01-04 11:53:02 +0000683 while (count >= 2) {
Al Viro09cc07a2006-01-12 01:06:21 -0800684 *(unsigned short *)target = *(unsigned short volatile *)ptr;
685 ptr += 4; /* skip cruft */
686 target += 2;
Joe Perches8e4d9692010-01-04 11:53:02 +0000687 count -= 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688 }
689 /* Trailing byte? */
Joe Perches8e4d9692010-01-04 11:53:02 +0000690 if (count)
Al Viro09cc07a2006-01-12 01:06:21 -0800691 *target = *ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692}
693
Joe Perches8e4d9692010-01-04 11:53:02 +0000694static void dayna_memcpy_tocard(struct net_device *dev, int to,
695 const void *from, int count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696{
697 volatile unsigned short *ptr;
Joe Perches8e4d9692010-01-04 11:53:02 +0000698 const unsigned char *src = from;
699 to <<= 1; /* word, skip overhead */
700 ptr = (unsigned short *)(dev->mem_start+to);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700701 /* Leading byte? */
Joe Perches8e4d9692010-01-04 11:53:02 +0000702 if (to & 2) { /* avoid a byte write (stomps on other data) */
Al Viro09cc07a2006-01-12 01:06:21 -0800703 ptr[-1] = (ptr[-1]&0xFF00)|*src++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700704 ptr++;
705 count--;
706 }
Joe Perches8e4d9692010-01-04 11:53:02 +0000707 while (count >= 2) {
708 *ptr++ = *(unsigned short *)src; /* Copy and */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700709 ptr++; /* skip cruft */
Al Viro09cc07a2006-01-12 01:06:21 -0800710 src += 2;
Joe Perches8e4d9692010-01-04 11:53:02 +0000711 count -= 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700712 }
713 /* Trailing byte? */
Joe Perches8e4d9692010-01-04 11:53:02 +0000714 if (count) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700715 /* card doesn't like byte writes */
Joe Perches8e4d9692010-01-04 11:53:02 +0000716 *ptr = (*ptr & 0x00FF) | (*src << 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700717 }
718}
719
720/* sane block input/output */
721static void sane_get_8390_hdr(struct net_device *dev,
722 struct e8390_pkt_hdr *hdr, int ring_page)
723{
724 unsigned long hdr_start = (ring_page - WD_START_PG)<<8;
Geert Uytterhoeven7e364e92010-06-02 07:36:20 +0000725 memcpy_fromio(hdr, dev->mem_start + hdr_start, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700726 /* Fix endianness */
727 hdr->count = swab16(hdr->count);
728}
729
730static void sane_block_input(struct net_device *dev, int count,
731 struct sk_buff *skb, int ring_offset)
732{
733 unsigned long xfer_base = ring_offset - (WD_START_PG<<8);
734 unsigned long xfer_start = xfer_base + dev->mem_start;
735
736 if (xfer_start + count > ei_status.rmem_end) {
737 /* We must wrap the input move. */
738 int semi_count = ei_status.rmem_end - xfer_start;
Geert Uytterhoeven7e364e92010-06-02 07:36:20 +0000739 memcpy_fromio(skb->data, dev->mem_start + xfer_base,
Joe Perches8e4d9692010-01-04 11:53:02 +0000740 semi_count);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700741 count -= semi_count;
Geert Uytterhoeven7e364e92010-06-02 07:36:20 +0000742 memcpy_fromio(skb->data + semi_count, ei_status.rmem_start,
Joe Perches8e4d9692010-01-04 11:53:02 +0000743 count);
Geert Uytterhoeven7e364e92010-06-02 07:36:20 +0000744 } else {
745 memcpy_fromio(skb->data, dev->mem_start + xfer_base, count);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700746 }
747}
748
749static void sane_block_output(struct net_device *dev, int count,
750 const unsigned char *buf, int start_page)
751{
752 long shmem = (start_page - WD_START_PG)<<8;
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400753
Geert Uytterhoeven7e364e92010-06-02 07:36:20 +0000754 memcpy_toio(dev->mem_start + shmem, buf, count);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700755}
756
757/* dayna block input/output */
Joe Perches8e4d9692010-01-04 11:53:02 +0000758static void dayna_get_8390_hdr(struct net_device *dev,
759 struct e8390_pkt_hdr *hdr, int ring_page)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700760{
761 unsigned long hdr_start = (ring_page - WD_START_PG)<<8;
762
Joe Perches5c7fffd2010-01-04 11:53:00 +0000763 dayna_memcpy_fromcard(dev, hdr, hdr_start, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700764 /* Fix endianness */
Joe Perches8e4d9692010-01-04 11:53:02 +0000765 hdr->count = (hdr->count & 0xFF) << 8 | (hdr->count >> 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700766}
767
Joe Perches8e4d9692010-01-04 11:53:02 +0000768static void dayna_block_input(struct net_device *dev, int count,
769 struct sk_buff *skb, int ring_offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700770{
771 unsigned long xfer_base = ring_offset - (WD_START_PG<<8);
772 unsigned long xfer_start = xfer_base+dev->mem_start;
773
774 /* Note the offset math is done in card memory space which is word
775 per long onto our space. */
776
Joe Perches8e4d9692010-01-04 11:53:02 +0000777 if (xfer_start + count > ei_status.rmem_end) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700778 /* We must wrap the input move. */
779 int semi_count = ei_status.rmem_end - xfer_start;
780 dayna_memcpy_fromcard(dev, skb->data, xfer_base, semi_count);
781 count -= semi_count;
782 dayna_memcpy_fromcard(dev, skb->data + semi_count,
783 ei_status.rmem_start - dev->mem_start,
784 count);
Joe Perches8e4d9692010-01-04 11:53:02 +0000785 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700786 dayna_memcpy_fromcard(dev, skb->data, xfer_base, count);
787 }
788}
789
Joe Perches8e4d9692010-01-04 11:53:02 +0000790static void dayna_block_output(struct net_device *dev, int count,
791 const unsigned char *buf,
792 int start_page)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700793{
794 long shmem = (start_page - WD_START_PG)<<8;
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400795
Linus Torvalds1da177e2005-04-16 15:20:36 -0700796 dayna_memcpy_tocard(dev, shmem, buf, count);
797}
798
799/* Cabletron block I/O */
Joe Perches8e4d9692010-01-04 11:53:02 +0000800static void slow_sane_get_8390_hdr(struct net_device *dev,
801 struct e8390_pkt_hdr *hdr,
802 int ring_page)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700803{
804 unsigned long hdr_start = (ring_page - WD_START_PG)<<8;
Geert Uytterhoeven7e364e92010-06-02 07:36:20 +0000805 word_memcpy_fromcard(hdr, dev->mem_start + hdr_start, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700806 /* Register endianism - fix here rather than 8390.c */
807 hdr->count = (hdr->count&0xFF)<<8|(hdr->count>>8);
808}
809
Joe Perches8e4d9692010-01-04 11:53:02 +0000810static void slow_sane_block_input(struct net_device *dev, int count,
811 struct sk_buff *skb, int ring_offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700812{
813 unsigned long xfer_base = ring_offset - (WD_START_PG<<8);
814 unsigned long xfer_start = xfer_base+dev->mem_start;
815
Joe Perches8e4d9692010-01-04 11:53:02 +0000816 if (xfer_start + count > ei_status.rmem_end) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700817 /* We must wrap the input move. */
818 int semi_count = ei_status.rmem_end - xfer_start;
Geert Uytterhoeven7e364e92010-06-02 07:36:20 +0000819 word_memcpy_fromcard(skb->data, dev->mem_start + xfer_base,
Joe Perches5c7fffd2010-01-04 11:53:00 +0000820 semi_count);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821 count -= semi_count;
822 word_memcpy_fromcard(skb->data + semi_count,
Geert Uytterhoeven7e364e92010-06-02 07:36:20 +0000823 ei_status.rmem_start, count);
Joe Perches8e4d9692010-01-04 11:53:02 +0000824 } else {
Geert Uytterhoeven7e364e92010-06-02 07:36:20 +0000825 word_memcpy_fromcard(skb->data, dev->mem_start + xfer_base,
826 count);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700827 }
828}
829
Joe Perches8e4d9692010-01-04 11:53:02 +0000830static void slow_sane_block_output(struct net_device *dev, int count,
831 const unsigned char *buf, int start_page)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700832{
833 long shmem = (start_page - WD_START_PG)<<8;
834
Geert Uytterhoeven7e364e92010-06-02 07:36:20 +0000835 word_memcpy_tocard(dev->mem_start + shmem, buf, count);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700836}
837
Geert Uytterhoeven7e364e92010-06-02 07:36:20 +0000838static void word_memcpy_tocard(unsigned long tp, const void *fp, int count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700839{
Geert Uytterhoeven7e364e92010-06-02 07:36:20 +0000840 volatile unsigned short *to = (void *)tp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700841 const unsigned short *from = fp;
842
843 count++;
Joe Perches8e4d9692010-01-04 11:53:02 +0000844 count /= 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700845
Joe Perches8e4d9692010-01-04 11:53:02 +0000846 while (count--)
847 *to++ = *from++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700848}
849
Geert Uytterhoeven7e364e92010-06-02 07:36:20 +0000850static void word_memcpy_fromcard(void *tp, unsigned long fp, int count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700851{
852 unsigned short *to = tp;
Geert Uytterhoeven7e364e92010-06-02 07:36:20 +0000853 const volatile unsigned short *from = (const void *)fp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700854
855 count++;
Joe Perches8e4d9692010-01-04 11:53:02 +0000856 count /= 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700857
Joe Perches8e4d9692010-01-04 11:53:02 +0000858 while (count--)
859 *to++ = *from++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700860}
861
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400862