summaryrefslogtreecommitdiffstats
path: root/drivers/net/mac8390.c
blob: a12bb64e3694d0790ff4738e8309ce8c94a830a5 (plain) (blame)
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
746
747
748
749
750
751
752
753
754
755
756
757
758
759
/* mac8390.c: New driver for 8390-based Nubus (or Nubus-alike)
   Ethernet cards on Linux */
/* Based on the former daynaport.c driver, by Alan Cox.  Some code
   taken from or inspired by skeleton.c by Donald Becker, acenic.c by
   Jes Sorensen, and ne2k-pci.c by Donald Becker and Paul Gortmaker.

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

/* 2000-02-28: support added for Dayna and Kinetics cards by
   A.G.deWijn@phys.uu.nl */
/* 2000-04-04: support added for Dayna2 by bart@etpmod.phys.tue.nl */
/* 2001-04-18: support for DaynaPort E/LC-M by rayk@knightsmanor.org */
/* 2001-05-15: support for Cabletron ported from old daynaport driver
 * and fixed access to Sonic Sys card which masquerades as a Farallon
 * by rayk@knightsmanor.org */

#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/types.h>
#include <linux/fcntl.h>
#include <linux/interrupt.h>
#include <linux/ptrace.h>
#include <linux/ioport.h>
#include <linux/nubus.h>
#include <linux/in.h>
#include <linux/slab.h>
#include <linux/string.h>
#include <linux/errno.h>
#include <linux/init.h>
#include <linux/netdevice.h>
#include <linux/etherdevice.h>
#include <linux/skbuff.h>
#include <linux/bitops.h>

#include <asm/system.h>
#include <asm/io.h>
#include <asm/dma.h>
#include <asm/hwtest.h>
#include <asm/macints.h>

static char version[] =
	"mac8390.c: v0.4 2001-05-15 David Huggins-Daines <dhd@debian.org> and others\n";

#define EI_SHIFT(x)	(ei_local->reg_offset[x])
#define ei_inb(port)   in_8(port)
#define ei_outb(val,port)  out_8(port,val)
#define ei_inb_p(port)   in_8(port)
#define ei_outb_p(val,port)  out_8(port,val)

#include "lib8390.c"

#define WD_START_PG			0x00	/* First page of TX buffer */
#define CABLETRON_RX_START_PG		0x00    /* First page of RX buffer */
#define CABLETRON_RX_STOP_PG		0x30    /* Last page +1 of RX ring */
#define CABLETRON_TX_START_PG		CABLETRON_RX_STOP_PG  /* First page of TX buffer */

/* Unfortunately it seems we have to hardcode these for the moment */
/* Shouldn't the card know about this? Does anyone know where to read it off the card? Do we trust the data provided by the card? */

#define DAYNA_8390_BASE		0x80000
#define DAYNA_8390_MEM		0x00000

#define KINETICS_8390_BASE	0x80000
#define KINETICS_8390_MEM	0x00000

#define CABLETRON_8390_BASE	0x90000
#define CABLETRON_8390_MEM	0x00000

enum mac8390_type {
	MAC8390_NONE = -1,
	MAC8390_APPLE,
	MAC8390_ASANTE,
	MAC8390_FARALLON,  /* Apple, Asante, and Farallon are all compatible */
	MAC8390_CABLETRON,
	MAC8390_DAYNA,
	MAC8390_INTERLAN,
	MAC8390_KINETICS,
	MAC8390_FOCUS,
	MAC8390_SONICSYS,
	MAC8390_DAYNA2,
	MAC8390_DAYNA3,
};

static const char * cardname[] = {
	"apple",
	"asante",
	"farallon",
	"cabletron",
	"dayna",
	"interlan",
	"kinetics",
	"focus",
	"sonic systems",
	"dayna2",
	"dayna_lc",
};

static int word16[] = {
	1, /* apple */
	1, /* asante */
	1, /* farallon */
	1, /* cabletron */
	0, /* dayna */
	1, /* interlan */
	0, /* kinetics */
	1, /* focus (??) */
	1, /* sonic systems  */
	1, /* dayna2 */
	1, /* dayna-lc */
};

/* on which cards do we use NuBus resources? */
static int useresources[] = {
	1, /* apple */
	1, /* asante */
	1, /* farallon */
	0, /* cabletron */
	0, /* dayna */
	0, /* interlan */
	0, /* kinetics */
	0, /* focus (??) */
	1, /* sonic systems */
	1, /* dayna2 */
	1, /* dayna-lc */
};

extern enum mac8390_type mac8390_ident(struct nubus_dev * dev);
extern int mac8390_memsize(unsigned long membase);
extern int mac8390_memtest(struct net_device * dev);
static int mac8390_initdev(struct net_device * dev, struct nubus_dev * ndev,
			   enum mac8390_type type);

static int mac8390_open(struct net_device * dev);
static int mac8390_close(struct net_device * dev);
static void mac8390_no_reset(struct net_device *dev);

/* Sane (32-bit chunk memory read/write) - Apple/Asante/Farallon do this*/
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);

/* dayna_memcpy to and from card */
static void dayna_memcpy_fromcard(struct net_device *dev, void *to,
				int from, int count);
static void dayna_memcpy_tocard(struct net_device *dev, int to,
			      const void *from, int count);

/* Dayna - Dayna/Kinetics use this */
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, int start_page);

#define memcpy_fromio(a,b,c)	memcpy((a),(void *)(b),(c))
#define memcpy_toio(a,b,c)	memcpy((void *)(a),(b),(c))

/* Slow Sane (16-bit chunk memory read/write) Cabletron uses this */
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, int start_page);
static void word_memcpy_tocard(void *tp, const void *fp, int count);
static void word_memcpy_fromcard(void *tp, const void *fp, int count);

enum mac8390_type __init mac8390_ident(struct nubus_dev * dev)
{
	if (dev->dr_sw == NUBUS_DRSW_ASANTE)
		return MAC8390_ASANTE;
	if (dev->dr_sw == NUBUS_DRSW_FARALLON)
		return MAC8390_FARALLON;
	if (dev->dr_sw == NUBUS_DRSW_KINETICS)
		return MAC8390_KINETICS;
	if (dev->dr_sw == NUBUS_DRSW_DAYNA)
		return MAC8390_DAYNA;
	if (dev->dr_sw == NUBUS_DRSW_DAYNA2)
		return MAC8390_DAYNA2;
	if (dev->dr_sw == NUBUS_DRSW_DAYNA_LC)
		return MAC8390_DAYNA3;
	if (dev->dr_hw == NUBUS_DRHW_CABLETRON)
		return MAC8390_CABLETRON;
	return MAC8390_NONE;
}

int __init mac8390_memsize(unsigned long membase)
{
	unsigned long flags;
	int i, j;

	local_irq_save(flags);
	/* Check up to 32K in 4K increments */
	for (i = 0; i < 8; i++) {
		volatile unsigned short *m = (unsigned short *) (membase + (i * 0x1000));

		/* Unwriteable - we have a fully decoded card and the
		   RAM end located */
		if (hwreg_present(m) == 0)
			break;

		/* write a distinctive byte */
		*m = 0xA5A0 | i;
		/* check that we read back what we wrote */
		if (*m != (0xA5A0 | i))
			break;

		/* check for partial decode and wrap */
		for (j = 0; j < i; j++) {
			volatile unsigned short *p = (unsigned short *) (membase + (j * 0x1000));
			if (*p != (0xA5A0 | j))
				break;
 		}
 	}
	local_irq_restore(flags);
	/* in any case, we stopped once we tried one block too many,
           or once we reached 32K */
 	return i * 0x1000;
}

struct net_device * __init mac8390_probe(int unit)
{
	struct net_device *dev;
	volatile unsigned short *i;
	int version_disp = 0;
	struct nubus_dev * ndev = NULL;
	int err = -ENODEV;

	struct nubus_dir dir;
	struct nubus_dirent ent;
	int offset;
	static unsigned int slots;

	enum mac8390_type cardtype;

	/* probably should check for Nubus instead */

	if (!MACH_IS_MAC)
		return ERR_PTR(-ENODEV);

	dev = ____alloc_ei_netdev(0);
	if (!dev)
		return ERR_PTR(-ENOMEM);

	if (unit >= 0)
		sprintf(dev->name, "eth%d", unit);

 	SET_MODULE_OWNER(dev);

	while ((ndev = nubus_find_type(NUBUS_CAT_NETWORK, NUBUS_TYPE_ETHERNET, ndev))) {
		/* Have we seen it already? */
		if (slots & (1<<ndev->board->slot))
			continue;
		slots |= 1<<ndev->board->slot;

		if ((cardtype = mac8390_ident(ndev)) == MAC8390_NONE)
			continue;

		if (version_disp == 0) {
			version_disp = 1;
			printk(version);
		}

		dev->irq = SLOT2IRQ(ndev->board->slot);
		/* This is getting to be a habit */
		dev->base_addr = ndev->board->slot_addr | ((ndev->board->slot&0xf) << 20);

		/* Get some Nubus info - we will trust the card's idea
		   of where its memory and registers are. */

		if (nubus_get_func_dir(ndev, &dir) == -1) {
			printk(KERN_ERR "%s: Unable to get Nubus functional"
					" directory for slot %X!\n",
			       dev->name, ndev->board->slot);
			continue;
		}

		/* Get the MAC address */
		if ((nubus_find_rsrc(&dir, NUBUS_RESID_MAC_ADDRESS, &ent)) == -1) {
			printk(KERN_INFO "%s: Couldn't get MAC address!\n",
					dev->name);
			continue;
		} else {
			nubus_get_rsrc_mem(dev->dev_addr, &ent, 6);
			/* Some Sonic Sys cards masquerade as Farallon */
			if (cardtype == MAC8390_FARALLON &&
					dev->dev_addr[0] == 0x0 &&
					dev->dev_addr[1] == 0x40 &&
					dev->dev_addr[2] == 0x10) {
				/* This is really Sonic Sys card */
				cardtype = MAC8390_SONICSYS;
			}
		}

		if (useresources[cardtype] == 1) {
			nubus_rewinddir(&dir);
			if (nubus_find_rsrc(&dir, NUBUS_RESID_MINOR_BASEOS, &ent) == -1) {
				printk(KERN_ERR "%s: Memory offset resource"
						" for slot %X not found!\n",
				       dev->name, ndev->board->slot);
				continue;
			}
			nubus_get_rsrc_mem(&offset, &ent, 4);
			dev->mem_start = dev->base_addr + offset;
			/* yes, this is how the Apple driver does it */
			dev->base_addr = dev->mem_start + 0x10000;
			nubus_rewinddir(&dir);
			if (nubus_find_rsrc(&dir, NUBUS_RESID_MINOR_LENGTH, &ent) == -1) {
				printk(KERN_INFO "%s: Memory length resource"
						 " for slot %X not found"
						 ", probing\n",
				       dev->name, ndev->board->slot);
				offset = mac8390_memsize(dev->mem_start);
				} else {
					nubus_get_rsrc_mem(&offset, &ent, 4);
				}
			dev->mem_end = dev->mem_start + offset;
		} else {
			switch (cardtype) {
				case MAC8390_KINETICS:
				case MAC8390_DAYNA: /* it's the same */
					dev->base_addr =
						(int)(ndev->board->slot_addr +
						DAYNA_8390_BASE);
					dev->mem_start =
						(int)(ndev->board->slot_addr +
						DAYNA_8390_MEM);
					dev->mem_end =
						dev->mem_start +
						mac8390_memsize(dev->mem_start);
					break;
				case MAC8390_CABLETRON:
					dev->base_addr =
						(int)(ndev->board->slot_addr +
						CABLETRON_8390_BASE);
					dev->mem_start =
						(int)(ndev->board->slot_addr +
						CABLETRON_8390_MEM);
					/* The base address is unreadable if 0x00
					 * has been written to the command register
					 * Reset the chip by writing E8390_NODMA +
					 *   E8390_PAGE0 + E8390_STOP just to be
					 *   sure
					 */
					i = (void *)dev->base_addr;
					*i = 0x21;
					dev->mem_end =
						dev->mem_start +
						mac8390_memsize(dev->mem_start);
					break;

				default:
					printk(KERN_ERR "Card type %s is"
							" unsupported, sorry\n",
					       cardname[cardtype]);
					continue;
			}
		}

		/* Do the nasty 8390 stuff */
		if (!mac8390_initdev(dev, ndev, cardtype))
			break;
	}

