forked from torvalds/linux
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path82596.c
1632 lines (1358 loc) · 40.6 KB
/
82596.c
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
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* 82596.c: A generic 82596 ethernet driver for linux. */
/*
Based on Apricot.c
Written 1994 by Mark Evans.
This driver is for the Apricot 82596 bus-master interface
Modularised 12/94 Mark Evans
Modified to support the 82596 ethernet chips on 680x0 VME boards.
by Richard Hirst <[email protected]>
Renamed to be 82596.c
980825: Changed to receive directly in to sk_buffs which are
allocated at open() time. Eliminates copy on incoming frames
(small ones are still copied). Shared data now held in a
non-cached page, so we can run on 68060 in copyback mode.
TBD:
* look at deferring rx frames rather than discarding (as per tulip)
* handle tx ring full as per tulip
* performance test to tune rx_copybreak
Most of my modifications relate to the braindead big-endian
implementation by Intel. When the i596 is operating in
'big-endian' mode, it thinks a 32 bit value of 0x12345678
should be stored as 0x56781234. This is a real pain, when
you have linked lists which are shared by the 680x0 and the
i596.
Driver skeleton
Written 1993 by Donald Becker.
Copyright 1993 United States Government as represented by the Director,
National Security Agency. This software may only be used and distributed
according to the terms of the GNU General Public License as modified by SRC,
incorporated herein by reference.
The author may be reached as [email protected], or C/O
Scyld Computing Corporation, 410 Severn Ave., Suite 210, Annapolis MD 21403
*/
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/string.h>
#include <linux/errno.h>
#include <linux/ioport.h>
#include <linux/interrupt.h>
#include <linux/delay.h>
#include <linux/netdevice.h>
#include <linux/etherdevice.h>
#include <linux/skbuff.h>
#include <linux/init.h>
#include <linux/bitops.h>
#include <linux/gfp.h>
#include <asm/io.h>
#include <asm/dma.h>
#include <asm/pgtable.h>
#include <asm/cacheflush.h>
static char version[] __initdata =
"82596.c $Revision: 1.5 $\n";
#define DRV_NAME "82596"
/* DEBUG flags
*/
#define DEB_INIT 0x0001
#define DEB_PROBE 0x0002
#define DEB_SERIOUS 0x0004
#define DEB_ERRORS 0x0008
#define DEB_MULTI 0x0010
#define DEB_TDR 0x0020
#define DEB_OPEN 0x0040
#define DEB_RESET 0x0080
#define DEB_ADDCMD 0x0100
#define DEB_STATUS 0x0200
#define DEB_STARTTX 0x0400
#define DEB_RXADDR 0x0800
#define DEB_TXADDR 0x1000
#define DEB_RXFRAME 0x2000
#define DEB_INTS 0x4000
#define DEB_STRUCT 0x8000
#define DEB_ANY 0xffff
#define DEB(x,y) if (i596_debug & (x)) y
#if defined(CONFIG_MVME16x_NET) || defined(CONFIG_MVME16x_NET_MODULE)
#define ENABLE_MVME16x_NET
#endif
#if defined(CONFIG_BVME6000_NET) || defined(CONFIG_BVME6000_NET_MODULE)
#define ENABLE_BVME6000_NET
#endif
#if defined(CONFIG_APRICOT) || defined(CONFIG_APRICOT_MODULE)
#define ENABLE_APRICOT
#endif
#ifdef ENABLE_MVME16x_NET
#include <asm/mvme16xhw.h>
#endif
#ifdef ENABLE_BVME6000_NET
#include <asm/bvme6000hw.h>
#endif
/*
* Define various macros for Channel Attention, word swapping etc., dependent
* on architecture. MVME and BVME are 680x0 based, otherwise it is Intel.
*/
#ifdef __mc68000__
#define WSWAPrfd(x) ((struct i596_rfd *) (((u32)(x)<<16) | ((((u32)(x)))>>16)))
#define WSWAPrbd(x) ((struct i596_rbd *) (((u32)(x)<<16) | ((((u32)(x)))>>16)))
#define WSWAPiscp(x) ((struct i596_iscp *)(((u32)(x)<<16) | ((((u32)(x)))>>16)))
#define WSWAPscb(x) ((struct i596_scb *) (((u32)(x)<<16) | ((((u32)(x)))>>16)))
#define WSWAPcmd(x) ((struct i596_cmd *) (((u32)(x)<<16) | ((((u32)(x)))>>16)))
#define WSWAPtbd(x) ((struct i596_tbd *) (((u32)(x)<<16) | ((((u32)(x)))>>16)))
#define WSWAPchar(x) ((char *) (((u32)(x)<<16) | ((((u32)(x)))>>16)))
#define ISCP_BUSY 0x00010000
#define MACH_IS_APRICOT 0
#else
#define WSWAPrfd(x) ((struct i596_rfd *)((long)x))
#define WSWAPrbd(x) ((struct i596_rbd *)((long)x))
#define WSWAPiscp(x) ((struct i596_iscp *)((long)x))
#define WSWAPscb(x) ((struct i596_scb *)((long)x))
#define WSWAPcmd(x) ((struct i596_cmd *)((long)x))
#define WSWAPtbd(x) ((struct i596_tbd *)((long)x))
#define WSWAPchar(x) ((char *)((long)x))
#define ISCP_BUSY 0x0001
#define MACH_IS_APRICOT 1
#endif
/*
* The MPU_PORT command allows direct access to the 82596. With PORT access
* the following commands are available (p5-18). The 32-bit port command
* must be word-swapped with the most significant word written first.
* This only applies to VME boards.
*/
#define PORT_RESET 0x00 /* reset 82596 */
#define PORT_SELFTEST 0x01 /* selftest */
#define PORT_ALTSCP 0x02 /* alternate SCB address */
#define PORT_ALTDUMP 0x03 /* Alternate DUMP address */
static int i596_debug = (DEB_SERIOUS|DEB_PROBE);
MODULE_AUTHOR("Richard Hirst");
MODULE_DESCRIPTION("i82596 driver");
MODULE_LICENSE("GPL");
module_param(i596_debug, int, 0);
MODULE_PARM_DESC(i596_debug, "i82596 debug mask");
/* Copy frames shorter than rx_copybreak, otherwise pass on up in
* a full sized sk_buff. Value of 100 stolen from tulip.c (!alpha).
*/
static int rx_copybreak = 100;
#define PKT_BUF_SZ 1536
#define MAX_MC_CNT 64
#define I596_TOTAL_SIZE 17
#define I596_NULL ((void *)0xffffffff)
#define CMD_EOL 0x8000 /* The last command of the list, stop. */
#define CMD_SUSP 0x4000 /* Suspend after doing cmd. */
#define CMD_INTR 0x2000 /* Interrupt after doing cmd. */
#define CMD_FLEX 0x0008 /* Enable flexible memory model */
enum commands {
CmdNOp = 0, CmdSASetup = 1, CmdConfigure = 2, CmdMulticastList = 3,
CmdTx = 4, CmdTDR = 5, CmdDump = 6, CmdDiagnose = 7
};
#define STAT_C 0x8000 /* Set to 0 after execution */
#define STAT_B 0x4000 /* Command being executed */
#define STAT_OK 0x2000 /* Command executed ok */
#define STAT_A 0x1000 /* Command aborted */
#define CUC_START 0x0100
#define CUC_RESUME 0x0200
#define CUC_SUSPEND 0x0300
#define CUC_ABORT 0x0400
#define RX_START 0x0010
#define RX_RESUME 0x0020
#define RX_SUSPEND 0x0030
#define RX_ABORT 0x0040
#define TX_TIMEOUT 5
struct i596_reg {
unsigned short porthi;
unsigned short portlo;
unsigned long ca;
};
#define EOF 0x8000
#define SIZE_MASK 0x3fff
struct i596_tbd {
unsigned short size;
unsigned short pad;
struct i596_tbd *next;
char *data;
};
/* The command structure has two 'next' pointers; v_next is the address of
* the next command as seen by the CPU, b_next is the address of the next
* command as seen by the 82596. The b_next pointer, as used by the 82596
* always references the status field of the next command, rather than the
* v_next field, because the 82596 is unaware of v_next. It may seem more
* logical to put v_next at the end of the structure, but we cannot do that
* because the 82596 expects other fields to be there, depending on command
* type.
*/
struct i596_cmd {
struct i596_cmd *v_next; /* Address from CPUs viewpoint */
unsigned short status;
unsigned short command;
struct i596_cmd *b_next; /* Address from i596 viewpoint */
};
struct tx_cmd {
struct i596_cmd cmd;
struct i596_tbd *tbd;
unsigned short size;
unsigned short pad;
struct sk_buff *skb; /* So we can free it after tx */
};
struct tdr_cmd {
struct i596_cmd cmd;
unsigned short status;
unsigned short pad;
};
struct mc_cmd {
struct i596_cmd cmd;
short mc_cnt;
char mc_addrs[MAX_MC_CNT*6];
};
struct sa_cmd {
struct i596_cmd cmd;
char eth_addr[8];
};
struct cf_cmd {
struct i596_cmd cmd;
char i596_config[16];
};
struct i596_rfd {
unsigned short stat;
unsigned short cmd;
struct i596_rfd *b_next; /* Address from i596 viewpoint */
struct i596_rbd *rbd;
unsigned short count;
unsigned short size;
struct i596_rfd *v_next; /* Address from CPUs viewpoint */
struct i596_rfd *v_prev;
};
struct i596_rbd {
unsigned short count;
unsigned short zero1;
struct i596_rbd *b_next;
unsigned char *b_data; /* Address from i596 viewpoint */
unsigned short size;
unsigned short zero2;
struct sk_buff *skb;
struct i596_rbd *v_next;
struct i596_rbd *b_addr; /* This rbd addr from i596 view */
unsigned char *v_data; /* Address from CPUs viewpoint */
};
#define TX_RING_SIZE 64
#define RX_RING_SIZE 16
struct i596_scb {
unsigned short status;
unsigned short command;
struct i596_cmd *cmd;
struct i596_rfd *rfd;
unsigned long crc_err;
unsigned long align_err;
unsigned long resource_err;
unsigned long over_err;
unsigned long rcvdt_err;
unsigned long short_err;
unsigned short t_on;
unsigned short t_off;
};
struct i596_iscp {
unsigned long stat;
struct i596_scb *scb;
};
struct i596_scp {
unsigned long sysbus;
unsigned long pad;
struct i596_iscp *iscp;
};
struct i596_private {
volatile struct i596_scp scp;
volatile struct i596_iscp iscp;
volatile struct i596_scb scb;
struct sa_cmd sa_cmd;
struct cf_cmd cf_cmd;
struct tdr_cmd tdr_cmd;
struct mc_cmd mc_cmd;
unsigned long stat;
int last_restart __attribute__((aligned(4)));
struct i596_rfd *rfd_head;
struct i596_rbd *rbd_head;
struct i596_cmd *cmd_tail;
struct i596_cmd *cmd_head;
int cmd_backlog;
unsigned long last_cmd;
struct i596_rfd rfds[RX_RING_SIZE];
struct i596_rbd rbds[RX_RING_SIZE];
struct tx_cmd tx_cmds[TX_RING_SIZE];
struct i596_tbd tbds[TX_RING_SIZE];
int next_tx_cmd;
spinlock_t lock;
};
static char init_setup[] =
{
0x8E, /* length, prefetch on */
0xC8, /* fifo to 8, monitor off */
#ifdef CONFIG_VME
0xc0, /* don't save bad frames */
#else
0x80, /* don't save bad frames */
#endif
0x2E, /* No source address insertion, 8 byte preamble */
0x00, /* priority and backoff defaults */
0x60, /* interframe spacing */
0x00, /* slot time LSB */
0xf2, /* slot time and retries */
0x00, /* promiscuous mode */
0x00, /* collision detect */
0x40, /* minimum frame length */
0xff,
0x00,
0x7f /* *multi IA */ };
static int i596_open(struct net_device *dev);
static netdev_tx_t i596_start_xmit(struct sk_buff *skb, struct net_device *dev);
static irqreturn_t i596_interrupt(int irq, void *dev_id);
static int i596_close(struct net_device *dev);
static void i596_add_cmd(struct net_device *dev, struct i596_cmd *cmd);
static void i596_tx_timeout (struct net_device *dev);
static void print_eth(unsigned char *buf, char *str);
static void set_multicast_list(struct net_device *dev);
static int rx_ring_size = RX_RING_SIZE;
static int ticks_limit = 25;
static int max_cmd_backlog = TX_RING_SIZE-1;
static inline void CA(struct net_device *dev)
{
#ifdef ENABLE_MVME16x_NET
if (MACH_IS_MVME16x) {
((struct i596_reg *) dev->base_addr)->ca = 1;
}
#endif
#ifdef ENABLE_BVME6000_NET
if (MACH_IS_BVME6000) {
volatile u32 i;
i = *(volatile u32 *) (dev->base_addr);
}
#endif
#ifdef ENABLE_APRICOT
if (MACH_IS_APRICOT) {
outw(0, (short) (dev->base_addr) + 4);
}
#endif
}
static inline void MPU_PORT(struct net_device *dev, int c, volatile void *x)
{
#ifdef ENABLE_MVME16x_NET
if (MACH_IS_MVME16x) {
struct i596_reg *p = (struct i596_reg *) (dev->base_addr);
p->porthi = ((c) | (u32) (x)) & 0xffff;
p->portlo = ((c) | (u32) (x)) >> 16;
}
#endif
#ifdef ENABLE_BVME6000_NET
if (MACH_IS_BVME6000) {
u32 v = (u32) (c) | (u32) (x);
v = ((u32) (v) << 16) | ((u32) (v) >> 16);
*(volatile u32 *) dev->base_addr = v;
udelay(1);
*(volatile u32 *) dev->base_addr = v;
}
#endif
}
static inline int wait_istat(struct net_device *dev, struct i596_private *lp, int delcnt, char *str)
{
while (--delcnt && lp->iscp.stat)
udelay(10);
if (!delcnt) {
printk(KERN_ERR "%s: %s, status %4.4x, cmd %4.4x.\n",
dev->name, str, lp->scb.status, lp->scb.command);
return -1;
}
else
return 0;
}
static inline int wait_cmd(struct net_device *dev, struct i596_private *lp, int delcnt, char *str)
{
while (--delcnt && lp->scb.command)
udelay(10);
if (!delcnt) {
printk(KERN_ERR "%s: %s, status %4.4x, cmd %4.4x.\n",
dev->name, str, lp->scb.status, lp->scb.command);
return -1;
}
else
return 0;
}
static inline int wait_cfg(struct net_device *dev, struct i596_cmd *cmd, int delcnt, char *str)
{
volatile struct i596_cmd *c = cmd;
while (--delcnt && c->command)
udelay(10);
if (!delcnt) {
printk(KERN_ERR "%s: %s.\n", dev->name, str);
return -1;
}
else
return 0;
}
static void i596_display_data(struct net_device *dev)
{
struct i596_private *lp = dev->ml_priv;
struct i596_cmd *cmd;
struct i596_rfd *rfd;
struct i596_rbd *rbd;
printk(KERN_ERR "lp and scp at %p, .sysbus = %08lx, .iscp = %p\n",
&lp->scp, lp->scp.sysbus, lp->scp.iscp);
printk(KERN_ERR "iscp at %p, iscp.stat = %08lx, .scb = %p\n",
&lp->iscp, lp->iscp.stat, lp->iscp.scb);
printk(KERN_ERR "scb at %p, scb.status = %04x, .command = %04x,"
" .cmd = %p, .rfd = %p\n",
&lp->scb, lp->scb.status, lp->scb.command,
lp->scb.cmd, lp->scb.rfd);
printk(KERN_ERR " errors: crc %lx, align %lx, resource %lx,"
" over %lx, rcvdt %lx, short %lx\n",
lp->scb.crc_err, lp->scb.align_err, lp->scb.resource_err,
lp->scb.over_err, lp->scb.rcvdt_err, lp->scb.short_err);
cmd = lp->cmd_head;
while (cmd != I596_NULL) {
printk(KERN_ERR "cmd at %p, .status = %04x, .command = %04x, .b_next = %p\n",
cmd, cmd->status, cmd->command, cmd->b_next);
cmd = cmd->v_next;
}
rfd = lp->rfd_head;
printk(KERN_ERR "rfd_head = %p\n", rfd);
do {
printk(KERN_ERR " %p .stat %04x, .cmd %04x, b_next %p, rbd %p,"
" count %04x\n",
rfd, rfd->stat, rfd->cmd, rfd->b_next, rfd->rbd,
rfd->count);
rfd = rfd->v_next;
} while (rfd != lp->rfd_head);
rbd = lp->rbd_head;
printk(KERN_ERR "rbd_head = %p\n", rbd);
do {
printk(KERN_ERR " %p .count %04x, b_next %p, b_data %p, size %04x\n",
rbd, rbd->count, rbd->b_next, rbd->b_data, rbd->size);
rbd = rbd->v_next;
} while (rbd != lp->rbd_head);
}
#if defined(ENABLE_MVME16x_NET) || defined(ENABLE_BVME6000_NET)
static irqreturn_t i596_error(int irq, void *dev_id)
{
struct net_device *dev = dev_id;
#ifdef ENABLE_MVME16x_NET
if (MACH_IS_MVME16x) {
volatile unsigned char *pcc2 = (unsigned char *) 0xfff42000;
pcc2[0x28] = 1;
pcc2[0x2b] = 0x1d;
}
#endif
#ifdef ENABLE_BVME6000_NET
if (MACH_IS_BVME6000) {
volatile unsigned char *ethirq = (unsigned char *) BVME_ETHIRQ_REG;
*ethirq = 1;
*ethirq = 3;
}
#endif
printk(KERN_ERR "%s: Error interrupt\n", dev->name);
i596_display_data(dev);
return IRQ_HANDLED;
}
#endif
static inline void remove_rx_bufs(struct net_device *dev)
{
struct i596_private *lp = dev->ml_priv;
struct i596_rbd *rbd;
int i;
for (i = 0, rbd = lp->rbds; i < rx_ring_size; i++, rbd++) {
if (rbd->skb == NULL)
break;
dev_kfree_skb(rbd->skb);
rbd->skb = NULL;
}
}
static inline int init_rx_bufs(struct net_device *dev)
{
struct i596_private *lp = dev->ml_priv;
int i;
struct i596_rfd *rfd;
struct i596_rbd *rbd;
/* First build the Receive Buffer Descriptor List */
for (i = 0, rbd = lp->rbds; i < rx_ring_size; i++, rbd++) {
struct sk_buff *skb = dev_alloc_skb(PKT_BUF_SZ);
if (skb == NULL) {
remove_rx_bufs(dev);
return -ENOMEM;
}
skb->dev = dev;
rbd->v_next = rbd+1;
rbd->b_next = WSWAPrbd(virt_to_bus(rbd+1));
rbd->b_addr = WSWAPrbd(virt_to_bus(rbd));
rbd->skb = skb;
rbd->v_data = skb->data;
rbd->b_data = WSWAPchar(virt_to_bus(skb->data));
rbd->size = PKT_BUF_SZ;
#ifdef __mc68000__
cache_clear(virt_to_phys(skb->data), PKT_BUF_SZ);
#endif
}
lp->rbd_head = lp->rbds;
rbd = lp->rbds + rx_ring_size - 1;
rbd->v_next = lp->rbds;
rbd->b_next = WSWAPrbd(virt_to_bus(lp->rbds));
/* Now build the Receive Frame Descriptor List */
for (i = 0, rfd = lp->rfds; i < rx_ring_size; i++, rfd++) {
rfd->rbd = I596_NULL;
rfd->v_next = rfd+1;
rfd->v_prev = rfd-1;
rfd->b_next = WSWAPrfd(virt_to_bus(rfd+1));
rfd->cmd = CMD_FLEX;
}
lp->rfd_head = lp->rfds;
lp->scb.rfd = WSWAPrfd(virt_to_bus(lp->rfds));
rfd = lp->rfds;
rfd->rbd = lp->rbd_head;
rfd->v_prev = lp->rfds + rx_ring_size - 1;
rfd = lp->rfds + rx_ring_size - 1;
rfd->v_next = lp->rfds;
rfd->b_next = WSWAPrfd(virt_to_bus(lp->rfds));
rfd->cmd = CMD_EOL|CMD_FLEX;
return 0;
}
static void rebuild_rx_bufs(struct net_device *dev)
{
struct i596_private *lp = dev->ml_priv;
int i;
/* Ensure rx frame/buffer descriptors are tidy */
for (i = 0; i < rx_ring_size; i++) {
lp->rfds[i].rbd = I596_NULL;
lp->rfds[i].cmd = CMD_FLEX;
}
lp->rfds[rx_ring_size-1].cmd = CMD_EOL|CMD_FLEX;
lp->rfd_head = lp->rfds;
lp->scb.rfd = WSWAPrfd(virt_to_bus(lp->rfds));
lp->rbd_head = lp->rbds;
lp->rfds[0].rbd = WSWAPrbd(virt_to_bus(lp->rbds));
}
static int init_i596_mem(struct net_device *dev)
{
struct i596_private *lp = dev->ml_priv;
#if !defined(ENABLE_MVME16x_NET) && !defined(ENABLE_BVME6000_NET) || defined(ENABLE_APRICOT)
short ioaddr = dev->base_addr;
#endif
unsigned long flags;
MPU_PORT(dev, PORT_RESET, NULL);
udelay(100); /* Wait 100us - seems to help */
#if defined(ENABLE_MVME16x_NET) || defined(ENABLE_BVME6000_NET)
#ifdef ENABLE_MVME16x_NET
if (MACH_IS_MVME16x) {
volatile unsigned char *pcc2 = (unsigned char *) 0xfff42000;
/* Disable all ints for now */
pcc2[0x28] = 1;
pcc2[0x2a] = 0x48;
/* Following disables snooping. Snooping is not required
* as we make appropriate use of non-cached pages for
* shared data, and cache_push/cache_clear.
*/
pcc2[0x2b] = 0x08;
}
#endif
#ifdef ENABLE_BVME6000_NET
if (MACH_IS_BVME6000) {
volatile unsigned char *ethirq = (unsigned char *) BVME_ETHIRQ_REG;
*ethirq = 1;
}
#endif
/* change the scp address */
MPU_PORT(dev, PORT_ALTSCP, (void *)virt_to_bus((void *)&lp->scp));
#elif defined(ENABLE_APRICOT)
{
u32 scp = virt_to_bus(&lp->scp);
/* change the scp address */
outw(0, ioaddr);
outw(0, ioaddr);
outb(4, ioaddr + 0xf);
outw(scp | 2, ioaddr);
outw(scp >> 16, ioaddr);
}
#endif
lp->last_cmd = jiffies;
#ifdef ENABLE_MVME16x_NET
if (MACH_IS_MVME16x)
lp->scp.sysbus = 0x00000054;
#endif
#ifdef ENABLE_BVME6000_NET
if (MACH_IS_BVME6000)
lp->scp.sysbus = 0x0000004c;
#endif
#ifdef ENABLE_APRICOT
if (MACH_IS_APRICOT)
lp->scp.sysbus = 0x00440000;
#endif
lp->scp.iscp = WSWAPiscp(virt_to_bus((void *)&lp->iscp));
lp->iscp.scb = WSWAPscb(virt_to_bus((void *)&lp->scb));
lp->iscp.stat = ISCP_BUSY;
lp->cmd_backlog = 0;
lp->cmd_head = lp->scb.cmd = I596_NULL;
#ifdef ENABLE_BVME6000_NET
if (MACH_IS_BVME6000) {
lp->scb.t_on = 7 * 25;
lp->scb.t_off = 1 * 25;
}
#endif
DEB(DEB_INIT,printk(KERN_DEBUG "%s: starting i82596.\n", dev->name));
#if defined(ENABLE_APRICOT)
(void) inb(ioaddr + 0x10);
outb(4, ioaddr + 0xf);
#endif
CA(dev);
if (wait_istat(dev,lp,1000,"initialization timed out"))
goto failed;
DEB(DEB_INIT,printk(KERN_DEBUG "%s: i82596 initialization successful\n", dev->name));
/* Ensure rx frame/buffer descriptors are tidy */
rebuild_rx_bufs(dev);
lp->scb.command = 0;
#ifdef ENABLE_MVME16x_NET
if (MACH_IS_MVME16x) {
volatile unsigned char *pcc2 = (unsigned char *) 0xfff42000;
/* Enable ints, etc. now */
pcc2[0x2a] = 0x55; /* Edge sensitive */
pcc2[0x2b] = 0x15;
}
#endif
#ifdef ENABLE_BVME6000_NET
if (MACH_IS_BVME6000) {
volatile unsigned char *ethirq = (unsigned char *) BVME_ETHIRQ_REG;
*ethirq = 3;
}
#endif
DEB(DEB_INIT,printk(KERN_DEBUG "%s: queuing CmdConfigure\n", dev->name));
memcpy(lp->cf_cmd.i596_config, init_setup, 14);
lp->cf_cmd.cmd.command = CmdConfigure;
i596_add_cmd(dev, &lp->cf_cmd.cmd);
DEB(DEB_INIT,printk(KERN_DEBUG "%s: queuing CmdSASetup\n", dev->name));
memcpy(lp->sa_cmd.eth_addr, dev->dev_addr, 6);
lp->sa_cmd.cmd.command = CmdSASetup;
i596_add_cmd(dev, &lp->sa_cmd.cmd);
DEB(DEB_INIT,printk(KERN_DEBUG "%s: queuing CmdTDR\n", dev->name));
lp->tdr_cmd.cmd.command = CmdTDR;
i596_add_cmd(dev, &lp->tdr_cmd.cmd);
spin_lock_irqsave (&lp->lock, flags);
if (wait_cmd(dev,lp,1000,"timed out waiting to issue RX_START")) {
spin_unlock_irqrestore (&lp->lock, flags);
goto failed;
}
DEB(DEB_INIT,printk(KERN_DEBUG "%s: Issuing RX_START\n", dev->name));
lp->scb.command = RX_START;
CA(dev);
spin_unlock_irqrestore (&lp->lock, flags);
if (wait_cmd(dev,lp,1000,"RX_START not processed"))
goto failed;
DEB(DEB_INIT,printk(KERN_DEBUG "%s: Receive unit started OK\n", dev->name));
return 0;
failed:
printk(KERN_CRIT "%s: Failed to initialise 82596\n", dev->name);
MPU_PORT(dev, PORT_RESET, NULL);
return -1;
}
static inline int i596_rx(struct net_device *dev)
{
struct i596_private *lp = dev->ml_priv;
struct i596_rfd *rfd;
struct i596_rbd *rbd;
int frames = 0;
DEB(DEB_RXFRAME,printk(KERN_DEBUG "i596_rx(), rfd_head %p, rbd_head %p\n",
lp->rfd_head, lp->rbd_head));
rfd = lp->rfd_head; /* Ref next frame to check */
while ((rfd->stat) & STAT_C) { /* Loop while complete frames */
if (rfd->rbd == I596_NULL)
rbd = I596_NULL;
else if (rfd->rbd == lp->rbd_head->b_addr)
rbd = lp->rbd_head;
else {
printk(KERN_CRIT "%s: rbd chain broken!\n", dev->name);
/* XXX Now what? */
rbd = I596_NULL;
}
DEB(DEB_RXFRAME, printk(KERN_DEBUG " rfd %p, rfd.rbd %p, rfd.stat %04x\n",
rfd, rfd->rbd, rfd->stat));
if (rbd != I596_NULL && ((rfd->stat) & STAT_OK)) {
/* a good frame */
int pkt_len = rbd->count & 0x3fff;
struct sk_buff *skb = rbd->skb;
int rx_in_place = 0;
DEB(DEB_RXADDR,print_eth(rbd->v_data, "received"));
frames++;
/* Check if the packet is long enough to just accept
* without copying to a properly sized skbuff.
*/
if (pkt_len > rx_copybreak) {
struct sk_buff *newskb;
/* Get fresh skbuff to replace filled one. */
newskb = dev_alloc_skb(PKT_BUF_SZ);
if (newskb == NULL) {
skb = NULL; /* drop pkt */
goto memory_squeeze;
}
/* Pass up the skb already on the Rx ring. */
skb_put(skb, pkt_len);
rx_in_place = 1;
rbd->skb = newskb;
newskb->dev = dev;
rbd->v_data = newskb->data;
rbd->b_data = WSWAPchar(virt_to_bus(newskb->data));
#ifdef __mc68000__
cache_clear(virt_to_phys(newskb->data), PKT_BUF_SZ);
#endif
}
else
skb = dev_alloc_skb(pkt_len + 2);
memory_squeeze:
if (skb == NULL) {
/* XXX tulip.c can defer packets here!! */
printk(KERN_WARNING "%s: i596_rx Memory squeeze, dropping packet.\n", dev->name);
dev->stats.rx_dropped++;
}
else {
if (!rx_in_place) {
/* 16 byte align the data fields */
skb_reserve(skb, 2);
memcpy(skb_put(skb,pkt_len), rbd->v_data, pkt_len);
}
skb->protocol=eth_type_trans(skb,dev);
skb->len = pkt_len;
#ifdef __mc68000__
cache_clear(virt_to_phys(rbd->skb->data),
pkt_len);
#endif
netif_rx(skb);
dev->stats.rx_packets++;
dev->stats.rx_bytes+=pkt_len;
}
}
else {
DEB(DEB_ERRORS, printk(KERN_DEBUG "%s: Error, rfd.stat = 0x%04x\n",
dev->name, rfd->stat));
dev->stats.rx_errors++;
if ((rfd->stat) & 0x0001)
dev->stats.collisions++;
if ((rfd->stat) & 0x0080)
dev->stats.rx_length_errors++;
if ((rfd->stat) & 0x0100)
dev->stats.rx_over_errors++;
if ((rfd->stat) & 0x0200)
dev->stats.rx_fifo_errors++;
if ((rfd->stat) & 0x0400)
dev->stats.rx_frame_errors++;
if ((rfd->stat) & 0x0800)
dev->stats.rx_crc_errors++;
if ((rfd->stat) & 0x1000)
dev->stats.rx_length_errors++;
}
/* Clear the buffer descriptor count and EOF + F flags */
if (rbd != I596_NULL && (rbd->count & 0x4000)) {
rbd->count = 0;
lp->rbd_head = rbd->v_next;
}
/* Tidy the frame descriptor, marking it as end of list */
rfd->rbd = I596_NULL;
rfd->stat = 0;
rfd->cmd = CMD_EOL|CMD_FLEX;
rfd->count = 0;
/* Remove end-of-list from old end descriptor */
rfd->v_prev->cmd = CMD_FLEX;
/* Update record of next frame descriptor to process */
lp->scb.rfd = rfd->b_next;
lp->rfd_head = rfd->v_next;
rfd = lp->rfd_head;
}
DEB(DEB_RXFRAME,printk(KERN_DEBUG "frames %d\n", frames));
return 0;
}
static void i596_cleanup_cmd(struct net_device *dev, struct i596_private *lp)
{
struct i596_cmd *ptr;
while (lp->cmd_head != I596_NULL) {
ptr = lp->cmd_head;
lp->cmd_head = ptr->v_next;
lp->cmd_backlog--;
switch ((ptr->command) & 0x7) {
case CmdTx:
{
struct tx_cmd *tx_cmd = (struct tx_cmd *) ptr;
struct sk_buff *skb = tx_cmd->skb;
dev_kfree_skb(skb);
dev->stats.tx_errors++;
dev->stats.tx_aborted_errors++;
ptr->v_next = ptr->b_next = I596_NULL;
tx_cmd->cmd.command = 0; /* Mark as free */
break;
}
default:
ptr->v_next = ptr->b_next = I596_NULL;
}
}
wait_cmd(dev,lp,100,"i596_cleanup_cmd timed out");
lp->scb.cmd = I596_NULL;
}
static void i596_reset(struct net_device *dev, struct i596_private *lp,
int ioaddr)
{
unsigned long flags;
DEB(DEB_RESET,printk(KERN_DEBUG "i596_reset\n"));
spin_lock_irqsave (&lp->lock, flags);
wait_cmd(dev,lp,100,"i596_reset timed out");
netif_stop_queue(dev);
lp->scb.command = CUC_ABORT | RX_ABORT;
CA(dev);
/* wait for shutdown */
wait_cmd(dev,lp,1000,"i596_reset 2 timed out");
spin_unlock_irqrestore (&lp->lock, flags);
i596_cleanup_cmd(dev,lp);
i596_rx(dev);
netif_start_queue(dev);
init_i596_mem(dev);
}
static void i596_add_cmd(struct net_device *dev, struct i596_cmd *cmd)
{
struct i596_private *lp = dev->ml_priv;
int ioaddr = dev->base_addr;
unsigned long flags;
DEB(DEB_ADDCMD,printk(KERN_DEBUG "i596_add_cmd\n"));
cmd->status = 0;
cmd->command |= (CMD_EOL | CMD_INTR);
cmd->v_next = cmd->b_next = I596_NULL;
spin_lock_irqsave (&lp->lock, flags);
if (lp->cmd_head != I596_NULL) {
lp->cmd_tail->v_next = cmd;
lp->cmd_tail->b_next = WSWAPcmd(virt_to_bus(&cmd->status));
} else {
lp->cmd_head = cmd;
wait_cmd(dev,lp,100,"i596_add_cmd timed out");
lp->scb.cmd = WSWAPcmd(virt_to_bus(&cmd->status));
lp->scb.command = CUC_START;
CA(dev);
}
lp->cmd_tail = cmd;
lp->cmd_backlog++;
spin_unlock_irqrestore (&lp->lock, flags);
if (lp->cmd_backlog > max_cmd_backlog) {
unsigned long tickssofar = jiffies - lp->last_cmd;
if (tickssofar < ticks_limit)
return;
printk(KERN_NOTICE "%s: command unit timed out, status resetting.\n", dev->name);