forked from torvalds/linux
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsmctr.c
5742 lines (4622 loc) · 187 KB
/
smctr.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
/*
* smctr.c: A network driver for the SMC Token Ring Adapters.
*
* Written by Jay Schulist <[email protected]>
*
* This software may be used and distributed according to the terms
* of the GNU General Public License, incorporated herein by reference.
*
* This device driver works with the following SMC adapters:
* - SMC TokenCard Elite (8115T, chips 825/584)
* - SMC TokenCard Elite/A MCA (8115T/A, chips 825/594)
*
* Source(s):
* - SMC TokenCard SDK.
*
* Maintainer(s):
* JS Jay Schulist <[email protected]>
*
* Changes:
* 07102000 JS Fixed a timing problem in smctr_wait_cmd();
* Also added a bit more discriptive error msgs.
* 07122000 JS Fixed problem with detecting a card with
* module io/irq/mem specified.
*
* To do:
* 1. Multicast support.
*
* Initial 2.5 cleanup Alan Cox <[email protected]> 2002/10/28
*/
#include <linux/module.h>
#include <linux/config.h>
#include <linux/kernel.h>
#include <linux/types.h>
#include <linux/fcntl.h>
#include <linux/interrupt.h>
#include <linux/ptrace.h>
#include <linux/ioport.h>
#include <linux/in.h>
#include <linux/slab.h>
#include <linux/string.h>
#include <linux/time.h>
#include <linux/errno.h>
#include <linux/init.h>
#include <linux/pci.h>
#include <linux/mca-legacy.h>
#include <linux/delay.h>
#include <linux/netdevice.h>
#include <linux/etherdevice.h>
#include <linux/skbuff.h>
#include <linux/trdevice.h>
#include <linux/bitops.h>
#include <asm/system.h>
#include <asm/io.h>
#include <asm/dma.h>
#include <asm/irq.h>
#if BITS_PER_LONG == 64
#error FIXME: driver does not support 64-bit platforms
#endif
#include "smctr.h" /* Our Stuff */
#include "smctr_firmware.h" /* SMC adapter firmware */
static char version[] __initdata = KERN_INFO "smctr.c: v1.4 7/12/00 by [email protected]\n";
static const char cardname[] = "smctr";
#define SMCTR_IO_EXTENT 20
#ifdef CONFIG_MCA_LEGACY
static unsigned int smctr_posid = 0x6ec6;
#endif
static int ringspeed;
/* SMC Name of the Adapter. */
static char smctr_name[] = "SMC TokenCard";
static char *smctr_model = "Unknown";
/* Use 0 for production, 1 for verification, 2 for debug, and
* 3 for very verbose debug.
*/
#ifndef SMCTR_DEBUG
#define SMCTR_DEBUG 1
#endif
static unsigned int smctr_debug = SMCTR_DEBUG;
/* smctr.c prototypes and functions are arranged alphabeticly
* for clearity, maintainability and pure old fashion fun.
*/
/* A */
static int smctr_alloc_shared_memory(struct net_device *dev);
/* B */
static int smctr_bypass_state(struct net_device *dev);
/* C */
static int smctr_checksum_firmware(struct net_device *dev);
static int __init smctr_chk_isa(struct net_device *dev);
static int smctr_chg_rx_mask(struct net_device *dev);
static int smctr_clear_int(struct net_device *dev);
static int smctr_clear_trc_reset(int ioaddr);
static int smctr_close(struct net_device *dev);
/* D */
static int smctr_decode_firmware(struct net_device *dev);
static int smctr_disable_16bit(struct net_device *dev);
static int smctr_disable_adapter_ctrl_store(struct net_device *dev);
static int smctr_disable_bic_int(struct net_device *dev);
/* E */
static int smctr_enable_16bit(struct net_device *dev);
static int smctr_enable_adapter_ctrl_store(struct net_device *dev);
static int smctr_enable_adapter_ram(struct net_device *dev);
static int smctr_enable_bic_int(struct net_device *dev);
/* G */
static int __init smctr_get_boardid(struct net_device *dev, int mca);
static int smctr_get_group_address(struct net_device *dev);
static int smctr_get_functional_address(struct net_device *dev);
static unsigned int smctr_get_num_rx_bdbs(struct net_device *dev);
static int smctr_get_physical_drop_number(struct net_device *dev);
static __u8 *smctr_get_rx_pointer(struct net_device *dev, short queue);
static int smctr_get_station_id(struct net_device *dev);
static struct net_device_stats *smctr_get_stats(struct net_device *dev);
static FCBlock *smctr_get_tx_fcb(struct net_device *dev, __u16 queue,
__u16 bytes_count);
static int smctr_get_upstream_neighbor_addr(struct net_device *dev);
/* H */
static int smctr_hardware_send_packet(struct net_device *dev,
struct net_local *tp);
/* I */
static int smctr_init_acbs(struct net_device *dev);
static int smctr_init_adapter(struct net_device *dev);
static int smctr_init_card_real(struct net_device *dev);
static int smctr_init_rx_bdbs(struct net_device *dev);
static int smctr_init_rx_fcbs(struct net_device *dev);
static int smctr_init_shared_memory(struct net_device *dev);
static int smctr_init_tx_bdbs(struct net_device *dev);
static int smctr_init_tx_fcbs(struct net_device *dev);
static int smctr_internal_self_test(struct net_device *dev);
static irqreturn_t smctr_interrupt(int irq, void *dev_id, struct pt_regs *regs);
static int smctr_issue_enable_int_cmd(struct net_device *dev,
__u16 interrupt_enable_mask);
static int smctr_issue_int_ack(struct net_device *dev, __u16 iack_code,
__u16 ibits);
static int smctr_issue_init_timers_cmd(struct net_device *dev);
static int smctr_issue_init_txrx_cmd(struct net_device *dev);
static int smctr_issue_insert_cmd(struct net_device *dev);
static int smctr_issue_read_ring_status_cmd(struct net_device *dev);
static int smctr_issue_read_word_cmd(struct net_device *dev, __u16 aword_cnt);
static int smctr_issue_remove_cmd(struct net_device *dev);
static int smctr_issue_resume_acb_cmd(struct net_device *dev);
static int smctr_issue_resume_rx_bdb_cmd(struct net_device *dev, __u16 queue);
static int smctr_issue_resume_rx_fcb_cmd(struct net_device *dev, __u16 queue);
static int smctr_issue_resume_tx_fcb_cmd(struct net_device *dev, __u16 queue);
static int smctr_issue_test_internal_rom_cmd(struct net_device *dev);
static int smctr_issue_test_hic_cmd(struct net_device *dev);
static int smctr_issue_test_mac_reg_cmd(struct net_device *dev);
static int smctr_issue_trc_loopback_cmd(struct net_device *dev);
static int smctr_issue_tri_loopback_cmd(struct net_device *dev);
static int smctr_issue_write_byte_cmd(struct net_device *dev,
short aword_cnt, void *byte);
static int smctr_issue_write_word_cmd(struct net_device *dev,
short aword_cnt, void *word);
/* J */
static int smctr_join_complete_state(struct net_device *dev);
/* L */
static int smctr_link_tx_fcbs_to_bdbs(struct net_device *dev);
static int smctr_load_firmware(struct net_device *dev);
static int smctr_load_node_addr(struct net_device *dev);
static int smctr_lobe_media_test(struct net_device *dev);
static int smctr_lobe_media_test_cmd(struct net_device *dev);
static int smctr_lobe_media_test_state(struct net_device *dev);
/* M */
static int smctr_make_8025_hdr(struct net_device *dev,
MAC_HEADER *rmf, MAC_HEADER *tmf, __u16 ac_fc);
static int smctr_make_access_pri(struct net_device *dev,
MAC_SUB_VECTOR *tsv);
static int smctr_make_addr_mod(struct net_device *dev, MAC_SUB_VECTOR *tsv);
static int smctr_make_auth_funct_class(struct net_device *dev,
MAC_SUB_VECTOR *tsv);
static int smctr_make_corr(struct net_device *dev,
MAC_SUB_VECTOR *tsv, __u16 correlator);
static int smctr_make_funct_addr(struct net_device *dev,
MAC_SUB_VECTOR *tsv);
static int smctr_make_group_addr(struct net_device *dev,
MAC_SUB_VECTOR *tsv);
static int smctr_make_phy_drop_num(struct net_device *dev,
MAC_SUB_VECTOR *tsv);
static int smctr_make_product_id(struct net_device *dev, MAC_SUB_VECTOR *tsv);
static int smctr_make_station_id(struct net_device *dev, MAC_SUB_VECTOR *tsv);
static int smctr_make_ring_station_status(struct net_device *dev,
MAC_SUB_VECTOR *tsv);
static int smctr_make_ring_station_version(struct net_device *dev,
MAC_SUB_VECTOR *tsv);
static int smctr_make_tx_status_code(struct net_device *dev,
MAC_SUB_VECTOR *tsv, __u16 tx_fstatus);
static int smctr_make_upstream_neighbor_addr(struct net_device *dev,
MAC_SUB_VECTOR *tsv);
static int smctr_make_wrap_data(struct net_device *dev,
MAC_SUB_VECTOR *tsv);
/* O */
static int smctr_open(struct net_device *dev);
static int smctr_open_tr(struct net_device *dev);
/* P */
struct net_device *smctr_probe(int unit);
static int __init smctr_probe1(struct net_device *dev, int ioaddr);
static int smctr_process_rx_packet(MAC_HEADER *rmf, __u16 size,
struct net_device *dev, __u16 rx_status);
/* R */
static int smctr_ram_memory_test(struct net_device *dev);
static int smctr_rcv_chg_param(struct net_device *dev, MAC_HEADER *rmf,
__u16 *correlator);
static int smctr_rcv_init(struct net_device *dev, MAC_HEADER *rmf,
__u16 *correlator);
static int smctr_rcv_tx_forward(struct net_device *dev, MAC_HEADER *rmf);
static int smctr_rcv_rq_addr_state_attch(struct net_device *dev,
MAC_HEADER *rmf, __u16 *correlator);
static int smctr_rcv_unknown(struct net_device *dev, MAC_HEADER *rmf,
__u16 *correlator);
static int smctr_reset_adapter(struct net_device *dev);
static int smctr_restart_tx_chain(struct net_device *dev, short queue);
static int smctr_ring_status_chg(struct net_device *dev);
static int smctr_rx_frame(struct net_device *dev);
/* S */
static int smctr_send_dat(struct net_device *dev);
static int smctr_send_packet(struct sk_buff *skb, struct net_device *dev);
static int smctr_send_lobe_media_test(struct net_device *dev);
static int smctr_send_rpt_addr(struct net_device *dev, MAC_HEADER *rmf,
__u16 correlator);
static int smctr_send_rpt_attch(struct net_device *dev, MAC_HEADER *rmf,
__u16 correlator);
static int smctr_send_rpt_state(struct net_device *dev, MAC_HEADER *rmf,
__u16 correlator);
static int smctr_send_rpt_tx_forward(struct net_device *dev,
MAC_HEADER *rmf, __u16 tx_fstatus);
static int smctr_send_rsp(struct net_device *dev, MAC_HEADER *rmf,
__u16 rcode, __u16 correlator);
static int smctr_send_rq_init(struct net_device *dev);
static int smctr_send_tx_forward(struct net_device *dev, MAC_HEADER *rmf,
__u16 *tx_fstatus);
static int smctr_set_auth_access_pri(struct net_device *dev,
MAC_SUB_VECTOR *rsv);
static int smctr_set_auth_funct_class(struct net_device *dev,
MAC_SUB_VECTOR *rsv);
static int smctr_set_corr(struct net_device *dev, MAC_SUB_VECTOR *rsv,
__u16 *correlator);
static int smctr_set_error_timer_value(struct net_device *dev,
MAC_SUB_VECTOR *rsv);
static int smctr_set_frame_forward(struct net_device *dev,
MAC_SUB_VECTOR *rsv, __u8 dc_sc);
static int smctr_set_local_ring_num(struct net_device *dev,
MAC_SUB_VECTOR *rsv);
static unsigned short smctr_set_ctrl_attention(struct net_device *dev);
static void smctr_set_multicast_list(struct net_device *dev);
static int smctr_set_page(struct net_device *dev, __u8 *buf);
static int smctr_set_phy_drop(struct net_device *dev,
MAC_SUB_VECTOR *rsv);
static int smctr_set_ring_speed(struct net_device *dev);
static int smctr_set_rx_look_ahead(struct net_device *dev);
static int smctr_set_trc_reset(int ioaddr);
static int smctr_setup_single_cmd(struct net_device *dev,
__u16 command, __u16 subcommand);
static int smctr_setup_single_cmd_w_data(struct net_device *dev,
__u16 command, __u16 subcommand);
static char *smctr_malloc(struct net_device *dev, __u16 size);
static int smctr_status_chg(struct net_device *dev);
/* T */
static void smctr_timeout(struct net_device *dev);
static int smctr_trc_send_packet(struct net_device *dev, FCBlock *fcb,
__u16 queue);
static __u16 smctr_tx_complete(struct net_device *dev, __u16 queue);
static unsigned short smctr_tx_move_frame(struct net_device *dev,
struct sk_buff *skb, __u8 *pbuff, unsigned int bytes);
/* U */
static int smctr_update_err_stats(struct net_device *dev);
static int smctr_update_rx_chain(struct net_device *dev, __u16 queue);
static int smctr_update_tx_chain(struct net_device *dev, FCBlock *fcb,
__u16 queue);
/* W */
static int smctr_wait_cmd(struct net_device *dev);
static int smctr_wait_while_cbusy(struct net_device *dev);
#define TO_256_BYTE_BOUNDRY(X) (((X + 0xff) & 0xff00) - X)
#define TO_PARAGRAPH_BOUNDRY(X) (((X + 0x0f) & 0xfff0) - X)
#define PARAGRAPH_BOUNDRY(X) smctr_malloc(dev, TO_PARAGRAPH_BOUNDRY(X))
/* Allocate Adapter Shared Memory.
* IMPORTANT NOTE: Any changes to this function MUST be mirrored in the
* function "get_num_rx_bdbs" below!!!
*
* Order of memory allocation:
*
* 0. Initial System Configuration Block Pointer
* 1. System Configuration Block
* 2. System Control Block
* 3. Action Command Block
* 4. Interrupt Status Block
*
* 5. MAC TX FCB'S
* 6. NON-MAC TX FCB'S
* 7. MAC TX BDB'S
* 8. NON-MAC TX BDB'S
* 9. MAC RX FCB'S
* 10. NON-MAC RX FCB'S
* 11. MAC RX BDB'S
* 12. NON-MAC RX BDB'S
* 13. MAC TX Data Buffer( 1, 256 byte buffer)
* 14. MAC RX Data Buffer( 1, 256 byte buffer)
*
* 15. NON-MAC TX Data Buffer
* 16. NON-MAC RX Data Buffer
*/
static int smctr_alloc_shared_memory(struct net_device *dev)
{
struct net_local *tp = netdev_priv(dev);
if(smctr_debug > 10)
printk(KERN_DEBUG "%s: smctr_alloc_shared_memory\n", dev->name);
/* Allocate initial System Control Block pointer.
* This pointer is located in the last page, last offset - 4.
*/
tp->iscpb_ptr = (ISCPBlock *)(tp->ram_access + ((__u32)64 * 0x400)
- (long)ISCP_BLOCK_SIZE);
/* Allocate System Control Blocks. */
tp->scgb_ptr = (SCGBlock *)smctr_malloc(dev, sizeof(SCGBlock));
PARAGRAPH_BOUNDRY(tp->sh_mem_used);
tp->sclb_ptr = (SCLBlock *)smctr_malloc(dev, sizeof(SCLBlock));
PARAGRAPH_BOUNDRY(tp->sh_mem_used);
tp->acb_head = (ACBlock *)smctr_malloc(dev,
sizeof(ACBlock)*tp->num_acbs);
PARAGRAPH_BOUNDRY(tp->sh_mem_used);
tp->isb_ptr = (ISBlock *)smctr_malloc(dev, sizeof(ISBlock));
PARAGRAPH_BOUNDRY(tp->sh_mem_used);
tp->misc_command_data = (__u16 *)smctr_malloc(dev, MISC_DATA_SIZE);
PARAGRAPH_BOUNDRY(tp->sh_mem_used);
/* Allocate transmit FCBs. */
tp->tx_fcb_head[MAC_QUEUE] = (FCBlock *)smctr_malloc(dev,
sizeof(FCBlock) * tp->num_tx_fcbs[MAC_QUEUE]);
tp->tx_fcb_head[NON_MAC_QUEUE] = (FCBlock *)smctr_malloc(dev,
sizeof(FCBlock) * tp->num_tx_fcbs[NON_MAC_QUEUE]);
tp->tx_fcb_head[BUG_QUEUE] = (FCBlock *)smctr_malloc(dev,
sizeof(FCBlock) * tp->num_tx_fcbs[BUG_QUEUE]);
/* Allocate transmit BDBs. */
tp->tx_bdb_head[MAC_QUEUE] = (BDBlock *)smctr_malloc(dev,
sizeof(BDBlock) * tp->num_tx_bdbs[MAC_QUEUE]);
tp->tx_bdb_head[NON_MAC_QUEUE] = (BDBlock *)smctr_malloc(dev,
sizeof(BDBlock) * tp->num_tx_bdbs[NON_MAC_QUEUE]);
tp->tx_bdb_head[BUG_QUEUE] = (BDBlock *)smctr_malloc(dev,
sizeof(BDBlock) * tp->num_tx_bdbs[BUG_QUEUE]);
/* Allocate receive FCBs. */
tp->rx_fcb_head[MAC_QUEUE] = (FCBlock *)smctr_malloc(dev,
sizeof(FCBlock) * tp->num_rx_fcbs[MAC_QUEUE]);
tp->rx_fcb_head[NON_MAC_QUEUE] = (FCBlock *)smctr_malloc(dev,
sizeof(FCBlock) * tp->num_rx_fcbs[NON_MAC_QUEUE]);
/* Allocate receive BDBs. */
tp->rx_bdb_head[MAC_QUEUE] = (BDBlock *)smctr_malloc(dev,
sizeof(BDBlock) * tp->num_rx_bdbs[MAC_QUEUE]);
tp->rx_bdb_end[MAC_QUEUE] = (BDBlock *)smctr_malloc(dev, 0);
tp->rx_bdb_head[NON_MAC_QUEUE] = (BDBlock *)smctr_malloc(dev,
sizeof(BDBlock) * tp->num_rx_bdbs[NON_MAC_QUEUE]);
tp->rx_bdb_end[NON_MAC_QUEUE] = (BDBlock *)smctr_malloc(dev, 0);
/* Allocate MAC transmit buffers.
* MAC Tx Buffers doen't have to be on an ODD Boundry.
*/
tp->tx_buff_head[MAC_QUEUE]
= (__u16 *)smctr_malloc(dev, tp->tx_buff_size[MAC_QUEUE]);
tp->tx_buff_curr[MAC_QUEUE] = tp->tx_buff_head[MAC_QUEUE];
tp->tx_buff_end [MAC_QUEUE] = (__u16 *)smctr_malloc(dev, 0);
/* Allocate BUG transmit buffers. */
tp->tx_buff_head[BUG_QUEUE]
= (__u16 *)smctr_malloc(dev, tp->tx_buff_size[BUG_QUEUE]);
tp->tx_buff_curr[BUG_QUEUE] = tp->tx_buff_head[BUG_QUEUE];
tp->tx_buff_end[BUG_QUEUE] = (__u16 *)smctr_malloc(dev, 0);
/* Allocate MAC receive data buffers.
* MAC Rx buffer doesn't have to be on a 256 byte boundary.
*/
tp->rx_buff_head[MAC_QUEUE] = (__u16 *)smctr_malloc(dev,
RX_DATA_BUFFER_SIZE * tp->num_rx_bdbs[MAC_QUEUE]);
tp->rx_buff_end[MAC_QUEUE] = (__u16 *)smctr_malloc(dev, 0);
/* Allocate Non-MAC transmit buffers.
* ?? For maximum Netware performance, put Tx Buffers on
* ODD Boundry and then restore malloc to Even Boundrys.
*/
smctr_malloc(dev, 1L);
tp->tx_buff_head[NON_MAC_QUEUE]
= (__u16 *)smctr_malloc(dev, tp->tx_buff_size[NON_MAC_QUEUE]);
tp->tx_buff_curr[NON_MAC_QUEUE] = tp->tx_buff_head[NON_MAC_QUEUE];
tp->tx_buff_end [NON_MAC_QUEUE] = (__u16 *)smctr_malloc(dev, 0);
smctr_malloc(dev, 1L);
/* Allocate Non-MAC receive data buffers.
* To guarantee a minimum of 256 contigous memory to
* UM_Receive_Packet's lookahead pointer, before a page
* change or ring end is encountered, place each rx buffer on
* a 256 byte boundary.
*/
smctr_malloc(dev, TO_256_BYTE_BOUNDRY(tp->sh_mem_used));
tp->rx_buff_head[NON_MAC_QUEUE] = (__u16 *)smctr_malloc(dev,
RX_DATA_BUFFER_SIZE * tp->num_rx_bdbs[NON_MAC_QUEUE]);
tp->rx_buff_end[NON_MAC_QUEUE] = (__u16 *)smctr_malloc(dev, 0);
return (0);
}
/* Enter Bypass state. */
static int smctr_bypass_state(struct net_device *dev)
{
int err;
if(smctr_debug > 10)
printk(KERN_DEBUG "%s: smctr_bypass_state\n", dev->name);
err = smctr_setup_single_cmd(dev, ACB_CMD_CHANGE_JOIN_STATE, JS_BYPASS_STATE);
return (err);
}
static int smctr_checksum_firmware(struct net_device *dev)
{
struct net_local *tp = netdev_priv(dev);
__u16 i, checksum = 0;
if(smctr_debug > 10)
printk(KERN_DEBUG "%s: smctr_checksum_firmware\n", dev->name);
smctr_enable_adapter_ctrl_store(dev);
for(i = 0; i < CS_RAM_SIZE; i += 2)
checksum += *((__u16 *)(tp->ram_access + i));
tp->microcode_version = *(__u16 *)(tp->ram_access
+ CS_RAM_VERSION_OFFSET);
tp->microcode_version >>= 8;
smctr_disable_adapter_ctrl_store(dev);
if(checksum)
return (checksum);
return (0);
}
static int __init smctr_chk_mca(struct net_device *dev)
{
#ifdef CONFIG_MCA_LEGACY
struct net_local *tp = netdev_priv(dev);
int current_slot;
__u8 r1, r2, r3, r4, r5;
current_slot = mca_find_unused_adapter(smctr_posid, 0);
if(current_slot == MCA_NOTFOUND)
return (-ENODEV);
mca_set_adapter_name(current_slot, smctr_name);
mca_mark_as_used(current_slot);
tp->slot_num = current_slot;
r1 = mca_read_stored_pos(tp->slot_num, 2);
r2 = mca_read_stored_pos(tp->slot_num, 3);
if(tp->slot_num)
outb(CNFG_POS_CONTROL_REG, (__u8)((tp->slot_num - 1) | CNFG_SLOT_ENABLE_BIT));
else
outb(CNFG_POS_CONTROL_REG, (__u8)((tp->slot_num) | CNFG_SLOT_ENABLE_BIT));
r1 = inb(CNFG_POS_REG1);
r2 = inb(CNFG_POS_REG0);
tp->bic_type = BIC_594_CHIP;
/* IO */
r2 = mca_read_stored_pos(tp->slot_num, 2);
r2 &= 0xF0;
dev->base_addr = ((__u16)r2 << 8) + (__u16)0x800;
request_region(dev->base_addr, SMCTR_IO_EXTENT, smctr_name);
/* IRQ */
r5 = mca_read_stored_pos(tp->slot_num, 5);
r5 &= 0xC;
switch(r5)
{
case 0:
dev->irq = 3;
break;
case 0x4:
dev->irq = 4;
break;
case 0x8:
dev->irq = 10;
break;
default:
dev->irq = 15;
break;
}
if (request_irq(dev->irq, smctr_interrupt, SA_SHIRQ, smctr_name, dev)) {
release_region(dev->base_addr, SMCTR_IO_EXTENT);
return -ENODEV;
}
/* Get RAM base */
r3 = mca_read_stored_pos(tp->slot_num, 3);
tp->ram_base = ((__u32)(r3 & 0x7) << 13) + 0x0C0000;
if (r3 & 0x8)
tp->ram_base += 0x010000;
if (r3 & 0x80)
tp->ram_base += 0xF00000;
/* Get Ram Size */
r3 &= 0x30;
r3 >>= 4;
tp->ram_usable = (__u16)CNFG_SIZE_8KB << r3;
tp->ram_size = (__u16)CNFG_SIZE_64KB;
tp->board_id |= TOKEN_MEDIA;
r4 = mca_read_stored_pos(tp->slot_num, 4);
tp->rom_base = ((__u32)(r4 & 0x7) << 13) + 0x0C0000;
if (r4 & 0x8)
tp->rom_base += 0x010000;
/* Get ROM size. */
r4 >>= 4;
switch (r4) {
case 0:
tp->rom_size = CNFG_SIZE_8KB;
break;
case 1:
tp->rom_size = CNFG_SIZE_16KB;
break;
case 2:
tp->rom_size = CNFG_SIZE_32KB;
break;
default:
tp->rom_size = ROM_DISABLE;
}
/* Get Media Type. */
r5 = mca_read_stored_pos(tp->slot_num, 5);
r5 &= CNFG_MEDIA_TYPE_MASK;
switch(r5)
{
case (0):
tp->media_type = MEDIA_STP_4;
break;
case (1):
tp->media_type = MEDIA_STP_16;
break;
case (3):
tp->media_type = MEDIA_UTP_16;
break;
default:
tp->media_type = MEDIA_UTP_4;
break;
}
tp->media_menu = 14;
r2 = mca_read_stored_pos(tp->slot_num, 2);
if(!(r2 & 0x02))
tp->mode_bits |= EARLY_TOKEN_REL;
/* Disable slot */
outb(CNFG_POS_CONTROL_REG, 0);
tp->board_id = smctr_get_boardid(dev, 1);
switch(tp->board_id & 0xffff)
{
case WD8115TA:
smctr_model = "8115T/A";
break;
case WD8115T:
if(tp->extra_info & CHIP_REV_MASK)
smctr_model = "8115T rev XE";
else
smctr_model = "8115T rev XD";
break;
default:
smctr_model = "Unknown";
break;
}
return (0);
#else
return (-1);
#endif /* CONFIG_MCA_LEGACY */
}
static int smctr_chg_rx_mask(struct net_device *dev)
{
struct net_local *tp = netdev_priv(dev);
int err = 0;
if(smctr_debug > 10)
printk(KERN_DEBUG "%s: smctr_chg_rx_mask\n", dev->name);
smctr_enable_16bit(dev);
smctr_set_page(dev, (__u8 *)tp->ram_access);
if(tp->mode_bits & LOOPING_MODE_MASK)
tp->config_word0 |= RX_OWN_BIT;
else
tp->config_word0 &= ~RX_OWN_BIT;
if(tp->receive_mask & PROMISCUOUS_MODE)
tp->config_word0 |= PROMISCUOUS_BIT;
else
tp->config_word0 &= ~PROMISCUOUS_BIT;
if(tp->receive_mask & ACCEPT_ERR_PACKETS)
tp->config_word0 |= SAVBAD_BIT;
else
tp->config_word0 &= ~SAVBAD_BIT;
if(tp->receive_mask & ACCEPT_ATT_MAC_FRAMES)
tp->config_word0 |= RXATMAC;
else
tp->config_word0 &= ~RXATMAC;
if(tp->receive_mask & ACCEPT_MULTI_PROM)
tp->config_word1 |= MULTICAST_ADDRESS_BIT;
else
tp->config_word1 &= ~MULTICAST_ADDRESS_BIT;
if(tp->receive_mask & ACCEPT_SOURCE_ROUTING_SPANNING)
tp->config_word1 |= SOURCE_ROUTING_SPANNING_BITS;
else
{
if(tp->receive_mask & ACCEPT_SOURCE_ROUTING)
tp->config_word1 |= SOURCE_ROUTING_EXPLORER_BIT;
else
tp->config_word1 &= ~SOURCE_ROUTING_SPANNING_BITS;
}
if((err = smctr_issue_write_word_cmd(dev, RW_CONFIG_REGISTER_0,
&tp->config_word0)))
{
return (err);
}
if((err = smctr_issue_write_word_cmd(dev, RW_CONFIG_REGISTER_1,
&tp->config_word1)))
{
return (err);
}
smctr_disable_16bit(dev);
return (0);
}
static int smctr_clear_int(struct net_device *dev)
{
struct net_local *tp = netdev_priv(dev);
outb((tp->trc_mask | CSR_CLRTINT), dev->base_addr + CSR);
return (0);
}
static int smctr_clear_trc_reset(int ioaddr)
{
__u8 r;
r = inb(ioaddr + MSR);
outb(~MSR_RST & r, ioaddr + MSR);
return (0);
}
/*
* The inverse routine to smctr_open().
*/
static int smctr_close(struct net_device *dev)
{
struct net_local *tp = netdev_priv(dev);
struct sk_buff *skb;
int err;
netif_stop_queue(dev);
tp->cleanup = 1;
/* Check to see if adapter is already in a closed state. */
if(tp->status != OPEN)
return (0);
smctr_enable_16bit(dev);
smctr_set_page(dev, (__u8 *)tp->ram_access);
if((err = smctr_issue_remove_cmd(dev)))
{
smctr_disable_16bit(dev);
return (err);
}
for(;;)
{
skb = skb_dequeue(&tp->SendSkbQueue);
if(skb == NULL)
break;
tp->QueueSkb++;
dev_kfree_skb(skb);
}
return (0);
}
static int smctr_decode_firmware(struct net_device *dev)
{
struct net_local *tp = netdev_priv(dev);
short bit = 0x80, shift = 12;
DECODE_TREE_NODE *tree;
short branch, tsize;
__u16 buff = 0;
long weight;
__u8 *ucode;
__u16 *mem;
if(smctr_debug > 10)
printk(KERN_DEBUG "%s: smctr_decode_firmware\n", dev->name);
weight = *(long *)(tp->ptr_ucode + WEIGHT_OFFSET);
tsize = *(__u8 *)(tp->ptr_ucode + TREE_SIZE_OFFSET);
tree = (DECODE_TREE_NODE *)(tp->ptr_ucode + TREE_OFFSET);
ucode = (__u8 *)(tp->ptr_ucode + TREE_OFFSET
+ (tsize * sizeof(DECODE_TREE_NODE)));
mem = (__u16 *)(tp->ram_access);
while(weight)
{
branch = ROOT;
while((tree + branch)->tag != LEAF && weight)
{
branch = *ucode & bit ? (tree + branch)->llink
: (tree + branch)->rlink;
bit >>= 1;
weight--;
if(bit == 0)
{
bit = 0x80;
ucode++;
}
}
buff |= (tree + branch)->info << shift;
shift -= 4;
if(shift < 0)
{
*(mem++) = SWAP_BYTES(buff);
buff = 0;
shift = 12;
}
}
/* The following assumes the Control Store Memory has
* been initialized to zero. If the last partial word
* is zero, it will not be written.
*/
if(buff)
*(mem++) = SWAP_BYTES(buff);
return (0);
}
static int smctr_disable_16bit(struct net_device *dev)
{
return (0);
}
/*
* On Exit, Adapter is:
* 1. TRC is in a reset state and un-initialized.
* 2. Adapter memory is enabled.
* 3. Control Store memory is out of context (-WCSS is 1).
*/
static int smctr_disable_adapter_ctrl_store(struct net_device *dev)
{
struct net_local *tp = netdev_priv(dev);
int ioaddr = dev->base_addr;
if(smctr_debug > 10)
printk(KERN_DEBUG "%s: smctr_disable_adapter_ctrl_store\n", dev->name);
tp->trc_mask |= CSR_WCSS;
outb(tp->trc_mask, ioaddr + CSR);
return (0);
}
static int smctr_disable_bic_int(struct net_device *dev)
{
struct net_local *tp = netdev_priv(dev);
int ioaddr = dev->base_addr;
tp->trc_mask = CSR_MSK_ALL | CSR_MSKCBUSY
| CSR_MSKTINT | CSR_WCSS;
outb(tp->trc_mask, ioaddr + CSR);
return (0);
}
static int smctr_enable_16bit(struct net_device *dev)
{
struct net_local *tp = netdev_priv(dev);
__u8 r;
if(tp->adapter_bus == BUS_ISA16_TYPE)
{
r = inb(dev->base_addr + LAAR);
outb((r | LAAR_MEM16ENB), dev->base_addr + LAAR);
}
return (0);
}
/*
* To enable the adapter control store memory:
* 1. Adapter must be in a RESET state.
* 2. Adapter memory must be enabled.
* 3. Control Store Memory is in context (-WCSS is 0).
*/
static int smctr_enable_adapter_ctrl_store(struct net_device *dev)
{
struct net_local *tp = netdev_priv(dev);
int ioaddr = dev->base_addr;
if(smctr_debug > 10)
printk(KERN_DEBUG "%s: smctr_enable_adapter_ctrl_store\n", dev->name);
smctr_set_trc_reset(ioaddr);
smctr_enable_adapter_ram(dev);
tp->trc_mask &= ~CSR_WCSS;
outb(tp->trc_mask, ioaddr + CSR);
return (0);
}
static int smctr_enable_adapter_ram(struct net_device *dev)
{
int ioaddr = dev->base_addr;
__u8 r;
if(smctr_debug > 10)
printk(KERN_DEBUG "%s: smctr_enable_adapter_ram\n", dev->name);
r = inb(ioaddr + MSR);
outb(MSR_MEMB | r, ioaddr + MSR);
return (0);
}
static int smctr_enable_bic_int(struct net_device *dev)
{
struct net_local *tp = netdev_priv(dev);
int ioaddr = dev->base_addr;
__u8 r;
switch(tp->bic_type)
{
case (BIC_584_CHIP):
tp->trc_mask = CSR_MSKCBUSY | CSR_WCSS;
outb(tp->trc_mask, ioaddr + CSR);
r = inb(ioaddr + IRR);
outb(r | IRR_IEN, ioaddr + IRR);
break;
case (BIC_594_CHIP):
tp->trc_mask = CSR_MSKCBUSY | CSR_WCSS;
outb(tp->trc_mask, ioaddr + CSR);
r = inb(ioaddr + IMCCR);
outb(r | IMCCR_EIL, ioaddr + IMCCR);
break;
}
return (0);
}
static int __init smctr_chk_isa(struct net_device *dev)
{
struct net_local *tp = netdev_priv(dev);
int ioaddr = dev->base_addr;
__u8 r1, r2, b, chksum = 0;
__u16 r;
int i;
int err = -ENODEV;
if(smctr_debug > 10)
printk(KERN_DEBUG "%s: smctr_chk_isa %#4x\n", dev->name, ioaddr);
if((ioaddr & 0x1F) != 0)
goto out;
/* Grab the region so that no one else tries to probe our ioports. */
if (!request_region(ioaddr, SMCTR_IO_EXTENT, smctr_name)) {
err = -EBUSY;
goto out;
}
/* Checksum SMC node address */
for(i = 0; i < 8; i++)
{
b = inb(ioaddr + LAR0 + i);
chksum += b;
}
if (chksum != NODE_ADDR_CKSUM)
goto out2;
b = inb(ioaddr + BDID);
if(b != BRD_ID_8115T)
{
printk(KERN_ERR "%s: The adapter found is not supported\n", dev->name);
goto out2;
}
/* Check for 8115T Board ID */
r2 = 0;
for(r = 0; r < 8; r++)
{
r1 = inb(ioaddr + 0x8 + r);
r2 += r1;
}
/* value of RegF adds up the sum to 0xFF */
if((r2 != 0xFF) && (r2 != 0xEE))
goto out2;
/* Get adapter ID */
tp->board_id = smctr_get_boardid(dev, 0);
switch(tp->board_id & 0xffff)
{
case WD8115TA:
smctr_model = "8115T/A";
break;
case WD8115T:
if(tp->extra_info & CHIP_REV_MASK)
smctr_model = "8115T rev XE";
else
smctr_model = "8115T rev XD";
break;
default:
smctr_model = "Unknown";
break;
}
/* Store BIC type. */
tp->bic_type = BIC_584_CHIP;
tp->nic_type = NIC_825_CHIP;