summaryrefslogtreecommitdiffstats
path: root/drivers/net/daynaport.c
blob: 02ebff8b6d67762258bbcb2093c5f6316f3c1414 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
/* mac_ns8390.c: A Macintosh 8390 based ethernet driver for linux. */
/*
	Derived from code:
	
	Written 1993-94 by Donald Becker.

	Copyright 1993 United States Government as represented by the
	Director, National Security Agency.

	This software may be used and distributed according to the terms
	of the GNU Public License, incorporated herein by reference.

	    TODO:

	    The block output routines may be wrong for non Dayna
	    cards

	    Reading MAC addresses
*/

static const char *version =
	"mac_ns8390.c:v0.01 7/5/97 Alan Cox (Alan.Cox@linux.org)\n";

#include <linux/module.h>

#include <linux/kernel.h>
#include <linux/sched.h>
#include <linux/errno.h>
#include <linux/string.h>
#include <linux/nubus.h>
#include <asm/io.h>
#include <asm/system.h>
#include <asm/hwtest.h>
#include <linux/delay.h>

#include <linux/netdevice.h>
#include <linux/etherdevice.h>
#include "8390.h"

int ns8390_probe1(struct net_device *dev, int word16, char *name, int id, int prom);

static int ns8390_open(struct net_device *dev);
static void ns8390_no_reset(struct net_device *dev);
static int ns8390_close_card(struct net_device *dev);

static void interlan_reset(struct net_device *dev);

static void dayna_get_8390_hdr(struct net_device *dev, struct e8390_pkt_hdr *hdr,
						int ring_page);
static void dayna_block_input(struct net_device *dev, int count,
						  struct sk_buff *skb, int ring_offset);
static void dayna_block_output(struct net_device *dev, int count,
						   const unsigned char *buf, const int start_page);

static void sane_get_8390_hdr(struct net_device *dev, struct e8390_pkt_hdr *hdr,
						int ring_page);
static void sane_block_input(struct net_device *dev, int count,
						  struct sk_buff *skb, int ring_offset);
static void sane_block_output(struct net_device *dev, int count,
						   const unsigned char *buf, const int start_page);

static void slow_sane_get_8390_hdr(struct net_device *dev, struct e8390_pkt_hdr *hdr,
						int ring_page);
static void slow_sane_block_input(struct net_device *dev, int count,
						  struct sk_buff *skb, int ring_offset);
static void slow_sane_block_output(struct net_device *dev, int count,
						   const unsigned char *buf, const int start_page);


#define WD_START_PG	0x00	/* First page of TX buffer */
#define WD03_STOP_PG	0x20	/* Last page +1 of RX ring */
#define WD13_STOP_PG	0x40	/* Last page +1 of RX ring */


#define DAYNA_MAC_BASE		0xf0007
#define DAYNA_8390_BASE		0x80000 /* 3 */
#define DAYNA_8390_MEM		0x00000
#define DAYNA_MEMSIZE		0x04000	/* First word of each long ! */

#define APPLE_8390_BASE		0xE0000
#define APPLE_8390_MEM		0xD0000
#define APPLE_MEMSIZE		8192    /* FIXME: need to dynamically check */

#define KINETICS_8390_BASE	0x80003
#define KINETICS_8390_MEM	0x00000
#define KINETICS_MEMSIZE	8192    /* FIXME: need to dynamically check */

static int test_8390(volatile char *ptr, int scale)
{
	int regd;
	int v;
	
	if(hwreg_present(&ptr[0x00])==0)
		return -EIO;
	if(hwreg_present(&ptr[0x0D<<scale])==0)
		return -EIO;
	if(hwreg_present(&ptr[0x0D<<scale])==0)
		return -EIO;
	ptr[0x00]=E8390_NODMA+E8390_PAGE1+E8390_STOP;
	regd=ptr[0x0D<<scale];
	ptr[0x0D<<scale]=0xFF;
	ptr[0x00]=E8390_NODMA+E8390_PAGE0;
	v=ptr[0x0D<<scale];
	if(ptr[0x0D<<scale]!=0)
	{
		ptr[0x0D<<scale]=regd;
		return -ENODEV;
	}
/*	printk("NS8390 found at %p scaled %d\n", ptr,scale);*/
	return 0;
}
/*
 *    Identify the species of NS8390 card/driver we need
 */