	if (!ndev)
		goto out;
	err = register_netdev(dev);
	if (err)
		goto out;
	return dev;

out:
	free_netdev(dev);
	return ERR_PTR(err);
}

#ifdef MODULE
MODULE_AUTHOR("David Huggins-Daines <dhd@debian.org> and others");
MODULE_DESCRIPTION("Macintosh NS8390-based Nubus Ethernet driver");
MODULE_LICENSE("GPL");

/* overkill, of course */
static struct net_device *dev_mac8390[15];
int init_module(void)
{
	int i;
	for (i = 0; i < 15; i++) {
		struct net_device *dev = mac8390_probe(-1);
		if (IS_ERR(dev))
			break;
		dev_mac890[i] = dev;
	}
	if (!i) {
		printk(KERN_NOTICE "mac8390.c: No useable cards found, driver NOT installed.\n");
		return -ENODEV;
	}
	return 0;
}

void cleanup_module(void)
{
	int i;
	for (i = 0; i < 15; i++) {
		struct net_device *dev = dev_mac890[i];
		if (dev) {
			unregister_netdev(dev);
			free_netdev(dev);
		}
	}
}

#endif /* MODULE */

static int __init mac8390_initdev(struct net_device * dev, struct nubus_dev * ndev,
			    enum mac8390_type type)
{
	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
	};
	static u32 fwrd2_offsets[16]={
		0,      2,      4,      6,
		8,     10,     12,     14,
		16,    18,     20,     22,
		24,    26,     28,     30
	};

	int access_bitmode;

	/* Now fill in our stuff */
	dev->open = &mac8390_open;
	dev->stop = &mac8390_close;
#ifdef CONFIG_NET_POLL_CONTROLLER
	dev->poll_controller = __ei_poll;
#endif

	/* GAR, ei_status is actually a macro even though it looks global */
	ei_status.name = cardname[type];
	ei_status.word16 = word16[type];

	/* Cabletron's TX/RX buffers are backwards */
	if (type == MAC8390_CABLETRON) {
               ei_status.tx_start_page = CABLETRON_TX_START_PG;
               ei_status.rx_start_page = CABLETRON_RX_START_PG;
               ei_status.stop_page = CABLETRON_RX_STOP_PG;
               ei_status.rmem_start = dev->mem_start;
               ei_status.rmem_end = dev->mem_start + CABLETRON_RX_STOP_PG*256;
	} else {
               ei_status.tx_start_page = WD_START_PG;
               ei_status.rx_start_page = WD_START_PG + TX_PAGES;
               ei_status.stop_page = (dev->mem_end - dev->mem_start)/256;
               ei_status.rmem_start = dev->mem_start + TX_PAGES*256;
               ei_status.rmem_end = dev->mem_end;
	}

	/* Fill in model-specific information and functions */
	switch(type) {
	case MAC8390_SONICSYS:
		/* 16 bit card, register map is reversed */
		ei_status.reset_8390 = &mac8390_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;
		access_bitmode = 0;
		break;
	case MAC8390_FARALLON:
	case MAC8390_APPLE:
	case MAC8390_ASANTE:
	case MAC8390_DAYNA2:
	case MAC8390_DAYNA3:
		/* 32 bit card, register map is reversed */
		/* sane */
		ei_status.reset_8390 = &mac8390_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;
		access_bitmode = 1;
		break;
	case MAC8390_CABLETRON:
		/* 16 bit card, register map is short forward */
		ei_status.reset_8390 = &mac8390_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 = fwrd2_offsets;
		access_bitmode = 0;
		break;
	case MAC8390_DAYNA:
	case MAC8390_KINETICS:
		/* 16 bit memory */
		/* dayna and similar */
		ei_status.reset_8390 = &mac8390_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;
		access_bitmode = 0;
		break;
	default:
		printk(KERN_ERR "Card type %s is unsupported, sorry\n", cardname[type]);
		return -ENODEV;
	}

	__NS8390_init(dev, 0);

	/* Good, done, now spit out some messages */
	printk(KERN_INFO "%s: %s in slot %X (type %s)\n",
		   dev->name, ndev->board->name, ndev->board->slot, cardname[type]);
	printk(KERN_INFO "MAC ");
	{
		int i;
		for (i = 0; i < 6; i++) {
			printk("%2.2x", dev->dev_addr[i]);
			if (i < 5)
				printk(":");
		}
	}
	printk(" IRQ %d, shared memory at %#lx-%#lx,  %d-bit access.\n",
		   dev->irq, dev->mem_start, dev->mem_end-1,
		   access_bitmode?32:16);
	return 0;
}

static int mac8390_open(struct net_device *dev)
{
	__ei_open(dev);
	if (request_irq(dev->irq, __ei_interrupt, 0, "8390 Ethernet", dev)) {
		printk ("%s: unable to get IRQ %d.\n", dev->name, dev->irq);
		return -EAGAIN;
	}
	return 0;
}

static int mac8390_close(struct net_device *dev)
{
	free_irq(dev->irq, dev);
	__ei_close(dev);
	return 0;
}

static void mac8390_no_reset(struct net_device *dev)
{
	ei_status.txing = 0;
	if (ei_debug > 1)
		printk("reset not supported\n");
	return;
}

/* dayna_memcpy_fromio/dayna_memcpy_toio */
/* directly from daynaport.c by Alan Cox */
static void dayna_memcpy_fromcard(struct net_device *dev, void *to, int from, int count)
{
	volatile unsigned char *ptr;
	unsigned char *target=to;
	from<<=1;	/* word, skip overhead */
	ptr=(unsigned char *)(dev->mem_start+from);
	/* Leading byte? */
	if (from&2) {
		*target++ = ptr[-1];
		ptr += 2;
		count--;
	}
	while(count>=2)
	{
		*(unsigned short *)target = *(unsigned short volatile *)ptr;
		ptr += 4;			/* skip cruft */
		target += 2;
		count-=2;
	}
	/* Trailing byte? */
	if(count)
		*target = *ptr;
}

static void dayna_memcpy_tocard(struct net_device *dev, int to, const void *from, int count)
{
	volatile unsigned short *ptr;
	const unsigned char *src=from;
	to<<=1;	/* word, skip overhead */
	ptr=(unsigned short *)(dev->mem_start+to);
	/* Leading byte? */
	if (to&2) { /* avoid a byte write (stomps on other data) */
		ptr[-1] = (ptr[-1]&0xFF00)|*src++;
		ptr++;
		count--;
	}
	while(count>=2)
	{
		*ptr++=*(unsigned short *)src;		/* Copy and */
		ptr++;			/* skip cruft */
		src += 2;
		count-=2;
	}
	/* Trailing byte? */
	if(count)
	{
		/* card doesn't like byte writes */
		*ptr=(*ptr&0x00FF)|(*src << 8);
	}
}

/* sane block input/output */
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_fromio((void *)hdr, (char *)dev->mem_start + hdr_start, 4);
	/* Fix endianness */
	hdr->count = swab16(hdr->count);
}

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 > ei_status.rmem_end) {
		/* We must wrap the input move. */
		int semi_count = ei_status.rmem_end - xfer_start;
		memcpy_fromio(skb->data, (char *)dev->mem_start + xfer_base, semi_count);
		count -= semi_count;
		memcpy_toio(skb->data + semi_count, (char *)ei_status.rmem_start, count);
	} else {
		memcpy_fromio(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_toio((char *)dev->mem_start + shmem, buf, count);
}

/* dayna block input/output */
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_memcpy_fromcard(dev, (void *)hdr, hdr_start, 4);
	/* Fix endianness */
	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 math is done in card memory space which is word
	   per long onto our space. */

	if (xfer_start + count > ei_status.rmem_end)
	{
		/* We must wrap the input move. */
		int semi_count = ei_status.rmem_end - xfer_start;
		dayna_memcpy_fromcard(dev, skb->data, xfer_base, semi_count);
		count -= semi_count;
		dayna_memcpy_fromcard(dev, skb->data + semi_count,
				      ei_status.rmem_start - dev->mem_start,
				      count);
	}
	else
	{
		dayna_memcpy_fromcard(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;

	dayna_memcpy_tocard(dev, shmem, buf, count);
}

/* Cabletron block I/O */
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 > ei_status.rmem_end)
	{
		/* We must wrap the input move. */
		int semi_count = ei_status.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 *)ei_status.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);
}

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++;
}


