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#include <linux/module.h>
67#include <linux/kernel.h>
68#include <linux/init.h>
69#include <linux/ptrace.h>
70#include <linux/slab.h>
71#include <linux/string.h>
72#include <linux/timer.h>
73#include <linux/interrupt.h>
74#include <linux/in.h>
75#include <linux/delay.h>
76#include <linux/ethtool.h>
77#include <linux/netdevice.h>
78#include <linux/etherdevice.h>
79#include <linux/skbuff.h>
80#include <linux/if_arp.h>
81#include <linux/ioport.h>
82
83#include <pcmcia/version.h>
84#include <pcmcia/cs_types.h>
85#include <pcmcia/cs.h>
86#include <pcmcia/cistpl.h>
87#include <pcmcia/cisreg.h>
88#include <pcmcia/ciscode.h>
89
90#include <asm/io.h>
91#include <asm/system.h>
92#include <asm/bitops.h>
93#include <asm/uaccess.h>
94
95#ifndef MANFID_COMPAQ
96 #define MANFID_COMPAQ 0x0138
97 #define MANFID_COMPAQ2 0x0183
98#endif
99
100#include <pcmcia/ds.h>
101
102
103#define TX_TIMEOUT ((400*HZ)/1000)
104
105
106
107
108
109
110#define XIRCREG_CR 0
111enum xirc_cr {
112 TransmitPacket = 0x01,
113 SoftReset = 0x02,
114 EnableIntr = 0x04,
115 ForceIntr = 0x08,
116 ClearTxFIFO = 0x10,
117 ClearRxOvrun = 0x20,
118 RestartTx = 0x40
119};
120#define XIRCREG_ESR 0
121enum xirc_esr {
122 FullPktRcvd = 0x01,
123 PktRejected = 0x04,
124 TxPktPend = 0x08,
125 IncorPolarity = 0x10,
126 MediaSelect = 0x20
127};
128#define XIRCREG_PR 1
129#define XIRCREG_EDP 4
130#define XIRCREG_ISR 6
131enum xirc_isr {
132 TxBufOvr = 0x01,
133 PktTxed = 0x02,
134 MACIntr = 0x04,
135 TxResGrant = 0x08,
136 RxFullPkt = 0x20,
137 RxPktRej = 0x40,
138 ForcedIntr= 0x80
139};
140#define XIRCREG1_IMR0 12
141#define XIRCREG1_IMR1 13
142#define XIRCREG0_TSO 8
143#define XIRCREG0_TRS 10
144#define XIRCREG0_DO 12
145#define XIRCREG0_RSR 12
146enum xirc_rsr {
147 PhyPkt = 0x01,
148 BrdcstPkt = 0x02,
149 PktTooLong = 0x04,
150 AlignErr = 0x10,
151 CRCErr = 0x20,
152 PktRxOk = 0x80
153};
154#define XIRCREG0_PTR 13
155#define XIRCREG0_RBC 14
156#define XIRCREG1_ECR 14
157enum xirc_ecr {
158 FullDuplex = 0x04,
159 LongTPMode = 0x08,
160 DisablePolCor = 0x10,
161 DisableLinkPulse = 0x20,
162 DisableAutoTx = 0x40,
163};
164#define XIRCREG2_RBS 8
165#define XIRCREG2_LED 10
166
167
168
169
170
171
172
173
174
175
176#define XIRCREG2_MSR 12
177
178#define XIRCREG4_GPR0 8
179#define XIRCREG4_GPR1 9
180#define XIRCREG2_GPR2 13
181#define XIRCREG4_BOV 10
182#define XIRCREG4_LMA 12
183#define XIRCREG4_LMD 14
184
185#define XIRCREG40_CMD0 8
186enum xirc_cmd {
187 Transmit = 0x01,
188 EnableRecv = 0x04,
189 DisableRecv = 0x08,
190 Abort = 0x10,
191 Online = 0x20,
192 IntrAck = 0x40,
193 Offline = 0x80
194};
195#define XIRCREG5_RHSA0 10
196#define XIRCREG40_RXST0 9
197#define XIRCREG40_TXST0 11
198#define XIRCREG40_TXST1 12
199#define XIRCREG40_RMASK0 13
200#define XIRCREG40_TMASK0 14
201#define XIRCREG40_TMASK1 15
202#define XIRCREG42_SWC0 8
203#define XIRCREG42_SWC1 9
204#define XIRCREG42_BOC 10
205#define XIRCREG44_TDR0 8
206#define XIRCREG44_TDR1 9
207#define XIRCREG44_RXBC_LO 10
208#define XIRCREG44_RXBC_HI 11
209#define XIRCREG45_REV 15
210#define XIRCREG50_IA 8
211
212static char *if_names[] = { "Auto", "10BaseT", "10Base2", "AUI", "100BaseT" };
213
214
215
216
217
218
219
220
221#ifdef PCMCIA_DEBUG
222static int pc_debug = PCMCIA_DEBUG;
223MODULE_PARM(pc_debug, "i");
224#define DEBUG(n, args...) if (pc_debug>(n)) printk(KDBG_XIRC args)
225#else
226#define DEBUG(n, args...)
227#endif
228
229#define KDBG_XIRC KERN_DEBUG "xirc2ps_cs: "
230#define KERR_XIRC KERN_ERR "xirc2ps_cs: "
231#define KWRN_XIRC KERN_WARNING "xirc2ps_cs: "
232#define KNOT_XIRC KERN_NOTICE "xirc2ps_cs: "
233#define KINF_XIRC KERN_INFO "xirc2ps_cs: "
234
235
236#define XIR_UNKNOWN 0
237#define XIR_CE 1
238#define XIR_CE2 2
239#define XIR_CE3 3
240#define XIR_CEM 4
241#define XIR_CEM2 5
242#define XIR_CEM3 6
243#define XIR_CEM33 7
244#define XIR_CEM56M 8
245#define XIR_CEM56 9
246#define XIR_CM28 10
247#define XIR_CM33 11
248#define XIR_CM56 12
249#define XIR_CG 13
250#define XIR_CBE 14
251
252
253
254
255MODULE_DESCRIPTION("Xircom PCMCIA ethernet driver");
256MODULE_LICENSE("Dual MPL/GPL");
257
258#define INT_MODULE_PARM(n, v) static int n = v; MODULE_PARM(n, "i")
259
260static int irq_list[4] = { -1 };
261MODULE_PARM(irq_list, "1-4i");
262INT_MODULE_PARM(irq_mask, 0xdeb8);
263INT_MODULE_PARM(if_port, 0);
264INT_MODULE_PARM(full_duplex, 0);
265INT_MODULE_PARM(do_sound, 1);
266INT_MODULE_PARM(lockup_hack, 0);
267
268
269
270
271
272
273
274
275
276
277static unsigned maxrx_bytes = 22000;
278
279
280static void mii_idle(ioaddr_t ioaddr);
281static void mii_putbit(ioaddr_t ioaddr, unsigned data);
282static int mii_getbit(ioaddr_t ioaddr);
283static void mii_wbits(ioaddr_t ioaddr, unsigned data, int len);
284static unsigned mii_rd(ioaddr_t ioaddr, u_char phyaddr, u_char phyreg);
285static void mii_wr(ioaddr_t ioaddr, u_char phyaddr, u_char phyreg,
286 unsigned data, int len);
287
288
289
290
291
292
293
294
295
296static int has_ce2_string(dev_link_t * link);
297static void xirc2ps_config(dev_link_t * link);
298static void xirc2ps_release(dev_link_t * link);
299static int xirc2ps_event(event_t event, int priority,
300 event_callback_args_t * args);
301
302
303
304
305
306
307
308static dev_link_t *xirc2ps_attach(void);
309static void xirc2ps_detach(dev_link_t *);
310
311
312
313
314
315
316
317
318static irqreturn_t xirc2ps_interrupt(int irq, void *dev_id, struct pt_regs *regs);
319
320
321
322
323
324
325
326static dev_info_t dev_info = "xirc2ps_cs";
327
328
329
330
331
332
333
334
335
336
337
338static dev_link_t *dev_list;
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357typedef struct local_info_t {
358 dev_link_t link;
359 dev_node_t node;
360 struct net_device_stats stats;
361 int card_type;
362 int probe_port;
363 int silicon;
364 int mohawk;
365 int dingo;
366 int new_mii;
367 int modem;
368 caddr_t dingo_ccr;
369 unsigned last_ptr_value;
370 const char *manf_str;
371} local_info_t;
372
373
374
375
376static int do_start_xmit(struct sk_buff *skb, struct net_device *dev);
377static void do_tx_timeout(struct net_device *dev);
378static struct net_device_stats *do_get_stats(struct net_device *dev);
379static void set_addresses(struct net_device *dev);
380static void set_multicast_list(struct net_device *dev);
381static int set_card_type(dev_link_t *link, const void *s);
382static int do_config(struct net_device *dev, struct ifmap *map);
383static int do_open(struct net_device *dev);
384static int do_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
385static struct ethtool_ops netdev_ethtool_ops;
386static void hardreset(struct net_device *dev);
387static void do_reset(struct net_device *dev, int full);
388static int init_mii(struct net_device *dev);
389static void do_powerdown(struct net_device *dev);
390static int do_stop(struct net_device *dev);
391
392
393static int
394get_tuple_data(int fn, client_handle_t handle, tuple_t *tuple)
395{
396 int err;
397
398 if ((err=CardServices(fn, handle, tuple)))
399 return err;
400 return CardServices(GetTupleData, handle, tuple);
401}
402
403static int
404get_tuple(int fn, client_handle_t handle, tuple_t *tuple, cisparse_t *parse)
405{
406 int err;
407
408 if ((err=get_tuple_data(fn, handle, tuple)))
409 return err;
410 return CardServices(ParseTuple, handle, tuple, parse);
411}
412
413#define first_tuple(a, b, c) get_tuple(GetFirstTuple, a, b, c)
414#define next_tuple(a, b, c) get_tuple(GetNextTuple, a, b, c)
415
416#define SelectPage(pgnr) outb((pgnr), ioaddr + XIRCREG_PR)
417#define GetByte(reg) ((unsigned)inb(ioaddr + (reg)))
418#define GetWord(reg) ((unsigned)inw(ioaddr + (reg)))
419#define PutByte(reg,value) outb((value), ioaddr+(reg))
420#define PutWord(reg,value) outw((value), ioaddr+(reg))
421
422#define Wait(n) do { \
423 set_current_state(TASK_UNINTERRUPTIBLE); \
424 schedule_timeout(n); \
425} while (0)
426
427
428#if defined(PCMCIA_DEBUG) && 0
429static void
430PrintRegisters(struct net_device *dev)
431{
432 ioaddr_t ioaddr = dev->base_addr;
433
434 if (pc_debug > 1) {
435 int i, page;
436
437 printk(KDBG_XIRC "Register common: ");
438 for (i = 0; i < 8; i++)
439 printk(" %2.2x", GetByte(i));
440 printk("\n");
441 for (page = 0; page <= 8; page++) {
442 printk(KDBG_XIRC "Register page %2x: ", page);
443 SelectPage(page);
444 for (i = 8; i < 16; i++)
445 printk(" %2.2x", GetByte(i));
446 printk("\n");
447 }
448 for (page=0x40 ; page <= 0x5f; page++) {
449 if (page == 0x43 || (page >= 0x46 && page <= 0x4f)
450 || (page >= 0x51 && page <=0x5e))
451 continue;
452 printk(KDBG_XIRC "Register page %2x: ", page);
453 SelectPage(page);
454 for (i = 8; i < 16; i++)
455 printk(" %2.2x", GetByte(i));
456 printk("\n");
457 }
458 }
459}
460#endif
461
462
463
464
465
466
467static void
468mii_idle(ioaddr_t ioaddr)
469{
470 PutByte(XIRCREG2_GPR2, 0x04|0);
471 udelay(1);
472 PutByte(XIRCREG2_GPR2, 0x04|1);
473 udelay(1);
474}
475
476
477
478
479static void
480mii_putbit(ioaddr_t ioaddr, unsigned data)
481{
482 #if 1
483 if (data) {
484 PutByte(XIRCREG2_GPR2, 0x0c|2|0);
485 udelay(1);
486 PutByte(XIRCREG2_GPR2, 0x0c|2|1);
487 udelay(1);
488 } else {
489 PutByte(XIRCREG2_GPR2, 0x0c|0|0);
490 udelay(1);
491 PutByte(XIRCREG2_GPR2, 0x0c|0|1);
492 udelay(1);
493 }
494 #else
495 if (data) {
496 PutWord(XIRCREG2_GPR2-1, 0x0e0e);
497 udelay(1);
498 PutWord(XIRCREG2_GPR2-1, 0x0f0f);
499 udelay(1);
500 } else {
501 PutWord(XIRCREG2_GPR2-1, 0x0c0c);
502 udelay(1);
503 PutWord(XIRCREG2_GPR2-1, 0x0d0d);
504 udelay(1);
505 }
506 #endif
507}
508
509
510
511
512static int
513mii_getbit(ioaddr_t ioaddr)
514{
515 unsigned d;
516
517 PutByte(XIRCREG2_GPR2, 4|0);
518 udelay(1);
519 d = GetByte(XIRCREG2_GPR2);
520 PutByte(XIRCREG2_GPR2, 4|1);
521 udelay(1);
522 return d & 0x20;
523}
524
525static void
526mii_wbits(ioaddr_t ioaddr, unsigned data, int len)
527{
528 unsigned m = 1 << (len-1);
529 for (; m; m >>= 1)
530 mii_putbit(ioaddr, data & m);
531}
532
533static unsigned
534mii_rd(ioaddr_t ioaddr, u_char phyaddr, u_char phyreg)
535{
536 int i;
537 unsigned data=0, m;
538
539 SelectPage(2);
540 for (i=0; i < 32; i++)
541 mii_putbit(ioaddr, 1);
542 mii_wbits(ioaddr, 0x06, 4);
543 mii_wbits(ioaddr, phyaddr, 5);
544 mii_wbits(ioaddr, phyreg, 5);
545 mii_idle(ioaddr);
546 mii_getbit(ioaddr);
547
548 for (m = 1<<15; m; m >>= 1)
549 if (mii_getbit(ioaddr))
550 data |= m;
551 mii_idle(ioaddr);
552 return data;
553}
554
555static void
556mii_wr(ioaddr_t ioaddr, u_char phyaddr, u_char phyreg, unsigned data, int len)
557{
558 int i;
559
560 SelectPage(2);
561 for (i=0; i < 32; i++)
562 mii_putbit(ioaddr, 1);
563 mii_wbits(ioaddr, 0x05, 4);
564 mii_wbits(ioaddr, phyaddr, 5);
565 mii_wbits(ioaddr, phyreg, 5);
566 mii_putbit(ioaddr, 1);
567 mii_putbit(ioaddr, 0);
568 mii_wbits(ioaddr, data, len);
569 mii_idle(ioaddr);
570}
571
572
573
574
575
576
577
578
579
580
581
582
583
584static dev_link_t *
585xirc2ps_attach(void)
586{
587 client_reg_t client_reg;
588 dev_link_t *link;
589 struct net_device *dev;
590 local_info_t *local;
591 int err;
592
593 DEBUG(0, "attach()\n");
594
595
596 dev = alloc_etherdev(sizeof(local_info_t));
597 if (!dev)
598 return NULL;
599 local = dev->priv;
600 link = &local->link;
601 link->priv = dev;
602
603
604 link->conf.Attributes = CONF_ENABLE_IRQ;
605 link->conf.Vcc = 50;
606 link->conf.IntType = INT_MEMORY_AND_IO;
607 link->conf.ConfigIndex = 1;
608 link->conf.Present = PRESENT_OPTION;
609 link->irq.Handler = xirc2ps_interrupt;
610 link->irq.Instance = dev;
611
612
613 SET_MODULE_OWNER(dev);
614 dev->hard_start_xmit = &do_start_xmit;
615 dev->set_config = &do_config;
616 dev->get_stats = &do_get_stats;
617 dev->do_ioctl = &do_ioctl;
618 SET_ETHTOOL_OPS(dev, &netdev_ethtool_ops);
619 dev->set_multicast_list = &set_multicast_list;
620 dev->open = &do_open;
621 dev->stop = &do_stop;
622#ifdef HAVE_TX_TIMEOUT
623 dev->tx_timeout = do_tx_timeout;
624 dev->watchdog_timeo = TX_TIMEOUT;
625#endif
626
627
628 link->next = dev_list;
629 dev_list = link;
630 client_reg.dev_info = &dev_info;
631 client_reg.Attributes = INFO_IO_CLIENT | INFO_CARD_SHARE;
632 client_reg.EventMask =
633 CS_EVENT_CARD_INSERTION | CS_EVENT_CARD_REMOVAL |
634 CS_EVENT_RESET_PHYSICAL | CS_EVENT_CARD_RESET |
635 CS_EVENT_PM_SUSPEND | CS_EVENT_PM_RESUME;
636 client_reg.event_handler = &xirc2ps_event;
637 client_reg.Version = 0x0210;
638 client_reg.event_callback_args.client_data = link;
639 if ((err = CardServices(RegisterClient, &link->handle, &client_reg))) {
640 cs_error(link->handle, RegisterClient, err);
641 xirc2ps_detach(link);
642 return NULL;
643 }
644
645 return link;
646}
647
648
649
650
651
652
653
654
655static void
656xirc2ps_detach(dev_link_t * link)
657{
658 struct net_device *dev = link->priv;
659 dev_link_t **linkp;
660
661 DEBUG(0, "detach(0x%p)\n", link);
662
663
664 for (linkp = &dev_list; *linkp; linkp = &(*linkp)->next)
665 if (*linkp == link)
666 break;
667 if (!*linkp) {
668 DEBUG(0, "detach(0x%p): dev_link lost\n", link);
669 return;
670 }
671
672
673
674
675
676
677
678 if (link->state & DEV_CONFIG)
679 xirc2ps_release(link);
680
681
682 if (link->handle)
683 CardServices(DeregisterClient, link->handle);
684
685
686 *linkp = link->next;
687 if (link->dev) {
688 unregister_netdev(dev);
689 free_netdev(dev);
690 } else
691 kfree(dev);
692
693}
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713static int
714set_card_type(dev_link_t *link, const void *s)
715{
716 struct net_device *dev = link->priv;
717 local_info_t *local = dev->priv;
718 #ifdef PCMCIA_DEBUG
719 unsigned cisrev = ((const unsigned char *)s)[2];
720 #endif
721 unsigned mediaid= ((const unsigned char *)s)[3];
722 unsigned prodid = ((const unsigned char *)s)[4];
723
724 DEBUG(0, "cisrev=%02x mediaid=%02x prodid=%02x\n",
725 cisrev, mediaid, prodid);
726
727 local->mohawk = 0;
728 local->dingo = 0;
729 local->modem = 0;
730 local->card_type = XIR_UNKNOWN;
731 if (!(prodid & 0x40)) {
732 printk(KNOT_XIRC "Ooops: Not a creditcard\n");
733 return 0;
734 }
735 if (!(mediaid & 0x01)) {
736 printk(KNOT_XIRC "Not an Ethernet card\n");
737 return 0;
738 }
739 if (mediaid & 0x10) {
740 local->modem = 1;
741 switch(prodid & 15) {
742 case 1: local->card_type = XIR_CEM ; break;
743 case 2: local->card_type = XIR_CEM2 ; break;
744 case 3: local->card_type = XIR_CEM3 ; break;
745 case 4: local->card_type = XIR_CEM33 ; break;
746 case 5: local->card_type = XIR_CEM56M;
747 local->mohawk = 1;
748 break;
749 case 6:
750 case 7:
751 local->card_type = XIR_CEM56 ;
752 local->mohawk = 1;
753 local->dingo = 1;
754 break;
755 }
756 } else {
757 switch(prodid & 15) {
758 case 1: local->card_type = has_ce2_string(link)? XIR_CE2 : XIR_CE ;
759 break;
760 case 2: local->card_type = XIR_CE2; break;
761 case 3: local->card_type = XIR_CE3;
762 local->mohawk = 1;
763 break;
764 }
765 }
766 if (local->card_type == XIR_CE || local->card_type == XIR_CEM) {
767 printk(KNOT_XIRC "Sorry, this is an old CE card\n");
768 return 0;
769 }
770 if (local->card_type == XIR_UNKNOWN)
771 printk(KNOT_XIRC "unknown card (mediaid=%02x prodid=%02x)\n",
772 mediaid, prodid);
773
774 return 1;
775}
776
777
778
779
780
781
782static int
783has_ce2_string(dev_link_t * link)
784{
785 client_handle_t handle = link->handle;
786 tuple_t tuple;
787 cisparse_t parse;
788 u_char buf[256];
789
790 tuple.Attributes = 0;
791 tuple.TupleData = buf;
792 tuple.TupleDataMax = 254;
793 tuple.TupleOffset = 0;
794 tuple.DesiredTuple = CISTPL_VERS_1;
795 if (!first_tuple(handle, &tuple, &parse) && parse.version_1.ns > 2) {
796 if (strstr(parse.version_1.str + parse.version_1.ofs[2], "CE2"))
797 return 1;
798 }
799 return 0;
800}
801
802
803
804
805
806
807static void
808xirc2ps_config(dev_link_t * link)
809{
810 client_handle_t handle = link->handle;
811 struct net_device *dev = link->priv;
812 local_info_t *local = dev->priv;
813 tuple_t tuple;
814 cisparse_t parse;
815 ioaddr_t ioaddr;
816 int err, i;
817 u_char buf[64];
818 cistpl_lan_node_id_t *node_id = (cistpl_lan_node_id_t*)parse.funce.data;
819 cistpl_cftable_entry_t *cf = &parse.cftable_entry;
820
821 local->dingo_ccr = 0;
822
823 DEBUG(0, "config(0x%p)\n", link);
824
825
826
827
828
829 tuple.Attributes = 0;
830 tuple.TupleData = buf;
831 tuple.TupleDataMax = 64;
832 tuple.TupleOffset = 0;
833
834
835 tuple.DesiredTuple = CISTPL_MANFID;
836 if ((err=first_tuple(handle, &tuple, &parse))) {
837 printk(KNOT_XIRC "manfid not found in CIS\n");
838 goto failure;
839 }
840
841 switch(parse.manfid.manf) {
842 case MANFID_XIRCOM:
843 local->manf_str = "Xircom";
844 break;
845 case MANFID_ACCTON:
846 local->manf_str = "Accton";
847 break;
848 case MANFID_COMPAQ:
849 case MANFID_COMPAQ2:
850 local->manf_str = "Compaq";
851 break;
852 case MANFID_INTEL:
853 local->manf_str = "Intel";
854 break;
855 case MANFID_TOSHIBA:
856 local->manf_str = "Toshiba";
857 break;
858 default:
859 printk(KNOT_XIRC "Unknown Card Manufacturer ID: 0x%04x\n",
860 (unsigned)parse.manfid.manf);
861 goto failure;
862 }
863 DEBUG(0, "found %s card\n", local->manf_str);
864
865 if (!set_card_type(link, buf)) {
866 printk(KNOT_XIRC "this card is not supported\n");
867 goto failure;
868 }
869
870
871 tuple.DesiredTuple = CISTPL_CONFIG;
872 if ((err=first_tuple(handle, &tuple, &parse)))
873 goto cis_error;
874 link->conf.ConfigBase = parse.config.base;
875 link->conf.Present = parse.config.rmask[0];
876
877
878 tuple.DesiredTuple = CISTPL_FUNCE;
879 for (err = first_tuple(handle, &tuple, &parse); !err;
880 err = next_tuple(handle, &tuple, &parse)) {
881
882
883
884 if (parse.funce.type == CISTPL_FUNCE_LAN_NODE_ID
885 && ((cistpl_lan_node_id_t *)parse.funce.data)->nb)
886 break;
887 }
888 if (err) {
889 tuple.DesiredTuple = 0x89;
890 if (!(err = get_tuple_data(GetFirstTuple, handle, &tuple))) {
891 if (tuple.TupleDataLen == 8 && *buf == CISTPL_FUNCE_LAN_NODE_ID)
892 memcpy(&parse, buf, 8);
893 else
894 err = -1;
895 }
896 }
897 if (err) {
898 tuple.DesiredTuple = CISTPL_FUNCE;
899 for (err = first_tuple(handle, &tuple, &parse); !err;
900 err = next_tuple(handle, &tuple, &parse)) {
901 if (parse.funce.type == 0x02 && parse.funce.data[0] == 1
902 && parse.funce.data[1] == 6 && tuple.TupleDataLen == 13) {
903 buf[1] = 4;
904 memcpy(&parse, buf+1, 8);
905 break;
906 }
907 }
908 }
909 if (err) {
910 printk(KNOT_XIRC "node-id not found in CIS\n");
911 goto failure;
912 }
913 node_id = (cistpl_lan_node_id_t *)parse.funce.data;
914 if (node_id->nb != 6) {
915 printk(KNOT_XIRC "malformed node-id in CIS\n");
916 goto failure;
917 }
918 for (i=0; i < 6; i++)
919 dev->dev_addr[i] = node_id->id[i];
920
921
922 link->state |= DEV_CONFIG;
923
924 link->io.IOAddrLines =10;
925 link->io.Attributes1 = IO_DATA_PATH_WIDTH_16;
926 link->irq.Attributes = IRQ_HANDLE_PRESENT;
927 link->irq.IRQInfo1 = IRQ_INFO2_VALID | IRQ_LEVEL_ID;
928 if (irq_list[0] == -1)
929 link->irq.IRQInfo2 = irq_mask;
930 else {
931 for (i = 0; i < 4; i++)
932 link->irq.IRQInfo2 |= 1 << irq_list[i];
933 }
934 if (local->modem) {
935 int pass;
936
937 if (do_sound) {
938 link->conf.Attributes |= CONF_ENABLE_SPKR;
939 link->conf.Status |= CCSR_AUDIO_ENA;
940 }
941 link->irq.Attributes |= IRQ_TYPE_DYNAMIC_SHARING|IRQ_FIRST_SHARED ;
942 link->io.NumPorts2 = 8;
943 link->io.Attributes2 = IO_DATA_PATH_WIDTH_8;
944 if (local->dingo) {
945
946
947 link->io.NumPorts1 = 16;
948 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
949 for (err = first_tuple(handle, &tuple, &parse); !err;
950 err = next_tuple(handle, &tuple, &parse)) {
951 if (cf->io.nwin > 0 && (cf->io.win[0].base & 0xf) == 8) {
952 for (ioaddr = 0x300; ioaddr < 0x400; ioaddr += 0x10) {
953 link->conf.ConfigIndex = cf->index ;
954 link->io.BasePort2 = cf->io.win[0].base;
955 link->io.BasePort1 = ioaddr;
956 if (!(err=CardServices(RequestIO, link->handle,
957 &link->io)))
958 goto port_found;
959 }
960 }
961 }
962 } else {
963 link->io.NumPorts1 = 18;
964
965
966
967
968
969 for (pass=0; pass < 2; pass++) {
970 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
971 for (err = first_tuple(handle, &tuple, &parse); !err;
972 err = next_tuple(handle, &tuple, &parse)){
973 if (cf->io.nwin > 0 && (cf->io.win[0].base & 0xf) == 8){
974 link->conf.ConfigIndex = cf->index ;
975 link->io.BasePort2 = cf->io.win[0].base;
976 link->io.BasePort1 = link->io.BasePort2
977 + (pass ? (cf->index & 0x20 ? -24:8)
978 : (cf->index & 0x20 ? 8:-24));
979 if (!(err=CardServices(RequestIO, link->handle,
980 &link->io)))
981 goto port_found;
982 }
983 }
984 }
985
986
987
988 }
989 printk(KNOT_XIRC "no ports available\n");
990 } else {
991 link->irq.Attributes |= IRQ_TYPE_EXCLUSIVE;
992 link->io.NumPorts1 = 16;
993 for (ioaddr = 0x300; ioaddr < 0x400; ioaddr += 0x10) {
994 link->io.BasePort1 = ioaddr;
995 if (!(err=CardServices(RequestIO, link->handle, &link->io)))
996 goto port_found;
997 }
998 link->io.BasePort1 = 0;
999 if ((err=CardServices(RequestIO, link->handle, &link->io))) {
1000 cs_error(link->handle, RequestIO, err);
1001 goto config_error;
1002 }
1003 }
1004 port_found:
1005 if (err)
1006 goto config_error;
1007
1008
1009
1010
1011
1012 if ((err=CardServices(RequestIRQ, link->handle, &link->irq))) {
1013 cs_error(link->handle, RequestIRQ, err);
1014 goto config_error;
1015 }
1016
1017
1018
1019
1020
1021 if ((err=CardServices(RequestConfiguration,
1022 link->handle, &link->conf))) {
1023 cs_error(link->handle, RequestConfiguration, err);
1024 goto config_error;
1025 }
1026
1027 if (local->dingo) {
1028 conf_reg_t reg;
1029 win_req_t req;
1030 memreq_t mem;
1031
1032
1033
1034
1035
1036
1037 reg.Action = CS_WRITE;
1038 reg.Offset = CISREG_IOBASE_0;
1039 reg.Value = link->io.BasePort2 & 0xff;
1040 if ((err = CardServices(AccessConfigurationRegister, link->handle,
1041 ®))) {
1042 cs_error(link->handle, AccessConfigurationRegister, err);
1043 goto config_error;
1044 }
1045 reg.Action = CS_WRITE;
1046 reg.Offset = CISREG_IOBASE_1;
1047 reg.Value = (link->io.BasePort2 >> 8) & 0xff;
1048 if ((err = CardServices(AccessConfigurationRegister, link->handle,
1049 ®))) {
1050 cs_error(link->handle, AccessConfigurationRegister, err);
1051 goto config_error;
1052 }
1053
1054
1055
1056
1057
1058 req.Attributes = WIN_DATA_WIDTH_8|WIN_MEMORY_TYPE_AM|WIN_ENABLE;
1059 req.Base = req.Size = 0;
1060 req.AccessSpeed = 0;
1061 link->win = (window_handle_t)link->handle;
1062 if ((err = CardServices(RequestWindow, &link->win, &req))) {
1063 cs_error(link->handle, RequestWindow, err);
1064 goto config_error;
1065 }
1066 local->dingo_ccr = ioremap(req.Base,0x1000) + 0x0800;
1067 mem.CardOffset = 0x0;
1068 mem.Page = 0;
1069 if ((err = CardServices(MapMemPage, link->win, &mem))) {
1070 cs_error(link->handle, MapMemPage, err);
1071 goto config_error;
1072 }
1073
1074
1075
1076
1077 writeb(0x47, local->dingo_ccr + CISREG_COR);
1078 ioaddr = link->io.BasePort1;
1079 writeb(ioaddr & 0xff , local->dingo_ccr + CISREG_IOBASE_0);
1080 writeb((ioaddr >> 8)&0xff , local->dingo_ccr + CISREG_IOBASE_1);
1081
1082 #if 0
1083 {
1084 u_char tmp;
1085 printk(KERN_INFO "ECOR:");
1086 for (i=0; i < 7; i++) {
1087 tmp = readb(local->dingo_ccr + i*2);
1088 printk(" %02x", tmp);
1089 }
1090 printk("\n");
1091 printk(KERN_INFO "DCOR:");
1092 for (i=0; i < 4; i++) {
1093 tmp = readb(local->dingo_ccr + 0x20 + i*2);
1094 printk(" %02x", tmp);
1095 }
1096 printk("\n");
1097 printk(KERN_INFO "SCOR:");
1098 for (i=0; i < 10; i++) {
1099 tmp = readb(local->dingo_ccr + 0x40 + i*2);
1100 printk(" %02x", tmp);
1101 }
1102 printk("\n");
1103 }
1104 #endif
1105
1106 writeb(0x01, local->dingo_ccr + 0x20);
1107 writeb(0x0c, local->dingo_ccr + 0x22);
1108 writeb(0x00, local->dingo_ccr + 0x24);
1109 writeb(0x00, local->dingo_ccr + 0x26);
1110 writeb(0x00, local->dingo_ccr + 0x28);
1111 }
1112
1113
1114 local->probe_port=0;
1115 if (!if_port) {
1116 local->probe_port = dev->if_port = 1;
1117 } else if ((if_port >= 1 && if_port <= 2) ||
1118 (local->mohawk && if_port==4))
1119 dev->if_port = if_port;
1120 else
1121 printk(KNOT_XIRC "invalid if_port requested\n");
1122
1123
1124 dev->irq = link->irq.AssignedIRQ;
1125 dev->base_addr = link->io.BasePort1;
1126 if ((err=register_netdev(dev))) {
1127 printk(KNOT_XIRC "register_netdev() failed\n");
1128 goto config_error;
1129 }
1130
1131 strcpy(local->node.dev_name, dev->name);
1132 link->dev = &local->node;
1133 link->state &= ~DEV_CONFIG_PENDING;
1134
1135 if (local->dingo)
1136 do_reset(dev, 1);
1137
1138
1139 printk(KERN_INFO "%s: %s: port %#3lx, irq %d, hwaddr",
1140 dev->name, local->manf_str,(u_long)dev->base_addr, (int)dev->irq);
1141 for (i = 0; i < 6; i++)
1142 printk("%c%02X", i?':':' ', dev->dev_addr[i]);
1143 printk("\n");
1144
1145 return;
1146
1147 config_error:
1148 link->state &= ~DEV_CONFIG_PENDING;
1149 xirc2ps_release(link);
1150 return;
1151
1152 cis_error:
1153 printk(KNOT_XIRC "unable to parse CIS\n");
1154 failure:
1155 link->state &= ~DEV_CONFIG_PENDING;
1156}
1157
1158
1159
1160
1161
1162
1163static void
1164xirc2ps_release(dev_link_t *link)
1165{
1166
1167 DEBUG(0, "release(0x%p)\n", link);
1168
1169 if (link->win) {
1170 struct net_device *dev = link->priv;
1171 local_info_t *local = dev->priv;
1172 if (local->dingo)
1173 iounmap(local->dingo_ccr - 0x0800);
1174 CardServices(ReleaseWindow, link->win);
1175 }
1176 CardServices(ReleaseConfiguration, link->handle);
1177 CardServices(ReleaseIO, link->handle, &link->io);
1178 CardServices(ReleaseIRQ, link->handle, &link->irq);
1179 link->state &= ~DEV_CONFIG;
1180
1181}
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197static int
1198xirc2ps_event(event_t event, int priority,
1199 event_callback_args_t * args)
1200{
1201 dev_link_t *link = args->client_data;
1202 struct net_device *dev = link->priv;
1203
1204 DEBUG(0, "event(%d)\n", (int)event);
1205
1206 switch (event) {
1207 case CS_EVENT_REGISTRATION_COMPLETE:
1208 DEBUG(0, "registration complete\n");
1209 break;
1210 case CS_EVENT_CARD_REMOVAL:
1211 link->state &= ~DEV_PRESENT;
1212 if (link->state & DEV_CONFIG) {
1213 netif_device_detach(dev);
1214 xirc2ps_release(link);
1215 }
1216 break;
1217 case CS_EVENT_CARD_INSERTION:
1218 link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
1219 xirc2ps_config(link);
1220 break;
1221 case CS_EVENT_PM_SUSPEND:
1222 link->state |= DEV_SUSPEND;
1223
1224 case CS_EVENT_RESET_PHYSICAL:
1225 if (link->state & DEV_CONFIG) {
1226 if (link->open) {
1227 netif_device_detach(dev);
1228 do_powerdown(dev);
1229 }
1230 CardServices(ReleaseConfiguration, link->handle);
1231 }
1232 break;
1233 case CS_EVENT_PM_RESUME:
1234 link->state &= ~DEV_SUSPEND;
1235
1236 case CS_EVENT_CARD_RESET:
1237 if (link->state & DEV_CONFIG) {
1238 CardServices(RequestConfiguration, link->handle, &link->conf);
1239 if (link->open) {
1240 do_reset(dev,1);
1241 netif_device_attach(dev);
1242 }
1243 }
1244 break;
1245 }
1246 return 0;
1247}
1248
1249
1250
1251
1252
1253
1254static irqreturn_t
1255xirc2ps_interrupt(int irq, void *dev_id, struct pt_regs *regs)
1256{
1257 struct net_device *dev = (struct net_device *)dev_id;
1258 local_info_t *lp = dev->priv;
1259 ioaddr_t ioaddr;
1260 u_char saved_page;
1261 unsigned bytes_rcvd;
1262 unsigned int_status, eth_status, rx_status, tx_status;
1263 unsigned rsr, pktlen;
1264 ulong start_ticks = jiffies;
1265
1266
1267
1268
1269 if (!netif_device_present(dev))
1270 return IRQ_HANDLED;
1271
1272 ioaddr = dev->base_addr;
1273 if (lp->mohawk) {
1274 PutByte(XIRCREG_CR, 0);
1275 }
1276
1277 DEBUG(6, "%s: interrupt %d at %#x.\n", dev->name, irq, ioaddr);
1278
1279 saved_page = GetByte(XIRCREG_PR);
1280
1281
1282
1283 int_status = GetByte(XIRCREG_ISR);
1284 bytes_rcvd = 0;
1285 loop_entry:
1286 if (int_status == 0xff) {
1287 DEBUG(3, "%s: interrupt %d for dead card\n", dev->name, irq);
1288 goto leave;
1289 }
1290 eth_status = GetByte(XIRCREG_ESR);
1291
1292 SelectPage(0x40);
1293 rx_status = GetByte(XIRCREG40_RXST0);
1294 PutByte(XIRCREG40_RXST0, (~rx_status & 0xff));
1295 tx_status = GetByte(XIRCREG40_TXST0);
1296 tx_status |= GetByte(XIRCREG40_TXST1) << 8;
1297 PutByte(XIRCREG40_TXST0, 0);
1298 PutByte(XIRCREG40_TXST1, 0);
1299
1300 DEBUG(3, "%s: ISR=%#2.2x ESR=%#2.2x RSR=%#2.2x TSR=%#4.4x\n",
1301 dev->name, int_status, eth_status, rx_status, tx_status);
1302
1303
1304 SelectPage(0);
1305 while (eth_status & FullPktRcvd) {
1306 rsr = GetByte(XIRCREG0_RSR);
1307 if (bytes_rcvd > maxrx_bytes && (rsr & PktRxOk)) {
1308
1309
1310 lp->stats.rx_dropped++;
1311 DEBUG(2, "%s: RX drop, too much done\n", dev->name);
1312 } else if (rsr & PktRxOk) {
1313 struct sk_buff *skb;
1314
1315 pktlen = GetWord(XIRCREG0_RBC);
1316 bytes_rcvd += pktlen;
1317
1318 DEBUG(5, "rsr=%#02x packet_length=%u\n", rsr, pktlen);
1319
1320 skb = dev_alloc_skb(pktlen+3);
1321 if (!skb) {
1322 printk(KNOT_XIRC "low memory, packet dropped (size=%u)\n",
1323 pktlen);
1324 lp->stats.rx_dropped++;
1325 } else {
1326 skb_reserve(skb, 2);
1327 if (lp->silicon == 0 ) {
1328 unsigned rhsa;
1329
1330 SelectPage(5);
1331 rhsa = GetWord(XIRCREG5_RHSA0);
1332 SelectPage(0);
1333 rhsa += 3;
1334 if (rhsa >= 0x8000)
1335 rhsa = 0;
1336 if (rhsa + pktlen > 0x8000) {
1337 unsigned i;
1338 u_char *buf = skb_put(skb, pktlen);
1339 for (i=0; i < pktlen ; i++, rhsa++) {
1340 buf[i] = GetByte(XIRCREG_EDP);
1341 if (rhsa == 0x8000) {
1342 rhsa = 0;
1343 i--;
1344 }
1345 }
1346 } else {
1347 insw(ioaddr+XIRCREG_EDP,
1348 skb_put(skb, pktlen), (pktlen+1)>>1);
1349 }
1350 }
1351 #if 0
1352 else if (lp->mohawk) {
1353
1354
1355
1356
1357
1358
1359
1360
1361 unsigned i;
1362 u_long *p = skb_put(skb, pktlen);
1363 register u_long a;
1364 ioaddr_t edpreg = ioaddr+XIRCREG_EDP-2;
1365 for (i=0; i < len ; i += 4, p++) {
1366 a = inl(edpreg);
1367 __asm__("rorl $16,%0\n\t"
1368 :"=q" (a)
1369 : "0" (a));
1370 *p = a;
1371 }
1372 }
1373 #endif
1374 else {
1375 insw(ioaddr+XIRCREG_EDP, skb_put(skb, pktlen),
1376 (pktlen+1)>>1);
1377 }
1378 skb->protocol = eth_type_trans(skb, dev);
1379 skb->dev = dev;
1380 netif_rx(skb);
1381 dev->last_rx = jiffies;
1382 lp->stats.rx_packets++;
1383 lp->stats.rx_bytes += pktlen;
1384 if (!(rsr & PhyPkt))
1385 lp->stats.multicast++;
1386 }
1387 } else {
1388 DEBUG(5, "rsr=%#02x\n", rsr);
1389 }
1390 if (rsr & PktTooLong) {
1391 lp->stats.rx_frame_errors++;
1392 DEBUG(3, "%s: Packet too long\n", dev->name);
1393 }
1394 if (rsr & CRCErr) {
1395 lp->stats.rx_crc_errors++;
1396 DEBUG(3, "%s: CRC error\n", dev->name);
1397 }
1398 if (rsr & AlignErr) {
1399 lp->stats.rx_fifo_errors++;
1400 DEBUG(3, "%s: Alignment error\n", dev->name);
1401 }
1402
1403
1404 PutWord(XIRCREG0_DO, 0x8000);
1405
1406
1407 eth_status = GetByte(XIRCREG_ESR);
1408 }
1409 if (rx_status & 0x10) {
1410 lp->stats.rx_over_errors++;
1411 PutByte(XIRCREG_CR, ClearRxOvrun);
1412 DEBUG(3, "receive overrun cleared\n");
1413 }
1414
1415
1416 if (int_status & PktTxed) {
1417 unsigned n, nn;
1418
1419 n = lp->last_ptr_value;
1420 nn = GetByte(XIRCREG0_PTR);
1421 lp->last_ptr_value = nn;
1422 if (nn < n)
1423 lp->stats.tx_packets += 256 - n;
1424 else if (n == nn) {
1425 DEBUG(0, "PTR not changed?\n");
1426 } else
1427 lp->stats.tx_packets += lp->last_ptr_value - n;
1428 netif_wake_queue(dev);
1429 }
1430 if (tx_status & 0x0002) {
1431 DEBUG(0, "tx restarted due to execssive collissions\n");
1432 PutByte(XIRCREG_CR, RestartTx);
1433 }
1434 if (tx_status & 0x0040)
1435 lp->stats.tx_aborted_errors++;
1436
1437
1438
1439
1440
1441 if (bytes_rcvd > 1000) {
1442 u_long duration = jiffies - start_ticks;
1443
1444 if (duration >= HZ/10) {
1445 maxrx_bytes = (bytes_rcvd * (HZ/10)) / duration;
1446 if (maxrx_bytes < 2000)
1447 maxrx_bytes = 2000;
1448 else if (maxrx_bytes > 22000)
1449 maxrx_bytes = 22000;
1450 DEBUG(1, "set maxrx=%u (rcvd=%u ticks=%lu)\n",
1451 maxrx_bytes, bytes_rcvd, duration);
1452 } else if (!duration && maxrx_bytes < 22000) {
1453
1454 maxrx_bytes += 2000;
1455 if (maxrx_bytes > 22000)
1456 maxrx_bytes = 22000;
1457 DEBUG(1, "set maxrx=%u\n", maxrx_bytes);
1458 }
1459 }
1460
1461 leave:
1462 if (lockup_hack) {
1463 if (int_status != 0xff && (int_status = GetByte(XIRCREG_ISR)) != 0)
1464 goto loop_entry;
1465 }
1466 SelectPage(saved_page);
1467 PutByte(XIRCREG_CR, EnableIntr);
1468
1469
1470
1471
1472 return IRQ_HANDLED;
1473}
1474
1475
1476
1477static void
1478do_tx_timeout(struct net_device *dev)
1479{
1480 local_info_t *lp = dev->priv;
1481 printk(KERN_NOTICE "%s: transmit timed out\n", dev->name);
1482 lp->stats.tx_errors++;
1483
1484 do_reset(dev,1);
1485 dev->trans_start = jiffies;
1486 netif_wake_queue(dev);
1487}
1488
1489static int
1490do_start_xmit(struct sk_buff *skb, struct net_device *dev)
1491{
1492 local_info_t *lp = dev->priv;
1493 ioaddr_t ioaddr = dev->base_addr;
1494 int okay;
1495 unsigned freespace;
1496 unsigned pktlen = skb? skb->len : 0;
1497
1498 DEBUG(1, "do_start_xmit(skb=%p, dev=%p) len=%u\n",
1499 skb, dev, pktlen);
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509 if (pktlen < ETH_ZLEN)
1510 {
1511 skb = skb_padto(skb, ETH_ZLEN);
1512 if (skb == NULL)
1513 return 0;
1514 pktlen = ETH_ZLEN;
1515 }
1516
1517 netif_stop_queue(dev);
1518 SelectPage(0);
1519 PutWord(XIRCREG0_TRS, (u_short)pktlen+2);
1520 freespace = GetWord(XIRCREG0_TSO);
1521 okay = freespace & 0x8000;
1522 freespace &= 0x7fff;
1523
1524 okay = pktlen +2 < freespace;
1525 DEBUG(2 + (okay ? 2 : 0), "%s: avail. tx space=%u%s\n",
1526 dev->name, freespace, okay ? " (okay)":" (not enough)");
1527 if (!okay) {
1528 return 1;
1529 }
1530
1531 PutWord(XIRCREG_EDP, (u_short)pktlen);
1532 outsw(ioaddr+XIRCREG_EDP, skb->data, pktlen>>1);
1533 if (pktlen & 1)
1534 PutByte(XIRCREG_EDP, skb->data[pktlen-1]);
1535
1536 if (lp->mohawk)
1537 PutByte(XIRCREG_CR, TransmitPacket|EnableIntr);
1538
1539 dev_kfree_skb (skb);
1540 dev->trans_start = jiffies;
1541 lp->stats.tx_bytes += pktlen;
1542 netif_start_queue(dev);
1543 return 0;
1544}
1545
1546static struct net_device_stats *
1547do_get_stats(struct net_device *dev)
1548{
1549 local_info_t *lp = dev->priv;
1550
1551
1552 return &lp->stats;
1553}
1554
1555
1556
1557
1558
1559
1560static void
1561set_addresses(struct net_device *dev)
1562{
1563 ioaddr_t ioaddr = dev->base_addr;
1564 local_info_t *lp = dev->priv;
1565 struct dev_mc_list *dmi = dev->mc_list;
1566 char *addr;
1567 int i,j,k,n;
1568
1569 SelectPage(k=0x50);
1570 for (i=0,j=8,n=0; ; i++, j++) {
1571 if (i > 5) {
1572 if (++n > 9)
1573 break;
1574 i = 0;
1575 }
1576 if (j > 15) {
1577 j = 8;
1578 k++;
1579 SelectPage(k);
1580 }
1581
1582 if (n && n <= dev->mc_count && dmi) {
1583 addr = dmi->dmi_addr;
1584 dmi = dmi->next;
1585 } else
1586 addr = dev->dev_addr;
1587
1588 if (lp->mohawk)
1589 PutByte(j, addr[5-i]);
1590 else
1591 PutByte(j, addr[i]);
1592 }
1593 SelectPage(0);
1594}
1595
1596
1597
1598
1599
1600
1601
1602static void
1603set_multicast_list(struct net_device *dev)
1604{
1605 ioaddr_t ioaddr = dev->base_addr;
1606
1607 SelectPage(0x42);
1608 if (dev->flags & IFF_PROMISC) {
1609 PutByte(XIRCREG42_SWC1, 0x06);
1610 } else if (dev->mc_count > 9 || (dev->flags & IFF_ALLMULTI)) {
1611 PutByte(XIRCREG42_SWC1, 0x06);
1612 } else if (dev->mc_count) {
1613
1614 PutByte(XIRCREG42_SWC1, 0x00);
1615 SelectPage(0x40);
1616 PutByte(XIRCREG40_CMD0, Offline);
1617 set_addresses(dev);
1618 SelectPage(0x40);
1619 PutByte(XIRCREG40_CMD0, EnableRecv | Online);
1620 } else {
1621 PutByte(XIRCREG42_SWC1, 0x00);
1622 }
1623 SelectPage(0);
1624}
1625
1626static int
1627do_config(struct net_device *dev, struct ifmap *map)
1628{
1629 local_info_t *local = dev->priv;
1630
1631 DEBUG(0, "do_config(%p)\n", dev);
1632 if (map->port != 255 && map->port != dev->if_port) {
1633 if (map->port > 4)
1634 return -EINVAL;
1635 if (!map->port) {
1636 local->probe_port = 1;
1637 dev->if_port = 1;
1638 } else {
1639 local->probe_port = 0;
1640 dev->if_port = map->port;
1641 }
1642 printk(KERN_INFO "%s: switching to %s port\n",
1643 dev->name, if_names[dev->if_port]);
1644 do_reset(dev,1);
1645 }
1646 return 0;
1647}
1648
1649
1650
1651
1652static int
1653do_open(struct net_device *dev)
1654{
1655 local_info_t *lp = dev->priv;
1656 dev_link_t *link = &lp->link;
1657
1658 DEBUG(0, "do_open(%p)\n", dev);
1659
1660
1661
1662 if (!DEV_OK(link))
1663 return -ENODEV;
1664
1665
1666 link->open++;
1667
1668 netif_start_queue(dev);
1669 do_reset(dev,1);
1670
1671 return 0;
1672}
1673
1674static void netdev_get_drvinfo(struct net_device *dev,
1675 struct ethtool_drvinfo *info)
1676{
1677 strcpy(info->driver, "xirc2ps_cs");
1678}
1679
1680static struct ethtool_ops netdev_ethtool_ops = {
1681 .get_drvinfo = netdev_get_drvinfo,
1682};
1683
1684static int
1685do_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
1686{
1687 local_info_t *local = dev->priv;
1688 ioaddr_t ioaddr = dev->base_addr;
1689 u16 *data = (u16 *)&rq->ifr_data;
1690
1691 DEBUG(1, "%s: ioctl(%-.6s, %#04x) %04x %04x %04x %04x\n",
1692 dev->name, rq->ifr_ifrn.ifrn_name, cmd,
1693 data[0], data[1], data[2], data[3]);
1694
1695 if (!local->mohawk)
1696 return -EOPNOTSUPP;
1697
1698 switch(cmd) {
1699 case SIOCGMIIPHY:
1700 data[0] = 0;
1701
1702 case SIOCGMIIREG:
1703 data[3] = mii_rd(ioaddr, data[0] & 0x1f, data[1] & 0x1f);
1704 break;
1705 case SIOCSMIIREG:
1706 if (!capable(CAP_NET_ADMIN))
1707 return -EPERM;
1708 mii_wr(ioaddr, data[0] & 0x1f, data[1] & 0x1f, data[2], 16);
1709 break;
1710 default:
1711 return -EOPNOTSUPP;
1712 }
1713 return 0;
1714}
1715
1716static void
1717hardreset(struct net_device *dev)
1718{
1719 local_info_t *local = dev->priv;
1720 ioaddr_t ioaddr = dev->base_addr;
1721
1722 SelectPage(4);
1723 udelay(1);
1724 PutByte(XIRCREG4_GPR1, 0);
1725 Wait(HZ/25);
1726 if (local->mohawk)
1727 PutByte(XIRCREG4_GPR1, 1);
1728 else
1729 PutByte(XIRCREG4_GPR1, 1 | 4);
1730 Wait(HZ/50);
1731}
1732
1733static void
1734do_reset(struct net_device *dev, int full)
1735{
1736 local_info_t *local = dev->priv;
1737 ioaddr_t ioaddr = dev->base_addr;
1738 unsigned value;
1739
1740 DEBUG(0, "%s: do_reset(%p,%d)\n", dev? dev->name:"eth?", dev, full);
1741
1742 hardreset(dev);
1743 PutByte(XIRCREG_CR, SoftReset);
1744 Wait(HZ/50);
1745 PutByte(XIRCREG_CR, 0);
1746 Wait(HZ/25);
1747 if (local->mohawk) {
1748 SelectPage(4);
1749
1750
1751
1752
1753 PutByte(XIRCREG4_GPR0, 0x0e);
1754 }
1755
1756
1757 Wait(HZ/2);
1758
1759 local->last_ptr_value = 0;
1760 local->silicon = local->mohawk ? (GetByte(XIRCREG4_BOV) & 0x70) >> 4
1761 : (GetByte(XIRCREG4_BOV) & 0x30) >> 4;
1762
1763 if (local->probe_port) {
1764 if (!local->mohawk) {
1765 SelectPage(4);
1766 PutByte(XIRCREG4_GPR0, 4);
1767 local->probe_port = 0;
1768 }
1769 } else if (dev->if_port == 2) {
1770 SelectPage(0x42);
1771 PutByte(XIRCREG42_SWC1, 0xC0);
1772 } else {
1773 SelectPage(0x42);
1774 PutByte(XIRCREG42_SWC1, 0x80);
1775 }
1776 Wait(HZ/25);
1777
1778 #ifdef PCMCIA_DEBUG
1779 if (pc_debug) {
1780 SelectPage(0);
1781 value = GetByte(XIRCREG_ESR);
1782 printk(KERN_DEBUG "%s: ESR is: %#02x\n", dev->name, value);
1783 }
1784 #endif
1785
1786
1787 SelectPage(1);
1788 PutByte(XIRCREG1_IMR0, 0xff);
1789 PutByte(XIRCREG1_IMR1, 1 );
1790 value = GetByte(XIRCREG1_ECR);
1791 #if 0
1792 if (local->mohawk)
1793 value |= DisableLinkPulse;
1794 PutByte(XIRCREG1_ECR, value);
1795 #endif
1796 DEBUG(0, "%s: ECR is: %#02x\n", dev->name, value);
1797
1798 SelectPage(0x42);
1799 PutByte(XIRCREG42_SWC0, 0x20);
1800
1801 if (local->silicon != 1) {
1802
1803
1804
1805
1806
1807 SelectPage(2);
1808 PutWord(XIRCREG2_RBS, 0x2000);
1809 }
1810
1811 if (full)
1812 set_addresses(dev);
1813
1814
1815
1816
1817
1818 SelectPage(0);
1819 PutWord(XIRCREG0_DO, 0x2000);
1820
1821
1822 SelectPage(0x40);
1823 PutByte(XIRCREG40_RMASK0, 0xff);
1824 PutByte(XIRCREG40_TMASK0, 0xff);
1825 PutByte(XIRCREG40_TMASK1, 0xb0);
1826 PutByte(XIRCREG40_RXST0, 0x00);
1827 PutByte(XIRCREG40_TXST0, 0x00);
1828 PutByte(XIRCREG40_TXST1, 0x00);
1829
1830 if (full && local->mohawk && init_mii(dev)) {
1831 if (dev->if_port == 4 || local->dingo || local->new_mii) {
1832 printk(KERN_INFO "%s: MII selected\n", dev->name);
1833 SelectPage(2);
1834 PutByte(XIRCREG2_MSR, GetByte(XIRCREG2_MSR) | 0x08);
1835 Wait(HZ/50);
1836 } else {
1837 printk(KERN_INFO "%s: MII detected; using 10mbs\n",
1838 dev->name);
1839 SelectPage(0x42);
1840 if (dev->if_port == 2)
1841 PutByte(XIRCREG42_SWC1, 0xC0);
1842 else
1843 PutByte(XIRCREG42_SWC1, 0x80);
1844 Wait(HZ/25);
1845 }
1846 if (full_duplex)
1847 PutByte(XIRCREG1_ECR, GetByte(XIRCREG1_ECR | FullDuplex));
1848 } else {
1849 SelectPage(0);
1850 value = GetByte(XIRCREG_ESR);
1851 dev->if_port = (value & MediaSelect) ? 1 : 2;
1852 }
1853
1854
1855 SelectPage(2);
1856 if (dev->if_port == 1 || dev->if_port == 4)
1857 PutByte(XIRCREG2_LED, 0x3b);
1858 else
1859 PutByte(XIRCREG2_LED, 0x3a);
1860
1861 if (local->dingo)
1862 PutByte(0x0b, 0x04);
1863
1864
1865 if (full) {
1866 SelectPage(0x40);
1867 PutByte(XIRCREG40_CMD0, EnableRecv | Online);
1868 }
1869
1870
1871 SelectPage(1);
1872 PutByte(XIRCREG1_IMR0, 0xff);
1873 udelay(1);
1874 SelectPage(0);
1875 PutByte(XIRCREG_CR, EnableIntr);
1876 if (local->modem && !local->dingo) {
1877 if (!(GetByte(0x10) & 0x01))
1878 PutByte(0x10, 0x11);
1879 }
1880
1881 if (full)
1882 printk(KERN_INFO "%s: media %s, silicon revision %d\n",
1883 dev->name, if_names[dev->if_port], local->silicon);
1884
1885
1886
1887 SelectPage(0);
1888}
1889
1890
1891
1892
1893
1894static int
1895init_mii(struct net_device *dev)
1896{
1897 local_info_t *local = dev->priv;
1898 ioaddr_t ioaddr = dev->base_addr;
1899 unsigned control, status, linkpartner;
1900 int i;
1901
1902 if (if_port == 4 || if_port == 1) {
1903 dev->if_port = if_port;
1904 local->probe_port = 0;
1905 return 1;
1906 }
1907
1908 status = mii_rd(ioaddr, 0, 1);
1909 if ((status & 0xff00) != 0x7800)
1910 return 0;
1911
1912 local->new_mii = (mii_rd(ioaddr, 0, 2) != 0xffff);
1913
1914 if (local->probe_port)
1915 control = 0x1000;
1916 else if (dev->if_port == 4)
1917 control = 0x2000;
1918 else
1919 control = 0x0000;
1920 mii_wr(ioaddr, 0, 0, control, 16);
1921 udelay(100);
1922 control = mii_rd(ioaddr, 0, 0);
1923
1924 if (control & 0x0400) {
1925 printk(KERN_NOTICE "%s can't take PHY out of isolation mode\n",
1926 dev->name);
1927 local->probe_port = 0;
1928 return 0;
1929 }
1930
1931 if (local->probe_port) {
1932
1933
1934
1935
1936 for (i=0; i < 35; i++) {
1937 Wait(HZ/10);
1938 status = mii_rd(ioaddr, 0, 1);
1939 if ((status & 0x0020) && (status & 0x0004))
1940 break;
1941 }
1942
1943 if (!(status & 0x0020)) {
1944 printk(KERN_INFO "%s: autonegotiation failed;"
1945 " using 10mbs\n", dev->name);
1946 if (!local->new_mii) {
1947 control = 0x0000;
1948 mii_wr(ioaddr, 0, 0, control, 16);
1949 udelay(100);
1950 SelectPage(0);
1951 dev->if_port = (GetByte(XIRCREG_ESR) & MediaSelect) ? 1 : 2;
1952 }
1953 } else {
1954 linkpartner = mii_rd(ioaddr, 0, 5);
1955 printk(KERN_INFO "%s: MII link partner: %04x\n",
1956 dev->name, linkpartner);
1957 if (linkpartner & 0x0080) {
1958 dev->if_port = 4;
1959 } else
1960 dev->if_port = 1;
1961 }
1962 }
1963
1964 return 1;
1965}
1966
1967static void
1968do_powerdown(struct net_device *dev)
1969{
1970
1971 ioaddr_t ioaddr = dev->base_addr;
1972
1973 DEBUG(0, "do_powerdown(%p)\n", dev);
1974
1975 SelectPage(4);
1976 PutByte(XIRCREG4_GPR1, 0);
1977 SelectPage(0);
1978}
1979
1980static int
1981do_stop(struct net_device *dev)
1982{
1983 ioaddr_t ioaddr = dev->base_addr;
1984 local_info_t *lp = dev->priv;
1985 dev_link_t *link = &lp->link;
1986
1987 DEBUG(0, "do_stop(%p)\n", dev);
1988
1989 if (!link)
1990 return -ENODEV;
1991
1992 netif_stop_queue(dev);
1993
1994 SelectPage(0);
1995 PutByte(XIRCREG_CR, 0);
1996 SelectPage(0x01);
1997 PutByte(XIRCREG1_IMR0, 0x00);
1998 SelectPage(4);
1999 PutByte(XIRCREG4_GPR1, 0);
2000 SelectPage(0);
2001
2002 link->open--;
2003 return 0;
2004}
2005
2006static struct pcmcia_driver xirc2ps_cs_driver = {
2007 .owner = THIS_MODULE,
2008 .drv = {
2009 .name = "xirc2ps_cs",
2010 },
2011 .attach = xirc2ps_attach,
2012 .detach = xirc2ps_detach,
2013};
2014
2015static int __init
2016init_xirc2ps_cs(void)
2017{
2018 return pcmcia_register_driver(&xirc2ps_cs_driver);
2019}
2020
2021static void __exit
2022exit_xirc2ps_cs(void)
2023{
2024 pcmcia_unregister_driver(&xirc2ps_cs_driver);
2025
2026 while (dev_list)
2027 xirc2ps_detach(dev_list);
2028}
2029
2030module_init(init_xirc2ps_cs);
2031module_exit(exit_xirc2ps_cs);
2032
2033#ifndef MODULE
2034static int __init setup_xirc2ps_cs(char *str)
2035{
2036
2037
2038
2039 int ints[10] = { -1 };
2040
2041 str = get_options(str, 9, ints);
2042
2043#define MAYBE_SET(X,Y) if (ints[0] >= Y && ints[Y] != -1) { X = ints[Y]; }
2044 MAYBE_SET(irq_list[0], 1);
2045 MAYBE_SET(irq_mask, 2);
2046 MAYBE_SET(if_port, 3);
2047 MAYBE_SET(full_duplex, 4);
2048 MAYBE_SET(do_sound, 5);
2049 MAYBE_SET(lockup_hack, 6);
2050 MAYBE_SET(irq_list[1], 7);
2051 MAYBE_SET(irq_list[2], 8);
2052 MAYBE_SET(irq_list[3], 9);
2053#undef MAYBE_SET
2054
2055 return 0;
2056}
2057
2058__setup("xirc2ps_cs=", setup_xirc2ps_cs);
2059#endif
2060