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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
|
/*
* Linux device driver for
* Broadcom BCM47XX 10/100 Mbps Ethernet Controller
*
* Copyright 2007, Broadcom Corporation
* All Rights Reserved.
*
* This is UNPUBLISHED PROPRIETARY SOURCE CODE of Broadcom Corporation;
* the contents of this file may not be disclosed to third parties, copied
* or duplicated in any form, in whole or in part, without the prior
* written permission of Broadcom Corporation.
*
* $Id: et_linux.c,v 1.1.1.1 2008/07/21 09:14:16 james26_jang Exp $
*/
#define __UNDEF_NO_VERSION__
#include <typedefs.h>
#include <linux/module.h>
#include <linuxver.h>
#include <bcmdefs.h>
#include <osl.h>
#include <linux/types.h>
#include <linux/errno.h>
#include <linux/pci.h>
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/netdevice.h>
#include <linux/etherdevice.h>
#include <linux/skbuff.h>
#include <linux/delay.h>
#include <linux/string.h>
#include <linux/sockios.h>
#ifdef SIOCETHTOOL
#include <linux/ethtool.h>
#endif /* SIOCETHTOOL */
#include <linux/ip.h>
#include <asm/system.h>
#include <asm/io.h>
#include <asm/irq.h>
#include <asm/pgtable.h>
#include <asm/uaccess.h>
#include <epivers.h>
#include <bcmendian.h>
#include <bcmdefs.h>
#include <proto/ethernet.h>
#include <proto/vlan.h>
#include <bcmdevs.h>
#include <bcmenetmib.h>
#include <bcmenetrxh.h>
#include <bcmenetphy.h>
#include <etioctl.h>
#include <bcmutils.h>
#include <pcicfg.h>
#include <et_dbg.h>
#include <etc.h>
#include <linux/proc_fs.h>
typedef struct et_info {
etc_info_t *etc; /* pointer to common os-independent data */
struct net_device *dev; /* backpoint to device */
struct pci_dev *pdev; /* backpoint to pci_dev */
void *osh; /* pointer to os handle */
spinlock_t lock; /* per-device perimeter lock */
struct sk_buff_head txq; /* send queue */
void *regsva; /* opaque chip registers virtual address */
struct timer_list timer; /* one second watchdog timer */
struct net_device_stats stats; /* stat counter reporting structure */
int events; /* bit channel between isr and dpc */
struct tasklet_struct tasklet; /* dpc tasklet */
struct et_info *next; /* pointer to next et_info_t in chain */
bool resched; /* dpc was rescheduled */
} et_info_t;
static int et_found = 0;
static et_info_t *et_list = NULL;
/* defines */
#define DATAHIWAT 50 /* data msg txq hiwat mark */
#define ET_INFO(dev) (et_info_t*)((dev)->priv)
#define ET_LOCK(et) spin_lock_bh(&(et)->lock)
#define ET_UNLOCK(et) spin_unlock_bh(&(et)->lock)
#define INT_LOCK(flags) local_irq_save(flags)
#define INT_UNLOCK(flags) local_irq_restore(flags)
#if LINUX_VERSION_CODE <= KERNEL_VERSION(2, 4, 5)
#error Linux version must be newer than 2.4.5
#endif /* LINUX_VERSION_CODE <= KERNEL_VERSION(2, 4, 5) */
/* prototypes called by etc.c */
void et_init(et_info_t *et);
void et_reset(et_info_t *et);
void et_link_up(et_info_t *et);
void et_link_down(et_info_t *et);
void et_up(et_info_t *et);
void et_down(et_info_t *et, int reset);
void et_dump(et_info_t *et, struct bcmstrbuf *b);
unsigned int etc_arl_dump(etc_info_t *etc, char *buffer, int maxno);
/* local prototypes */
static void et_free(et_info_t *et);
static int et_open(struct net_device *dev);
static int et_close(struct net_device *dev);
static int et_start(struct sk_buff *skb, struct net_device *dev);
static void et_sendnext(et_info_t *et);
static struct net_device_stats *et_get_stats(struct net_device *dev);
static int et_set_mac_address(struct net_device *dev, void *addr);
static void et_set_multicast_list(struct net_device *dev);
static void et_watchdog(ulong data);
static int et_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd);
static irqreturn_t et_isr(int irq, void *dev_id, struct pt_regs *ptregs);
static void et_dpc(ulong data);
static void et_sendup(et_info_t *et, struct sk_buff *skb);
/* recognized PCI IDs */
static struct pci_device_id et_id_table[] __devinitdata = {
{ vendor: PCI_ANY_ID,
device: PCI_ANY_ID,
subvendor: PCI_ANY_ID,
subdevice: PCI_ANY_ID,
class: PCI_CLASS_NETWORK_ETHERNET << 8,
class_mask: 0xffff00,
driver_data: 0,
},
{ 0, }
};
et_info_t *et_g=NULL;
MODULE_DEVICE_TABLE(pci, et_id_table);
static int __devinit
et_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
{
struct net_device *dev;
et_info_t *et;
osl_t *osh;
char name[128];
int unit = et_found;
ET_TRACE(("et%d: et_probe: bus %d slot %d func %d irq %d\n", unit,
pdev->bus->number, PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn), pdev->irq));
if (!etc_chipmatch(pdev->vendor, pdev->device))
return -ENODEV;
osh = osl_attach(pdev, PCI_BUS, FALSE);
ASSERT(osh);
pci_set_master(pdev);
pci_enable_device(pdev);
if (!(dev = (struct net_device *) MALLOC(osh, sizeof(struct net_device)))) {
ET_ERROR(("et%d: et_probe: out of memory, malloced %d bytes\n", unit,
MALLOCED(osh)));
osl_detach(osh);
return -ENOMEM;
}
bzero(dev, sizeof(struct net_device));
if (!init_etherdev(dev, 0)) {
ET_ERROR(("et%d: et_probe: init_etherdev() failed\n", unit));
MFREE(osh, dev, sizeof(struct net_device));
osl_detach(osh);
return -ENOMEM;
}
/* allocate private info */
if ((et = (et_info_t*) MALLOC(osh, sizeof(et_info_t))) == NULL) {
ET_ERROR(("et%d: et_probe: out of memory, malloced %d bytes\n", unit,
MALLOCED(osh)));
MFREE(osh, dev, sizeof(et_info_t));
osl_detach(osh);
return -ENOMEM;
}
bzero(et, sizeof(et_info_t));
dev->priv = (void*) et;
et->dev = dev;
et->pdev = pdev;
et->osh = osh;
pci_set_drvdata(pdev, et);
/* map chip registers (47xx: and sprom) */
dev->base_addr = pci_resource_start(pdev, 0);
if ((et->regsva = ioremap_nocache(dev->base_addr, PCI_BAR0_WINSZ)) == NULL) {
ET_ERROR(("et%d: ioremap() failed\n", unit));
goto fail;
}
spin_lock_init(&et->lock);
skb_queue_head_init(&et->txq);
/* common load-time initialization */
if ((et->etc = etc_attach((void*)et, pdev->vendor, pdev->device, unit, osh, et->regsva)) ==
NULL) {
ET_ERROR(("et%d: etc_attach() failed\n", unit));
goto fail;
}
bcopy(&et->etc->cur_etheraddr, dev->dev_addr, ETHER_ADDR_LEN);
/* init 1 second watchdog timer */
init_timer(&et->timer);
et->timer.data = (ulong)dev;
et->timer.function = et_watchdog;
/* setup the bottom half handler */
tasklet_init(&et->tasklet, et_dpc, (ulong)et);
/* register our interrupt handler */
if (request_irq(pdev->irq, et_isr, SA_SHIRQ, dev->name, et)) {
ET_ERROR(("et%d: request_irq() failed\n", unit));
goto fail;
}
dev->irq = pdev->irq;
/* add us to the global linked list */
et->next = et_list;
et_list = et;
/* print hello string */
(*et->etc->chops->longname)(et->etc->ch, name, sizeof(name));
printf("%s: %s %s\n", dev->name, name, EPI_VERSION_STR);
/* lastly, enable our entry points */
dev->open = et_open;
dev->stop = et_close;
dev->hard_start_xmit = et_start;
dev->get_stats = et_get_stats;
dev->set_mac_address = et_set_mac_address;
dev->set_multicast_list = et_set_multicast_list;
dev->do_ioctl = et_ioctl;
if (register_netdev(dev)) {
ET_ERROR(("et%d: register_netdev() failed\n", unit));
goto fail;
}
et_found++;
return (0);
fail:
et_free(et);
return (-ENODEV);
}
static int
et_suspend(struct pci_dev *pdev, u32 state)
{
et_info_t *et;
if ((et = (et_info_t *) pci_get_drvdata(pdev))) {
netif_device_detach(et->dev);
ET_LOCK(et);
et_down(et, 1);
ET_UNLOCK(et);
}
return 0;
}
static int
et_resume(struct pci_dev *pdev)
{
et_info_t *et;
if ((et = (et_info_t *) pci_get_drvdata(pdev))) {
ET_LOCK(et);
et_up(et);
ET_UNLOCK(et);
netif_device_attach(et->dev);
}
return 0;
}
/* Compatibility routines */
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 4, 6)
static void
_et_suspend(struct pci_dev *pdev)
{
et_suspend(pdev, 0);
}
static void
_et_resume(struct pci_dev *pdev)
{
et_resume(pdev);
}
#endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2, 4, 6) */
static void __devexit
et_remove(struct pci_dev *pdev)
{
et_info_t *et;
if (!etc_chipmatch(pdev->vendor, pdev->device))
return;
et_suspend(pdev, 0);
if ((et = (et_info_t *) pci_get_drvdata(pdev))) {
et_free(et);
pci_set_drvdata(pdev, NULL);
}
}
#define TBUFFER_LEN 32
#define TBUFFER_COUNT 96
static int et_arl_get_info(char *buffer, char **start, off_t offset, int length)
{
int len=0;
int size=0;
char tbuffer[TBUFFER_LEN*TBUFFER_COUNT];
if(!et_g || !et_g->etc) return 0;
len = sprintf(tbuffer,"[MAC Address] [PO][ST][EXT]\n");
/*XX:XX:XX:XX:XX:XX XX XX XX */
size = etc_arl_dump(et_g->etc, tbuffer+len, TBUFFER_COUNT);
len += size;
len += sprintf(tbuffer+len,"\n");
//printk("arl_get_info start %x %x %x\n", (int)offset, length, len);
strncpy(buffer, tbuffer, len+1);
//printk("*** test buffer %s. ***\n", buffer);
if(offset>len)
offset = len;
*start = buffer + offset; /* Start of wanted data */
if(offset+length>len)
length = len-offset;
//printk("arl_get_info %x %x\n", (int)offset, length);
//printk("\n%s\n", tbuffer);
return length;
}
static struct pci_driver et_pci_driver = {
name: "et",
probe: et_probe,
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 4, 6)
suspend: _et_suspend,
resume: _et_resume,
#else
suspend: et_suspend,
resume: et_resume,
#endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2, 4, 6) */
remove: __devexit_p(et_remove),
id_table: et_id_table,
};
static int __init
et_module_init(void)
{
proc_net_create ("arl", 0, et_arl_get_info);
return pci_module_init(&et_pci_driver);
}
static void __exit
et_module_exit(void)
{
pci_unregister_driver(&et_pci_driver);
}
module_init(et_module_init);
module_exit(et_module_exit);
static void
et_free(et_info_t *et)
{
et_info_t **prev;
osl_t *osh;
if (et == NULL)
return;
ET_TRACE(("et: et_free\n"));
if (et->dev && et->dev->irq)
free_irq(et->dev->irq, et);
if (et->dev) {
unregister_netdev(et->dev);
MFREE(et->osh, et->dev, sizeof(struct net_device));
et->dev = NULL;
}
/* free common resources */
if (et->etc) {
etc_detach(et->etc);
et->etc = NULL;
}
/*
* unregister_netdev() calls get_stats() which may read chip registers
* so we cannot unmap the chip registers until after calling unregister_netdev() .
*/
if (et->regsva) {
iounmap((void*)et->regsva);
et->regsva = NULL;
}
/* remove us from the global linked list */
for (prev = &et_list; *prev; prev = &(*prev)->next)
if (*prev == et) {
*prev = et->next;
break;
}
osh = et->osh;
MFREE(et->osh, et, sizeof(et_info_t));
ASSERT(MALLOCED(osh) == 0);
osl_detach(osh);
}
static int
et_open(struct net_device *dev)
{
et_info_t *et;
et = ET_INFO(dev);
et_g = et;
ET_TRACE(("et%d: et_open\n", et->etc->unit));
et->etc->promisc = (dev->flags & IFF_PROMISC)? TRUE: FALSE;
ET_LOCK(et);
et_up(et);
ET_UNLOCK(et);
OLD_MOD_INC_USE_COUNT;
return (0);
}
static int
et_close(struct net_device *dev)
{
et_info_t *et;
et = ET_INFO(dev);
et_g = NULL;
ET_TRACE(("et%d: et_close\n", et->etc->unit));
et->etc->promisc = FALSE;
ET_LOCK(et);
et_down(et, 1);
ET_UNLOCK(et);
OLD_MOD_DEC_USE_COUNT;
return (0);
}
/*
* Yeah, queueing the packets on a tx queue instead of throwing them
* directly into the descriptor ring in the case of dma is kinda lame,
* but this results in a unified transmit path for both dma and pio
* and localizes/simplifies the netif_*_queue semantics, too.
*/
static int
et_start(struct sk_buff *skb, struct net_device *dev)
{
et_info_t *et;
et = ET_INFO(dev);
ET_TRACE(("et%d: et_start: len %d\n", et->etc->unit, skb->len));
ET_LOG("et%d: et_start: len %d", et->etc->unit, skb->len);
ET_LOCK(et);
/* put it on the tx queue and call sendnext */
skb_queue_tail(&et->txq, skb);
et_sendnext(et);
ET_UNLOCK(et);
ET_LOG("et%d: et_start ret\n", et->etc->unit, 0);
return (0);
}
static void
et_sendnext(et_info_t *et)
{
etc_info_t *etc;
struct sk_buff *skb;
void *p;
etc = et->etc;
ET_TRACE(("et%d: et_sendnext\n", etc->unit));
ET_LOG("et%d: et_sendnext", etc->unit, 0);
/* dequeue and send each packet */
#ifdef DMA
while (*etc->txavail > 0) {
#else
while (etc->pioactive == NULL) {
#endif /* DMA */
if ((skb = skb_dequeue(&et->txq)) == NULL)
break;
ET_PRHDR("tx", (struct ether_header*) skb->data, skb->len, etc->unit);
ET_PRPKT("txpkt", skb->data, skb->len, etc->unit);
/* Convert the packet. */
if ((p = PKTFRMNATIVE(et->osh, skb)) == NULL) {
dev_kfree_skb_any(skb);
return;
}
(*etc->chops->tx)(etc->ch, p);
etc->txframe++;
etc->txbyte += skb->len;
}
/* stop the queue whenever txq fills */
if ((skb_queue_len(&et->txq) > DATAHIWAT) && !netif_queue_stopped(et->dev))
netif_stop_queue(et->dev);
else if (netif_queue_stopped(et->dev) && (skb_queue_len(&et->txq) < (DATAHIWAT/2))) {
netif_wake_queue(et->dev);
}
}
void
et_init(et_info_t *et)
{
ET_TRACE(("et%d: et_init\n", et->etc->unit));
ET_LOG("et%d: et_init", et->etc->unit, 0);
et_reset(et);
etc_init(et->etc);
}
void
et_reset(et_info_t *et)
{
ET_TRACE(("et%d: et_reset\n", et->etc->unit));
etc_reset(et->etc);
/* zap any pending dpc interrupt bits */
et->events = 0;
/* dpc will not be rescheduled */
et->resched = 0;
}
void
et_up(et_info_t *et)
{
etc_info_t *etc;
etc = et->etc;
if (etc->up)
return;
ET_TRACE(("et%d: et_up\n", etc->unit));
etc_up(etc);
/* schedule one second watchdog timer */
et->timer.expires = jiffies + HZ;
add_timer(&et->timer);
netif_start_queue(et->dev);
}
void
et_down(et_info_t *et, int reset)
{
etc_info_t *etc;
struct sk_buff *skb;
etc = et->etc;
ET_TRACE(("et%d: et_down\n", etc->unit));
netif_down(et->dev);
netif_stop_queue(et->dev);
/* stop watchdog timer */
del_timer(&et->timer);
etc_down(etc, reset);
/* flush the txq */
while ((skb = skb_dequeue(&et->txq)))
dev_kfree_skb_any(skb);
/* kill dpc */
ET_UNLOCK(et);
tasklet_kill(&et->tasklet);
ET_LOCK(et);
}
/*
* These are interrupt on/off entry points. Disable interrupts
* during interrupt state transition.
*/
void
et_intrson(et_info_t *et)
{
unsigned long flags;
INT_LOCK(flags);
(*et->etc->chops->intrson)(et->etc->ch);
INT_UNLOCK(flags);
}
static void
et_watchdog(ulong data)
{
et_info_t *et;
et = ET_INFO((struct net_device*)data);
ET_LOCK(et);
etc_watchdog(et->etc);
/* reschedule one second watchdog timer */
et->timer.expires = jiffies + HZ;
add_timer(&et->timer);
ET_UNLOCK(et);
}
#ifdef SIOCETHTOOL
static int
et_ethtool(et_info_t *et, struct ethtool_cmd *ecmd)
{
int ret = 0;
int speed;
struct ethtool_drvinfo *info;
ET_LOCK(et);
switch (ecmd->cmd) {
case ETHTOOL_GSET:
ecmd->supported = (SUPPORTED_10baseT_Half | SUPPORTED_10baseT_Full |
SUPPORTED_100baseT_Half | SUPPORTED_100baseT_Full |
SUPPORTED_Autoneg);
ecmd->advertising = ADVERTISED_TP;
ecmd->advertising |= (et->etc->advertise & ADV_10HALF) ?
ADVERTISED_10baseT_Half : 0;
ecmd->advertising |= (et->etc->advertise & ADV_10FULL) ?
ADVERTISED_10baseT_Full : 0;
ecmd->advertising |= (et->etc->advertise & ADV_100HALF) ?
ADVERTISED_100baseT_Half : 0;
ecmd->advertising |= (et->etc->advertise & ADV_100FULL) ?
ADVERTISED_100baseT_Full : 0;
if (et->etc->linkstate) {
ecmd->speed = (et->etc->speed == 100) ? SPEED_100 : SPEED_10;
ecmd->duplex = (et->etc->duplex == 1) ? DUPLEX_FULL : DUPLEX_HALF;
} else {
ecmd->speed = 0;
ecmd->duplex = 0;
}
ecmd->port = PORT_TP;
ecmd->phy_address = 0;
ecmd->transceiver = XCVR_INTERNAL;
ecmd->autoneg = (et->etc->forcespeed == ET_AUTO) ? AUTONEG_ENABLE : AUTONEG_DISABLE;
ecmd->maxtxpkt = 0;
ecmd->maxrxpkt = 0;
break;
case ETHTOOL_SSET:
if (!capable(CAP_NET_ADMIN)) {
ret = -EPERM;
break;
}
else if (ecmd->speed == SPEED_10 && ecmd->duplex == DUPLEX_HALF)
speed = ET_10HALF;
else if (ecmd->speed == SPEED_10 && ecmd->duplex == DUPLEX_FULL)
speed = ET_10FULL;
else if (ecmd->speed == SPEED_100 && ecmd->duplex == DUPLEX_HALF)
speed = ET_100HALF;
else if (ecmd->speed == SPEED_100 && ecmd->duplex == DUPLEX_FULL)
speed = ET_100FULL;
else if (ecmd->autoneg == AUTONEG_ENABLE)
speed = ET_AUTO;
else {
ret = -EINVAL;
break;
}
ret = etc_ioctl(et->etc, ETCSPEED, &speed);
break;
case ETHTOOL_GDRVINFO:
info = (struct ethtool_drvinfo *)ecmd;
bzero(info, sizeof(struct ethtool_drvinfo));
info->cmd = ETHTOOL_GDRVINFO;
sprintf(info->driver, "et%d", et->etc->unit);
strcpy(info->version, EPI_VERSION_STR);
break;
default:
ret = -EINVAL;
break;
}
ET_UNLOCK(et);
return (ret);
}
#endif /* SIOCETHTOOL */
static int
et_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
{
et_info_t *et;
int error;
char *buf;
int size;
bool get, set;
et = ET_INFO(dev);
ET_TRACE(("et%d: et_ioctl: cmd 0x%x\n", et->etc->unit, cmd));
switch (cmd) {
#ifdef SIOCETHTOOL
case SIOCETHTOOL:
if (((struct ethtool_cmd *)ifr->ifr_data)->cmd == ETHTOOL_GDRVINFO)
size = sizeof(struct ethtool_drvinfo);
else
size = sizeof(struct ethtool_cmd);
get = TRUE; set = TRUE;
break;
#endif /* SIOCETHTOOL */
case SIOCGETCDUMP:
size = 4096;
get = TRUE; set = FALSE;
break;
case SIOCGETCPHYRD:
case SIOCGETCPHYRD2:
case SIOCGETCROBORD:
size = sizeof(int) * 2;
get = TRUE; set = TRUE;
break;
case SIOCSETCPHYWR:
case SIOCSETCPHYWR2:
case SIOCSETCROBOWR:
size = sizeof(int) * 2;
get = FALSE; set = TRUE;
break;
default:
size = sizeof(int);
get = FALSE; set = TRUE;
break;
}
if ((buf = MALLOC(et->osh, size)) == NULL) {
ET_ERROR(("et: et_ioctl: out of memory, malloced %d bytes\n", MALLOCED(et->osh)));
return (-ENOMEM);
}
if (set && copy_from_user(buf, ifr->ifr_data, size)) {
MFREE(et->osh, buf, size);
return (-EFAULT);
}
switch (cmd) {
#ifdef SIOCETHTOOL
case SIOCETHTOOL:
error = et_ethtool(et, (struct ethtool_cmd*)buf);
break;
#endif /* SIOCETHTOOL */
default:
ET_LOCK(et);
error = etc_ioctl(et->etc, cmd - SIOCSETCUP, buf) ? -EINVAL : 0;
ET_UNLOCK(et);
break;
}
if (!error && get)
error = copy_to_user(ifr->ifr_data, buf, size);
MFREE(et->osh, buf, size);
return (error);
}
static struct net_device_stats*
et_get_stats(struct net_device *dev)
{
et_info_t *et;
etc_info_t *etc;
struct net_device_stats *stats;
et = ET_INFO(dev);
ET_TRACE(("et%d: et_get_stats\n", et->etc->unit));
ET_LOCK(et);
etc = et->etc;
stats = &et->stats;
bzero(stats, sizeof(struct net_device_stats));
/* refresh stats */
if (et->etc->up)
(*etc->chops->statsupd)(etc->ch);
/* SWAG */
stats->rx_packets = etc->rxframe;
stats->tx_packets = etc->txframe;
stats->rx_bytes = etc->rxbyte;
stats->tx_bytes = etc->txbyte;
stats->rx_errors = etc->rxerror;
stats->tx_errors = etc->txerror;
stats->collisions = etc->mib.tx_total_cols;
stats->rx_length_errors = (etc->mib.rx_oversize_pkts + etc->mib.rx_undersize);
stats->rx_over_errors = etc->rxoflo;
stats->rx_crc_errors = etc->mib.rx_crc_errs;
stats->rx_frame_errors = etc->mib.rx_align_errs;
stats->rx_fifo_errors = etc->rxoflo;
stats->rx_missed_errors = etc->mib.rx_missed_pkts;
stats->tx_fifo_errors = etc->txuflo;
ET_UNLOCK(et);
return (stats);
}
static int
et_set_mac_address(struct net_device *dev, void *addr)
{
et_info_t *et;
struct sockaddr *sa = (struct sockaddr *) addr;
et = ET_INFO(dev);
ET_TRACE(("et%d: et_set_mac_address\n", et->etc->unit));
if (et->etc->up)
return -EBUSY;
bcopy(sa->sa_data, dev->dev_addr, ETHER_ADDR_LEN);
bcopy(dev->dev_addr, &et->etc->cur_etheraddr, ETHER_ADDR_LEN);
return 0;
}
static void
et_set_multicast_list(struct net_device *dev)
{
et_info_t *et;
etc_info_t *etc;
struct dev_mc_list *mclist;
int i;
et = ET_INFO(dev);
etc = et->etc;
ET_TRACE(("et%d: et_set_multicast_list\n", etc->unit));
ET_LOCK(et);
if (etc->up) {
etc->promisc = (dev->flags & IFF_PROMISC)? TRUE: FALSE;
etc->allmulti = (dev->flags & IFF_ALLMULTI)? TRUE: FALSE;
/* copy the list of multicasts into our private table */
for (i = 0, mclist = dev->mc_list; mclist && (i < dev->mc_count);
i++, mclist = mclist->next) {
if (i >= MAXMULTILIST) {
etc->allmulti = TRUE;
i = 0;
break;
}
etc->multicast[i] = *((struct ether_addr*) mclist->dmi_addr);
}
etc->nmulticast = i;
et_init(et);
}
ET_UNLOCK(et);
}
static irqreturn_t
et_isr(int irq, void *dev_id, struct pt_regs *ptregs)
{
et_info_t *et;
struct chops *chops;
void *ch;
uint events = 0;
et = (et_info_t*) dev_id;
chops = et->etc->chops;
ch = et->etc->ch;
/* guard against shared interrupts */
if (!et->etc->up)
goto done;
/* get interrupt condition bits */
events = (*chops->getintrevents)(ch, TRUE);
/* not for us */
if (!(events & INTR_NEW))
goto done;
ET_TRACE(("et%d: et_isr: events 0x%x\n", et->etc->unit, events));
ET_LOG("et%d: et_isr: events 0x%x", et->etc->unit, events);
/* disable interrupts */
(*chops->intrsoff)(ch);
/* save intstatus bits */
ASSERT(et->events == 0);
et->events = events;
/* schedule dpc */
ASSERT(et->resched == FALSE);
tasklet_schedule(&et->tasklet);
done:
ET_LOG("et%d: et_isr ret", et->etc->unit, 0);
return IRQ_RETVAL(events & INTR_NEW);
}
static void
et_dpc(ulong data)
{
et_info_t *et;
struct chops *chops;
void *ch;
struct sk_buff *skb;
void *p;
osl_t *osh;
et = (et_info_t*) data;
chops = et->etc->chops;
ch = et->etc->ch;
osh = et->etc->osh;
ET_TRACE(("et%d: et_dpc: events 0x%x\n", et->etc->unit, et->events));
ET_LOG("et%d: et_dpc: events 0x%x", et->etc->unit, et->events);
ET_LOCK(et);
if (!et->etc->up)
goto done;
/* get interrupt condition bits again when dpc was rescheduled */
if (et->resched) {
et->events = (*chops->getintrevents)(ch, FALSE);
et->resched = FALSE;
}
if (et->events & INTR_RX) {
uint processed = 0;
while ((p = (*chops->rx)(ch))) {
skb = PKTTONATIVE(osh, p);
et_sendup(et, skb);
/* more frames, need to reschedule et_dpc() */
if (++processed >= RXBND) {
et->resched = TRUE;
break;
}
}
/* post more rx bufs */
(*chops->rxfill)(ch);
}
if (et->events & INTR_TX)
(*chops->txreclaim)(ch, FALSE);
/* handle error condtions, if reset required leave interrupts off! */
if (et->events & INTR_ERROR)
if ((*chops->errors)(ch))
et_init(et);
/* run the tx queue */
if (skb_queue_len(&et->txq) > 0)
et_sendnext(et);
/* clear this before re-enabling interrupts */
et->events = 0;
/* something may bring the driver down */
if (!et->etc->up) {
et->resched = FALSE;
goto done;
}
/* there may be frames left, reschedule et_dpc() */
if (et->resched)
tasklet_schedule(&et->tasklet);
/* re-enable interrupts */
else
(*chops->intrson)(ch);
done:
ET_UNLOCK(et);
ET_LOG("et%d: et_dpc ret", et->etc->unit, 0);
}
void
et_sendup(et_info_t *et, struct sk_buff *skb)
{
etc_info_t *etc;
bcmenetrxh_t *rxh;
uint16 flags;
uchar eabuf[32];
etc = et->etc;
/* packet buffer starts with rxhdr */
rxh = (bcmenetrxh_t*) skb->data;
/* strip off rxhdr */
skb_pull(skb, HWRXOFF);
ET_TRACE(("et%d: et_sendup: %d bytes\n", et->etc->unit, skb->len));
ET_LOG("et%d: et_sendup: len %d", et->etc->unit, skb->len);
etc->rxframe++;
etc->rxbyte += skb->len;
/* eh should now be aligned 2-mod-4 */
ASSERT(((uint)skb->data & 3) == 2);
/* strip off crc32 */
skb_trim(skb, skb->len - ETHER_CRC_LEN);
ET_PRHDR("rx", (struct ether_header*) skb->data, skb->len, etc->unit);
ET_PRPKT("rxpkt", skb->data, skb->len, etc->unit);
/* check for reported frame errors */
flags = ltoh16(rxh->flags);
if (flags & (RXF_NO | RXF_RXER | RXF_CRC | RXF_OV))
goto err;
/* Extract priority from payload and store it out-of-band in skb->priority */
if (et->etc->qos)
pktsetprio(skb, TRUE);
skb->dev = et->dev;
skb->protocol = eth_type_trans(skb, et->dev);
/* send it up */
netif_rx(skb);
ET_LOG("et%d: et_sendup ret", et->etc->unit, 0);
return;
err:
bcm_ether_ntoa((struct ether_addr*)((struct ether_header*)skb->data)->ether_shost, eabuf);
if (flags & RXF_NO) {
ET_ERROR(("et%d: rx: crc error (odd nibbles) from %s\n", etc->unit, eabuf));
}
if (flags & RXF_RXER) {
ET_ERROR(("et%d: rx: symbol error from %s\n", etc->unit, eabuf));
}
if ((flags & RXF_CRC) == RXF_CRC) {
ET_ERROR(("et%d: rx: crc error from %s\n", etc->unit, eabuf));
}
if (flags & RXF_OV) {
ET_ERROR(("et%d: rx: fifo overflow\n", etc->unit));
}
dev_kfree_skb_any(skb);
return;
}
void
et_dump(et_info_t *et, struct bcmstrbuf *b)
{
bcm_bprintf(b, "et%d: %s %s version %s\n", et->etc->unit,
__DATE__, __TIME__, EPI_VERSION_STR);
}
void
et_link_up(et_info_t *et)
{
ET_ERROR(("et%d: link up (%d%s)\n",
et->etc->unit, et->etc->speed, (et->etc->duplex? "FD" : "HD")));
}
void
et_link_down(et_info_t *et)
{
ET_ERROR(("et%d: link down\n", et->etc->unit));
}
/*
* 47XX-specific shared mdc/mdio contortion:
* Find the et associated with the same chip as <et>
* and coreunit matching <coreunit>.
*/
void*
et_phyfind(et_info_t *et, uint coreunit)
{
et_info_t *tmp;
uint bus, slot;
bus = et->pdev->bus->number;
slot = PCI_SLOT(et->pdev->devfn);
/* walk the list et's */
for (tmp = et_list; tmp; tmp = tmp->next) {
if (et->etc == NULL)
continue;
if (tmp->pdev == NULL)
continue;
if (tmp->pdev->bus->number != bus)
continue;
if (tmp->etc->nicmode)
if (PCI_SLOT(tmp->pdev->devfn) != slot)
continue;
if (tmp->etc->coreunit != coreunit)
continue;
break;
}
return (tmp);
}
/* shared phy read entry point */
uint16
et_phyrd(et_info_t *et, uint phyaddr, uint reg)
{
uint16 val;
ET_LOCK(et);
val = et->etc->chops->phyrd(et->etc->ch, phyaddr, reg);
ET_UNLOCK(et);
return (val);
}
/* shared phy write entry point */
void
et_phywr(et_info_t *et, uint phyaddr, uint reg, uint16 val)
{
ET_LOCK(et);
et->etc->chops->phywr(et->etc->ch, phyaddr, reg, val);
ET_UNLOCK(et);
}
|