1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
18
19#include <linux/module.h>
20#include <linux/kernel.h>
21#include <linux/string.h>
22#include <linux/errno.h>
23#include <linux/ioport.h>
24#include <linux/slab.h>
25#include <linux/interrupt.h>
26#include <linux/pci.h>
27#include <linux/netdevice.h>
28#include <linux/etherdevice.h>
29#include <linux/skbuff.h>
30#include <linux/delay.h>
31#include <linux/init.h>
32#include <linux/bitops.h>
33
34#include <asm/uaccess.h>
35#include <asm/io.h>
36#ifdef CONFIG_NET_POLL_CONTROLLER
37#include <asm/irq.h>
38#endif
39
40#ifdef DEBUG
41#define enter(x) printk("Enter: %s, %s line %i\n",x,__FILE__,__LINE__)
42#define leave(x) printk("Leave: %s, %s line %i\n",x,__FILE__,__LINE__)
43#else
44#define enter(x) do {} while (0)
45#define leave(x) do {} while (0)
46#endif
47
48
49MODULE_DESCRIPTION("Xircom Cardbus ethernet driver");
50MODULE_AUTHOR("Arjan van de Ven <arjanv@redhat.com>");
51MODULE_LICENSE("GPL");
52
53
54
55
56#define CSR0 0x00
57#define CSR1 0x08
58#define CSR2 0x10
59#define CSR3 0x18
60#define CSR4 0x20
61#define CSR5 0x28
62#define CSR6 0x30
63#define CSR7 0x38
64#define CSR8 0x40
65#define CSR9 0x48
66#define CSR10 0x50
67#define CSR11 0x58
68#define CSR12 0x60
69#define CSR13 0x68
70#define CSR14 0x70
71#define CSR15 0x78
72#define CSR16 0x80
73
74
75#define PCI_POWERMGMT 0x40
76
77
78
79#define NUMDESCRIPTORS 4
80
81static int bufferoffsets[NUMDESCRIPTORS] = {128,2048,4096,6144};
82
83
84struct xircom_private {
85
86
87 __le32 *rx_buffer;
88 __le32 *tx_buffer;
89
90 dma_addr_t rx_dma_handle;
91 dma_addr_t tx_dma_handle;
92
93 struct sk_buff *tx_skb[4];
94
95 unsigned long io_port;
96 int open;
97
98
99
100 int transmit_used;
101
102
103
104
105
106 spinlock_t lock;
107
108 struct pci_dev *pdev;
109 struct net_device *dev;
110};
111
112
113
114static int xircom_probe(struct pci_dev *pdev, const struct pci_device_id *id);
115static void xircom_remove(struct pci_dev *pdev);
116static irqreturn_t xircom_interrupt(int irq, void *dev_instance);
117static netdev_tx_t xircom_start_xmit(struct sk_buff *skb,
118 struct net_device *dev);
119static int xircom_open(struct net_device *dev);
120static int xircom_close(struct net_device *dev);
121static void xircom_up(struct xircom_private *card);
122#ifdef CONFIG_NET_POLL_CONTROLLER
123static void xircom_poll_controller(struct net_device *dev);
124#endif
125
126static void investigate_read_descriptor(struct net_device *dev,struct xircom_private *card, int descnr, unsigned int bufferoffset);
127static void investigate_write_descriptor(struct net_device *dev, struct xircom_private *card, int descnr, unsigned int bufferoffset);
128static void read_mac_address(struct xircom_private *card);
129static void transceiver_voodoo(struct xircom_private *card);
130static void initialize_card(struct xircom_private *card);
131static void trigger_transmit(struct xircom_private *card);
132static void trigger_receive(struct xircom_private *card);
133static void setup_descriptors(struct xircom_private *card);
134static void remove_descriptors(struct xircom_private *card);
135static int link_status_changed(struct xircom_private *card);
136static void activate_receiver(struct xircom_private *card);
137static void deactivate_receiver(struct xircom_private *card);
138static void activate_transmitter(struct xircom_private *card);
139static void deactivate_transmitter(struct xircom_private *card);
140static void enable_transmit_interrupt(struct xircom_private *card);
141static void enable_receive_interrupt(struct xircom_private *card);
142static void enable_link_interrupt(struct xircom_private *card);
143static void disable_all_interrupts(struct xircom_private *card);
144static int link_status(struct xircom_private *card);
145
146
147
148static DEFINE_PCI_DEVICE_TABLE(xircom_pci_table) = {
149 {0x115D, 0x0003, PCI_ANY_ID, PCI_ANY_ID,},
150 {0,},
151};
152MODULE_DEVICE_TABLE(pci, xircom_pci_table);
153
154static struct pci_driver xircom_ops = {
155 .name = "xircom_cb",
156 .id_table = xircom_pci_table,
157 .probe = xircom_probe,
158 .remove = xircom_remove,
159 .suspend =NULL,
160 .resume =NULL
161};
162
163
164#ifdef DEBUG
165static void print_binary(unsigned int number)
166{
167 int i,i2;
168 char buffer[64];
169 memset(buffer,0,64);
170 i2=0;
171 for (i=31;i>=0;i--) {
172 if (number & (1<<i))
173 buffer[i2++]='1';
174 else
175 buffer[i2++]='0';
176 if ((i&3)==0)
177 buffer[i2++]=' ';
178 }
179 printk("%s\n",buffer);
180}
181#endif
182
183static const struct net_device_ops netdev_ops = {
184 .ndo_open = xircom_open,
185 .ndo_stop = xircom_close,
186 .ndo_start_xmit = xircom_start_xmit,
187 .ndo_change_mtu = eth_change_mtu,
188 .ndo_set_mac_address = eth_mac_addr,
189 .ndo_validate_addr = eth_validate_addr,
190#ifdef CONFIG_NET_POLL_CONTROLLER
191 .ndo_poll_controller = xircom_poll_controller,
192#endif
193};
194
195
196
197
198
199
200
201
202static int __devinit xircom_probe(struct pci_dev *pdev, const struct pci_device_id *id)
203{
204 struct net_device *dev = NULL;
205 struct xircom_private *private;
206 unsigned long flags;
207 unsigned short tmp16;
208 enter("xircom_probe");
209
210
211
212 if (pci_enable_device(pdev))
213 return -ENODEV;
214
215
216 pci_write_config_dword(pdev, PCI_POWERMGMT, 0x0000);
217
218 pci_set_master(pdev);
219
220
221 pci_read_config_word (pdev,PCI_STATUS, &tmp16);
222 pci_write_config_word (pdev, PCI_STATUS,tmp16);
223
224 if (!request_region(pci_resource_start(pdev, 0), 128, "xircom_cb")) {
225 pr_err("%s: failed to allocate io-region\n", __func__);
226 return -ENODEV;
227 }
228
229
230
231
232
233
234 dev = alloc_etherdev(sizeof(struct xircom_private));
235 if (!dev) {
236 pr_err("%s: failed to allocate etherdev\n", __func__);
237 goto device_fail;
238 }
239 private = netdev_priv(dev);
240
241
242 private->rx_buffer = pci_alloc_consistent(pdev,8192,&private->rx_dma_handle);
243 if (private->rx_buffer == NULL) {
244 pr_err("%s: no memory for rx buffer\n", __func__);
245 goto rx_buf_fail;
246 }
247 private->tx_buffer = pci_alloc_consistent(pdev,8192,&private->tx_dma_handle);
248 if (private->tx_buffer == NULL) {
249 pr_err("%s: no memory for tx buffer\n", __func__);
250 goto tx_buf_fail;
251 }
252
253 SET_NETDEV_DEV(dev, &pdev->dev);
254
255
256 private->dev = dev;
257 private->pdev = pdev;
258 private->io_port = pci_resource_start(pdev, 0);
259 spin_lock_init(&private->lock);
260 dev->irq = pdev->irq;
261 dev->base_addr = private->io_port;
262
263 initialize_card(private);
264 read_mac_address(private);
265 setup_descriptors(private);
266
267 dev->netdev_ops = &netdev_ops;
268 pci_set_drvdata(pdev, dev);
269
270 if (register_netdev(dev)) {
271 pr_err("%s: netdevice registration failed\n", __func__);
272 goto reg_fail;
273 }
274
275 dev_info(&dev->dev, "Xircom cardbus revision %i at irq %i\n",
276 pdev->revision, pdev->irq);
277
278
279 transceiver_voodoo(private);
280
281 spin_lock_irqsave(&private->lock,flags);
282 activate_transmitter(private);
283 activate_receiver(private);
284 spin_unlock_irqrestore(&private->lock,flags);
285
286 trigger_receive(private);
287
288 leave("xircom_probe");
289 return 0;
290
291reg_fail:
292 kfree(private->tx_buffer);
293tx_buf_fail:
294 kfree(private->rx_buffer);
295rx_buf_fail:
296 free_netdev(dev);
297device_fail:
298 return -ENODEV;
299}
300
301
302
303
304
305
306
307
308static void __devexit xircom_remove(struct pci_dev *pdev)
309{
310 struct net_device *dev = pci_get_drvdata(pdev);
311 struct xircom_private *card = netdev_priv(dev);
312
313 enter("xircom_remove");
314 pci_free_consistent(pdev,8192,card->rx_buffer,card->rx_dma_handle);
315 pci_free_consistent(pdev,8192,card->tx_buffer,card->tx_dma_handle);
316
317 release_region(dev->base_addr, 128);
318 unregister_netdev(dev);
319 free_netdev(dev);
320 pci_set_drvdata(pdev, NULL);
321 leave("xircom_remove");
322}
323
324static irqreturn_t xircom_interrupt(int irq, void *dev_instance)
325{
326 struct net_device *dev = (struct net_device *) dev_instance;
327 struct xircom_private *card = netdev_priv(dev);
328 unsigned int status;
329 int i;
330
331 enter("xircom_interrupt\n");
332
333 spin_lock(&card->lock);
334 status = inl(card->io_port+CSR5);
335
336#ifdef DEBUG
337 print_binary(status);
338 printk("tx status 0x%08x 0x%08x\n",
339 card->tx_buffer[0], card->tx_buffer[4]);
340 printk("rx status 0x%08x 0x%08x\n",
341 card->rx_buffer[0], card->rx_buffer[4]);
342#endif
343
344 if (status == 0 || status == 0xffffffff) {
345 spin_unlock(&card->lock);
346 return IRQ_NONE;
347 }
348
349 if (link_status_changed(card)) {
350 int newlink;
351 printk(KERN_DEBUG "xircom_cb: Link status has changed\n");
352 newlink = link_status(card);
353 dev_info(&dev->dev, "Link is %i mbit\n", newlink);
354 if (newlink)
355 netif_carrier_on(dev);
356 else
357 netif_carrier_off(dev);
358
359 }
360
361
362 status |= 0xffffffff;
363
364 outl(status,card->io_port+CSR5);
365
366
367 for (i=0;i<NUMDESCRIPTORS;i++)
368 investigate_write_descriptor(dev,card,i,bufferoffsets[i]);
369 for (i=0;i<NUMDESCRIPTORS;i++)
370 investigate_read_descriptor(dev,card,i,bufferoffsets[i]);
371
372
373 spin_unlock(&card->lock);
374 leave("xircom_interrupt");
375 return IRQ_HANDLED;
376}
377
378static netdev_tx_t xircom_start_xmit(struct sk_buff *skb,
379 struct net_device *dev)
380{
381 struct xircom_private *card;
382 unsigned long flags;
383 int nextdescriptor;
384 int desc;
385 enter("xircom_start_xmit");
386
387 card = netdev_priv(dev);
388 spin_lock_irqsave(&card->lock,flags);
389
390
391 for (desc=0;desc<NUMDESCRIPTORS;desc++)
392 investigate_write_descriptor(dev,card,desc,bufferoffsets[desc]);
393
394
395 nextdescriptor = (card->transmit_used +1) % (NUMDESCRIPTORS);
396 desc = card->transmit_used;
397
398
399 if (card->tx_buffer[4*desc]==0) {
400
401
402
403 memset(&card->tx_buffer[bufferoffsets[desc]/4],0,1536);
404 skb_copy_from_linear_data(skb,
405 &(card->tx_buffer[bufferoffsets[desc] / 4]),
406 skb->len);
407
408
409
410 card->tx_buffer[4*desc+1] = cpu_to_le32(skb->len);
411 if (desc == NUMDESCRIPTORS - 1)
412 card->tx_buffer[4*desc+1] |= cpu_to_le32(1<<25);
413
414 card->tx_buffer[4*desc+1] |= cpu_to_le32(0xF0000000);
415
416 card->tx_skb[desc] = skb;
417
418 wmb();
419
420 card->tx_buffer[4*desc] = cpu_to_le32(0x80000000);
421 trigger_transmit(card);
422 if (card->tx_buffer[nextdescriptor*4] & cpu_to_le32(0x8000000)) {
423
424 netif_stop_queue(dev);
425 }
426 card->transmit_used = nextdescriptor;
427 leave("xircom-start_xmit - sent");
428 spin_unlock_irqrestore(&card->lock,flags);
429 return NETDEV_TX_OK;
430 }
431
432
433
434
435 netif_stop_queue(dev);
436 spin_unlock_irqrestore(&card->lock,flags);
437 trigger_transmit(card);
438
439 return NETDEV_TX_BUSY;
440}
441
442
443
444
445static int xircom_open(struct net_device *dev)
446{
447 struct xircom_private *xp = netdev_priv(dev);
448 int retval;
449 enter("xircom_open");
450 pr_info("xircom cardbus adaptor found, registering as %s, using irq %i\n",
451 dev->name, dev->irq);
452 retval = request_irq(dev->irq, xircom_interrupt, IRQF_SHARED, dev->name, dev);
453 if (retval) {
454 leave("xircom_open - No IRQ");
455 return retval;
456 }
457
458 xircom_up(xp);
459 xp->open = 1;
460 leave("xircom_open");
461 return 0;
462}
463
464static int xircom_close(struct net_device *dev)
465{
466 struct xircom_private *card;
467 unsigned long flags;
468
469 enter("xircom_close");
470 card = netdev_priv(dev);
471 netif_stop_queue(dev);
472
473
474 spin_lock_irqsave(&card->lock,flags);
475
476 disable_all_interrupts(card);
477#if 0
478
479 deactivate_receiver(card);
480 deactivate_transmitter(card);
481#endif
482 remove_descriptors(card);
483
484 spin_unlock_irqrestore(&card->lock,flags);
485
486 card->open = 0;
487 free_irq(dev->irq,dev);
488
489 leave("xircom_close");
490
491 return 0;
492
493}
494
495
496#ifdef CONFIG_NET_POLL_CONTROLLER
497static void xircom_poll_controller(struct net_device *dev)
498{
499 disable_irq(dev->irq);
500 xircom_interrupt(dev->irq, dev);
501 enable_irq(dev->irq);
502}
503#endif
504
505
506static void initialize_card(struct xircom_private *card)
507{
508 unsigned int val;
509 unsigned long flags;
510 enter("initialize_card");
511
512
513 spin_lock_irqsave(&card->lock, flags);
514
515
516 val = inl(card->io_port + CSR0);
517 val |= 0x01;
518 outl(val, card->io_port + CSR0);
519
520 udelay(100);
521
522 val = inl(card->io_port + CSR0);
523 val &= ~0x01;
524 outl(val, card->io_port + CSR0);
525
526
527 val = 0;
528
529 outl(val, card->io_port + CSR0);
530
531
532 disable_all_interrupts(card);
533 deactivate_receiver(card);
534 deactivate_transmitter(card);
535
536 spin_unlock_irqrestore(&card->lock, flags);
537
538 leave("initialize_card");
539}
540
541
542
543
544
545
546
547static void trigger_transmit(struct xircom_private *card)
548{
549 unsigned int val;
550 enter("trigger_transmit");
551
552 val = 0;
553 outl(val, card->io_port + CSR1);
554
555 leave("trigger_transmit");
556}
557
558
559
560
561
562
563
564
565static void trigger_receive(struct xircom_private *card)
566{
567 unsigned int val;
568 enter("trigger_receive");
569
570 val = 0;
571 outl(val, card->io_port + CSR2);
572
573 leave("trigger_receive");
574}
575
576
577
578
579
580static void setup_descriptors(struct xircom_private *card)
581{
582 u32 address;
583 int i;
584 enter("setup_descriptors");
585
586
587 BUG_ON(card->rx_buffer == NULL);
588 BUG_ON(card->tx_buffer == NULL);
589
590
591 memset(card->rx_buffer, 0, 128);
592 for (i=0;i<NUMDESCRIPTORS;i++ ) {
593
594
595 card->rx_buffer[i*4 + 0] = cpu_to_le32(0x80000000);
596
597 card->rx_buffer[i*4 + 1] = cpu_to_le32(1536);
598 if (i == NUMDESCRIPTORS - 1)
599 card->rx_buffer[i*4 + 1] |= cpu_to_le32(1 << 25);
600
601
602
603
604 address = card->rx_dma_handle;
605 card->rx_buffer[i*4 + 2] = cpu_to_le32(address + bufferoffsets[i]);
606
607 card->rx_buffer[i*4 + 3] = 0;
608 }
609
610 wmb();
611
612 address = card->rx_dma_handle;
613 outl(address, card->io_port + CSR3);
614
615
616
617 memset(card->tx_buffer, 0, 128);
618
619 for (i=0;i<NUMDESCRIPTORS;i++ ) {
620
621 card->tx_buffer[i*4 + 0] = 0x00000000;
622
623 card->tx_buffer[i*4 + 1] = cpu_to_le32(1536);
624 if (i == NUMDESCRIPTORS - 1)
625 card->tx_buffer[i*4 + 1] |= cpu_to_le32(1 << 25);
626
627
628
629 address = card->tx_dma_handle;
630 card->tx_buffer[i*4 + 2] = cpu_to_le32(address + bufferoffsets[i]);
631
632 card->tx_buffer[i*4 + 3] = 0;
633 }
634
635 wmb();
636
637 address = card->tx_dma_handle;
638 outl(address, card->io_port + CSR4);
639
640 leave("setup_descriptors");
641}
642
643
644
645
646
647static void remove_descriptors(struct xircom_private *card)
648{
649 unsigned int val;
650 enter("remove_descriptors");
651
652 val = 0;
653 outl(val, card->io_port + CSR3);
654 outl(val, card->io_port + CSR4);
655
656 leave("remove_descriptors");
657}
658
659
660
661
662
663
664
665static int link_status_changed(struct xircom_private *card)
666{
667 unsigned int val;
668 enter("link_status_changed");
669
670 val = inl(card->io_port + CSR5);
671
672 if ((val & (1 << 27)) == 0) {
673 leave("link_status_changed - nochange");
674 return 0;
675 }
676
677
678
679 val = (1 << 27);
680 outl(val, card->io_port + CSR5);
681
682 leave("link_status_changed - changed");
683 return 1;
684}
685
686
687
688
689
690
691static int transmit_active(struct xircom_private *card)
692{
693 unsigned int val;
694 enter("transmit_active");
695
696 val = inl(card->io_port + CSR5);
697
698 if ((val & (7 << 20)) == 0) {
699 leave("transmit_active - inactive");
700 return 0;
701 }
702
703 leave("transmit_active - active");
704 return 1;
705}
706
707
708
709
710
711static int receive_active(struct xircom_private *card)
712{
713 unsigned int val;
714 enter("receive_active");
715
716
717 val = inl(card->io_port + CSR5);
718
719 if ((val & (7 << 17)) == 0) {
720 leave("receive_active - inactive");
721 return 0;
722 }
723
724 leave("receive_active - active");
725 return 1;
726}
727
728
729
730
731
732
733
734
735
736
737
738static void activate_receiver(struct xircom_private *card)
739{
740 unsigned int val;
741 int counter;
742 enter("activate_receiver");
743
744
745 val = inl(card->io_port + CSR6);
746
747
748
749 if ((val&2) && (receive_active(card)))
750 return;
751
752
753 val = val & ~2;
754 outl(val, card->io_port + CSR6);
755
756 counter = 10;
757 while (counter > 0) {
758 if (!receive_active(card))
759 break;
760
761 udelay(50);
762 counter--;
763 if (counter <= 0)
764 pr_err("Receiver failed to deactivate\n");
765 }
766
767
768 val = inl(card->io_port + CSR6);
769 val = val | 2;
770 outl(val, card->io_port + CSR6);
771
772
773 counter = 10;
774 while (counter > 0) {
775 if (receive_active(card))
776 break;
777
778 udelay(50);
779 counter--;
780 if (counter <= 0)
781 pr_err("Receiver failed to re-activate\n");
782 }
783
784 leave("activate_receiver");
785}
786
787
788
789
790
791
792
793
794static void deactivate_receiver(struct xircom_private *card)
795{
796 unsigned int val;
797 int counter;
798 enter("deactivate_receiver");
799
800 val = inl(card->io_port + CSR6);
801 val = val & ~2;
802 outl(val, card->io_port + CSR6);
803
804 counter = 10;
805 while (counter > 0) {
806 if (!receive_active(card))
807 break;
808
809 udelay(50);
810 counter--;
811 if (counter <= 0)
812 pr_err("Receiver failed to deactivate\n");
813 }
814
815
816 leave("deactivate_receiver");
817}
818
819
820
821
822
823
824
825
826
827
828
829
830static void activate_transmitter(struct xircom_private *card)
831{
832 unsigned int val;
833 int counter;
834 enter("activate_transmitter");
835
836
837 val = inl(card->io_port + CSR6);
838
839
840
841 if ((val&(1<<13)) && (transmit_active(card)))
842 return;
843
844 val = val & ~(1 << 13);
845 outl(val, card->io_port + CSR6);
846
847 counter = 10;
848 while (counter > 0) {
849 if (!transmit_active(card))
850 break;
851
852 udelay(50);
853 counter--;
854 if (counter <= 0)
855 pr_err("Transmitter failed to deactivate\n");
856 }
857
858
859 val = inl(card->io_port + CSR6);
860 val = val | (1 << 13);
861 outl(val, card->io_port + CSR6);
862
863
864 counter = 10;
865 while (counter > 0) {
866 if (transmit_active(card))
867 break;
868
869 udelay(50);
870 counter--;
871 if (counter <= 0)
872 pr_err("Transmitter failed to re-activate\n");
873 }
874
875 leave("activate_transmitter");
876}
877
878
879
880
881
882
883
884
885static void deactivate_transmitter(struct xircom_private *card)
886{
887 unsigned int val;
888 int counter;
889 enter("deactivate_transmitter");
890
891 val = inl(card->io_port + CSR6);
892 val = val & ~2;
893 outl(val, card->io_port + CSR6);
894
895 counter = 20;
896 while (counter > 0) {
897 if (!transmit_active(card))
898 break;
899
900 udelay(50);
901 counter--;
902 if (counter <= 0)
903 pr_err("Transmitter failed to deactivate\n");
904 }
905
906
907 leave("deactivate_transmitter");
908}
909
910
911
912
913
914
915
916static void enable_transmit_interrupt(struct xircom_private *card)
917{
918 unsigned int val;
919 enter("enable_transmit_interrupt");
920
921 val = inl(card->io_port + CSR7);
922 val |= 1;
923 outl(val, card->io_port + CSR7);
924
925 leave("enable_transmit_interrupt");
926}
927
928
929
930
931
932
933
934static void enable_receive_interrupt(struct xircom_private *card)
935{
936 unsigned int val;
937 enter("enable_receive_interrupt");
938
939 val = inl(card->io_port + CSR7);
940 val = val | (1 << 6);
941 outl(val, card->io_port + CSR7);
942
943 leave("enable_receive_interrupt");
944}
945
946
947
948
949
950
951static void enable_link_interrupt(struct xircom_private *card)
952{
953 unsigned int val;
954 enter("enable_link_interrupt");
955
956 val = inl(card->io_port + CSR7);
957 val = val | (1 << 27);
958 outl(val, card->io_port + CSR7);
959
960 leave("enable_link_interrupt");
961}
962
963
964
965
966
967
968
969
970static void disable_all_interrupts(struct xircom_private *card)
971{
972 unsigned int val;
973 enter("enable_all_interrupts");
974
975 val = 0;
976 outl(val, card->io_port + CSR7);
977
978 leave("disable_all_interrupts");
979}
980
981
982
983
984
985
986static void enable_common_interrupts(struct xircom_private *card)
987{
988 unsigned int val;
989 enter("enable_link_interrupt");
990
991 val = inl(card->io_port + CSR7);
992 val |= (1<<16);
993 val |= (1<<15);
994 val |= (1<<13);
995 val |= (1<<8);
996 val |= (1<<7);
997 val |= (1<<5);
998 val |= (1<<2);
999 val |= (1<<1);
1000 outl(val, card->io_port + CSR7);
1001
1002 leave("enable_link_interrupt");
1003}
1004
1005
1006
1007
1008
1009
1010static int enable_promisc(struct xircom_private *card)
1011{
1012 unsigned int val;
1013 enter("enable_promisc");
1014
1015 val = inl(card->io_port + CSR6);
1016 val = val | (1 << 6);
1017 outl(val, card->io_port + CSR6);
1018
1019 leave("enable_promisc");
1020 return 1;
1021}
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031static int link_status(struct xircom_private *card)
1032{
1033 unsigned int val;
1034 enter("link_status");
1035
1036 val = inb(card->io_port + CSR12);
1037
1038 if (!(val&(1<<2)))
1039 return 10;
1040 if (!(val&(1<<1)))
1041 return 100;
1042
1043
1044
1045 leave("link_status");
1046 return 0;
1047}
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058static void read_mac_address(struct xircom_private *card)
1059{
1060 unsigned char j, tuple, link, data_id, data_count;
1061 unsigned long flags;
1062 int i;
1063
1064 enter("read_mac_address");
1065
1066 spin_lock_irqsave(&card->lock, flags);
1067
1068 outl(1 << 12, card->io_port + CSR9);
1069 for (i = 0x100; i < 0x1f7; i += link + 2) {
1070 outl(i, card->io_port + CSR10);
1071 tuple = inl(card->io_port + CSR9) & 0xff;
1072 outl(i + 1, card->io_port + CSR10);
1073 link = inl(card->io_port + CSR9) & 0xff;
1074 outl(i + 2, card->io_port + CSR10);
1075 data_id = inl(card->io_port + CSR9) & 0xff;
1076 outl(i + 3, card->io_port + CSR10);
1077 data_count = inl(card->io_port + CSR9) & 0xff;
1078 if ((tuple == 0x22) && (data_id == 0x04) && (data_count == 0x06)) {
1079
1080
1081
1082 for (j = 0; j < 6; j++) {
1083 outl(i + j + 4, card->io_port + CSR10);
1084 card->dev->dev_addr[j] = inl(card->io_port + CSR9) & 0xff;
1085 }
1086 break;
1087 } else if (link == 0) {
1088 break;
1089 }
1090 }
1091 spin_unlock_irqrestore(&card->lock, flags);
1092 pr_debug(" %pM\n", card->dev->dev_addr);
1093 leave("read_mac_address");
1094}
1095
1096
1097
1098
1099
1100
1101
1102static void transceiver_voodoo(struct xircom_private *card)
1103{
1104 unsigned long flags;
1105
1106 enter("transceiver_voodoo");
1107
1108
1109 pci_write_config_dword(card->pdev, PCI_POWERMGMT, 0x0000);
1110
1111 setup_descriptors(card);
1112
1113 spin_lock_irqsave(&card->lock, flags);
1114
1115 outl(0x0008, card->io_port + CSR15);
1116 udelay(25);
1117 outl(0xa8050000, card->io_port + CSR15);
1118 udelay(25);
1119 outl(0xa00f0000, card->io_port + CSR15);
1120 udelay(25);
1121
1122 spin_unlock_irqrestore(&card->lock, flags);
1123
1124 netif_start_queue(card->dev);
1125 leave("transceiver_voodoo");
1126}
1127
1128
1129static void xircom_up(struct xircom_private *card)
1130{
1131 unsigned long flags;
1132 int i;
1133
1134 enter("xircom_up");
1135
1136
1137 pci_write_config_dword(card->pdev, PCI_POWERMGMT, 0x0000);
1138
1139 setup_descriptors(card);
1140
1141 spin_lock_irqsave(&card->lock, flags);
1142
1143
1144 enable_link_interrupt(card);
1145 enable_transmit_interrupt(card);
1146 enable_receive_interrupt(card);
1147 enable_common_interrupts(card);
1148 enable_promisc(card);
1149
1150
1151 for (i=0;i<NUMDESCRIPTORS;i++)
1152 investigate_read_descriptor(card->dev,card,i,bufferoffsets[i]);
1153
1154
1155 spin_unlock_irqrestore(&card->lock, flags);
1156 trigger_receive(card);
1157 trigger_transmit(card);
1158 netif_start_queue(card->dev);
1159 leave("xircom_up");
1160}
1161
1162
1163static void investigate_read_descriptor(struct net_device *dev,struct xircom_private *card, int descnr, unsigned int bufferoffset)
1164{
1165 int status;
1166
1167 enter("investigate_read_descriptor");
1168 status = le32_to_cpu(card->rx_buffer[4*descnr]);
1169
1170 if ((status > 0)) {
1171
1172
1173
1174 short pkt_len = ((status >> 16) & 0x7ff) - 4;
1175 struct sk_buff *skb;
1176
1177 if (pkt_len > 1518) {
1178 pr_err("Packet length %i is bogus\n", pkt_len);
1179 pkt_len = 1518;
1180 }
1181
1182 skb = dev_alloc_skb(pkt_len + 2);
1183 if (skb == NULL) {
1184 dev->stats.rx_dropped++;
1185 goto out;
1186 }
1187 skb_reserve(skb, 2);
1188 skb_copy_to_linear_data(skb, (unsigned char*)&card->rx_buffer[bufferoffset / 4], pkt_len);
1189 skb_put(skb, pkt_len);
1190 skb->protocol = eth_type_trans(skb, dev);
1191 netif_rx(skb);
1192 dev->stats.rx_packets++;
1193 dev->stats.rx_bytes += pkt_len;
1194
1195 out:
1196
1197 card->rx_buffer[4*descnr] = cpu_to_le32(0x80000000);
1198 trigger_receive(card);
1199 }
1200
1201 leave("investigate_read_descriptor");
1202
1203}
1204
1205
1206
1207static void investigate_write_descriptor(struct net_device *dev, struct xircom_private *card, int descnr, unsigned int bufferoffset)
1208{
1209 int status;
1210
1211 enter("investigate_write_descriptor");
1212
1213 status = le32_to_cpu(card->tx_buffer[4*descnr]);
1214#if 0
1215 if (status & 0x8000) {
1216 pr_err("Major transmit error status %x\n", status);
1217 card->tx_buffer[4*descnr] = 0;
1218 netif_wake_queue (dev);
1219 }
1220#endif
1221 if (status > 0) {
1222 if (card->tx_skb[descnr]!=NULL) {
1223 dev->stats.tx_bytes += card->tx_skb[descnr]->len;
1224 dev_kfree_skb_irq(card->tx_skb[descnr]);
1225 }
1226 card->tx_skb[descnr] = NULL;
1227
1228 if (status&(1<<8))
1229 dev->stats.collisions++;
1230 card->tx_buffer[4*descnr] = 0;
1231 netif_wake_queue (dev);
1232 dev->stats.tx_packets++;
1233 }
1234
1235 leave("investigate_write_descriptor");
1236
1237}
1238
1239
1240static int __init xircom_init(void)
1241{
1242 return pci_register_driver(&xircom_ops);
1243}
1244
1245static void __exit xircom_exit(void)
1246{
1247 pci_unregister_driver(&xircom_ops);
1248}
1249
1250module_init(xircom_init)
1251module_exit(xircom_exit)
1252
1253