forked from torvalds/linux
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxirc2ps_cs.c
1814 lines (1595 loc) · 52.3 KB
/
xirc2ps_cs.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* [xirc2ps_cs.c wk 03.11.99] (1.40 1999/11/18 00:06:03)
* Xircom CreditCard Ethernet Adapter IIps driver
* Xircom Realport 10/100 (RE-100) driver
*
* This driver supports various Xircom CreditCard Ethernet adapters
* including the CE2, CE IIps, RE-10, CEM28, CEM33, CE33, CEM56,
* CE3-100, CE3B, RE-100, REM10BT, and REM56G-100.
*
* 2000-09-24 <psheer@icon.co.za> The Xircom CE3B-100 may not
* autodetect the media properly. In this case use the
* if_port=1 (for 10BaseT) or if_port=4 (for 100BaseT) options
* to force the media type.
*
* Written originally by Werner Koch based on David Hinds' skeleton of the
* PCMCIA driver.
*
* Copyright (c) 1997,1998 Werner Koch (dd9jn)
*
* This driver is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* It is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*
*
* ALTERNATIVELY, this driver may be distributed under the terms of
* the following license, in which case the provisions of this license
* are required INSTEAD OF the GNU General Public License. (This clause
* is necessary due to a potential bad interaction between the GPL and
* the restrictions contained in a BSD-style copyright.)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, and the entire permission notice in its entirety,
* including the disclaimer of warranties.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote
* products derived from this software without specific prior
* written permission.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/ptrace.h>
#include <linux/slab.h>
#include <linux/string.h>
#include <linux/timer.h>
#include <linux/interrupt.h>
#include <linux/in.h>
#include <linux/delay.h>
#include <linux/ethtool.h>
#include <linux/netdevice.h>
#include <linux/etherdevice.h>
#include <linux/skbuff.h>
#include <linux/if_arp.h>
#include <linux/ioport.h>
#include <linux/bitops.h>
#include <linux/mii.h>
#include <pcmcia/cistpl.h>
#include <pcmcia/cisreg.h>
#include <pcmcia/ciscode.h>
#include <asm/io.h>
#include <asm/uaccess.h>
#ifndef MANFID_COMPAQ
#define MANFID_COMPAQ 0x0138
#define MANFID_COMPAQ2 0x0183 /* is this correct? */
#endif
#include <pcmcia/ds.h>
/* Time in jiffies before concluding Tx hung */
#define TX_TIMEOUT ((400*HZ)/1000)
/****************
* Some constants used to access the hardware
*/
/* Register offsets and value constans */
#define XIRCREG_CR 0 /* Command register (wr) */
enum xirc_cr {
TransmitPacket = 0x01,
SoftReset = 0x02,
EnableIntr = 0x04,
ForceIntr = 0x08,
ClearTxFIFO = 0x10,
ClearRxOvrun = 0x20,
RestartTx = 0x40
};
#define XIRCREG_ESR 0 /* Ethernet status register (rd) */
enum xirc_esr {
FullPktRcvd = 0x01, /* full packet in receive buffer */
PktRejected = 0x04, /* a packet has been rejected */
TxPktPend = 0x08, /* TX Packet Pending */
IncorPolarity = 0x10,
MediaSelect = 0x20 /* set if TP, clear if AUI */
};
#define XIRCREG_PR 1 /* Page Register select */
#define XIRCREG_EDP 4 /* Ethernet Data Port Register */
#define XIRCREG_ISR 6 /* Ethernet Interrupt Status Register */
enum xirc_isr {
TxBufOvr = 0x01, /* TX Buffer Overflow */
PktTxed = 0x02, /* Packet Transmitted */
MACIntr = 0x04, /* MAC Interrupt occurred */
TxResGrant = 0x08, /* Tx Reservation Granted */
RxFullPkt = 0x20, /* Rx Full Packet */
RxPktRej = 0x40, /* Rx Packet Rejected */
ForcedIntr= 0x80 /* Forced Interrupt */
};
#define XIRCREG1_IMR0 12 /* Ethernet Interrupt Mask Register (on page 1)*/
#define XIRCREG1_IMR1 13
#define XIRCREG0_TSO 8 /* Transmit Space Open Register (on page 0)*/
#define XIRCREG0_TRS 10 /* Transmit reservation Size Register (page 0)*/
#define XIRCREG0_DO 12 /* Data Offset Register (page 0) (wr) */
#define XIRCREG0_RSR 12 /* Receive Status Register (page 0) (rd) */
enum xirc_rsr {
PhyPkt = 0x01, /* set:physical packet, clear: multicast packet */
BrdcstPkt = 0x02, /* set if it is a broadcast packet */
PktTooLong = 0x04, /* set if packet length > 1518 */
AlignErr = 0x10, /* incorrect CRC and last octet not complete */
CRCErr = 0x20, /* incorrect CRC and last octet is complete */
PktRxOk = 0x80 /* received ok */
};
#define XIRCREG0_PTR 13 /* packets transmitted register (rd) */
#define XIRCREG0_RBC 14 /* receive byte count regsister (rd) */
#define XIRCREG1_ECR 14 /* ethernet configurationn register */
enum xirc_ecr {
FullDuplex = 0x04, /* enable full duplex mode */
LongTPMode = 0x08, /* adjust for longer lengths of TP cable */
DisablePolCor = 0x10,/* disable auto polarity correction */
DisableLinkPulse = 0x20, /* disable link pulse generation */
DisableAutoTx = 0x40, /* disable auto-transmit */
};
#define XIRCREG2_RBS 8 /* receive buffer start register */
#define XIRCREG2_LED 10 /* LED Configuration register */
/* values for the leds: Bits 2-0 for led 1
* 0 disabled Bits 5-3 for led 2
* 1 collision
* 2 noncollision
* 3 link_detected
* 4 incor_polarity
* 5 jabber
* 6 auto_assertion
* 7 rx_tx_activity
*/
#define XIRCREG2_MSR 12 /* Mohawk specific register */
#define XIRCREG4_GPR0 8 /* General Purpose Register 0 */
#define XIRCREG4_GPR1 9 /* General Purpose Register 1 */
#define XIRCREG2_GPR2 13 /* General Purpose Register 2 (page2!)*/
#define XIRCREG4_BOV 10 /* Bonding Version Register */
#define XIRCREG4_LMA 12 /* Local Memory Address Register */
#define XIRCREG4_LMD 14 /* Local Memory Data Port */
/* MAC register can only by accessed with 8 bit operations */
#define XIRCREG40_CMD0 8 /* Command Register (wr) */
enum xirc_cmd { /* Commands */
Transmit = 0x01,
EnableRecv = 0x04,
DisableRecv = 0x08,
Abort = 0x10,
Online = 0x20,
IntrAck = 0x40,
Offline = 0x80
};
#define XIRCREG5_RHSA0 10 /* Rx Host Start Address */
#define XIRCREG40_RXST0 9 /* Receive Status Register */
#define XIRCREG40_TXST0 11 /* Transmit Status Register 0 */
#define XIRCREG40_TXST1 12 /* Transmit Status Register 10 */
#define XIRCREG40_RMASK0 13 /* Receive Mask Register */
#define XIRCREG40_TMASK0 14 /* Transmit Mask Register 0 */
#define XIRCREG40_TMASK1 15 /* Transmit Mask Register 0 */
#define XIRCREG42_SWC0 8 /* Software Configuration 0 */
#define XIRCREG42_SWC1 9 /* Software Configuration 1 */
#define XIRCREG42_BOC 10 /* Back-Off Configuration */
#define XIRCREG44_TDR0 8 /* Time Domain Reflectometry 0 */
#define XIRCREG44_TDR1 9 /* Time Domain Reflectometry 1 */
#define XIRCREG44_RXBC_LO 10 /* Rx Byte Count 0 (rd) */
#define XIRCREG44_RXBC_HI 11 /* Rx Byte Count 1 (rd) */
#define XIRCREG45_REV 15 /* Revision Register (rd) */
#define XIRCREG50_IA 8 /* Individual Address (8-13) */
static const char *if_names[] = { "Auto", "10BaseT", "10Base2", "AUI", "100BaseT" };
/* card types */
#define XIR_UNKNOWN 0 /* unknown: not supported */
#define XIR_CE 1 /* (prodid 1) different hardware: not supported */
#define XIR_CE2 2 /* (prodid 2) */
#define XIR_CE3 3 /* (prodid 3) */
#define XIR_CEM 4 /* (prodid 1) different hardware: not supported */
#define XIR_CEM2 5 /* (prodid 2) */
#define XIR_CEM3 6 /* (prodid 3) */
#define XIR_CEM33 7 /* (prodid 4) */
#define XIR_CEM56M 8 /* (prodid 5) */
#define XIR_CEM56 9 /* (prodid 6) */
#define XIR_CM28 10 /* (prodid 3) modem only: not supported here */
#define XIR_CM33 11 /* (prodid 4) modem only: not supported here */
#define XIR_CM56 12 /* (prodid 5) modem only: not supported here */
#define XIR_CG 13 /* (prodid 1) GSM modem only: not supported */
#define XIR_CBE 14 /* (prodid 1) cardbus ethernet: not supported */
/*====================================================================*/
/* Module parameters */
MODULE_DESCRIPTION("Xircom PCMCIA ethernet driver");
MODULE_LICENSE("Dual MPL/GPL");
#define INT_MODULE_PARM(n, v) static int n = v; module_param(n, int, 0)
INT_MODULE_PARM(if_port, 0);
INT_MODULE_PARM(full_duplex, 0);
INT_MODULE_PARM(do_sound, 1);
INT_MODULE_PARM(lockup_hack, 0); /* anti lockup hack */
/*====================================================================*/
/* We do not process more than these number of bytes during one
* interrupt. (Of course we receive complete packets, so this is not
* an exact value).
* Something between 2000..22000; first value gives best interrupt latency,
* the second enables the usage of the complete on-chip buffer. We use the
* high value as the initial value.
*/
static unsigned maxrx_bytes = 22000;
/* MII management prototypes */
static void mii_idle(unsigned int ioaddr);
static void mii_putbit(unsigned int ioaddr, unsigned data);
static int mii_getbit(unsigned int ioaddr);
static void mii_wbits(unsigned int ioaddr, unsigned data, int len);
static unsigned mii_rd(unsigned int ioaddr, u_char phyaddr, u_char phyreg);
static void mii_wr(unsigned int ioaddr, u_char phyaddr, u_char phyreg,
unsigned data, int len);
static int has_ce2_string(struct pcmcia_device * link);
static int xirc2ps_config(struct pcmcia_device * link);
static void xirc2ps_release(struct pcmcia_device * link);
static void xirc2ps_detach(struct pcmcia_device *p_dev);
static irqreturn_t xirc2ps_interrupt(int irq, void *dev_id);
typedef struct local_info_t {
struct net_device *dev;
struct pcmcia_device *p_dev;
int card_type;
int probe_port;
int silicon; /* silicon revision. 0=old CE2, 1=Scipper, 4=Mohawk */
int mohawk; /* a CE3 type card */
int dingo; /* a CEM56 type card */
int new_mii; /* has full 10baseT/100baseT MII */
int modem; /* is a multi function card (i.e with a modem) */
void __iomem *dingo_ccr; /* only used for CEM56 cards */
unsigned last_ptr_value; /* last packets transmitted value */
const char *manf_str;
struct work_struct tx_timeout_task;
} local_info_t;
/****************
* Some more prototypes
*/
static netdev_tx_t do_start_xmit(struct sk_buff *skb,
struct net_device *dev);
static void xirc_tx_timeout(struct net_device *dev);
static void xirc2ps_tx_timeout_task(struct work_struct *work);
static void set_addresses(struct net_device *dev);
static void set_multicast_list(struct net_device *dev);
static int set_card_type(struct pcmcia_device *link);
static int do_config(struct net_device *dev, struct ifmap *map);
static int do_open(struct net_device *dev);
static int do_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
static const struct ethtool_ops netdev_ethtool_ops;
static void hardreset(struct net_device *dev);
static void do_reset(struct net_device *dev, int full);
static int init_mii(struct net_device *dev);
static void do_powerdown(struct net_device *dev);
static int do_stop(struct net_device *dev);
/*=============== Helper functions =========================*/
#define SelectPage(pgnr) outb((pgnr), ioaddr + XIRCREG_PR)
#define GetByte(reg) ((unsigned)inb(ioaddr + (reg)))
#define GetWord(reg) ((unsigned)inw(ioaddr + (reg)))
#define PutByte(reg,value) outb((value), ioaddr+(reg))
#define PutWord(reg,value) outw((value), ioaddr+(reg))
/*====== Functions used for debugging =================================*/
#if 0 /* reading regs may change system status */
static void
PrintRegisters(struct net_device *dev)
{
unsigned int ioaddr = dev->base_addr;
if (pc_debug > 1) {
int i, page;
printk(KERN_DEBUG pr_fmt("Register common: "));
for (i = 0; i < 8; i++)
pr_cont(" %2.2x", GetByte(i));
pr_cont("\n");
for (page = 0; page <= 8; page++) {
printk(KERN_DEBUG pr_fmt("Register page %2x: "), page);
SelectPage(page);
for (i = 8; i < 16; i++)
pr_cont(" %2.2x", GetByte(i));
pr_cont("\n");
}
for (page=0x40 ; page <= 0x5f; page++) {
if (page == 0x43 || (page >= 0x46 && page <= 0x4f) ||
(page >= 0x51 && page <=0x5e))
continue;
printk(KERN_DEBUG pr_fmt("Register page %2x: "), page);
SelectPage(page);
for (i = 8; i < 16; i++)
pr_cont(" %2.2x", GetByte(i));
pr_cont("\n");
}
}
}
#endif /* 0 */
/*============== MII Management functions ===============*/
/****************
* Turn around for read
*/
static void
mii_idle(unsigned int ioaddr)
{
PutByte(XIRCREG2_GPR2, 0x04|0); /* drive MDCK low */
udelay(1);
PutByte(XIRCREG2_GPR2, 0x04|1); /* and drive MDCK high */
udelay(1);
}
/****************
* Write a bit to MDI/O
*/
static void
mii_putbit(unsigned int ioaddr, unsigned data)
{
#if 1
if (data) {
PutByte(XIRCREG2_GPR2, 0x0c|2|0); /* set MDIO */
udelay(1);
PutByte(XIRCREG2_GPR2, 0x0c|2|1); /* and drive MDCK high */
udelay(1);
} else {
PutByte(XIRCREG2_GPR2, 0x0c|0|0); /* clear MDIO */
udelay(1);
PutByte(XIRCREG2_GPR2, 0x0c|0|1); /* and drive MDCK high */
udelay(1);
}
#else
if (data) {
PutWord(XIRCREG2_GPR2-1, 0x0e0e);
udelay(1);
PutWord(XIRCREG2_GPR2-1, 0x0f0f);
udelay(1);
} else {
PutWord(XIRCREG2_GPR2-1, 0x0c0c);
udelay(1);
PutWord(XIRCREG2_GPR2-1, 0x0d0d);
udelay(1);
}
#endif
}
/****************
* Get a bit from MDI/O
*/
static int
mii_getbit(unsigned int ioaddr)
{
unsigned d;
PutByte(XIRCREG2_GPR2, 4|0); /* drive MDCK low */
udelay(1);
d = GetByte(XIRCREG2_GPR2); /* read MDIO */
PutByte(XIRCREG2_GPR2, 4|1); /* drive MDCK high again */
udelay(1);
return d & 0x20; /* read MDIO */
}
static void
mii_wbits(unsigned int ioaddr, unsigned data, int len)
{
unsigned m = 1 << (len-1);
for (; m; m >>= 1)
mii_putbit(ioaddr, data & m);
}
static unsigned
mii_rd(unsigned int ioaddr, u_char phyaddr, u_char phyreg)
{
int i;
unsigned data=0, m;
SelectPage(2);
for (i=0; i < 32; i++) /* 32 bit preamble */
mii_putbit(ioaddr, 1);
mii_wbits(ioaddr, 0x06, 4); /* Start and opcode for read */
mii_wbits(ioaddr, phyaddr, 5); /* PHY address to be accessed */
mii_wbits(ioaddr, phyreg, 5); /* PHY register to read */
mii_idle(ioaddr); /* turn around */
mii_getbit(ioaddr);
for (m = 1<<15; m; m >>= 1)
if (mii_getbit(ioaddr))
data |= m;
mii_idle(ioaddr);
return data;
}
static void
mii_wr(unsigned int ioaddr, u_char phyaddr, u_char phyreg, unsigned data,
int len)
{
int i;
SelectPage(2);
for (i=0; i < 32; i++) /* 32 bit preamble */
mii_putbit(ioaddr, 1);
mii_wbits(ioaddr, 0x05, 4); /* Start and opcode for write */
mii_wbits(ioaddr, phyaddr, 5); /* PHY address to be accessed */
mii_wbits(ioaddr, phyreg, 5); /* PHY Register to write */
mii_putbit(ioaddr, 1); /* turn around */
mii_putbit(ioaddr, 0);
mii_wbits(ioaddr, data, len); /* And write the data */
mii_idle(ioaddr);
}
/*============= Main bulk of functions =========================*/
static const struct net_device_ops netdev_ops = {
.ndo_open = do_open,
.ndo_stop = do_stop,
.ndo_start_xmit = do_start_xmit,
.ndo_tx_timeout = xirc_tx_timeout,
.ndo_set_config = do_config,
.ndo_do_ioctl = do_ioctl,
.ndo_set_rx_mode = set_multicast_list,
.ndo_change_mtu = eth_change_mtu,
.ndo_set_mac_address = eth_mac_addr,
.ndo_validate_addr = eth_validate_addr,
};
static int
xirc2ps_probe(struct pcmcia_device *link)
{
struct net_device *dev;
local_info_t *local;
dev_dbg(&link->dev, "attach()\n");
/* Allocate the device structure */
dev = alloc_etherdev(sizeof(local_info_t));
if (!dev)
return -ENOMEM;
local = netdev_priv(dev);
local->dev = dev;
local->p_dev = link;
link->priv = dev;
/* General socket configuration */
link->config_index = 1;
/* Fill in card specific entries */
dev->netdev_ops = &netdev_ops;
dev->ethtool_ops = &netdev_ethtool_ops;
dev->watchdog_timeo = TX_TIMEOUT;
INIT_WORK(&local->tx_timeout_task, xirc2ps_tx_timeout_task);
return xirc2ps_config(link);
} /* xirc2ps_attach */
static void
xirc2ps_detach(struct pcmcia_device *link)
{
struct net_device *dev = link->priv;
dev_dbg(&link->dev, "detach\n");
unregister_netdev(dev);
xirc2ps_release(link);
free_netdev(dev);
} /* xirc2ps_detach */
/****************
* Detect the type of the card. s is the buffer with the data of tuple 0x20
* Returns: 0 := not supported
* mediaid=11 and prodid=47
* Media-Id bits:
* Ethernet 0x01
* Tokenring 0x02
* Arcnet 0x04
* Wireless 0x08
* Modem 0x10
* GSM only 0x20
* Prod-Id bits:
* Pocket 0x10
* External 0x20
* Creditcard 0x40
* Cardbus 0x80
*
*/
static int
set_card_type(struct pcmcia_device *link)
{
struct net_device *dev = link->priv;
local_info_t *local = netdev_priv(dev);
u8 *buf;
unsigned int cisrev, mediaid, prodid;
size_t len;
len = pcmcia_get_tuple(link, CISTPL_MANFID, &buf);
if (len < 5) {
dev_err(&link->dev, "invalid CIS -- sorry\n");
return 0;
}
cisrev = buf[2];
mediaid = buf[3];
prodid = buf[4];
dev_dbg(&link->dev, "cisrev=%02x mediaid=%02x prodid=%02x\n",
cisrev, mediaid, prodid);
local->mohawk = 0;
local->dingo = 0;
local->modem = 0;
local->card_type = XIR_UNKNOWN;
if (!(prodid & 0x40)) {
pr_notice("Oops: Not a creditcard\n");
return 0;
}
if (!(mediaid & 0x01)) {
pr_notice("Not an Ethernet card\n");
return 0;
}
if (mediaid & 0x10) {
local->modem = 1;
switch(prodid & 15) {
case 1: local->card_type = XIR_CEM ; break;
case 2: local->card_type = XIR_CEM2 ; break;
case 3: local->card_type = XIR_CEM3 ; break;
case 4: local->card_type = XIR_CEM33 ; break;
case 5: local->card_type = XIR_CEM56M;
local->mohawk = 1;
break;
case 6:
case 7: /* 7 is the RealPort 10/56 */
local->card_type = XIR_CEM56 ;
local->mohawk = 1;
local->dingo = 1;
break;
}
} else {
switch(prodid & 15) {
case 1: local->card_type = has_ce2_string(link)? XIR_CE2 : XIR_CE ;
break;
case 2: local->card_type = XIR_CE2; break;
case 3: local->card_type = XIR_CE3;
local->mohawk = 1;
break;
}
}
if (local->card_type == XIR_CE || local->card_type == XIR_CEM) {
pr_notice("Sorry, this is an old CE card\n");
return 0;
}
if (local->card_type == XIR_UNKNOWN)
pr_notice("unknown card (mediaid=%02x prodid=%02x)\n", mediaid, prodid);
return 1;
}
/****************
* There are some CE2 cards out which claim to be a CE card.
* This function looks for a "CE2" in the 3rd version field.
* Returns: true if this is a CE2
*/
static int
has_ce2_string(struct pcmcia_device * p_dev)
{
if (p_dev->prod_id[2] && strstr(p_dev->prod_id[2], "CE2"))
return 1;
return 0;
}
static int
xirc2ps_config_modem(struct pcmcia_device *p_dev, void *priv_data)
{
unsigned int ioaddr;
if ((p_dev->resource[0]->start & 0xf) == 8)
return -ENODEV;
p_dev->resource[0]->end = 16;
p_dev->resource[1]->end = 8;
p_dev->resource[0]->flags &= ~IO_DATA_PATH_WIDTH;
p_dev->resource[0]->flags |= IO_DATA_PATH_WIDTH_16;
p_dev->resource[1]->flags &= ~IO_DATA_PATH_WIDTH;
p_dev->resource[1]->flags |= IO_DATA_PATH_WIDTH_8;
p_dev->io_lines = 10;
p_dev->resource[1]->start = p_dev->resource[0]->start;
for (ioaddr = 0x300; ioaddr < 0x400; ioaddr += 0x10) {
p_dev->resource[0]->start = ioaddr;
if (!pcmcia_request_io(p_dev))
return 0;
}
return -ENODEV;
}
static int
xirc2ps_config_check(struct pcmcia_device *p_dev, void *priv_data)
{
int *pass = priv_data;
resource_size_t tmp = p_dev->resource[1]->start;
tmp += (*pass ? (p_dev->config_index & 0x20 ? -24 : 8)
: (p_dev->config_index & 0x20 ? 8 : -24));
if ((p_dev->resource[0]->start & 0xf) == 8)
return -ENODEV;
p_dev->resource[0]->end = 18;
p_dev->resource[1]->end = 8;
p_dev->resource[0]->flags &= ~IO_DATA_PATH_WIDTH;
p_dev->resource[0]->flags |= IO_DATA_PATH_WIDTH_16;
p_dev->resource[1]->flags &= ~IO_DATA_PATH_WIDTH;
p_dev->resource[1]->flags |= IO_DATA_PATH_WIDTH_8;
p_dev->io_lines = 10;
p_dev->resource[1]->start = p_dev->resource[0]->start;
p_dev->resource[0]->start = tmp;
return pcmcia_request_io(p_dev);
}
static int pcmcia_get_mac_ce(struct pcmcia_device *p_dev,
tuple_t *tuple,
void *priv)
{
struct net_device *dev = priv;
int i;
if (tuple->TupleDataLen != 13)
return -EINVAL;
if ((tuple->TupleData[0] != 2) || (tuple->TupleData[1] != 1) ||
(tuple->TupleData[2] != 6))
return -EINVAL;
/* another try (James Lehmer's CE2 version 4.1)*/
for (i = 2; i < 6; i++)
dev->dev_addr[i] = tuple->TupleData[i+2];
return 0;
};
static int
xirc2ps_config(struct pcmcia_device * link)
{
struct net_device *dev = link->priv;
local_info_t *local = netdev_priv(dev);
unsigned int ioaddr;
int err;
u8 *buf;
size_t len;
local->dingo_ccr = NULL;
dev_dbg(&link->dev, "config\n");
/* Is this a valid card */
if (link->has_manf_id == 0) {
pr_notice("manfid not found in CIS\n");
goto failure;
}
switch (link->manf_id) {
case MANFID_XIRCOM:
local->manf_str = "Xircom";
break;
case MANFID_ACCTON:
local->manf_str = "Accton";
break;
case MANFID_COMPAQ:
case MANFID_COMPAQ2:
local->manf_str = "Compaq";
break;
case MANFID_INTEL:
local->manf_str = "Intel";
break;
case MANFID_TOSHIBA:
local->manf_str = "Toshiba";
break;
default:
pr_notice("Unknown Card Manufacturer ID: 0x%04x\n",
(unsigned)link->manf_id);
goto failure;
}
dev_dbg(&link->dev, "found %s card\n", local->manf_str);
if (!set_card_type(link)) {
pr_notice("this card is not supported\n");
goto failure;
}
/* get the ethernet address from the CIS */
err = pcmcia_get_mac_from_cis(link, dev);
/* not found: try to get the node-id from tuple 0x89 */
if (err) {
len = pcmcia_get_tuple(link, 0x89, &buf);
/* data layout looks like tuple 0x22 */
if (buf && len == 8) {
if (*buf == CISTPL_FUNCE_LAN_NODE_ID) {
int i;
for (i = 2; i < 6; i++)
dev->dev_addr[i] = buf[i+2];
} else
err = -1;
}
kfree(buf);
}
if (err)
err = pcmcia_loop_tuple(link, CISTPL_FUNCE, pcmcia_get_mac_ce, dev);
if (err) {
pr_notice("node-id not found in CIS\n");
goto failure;
}
if (local->modem) {
int pass;
link->config_flags |= CONF_AUTO_SET_IO;
if (local->dingo) {
/* Take the Modem IO port from the CIS and scan for a free
* Ethernet port */
if (!pcmcia_loop_config(link, xirc2ps_config_modem, NULL))
goto port_found;
} else {
/* We do 2 passes here: The first one uses the regular mapping and
* the second tries again, thereby considering that the 32 ports are
* mirrored every 32 bytes. Actually we use a mirrored port for
* the Mako if (on the first pass) the COR bit 5 is set.
*/
for (pass=0; pass < 2; pass++)
if (!pcmcia_loop_config(link, xirc2ps_config_check,
&pass))
goto port_found;
/* if special option:
* try to configure as Ethernet only.
* .... */
}
pr_notice("no ports available\n");
} else {
link->io_lines = 10;
link->resource[0]->end = 16;
link->resource[0]->flags |= IO_DATA_PATH_WIDTH_16;
for (ioaddr = 0x300; ioaddr < 0x400; ioaddr += 0x10) {
link->resource[0]->start = ioaddr;
if (!(err = pcmcia_request_io(link)))
goto port_found;
}
link->resource[0]->start = 0; /* let CS decide */
if ((err = pcmcia_request_io(link)))
goto config_error;
}
port_found:
if (err)
goto config_error;
/****************
* Now allocate an interrupt line. Note that this does not
* actually assign a handler to the interrupt.
*/
if ((err=pcmcia_request_irq(link, xirc2ps_interrupt)))
goto config_error;
link->config_flags |= CONF_ENABLE_IRQ;
if (do_sound)
link->config_flags |= CONF_ENABLE_SPKR;
if ((err = pcmcia_enable_device(link)))
goto config_error;
if (local->dingo) {
/* Reset the modem's BAR to the correct value
* This is necessary because in the RequestConfiguration call,
* the base address of the ethernet port (BasePort1) is written
* to the BAR registers of the modem.
*/
err = pcmcia_write_config_byte(link, CISREG_IOBASE_0, (u8)
link->resource[1]->start & 0xff);
if (err)
goto config_error;
err = pcmcia_write_config_byte(link, CISREG_IOBASE_1,
(link->resource[1]->start >> 8) & 0xff);
if (err)
goto config_error;
/* There is no config entry for the Ethernet part which
* is at 0x0800. So we allocate a window into the attribute
* memory and write direct to the CIS registers
*/
link->resource[2]->flags = WIN_DATA_WIDTH_8 | WIN_MEMORY_TYPE_AM |
WIN_ENABLE;
link->resource[2]->start = link->resource[2]->end = 0;
if ((err = pcmcia_request_window(link, link->resource[2], 0)))
goto config_error;
local->dingo_ccr = ioremap(link->resource[2]->start, 0x1000) + 0x0800;
if ((err = pcmcia_map_mem_page(link, link->resource[2], 0)))
goto config_error;
/* Setup the CCRs; there are no infos in the CIS about the Ethernet
* part.
*/
writeb(0x47, local->dingo_ccr + CISREG_COR);
ioaddr = link->resource[0]->start;
writeb(ioaddr & 0xff , local->dingo_ccr + CISREG_IOBASE_0);
writeb((ioaddr >> 8)&0xff , local->dingo_ccr + CISREG_IOBASE_1);
#if 0
{
u_char tmp;
pr_info("ECOR:");
for (i=0; i < 7; i++) {
tmp = readb(local->dingo_ccr + i*2);
pr_cont(" %02x", tmp);
}
pr_cont("\n");
pr_info("DCOR:");
for (i=0; i < 4; i++) {
tmp = readb(local->dingo_ccr + 0x20 + i*2);
pr_cont(" %02x", tmp);
}
pr_cont("\n");
pr_info("SCOR:");
for (i=0; i < 10; i++) {
tmp = readb(local->dingo_ccr + 0x40 + i*2);
pr_cont(" %02x", tmp);
}
pr_cont("\n");
}
#endif
writeb(0x01, local->dingo_ccr + 0x20);
writeb(0x0c, local->dingo_ccr + 0x22);
writeb(0x00, local->dingo_ccr + 0x24);
writeb(0x00, local->dingo_ccr + 0x26);
writeb(0x00, local->dingo_ccr + 0x28);
}
/* The if_port symbol can be set when the module is loaded */
local->probe_port=0;
if (!if_port) {
local->probe_port = dev->if_port = 1;
} else if ((if_port >= 1 && if_port <= 2) ||
(local->mohawk && if_port==4))
dev->if_port = if_port;
else
pr_notice("invalid if_port requested\n");
/* we can now register the device with the net subsystem */
dev->irq = link->irq;
dev->base_addr = link->resource[0]->start;
if (local->dingo)
do_reset(dev, 1); /* a kludge to make the cem56 work */
SET_NETDEV_DEV(dev, &link->dev);
if ((err=register_netdev(dev))) {
pr_notice("register_netdev() failed\n");
goto config_error;
}
/* give some infos about the hardware */
netdev_info(dev, "%s: port %#3lx, irq %d, hwaddr %pM\n",
local->manf_str, (u_long)dev->base_addr, (int)dev->irq,
dev->dev_addr);
return 0;
config_error:
xirc2ps_release(link);
return -ENODEV;
failure:
return -ENODEV;
} /* xirc2ps_config */
static void
xirc2ps_release(struct pcmcia_device *link)
{
dev_dbg(&link->dev, "release\n");
if (link->resource[2]->end) {
struct net_device *dev = link->priv;
local_info_t *local = netdev_priv(dev);
if (local->dingo)
iounmap(local->dingo_ccr - 0x0800);
}
pcmcia_disable_device(link);
} /* xirc2ps_release */
/*====================================================================*/
static int xirc2ps_suspend(struct pcmcia_device *link)
{
struct net_device *dev = link->priv;
if (link->open) {
netif_device_detach(dev);
do_powerdown(dev);
}
return 0;
}
static int xirc2ps_resume(struct pcmcia_device *link)
{
struct net_device *dev = link->priv;
if (link->open) {
do_reset(dev,1);
netif_device_attach(dev);
}
return 0;
}
/*====================================================================*/
/****************
* This is the Interrupt service route.
*/
static irqreturn_t
xirc2ps_interrupt(int irq, void *dev_id)
{
struct net_device *dev = (struct net_device *)dev_id;
local_info_t *lp = netdev_priv(dev);
unsigned int ioaddr;
u_char saved_page;
unsigned bytes_rcvd;
unsigned int_status, eth_status, rx_status, tx_status;
unsigned rsr, pktlen;
ulong start_ticks = jiffies; /* fixme: jiffies rollover every 497 days
* is this something to worry about?
* -- on a laptop?
*/
if (!netif_device_present(dev))
return IRQ_HANDLED;
ioaddr = dev->base_addr;
if (lp->mohawk) { /* must disable the interrupt */
PutByte(XIRCREG_CR, 0);
}
pr_debug("%s: interrupt %d at %#x.\n", dev->name, irq, ioaddr);
saved_page = GetByte(XIRCREG_PR);