com">** TODO: ** - J2573 seems to hang sometimes when in shared memory mode. ** - Mode for Priority TX ** - Check PCI registers, performance might be improved? ** - To reduce interrupt load in busmaster, one could switch off ** the interrupts that are used to refill the queues whenever the ** queues are filled up to more than a certain threshold. ** - some updates for EISA version of card ** ** ** This code is free software; you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation; either version 2 of the License, or ** (at your option) any later version. ** ** This code is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. ** ** You should have received a copy of the GNU General Public License ** along with this program; if not, write to the Free Software ** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. ** ** 1.57c -> 1.58 ** - used indent to change coding-style ** - added KTI DP-200 EISA ID ** - ioremap is also used for low (<1MB) memory (multi-architecture support) ** ** 1.57b -> 1.57c - Arnaldo Carvalho de Melo <acme@conectiva.com.br> ** - release resources on failure in init_module ** ** 1.57 -> 1.57b - Jean II ** - fix spinlocks, SMP is now working ! ** ** 1.56 -> 1.57 ** - updates for new PCI interface for 2.1 kernels ** ** 1.55 -> 1.56 ** - removed printk in misc. interrupt and update statistics to allow ** monitoring of card status ** - timing changes in xmit routines, relogin to 100VG hub added when ** driver does reset ** - included fix for Compex FreedomLine PCI adapter ** ** 1.54 -> 1.55 ** - fixed bad initialization in init_module ** - added Compex FreedomLine adapter ** - some fixes in card initialization ** ** 1.53 -> 1.54 ** - added hardware multicast filter support (doesn't work) ** - little changes in hp100_sense_lan routine ** - added support for Coax and AUI (J2970) ** - fix for multiple cards and hp100_mode parameter (insmod) ** - fix for shared IRQ ** ** 1.52 -> 1.53 ** - fixed bug in multicast support ** */ #define HP100_DEFAULT_PRIORITY_TX 0 #undef HP100_DEBUG #undef HP100_DEBUG_B /* Trace */ #undef HP100_DEBUG_BM /* Debug busmaster code (PDL stuff) */ #undef HP100_DEBUG_TRAINING /* Debug login-to-hub procedure */ #undef HP100_DEBUG_TX #undef HP100_DEBUG_IRQ #undef HP100_DEBUG_RX #undef HP100_MULTICAST_FILTER /* Need to be debugged... */ #include <linux/module.h> #include <linux/kernel.h> #include <linux/string.h> #include <linux/errno.h> #include <linux/ioport.h> #include <linux/slab.h> #include <linux/interrupt.h> #include <linux/eisa.h> #include <linux/pci.h> #include <linux/dma-mapping.h> #include <linux/spinlock.h> #include <linux/netdevice.h> #include <linux/etherdevice.h> #include <linux/skbuff.h> #include <linux/types.h> #include <linux/delay.h> #include <linux/init.h> #include <linux/bitops.h> #include <linux/jiffies.h> #include <asm/io.h> #include "hp100.h" /* * defines */ #define HP100_BUS_ISA 0 #define HP100_BUS_EISA 1 #define HP100_BUS_PCI 2 #define HP100_REGION_SIZE 0x20 /* for ioports */ #define HP100_SIG_LEN 8 /* same as EISA_SIG_LEN */ #define HP100_MAX_PACKET_SIZE (1536+4) #define HP100_MIN_PACKET_SIZE 60 #ifndef HP100_DEFAULT_RX_RATIO /* default - 75% onboard memory on the card are used for RX packets */ #define HP100_DEFAULT_RX_RATIO 75 #endif #ifndef HP100_DEFAULT_PRIORITY_TX /* default - don't enable transmit outgoing packets as priority */ #define HP100_DEFAULT_PRIORITY_TX 0 #endif /* * structures */ struct hp100_private { spinlock_t lock; char id[HP100_SIG_LEN]; u_short chip; u_short soft_model; u_int memory_size; u_int virt_memory_size; u_short rx_ratio; /* 1 - 99 */ u_short priority_tx; /* != 0 - priority tx */ u_short mode; /* PIO, Shared Mem or Busmaster */ u_char bus; struct pci_dev *pci_dev; short mem_mapped; /* memory mapped access */ void __iomem *mem_ptr_virt; /* virtual memory mapped area, maybe NULL */ unsigned long mem_ptr_phys; /* physical memory mapped area */ short lan_type; /* 10Mb/s, 100Mb/s or -1 (error) */ int hub_status; /* was login to hub successful? */ u_char mac1_mode; u_char mac2_mode; u_char hash_bytes[8]; struct net_device_stats stats; /* Rings for busmaster mode: */ hp100_ring_t *rxrhead; /* Head (oldest) index into rxring */ hp100_ring_t *rxrtail; /* Tail (newest) index into rxring */ hp100_ring_t *txrhead; /* Head (oldest) index into txring */ hp100_ring_t *txrtail; /* Tail (newest) index into txring */ hp100_ring_t rxring[MAX_RX_PDL]; hp100_ring_t txring[MAX_TX_PDL]; u_int *page_vaddr_algn; /* Aligned virtual address of allocated page */ u_long whatever_offset; /* Offset to bus/phys/dma address */ int rxrcommit; /* # Rx PDLs commited to adapter */ int txrcommit; /* # Tx PDLs commited to adapter */ }; /* * variables */ #ifdef CONFIG_ISA static const char *hp100_isa_tbl[] = { "HWPF150", /* HP J2573 rev A */ "HWP1950", /* HP J2573 */ }; #endif #ifdef CONFIG_EISA static struct eisa_device_id hp100_eisa_tbl[] = { { "HWPF180" }, /* HP J2577 rev A */ { "HWP1920" }, /* HP 27248B */ { "HWP1940" }, /* HP J2577 */ { "HWP1990" }, /* HP J2577 */ { "CPX0301" }, /* ReadyLink ENET100-VG4 */ { "CPX0401" }, /* FreedomLine 100/VG */ { "" } /* Mandatory final entry ! */ }; MODULE_DEVICE_TABLE(eisa, hp100_eisa_tbl); #endif #ifdef CONFIG_PCI static struct pci_device_id hp100_pci_tbl[] = { {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_J2585A, PCI_ANY_ID, PCI_ANY_ID,}, {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_J2585B, PCI_ANY_ID, PCI_ANY_ID,}, {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_J2970A, PCI_ANY_ID, PCI_ANY_ID,}, {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_J2973A, PCI_ANY_ID, PCI_ANY_ID,}, {PCI_VENDOR_ID_COMPEX, PCI_DEVICE_ID_COMPEX_ENET100VG4, PCI_ANY_ID, PCI_ANY_ID,}, {PCI_VENDOR_ID_COMPEX2, PCI_DEVICE_ID_COMPEX2_100VG, PCI_ANY_ID, PCI_ANY_ID,}, /* {PCI_VENDOR_ID_KTI, PCI_DEVICE_ID_KTI_DP200, PCI_ANY_ID, PCI_ANY_ID }, */ {} /* Terminating entry */ }; MODULE_DEVICE_TABLE(pci, hp100_pci_tbl); #endif static int hp100_rx_ratio = HP100_DEFAULT_RX_RATIO; static int hp100_priority_tx = HP100_DEFAULT_PRIORITY_TX; static int hp100_mode = 1; module_param(hp100_rx_ratio, int, 0); module_param(hp100_priority_tx, int, 0); module_param(hp100_mode, int, 0); /* * prototypes */ static int hp100_probe1(struct net_device *dev, int ioaddr, u_char bus, struct pci_dev *pci_dev); static int hp100_open(struct net_device *dev); static int hp100_close(struct net_device *dev); static int hp100_start_xmit(struct sk_buff *skb, struct net_device *dev); static int hp100_start_xmit_bm(struct sk_buff *skb, struct net_device *dev); static void hp100_rx(struct net_device *dev); static struct net_device_stats *hp100_get_stats(struct net_device *dev); static void hp100_misc_interrupt(struct net_device *dev); static void hp100_update_stats(struct net_device *dev); static void hp100_clear_stats(struct hp100_private *lp, int ioaddr); static void hp100_set_multicast_list(struct net_device *dev); static irqreturn_t hp100_interrupt(int irq, void *dev_id); static void hp100_start_interface(struct net_device *dev); static void hp100_stop_interface(struct net_device *dev); static void hp100_load_eeprom(struct net_device *dev, u_short ioaddr); static int hp100_sense_lan(struct net_device *dev); static int hp100_login_to_vg_hub(struct net_device *dev, u_short force_relogin); static int hp100_down_vg_link(struct net_device *dev); static void hp100_cascade_reset(struct net_device *dev, u_short enable); static void hp100_BM_shutdown(struct net_device *dev); static void hp100_mmuinit(struct net_device *dev); static void hp100_init_pdls(struct net_device *dev); static int hp100_init_rxpdl(struct net_device *dev, register hp100_ring_t * ringptr, register u_int * pdlptr); static int hp100_init_txpdl(struct net_device *dev, register hp100_ring_t * ringptr, register u_int * pdlptr); static void hp100_rxfill(struct net_device *dev); static void hp100_hwinit(struct net_device *dev); static void hp100_clean_txring(struct net_device *dev); #ifdef HP100_DEBUG static void hp100_RegisterDump(struct net_device *dev); #endif /* Conversion to new PCI API : * Convert an address in a kernel buffer to a bus/phys/dma address. * This work *only* for memory fragments part of lp->page_vaddr, * because it was properly DMA allocated via pci_alloc_consistent(), * so we just need to "retrieve" the original mapping to bus/phys/dma * address - Jean II */ static inline dma_addr_t virt_to_whatever(struct net_device *dev, u32 * ptr) { struct hp100_private *lp = netdev_priv(dev); return ((u_long) ptr) + lp->whatever_offset; } static inline u_int pdl_map_data(struct hp100_private *lp, void *data) { return pci_map_single(lp->pci_dev, data, MAX_ETHER_SIZE, PCI_DMA_FROMDEVICE); } /* TODO: This function should not really be needed in a good design... */ static void wait(void) { mdelay(1); } /* * probe functions * These functions should - if possible - avoid doing write operations * since this could cause problems when the card is not installed. */ /* * Read board id and convert to string. * Effectively same code as decode_eisa_sig */ static __devinit const char *hp100_read_id(int ioaddr) { int i; static char str[HP100_SIG_LEN]; unsigned char sig[4], sum; unsigned short rev; hp100_page(ID_MAC_ADDR); sum = 0; for (i = 0; i < 4; i++) { sig[i] = hp100_inb(BOARD_ID + i); sum += sig[i]; } sum += hp100_inb(BOARD_ID + i); if (sum != 0xff) return NULL; /* bad checksum */ str[0] = ((sig[0] >> 2) & 0x1f) + ('A' - 1); str[1] = (((sig[0] & 3) << 3) | (sig[1] >> 5)) + ('A' - 1); str[2] = (sig[1] & 0x1f) + ('A' - 1); rev = (sig[2] << 8) | sig[3]; sprintf(str + 3, "%04X", rev); return str; } #ifdef CONFIG_ISA static __init int hp100_isa_probe1(struct net_device *dev, int ioaddr) { const char *sig; int i; if (!request_region(ioaddr, HP100_REGION_SIZE, "hp100")) goto err; if (hp100_inw(HW_ID) != HP100_HW_ID_CASCADE) { release_region(ioaddr, HP100_REGION_SIZE); goto err; } sig = hp100_read_id(ioaddr); release_region(ioaddr, HP100_REGION_SIZE); if (sig == NULL) goto err; for (i = 0; i < ARRAY_SIZE(hp100_isa_tbl); i++) { if (!strcmp(hp100_isa_tbl[i], sig)) break; } if (i < ARRAY_SIZE(hp100_isa_tbl)) return hp100_probe1(dev, ioaddr, HP100_BUS_ISA, NULL); err: return -ENODEV; } /* * Probe for ISA board. * EISA and PCI are handled by device infrastructure. */ static int __init hp100_isa_probe(struct net_device *dev, int addr) { int err = -ENODEV; /* Probe for a specific ISA address */ if (addr > 0xff && addr < 0x400) err = hp100_isa_probe1(dev, addr); else if (addr != 0) err = -ENXIO; else { /* Probe all ISA possible port regions */ for (addr = 0x100; addr < 0x400; addr += 0x20) { err = hp100_isa_probe1(dev, addr); if (!err) break; } } return err; } #endif /* CONFIG_ISA */ #if !defined(MODULE) && defined(CONFIG_ISA) struct net_device * __init hp100_probe(int unit) { struct net_device *dev = alloc_etherdev(sizeof(struct hp100_private)); int err; if (!dev) return ERR_PTR(-ENODEV); SET_MODULE_OWNER(dev); #ifdef HP100_DEBUG_B hp100_outw(0x4200, TRACE); printk("hp100: %s: probe\n", dev->name); #endif if (unit >= 0) { sprintf(dev->name, "eth%d", unit); netdev_boot_setup_check(dev); } err = hp100_isa_probe(dev, dev->base_addr); if (err) goto out; return dev; out: free_netdev(dev); return ERR_PTR(err); } #endif /* !MODULE && CONFIG_ISA */ static int __devinit hp100_probe1(struct net_device *dev, int ioaddr, u_char bus, struct pci_dev *pci_dev) { int i; int err = -ENODEV; const char *eid; u_int chip; u_char uc; u_int memory_size = 0, virt_memory_size = 0; u_short local_mode, lsw; short mem_mapped; unsigned long mem_ptr_phys; void __iomem *mem_ptr_virt; struct hp100_private *lp; #ifdef HP100_DEBUG_B hp100_outw(0x4201, TRACE); printk("hp100: %s: probe1\n", dev->name); #endif /* memory region for programmed i/o */ if (!request_region(ioaddr, HP100_REGION_SIZE, "hp100")) goto out1; if (hp100_inw(HW_ID) != HP100_HW_ID_CASCADE) goto out2; chip = hp100_inw(PAGING) & HP100_CHIPID_MASK; #ifdef HP100_DEBUG if (chip == HP100_CHIPID_SHASTA) printk("hp100: %s: Shasta Chip detected. (This is a pre 802.12 chip)\n", dev->name); else if (chip == HP100_CHIPID_RAINIER) printk("hp100: %s: Rainier Chip detected. (This is a pre 802.12 chip)\n", dev->name); else if (chip == HP100_CHIPID_LASSEN) printk("hp100: %s: Lassen Chip detected.\n", dev->name); else printk("hp100: %s: Warning: Unknown CASCADE chip (id=0x%.4x).\n", dev->name, chip); #endif dev->base_addr = ioaddr; eid = hp100_read_id(ioaddr); if (eid == NULL) { /* bad checksum? */ printk(KERN_WARNING "hp100_probe: bad ID checksum at base port 0x%x\n", ioaddr); goto out2; } hp100_page(ID_MAC_ADDR); for (i = uc = 0; i < 7; i++) uc += hp100_inb(LAN_ADDR + i); if (uc != 0xff) { printk(KERN_WARNING "hp100_probe: bad lan address checksum at port 0x%x)\n", ioaddr); err = -EIO; goto out2; } /* Make sure, that all registers are correctly updated... */ hp100_load_eeprom(dev, ioaddr); wait(); /* * Determine driver operation mode * * Use the variable "hp100_mode" upon insmod or as kernel parameter to * force driver modes: * hp100_mode=1 -> default, use busmaster mode if configured. * hp100_mode=2 -> enable shared memory mode * hp100_mode=3 -> force use of i/o mapped mode. * hp100_mode=4 -> same as 1, but re-set the enable bit on the card. */ /* * LSW values: * 0x2278 -> J2585B, PnP shared memory mode * 0x2270 -> J2585B, shared memory mode, 0xdc000 * 0xa23c -> J2585B, I/O mapped mode * 0x2240 -> EISA COMPEX, BusMaster (Shasta Chip) * 0x2220 -> EISA HP, I/O (Shasta Chip) * 0x2260 -> EISA HP, BusMaster (Shasta Chip) */ #if 0 local_mode = 0x2270; hp100_outw(0xfefe, OPTION_LSW); hp100_outw(local_mode | HP100_SET_LB | HP100_SET_HB, OPTION_LSW); #endif /* hp100_mode value maybe used in future by another card */ local_mode = hp100_mode; if (local_mode < 1 || local_mode > 4) local_mode = 1; /* default */ #ifdef HP100_DEBUG printk("hp100: %s: original LSW = 0x%x\n", dev->name, hp100_inw(OPTION_LSW)); #endif if (local_mode == 3) { hp100_outw(HP100_MEM_EN | HP100_RESET_LB, OPTION_LSW); hp100_outw(HP100_IO_EN | HP100_SET_LB, OPTION_LSW); hp100_outw(HP100_BM_WRITE | HP100_BM_READ | HP100_RESET_HB, OPTION_LSW); printk("hp100: IO mapped mode forced.\n"); } else if (local_mode == 2) { hp100_outw(HP100_MEM_EN | HP100_SET_LB, OPTION_LSW); hp100_outw(HP100_IO_EN | HP100_SET_LB, OPTION_LSW); hp100_outw(HP100_BM_WRITE | HP100_BM_READ | HP100_RESET_HB, OPTION_LSW); printk("hp100: Shared memory mode requested.\n"); } else if (local_mode == 4) { if (chip == HP100_CHIPID_LASSEN) { hp100_outw(HP100_BM_WRITE | HP100_BM_READ | HP100_SET_HB, OPTION_LSW); hp100_outw(HP100_IO_EN | HP100_MEM_EN | HP100_RESET_LB, OPTION_LSW); printk("hp100: Busmaster mode requested.\n"); } local_mode = 1; } if (local_mode == 1) { /* default behaviour */ lsw = hp100_inw(OPTION_LSW); if ((lsw & HP100_IO_EN) && (~lsw & HP100_MEM_EN) && (~lsw & (HP100_BM_WRITE | HP100_BM_READ))) { #ifdef HP100_DEBUG printk("hp100: %s: IO_EN bit is set on card.\n", dev->name); #endif local_mode = 3; } else if (chip == HP100_CHIPID_LASSEN && (lsw & (HP100_BM_WRITE | HP100_BM_READ)) == (HP100_BM_WRITE | HP100_BM_READ)) { /* Conversion to new PCI API : * I don't have the doc, but I assume that the card * can map the full 32bit address space. * Also, we can have EISA Busmaster cards (not tested), * so beware !!! - Jean II */ if((bus == HP100_BUS_PCI) && (pci_set_dma_mask(pci_dev, DMA_32BIT_MASK))) { /* Gracefully fallback to shared memory */ goto busmasterfail; } printk("hp100: Busmaster mode enabled.\n"); hp100_outw(HP100_MEM_EN | HP100_IO_EN | HP100_RESET_LB, OPTION_LSW); } else { busmasterfail: #ifdef HP100_DEBUG printk("hp100: %s: Card not configured for BM or BM not supported with this card.\n", dev->name); printk("hp100: %s: Trying shared memory mode.\n", dev->name); #endif /* In this case, try shared memory mode */ local_mode = 2; hp100_outw(HP100_MEM_EN | HP100_SET_LB, OPTION_LSW); /* hp100_outw(HP100_IO_EN|HP100_RESET_LB, OPTION_LSW); */ } } #ifdef HP100_DEBUG printk("hp100: %s: new LSW = 0x%x\n", dev->name, hp100_inw(OPTION_LSW)); #endif /* Check for shared memory on the card, eventually remap it */ hp100_page(HW_MAP); mem_mapped = ((hp100_inw(OPTION_LSW) & (HP100_MEM_EN)) != 0); mem_ptr_phys = 0UL; mem_ptr_virt = NULL; memory_size = (8192 << ((hp100_inb(SRAM) >> 5) & 0x07)); virt_memory_size = 0; /* For memory mapped or busmaster mode, we want the memory address */ if (mem_mapped || (local_mode == 1)) { mem_ptr_phys = (hp100_inw(MEM_MAP_LSW) | (hp100_inw(MEM_MAP_MSW) << 16)); mem_ptr_phys &= ~0x1fff; /* 8k alignment */ if (bus == HP100_BUS_ISA && (mem_ptr_phys & ~0xfffff) != 0) { printk("hp100: Can only use programmed i/o mode.\n"); mem_ptr_phys = 0; mem_mapped = 0; local_mode = 3; /* Use programmed i/o */ } /* We do not need access to shared memory in busmaster mode */ /* However in slave mode we need to remap high (>1GB) card memory */ if (local_mode != 1) { /* = not busmaster */ /* We try with smaller memory sizes, if ioremap fails */ for (virt_memory_size = memory_size; virt_memory_size > 16383; virt_memory_size >>= 1) { if ((mem_ptr_virt = ioremap((u_long) mem_ptr_phys, virt_memory_size)) == NULL) { #ifdef HP100_DEBUG printk("hp100: %s: ioremap for 0x%x bytes high PCI memory at 0x%lx failed\n", dev->name, virt_memory_size, mem_ptr_phys); #endif } else { #ifdef HP100_DEBUG printk("hp100: %s: remapped 0x%x bytes high PCI memory at 0x%lx to %p.\n", dev->name, virt_memory_size, mem_ptr_phys, mem_ptr_virt); #endif break; } } if (mem_ptr_virt == NULL) { /* all ioremap tries failed */ printk("hp100: Failed to ioremap the PCI card memory. Will have to use i/o mapped mode.\n"); local_mode = 3; virt_memory_size = 0; } } } if (local_mode == 3) { /* io mapped forced */ mem_mapped = 0; mem_ptr_phys = 0; mem_ptr_virt = NULL; printk("hp100: Using (slow) programmed i/o mode.\n"); } /* Initialise the "private" data structure for this card. */ lp = netdev_priv(dev); spin_lock_init(&lp->lock); strlcpy(lp->id, eid, HP100_SIG_LEN); lp->chip = chip; lp->mode = local_mode; lp->bus = bus; lp->pci_dev = pci_dev; lp->priority_tx = hp100_priority_tx; lp->rx_ratio = hp100_rx_ratio; lp->mem_ptr_phys = mem_ptr_phys; lp->mem_ptr_virt = mem_ptr_virt; hp100_page(ID_MAC_ADDR); lp->soft_model = hp100_inb(SOFT_MODEL); lp->mac1_mode = HP100_MAC1MODE3; lp->mac2_mode = HP100_MAC2MODE3; memset(&lp->hash_bytes, 0x00, 8); dev->base_addr = ioaddr; lp->memory_size = memory_size; lp->virt_memory_size = virt_memory_size; lp->rx_ratio = hp100_rx_ratio; /* can be conf'd with insmod */ dev->open = hp100_open; dev->stop = hp100_close; if (lp->mode == 1) /* busmaster */ dev->hard_start_xmit = hp100_start_xmit_bm; else dev->hard_start_xmit = hp100_start_xmit; dev->get_stats = hp100_get_stats; dev->set_multicast_list = &hp100_set_multicast_list; /* Ask the card for which IRQ line it is configured */ if (bus == HP100_BUS_PCI) { dev->irq = pci_dev->irq; } else { hp100_page(HW_MAP); dev->irq = hp100_inb(IRQ_CHANNEL) & HP100_IRQMASK; if (dev->irq == 2) dev->irq = 9; } if (lp->mode == 1) /* busmaster */ dev->dma = 4; /* Ask the card for its MAC address and store it for later use. */ hp100_page(ID_MAC_ADDR); for (i = uc = 0; i < 6; i++) dev->dev_addr[i] = hp100_inb(LAN_ADDR + i); /* Reset statistics (counters) */ hp100_clear_stats(lp, ioaddr); /* If busmaster mode is wanted, a dma-capable memory area is needed for * the rx and tx PDLs * PCI cards can access the whole PC memory. Therefore GFP_DMA is not * needed for the allocation of the memory area. */ /* TODO: We do not need this with old cards, where PDLs are stored * in the cards shared memory area. But currently, busmaster has been * implemented/tested only with the lassen chip anyway... */ if (lp->mode == 1) { /* busmaster */ dma_addr_t page_baddr; /* Get physically continous memory for TX & RX PDLs */ /* Conversion to new PCI API : * Pages are always aligned and zeroed, no need to it ourself. * Doc says should be OK for EISA bus as well - Jean II */ if ((lp->page_vaddr_algn = pci_alloc_consistent(lp->pci_dev, MAX_RINGSIZE, &page_baddr)) == NULL) { err = -ENOMEM; goto out2; } lp->whatever_offset = ((u_long) page_baddr) - ((u_long) lp->page_vaddr_algn); #ifdef HP100_DEBUG_BM printk("hp100: %s: Reserved DMA memory from 0x%x to 0x%x\n", dev->name, (u_int) lp->page_vaddr_algn, (u_int) lp->page_vaddr_algn + MAX_RINGSIZE); #endif lp->rxrcommit = lp->txrcommit = 0; lp->rxrhead = lp->rxrtail = &(lp->rxring[0]); lp->txrhead = lp->txrtail = &(lp->txring[0]); } /* Initialise the card. */ /* (I'm not really sure if it's a good idea to do this during probing, but * like this it's assured that the lan connection type can be sensed * correctly) */ hp100_hwinit(dev); /* Try to find out which kind of LAN the card is connected to. */ lp->lan_type = hp100_sense_lan(dev); /* Print out a message what about what we think we have probed. */ printk("hp100: at 0x%x, IRQ %d, ", ioaddr, dev->irq); switch (bus) { case HP100_BUS_EISA: printk("EISA"); break; case HP100_BUS_PCI: printk("PCI"); break; default: printk("ISA"); break; } printk(" bus, %dk SRAM (rx/tx %d%%).\n", lp->memory_size >> 10, lp->rx_ratio); if (lp->mode == 2) { /* memory mapped */ printk("hp100: Memory area at 0x%lx-0x%lx", mem_ptr_phys, (mem_ptr_phys + (mem_ptr_phys > 0x100000 ? (u_long) lp->memory_size : 16 * 1024)) - 1); if (mem_ptr_virt) printk(" (virtual base %p)", mem_ptr_virt); printk(".\n"); /* Set for info when doing ifconfig */ dev->mem_start = mem_ptr_phys; dev->mem_end = mem_ptr_phys + lp->memory_size; } printk("hp100: "); if (lp->lan_type != HP100_LAN_ERR) printk("Adapter is attached to "); switch (lp->lan_type) { case HP100_LAN_100: printk("100Mb/s Voice Grade AnyLAN network.\n"); break; case HP100_LAN_10: printk("10Mb/s network (10baseT).\n"); break; case HP100_LAN_COAX: printk("10Mb/s network (coax).\n"); break; default: printk("Warning! Link down.\n"); } err = register_netdev(dev); if (err) goto out3; return 0; out3: if (local_mode == 1) pci_free_consistent(lp->pci_dev, MAX_RINGSIZE + 0x0f, lp->page_vaddr_algn, virt_to_whatever(dev, lp->page_vaddr_algn)); if (mem_ptr_virt) iounmap(mem_ptr_virt); out2: release_region(ioaddr, HP100_REGION_SIZE); out1: return err; } /* This procedure puts the card into a stable init state */ static void hp100_hwinit(struct net_device *dev) { int ioaddr = dev->base_addr; struct hp100_private *lp = netdev_priv(dev); #ifdef HP100_DEBUG_B hp100_outw(0x4202, TRACE); printk("hp100: %s: hwinit\n", dev->name); #endif /* Initialise the card. -------------------------------------------- */ /* Clear all pending Ints and disable Ints */ hp100_page(PERFORMANCE); hp100_outw(0xfefe, IRQ_MASK); /* mask off all ints */ hp100_outw(0xffff, IRQ_STATUS); /* clear all pending ints */ hp100_outw(HP100_INT_EN | HP100_RESET_LB, OPTION_LSW); hp100_outw(HP100_TRI_INT | HP100_SET_HB, OPTION_LSW); if (lp->mode == 1) { hp100_BM_shutdown(dev); /* disables BM, puts cascade in reset */ wait(); } else { hp100_outw(HP100_INT_EN | HP100_RESET_LB, OPTION_LSW); hp100_cascade_reset(dev, 1); hp100_page(MAC_CTRL); hp100_andb(~(HP100_RX_EN | HP100_TX_EN), MAC_CFG_1); } /* Initiate EEPROM reload */ hp100_load_eeprom(dev, 0); wait(); /* Go into reset again. */ hp100_cascade_reset(dev, 1); /* Set Option Registers to a safe state */ hp100_outw(HP100_DEBUG_EN | HP100_RX_HDR | HP100_EE_EN | HP100_BM_WRITE | HP100_BM_READ | HP100_RESET_HB | HP100_FAKE_INT | HP100_INT_EN | HP100_MEM_EN | HP100_IO_EN | HP100_RESET_LB, OPTION_LSW); hp100_outw(HP100_TRI_INT | HP100_MMAP_DIS | HP100_SET_HB, OPTION_LSW); hp100_outb(HP100_PRIORITY_TX | HP100_ADV_NXT_PKT | HP100_TX_CMD | HP100_RESET_LB, OPTION_MSW); /* TODO: Configure MMU for Ram Test. */ /* TODO: Ram Test. */ /* Re-check if adapter is still at same i/o location */ /* (If the base i/o in eeprom has been changed but the */ /* registers had not been changed, a reload of the eeprom */ /* would move the adapter to the address stored in eeprom */ /* TODO: Code to implement. */ /* Until here it was code from HWdiscover procedure. */ /* Next comes code from mmuinit procedure of SCO BM driver which is * called from HWconfigure in the SCO driver. */ /* Initialise MMU, eventually switch on Busmaster Mode, initialise * multicast filter... */ hp100_mmuinit(dev); /* We don't turn the interrupts on here - this is done by start_interface. */ wait(); /* TODO: Do we really need this? */ /* Enable Hardware (e.g. unreset) */ hp100_cascade_reset(dev, 0); /* ------- initialisation complete ----------- */ /* Finally try to log in the Hub if there may be a VG connection. */ if ((lp->lan_type == HP100_LAN_100) || (lp->lan_type == HP100_LAN_ERR)) hp100_login_to_vg_hub(dev, 0); /* relogin */ } /* * mmuinit - Reinitialise Cascade MMU and MAC settings. * Note: Must already be in reset and leaves card in reset. */ static void hp100_mmuinit(struct net_device *dev) { int ioaddr = dev->base_addr; struct hp100_private *lp = netdev_priv(dev); int i; #ifdef HP100_DEBUG_B hp100_outw(0x4203, TRACE); printk("hp100: %s: mmuinit\n", dev->name); #endif #ifdef HP100_DEBUG if (0 != (hp100_inw(OPTION_LSW) & HP100_HW_RST)) { printk("hp100: %s: Not in reset when entering mmuinit. Fix me.\n", dev->name); return; } #endif /* Make sure IRQs are masked off and ack'ed. */ hp100_page(PERFORMANCE); hp100_outw(0xfefe, IRQ_MASK); /* mask off all ints */ hp100_outw(0xffff, IRQ_STATUS); /* ack IRQ */ /* * Enable Hardware * - Clear Debug En, Rx Hdr Pipe, EE En, I/O En, Fake Int and Intr En * - Set Tri-State Int, Bus Master Rd/Wr, and Mem Map Disable * - Clear Priority, Advance Pkt and Xmit Cmd */ hp100_outw(HP100_DEBUG_EN | HP100_RX_HDR | HP100_EE_EN | HP100_RESET_HB | HP100_IO_EN | HP100_FAKE_INT | HP100_INT_EN | HP100_RESET_LB, OPTION_LSW); hp100_outw(HP100_TRI_INT | HP100_SET_HB, OPTION_LSW); if (lp->mode == 1) { /* busmaster */ hp100_outw(HP100_BM_WRITE | HP100_BM_READ | HP100_MMAP_DIS | HP100_SET_HB, OPTION_LSW); } else if (lp->mode == 2) { /* memory mapped */ hp100_outw(HP100_BM_WRITE | HP100_BM_READ | HP100_RESET_HB, OPTION_LSW); hp100_outw(HP100_MMAP_DIS | HP100_RESET_HB, OPTION_LSW); hp100_outw(HP100_MEM_EN | HP100_SET_LB, OPTION_LSW); hp100_outw(HP100_IO_EN | HP100_SET_LB, OPTION_LSW); } else if (lp->mode == 3) { /* i/o mapped mode */ hp100_outw(HP100_MMAP_DIS | HP100_SET_HB | HP100_IO_EN | HP100_SET_LB, OPTION_LSW); } hp100_page(HW_MAP); hp100_outb(0, EARLYRXCFG); hp100_outw(0, EARLYTXCFG); /* * Enable Bus Master mode */ if (lp->mode == 1) { /* busmaster */ /* Experimental: Set some PCI configuration bits */ hp100_page(HW_MAP); hp100_andb(~HP100_PDL_USE3, MODECTRL1); /* BM engine read maximum */ hp100_andb(~HP100_TX_DUALQ, MODECTRL1); /* No Queue for Priority TX */ /* PCI Bus failures should result in a Misc. Interrupt */ hp100_orb(HP100_EN_BUS_FAIL, MODECTRL2); hp100_outw(HP100_BM_READ | HP100_BM_WRITE | HP100_SET_HB, OPTION_LSW); hp100_page(HW_MAP); /* Use Burst Mode and switch on PAGE_CK */ hp100_orb(HP100_BM_BURST_RD | HP100_BM_BURST_WR, BM); if ((lp->chip == HP100_CHIPID_RAINIER) || (lp->chip == HP100_CHIPID_SHASTA)) hp100_orb(HP100_BM_PAGE_CK, BM); hp100_orb(HP100_BM_MASTER, BM); } else { /* not busmaster */ hp100_page(HW_MAP); hp100_andb(~HP100_BM_MASTER, BM); } /* * Divide card memory into regions for Rx, Tx and, if non-ETR chip, PDLs */ hp100_page(MMU_CFG); if (lp->mode == 1) { /* only needed for Busmaster */ int xmit_stop, recv_stop; if ((lp->chip == HP100_CHIPID_RAINIER) || (lp->chip == HP100_CHIPID_SHASTA)) { int pdl_stop; /* * Each pdl is 508 bytes long. (63 frags * 4 bytes for address and * 4 bytes for header). We will leave NUM_RXPDLS * 508 (rounded * to the next higher 1k boundary) bytes for the rx-pdl's * Note: For non-etr chips the transmit stop register must be * programmed on a 1k boundary, i.e. bits 9:0 must be zero. */ pdl_stop = lp->memory_size; xmit_stop = (pdl_stop - 508 * (MAX_RX_PDL) - 16) & ~(0x03ff); recv_stop = (xmit_stop * (lp->rx_ratio) / 100) & ~(0x03ff); hp100_outw((pdl_stop >> 4) - 1, PDL_MEM_STOP); #ifdef HP100_DEBUG_BM printk("hp100: %s: PDL_STOP = 0x%x\n", dev->name, pdl_stop); #endif } else { /* ETR chip (Lassen) in busmaster mode */ xmit_stop = (lp->memory_size) - 1; recv_stop = ((lp->memory_size * lp->rx_ratio) / 100) & ~(0x03ff); } hp100_outw(xmit_stop >> 4, TX_MEM_STOP); hp100_outw(recv_stop >> 4, RX_MEM_STOP); #ifdef HP100_DEBUG_BM printk("hp100: %s: TX_STOP = 0x%x\n", dev->name, xmit_stop >> 4); printk("hp100: %s: RX_STOP = 0x%x\n", dev->name, recv_stop >> 4); #endif } else { /* Slave modes (memory mapped and programmed io) */ hp100_outw((((lp->memory_size * lp->rx_ratio) / 100) >> 4), RX_MEM_STOP); hp100_outw(((lp->memory_size - 1) >> 4), TX_MEM_STOP); #ifdef HP100_DEBUG printk("hp100: %s: TX_MEM_STOP: 0x%x\n", dev->name, hp100_inw(TX_MEM_STOP)); printk("hp100: %s: RX_MEM_STOP: 0x%x\n", dev->name, hp100_inw(RX_MEM_STOP)); #endif } /* Write MAC address into page 1 */ hp100_page(MAC_ADDRESS); for (i = 0; i < 6; i++) hp100_outb(dev->dev_addr[i], MAC_ADDR + i); /* Zero the multicast hash registers */ for (i = 0; i < 8; i++) hp100_outb(0x0, HASH_BYTE0 + i); /* Set up MAC defaults */ hp100_page(MAC_CTRL); /* Go to LAN Page and zero all filter bits */ /* Zero accept error, accept multicast, accept broadcast and accept */ /* all directed packet bits */ hp100_andb(~(HP100_RX_EN | HP100_TX_EN | HP100_ACC_ERRORED | HP100_ACC_MC | HP100_ACC_BC | HP100_ACC_PHY), MAC_CFG_1); hp100_outb(0x00, MAC_CFG_2); /* Zero the frame format bit. This works around a training bug in the */ /* new hubs. */ hp100_outb(0x00, VG_LAN_CFG_2); /* (use 802.3) */ if (lp->priority_tx) hp100_outb(HP100_PRIORITY_TX | HP100_SET_LB, OPTION_MSW); else hp100_outb(HP100_PRIORITY_TX | HP100_RESET_LB, OPTION_MSW); hp100_outb(HP100_ADV_NXT_PKT | HP100_TX_CMD | HP100_RESET_LB, OPTION_MSW); /* If busmaster, initialize the PDLs */ if (lp->mode == 1) hp100_init_pdls(dev); /* Go to performance page and initalize isr and imr registers */ hp100_page(PERFORMANCE); hp100_outw(0xfefe, IRQ_MASK); /* mask off all ints */ hp100_outw(0xffff, IRQ_STATUS); /* ack IRQ */ } /* * open/close functions */ static int hp100_open(struct net_device *dev) { struct hp100_private *lp = netdev_priv(dev); #ifdef HP100_DEBUG_B int ioaddr = dev->base_addr; #endif #ifdef HP100_DEBUG_B hp100_outw(0x4204, TRACE); printk("hp100: %s: open\n", dev->name); #endif /* New: if bus is PCI or EISA, interrupts might be shared interrupts */ if (request_irq(dev->irq, hp100_interrupt, lp->bus == HP100_BUS_PCI || lp->bus == HP100_BUS_EISA ? IRQF_SHARED : IRQF_DISABLED, "hp100", dev)) { printk("hp100: %s: unable to get IRQ %d\n", dev->name, dev->irq); return -EAGAIN; } dev->trans_start = jiffies; netif_start_queue(dev); lp->lan_type = hp100_sense_lan(dev); lp->mac1_mode = HP100_MAC1MODE3; lp->mac2_mode = HP100_MAC2MODE3; memset(&lp->hash_bytes, 0x00, 8); hp100_stop_interface(dev); hp100_hwinit(dev); hp100_start_interface(dev); /* sets mac modes, enables interrupts */ return 0; } /* The close function is called when the interface is to be brought down */ static int hp100_close(struct net_device *dev) { int ioaddr = dev->base_addr; struct hp100_private *lp = netdev_priv(dev); #ifdef HP100_DEBUG_B hp100_outw(0x4205, TRACE); printk("hp100: %s: close\n", dev->name); #endif hp100_page(PERFORMANCE); hp100_outw(0xfefe, IRQ_MASK); /* mask off all IRQs */ hp100_stop_interface(dev); if (lp->lan_type == HP100_LAN_100) lp->hub_status = hp100_login_to_vg_hub(dev, 0); netif_stop_queue(dev); free_irq(dev->irq, dev); #ifdef HP100_DEBUG printk("hp100: %s: close LSW = 0x%x\n", dev->name, hp100_inw(OPTION_LSW)); #endif return 0; } /* * Configure the PDL Rx rings and LAN */ static void hp100_init_pdls(struct net_device *dev) { struct hp100_private *lp = netdev_priv(dev); hp100_ring_t *ringptr; u_int *pageptr; /* Warning : increment by 4 - Jean II */ int i; #ifdef HP100_DEBUG_B int ioaddr = dev->base_addr; #endif #ifdef HP100_DEBUG_B hp100_outw(0x4206, TRACE); printk("hp100: %s: init pdls\n", dev->name); #endif if (0 == lp->page_vaddr_algn) printk("hp100: %s: Warning: lp->page_vaddr_algn not initialised!\n", dev->name); else { /* pageptr shall point into the DMA accessible memory region */ /* we use this pointer to status the upper limit of allocated */ /* memory in the allocated page. */ /* note: align the pointers to the pci cache line size */ memset(lp->page_vaddr_algn, 0, MAX_RINGSIZE); /* Zero Rx/Tx ring page */ pageptr = lp->page_vaddr_algn; lp->rxrcommit = 0; ringptr = lp->rxrhead = lp->rxrtail = &(lp->rxring[0]); /* Initialise Rx Ring */ for (i = MAX_RX_PDL - 1; i >= 0; i--) { lp->rxring[i].next = ringptr; ringptr = &(lp->rxring[i]); pageptr += hp100_init_rxpdl(dev, ringptr, pageptr); } /* Initialise Tx Ring */ lp->txrcommit = 0; ringptr = lp->txrhead = lp->txrtail = &(lp->txring[0]); for (i = MAX_TX_PDL - 1; i >= 0; i--) { lp->txring[i].next = ringptr; ringptr = &(lp->txring[i]); pageptr += hp100_init_txpdl(dev, ringptr, pageptr); } } } /* These functions "format" the entries in the pdl structure */ /* They return how much memory the fragments need. */ static int hp100_init_rxpdl(struct net_device *dev, register hp100_ring_t * ringptr, register u32 * pdlptr) { /* pdlptr is starting address for this pdl */ if (0 != (((unsigned long) pdlptr) & 0xf)) printk("hp100: %s: Init rxpdl: Unaligned pdlptr 0x%lx.\n", dev->name, (unsigned long) pdlptr); ringptr->pdl = pdlptr + 1; ringptr->pdl_paddr = virt_to_whatever(dev, pdlptr + 1); ringptr->skb = (void *) NULL; /* * Write address and length of first PDL Fragment (which is used for * storing the RX-Header * We use the 4 bytes _before_ the PDH in the pdl memory area to * store this information. (PDH is at offset 0x04) */ /* Note that pdlptr+1 and not pdlptr is the pointer to the PDH */ *(pdlptr + 2) = (u_int) virt_to_whatever(dev, pdlptr); /* Address Frag 1 */ *(pdlptr + 3) = 4; /* Length Frag 1 */ return ((((MAX_RX_FRAG * 2 + 2) + 3) / 4) * 4); } static int hp100_init_txpdl(struct net_device *dev, register hp100_ring_t * ringptr, register u32 * pdlptr) { if (0 != (((unsigned long) pdlptr) & 0xf)) printk("hp100: %s: Init txpdl: Unaligned pdlptr 0x%lx.\n", dev->name, (unsigned long) pdlptr); ringptr->pdl = pdlptr; /* +1; */ ringptr->pdl_paddr = virt_to_whatever(dev, pdlptr); /* +1 */ ringptr->skb = (void *) NULL; return ((((MAX_TX_FRAG * 2 + 2) + 3) / 4) * 4); } /* * hp100_build_rx_pdl allocates an skb_buff of maximum size plus two bytes * for possible odd word alignment rounding up to next dword and set PDL * address for fragment#2 * Returns: 0 if unable to allocate skb_buff * 1 if successful */ static int hp100_build_rx_pdl(hp100_ring_t * ringptr, struct net_device *dev) { #ifdef HP100_DEBUG_B int ioaddr = dev->base_addr; #endif #ifdef HP100_DEBUG_BM u_int *p; #endif #ifdef HP100_DEBUG_B hp100_outw(0x4207, TRACE); printk("hp100: %s: build rx pdl\n", dev->name); #endif /* Allocate skb buffer of maximum size */ /* Note: This depends on the alloc_skb functions allocating more * space than requested, i.e. aligning to 16bytes */ ringptr->skb = dev_alloc_skb(((MAX_ETHER_SIZE + 2 + 3) / 4) * 4); if (NULL != ringptr->skb) { /* * Reserve 2 bytes at the head of the buffer to land the IP header * on a long word boundary (According to the Network Driver section * in the Linux KHG, this should help to increase performance.) */ skb_reserve(ringptr->skb, 2); ringptr->skb->dev = dev; ringptr->skb->data = (u_char *) skb_put(ringptr->skb, MAX_ETHER_SIZE); /* ringptr->pdl points to the beginning of the PDL, i.e. the PDH */ /* Note: 1st Fragment is used for the 4 byte packet status * (receive header). Its PDL entries are set up by init_rxpdl. So * here we only have to set up the PDL fragment entries for the data * part. Those 4 bytes will be stored in the DMA memory region * directly before the PDL. */ #ifdef HP100_DEBUG_BM printk("hp100: %s: build_rx_pdl: PDH@0x%x, skb->data (len %d) at 0x%x\n", dev->name, (u_int) ringptr->pdl, ((MAX_ETHER_SIZE + 2 + 3) / 4) * 4, (unsigned int) ringptr->skb->data); #endif /* Conversion to new PCI API : map skbuf data to PCI bus. * Doc says it's OK for EISA as well - Jean II */ ringptr->pdl[0] = 0x00020000; /* Write PDH */ ringptr->pdl[3] = pdl_map_data(netdev_priv(dev), ringptr->skb->data); ringptr->pdl[4] = MAX_ETHER_SIZE; /* Length of Data */ #ifdef HP100_DEBUG_BM for (p = (ringptr->pdl); p < (ringptr->pdl + 5); p++) printk("hp100: %s: Adr 0x%.8x = 0x%.8x\n", dev->name, (u_int) p, (u_int) * p); #endif return (1); } /* else: */ /* alloc_skb failed (no memory) -> still can receive the header * fragment into PDL memory. make PDL safe by clearing msgptr and * making the PDL only 1 fragment (i.e. the 4 byte packet status) */ #ifdef HP100_DEBUG_BM printk("hp100: %s: build_rx_pdl: PDH@0x%x, No space for skb.\n", dev->name, (u_int) ringptr->pdl); #endif ringptr->pdl[0] = 0x00010000; /* PDH: Count=1 Fragment */ return (0); } /* * hp100_rxfill - attempt to fill the Rx Ring will empty skb's * * Makes assumption that skb's are always contiguous memory areas and * therefore PDLs contain only 2 physical fragments. * - While the number of Rx PDLs with buffers is less than maximum * a. Get a maximum packet size skb * b. Put the physical address of the buffer into the PDL. * c. Output physical address of PDL to adapter. */ static void hp100_rxfill(struct net_device *dev) { int ioaddr = dev->base_addr; struct hp100_private *lp = netdev_priv(dev); hp100_ring_t *ringptr; #ifdef HP100_DEBUG_B hp100_outw(0x4208, TRACE); printk("hp100: %s: rxfill\n", dev->name); #endif hp100_page(PERFORMANCE); while (lp->rxrcommit < MAX_RX_PDL) { /* ** Attempt to get a buffer and build a Rx PDL. */ ringptr = lp->rxrtail; if (0 == hp100_build_rx_pdl(ringptr, dev)) { return; /* None available, return */ } /* Hand this PDL over to the card */ /* Note: This needs performance page selected! */ #ifdef HP100_DEBUG_BM printk("hp100: %s: rxfill: Hand to card: pdl #%d @0x%x phys:0x%x, buffer: 0x%x\n", dev->name, lp->rxrcommit, (u_int) ringptr->pdl, (u_int) ringptr->pdl_paddr, (u_int) ringptr->pdl[3]); #endif hp100_outl((u32) ringptr->pdl_paddr, RX_PDA); lp->rxrcommit += 1; lp->rxrtail = ringptr->next; } } /* * BM_shutdown - shutdown bus mastering and leave chip in reset state */ static void hp100_BM_shutdown(struct net_device *dev) { int ioaddr = dev->base_addr; struct hp100_private *lp = netdev_priv(dev); unsigned long time; #ifdef HP100_DEBUG_B hp100_outw(0x4209, TRACE); printk("hp100: %s: bm shutdown\n", dev->name); #endif hp100_page(PERFORMANCE); hp100_outw(0xfefe, IRQ_MASK); /* mask off all ints */ hp100_outw(0xffff, IRQ_STATUS); /* Ack all ints */ /* Ensure Interrupts are off */ hp100_outw(HP100_INT_EN | HP100_RESET_LB, OPTION_LSW); /* Disable all MAC activity */ hp100_page(MAC_CTRL); hp100_andb(~(HP100_RX_EN | HP100_TX_EN), MAC_CFG_1); /* stop rx/tx */ /* If cascade MMU is not already in reset */ if (0 != (hp100_inw(OPTION_LSW) & HP100_HW_RST)) { /* Wait 1.3ms (10Mb max packet time) to ensure MAC is idle so * MMU pointers will not be reset out from underneath */ hp100_page(MAC_CTRL); for (time = 0; time < 5000; time++) { if ((hp100_inb(MAC_CFG_1) & (HP100_TX_IDLE | HP100_RX_IDLE)) == (HP100_TX_IDLE | HP100_RX_IDLE)) break; } /* Shutdown algorithm depends on the generation of Cascade */ if (lp->chip == HP100_CHIPID_LASSEN) { /* ETR shutdown/reset */ /* Disable Busmaster mode and wait for bit to go to zero. */ hp100_page(HW_MAP); hp100_andb(~HP100_BM_MASTER, BM); /* 100 ms timeout */ for (time = 0; time < 32000; time++) { if (0 == (hp100_inb(BM) & HP100_BM_MASTER)) break; } } else { /* Shasta or Rainier Shutdown/Reset */ /* To ensure all bus master inloading activity has ceased, * wait for no Rx PDAs or no Rx packets on card. */ hp100_page(PERFORMANCE); /* 100 ms timeout */ for (time = 0; time < 10000; time++) { /* RX_PDL: PDLs not executed. */ /* RX_PKT_CNT: RX'd packets on card. */ if ((hp100_inb(RX_PDL) == 0) && (hp100_inb(RX_PKT_CNT) == 0)) break; } if (time >= 10000) printk("hp100: %s: BM shutdown error.\n", dev->name); /* To ensure all bus master outloading activity has ceased, * wait until the Tx PDA count goes to zero or no more Tx space * available in the Tx region of the card. */ /* 100 ms timeout */ for (time = 0; time < 10000; time++) { if ((0 == hp100_inb(TX_PKT_CNT)) && (0 != (hp100_inb(TX_MEM_FREE) & HP100_AUTO_COMPARE))) break; } /* Disable Busmaster mode */ hp100_page(HW_MAP); hp100_andb(~HP100_BM_MASTER, BM); } /* end of shutdown procedure for non-etr parts */ hp100_cascade_reset(dev, 1); } hp100_page(PERFORMANCE); /* hp100_outw( HP100_BM_READ | HP100_BM_WRITE | HP100_RESET_HB, OPTION_LSW ); */ /* Busmaster mode should be shut down now. */ } static int hp100_check_lan(struct net_device *dev) { struct hp100_private *lp = netdev_priv(dev); if (lp->lan_type < 0) { /* no LAN type detected yet? */ hp100_stop_interface(dev); if ((lp->lan_type = hp100_sense_lan(dev)) < 0) { printk("hp100: %s: no connection found - check wire\n", dev->name); hp100_start_interface(dev); /* 10Mb/s RX packets maybe handled */ return -EIO; } if (lp->lan_type == HP100_LAN_100) lp->hub_status = hp100_login_to_vg_hub(dev, 0); /* relogin */ hp100_start_interface(dev); } return 0; } /* * transmit functions */ /* tx function for busmaster mode */ static int hp100_start_xmit_bm(struct sk_buff *skb, struct net_device *dev) { unsigned long flags; int i, ok_flag; int ioaddr = dev->base_addr; struct hp100_private *lp = netdev_priv(dev); hp100_ring_t *ringptr; #ifdef HP100_DEBUG_B hp100_outw(0x4210, TRACE); printk("hp100: %s: start_xmit_bm\n", dev->name); #endif if (skb == NULL) { return 0; } if (skb->len <= 0) return 0; if (lp->chip == HP100_CHIPID_SHASTA && skb_padto(skb, ETH_ZLEN)) return 0; /* Get Tx ring tail pointer */ if (lp->txrtail->next == lp->txrhead) { /* No memory. */ #ifdef HP100_DEBUG printk("hp100: %s: start_xmit_bm: No TX PDL available.\n", dev->name); #endif /* not waited long enough since last tx? */ if (time_before(jiffies, dev->trans_start + HZ)) return -EAGAIN; if (hp100_check_lan(dev)) return -EIO; if (lp->lan_type == HP100_LAN_100 && lp->hub_status < 0) { /* we have a 100Mb/s adapter but it isn't connected to hub */ printk("hp100: %s: login to 100Mb/s hub retry\n", dev->name); hp100_stop_interface(dev); lp->hub_status = hp100_login_to_vg_hub(dev, 0); hp100_start_interface(dev); } else { spin_lock_irqsave(&lp->lock, flags); hp100_ints_off(); /* Useful ? Jean II */ i = hp100_sense_lan(dev); hp100_ints_on(); spin_unlock_irqrestore(&lp->lock, flags); if (i == HP100_LAN_ERR) printk("hp100: %s: link down detected\n", dev->name); else if (lp->lan_type != i) { /* cable change! */ /* it's very hard - all network settings must be changed!!! */ printk("hp100: %s: cable change 10Mb/s <-> 100Mb/s detected\n", dev->name); lp->lan_type = i; hp100_stop_interface(dev); if (lp->lan_type == HP100_LAN_100) lp->hub_status = hp100_login_to_vg_hub(dev, 0); hp100_start_interface(dev); } else { printk("hp100: %s: interface reset\n", dev->name); hp100_stop_interface(dev); if (lp->lan_type == HP100_LAN_100) lp->hub_status = hp100_login_to_vg_hub(dev, 0); hp100_start_interface(dev); } } dev->trans_start = jiffies; return -EAGAIN; } /* * we have to turn int's off before modifying this, otherwise * a tx_pdl_cleanup could occur at the same time */ spin_lock_irqsave(&lp->lock, flags); ringptr = lp->txrtail; lp->txrtail = ringptr->next; /* Check whether packet has minimal packet size */ ok_flag = skb->len >= HP100_MIN_PACKET_SIZE; i = ok_flag ? skb->len : HP100_MIN_PACKET_SIZE; ringptr->skb = skb; ringptr->pdl[0] = ((1 << 16) | i); /* PDH: 1 Fragment & length */ if (lp->chip == HP100_CHIPID_SHASTA) { /* TODO:Could someone who has the EISA card please check if this works? */ ringptr->pdl[2] = i; } else { /* Lassen */ /* In the PDL, don't use the padded size but the real packet size: */ ringptr->pdl[2] = skb->len; /* 1st Frag: Length of frag */ } /* Conversion to new PCI API : map skbuf data to PCI bus. * Doc says it's OK for EISA as well - Jean II */ ringptr->pdl[1] = ((u32) pci_map_single(lp->pci_dev, skb->data, ringptr->pdl[2], PCI_DMA_TODEVICE)); /* 1st Frag: Adr. of data */ /* Hand this PDL to the card. */ hp100_outl(ringptr->pdl_paddr, TX_PDA_L); /* Low Prio. Queue */ lp->txrcommit++; spin_unlock_irqrestore(&lp->lock, flags); /* Update statistics */ lp->stats.tx_packets++; lp->stats.tx_bytes += skb->len; dev->trans_start = jiffies; return 0; } /* clean_txring checks if packets have been sent by the card by reading * the TX_PDL register from the performance page and comparing it to the * number of commited packets. It then frees the skb's of the packets that * obviously have been sent to the network. * * Needs the PERFORMANCE page selected. */ static void hp100_clean_txring(struct net_device *dev) { struct hp100_private *lp = netdev_priv(dev); int ioaddr = dev->base_addr; int donecount; #ifdef HP100_DEBUG_B hp100_outw(0x4211, TRACE); printk("hp100: %s: clean txring\n", dev->name); #endif /* How many PDLs have been transmitted? */ donecount = (lp->txrcommit) - hp100_inb(TX_PDL); #ifdef HP100_DEBUG if (donecount > MAX_TX_PDL) printk("hp100: %s: Warning: More PDLs transmitted than commited to card???\n", dev->name); #endif for (; 0 != donecount; donecount--) { #ifdef HP100_DEBUG_BM printk("hp100: %s: Free skb: data @0x%.8x txrcommit=0x%x TXPDL=0x%x, done=0x%x\n", dev->name, (u_int) lp->txrhead->skb->data, lp->txrcommit, hp100_inb(TX_PDL), donecount); #endif /* Conversion to new PCI API : NOP */ pci_unmap_single(lp->pci_dev, (dma_addr_t) lp->txrhead->pdl[1], lp->txrhead->pdl[2], PCI_DMA_TODEVICE); dev_kfree_skb_any(lp->txrhead->skb); lp->txrhead->skb = (void *) NULL; lp->txrhead = lp->txrhead->next; lp->txrcommit--; } } /* tx function for slave modes */ static int hp100_start_xmit(struct sk_buff *skb, struct net_device *dev) { unsigned long flags; int i, ok_flag; int ioaddr = dev->base_addr; u_short val; struct hp100_private *lp = netdev_priv(dev); #ifdef HP100_DEBUG_B hp100_outw(0x4212, TRACE); printk("hp100: %s: start_xmit\n", dev->name); #endif if (skb == NULL) { return 0; } if (skb->len <= 0) return 0; if (hp100_check_lan(dev)) return -EIO; /* If there is not enough free memory on the card... */ i = hp100_inl(TX_MEM_FREE) & 0x7fffffff; if (!(((i / 2) - 539) > (skb->len + 16) && (hp100_inb(TX_PKT_CNT) < 255))) { #ifdef HP100_DEBUG printk("hp100: %s: start_xmit: tx free mem = 0x%x\n", dev->name, i); #endif /* not waited long enough since last failed tx try? */ if (time_before(jiffies, dev->trans_start + HZ)) { #ifdef HP100_DEBUG printk("hp100: %s: trans_start timing problem\n", dev->name); #endif return -EAGAIN; } if (lp->lan_type == HP100_LAN_100 && lp->hub_status < 0) { /* we have a 100Mb/s adapter but it isn't connected to hub */ printk("hp100: %s: login to 100Mb/s hub retry\n", dev->name); hp100_stop_interface(dev); lp->hub_status = hp100_login_to_vg_hub(dev, 0); hp100_start_interface(dev); } else { spin_lock_irqsave(&lp->lock, flags); hp100_ints_off(); /* Useful ? Jean II */ i = hp100_sense_lan(dev); hp100_ints_on(); spin_unlock_irqrestore(&lp->lock, flags); if (i == HP100_LAN_ERR) printk("hp100: %s: link down detected\n", dev->name); else if (lp->lan_type != i) { /* cable change! */ /* it's very hard - all network setting must be changed!!! */ printk("hp100: %s: cable change 10Mb/s <-> 100Mb/s detected\n", dev->name); lp->lan_type = i; hp100_stop_interface(dev); if (lp->lan_type == HP100_LAN_100) lp->hub_status = hp100_login_to_vg_hub(dev, 0); hp100_start_interface(dev); } else { printk("hp100: %s: interface reset\n", dev->name); hp100_stop_interface(dev); if (lp->lan_type == HP100_LAN_100) lp->hub_status = hp100_login_to_vg_hub(dev, 0); hp100_start_interface(dev); mdelay(1); } } dev->trans_start = jiffies; return -EAGAIN; } for (i = 0; i < 6000 && (hp100_inb(OPTION_MSW) & HP100_TX_CMD); i++) { #ifdef HP100_DEBUG_TX printk("hp100: %s: start_xmit: busy\n", dev->name); #endif } spin_lock_irqsave(&lp->lock, flags); hp100_ints_off(); val = hp100_inw(IRQ_STATUS); /* Ack / clear the interrupt TX_COMPLETE interrupt - this interrupt is set * when the current packet being transmitted on the wire is completed. */ hp100_outw(HP100_TX_COMPLETE, IRQ_STATUS); #ifdef HP100_DEBUG_TX printk("hp100: %s: start_xmit: irq_status=0x%.4x, irqmask=0x%.4x, len=%d\n", dev->name, val, hp100_inw(IRQ_MASK), (int) skb->len); #endif ok_flag = skb->len >= HP100_MIN_PACKET_SIZE; i = ok_flag ? skb->len : HP100_MIN_PACKET_SIZE; hp100_outw(i, DATA32); /* tell card the total packet length */ hp100_outw(i, FRAGMENT_LEN); /* and first/only fragment length */ if (lp->mode == 2) { /* memory mapped */ /* Note: The J2585B needs alignment to 32bits here! */ memcpy_toio(lp->mem_ptr_virt, skb->data, (skb->len + 3) & ~3); if (!ok_flag) memset_io(lp->mem_ptr_virt, 0, HP100_MIN_PACKET_SIZE - skb->len); } else { /* programmed i/o */ outsl(ioaddr + HP100_REG_DATA32, skb->data, (skb->len + 3) >> 2); if (!ok_flag) for (i = (skb->len + 3) & ~3; i < HP100_MIN_PACKET_SIZE; i += 4) hp100_outl(0, DATA32); } hp100_outb(HP100_TX_CMD | HP100_SET_LB, OPTION_MSW); /* send packet */ lp->stats.tx_packets++; lp->stats.tx_bytes += skb->len; dev->trans_start = jiffies; hp100_ints_on(); spin_unlock_irqrestore(&lp->lock, flags); dev_kfree_skb_any(skb); #ifdef HP100_DEBUG_TX printk("hp100: %s: start_xmit: end\n", dev->name); #endif return 0; } /* * Receive Function (Non-Busmaster mode) * Called when an "Receive Packet" interrupt occurs, i.e. the receive * packet counter is non-zero. * For non-busmaster, this function does the whole work of transfering * the packet to the host memory and then up to higher layers via skb * and netif_rx. */ static void hp100_rx(struct net_device *dev) { int packets, pkt_len; int ioaddr = dev->base_addr; struct hp100_private *lp = netdev_priv(dev); u_int header; struct sk_buff *skb; #ifdef DEBUG_B hp100_outw(0x4213, TRACE); printk("hp100: %s: rx\n", dev->name); #endif /* First get indication of received lan packet */ /* RX_PKT_CND indicates the number of packets which have been fully */ /* received onto the card but have not been fully transferred of the card */ packets = hp100_inb(RX_PKT_CNT); #ifdef HP100_DEBUG_RX if (packets > 1) printk("hp100: %s: rx: waiting packets = %d\n", dev->name, packets); #endif while (packets-- > 0) { /* If ADV_NXT_PKT is still set, we have to wait until the card has */ /* really advanced to the next packet. */ for (pkt_len = 0; pkt_len < 6000 && (hp100_inb(OPTION_MSW) & HP100_ADV_NXT_PKT); pkt_len++) { #ifdef HP100_DEBUG_RX printk ("hp100: %s: rx: busy, remaining packets = %d\n", dev->name, packets); #endif } /* First we get the header, which contains information about the */ /* actual length of the received packet. */ if (lp->mode == 2) { /* memory mapped mode */ header = readl(lp->mem_ptr_virt); } else /* programmed i/o */ header = hp100_inl(DATA32); pkt_len = ((header & HP100_PKT_LEN_MASK) + 3) & ~3; #ifdef HP100_DEBUG_RX printk("hp100: %s: rx: new packet - length=%d, errors=0x%x, dest=0x%x\n", dev->name, header & HP100_PKT_LEN_MASK, (header >> 16) & 0xfff8, (header >> 16) & 7); #endif /* Now we allocate the skb and transfer the data into it. */ skb = dev_alloc_skb(pkt_len+2); if (skb == NULL) { /* Not enough memory->drop packet */ #ifdef HP100_DEBUG printk("hp100: %s: rx: couldn't allocate a sk_buff of size %d\n", dev->name, pkt_len); #endif lp->stats.rx_dropped++; } else { /* skb successfully allocated */ u_char *ptr; skb_reserve(skb,2); /* ptr to start of the sk_buff data area */ skb_put(skb, pkt_len); ptr = skb->data; /* Now transfer the data from the card into that area */ if (lp->mode == 2) memcpy_fromio(ptr, lp->mem_ptr_virt,pkt_len); else /* io mapped */ insl(ioaddr + HP100_REG_DATA32, ptr, pkt_len >> 2); skb->protocol = eth_type_trans(skb, dev); #ifdef HP100_DEBUG_RX printk("hp100: %s: rx: %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x\n", dev->name, ptr[0], ptr[1], ptr[2], ptr[3], ptr[4], ptr[5], ptr[6], ptr[7], ptr[8], ptr[9], ptr[10], ptr[11]); #endif netif_rx(skb); dev->last_rx = jiffies; lp->stats.rx_packets++; lp->stats.rx_bytes += pkt_len; } /* Indicate the card that we have got the packet */ hp100_outb(HP100_ADV_NXT_PKT | HP100_SET_LB, OPTION_MSW); switch (header & 0x00070000) { case (HP100_MULTI_ADDR_HASH << 16): case (HP100_MULTI_ADDR_NO_HASH << 16): lp->stats.multicast++; break; } } /* end of while(there are packets) loop */ #ifdef HP100_DEBUG_RX printk("hp100_rx: %s: end\n", dev->name); #endif } /* * Receive Function for Busmaster Mode */ static void hp100_rx_bm(struct net_device *dev) { int ioaddr = dev->base_addr; struct hp100_private *lp = netdev_priv(dev); hp100_ring_t *ptr; u_int header; int pkt_len; #ifdef HP100_DEBUG_B hp100_outw(0x4214, TRACE); printk("hp100: %s: rx_bm\n", dev->name); #endif #ifdef HP100_DEBUG if (0 == lp->rxrcommit) { printk("hp100: %s: rx_bm called although no PDLs were committed to adapter?\n", dev->name); return; } else /* RX_PKT_CNT states how many PDLs are currently formatted and available to * the cards BM engine */ if ((hp100_inw(RX_PKT_CNT) & 0x00ff) >= lp->rxrcommit) { printk("hp100: %s: More packets received than commited? RX_PKT_CNT=0x%x, commit=0x%x\n", dev->name, hp100_inw(RX_PKT_CNT) & 0x00ff, lp->rxrcommit); return; } #endif