#define NS8390_DAYNA		1
#define NS8390_INTERLAN		2
#define NS8390_KINETICS		3
#define NS8390_APPLE		4
#define NS8390_FARALLON		5
#define NS8390_ASANTE		6

int ns8390_ident(struct nubus_type *nb)
{
	/* It appears anything with a software type of 0 is an apple
	   compatible - even if the hardware matches others */
	   
	if(nb->DrSW==0x0001 || nb->DrSW==0x0109 || nb->DrSW==0x0000 || nb->DrSW==0x0100)
		return NS8390_APPLE;
	
	/* Dayna ex Kinetics board */
	if(nb->DrHW==0x0103)
		return NS8390_DAYNA;

	/* Asante board */
	if(nb->DrHW==0x0104)
		return NS8390_ASANTE;
	if(nb->DrHW==0x0100)
		return NS8390_INTERLAN;
	if(nb->DrHW==0x0106)
		return NS8390_KINETICS;
	if(nb->DrSW==0x010C)
		return NS8390_FARALLON;
	return -1;
}

/*
 *	Memory probe for 8390 cards
 */
 
int apple_8390_mem_probe(volatile unsigned short *p)
{
	int i, j;
	/*
	 *	Algorithm.
	 *	1.	Check each block size of memory doesn't fault
	 *	2.	Write a value to it
	 *	3.	Check all previous blocks are unaffected
	 */
	
	for(i=0;i<2;i++)
	{
		volatile unsigned short *m=p+4096*i;
		/* Unwriteable - we have a fully decoded card and the
		   RAM end located */
		   
		if(hwreg_present(m)==0)
			return 8192*i;
			
		*m=0xA5A0|i;
		
		for(j=0;j<i;j++)
		{
			/* Partial decode and wrap ? */
			if(p[4096*j]!=(0xA5A0|j))
			{
				/* This is the first misdecode, so it had
				   one less page than we tried */
				return 8192*i;
			}
 			j++;
 		}
 		/* Ok it still decodes.. move on 8K */
 	}
 	/* 
 	 *	We don't look past 16K. That should cover most cards
 	 *	and above 16K there isnt really any gain.
 	 */
 	return 16384;
 }
 		
/*
 *    Probe for 8390 cards.  
 *    The ns8390_probe1() routine initializes the card and fills the
 *    station address field. On entry base_addr is set, irq is set
 *    (These come from the nubus probe code). dev->mem_start points
 *    at the memory ring, dev->mem_end gives the end of it.
 */

