forked from torvalds/linux
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrrunner.c
1687 lines (1422 loc) · 41 KB
/
rrunner.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
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* rrunner.c: Linux driver for the Essential RoadRunner HIPPI board.
*
* Copyright (C) 1998-2002 by Jes Sorensen, <[email protected]>.
*
* Thanks to Essential Communication for providing us with hardware
* and very comprehensive documentation without which I would not have
* been able to write this driver. A special thank you to John Gibbon
* for sorting out the legal issues, with the NDA, allowing the code to
* be released under the GPL.
*
* Thanks to Jayaram Bhat from ODS/Essential for fixing some of the
* stupid bugs in my code.
*
* Softnet support and various other patches from Val Henson of
* ODS/Essential.
*
* PCI DMA mapping code partly based on work by Francois Romieu.
*/
#define DEBUG 1
#define RX_DMA_SKBUFF 1
#define PKT_COPY_THRESHOLD 512
#include <linux/module.h>
#include <linux/types.h>
#include <linux/errno.h>
#include <linux/ioport.h>
#include <linux/pci.h>
#include <linux/kernel.h>
#include <linux/netdevice.h>
#include <linux/hippidevice.h>
#include <linux/skbuff.h>
#include <linux/delay.h>
#include <linux/mm.h>
#include <linux/slab.h>
#include <net/sock.h>
#include <asm/cache.h>
#include <asm/byteorder.h>
#include <asm/io.h>
#include <asm/irq.h>
#include <linux/uaccess.h>
#define rr_if_busy(dev) netif_queue_stopped(dev)
#define rr_if_running(dev) netif_running(dev)
#include "rrunner.h"
#define RUN_AT(x) (jiffies + (x))
MODULE_AUTHOR("Jes Sorensen <[email protected]>");
MODULE_DESCRIPTION("Essential RoadRunner HIPPI driver");
MODULE_LICENSE("GPL");
static const char version[] =
"rrunner.c: v0.50 11/11/2002 Jes Sorensen ([email protected])\n";
static const struct net_device_ops rr_netdev_ops = {
.ndo_open = rr_open,
.ndo_stop = rr_close,
.ndo_siocdevprivate = rr_siocdevprivate,
.ndo_start_xmit = rr_start_xmit,
.ndo_set_mac_address = hippi_mac_addr,
};
/*
* Implementation notes:
*
* The DMA engine only allows for DMA within physical 64KB chunks of
* memory. The current approach of the driver (and stack) is to use
* linear blocks of memory for the skbuffs. However, as the data block
* is always the first part of the skb and skbs are 2^n aligned so we
* are guarantted to get the whole block within one 64KB align 64KB
* chunk.
*
* On the long term, relying on being able to allocate 64KB linear
* chunks of memory is not feasible and the skb handling code and the
* stack will need to know about I/O vectors or something similar.
*/
static int rr_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
{
struct net_device *dev;
static int version_disp;
u8 pci_latency;
struct rr_private *rrpriv;
void *tmpptr;
dma_addr_t ring_dma;
int ret = -ENOMEM;
dev = alloc_hippi_dev(sizeof(struct rr_private));
if (!dev)
goto out3;
ret = pci_enable_device(pdev);
if (ret) {
ret = -ENODEV;
goto out2;
}
rrpriv = netdev_priv(dev);
SET_NETDEV_DEV(dev, &pdev->dev);
ret = pci_request_regions(pdev, "rrunner");
if (ret < 0)
goto out;
pci_set_drvdata(pdev, dev);
rrpriv->pci_dev = pdev;
spin_lock_init(&rrpriv->lock);
dev->netdev_ops = &rr_netdev_ops;
/* display version info if adapter is found */
if (!version_disp) {
/* set display flag to TRUE so that */
/* we only display this string ONCE */
version_disp = 1;
printk(version);
}
pci_read_config_byte(pdev, PCI_LATENCY_TIMER, &pci_latency);
if (pci_latency <= 0x58){
pci_latency = 0x58;
pci_write_config_byte(pdev, PCI_LATENCY_TIMER, pci_latency);
}
pci_set_master(pdev);
printk(KERN_INFO "%s: Essential RoadRunner serial HIPPI "
"at 0x%llx, irq %i, PCI latency %i\n", dev->name,
(unsigned long long)pci_resource_start(pdev, 0),
pdev->irq, pci_latency);
/*
* Remap the MMIO regs into kernel space.
*/
rrpriv->regs = pci_iomap(pdev, 0, 0x1000);
if (!rrpriv->regs) {
printk(KERN_ERR "%s: Unable to map I/O register, "
"RoadRunner will be disabled.\n", dev->name);
ret = -EIO;
goto out;
}
tmpptr = dma_alloc_coherent(&pdev->dev, TX_TOTAL_SIZE, &ring_dma,
GFP_KERNEL);
rrpriv->tx_ring = tmpptr;
rrpriv->tx_ring_dma = ring_dma;
if (!tmpptr) {
ret = -ENOMEM;
goto out;
}
tmpptr = dma_alloc_coherent(&pdev->dev, RX_TOTAL_SIZE, &ring_dma,
GFP_KERNEL);
rrpriv->rx_ring = tmpptr;
rrpriv->rx_ring_dma = ring_dma;
if (!tmpptr) {
ret = -ENOMEM;
goto out;
}
tmpptr = dma_alloc_coherent(&pdev->dev, EVT_RING_SIZE, &ring_dma,
GFP_KERNEL);
rrpriv->evt_ring = tmpptr;
rrpriv->evt_ring_dma = ring_dma;
if (!tmpptr) {
ret = -ENOMEM;
goto out;
}
/*
* Don't access any register before this point!
*/
#ifdef __BIG_ENDIAN
writel(readl(&rrpriv->regs->HostCtrl) | NO_SWAP,
&rrpriv->regs->HostCtrl);
#endif
/*
* Need to add a case for little-endian 64-bit hosts here.
*/
rr_init(dev);
ret = register_netdev(dev);
if (ret)
goto out;
return 0;
out:
if (rrpriv->evt_ring)
dma_free_coherent(&pdev->dev, EVT_RING_SIZE, rrpriv->evt_ring,
rrpriv->evt_ring_dma);
if (rrpriv->rx_ring)
dma_free_coherent(&pdev->dev, RX_TOTAL_SIZE, rrpriv->rx_ring,
rrpriv->rx_ring_dma);
if (rrpriv->tx_ring)
dma_free_coherent(&pdev->dev, TX_TOTAL_SIZE, rrpriv->tx_ring,
rrpriv->tx_ring_dma);
if (rrpriv->regs)
pci_iounmap(pdev, rrpriv->regs);
if (pdev)
pci_release_regions(pdev);
pci_disable_device(pdev);
out2:
free_netdev(dev);
out3:
return ret;
}
static void rr_remove_one(struct pci_dev *pdev)
{
struct net_device *dev = pci_get_drvdata(pdev);
struct rr_private *rr = netdev_priv(dev);
if (!(readl(&rr->regs->HostCtrl) & NIC_HALTED)) {
printk(KERN_ERR "%s: trying to unload running NIC\n",
dev->name);
writel(HALT_NIC, &rr->regs->HostCtrl);
}
unregister_netdev(dev);
dma_free_coherent(&pdev->dev, EVT_RING_SIZE, rr->evt_ring,
rr->evt_ring_dma);
dma_free_coherent(&pdev->dev, RX_TOTAL_SIZE, rr->rx_ring,
rr->rx_ring_dma);
dma_free_coherent(&pdev->dev, TX_TOTAL_SIZE, rr->tx_ring,
rr->tx_ring_dma);
pci_iounmap(pdev, rr->regs);
pci_release_regions(pdev);
pci_disable_device(pdev);
free_netdev(dev);
}
/*
* Commands are considered to be slow, thus there is no reason to
* inline this.
*/
static void rr_issue_cmd(struct rr_private *rrpriv, struct cmd *cmd)
{
struct rr_regs __iomem *regs;
u32 idx;
regs = rrpriv->regs;
/*
* This is temporary - it will go away in the final version.
* We probably also want to make this function inline.
*/
if (readl(®s->HostCtrl) & NIC_HALTED){
printk("issuing command for halted NIC, code 0x%x, "
"HostCtrl %08x\n", cmd->code, readl(®s->HostCtrl));
if (readl(®s->Mode) & FATAL_ERR)
printk("error codes Fail1 %02x, Fail2 %02x\n",
readl(®s->Fail1), readl(®s->Fail2));
}
idx = rrpriv->info->cmd_ctrl.pi;
writel(*(u32*)(cmd), ®s->CmdRing[idx]);
wmb();
idx = (idx - 1) % CMD_RING_ENTRIES;
rrpriv->info->cmd_ctrl.pi = idx;
wmb();
if (readl(®s->Mode) & FATAL_ERR)
printk("error code %02x\n", readl(®s->Fail1));
}
/*
* Reset the board in a sensible manner. The NIC is already halted
* when we get here and a spin-lock is held.
*/
static int rr_reset(struct net_device *dev)
{
struct rr_private *rrpriv;
struct rr_regs __iomem *regs;
u32 start_pc;
int i;
rrpriv = netdev_priv(dev);
regs = rrpriv->regs;
rr_load_firmware(dev);
writel(0x01000000, ®s->TX_state);
writel(0xff800000, ®s->RX_state);
writel(0, ®s->AssistState);
writel(CLEAR_INTA, ®s->LocalCtrl);
writel(0x01, ®s->BrkPt);
writel(0, ®s->Timer);
writel(0, ®s->TimerRef);
writel(RESET_DMA, ®s->DmaReadState);
writel(RESET_DMA, ®s->DmaWriteState);
writel(0, ®s->DmaWriteHostHi);
writel(0, ®s->DmaWriteHostLo);
writel(0, ®s->DmaReadHostHi);
writel(0, ®s->DmaReadHostLo);
writel(0, ®s->DmaReadLen);
writel(0, ®s->DmaWriteLen);
writel(0, ®s->DmaWriteLcl);
writel(0, ®s->DmaWriteIPchecksum);
writel(0, ®s->DmaReadLcl);
writel(0, ®s->DmaReadIPchecksum);
writel(0, ®s->PciState);
#if (BITS_PER_LONG == 64) && defined __LITTLE_ENDIAN
writel(SWAP_DATA | PTR64BIT | PTR_WD_SWAP, ®s->Mode);
#elif (BITS_PER_LONG == 64)
writel(SWAP_DATA | PTR64BIT | PTR_WD_NOSWAP, ®s->Mode);
#else
writel(SWAP_DATA | PTR32BIT | PTR_WD_NOSWAP, ®s->Mode);
#endif
#if 0
/*
* Don't worry, this is just black magic.
*/
writel(0xdf000, ®s->RxBase);
writel(0xdf000, ®s->RxPrd);
writel(0xdf000, ®s->RxCon);
writel(0xce000, ®s->TxBase);
writel(0xce000, ®s->TxPrd);
writel(0xce000, ®s->TxCon);
writel(0, ®s->RxIndPro);
writel(0, ®s->RxIndCon);
writel(0, ®s->RxIndRef);
writel(0, ®s->TxIndPro);
writel(0, ®s->TxIndCon);
writel(0, ®s->TxIndRef);
writel(0xcc000, ®s->pad10[0]);
writel(0, ®s->DrCmndPro);
writel(0, ®s->DrCmndCon);
writel(0, ®s->DwCmndPro);
writel(0, ®s->DwCmndCon);
writel(0, ®s->DwCmndRef);
writel(0, ®s->DrDataPro);
writel(0, ®s->DrDataCon);
writel(0, ®s->DrDataRef);
writel(0, ®s->DwDataPro);
writel(0, ®s->DwDataCon);
writel(0, ®s->DwDataRef);
#endif
writel(0xffffffff, ®s->MbEvent);
writel(0, ®s->Event);
writel(0, ®s->TxPi);
writel(0, ®s->IpRxPi);
writel(0, ®s->EvtCon);
writel(0, ®s->EvtPrd);
rrpriv->info->evt_ctrl.pi = 0;
for (i = 0; i < CMD_RING_ENTRIES; i++)
writel(0, ®s->CmdRing[i]);
/*
* Why 32 ? is this not cache line size dependent?
*/
writel(RBURST_64|WBURST_64, ®s->PciState);
wmb();
start_pc = rr_read_eeprom_word(rrpriv,
offsetof(struct eeprom, rncd_info.FwStart));
#if (DEBUG > 1)
printk("%s: Executing firmware at address 0x%06x\n",
dev->name, start_pc);
#endif
writel(start_pc + 0x800, ®s->Pc);
wmb();
udelay(5);
writel(start_pc, ®s->Pc);
wmb();
return 0;
}
/*
* Read a string from the EEPROM.
*/
static unsigned int rr_read_eeprom(struct rr_private *rrpriv,
unsigned long offset,
unsigned char *buf,
unsigned long length)
{
struct rr_regs __iomem *regs = rrpriv->regs;
u32 misc, io, host, i;
io = readl(®s->ExtIo);
writel(0, ®s->ExtIo);
misc = readl(®s->LocalCtrl);
writel(0, ®s->LocalCtrl);
host = readl(®s->HostCtrl);
writel(host | HALT_NIC, ®s->HostCtrl);
mb();
for (i = 0; i < length; i++){
writel((EEPROM_BASE + ((offset+i) << 3)), ®s->WinBase);
mb();
buf[i] = (readl(®s->WinData) >> 24) & 0xff;
mb();
}
writel(host, ®s->HostCtrl);
writel(misc, ®s->LocalCtrl);
writel(io, ®s->ExtIo);
mb();
return i;
}
/*
* Shortcut to read one word (4 bytes) out of the EEPROM and convert
* it to our CPU byte-order.
*/
static u32 rr_read_eeprom_word(struct rr_private *rrpriv,
size_t offset)
{
__be32 word;
if ((rr_read_eeprom(rrpriv, offset,
(unsigned char *)&word, 4) == 4))
return be32_to_cpu(word);
return 0;
}
/*
* Write a string to the EEPROM.
*
* This is only called when the firmware is not running.
*/
static unsigned int write_eeprom(struct rr_private *rrpriv,
unsigned long offset,
unsigned char *buf,
unsigned long length)
{
struct rr_regs __iomem *regs = rrpriv->regs;
u32 misc, io, data, i, j, ready, error = 0;
io = readl(®s->ExtIo);
writel(0, ®s->ExtIo);
misc = readl(®s->LocalCtrl);
writel(ENABLE_EEPROM_WRITE, ®s->LocalCtrl);
mb();
for (i = 0; i < length; i++){
writel((EEPROM_BASE + ((offset+i) << 3)), ®s->WinBase);
mb();
data = buf[i] << 24;
/*
* Only try to write the data if it is not the same
* value already.
*/
if ((readl(®s->WinData) & 0xff000000) != data){
writel(data, ®s->WinData);
ready = 0;
j = 0;
mb();
while(!ready){
udelay(20);
if ((readl(®s->WinData) & 0xff000000) ==
data)
ready = 1;
mb();
if (j++ > 5000){
printk("data mismatch: %08x, "
"WinData %08x\n", data,
readl(®s->WinData));
ready = 1;
error = 1;
}
}
}
}
writel(misc, ®s->LocalCtrl);
writel(io, ®s->ExtIo);
mb();
return error;
}
static int rr_init(struct net_device *dev)
{
u8 addr[HIPPI_ALEN] __aligned(4);
struct rr_private *rrpriv;
struct rr_regs __iomem *regs;
u32 sram_size, rev;
rrpriv = netdev_priv(dev);
regs = rrpriv->regs;
rev = readl(®s->FwRev);
rrpriv->fw_rev = rev;
if (rev > 0x00020024)
printk(" Firmware revision: %i.%i.%i\n", (rev >> 16),
((rev >> 8) & 0xff), (rev & 0xff));
else if (rev >= 0x00020000) {
printk(" Firmware revision: %i.%i.%i (2.0.37 or "
"later is recommended)\n", (rev >> 16),
((rev >> 8) & 0xff), (rev & 0xff));
}else{
printk(" Firmware revision too old: %i.%i.%i, please "
"upgrade to 2.0.37 or later.\n",
(rev >> 16), ((rev >> 8) & 0xff), (rev & 0xff));
}
#if (DEBUG > 2)
printk(" Maximum receive rings %i\n", readl(®s->MaxRxRng));
#endif
/*
* Read the hardware address from the eeprom. The HW address
* is not really necessary for HIPPI but awfully convenient.
* The pointer arithmetic to put it in dev_addr is ugly, but
* Donald Becker does it this way for the GigE version of this
* card and it's shorter and more portable than any
* other method I've seen. -VAL
*/
*(__be16 *)(addr) =
htons(rr_read_eeprom_word(rrpriv, offsetof(struct eeprom, manf.BoardULA)));
*(__be32 *)(addr+2) =
htonl(rr_read_eeprom_word(rrpriv, offsetof(struct eeprom, manf.BoardULA[4])));
dev_addr_set(dev, addr);
printk(" MAC: %pM\n", dev->dev_addr);
sram_size = rr_read_eeprom_word(rrpriv, 8);
printk(" SRAM size 0x%06x\n", sram_size);
return 0;
}
static int rr_init1(struct net_device *dev)
{
struct rr_private *rrpriv;
struct rr_regs __iomem *regs;
unsigned long myjif, flags;
struct cmd cmd;
u32 hostctrl;
int ecode = 0;
short i;
rrpriv = netdev_priv(dev);
regs = rrpriv->regs;
spin_lock_irqsave(&rrpriv->lock, flags);
hostctrl = readl(®s->HostCtrl);
writel(hostctrl | HALT_NIC | RR_CLEAR_INT, ®s->HostCtrl);
wmb();
if (hostctrl & PARITY_ERR){
printk("%s: Parity error halting NIC - this is serious!\n",
dev->name);
spin_unlock_irqrestore(&rrpriv->lock, flags);
ecode = -EFAULT;
goto error;
}
set_rxaddr(regs, rrpriv->rx_ctrl_dma);
set_infoaddr(regs, rrpriv->info_dma);
rrpriv->info->evt_ctrl.entry_size = sizeof(struct event);
rrpriv->info->evt_ctrl.entries = EVT_RING_ENTRIES;
rrpriv->info->evt_ctrl.mode = 0;
rrpriv->info->evt_ctrl.pi = 0;
set_rraddr(&rrpriv->info->evt_ctrl.rngptr, rrpriv->evt_ring_dma);
rrpriv->info->cmd_ctrl.entry_size = sizeof(struct cmd);
rrpriv->info->cmd_ctrl.entries = CMD_RING_ENTRIES;
rrpriv->info->cmd_ctrl.mode = 0;
rrpriv->info->cmd_ctrl.pi = 15;
for (i = 0; i < CMD_RING_ENTRIES; i++) {
writel(0, ®s->CmdRing[i]);
}
for (i = 0; i < TX_RING_ENTRIES; i++) {
rrpriv->tx_ring[i].size = 0;
set_rraddr(&rrpriv->tx_ring[i].addr, 0);
rrpriv->tx_skbuff[i] = NULL;
}
rrpriv->info->tx_ctrl.entry_size = sizeof(struct tx_desc);
rrpriv->info->tx_ctrl.entries = TX_RING_ENTRIES;
rrpriv->info->tx_ctrl.mode = 0;
rrpriv->info->tx_ctrl.pi = 0;
set_rraddr(&rrpriv->info->tx_ctrl.rngptr, rrpriv->tx_ring_dma);
/*
* Set dirty_tx before we start receiving interrupts, otherwise
* the interrupt handler might think it is supposed to process
* tx ints before we are up and running, which may cause a null
* pointer access in the int handler.
*/
rrpriv->tx_full = 0;
rrpriv->cur_rx = 0;
rrpriv->dirty_rx = rrpriv->dirty_tx = 0;
rr_reset(dev);
/* Tuning values */
writel(0x5000, ®s->ConRetry);
writel(0x100, ®s->ConRetryTmr);
writel(0x500000, ®s->ConTmout);
writel(0x60, ®s->IntrTmr);
writel(0x500000, ®s->TxDataMvTimeout);
writel(0x200000, ®s->RxDataMvTimeout);
writel(0x80, ®s->WriteDmaThresh);
writel(0x80, ®s->ReadDmaThresh);
rrpriv->fw_running = 0;
wmb();
hostctrl &= ~(HALT_NIC | INVALID_INST_B | PARITY_ERR);
writel(hostctrl, ®s->HostCtrl);
wmb();
spin_unlock_irqrestore(&rrpriv->lock, flags);
for (i = 0; i < RX_RING_ENTRIES; i++) {
struct sk_buff *skb;
dma_addr_t addr;
rrpriv->rx_ring[i].mode = 0;
skb = alloc_skb(dev->mtu + HIPPI_HLEN, GFP_ATOMIC);
if (!skb) {
printk(KERN_WARNING "%s: Unable to allocate memory "
"for receive ring - halting NIC\n", dev->name);
ecode = -ENOMEM;
goto error;
}
rrpriv->rx_skbuff[i] = skb;
addr = dma_map_single(&rrpriv->pci_dev->dev, skb->data,
dev->mtu + HIPPI_HLEN, DMA_FROM_DEVICE);
/*
* Sanity test to see if we conflict with the DMA
* limitations of the Roadrunner.
*/
if ((((unsigned long)skb->data) & 0xfff) > ~65320)
printk("skb alloc error\n");
set_rraddr(&rrpriv->rx_ring[i].addr, addr);
rrpriv->rx_ring[i].size = dev->mtu + HIPPI_HLEN;
}
rrpriv->rx_ctrl[4].entry_size = sizeof(struct rx_desc);
rrpriv->rx_ctrl[4].entries = RX_RING_ENTRIES;
rrpriv->rx_ctrl[4].mode = 8;
rrpriv->rx_ctrl[4].pi = 0;
wmb();
set_rraddr(&rrpriv->rx_ctrl[4].rngptr, rrpriv->rx_ring_dma);
udelay(1000);
/*
* Now start the FirmWare.
*/
cmd.code = C_START_FW;
cmd.ring = 0;
cmd.index = 0;
rr_issue_cmd(rrpriv, &cmd);
/*
* Give the FirmWare time to chew on the `get running' command.
*/
myjif = jiffies + 5 * HZ;
while (time_before(jiffies, myjif) && !rrpriv->fw_running)
cpu_relax();
netif_start_queue(dev);
return ecode;
error:
/*
* We might have gotten here because we are out of memory,
* make sure we release everything we allocated before failing
*/
for (i = 0; i < RX_RING_ENTRIES; i++) {
struct sk_buff *skb = rrpriv->rx_skbuff[i];
if (skb) {
dma_unmap_single(&rrpriv->pci_dev->dev,
rrpriv->rx_ring[i].addr.addrlo,
dev->mtu + HIPPI_HLEN,
DMA_FROM_DEVICE);
rrpriv->rx_ring[i].size = 0;
set_rraddr(&rrpriv->rx_ring[i].addr, 0);
dev_kfree_skb(skb);
rrpriv->rx_skbuff[i] = NULL;
}
}
return ecode;
}
/*
* All events are considered to be slow (RX/TX ints do not generate
* events) and are handled here, outside the main interrupt handler,
* to reduce the size of the handler.
*/
static u32 rr_handle_event(struct net_device *dev, u32 prodidx, u32 eidx)
{
struct rr_private *rrpriv;
struct rr_regs __iomem *regs;
u32 tmp;
rrpriv = netdev_priv(dev);
regs = rrpriv->regs;
while (prodidx != eidx){
switch (rrpriv->evt_ring[eidx].code){
case E_NIC_UP:
tmp = readl(®s->FwRev);
printk(KERN_INFO "%s: Firmware revision %i.%i.%i "
"up and running\n", dev->name,
(tmp >> 16), ((tmp >> 8) & 0xff), (tmp & 0xff));
rrpriv->fw_running = 1;
writel(RX_RING_ENTRIES - 1, ®s->IpRxPi);
wmb();
break;
case E_LINK_ON:
printk(KERN_INFO "%s: Optical link ON\n", dev->name);
break;
case E_LINK_OFF:
printk(KERN_INFO "%s: Optical link OFF\n", dev->name);
break;
case E_RX_IDLE:
printk(KERN_WARNING "%s: RX data not moving\n",
dev->name);
goto drop;
case E_WATCHDOG:
printk(KERN_INFO "%s: The watchdog is here to see "
"us\n", dev->name);
break;
case E_INTERN_ERR:
printk(KERN_ERR "%s: HIPPI Internal NIC error\n",
dev->name);
writel(readl(®s->HostCtrl)|HALT_NIC|RR_CLEAR_INT,
®s->HostCtrl);
wmb();
break;
case E_HOST_ERR:
printk(KERN_ERR "%s: Host software error\n",
dev->name);
writel(readl(®s->HostCtrl)|HALT_NIC|RR_CLEAR_INT,
®s->HostCtrl);
wmb();
break;
/*
* TX events.
*/
case E_CON_REJ:
printk(KERN_WARNING "%s: Connection rejected\n",
dev->name);
dev->stats.tx_aborted_errors++;
break;
case E_CON_TMOUT:
printk(KERN_WARNING "%s: Connection timeout\n",
dev->name);
break;
case E_DISC_ERR:
printk(KERN_WARNING "%s: HIPPI disconnect error\n",
dev->name);
dev->stats.tx_aborted_errors++;
break;
case E_INT_PRTY:
printk(KERN_ERR "%s: HIPPI Internal Parity error\n",
dev->name);
writel(readl(®s->HostCtrl)|HALT_NIC|RR_CLEAR_INT,
®s->HostCtrl);
wmb();
break;
case E_TX_IDLE:
printk(KERN_WARNING "%s: Transmitter idle\n",
dev->name);
break;
case E_TX_LINK_DROP:
printk(KERN_WARNING "%s: Link lost during transmit\n",
dev->name);
dev->stats.tx_aborted_errors++;
writel(readl(®s->HostCtrl)|HALT_NIC|RR_CLEAR_INT,
®s->HostCtrl);
wmb();
break;
case E_TX_INV_RNG:
printk(KERN_ERR "%s: Invalid send ring block\n",
dev->name);
writel(readl(®s->HostCtrl)|HALT_NIC|RR_CLEAR_INT,
®s->HostCtrl);
wmb();
break;
case E_TX_INV_BUF:
printk(KERN_ERR "%s: Invalid send buffer address\n",
dev->name);
writel(readl(®s->HostCtrl)|HALT_NIC|RR_CLEAR_INT,
®s->HostCtrl);
wmb();
break;
case E_TX_INV_DSC:
printk(KERN_ERR "%s: Invalid descriptor address\n",
dev->name);
writel(readl(®s->HostCtrl)|HALT_NIC|RR_CLEAR_INT,
®s->HostCtrl);
wmb();
break;
/*
* RX events.
*/
case E_RX_RNG_OUT:
printk(KERN_INFO "%s: Receive ring full\n", dev->name);
break;
case E_RX_PAR_ERR:
printk(KERN_WARNING "%s: Receive parity error\n",
dev->name);
goto drop;
case E_RX_LLRC_ERR:
printk(KERN_WARNING "%s: Receive LLRC error\n",
dev->name);
goto drop;
case E_PKT_LN_ERR:
printk(KERN_WARNING "%s: Receive packet length "
"error\n", dev->name);
goto drop;
case E_DTA_CKSM_ERR:
printk(KERN_WARNING "%s: Data checksum error\n",
dev->name);
goto drop;
case E_SHT_BST:
printk(KERN_WARNING "%s: Unexpected short burst "
"error\n", dev->name);
goto drop;
case E_STATE_ERR:
printk(KERN_WARNING "%s: Recv. state transition"
" error\n", dev->name);
goto drop;
case E_UNEXP_DATA:
printk(KERN_WARNING "%s: Unexpected data error\n",
dev->name);
goto drop;
case E_LST_LNK_ERR:
printk(KERN_WARNING "%s: Link lost error\n",
dev->name);
goto drop;
case E_FRM_ERR:
printk(KERN_WARNING "%s: Framing Error\n",
dev->name);
goto drop;
case E_FLG_SYN_ERR:
printk(KERN_WARNING "%s: Flag sync. lost during "
"packet\n", dev->name);
goto drop;
case E_RX_INV_BUF:
printk(KERN_ERR "%s: Invalid receive buffer "
"address\n", dev->name);
writel(readl(®s->HostCtrl)|HALT_NIC|RR_CLEAR_INT,
®s->HostCtrl);
wmb();
break;
case E_RX_INV_DSC:
printk(KERN_ERR "%s: Invalid receive descriptor "
"address\n", dev->name);
writel(readl(®s->HostCtrl)|HALT_NIC|RR_CLEAR_INT,
®s->HostCtrl);
wmb();
break;
case E_RNG_BLK:
printk(KERN_ERR "%s: Invalid ring block\n",
dev->name);
writel(readl(®s->HostCtrl)|HALT_NIC|RR_CLEAR_INT,
®s->HostCtrl);
wmb();
break;
drop:
/* Label packet to be dropped.
* Actual dropping occurs in rx
* handling.
*
* The index of packet we get to drop is
* the index of the packet following
* the bad packet. -kbf
*/
{
u16 index = rrpriv->evt_ring[eidx].index;
index = (index + (RX_RING_ENTRIES - 1)) %
RX_RING_ENTRIES;
rrpriv->rx_ring[index].mode |=
(PACKET_BAD | PACKET_END);
}
break;
default:
printk(KERN_WARNING "%s: Unhandled event 0x%02x\n",
dev->name, rrpriv->evt_ring[eidx].code);
}
eidx = (eidx + 1) % EVT_RING_ENTRIES;
}
rrpriv->info->evt_ctrl.pi = eidx;
wmb();
return eidx;
}
static void rx_int(struct net_device *dev, u32 rxlimit, u32 index)
{
struct rr_private *rrpriv = netdev_priv(dev);
struct rr_regs __iomem *regs = rrpriv->regs;
do {
struct rx_desc *desc;
u32 pkt_len;
desc = &(rrpriv->rx_ring[index]);
pkt_len = desc->size;
#if (DEBUG > 2)
printk("index %i, rxlimit %i\n", index, rxlimit);
printk("len %x, mode %x\n", pkt_len, desc->mode);
#endif
if ( (rrpriv->rx_ring[index].mode & PACKET_BAD) == PACKET_BAD){
dev->stats.rx_dropped++;
goto defer;
}
if (pkt_len > 0){
struct sk_buff *skb, *rx_skb;
rx_skb = rrpriv->rx_skbuff[index];
if (pkt_len < PKT_COPY_THRESHOLD) {
skb = alloc_skb(pkt_len, GFP_ATOMIC);
if (skb == NULL){
printk(KERN_WARNING "%s: Unable to allocate skb (%i bytes), deferring packet\n", dev->name, pkt_len);
dev->stats.rx_dropped++;
goto defer;
} else {
dma_sync_single_for_cpu(&rrpriv->pci_dev->dev,
desc->addr.addrlo,
pkt_len,
DMA_FROM_DEVICE);
skb_put_data(skb, rx_skb->data,
pkt_len);
dma_sync_single_for_device(&rrpriv->pci_dev->dev,
desc->addr.addrlo,
pkt_len,
DMA_FROM_DEVICE);
}
}else{
struct sk_buff *newskb;
newskb = alloc_skb(dev->mtu + HIPPI_HLEN,
GFP_ATOMIC);
if (newskb){
dma_addr_t addr;
dma_unmap_single(&rrpriv->pci_dev->dev,
desc->addr.addrlo,
dev->mtu + HIPPI_HLEN,
DMA_FROM_DEVICE);
skb = rx_skb;
skb_put(skb, pkt_len);
rrpriv->rx_skbuff[index] = newskb;
addr = dma_map_single(&rrpriv->pci_dev->dev,
newskb->data,
dev->mtu + HIPPI_HLEN,
DMA_FROM_DEVICE);
set_rraddr(&desc->addr, addr);
} else {
printk("%s: Out of memory, deferring "
"packet\n", dev->name);
dev->stats.rx_dropped++;
goto defer;
}