blob: 88ccc8b14f0a4b09aa8097a5f8a5dbcbacb128ba [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);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170
Adrian Bunk909fa882008-06-10 01:23:39 +0300171static enum mac8390_type __init mac8390_ident(struct nubus_dev *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172{
Finn Thain2964db02007-05-01 22:32:54 +0200173 switch (dev->dr_sw) {
Joe Perches35076402010-01-04 11:52:59 +0000174 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 Thain2964db02007-05-01 22:32:54 +0200180 break;
Joe Perches35076402010-01-04 11:52:59 +0000181 default:
182 return MAC8390_APPLE;
183 break;
184 }
185 break;
Finn Thain2964db02007-05-01 22:32:54 +0200186
Joe Perches35076402010-01-04 11:52:59 +0000187 case NUBUS_DRSW_APPLE:
188 switch (dev->dr_hw) {
189 case NUBUS_DRHW_ASANTE_LC:
190 return MAC8390_NONE;
Finn Thain2964db02007-05-01 22:32:54 +0200191 break;
Joe Perches35076402010-01-04 11:52:59 +0000192 case NUBUS_DRHW_CABLETRON:
193 return MAC8390_CABLETRON;
194 break;
195 default:
196 return MAC8390_APPLE;
197 break;
198 }
199 break;
Finn Thain2964db02007-05-01 22:32:54 +0200200
Joe Perches35076402010-01-04 11:52:59 +0000201 case NUBUS_DRSW_ASANTE:
202 return MAC8390_ASANTE;
203 break;
Finn Thain2964db02007-05-01 22:32:54 +0200204
Joe Perches35076402010-01-04 11:52:59 +0000205 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 Thain2964db02007-05-01 22:32:54 +0200213
Joe Perches35076402010-01-04 11:52:59 +0000214 case NUBUS_DRSW_FARALLON:
215 return MAC8390_FARALLON;
216 break;
Finn Thain2964db02007-05-01 22:32:54 +0200217
Joe Perches35076402010-01-04 11:52:59 +0000218 case NUBUS_DRSW_KINETICS:
219 switch (dev->dr_hw) {
220 case NUBUS_DRHW_INTERLAN:
221 return MAC8390_INTERLAN;
Finn Thain2964db02007-05-01 22:32:54 +0200222 break;
Joe Perches35076402010-01-04 11:52:59 +0000223 default:
224 return MAC8390_KINETICS;
225 break;
226 }
227 break;
Finn Thain2964db02007-05-01 22:32:54 +0200228
Joe Perches35076402010-01-04 11:52:59 +0000229 case NUBUS_DRSW_DAYNA:
Joe Perches8e4d9692010-01-04 11:53:02 +0000230 /*
231 * These correspond to Dayna Sonic cards
232 * which use the macsonic driver
233 */
Joe Perches35076402010-01-04 11:52:59 +0000234 if (dev->dr_hw == NUBUS_DRHW_SMC9194 ||
Joe Perches8e4d9692010-01-04 11:53:02 +0000235 dev->dr_hw == NUBUS_DRHW_INTERLAN)
Joe Perches35076402010-01-04 11:52:59 +0000236 return MAC8390_NONE;
237 else
238 return MAC8390_DAYNA;
239 break;
Finn Thain2964db02007-05-01 22:32:54 +0200240 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241 return MAC8390_NONE;
242}
243
Adrian Bunk909fa882008-06-10 01:23:39 +0300244static enum mac8390_access __init mac8390_testio(volatile unsigned long membase)
Finn Thain2964db02007-05-01 22:32:54 +0200245{
246 unsigned long outdata = 0xA5A0B5B0;
247 unsigned long indata = 0x00000000;
248 /* Try writing 32 bits */
Geert Uytterhoeven7e364e92010-06-02 07:36:20 +0000249 memcpy_toio(membase, &outdata, 4);
Finn Thain2964db02007-05-01 22:32:54 +0200250 /* Now compare them */
Geert Uytterhoeven7e364e92010-06-02 07:36:20 +0000251 if (memcmp_withio(&outdata, membase, 4) == 0)
Finn Thain2964db02007-05-01 22:32:54 +0200252 return ACCESS_32;
253 /* Write 16 bit output */
Joe Perches5c7fffd2010-01-04 11:53:00 +0000254 word_memcpy_tocard(membase, &outdata, 4);
Finn Thain2964db02007-05-01 22:32:54 +0200255 /* Now read it back */
Joe Perches5c7fffd2010-01-04 11:53:00 +0000256 word_memcpy_fromcard(&indata, membase, 4);
Finn Thain2964db02007-05-01 22:32:54 +0200257 if (outdata == indata)
258 return ACCESS_16;
259 return ACCESS_UNKNOWN;
260}
261
Adrian Bunk909fa882008-06-10 01:23:39 +0300262static int __init mac8390_memsize(unsigned long membase)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263{
264 unsigned long flags;
265 int i, j;
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400266
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267 local_irq_save(flags);
268 /* Check up to 32K in 4K increments */
269 for (i = 0; i < 8; i++) {
Joe Perches8e4d9692010-01-04 11:53:02 +0000270 volatile unsigned short *m = (unsigned short *)(membase + (i * 0x1000));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271
272 /* Unwriteable - we have a fully decoded card and the
273 RAM end located */
274 if (hwreg_present(m) == 0)
275 break;
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400276
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277 /* 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 Perches8e4d9692010-01-04 11:53:02 +0000285 volatile unsigned short *p = (unsigned short *)(membase + (j * 0x1000));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286 if (*p != (0xA5A0 | j))
287 break;
Joe Perches8e4d9692010-01-04 11:53:02 +0000288 }
289 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290 local_irq_restore(flags);
Joe Perches8e4d9692010-01-04 11:53:02 +0000291 /*
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 Torvalds1da177e2005-04-16 15:20:36 -0700296}
297
Joe Perchesf6de7ac2010-01-04 11:53:03 +0000298static bool __init mac8390_init(struct net_device *dev, struct nubus_dev *ndev,
299 enum mac8390_type cardtype)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301 struct nubus_dir dir;
302 struct nubus_dirent ent;
303 int offset;
Joe Perchesf6de7ac2010-01-04 11:53:03 +0000304 volatile unsigned short *i;
305
Geert Uytterhoeven51f53002010-01-09 23:00:32 -0800306 printk_once(KERN_INFO pr_fmt("%s"), version);
Joe Perchesf6de7ac2010-01-04 11:53:03 +0000307
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
400struct 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 Torvalds1da177e2005-04-16 15:20:36 -0700406 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 Thain217cbfa2009-05-25 22:43:49 -0700415 dev = ____alloc_ei_netdev(0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416 if (!dev)
417 return ERR_PTR(-ENOMEM);
418
419 if (unit >= 0)
420 sprintf(dev->name, "eth%d", unit);
421
Joe Perches8e4d9692010-01-04 11:53:02 +0000422 while ((ndev = nubus_find_type(NUBUS_CAT_NETWORK, NUBUS_TYPE_ETHERNET,
423 ndev))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424 /* Have we seen it already? */
Joe Perchesf6de7ac2010-01-04 11:53:03 +0000425 if (slots & (1 << ndev->board->slot))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426 continue;
Joe Perchesf6de7ac2010-01-04 11:53:03 +0000427 slots |= 1 << ndev->board->slot;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428
Joe Perches8e4d9692010-01-04 11:53:02 +0000429 cardtype = mac8390_ident(ndev);
430 if (cardtype == MAC8390_NONE)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431 continue;
432
Joe Perchesf6de7ac2010-01-04 11:53:03 +0000433 if (!mac8390_init(dev, ndev, cardtype))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435
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
448out:
449 free_netdev(dev);
450 return ERR_PTR(err);
451}
452
453#ifdef MODULE
454MODULE_AUTHOR("David Huggins-Daines <dhd@debian.org> and others");
455MODULE_DESCRIPTION("Macintosh NS8390-based Nubus Ethernet driver");
456MODULE_LICENSE("GPL");
457
458/* overkill, of course */
459static struct net_device *dev_mac8390[15];
460int 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 Perches18c00192010-01-04 11:53:01 +0000470 pr_notice("No useable cards found, driver NOT installed.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471 return -ENODEV;
472 }
473 return 0;
474}
475
476void 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 Hemmingerca175842008-12-02 15:00:28 -0800490static const struct net_device_ops mac8390_netdev_ops = {
491 .ndo_open = mac8390_open,
492 .ndo_stop = mac8390_close,
Finn Thain217cbfa2009-05-25 22:43:49 -0700493 .ndo_start_xmit = __ei_start_xmit,
494 .ndo_tx_timeout = __ei_tx_timeout,
495 .ndo_get_stats = __ei_get_stats,
Jiri Pirkoafc4b132011-08-16 06:29:01 +0000496 .ndo_set_rx_mode = __ei_set_multicast_list,
Stephen Hemmingerca175842008-12-02 15:00:28 -0800497 .ndo_validate_addr = eth_validate_addr,
Stephen Hemmingerfe96aaa2009-01-09 11:13:14 +0000498 .ndo_set_mac_address = eth_mac_addr,
Stephen Hemmingerca175842008-12-02 15:00:28 -0800499 .ndo_change_mtu = eth_change_mtu,
500#ifdef CONFIG_NET_POLL_CONTROLLER
Finn Thain4e0168f2009-05-28 02:05:53 +0000501 .ndo_poll_controller = __ei_poll,
Stephen Hemmingerca175842008-12-02 15:00:28 -0800502#endif
503};
504
Joe Perches8e4d9692010-01-04 11:53:02 +0000505static int __init mac8390_initdev(struct net_device *dev,
506 struct nubus_dev *ndev,
507 enum mac8390_type type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508{
Joe Perches8e4d9692010-01-04 11:53:02 +0000509 static u32 fwrd4_offsets[16] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510 0, 4, 8, 12,
511 16, 20, 24, 28,
512 32, 36, 40, 44,
513 48, 52, 56, 60
514 };
Joe Perches8e4d9692010-01-04 11:53:02 +0000515 static u32 back4_offsets[16] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516 60, 56, 52, 48,
517 44, 40, 36, 32,
518 28, 24, 20, 16,
519 12, 8, 4, 0
520 };
Joe Perches8e4d9692010-01-04 11:53:02 +0000521 static u32 fwrd2_offsets[16] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522 0, 2, 4, 6,
523 8, 10, 12, 14,
524 16, 18, 20, 22,
525 24, 26, 28, 30
526 };
527
Finn Thain2964db02007-05-01 22:32:54 +0200528 int access_bitmode = 0;
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400529
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530 /* Now fill in our stuff */
Stephen Hemmingerca175842008-12-02 15:00:28 -0800531 dev->netdev_ops = &mac8390_netdev_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532
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 Perches8e4d9692010-01-04 11:53:02 +0000539 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 Torvalds1da177e2005-04-16 15:20:36 -0700544 } else {
Joe Perches8e4d9692010-01-04 11:53:02 +0000545 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 Torvalds1da177e2005-04-16 15:20:36 -0700550 }
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400551
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552 /* Fill in model-specific information and functions */
Joe Perches35076402010-01-04 11:52:59 +0000553 switch (type) {
Finn Thain2964db02007-05-01 22:32:54 +0200554 case MAC8390_FARALLON:
555 case MAC8390_APPLE:
Joe Perches35076402010-01-04 11:52:59 +0000556 switch (mac8390_testio(dev->mem_start)) {
557 case ACCESS_UNKNOWN:
Finn Thaind92222e2010-06-02 07:06:34 -0700558 pr_err("Don't know how to access card memory!\n");
Joe Perches35076402010-01-04 11:52:59 +0000559 return -ENODEV;
560 break;
Finn Thain2964db02007-05-01 22:32:54 +0200561
Joe Perches35076402010-01-04 11:52:59 +0000562 case ACCESS_16:
563 /* 16 bit card, register map is reversed */
Joe Perchesc061b182010-08-23 18:20:03 +0000564 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;
Joe Perches35076402010-01-04 11:52:59 +0000568 ei_status.reg_offset = back4_offsets;
569 break;
Finn Thain2964db02007-05-01 22:32:54 +0200570
Joe Perches35076402010-01-04 11:52:59 +0000571 case ACCESS_32:
572 /* 32 bit card, register map is reversed */
Joe Perchesc061b182010-08-23 18:20:03 +0000573 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;
Joe Perches35076402010-01-04 11:52:59 +0000577 ei_status.reg_offset = back4_offsets;
578 access_bitmode = 1;
579 break;
Finn Thain2964db02007-05-01 22:32:54 +0200580 }
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 */
Joe Perchesc061b182010-08-23 18:20:03 +0000588 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;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592 ei_status.reg_offset = back4_offsets;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593 break;
Finn Thain2964db02007-05-01 22:32:54 +0200594
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595 case MAC8390_CABLETRON:
596 /* 16 bit card, register map is short forward */
Joe Perchesc061b182010-08-23 18:20:03 +0000597 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;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601 ei_status.reg_offset = fwrd2_offsets;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602 break;
Finn Thain2964db02007-05-01 22:32:54 +0200603
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604 case MAC8390_DAYNA:
605 case MAC8390_KINETICS:
Finn Thain2964db02007-05-01 22:32:54 +0200606 /* 16 bit memory, register map is forward */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607 /* dayna and similar */
Joe Perchesc061b182010-08-23 18:20:03 +0000608 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;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700612 ei_status.reg_offset = fwrd4_offsets;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613 break;
Finn Thain2964db02007-05-01 22:32:54 +0200614
615 case MAC8390_INTERLAN:
616 /* 16 bit memory, register map is forward */
Joe Perchesc061b182010-08-23 18:20:03 +0000617 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 Perches8e4d9692010-01-04 11:53:02 +0000621 ei_status.reg_offset = fwrd4_offsets;
622 break;
Finn Thain2964db02007-05-01 22:32:54 +0200623
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624 default:
Joe Perches18c00192010-01-04 11:53:01 +0000625 pr_err("Card type %s is unsupported, sorry\n",
626 ndev->board->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627 return -ENODEV;
628 }
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400629
Al Viro8c6270f2006-10-10 00:19:36 +0100630 __NS8390_init(dev, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631
632 /* Good, done, now spit out some messages */
Joe Perches18c00192010-01-04 11:53:01 +0000633 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 Torvalds1da177e2005-04-16 15:20:36 -0700640 return 0;
641}
642
643static int mac8390_open(struct net_device *dev)
644{
Finn Thain38454db2010-06-01 02:18:32 +0000645 int err;
646
Al Viro8c6270f2006-10-10 00:19:36 +0100647 __ei_open(dev);
Finn Thain38454db2010-06-01 02:18:32 +0000648 err = request_irq(dev->irq, __ei_interrupt, 0, "8390 Ethernet", dev);
649 if (err)
Finn Thaind92222e2010-06-02 07:06:34 -0700650 pr_err("%s: unable to get IRQ %d\n", dev->name, dev->irq);
Finn Thain38454db2010-06-01 02:18:32 +0000651 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652}
653
654static int mac8390_close(struct net_device *dev)
655{
656 free_irq(dev->irq, dev);
Al Viro8c6270f2006-10-10 00:19:36 +0100657 __ei_close(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658 return 0;
659}
660
661static void mac8390_no_reset(struct net_device *dev)
662{
663 ei_status.txing = 0;
664 if (ei_debug > 1)
Joe Perches18c00192010-01-04 11:53:01 +0000665 pr_info("reset not supported\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666}
667
Finn Thain2964db02007-05-01 22:32:54 +0200668static void interlan_reset(struct net_device *dev)
669{
Joe Perches8e4d9692010-01-04 11:53:02 +0000670 unsigned char *target = nubus_slot_addr(IRQ2SLOT(dev->irq));
Finn Thain2964db02007-05-01 22:32:54 +0200671 if (ei_debug > 1)
Joe Perches18c00192010-01-04 11:53:01 +0000672 pr_info("Need to reset the NS8390 t=%lu...", jiffies);
Finn Thain2964db02007-05-01 22:32:54 +0200673 ei_status.txing = 0;
674 target[0xC0000] = 0;
675 if (ei_debug > 1)
Joe Perches18c00192010-01-04 11:53:01 +0000676 pr_cont("reset complete\n");
Finn Thain2964db02007-05-01 22:32:54 +0200677}
678
Linus Torvalds1da177e2005-04-16 15:20:36 -0700679/* dayna_memcpy_fromio/dayna_memcpy_toio */
680/* directly from daynaport.c by Alan Cox */
Joe Perches8e4d9692010-01-04 11:53:02 +0000681static void dayna_memcpy_fromcard(struct net_device *dev, void *to, int from,
682 int count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683{
Al Viro09cc07a2006-01-12 01:06:21 -0800684 volatile unsigned char *ptr;
Joe Perches8e4d9692010-01-04 11:53:02 +0000685 unsigned char *target = to;
686 from <<= 1; /* word, skip overhead */
687 ptr = (unsigned char *)(dev->mem_start+from);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688 /* Leading byte? */
Joe Perches8e4d9692010-01-04 11:53:02 +0000689 if (from & 2) {
Al Viro09cc07a2006-01-12 01:06:21 -0800690 *target++ = ptr[-1];
691 ptr += 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692 count--;
693 }
Joe Perches8e4d9692010-01-04 11:53:02 +0000694 while (count >= 2) {
Al Viro09cc07a2006-01-12 01:06:21 -0800695 *(unsigned short *)target = *(unsigned short volatile *)ptr;
696 ptr += 4; /* skip cruft */
697 target += 2;
Joe Perches8e4d9692010-01-04 11:53:02 +0000698 count -= 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699 }
700 /* Trailing byte? */
Joe Perches8e4d9692010-01-04 11:53:02 +0000701 if (count)
Al Viro09cc07a2006-01-12 01:06:21 -0800702 *target = *ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703}
704
Joe Perches8e4d9692010-01-04 11:53:02 +0000705static void dayna_memcpy_tocard(struct net_device *dev, int to,
706 const void *from, int count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700707{
708 volatile unsigned short *ptr;
Joe Perches8e4d9692010-01-04 11:53:02 +0000709 const unsigned char *src = from;
710 to <<= 1; /* word, skip overhead */
711 ptr = (unsigned short *)(dev->mem_start+to);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700712 /* Leading byte? */
Joe Perches8e4d9692010-01-04 11:53:02 +0000713 if (to & 2) { /* avoid a byte write (stomps on other data) */
Al Viro09cc07a2006-01-12 01:06:21 -0800714 ptr[-1] = (ptr[-1]&0xFF00)|*src++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700715 ptr++;
716 count--;
717 }
Joe Perches8e4d9692010-01-04 11:53:02 +0000718 while (count >= 2) {
719 *ptr++ = *(unsigned short *)src; /* Copy and */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700720 ptr++; /* skip cruft */
Al Viro09cc07a2006-01-12 01:06:21 -0800721 src += 2;
Joe Perches8e4d9692010-01-04 11:53:02 +0000722 count -= 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700723 }
724 /* Trailing byte? */
Joe Perches8e4d9692010-01-04 11:53:02 +0000725 if (count) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700726 /* card doesn't like byte writes */
Joe Perches8e4d9692010-01-04 11:53:02 +0000727 *ptr = (*ptr & 0x00FF) | (*src << 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700728 }
729}
730
731/* sane block input/output */
732static void sane_get_8390_hdr(struct net_device *dev,
733 struct e8390_pkt_hdr *hdr, int ring_page)
734{
735 unsigned long hdr_start = (ring_page - WD_START_PG)<<8;
Geert Uytterhoeven7e364e92010-06-02 07:36:20 +0000736 memcpy_fromio(hdr, dev->mem_start + hdr_start, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700737 /* Fix endianness */
738 hdr->count = swab16(hdr->count);
739}
740
741static void sane_block_input(struct net_device *dev, int count,
742 struct sk_buff *skb, int ring_offset)
743{
744 unsigned long xfer_base = ring_offset - (WD_START_PG<<8);
745 unsigned long xfer_start = xfer_base + dev->mem_start;
746
747 if (xfer_start + count > ei_status.rmem_end) {
748 /* We must wrap the input move. */
749 int semi_count = ei_status.rmem_end - xfer_start;
Geert Uytterhoeven7e364e92010-06-02 07:36:20 +0000750 memcpy_fromio(skb->data, dev->mem_start + xfer_base,
Joe Perches8e4d9692010-01-04 11:53:02 +0000751 semi_count);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700752 count -= semi_count;
Geert Uytterhoeven7e364e92010-06-02 07:36:20 +0000753 memcpy_fromio(skb->data + semi_count, ei_status.rmem_start,
Joe Perches8e4d9692010-01-04 11:53:02 +0000754 count);
Geert Uytterhoeven7e364e92010-06-02 07:36:20 +0000755 } else {
756 memcpy_fromio(skb->data, dev->mem_start + xfer_base, count);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700757 }
758}
759
760static void sane_block_output(struct net_device *dev, int count,
761 const unsigned char *buf, int start_page)
762{
763 long shmem = (start_page - WD_START_PG)<<8;
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400764
Geert Uytterhoeven7e364e92010-06-02 07:36:20 +0000765 memcpy_toio(dev->mem_start + shmem, buf, count);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700766}
767
768/* dayna block input/output */
Joe Perches8e4d9692010-01-04 11:53:02 +0000769static void dayna_get_8390_hdr(struct net_device *dev,
770 struct e8390_pkt_hdr *hdr, int ring_page)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700771{
772 unsigned long hdr_start = (ring_page - WD_START_PG)<<8;
773
Joe Perches5c7fffd2010-01-04 11:53:00 +0000774 dayna_memcpy_fromcard(dev, hdr, hdr_start, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700775 /* Fix endianness */
Joe Perches8e4d9692010-01-04 11:53:02 +0000776 hdr->count = (hdr->count & 0xFF) << 8 | (hdr->count >> 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700777}
778
Joe Perches8e4d9692010-01-04 11:53:02 +0000779static void dayna_block_input(struct net_device *dev, int count,
780 struct sk_buff *skb, int ring_offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700781{
782 unsigned long xfer_base = ring_offset - (WD_START_PG<<8);
783 unsigned long xfer_start = xfer_base+dev->mem_start;
784
785 /* Note the offset math is done in card memory space which is word
786 per long onto our space. */
787
Joe Perches8e4d9692010-01-04 11:53:02 +0000788 if (xfer_start + count > ei_status.rmem_end) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700789 /* We must wrap the input move. */
790 int semi_count = ei_status.rmem_end - xfer_start;
791 dayna_memcpy_fromcard(dev, skb->data, xfer_base, semi_count);
792 count -= semi_count;
793 dayna_memcpy_fromcard(dev, skb->data + semi_count,
794 ei_status.rmem_start - dev->mem_start,
795 count);
Joe Perches8e4d9692010-01-04 11:53:02 +0000796 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700797 dayna_memcpy_fromcard(dev, skb->data, xfer_base, count);
798 }
799}
800
Joe Perches8e4d9692010-01-04 11:53:02 +0000801static void dayna_block_output(struct net_device *dev, int count,
802 const unsigned char *buf,
803 int start_page)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700804{
805 long shmem = (start_page - WD_START_PG)<<8;
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400806
Linus Torvalds1da177e2005-04-16 15:20:36 -0700807 dayna_memcpy_tocard(dev, shmem, buf, count);
808}
809
810/* Cabletron block I/O */
Joe Perches8e4d9692010-01-04 11:53:02 +0000811static void slow_sane_get_8390_hdr(struct net_device *dev,
812 struct e8390_pkt_hdr *hdr,
813 int ring_page)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700814{
815 unsigned long hdr_start = (ring_page - WD_START_PG)<<8;
Geert Uytterhoeven7e364e92010-06-02 07:36:20 +0000816 word_memcpy_fromcard(hdr, dev->mem_start + hdr_start, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700817 /* Register endianism - fix here rather than 8390.c */
818 hdr->count = (hdr->count&0xFF)<<8|(hdr->count>>8);
819}
820
Joe Perches8e4d9692010-01-04 11:53:02 +0000821static void slow_sane_block_input(struct net_device *dev, int count,
822 struct sk_buff *skb, int ring_offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700823{
824 unsigned long xfer_base = ring_offset - (WD_START_PG<<8);
825 unsigned long xfer_start = xfer_base+dev->mem_start;
826
Joe Perches8e4d9692010-01-04 11:53:02 +0000827 if (xfer_start + count > ei_status.rmem_end) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700828 /* We must wrap the input move. */
829 int semi_count = ei_status.rmem_end - xfer_start;
Geert Uytterhoeven7e364e92010-06-02 07:36:20 +0000830 word_memcpy_fromcard(skb->data, dev->mem_start + xfer_base,
Joe Perches5c7fffd2010-01-04 11:53:00 +0000831 semi_count);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700832 count -= semi_count;
833 word_memcpy_fromcard(skb->data + semi_count,
Geert Uytterhoeven7e364e92010-06-02 07:36:20 +0000834 ei_status.rmem_start, count);
Joe Perches8e4d9692010-01-04 11:53:02 +0000835 } else {
Geert Uytterhoeven7e364e92010-06-02 07:36:20 +0000836 word_memcpy_fromcard(skb->data, dev->mem_start + xfer_base,
837 count);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700838 }
839}
840
Joe Perches8e4d9692010-01-04 11:53:02 +0000841static void slow_sane_block_output(struct net_device *dev, int count,
842 const unsigned char *buf, int start_page)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700843{
844 long shmem = (start_page - WD_START_PG)<<8;
845
Geert Uytterhoeven7e364e92010-06-02 07:36:20 +0000846 word_memcpy_tocard(dev->mem_start + shmem, buf, count);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700847}
848
Geert Uytterhoeven7e364e92010-06-02 07:36:20 +0000849static void word_memcpy_tocard(unsigned long tp, const void *fp, int count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700850{
Geert Uytterhoeven7e364e92010-06-02 07:36:20 +0000851 volatile unsigned short *to = (void *)tp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700852 const unsigned short *from = fp;
853
854 count++;
Joe Perches8e4d9692010-01-04 11:53:02 +0000855 count /= 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700856
Joe Perches8e4d9692010-01-04 11:53:02 +0000857 while (count--)
858 *to++ = *from++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700859}
860
Geert Uytterhoeven7e364e92010-06-02 07:36:20 +0000861static void word_memcpy_fromcard(void *tp, unsigned long fp, int count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700862{
863 unsigned short *to = tp;
Geert Uytterhoeven7e364e92010-06-02 07:36:20 +0000864 const volatile unsigned short *from = (const void *)fp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700865
866 count++;
Joe Perches8e4d9692010-01-04 11:53:02 +0000867 count /= 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700868
Joe Perches8e4d9692010-01-04 11:53:02 +0000869 while (count--)
870 *to++ = *from++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700871}
872
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400873