int ns8390_probe(struct nubus_device_specifier *d, int slot, struct nubus_type *match)
{
	struct net_device *dev;
	volatile unsigned short *i;
	volatile unsigned char *p;
	int plen;
	int id;

	if(match->category!=NUBUS_CAT_NETWORK || match->type!=1)
		return -ENODEV;		
	/* Ok so it is an ethernet network device */
	if((id=ns8390_ident(match))==-1)
	{
		printk("Ethernet but type unknown %d\n",match->DrHW);
		return -ENODEV;
	}
	dev = init_etherdev(0, 0);
	if(dev==NULL)
		return -ENOMEM;

	/*
	 *	Dayna specific init
	 */
	if(id==NS8390_DAYNA)
	{
		dev->base_addr=(int)(nubus_slot_addr(slot)+DAYNA_8390_BASE);
		dev->mem_start=(int)(nubus_slot_addr(slot)+DAYNA_8390_MEM);
		dev->mem_end=dev->mem_start+DAYNA_MEMSIZE; /* 8K it seems */
	
		printk("daynaport: testing board: ");

		printk("memory - ");	
	
		i=(void *)dev->mem_start;
		memset((void *)i,0xAA, DAYNA_MEMSIZE);
		while(i<(volatile unsigned short *)dev->mem_end)
		{
			if(*i!=0xAAAA)
				goto membad;
			*i=0x5555;
			if(*i!=0x5555)
				goto membad;
			i+=2;	/* Skip a word */
		}

		printk("controller - ");
	
		p=(void *)dev->base_addr;
		plen=0;
	
		while(plen<0x3FF00)
		{
			if(test_8390(p,0)==0)
				break;
			if(test_8390(p,1)==0)
				break;
			if(test_8390(p,2)==0)
				break;
			if(test_8390(p,3)==0)
				break;
			plen++;
			p++;
		}
		if(plen==0x3FF00)
			goto membad;
		printk("OK\n");
		dev->irq=slot;
		if(ns8390_probe1(dev, 0, "dayna", id, -1)==0)
		return 0;
	}
	/* Apple, Farallon, Asante */
	if(id==NS8390_APPLE|| id==NS8390_FARALLON || id==NS8390_ASANTE)
	{
		int memsize;
		
		dev->base_addr=(int)(nubus_slot_addr(slot)+APPLE_8390_BASE);
		dev->mem_start=(int)(nubus_slot_addr(slot)+APPLE_8390_MEM);
		
		memsize = apple_8390_mem_probe((void *)dev->mem_start);
		
		dev->mem_end=dev->mem_start+memsize;
		dev->irq=slot;
		printk("apple/clone: testing board: ");

		printk("%dK memory - ", memsize>>10);		

		i=(void *)dev->mem_start;
		memset((void *)i,0xAA, memsize);
		while(i<(volatile unsigned short *)dev->mem_end)
		{
			if(*i!=0xAAAA)
				goto membad;
			*i=0x5555;
			if(*i!=0x5555)
				goto membad;
			i+=2;	/* Skip a word */
		}
		printk("OK\n");

		if(id==NS8390_FARALLON)
		{
			if(ns8390_probe1(dev, 1, "farallon", id, -1)==0)
				return 0;
		}
		else
		{
			if(ns8390_probe1(dev, 1, "apple/clone", id, -1)==0)
			    return 0;
		}
	}
	/* Interlan */
	if(id==NS8390_INTERLAN)
	{
		/* As apple and asante */
		dev->base_addr=(int)(nubus_slot_addr(slot)+APPLE_8390_BASE);
		dev->mem_start=(int)(nubus_slot_addr(slot)+APPLE_8390_MEM);
		dev->mem_end=dev->mem_start+APPLE_MEMSIZE; /* 8K it seems */
		dev->irq=slot;
		if(ns8390_probe1(dev, 1, "interlan", id, -1)==0)
			return 0;
	}
	/* Kinetics */
	if(id==NS8390_KINETICS)
	{
		dev->base_addr=(int)(nubus_slot_addr(slot)+KINETICS_8390_BASE);
		dev->mem_start=(int)(nubus_slot_addr(slot)+KINETICS_8390_MEM);
		dev->mem_end=dev->mem_start+KINETICS_MEMSIZE; /* 8K it seems */
		dev->irq=slot;
		if(ns8390_probe1(dev, 0, "kinetics", id, -1)==0)
			return 0;
	}
	kfree(dev);
	return -ENODEV;
membad:
	printk("failed.\n");
	kfree(dev);
	return -ENODEV;
}

int ns8390_probe1(struct net_device *dev, int word16, char *model_name, int type, int promoff)
{
	static unsigned version_printed = 0;

	static u32 fwrd4_offsets[16]={
		0,      4,      8,      12,
		16,     20,     24,     28,
		32,     36,     40,     44,
		48,     52,     56,     60
	};
	static u32 back4_offsets[16]={
		60,     56,     52,     48,
		44,     40,     36,     32,
		28,     24,     20,     16,
		12,     8,      4,      0
	};

	unsigned char *prom=((unsigned char *)nubus_slot_addr(dev->irq))+promoff;

	if (ei_debug  &&  version_printed++ == 0)
		printk(version);
	
	/* Snarf the interrupt now.  There's no point in waiting since we cannot
	   share a slot! and the board will usually be enabled. */
	if (nubus_request_irq(dev->irq, dev, ei_interrupt)) 
	{
		printk (" unable to get nubus IRQ %d.\n", dev->irq);
		return EAGAIN;
	}
	
	/* Allocate dev->priv and fill in 8390 specific dev fields. */
	if (ethdev_init(dev)) 
	{	
		printk (" unable to get memory for dev->priv.\n");
		nubus_free_irq(dev->irq);
		return -ENOMEM;
	}

	/* OK, we are certain this is going to work.  Setup the device. */

	ei_status.name = model_name;
	ei_status.word16 = word16;
	ei_status.tx_start_page = WD_START_PG;
	ei_status.rx_start_page = WD_START_PG + TX_PAGES;

	dev->rmem_start = dev->mem_start + TX_PAGES*256;
	ei_status.stop_page = (dev->mem_end - dev->mem_start)/256;
	dev->rmem_end = dev->mem_end;
	
	if(promoff==-1)		/* Use nubus resources ? */
	{
		if(nubus_ethernet_addr(dev->irq /* slot */, dev->dev_addr))
		{
		  printk("mac_ns8390: MAC address not in resources!\n");
		  return -ENODEV;
		}
	}
	else			/* Pull it off the card */
	{
		int i=0;
		int x=1;
		/* These should go in the end I hope */
		if(type==NS8390_DAYNA)
			x=2;
		if(type==NS8390_INTERLAN)
			x=4;
		while(i<6)
		{
			dev->dev_addr[i]=*prom;
			prom+=x;
			if(i)
				printk(":");
			printk("%02X",dev->dev_addr[i++]);
		}
	}

	printk(" %s, IRQ %d, shared memory at %#lx-%#lx.\n",
		   model_name, dev->irq, dev->mem_start, dev->mem_end-1);

	switch(type)
	{
		case NS8390_DAYNA:      /* Dayna card */
			/* 16 bit, 4 word offsets */
			ei_status.reset_8390 = &ns8390_no_reset;
			ei_status.block_input = &dayna_block_input;
			ei_status.block_output = &dayna_block_output;
			ei_status.get_8390_hdr = &dayna_get_8390_hdr;
			ei_status.reg_offset = fwrd4_offsets;
			break;
		case NS8390_FARALLON:
		case NS8390_APPLE:	/* Apple/Asante/Farallon */
			/*      16 bit card, register map is reversed */
			ei_status.reset_8390 = &ns8390_no_reset;
			ei_status.block_input = &slow_sane_block_input;
			ei_status.block_output = &slow_sane_block_output;
			ei_status.get_8390_hdr = &slow_sane_get_8390_hdr;
			ei_status.reg_offset = back4_offsets;
			break;
		case NS8390_ASANTE:
			/*      16 bit card, register map is reversed */
			ei_status.reset_8390 = &ns8390_no_reset;
			ei_status.block_input = &sane_block_input;
			ei_status.block_output = &sane_block_output;
			ei_status.get_8390_hdr = &sane_get_8390_hdr;
			ei_status.reg_offset = back4_offsets;
			break;
		case NS8390_INTERLAN:   /* Interlan */
			/*      16 bit card, map is forward */
			ei_status.reset_8390 = &interlan_reset;
			ei_status.block_input = &sane_block_input;
			ei_status.block_output = &sane_block_output;
			ei_status.get_8390_hdr = &sane_get_8390_hdr;
			ei_status.reg_offset = back4_offsets;
			break;
		case NS8390_KINETICS:   /* Kinetics */
			/*      8bit card, map is forward */
			ei_status.reset_8390 = &ns8390_no_reset;
			ei_status.block_input = &sane_block_input;
			ei_status.block_output = &sane_block_output;
			ei_status.get_8390_hdr = &sane_get_8390_hdr;
			ei_status.reg_offset = back4_offsets;
			break;
		default:
			panic("Detected a card I can't drive - whoops\n");
	}
	dev->open = &ns8390_open;
	dev->stop = &ns8390_close_card;

	NS8390_init(dev, 0);

	return 0;
}

static int ns8390_open(struct net_device *dev)
{
	ei_open(dev);
	MOD_INC_USE_COUNT;
	return 0;
}

static void ns8390_no_reset(struct net_device *dev)
{
	if (ei_debug > 1) 
		printk("Need to reset the NS8390 t=%lu...", jiffies);
	ei_status.txing = 0;
	if (ei_debug > 1) printk("reset not supported\n");
	return;
}

static int ns8390_close_card(struct net_device *dev)
{
	if (ei_debug > 1)
		printk("%s: Shutting down ethercard.\n", dev->name);
	ei_close(dev);
	MOD_DEC_USE_COUNT;
	return 0;
}

struct nubus_device_specifier nubus_8390={
	ns8390_probe,
	NULL
};


/*
 *    Interlan Specific Code Starts Here
 */

static void interlan_reset(struct net_device *dev)
{
	unsigned char *target=nubus_slot_addr(dev->irq);
	if (ei_debug > 1) 
		printk("Need to reset the NS8390 t=%lu...", jiffies);
	ei_status.txing = 0;
	/* This write resets the card */
	target[0xC0000]=0;
	if (ei_debug > 1) printk("reset complete\n");
	return;
}

/*
 *    Daynaport code (some is used by other drivers)
 */


/* Grab the 8390 specific header. Similar to the block_input routine, but
   we don't need to be concerned with ring wrap as the header will be at
   the start of a page, so we optimize accordingly. */


/* Block input and output are easy on shared memory ethercards, and trivial
   on the Daynaport card where there is no choice of how to do it.
   The only complications are that the ring buffer wraps.
*/

static void dayna_cpu_memcpy(struct net_device *dev, void *to, int from, int count)
{
	volatile unsigned short *ptr;
	unsigned short *target=to;
	from<<=1;	/* word, skip overhead */
	ptr=(unsigned short *)(dev->mem_start+from);
	while(count>=2)
	{
		*target++=*ptr++;	/* Copy and */
		ptr++;			/* Cruft and */
		count-=2;
	}
	/*
	 *	Trailing byte ?
	 */
	if(count)
	{
		/* Big endian */
		unsigned short v=*ptr;
		*((char *)target)=v>>8;
	}
}

static void cpu_dayna_memcpy(struct net_device *dev, int to, const void *from, int count)
{
	volatile unsigned short *ptr;
	const unsigned short *src=from;
	to<<=1;	/* word, skip overhead */
	ptr=(unsigned short *)(dev->mem_start+to);
	while(count>=2)
	{
		*ptr++=*src++;		/* Copy and */
		ptr++;			/* Cruft and */
		count-=2;
	}
	/*
	 *	Trailing byte ?
	 */
	if(count)
	{
		/* Big endian */
		unsigned short v=*src;
		*((char *)ptr)=v>>8;
	}
}

static void dayna_get_8390_hdr(struct net_device *dev, struct e8390_pkt_hdr *hdr, int ring_page)
{
	unsigned long hdr_start = (ring_page - WD_START_PG)<<8;
	dayna_cpu_memcpy(dev, (void *)hdr, hdr_start, 4);
	/* Register endianism - fix here rather than 8390.c */
	hdr->count=(hdr->count&0xFF)<<8|(hdr->count>>8);
}

static void dayna_block_input(struct net_device *dev, int count, struct sk_buff *skb, int ring_offset)
{
	unsigned long xfer_base = ring_offset - (WD_START_PG<<8);
	unsigned long xfer_start = xfer_base+dev->mem_start;

	/*
	 *	Note the offset maths is done in card memory space which
	 *	is word per long onto our space.
	 */
	 
	if (xfer_start + count > dev->rmem_end) 
	{
		/* We must wrap the input move. */
		int semi_count = dev->rmem_end - xfer_start;
		dayna_cpu_memcpy(dev, skb->data, xfer_base, semi_count);
		count -= semi_count;
		dayna_cpu_memcpy(dev, skb->data + semi_count, 
			dev->rmem_start - dev->mem_start, count);
	}
	else
	{
		dayna_cpu_memcpy(dev, skb->data, xfer_base, count);
	}
}

static void dayna_block_output(struct net_device *dev, int count, const unsigned char *buf,
				int start_page)
{
	long shmem = (start_page - WD_START_PG)<<8;
	
	cpu_dayna_memcpy(dev, shmem, buf, count);
}

/*
 *	Cards with full width memory
 */


static void sane_get_8390_hdr(struct net_device *dev, struct e8390_pkt_hdr *hdr, int ring_page)
{
	unsigned long hdr_start = (ring_page - WD_START_PG)<<8;
	memcpy((void *)hdr, (char *)dev->mem_start+hdr_start, 4);
	/* Register endianism - fix here rather than 8390.c */
	hdr->count=(hdr->count&0xFF)<<8|(hdr->count>>8);
}

static void sane_block_input(struct net_device *dev, int count, struct sk_buff *skb, int ring_offset)
{
	unsigned long xfer_base = ring_offset - (WD_START_PG<<8);
	unsigned long xfer_start = xfer_base+dev->mem_start;

	if (xfer_start + count > dev->rmem_end) 
	{
		/* We must wrap the input move. */
		int semi_count = dev->rmem_end - xfer_start;
		memcpy(skb->data, (char *)dev->mem_start+xfer_base, semi_count);
		count -= semi_count;
		memcpy(skb->data + semi_count, 
			(char *)dev->rmem_start, count);
	}
	else
	{
		memcpy(skb->data, (char *)dev->mem_start+xfer_base, count);
	}
}


static void sane_block_output(struct net_device *dev, int count, const unsigned char *buf,
				int start_page)
{
	long shmem = (start_page - WD_START_PG)<<8;
	
	memcpy((char *)dev->mem_start+shmem, buf, count);
}

static void word_memcpy_tocard(void *tp, const void *fp, int count)
{
	volatile unsigned short *to = tp;
	const unsigned short *from = fp;
	
	count++;
	count/=2;
	
	while(count--)
		*to++=*from++;
}

static void word_memcpy_fromcard(void *tp, const void *fp, int count)
{
	unsigned short *to = tp;
	const volatile unsigned short *from = fp;
	
	count++;
	count/=2;
	
	while(count--)
		*to++=*from++;
}

static void slow_sane_get_8390_hdr(struct net_device *dev, struct e8390_pkt_hdr *hdr, int ring_page)
{
	unsigned long hdr_start = (ring_page - WD_START_PG)<<8;
	word_memcpy_fromcard((void *)hdr, (char *)dev->mem_start+hdr_start, 4);
	/* Register endianism - fix here rather than 8390.c */
	hdr->count=(hdr->count&0xFF)<<8|(hdr->count>>8);
}

static void slow_sane_block_input(struct net_device *dev, int count, struct sk_buff *skb, int ring_offset)
{
	unsigned long xfer_base = ring_offset - (WD_START_PG<<8);
	unsigned long xfer_start = xfer_base+dev->mem_start;

	if (xfer_start + count > dev->rmem_end) 
	{
		/* We must wrap the input move. */
		int semi_count = dev->rmem_end - xfer_start;
		word_memcpy_fromcard(skb->data, (char *)dev->mem_start+xfer_base, semi_count);
		count -= semi_count;
		word_memcpy_fromcard(skb->data + semi_count, 
			(char *)dev->rmem_start, count);
	}
	else
	{
		word_memcpy_fromcard(skb->data, (char *)dev->mem_start+xfer_base, count);
	}
}

static void slow_sane_block_output(struct net_device *dev, int count, const unsigned char *buf,
				int start_page)
{
	long shmem = (start_page - WD_START_PG)<<8;
	
	word_memcpy_tocard((char *)dev->mem_start+shmem, buf, count);
#if 0
	long shmem = (start_page - WD_START_PG)<<8;
	volatile unsigned short *to=(unsigned short *)(dev->mem_start+shmem);
	volatile int p;
	unsigned short *bp=(unsigned short *)buf;
	
	count=(count+1)/2;
	
	while(count--)
	{
		*to++=*bp++;
		for(p=0;p<10;p++)
			p++;
	}
#endif	
}

/*
 * Local variables:
 *  compile-command: "gcc -D__KERNEL__ -I/usr/src/linux/net/inet -Wall -Wstrict-prototypes -O6 -m486 -c daynaport.c"
 *  version-control: t
 *  tab-width: 4
 *  kept-new-versions: 5
 * End:
 */