summaryrefslogblamecommitdiffstats
path: root/private/ntos/ndis/madge/driver/drv_init.c
blob: 28539f67c98e6cd93f6e4b0b41adf218d5e1e6d9 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656























































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































                                                                                  
/****************************************************************************
*
* DRV_INIT.C : Part of the FASTMAC TOOL-KIT (FTK)
*
* THE DRIVER MODULE (INITIALIZE / REMOVE)
*
* Copyright (c) Madge Networks Ltd. 1991-1994
*
* COMPANY CONFIDENTIAL
*
*****************************************************************************
*
* The  driver  module  provides  a  simple  interface  to allow the use of
* Fastmac in as general a setting as possible. It handles the  downloading
* of  the  Fastmac  code  and  the initialization of the adapter card.  It
* provides simple transmit  and  receive  routines.   It  is  desgined  to
* quickly  allow  the  implementation  of  Fastmac applications. It is not
* designed as the fastest or most memory efficient solution.
*
* The DRV_INIT.C module contains  the  routines  necessary  to  initialize
* Fastmac  and  the  adapter  and  remove,  ie.   terminate  usage of, the
* adapter.  Upon adapter initialization the  user  is  returned  a  handle
* which  is  used  to  identify  the adapter in all future accesses to the
* driver module.
*
****************************************************************************/

/*---------------------------------------------------------------------------
|
| DEFINITIONS
|
---------------------------------------------------------------------------*/

#include "ftk_defs.h"

/*---------------------------------------------------------------------------
|
| MODULE ENTRY POINTS
|
---------------------------------------------------------------------------*/

#include "ftk_intr.h"   /* routines internal to FTK */
#include "ftk_extr.h"   /* routines provided or used by external FTK user */

/*---------------------------------------------------------------------------
|
| LOCAL FUNCTIONS
|
---------------------------------------------------------------------------*/

local WBOOLEAN  
driver_wait_for_adapter_open(
    UINT    * open_status,
    ADAPTER * adapter
    );

local WORD
driver_get_max_frame_size(
    ADAPTER            * adapter,
    FASTMAC_INIT_PARMS * fastmac_parms
    );

/*---------------------------------------------------------------------------
|
| GLOBAL VARIABLES
|
---------------------------------------------------------------------------*/

export ADAPTER * adapter_record[MAX_NUMBER_OF_ADAPTERS]  = {NULL};

#ifndef FTK_NO_PROBE
/****************************************************************************
*
*                        driver_probe_card
*                        =================
*
*
* PARAMETERS :
* ============
*
* WORD    adapter_card_bus_type
*
* The bus type (card family) the adapters for which to search. e.g.
* ADAPTER_CARD_ATULA_BUS_TYPE or ADAPTER_CARD_EISA_BUS_TYPE.
*
* PROBE * resources
*
* resources is an array structures used to identify and record specific 
* information about adapters found.
*
* UINT    length
*
* length is the number of structures pointed to by reources.
*
* WORD *  valid_locations
*
* valid_locations is an array of IO locations to examine for the presence
* of an adapter. For ATULA based adapters with should be a subset of
* {0x0a20, 0x1a20, 0x2a20, 0x3a20}.
*
* UINT    number_locations
*
* This is the number of IO locations in the above list.
*
* BODY :
* ======
* 
* The  hwi_atula_probe_card  routine is  called by  hwi_probe_adapter.  It
* probes the  adapter card for information such as DMA channel, IRQ number
* etc. This information can then be supplied by the user when starting the
* adapter.
*
*
* RETURNS :
* =========
* 
* The routine  returns the  number of adapters found, or PROBE_FAILURE 
* if there's a problem.
*
****************************************************************************/

#ifdef FTK_INIT_FUNCTION
#pragma FTK_INIT_FUNCTION(driver_probe_adapter)
#endif

export UINT  
driver_probe_adapter(
    WORD    adapter_card_bus_type,
    PROBE * resources,
    UINT    length,
    WORD  * valid_locations,
    UINT    number_locations
    )
{
    return hwi_probe_adapter(
               adapter_card_bus_type,
               resources,
               length,
               valid_locations,
               number_locations
               );
}


/****************************************************************************
*
*                       driver_deprobe_adapter
*                       ======================
*
* PARAMETERS :
* ============
*
* PROBE * resources
*
* resources is an array structures used to identify and record specific 
* information about adapters found.
*
* UINT    length
*
* length is the number of structures pointed to by reources.
*
* BODY :
* ======
*
* This function frees any resources that were claimed by a call to 
* driver_probe_adapter. Every valid PROBE structure returned by 
* driver_probe_adapter MUST be passed to driver_deprobe adapter otherwise
* resources that were claimed from the operating system by
* driver_probe_adapter (such as PCMCIA sockets) will not be freed.
*
* RETURNS :
* =========
*
* TRUE if everything worked or FALSE if it did not. 
*
****************************************************************************/

#ifdef FTK_RES_FUNCTION
#pragma FTK_RES_FUNCTION(driver_deprobe_adapter)
#endif

export WBOOLEAN 
driver_deprobe_adapter(
    PROBE * resources,
    UINT    length
    )
{
    return hwi_deprobe_adapter(
               resources,
               length
               );
}

#endif

/****************************************************************************
*
*                      driver_prepare_adapter
*                      ======================
*
*
* PARAMETERS :
* ============
*
* PREPARE_ARGS   * arguments
*
* This is a pointer to the arguments structure set up by the user code.
*
* ADAPTER_HANDLE * returned_adapter_handle
*
* An  adapter  handle is returned that is used for all subsequent calls to
* the driver to identify the particular adapter.
* 
* BODY :
* ======
*
* The driver_prepare_adapter routine firstly sets up the adapter structure
* for this adapter.  Then  it  gets  memory  for  the  status  information
* structure  that is filled in by driver_get_status calls. It then 
* requests memory for the Fastmac transmit and receive buffers. This memory 
* must be static, it must not be swapped out to disk because of DMA issues.
*
* This routine should be called once for every adapter  that  is  to  have
* Fastmac used on it.
* 
* RETURNS :
* =========
*
* The routine returns TRUE if it succeeds.  If this routine fails (returns
* FALSE)  then a subsequent call to driver_explain_error with the returned
* adapter handle will give an explanation.
* 
****************************************************************************/

#ifdef FTK_INIT_FUNCTION
#pragma FTK_INIT_FUNCTION(driver_prepare_adapter)
#endif

export WBOOLEAN  
driver_prepare_adapter(
    PREPARE_ARGS   * arguments,
    ADAPTER_HANDLE * returned_adapter_handle
    )
{
    ADAPTER_HANDLE       adapter_handle;
    ADAPTER            * adapter;
    FASTMAC_INIT_PARMS * fastmac_parms;
    WORD                 i;

    /*
     * Set up adapter handle which is an index to an array of pointers.
     * Find first a pointer not yet used.
     */

    for (i = 0; i < MAX_NUMBER_OF_ADAPTERS; i++)
    {
        if (adapter_record[i] == NULL)
        {
            break;
        }
    }

    /*
     * Set up returned adapter handle ( = index to adapter structure).
     * returned_adapter_handle is set up here before any failure.
     * This is so can use adapter handle for call to driver_explain_error.
     */

    adapter_handle           = (ADAPTER_HANDLE) i;
    *returned_adapter_handle = adapter_handle;

    /*
     * If all pointers to adapter structures are used then return error.
     * Can not set up error record but see driver_explain_error.
     */

    if (i == MAX_NUMBER_OF_ADAPTERS)
    {
        return FALSE;
    }

    /*
     * Get memory for adapter structure.
     */

    adapter_record[adapter_handle] = (ADAPTER *)
        sys_alloc_adapter_structure(adapter_handle, sizeof(ADAPTER));

    /*
     * Check that the memory allocation was successful. Can not set up 
     * error record but see driver_explain_error.
     */

    if (adapter_record[adapter_handle] == NULL)
    {
        return FALSE;
    }

    /*
     * Remember pointer to adapter structure.
     */

    adapter = adapter_record[adapter_handle];

    /*
     * Zero adapter structure memory.
     */

    util_zero_memory((BYTE *) adapter, sizeof(ADAPTER));

    /*
     * Save handle, so that HWI routines that need it can find it.
     */

    adapter->adapter_handle = adapter_handle;

    /*
     * Save the user's private information for the users sys_ functions.
     */

    adapter->user_information = arguments->user_information;

#ifdef FMPLUS

    /*
     * Allocate memory for the FastMAC Plus to do its DMA tests.
     * This is now a byte longer to allocate the byte used
     * to handshake the DMA on a PCI(T) card with broken DMA.
     */  

    if (!sys_alloc_dma_phys_buffer(
             adapter_handle,
             SCB_TEST_PATTERN_LENGTH + SSB_TEST_PATTERN_LENGTH + 1,
             &(adapter->dma_test_buf_phys),
             &(adapter->dma_test_buf_virt)))
    {
        adapter->error_record.type  = ERROR_TYPE_DRIVER;
        adapter->error_record.value = DRIVER_E_12_FAIL_ALLOC_DMA_BUF;

        return FALSE;
    }

#endif

    /*
     * Indicate no errors have occured for this adapter yet.
     */

    adapter->error_record.type = ERROR_TYPE_NONE;

    /*
     * Get memory for status information structure.
     */

    adapter->status_info = (STATUS_INFORMATION *)
        sys_alloc_status_structure(adapter_handle,sizeof(STATUS_INFORMATION));

    /*
     * Check that the memory allocation was successful.
     */

    if (adapter->status_info == NULL)
    {
        adapter->error_record.type  = ERROR_TYPE_DRIVER;
        adapter->error_record.value = DRIVER_E_03_FAIL_ALLOC_STATUS;

        return FALSE;
    }

    /*
     * Zero status information structure memory.
     */

    util_zero_memory(
        (BYTE *) adapter->status_info, 
        sizeof(STATUS_INFORMATION)
        );

    /*
     * Get memory for initialization block.
     */

    adapter->init_block = (INITIALIZATION_BLOCK *)
        sys_alloc_init_block(adapter_handle, sizeof(INITIALIZATION_BLOCK));

    /*
     * Check that the memory allocation was successful.
     */

    if (adapter->init_block == NULL)
    {
        adapter->error_record.type  = ERROR_TYPE_DRIVER;
        adapter->error_record.value = DRIVER_E_04_FAIL_ALLOC_INIT;

        return FALSE;
    }

    /*
     * Zero initialization block memory.
     */

    util_zero_memory(
        (BYTE *) adapter->init_block,
        sizeof(INITIALIZATION_BLOCK)
        );

    /*
     * Get pointer to Fastmac init parameters for this adapter.
     */

    fastmac_parms = &adapter->init_block->fastmac_parms;

    /*
     * Ensure that the fastmac_parms->features reserved bits and the
     * fastmac_parms->int_flags reserved bits are zero (bits 4,11-15
     * of features, and bits 3-15 of int_flags).
     * (In fact they will be already from the above util_zero_memory.)
     */
    
    /*
     * Now fill in all of the hardware independant non-zero fields in the 
     * Fastmac part of init block.
     */

    /*
     * Check that the frame size requested in within the bounds
     * of possibility.
     */

    if (arguments->max_frame_size < MIN_FRAME_SIZE ||
        arguments->max_frame_size > MAX_FRAME_SIZE_16_MBITS)
    {
        adapter->error_record.type  = ERROR_TYPE_DRIVER;
        adapter->error_record.value = DRIVER_E_13_BAD_FRAME_SIZE;

        return FALSE;
    }
        
    /*
     * Make a note of the maximum frame size requested.
     */

    fastmac_parms->max_frame_size = arguments->max_frame_size;


#ifndef FMPLUS

    /*
     * Set up the header.
     */

    fastmac_parms->header.length    = sizeof(FASTMAC_INIT_PARMS);
    fastmac_parms->header.signature = FASTMAC_INIT_HEADER_SIGNATURE;
    fastmac_parms->header.version   = FASTMAC_INIT_HEADER_VERSION;

    /*
     * Now set up the interrupt options.
     */

#ifdef FTK_TX_WITH_COMPLETION
    fastmac_parms->int_flags |= INT_FLAG_TX_BUF_EMPTY;
#endif

    /*
     * Check have sensible value for Fastmac receive buffer size.
     */

    if ((arguments->receive_buffer_byte_size < FASTMAC_MINIMUM_BUFFER_SIZE) ||
        (arguments->receive_buffer_byte_size > FASTMAC_MAXIMUM_BUFFER_SIZE))
    {
        adapter->error_record.type  = ERROR_TYPE_DRIVER;
        adapter->error_record.value = DRIVER_E_0A_RX_BUF_BAD_SIZE;

        return FALSE;
    }

    /*
     * Get memory for the receive buffer.
     */

    if (!sys_alloc_dma_phys_buffer(
             adapter_handle,
             arguments->receive_buffer_byte_size,
             &adapter->rx_buffer_phys,
             &adapter->rx_buffer_virt))
    {
        adapter->error_record.type  = ERROR_TYPE_DRIVER;
        adapter->error_record.value = DRIVER_E_05_FAIL_ALLOC_RX_BUF;

        return FALSE;
    }

    fastmac_parms->rx_buf_physaddr = adapter->rx_buffer_phys;

    /*
     * Check that Fastmac receive buffer begins on a DWORD boundary.
     */

    if ((fastmac_parms->rx_buf_physaddr & 0x00000003) != 0L)
    {
        adapter->error_record.type  = ERROR_TYPE_DRIVER;
        adapter->error_record.value = DRIVER_E_0B_RX_BUF_NOT_DWORD;

        return FALSE;
    }

    /*
     * Fill in Fastmac receive buffer size.
     */

    fastmac_parms->rx_buf_size = arguments->receive_buffer_byte_size;

    /*
     * Check have sensible value for Fastmac transmit buffer size.
     */

    if ((arguments->transmit_buffer_byte_size < FASTMAC_MINIMUM_BUFFER_SIZE) ||
        (arguments->transmit_buffer_byte_size > FASTMAC_MAXIMUM_BUFFER_SIZE))
    {
        adapter->error_record.type  = ERROR_TYPE_DRIVER;
        adapter->error_record.value = DRIVER_E_0C_TX_BUF_BAD_SIZE;

        return FALSE;
    }

    /*
     * Get memory for the transmit buffer.
     */

    if (!sys_alloc_dma_phys_buffer(
             adapter_handle,
             arguments->receive_buffer_byte_size,
             &adapter->tx_buffer_phys,
             &adapter->tx_buffer_virt))
    {
        adapter->error_record.type  = ERROR_TYPE_DRIVER;
        adapter->error_record.value = DRIVER_E_06_FAIL_ALLOC_TX_BUF;

        return FALSE;
    }

    fastmac_parms->tx_buf_physaddr = adapter->tx_buffer_phys;

    /*
     * Check that Fastmac transmit buffer begins on a DWORD boundary.
     */

    if ((fastmac_parms->tx_buf_physaddr & 0x00000003) != 0L)
    {
        adapter->error_record.type  = ERROR_TYPE_DRIVER;
        adapter->error_record.value = DRIVER_E_0D_TX_BUF_NOT_DWORD;

        return FALSE;
    }

    /*
     * Fill in Fastmac transmit buffer size.
     */

    fastmac_parms->tx_buf_size = arguments->transmit_buffer_byte_size;

    /*
     * Mark adapter structure as containing details of initialized Fastmac
     * and indicate that SRB is free.
     */

    adapter->adapter_status = ADAPTER_PREPARED_FOR_START;
    adapter->srb_status     = SRB_FREE;

#else

    /*
     * Set set up the header.
     */

    fastmac_parms->header.length    = sizeof(FASTMAC_INIT_PARMS);
    fastmac_parms->header.signature = FMPLUS_INIT_HEADER_SIGNATURE;
    fastmac_parms->header.version   = FMPLUS_INIT_HEADER_VERSION;

    /*
     * Now set up the interrupt options.
     */

#ifdef FTK_RX_OUT_OF_INTERRUPTS
    fastmac_parms->int_flags |= INT_FLAG_RX;
#endif

#ifdef FTK_RX_BY_SCHEDULED_PROCESS
    fastmac_parms->int_flags |= INT_FLAG_RX;
#endif

#ifdef FTK_TX_WITH_COMPLETION
    fastmac_parms->int_flags |= INT_FLAG_LARGE_DMA;
#endif

    /*
     * Now fill in the number of slots that are required. These are user
     * specified, since the numbers are host dependent (each slot must have
     * a maximum frame sized buffer on the host).
     */

    if (arguments->number_of_rx_slots < FMPLUS_MIN_RX_SLOTS ||
        arguments->number_of_rx_slots > FMPLUS_MAX_RX_SLOTS)
    {
        adapter->error_record.type  = ERROR_TYPE_DRIVER;
        adapter->error_record.value = DRIVER_E_10_BAD_RX_SLOT_NUMBER;

        return FALSE;
    }

    fastmac_parms->rx_slots = arguments->number_of_rx_slots;

    if (arguments->number_of_tx_slots < FMPLUS_MIN_TX_SLOTS ||
        arguments->number_of_tx_slots > FMPLUS_MAX_TX_SLOTS)
    {
        adapter->error_record.type  = ERROR_TYPE_DRIVER;
        adapter->error_record.value = DRIVER_E_11_BAD_TX_SLOT_NUMBER;

        return FALSE;
    }

    fastmac_parms->tx_slots = arguments->number_of_tx_slots;

    /*
     * Allocate the receive slot buffers.
     */

    if (!rxtx_allocate_rx_buffers(
             adapter, 
             arguments->max_frame_size,
             arguments->number_of_rx_slots
             ))
    {
        adapter->error_record.type  = ERROR_TYPE_DRIVER;
        adapter->error_record.value = DRIVER_E_05_FAIL_ALLOC_RX_BUF;

	return FALSE;
    }

    /*
     * Allocate the transmit slot buffers.
     */

    if (!rxtx_allocate_tx_buffers(
             adapter, 
             arguments->max_frame_size,
             arguments->number_of_tx_slots
             ))
    {
        adapter->error_record.type  = ERROR_TYPE_DRIVER;
        adapter->error_record.value = DRIVER_E_06_FAIL_ALLOC_TX_BUF;

	return FALSE;
    }

    /*
     * Mark adapter structure as containing details of initialized Fastmac
     * and indicate that SRB is free.
     */

    adapter->adapter_status = ADAPTER_PREPARED_FOR_START;
    adapter->srb_status     = SRB_FREE;

#endif

    /*
     * Complete successfully.
     */

    return TRUE;
}

/****************************************************************************
*
*                      driver_start_adapter
*                      ====================
*
* PARAMETERS :
* ============
*
* ADAPTER_HANDLE   adapter_handle
* 
* This handle identifies the adapter to be initialized. This should  be  a
* handle returned by a call to driver_prepare_adapter.
*
* START_ARGS     * arguments
*
* This is a pointer to the arguments structure set up by the user code.
*
* NODE_ADDRESS   * returned_permanent_address
*
* The node address pointed to is always filled in with the BIA  PROM  node
* address  of the adapter.  This is so the user of the FTK can fill in MAC
* headers etc. with the source node address (unless the user has  supplied
* an  opening address to driver_prepare_adapter which they should then use
* instead).
*
*
* BODY :
* ====== 
*
* The driver_start_adapter routine is called once per adapter after a call
* to   driver_prepare_adapter.    It   takes  the  user  supplied  adapter
* information and passes it in a form usable by the HWI so  that  the  HWI
* can  install  and  then  initialize  the  adapter  (that  is  initialize
* registers on the card, download the Fastmac image and set up the IRQ and
* DMA channels if necessary). After initialization, this routine waits for
* the adapter to open if the auto-open option is enabled.
*
* RETURNS :
* =========
* 
* The routine returns TRUE if it succeeds.  If this routine fails (returns
* FALSE) then a subsequent call  to  driver_explain_error  with  the  same
* adapter handle will give an explanation.
*
****************************************************************************/

#ifdef FTK_INIT_FUNCTION
#pragma FTK_INIT_FUNCTION(driver_start_adapter)
#endif

export WBOOLEAN 
driver_start_adapter(
    ADAPTER_HANDLE   adapter_handle,
    START_ARGS     * arguments,
    NODE_ADDRESS   * returned_permanent_address
    )
{
    ADAPTER            * adapter;
    FASTMAC_INIT_PARMS * fastmac_parms;
    WBOOLEAN             init_success;
    WORD                 max_frame_size;
    UINT                 i;
#ifdef FMPLUS
    RX_SLOT *            next_rx_slot;
    TX_SLOT *            next_tx_slot;
    RX_SLOT * *          rx_slot_array;
    TX_SLOT * *          tx_slot_array;
    UINT                 slot_index;
#endif

    /*
     * Check adapter handle and status of adapter for validity.
     * If routine fails return failure (error record already filled in).
     */

    if (!driver_check_adapter( 
             adapter_handle,
             ADAPTER_PREPARED_FOR_START,
             SRB_ANY_STATE
             ))
    {
        return FALSE;
    }

    /*
     * Get pointer to adapter structure.
     */

    adapter = adapter_record[adapter_handle];

    /*
     * Fill user supplied info into adapter structure.
     */

    adapter->mmio_base_address     = arguments->mmio_base_address;
    adapter->adapter_card_bus_type = arguments->adapter_card_bus_type;
    adapter->io_location           = arguments->io_location;
    adapter->dma_channel           = arguments->dma_channel;
    adapter->transfer_mode         = arguments->transfer_mode;
    adapter->interrupt_number      = arguments->interrupt_number;
    adapter->set_dma               = arguments->set_dma_channel;
    adapter->set_irq               = arguments->set_interrupt_number;
    adapter->set_ring_speed        = arguments->set_ring_speed;
    adapter->download_image        = arguments->code;
    adapter->pci_handle            = arguments->pci_handle;


#ifdef FMPLUS    

    /*
     * Need these values later.
     */

    rx_slot_array = adapter->rx_slot_array;
    tx_slot_array = adapter->tx_slot_array;

#endif

    /*
     * Call the HWI routine to install the adapter. This also downloads 
     * the Fastmac image to the adapter. If routine fails return failure 
     * (error record already filled in). DMA and IRQ are only enabled 
     * if hwi_install_adapter succeeds.
     */

    /*
     * WARNING: we must mark the adapter as running NOW, before downloading
     *          the microcode, because on AT cards in PIO mode ONLY,  bring
     *          up diagnostics on the card fail when carrying out DMA tests.
     *          This occurs because the interrupt handling routine ignores
     *          all interrupts from the card until it is marked as running,
     *          but this unfortunately masks off PIO interrupts too.
     */

    /*
     * Mark adapter structure that adapter is now going to be running.
     * Hence hwi_interrupt_entry will check adapter for interrupts
     */

    adapter->adapter_status = ADAPTER_RUNNING;

    if (!hwi_install_adapter(adapter, adapter->download_image))
    {
        /*
	      * Now that initial installation has failed, we can turn off the
	      * above indication that the card is running.
         */

         adapter->adapter_status = ADAPTER_PREPARED_FOR_START;

         return FALSE;
    }

    /*
     * Get pointer to Fastmac init parameters for this adapter.
     */

    fastmac_parms = &adapter->init_block->fastmac_parms;

    /*
     * Now fill in max frame size in init block that Fastmac should support.
     * This is based on the size of the Fastmac buffers and
     * max frame size supported by adapter because of ring speed. We
     * put the requested max frame is into fastmac_parms->max_frame_size
     * in driver_prepare_adapter.
     */

    max_frame_size = driver_get_max_frame_size(adapter, fastmac_parms);

    fastmac_parms->max_frame_size = 
        min(max_frame_size, fastmac_parms->max_frame_size);

    /*
     * Write the actual max frame size back up to the caller, so they know
     * what it is too.
     */

    arguments->max_frame_size = fastmac_parms->max_frame_size;


#ifdef FMPLUS

    /*
     * Set up the user selected RX/TX buffer size. This will be changed
     * in hwi_gen.c if the value given is not sensible.
     */

    adapter->init_block->smart_parms.rx_tx_buffer_size = 
        arguments->rx_tx_buffer_size;

#endif

    /*
     * If auto open option is on then put necessary info into init block.
     */

    if (arguments->auto_open_option)
    {
#ifndef FMPLUS

        /*
         * Use delay_rx to prevent race condition occuring whereby 
         * on auto-open an interrupt could occur before the  host  
         * code  has had a chance to read the location of the status 
         * block on the card. The other half of the code to fix this 
         * problem is in driver_start_adapter, where the ARB is freed.
         */

        fastmac_parms->feature_flags =
            FEATURE_FLAG_AUTO_OPEN | FEATURE_FLAG_DELAY_RX;

#else

        fastmac_parms->feature_flags = FEATURE_FLAG_AUTO_OPEN;

#endif

        fastmac_parms->open_options = arguments->open_options;

        /*
         * Check if auto-opening node address is set (ie. not all zeroes).
         */

        for (i = 0; i < sizeof(NODE_ADDRESS); i++)
        {
            if (arguments->opening_node_address.byte[i] != 0)
            {
                break;
            }
        }

        /*
         * If opening node address not set up use BIA PROM address.
         */

        if (i == sizeof(NODE_ADDRESS))
        {
            fastmac_parms->open_address = adapter->permanent_address;
        }
        else
        {
            fastmac_parms->open_address = arguments->opening_node_address;
        }

        fastmac_parms->group_address      = arguments->opening_group_address;
        fastmac_parms->functional_address = arguments->opening_functional_address;
    }

    /*
     * Call the HWI routine to initialize the adapter. This downloads the 
     * init block to the adapter. Leaves EAGLE_SIFADRX=0x0001 so driver 
     * never use extended SIF regs. If routine fails return failure 
     * (error record already filled in).
     */

    if (!hwi_initialize_adapter(adapter, adapter->init_block))
    {
         return FALSE;
    }

    /*
     * At this stage the actual adapter card type is known.
     * Get the IO location of the first SIF register for the adapter.
     * Inform the system about the IO ports we are going to access.
     */

#ifndef FTK_NO_IO_ENABLE
    macro_enable_io(adapter);
#endif

    /*
     * Get the DIO addresses of the Fastmac SSB and STB (ststus block).
     * Only use non-extended SIF regs (EAGLE_SIFADR and EAGLE_SIFDAT_INC).
     * Hence can use same code for all adapter card types.
     */

    sys_outsw(adapter_handle, adapter->sif_adr, DIO_LOCATION_SRB_POINTER);

    adapter->srb_dio_addr = (SRB_HEADER *) (card_t) 
        sys_insw(adapter_handle, adapter->sif_datinc);

    sys_outsw(adapter_handle, adapter->sif_adr, DIO_LOCATION_STB_POINTER);

    adapter->stb_dio_addr = (FASTMAC_STATUS_BLOCK *) (card_t)
        sys_insw(adapter_handle, adapter->sif_datinc);

#ifndef FMPLUS

    /*
     * In the case of auto-open :
     * Free the ARB to enable data to be received from here on... This only
     * occurs now because it is only now that we know where to look for the
     * pointers in the status block that will tell us whether data has come
     * in or not.
     */

    if (arguments->auto_open_option)
    {
        sys_outsw(adapter_handle, adapter->sif_int, EAGLE_ARB_FREE_CODE);
    }

#else

    /*
     * Now recover the receive slot and transmit slot chains.
     */

    /*
     * Start with the receive slot chain. We must poll the location in the
     * status block that holds the start address until it is non-zero.  It
     * is then safe to run down the chain finding the other slots.
     */

    sys_outsw(
        adapter_handle, 
        adapter->sif_adr,
        (WORD) (card_t) &adapter->stb_dio_addr->rx_slot_start
        );

    /*
     * Poll this address until it is non-zero.
     */

    do
    {
        rx_slot_array[0] = (RX_SLOT *) (card_t) 
            sys_insw(adapter_handle, adapter->sif_dat);
    }
    while (rx_slot_array[0] == 0);

    /*
     * Recover all the other slots by running down the chain.
     */

    slot_index = 0;

    do
    {
        sys_outsw(
            adapter_handle, 
            adapter->sif_adr,
            (WORD) (card_t) &rx_slot_array[slot_index]->next_slot
            );

        next_rx_slot = (RX_SLOT *) (card_t) 
            sys_insw(adapter_handle, adapter->sif_dat);

        if (next_rx_slot != rx_slot_array[0])
        {
            rx_slot_array[++slot_index] = next_rx_slot;
        }
    }
    while (next_rx_slot != rx_slot_array[0]);

    /*
     * Now do the same for the transmit slots.
     */

    sys_outsw(
        adapter_handle, 
        adapter->sif_adr,
        (WORD) (card_t) &adapter->stb_dio_addr->tx_slot_start
        );

    /*
     * Poll this address until it is non-zero.
     */

    do
    {
        tx_slot_array[0] = (TX_SLOT *) (card_t)
            sys_insw(adapter_handle, adapter->sif_dat);
    }
    while (tx_slot_array[0] == 0);

    /*
     * Now recover all the other slots by running down the chain.
     */

    slot_index = 0;

    do
    {
        sys_outsw(
            adapter_handle, 
            adapter->sif_adr,
            (WORD) (card_t) &tx_slot_array[slot_index]->next_slot
            );

        next_tx_slot = (TX_SLOT *) (card_t)
            sys_insw(adapter_handle, adapter->sif_dat);

        if (next_tx_slot != tx_slot_array[0])
        {
            tx_slot_array[++slot_index] = next_tx_slot;
        }
    }
    while (next_tx_slot != tx_slot_array[0]);

    /*
     * Now that we have the slot locations on the card, we can associate
     * buffers with each of them. The user needs to supply a routine that
     * set up the slots from the host buffers previously allocated as
     * we don't enforce an organisation on the allocation of multiple
     * slot buffers. We tell the user routine if it should program the
     * adapter slots with physical addresses (for DMA) or virtual
     * addresses (for PIO or MMIO).
     */


    rxtx_setup_rx_buffers(
        adapter, 
        (WBOOLEAN) (adapter->transfer_mode == DMA_DATA_TRANSFER_MODE),
        fastmac_parms->rx_slots
        );


    rxtx_setup_tx_buffers(
        adapter, 
        (WBOOLEAN) (adapter->transfer_mode == DMA_DATA_TRANSFER_MODE),
        fastmac_parms->tx_slots
        );

#endif        

    /*
     * Let the system know we have finished accessing the IO ports.
     */

#ifndef FTK_NO_IO_ENABLE
    macro_disable_io( adapter);
#endif

    /*
     * Check that Fastmac has correctly installed. Do this by reading 
     * node address from Fastmac status block. If routine fails return 
     * failure (error record already filled in). Note for EISA cards, 
     * this is actually first time get node address.
     */

    if (!hwi_get_node_address_check(adapter))
    {
        return FALSE;
    }

    /*
     * Copy permanent BIA PROM node address into user supplied node address.
     */

    *returned_permanent_address = adapter->permanent_address;

    /*
     * If the auto open option is on then wait to see if adapter opens okay.
     * Enable and disable accessing IO locations around check.
     * If adapter open routine fails then error record already filled in.
     */

    if (arguments->auto_open_option)
    {
#ifndef FTK_NO_IO_ENABLE
        macro_enable_io( adapter);
#endif

        init_success = driver_wait_for_adapter_open(
                           &(arguments->open_status), 
                           adapter
                           );

#ifndef FTK_NO_IO_ENABLE
        macro_disable_io( adapter);
#endif
    }
    else
    {
        init_success = TRUE;
    }

    /*
     * Initialization completed.
     */

    return init_success;
}

#ifdef FMPLUS

/****************************************************************************
*
*                      driver_start_receive_process
*                      ============================
*
* PARAMETERS :
* ============
*
* ADAPTER_HANDLE adapter_handle
*
* This handle identifies the adapter to be initialized. This should  be  a
* handle returned by a call to driver_prepare_adapter.
*
* BODY :
* ======
*
* The driver_start_adapter routine is called once per adapter after a call
* to driver_start_adapter.  It  uses the supplied handle to identify which
* adapter it should affect : by writing a zero into the Fastmac Plus init-
* ialization block on the adapter  (as specified in the manual),  the card
* will start to receive frames and pass them up to the host.
*
* NOTE: If SRBs are going to be used, this MUST be called first.
* 
* RETURNS :
* =========
*
* The routine returns TRUE if it succeeds.  If this routine fails (returns
* FALSE) then a subsequent call  to  driver_explain_error  with  the  same
* adapter handle will give an explanation.
*
****************************************************************************/

#ifdef FTK_INIT_FUNCTION
#pragma FTK_INIT_FUNCTION(driver_start_receive_process)
#endif

export WBOOLEAN 
driver_start_receive_process(
    ADAPTER_HANDLE adapter_handle
    )
{
    ADAPTER * adapter;

    /*
     * Adapter handle is invalid if greater than max number of adapters.
     * Can not set up error record but see driver_explain_error.
     */

    if (adapter_handle >= MAX_NUMBER_OF_ADAPTERS)
    {
        return FALSE;
    }

    /*
     * Adapter handle is invalid when no adapter structure for handle.
     * Can not set up error record but see driver_explain_error.
     */

    if (adapter_record[adapter_handle] == NULL)
    {
        return FALSE;
    }

    /*
     * Get pointer to adapter structure.
     */

    adapter = adapter_record[adapter_handle];

    /*
     * Inform the system about the IO ports we are going to access.
     */

#ifndef FTK_NO_IO_ENABLE
    macro_enable_io(adapter);
#endif

    /*
     * Let's fire off the receive process from here then...
     */

    sys_outsw(
        adapter_handle, 
        adapter->sif_adr,
        (WORD) (card_t) &adapter->stb_dio_addr->rx_slot_start
        );

    sys_outsw(adapter_handle, adapter->sif_dat, 0);

    /*
     * Let the system know we have finished accessing the IO ports.
     */

#ifndef FTK_NO_IO_ENABLE
    macro_disable_io(adapter);
#endif

    return TRUE;
}

#endif

/****************************************************************************
*
*                      driver_remove_adapter
*                      =====================
*
* PARAMETERS :
* ============
*
* ADAPTER_HANDLE adapter_handle
* 
* This handle identifies the adapter to be removed.
*
* BODY :
* ======
*
* The driver_remove_adapter routine is written  such  that,  whatever  the
* current state of the adapter, a call to driver_remove_adapter will place
* the  adapter in a state whereby driver_prepare_adapter must be called to
* start using the adapter once more.  Hence, on ANY fatal adapter error, a
* call to driver_remove adapter is needed before  installing  the  adapter
* again.
*
* The  routine  calls the HWI to reset the required adapter if the adapter
* has been running.  It also calls certain system  routines  in  order  to
* free the memory used by the Fastmac receive and transmit buffers as well
* as  that  used by the adapter structure. However, it only does this when
* the allocate calls were successful.
*
* RETURNS :
* =========
*
* The routine always succeeds. Even if the adapter handle is invalid  then
* the routine does not fail it just does nothing.
*
****************************************************************************/

#ifdef FTK_RES_FUNCTION
#pragma FTK_RES_FUNCTION(driver_remove_adapter)
#endif

export WBOOLEAN 
driver_remove_adapter(
    ADAPTER_HANDLE adapter_handle
    )
{
    ADAPTER *            adapter;
    FASTMAC_INIT_PARMS * fastmac_parms;

    /*
     * Adapter handle is invalid if greater than max number of adapters.
     * Can not set up error record but see driver_explain_error.
     */

    if (adapter_handle >= MAX_NUMBER_OF_ADAPTERS)
    {
        return FALSE;
    }

    /*
     * Adapter handle is invalid when no adapter structure for handle.
     * Can not set up error record but see driver_explain_error.
     */

    if (adapter_record[adapter_handle] == NULL)
    {
        return FALSE;
    }

    /*
     * Get pointer to adapter structure.
     */

    adapter = adapter_record[adapter_handle];

    /*
     * Call the HWI routine to kill the adapter (DMA channel, IRQ number).
     * Only call it if either DMA or interrupts are enabled at adapter.
     * Note in this case the actual adapter card type is known.
     */

    if (adapter->interrupts_on || adapter->dma_on)
    {
        hwi_remove_adapter(adapter);
    }

    /*
     * Free all memory that was allocated for handling use of this adapter.
     * Includes Fastmac buffers, init block and adapter structure.
     * Only free memory if allocate memory calls were successful.
     */

    if (adapter->init_block != NULL)
    {
        /*
         * Initialize variable used for freeing memory.
         */

        fastmac_parms = &adapter->init_block->fastmac_parms;

#ifndef FMPLUS

        /*
         * Free transmit buffer space if allocated.
         */

        if (adapter->tx_buffer_phys != NULL_PHYSADDR)
        {
            sys_free_dma_phys_buffer(
                adapter_handle,
                fastmac_parms->tx_buf_size,
                adapter->tx_buffer_phys,
                adapter->tx_buffer_virt
                );
        }

        /*
         * Free receive buffer space if allocated.
         */

        if (adapter->rx_buffer_phys != NULL_PHYSADDR)
        {
            sys_free_dma_phys_buffer(
                adapter_handle,
                fastmac_parms->rx_buf_size,
                adapter->rx_buffer_phys,
                adapter->rx_buffer_virt
                );
        }

#else

        /*
         * Free receive buffer space if allocated.
         */

        rxtx_free_rx_buffers(
            adapter, 
            fastmac_parms->max_frame_size,
            fastmac_parms->rx_slots
            );

        /*
         * Free transmit buffer space if allocated.
         */

         rxtx_free_tx_buffers(
            adapter, 
            fastmac_parms->max_frame_size,
            fastmac_parms->tx_slots
            );

#endif

        /*
         * Free the initialization block allocated memory.
         */

        sys_free_init_block(
            adapter_handle,
            (BYTE *) adapter->init_block,
            sizeof(INITIALIZATION_BLOCK)
            );
    }

    /*
     * Free status structure if allocated.
     */

    if (adapter->status_info != NULL)
    {
        sys_free_status_structure(
            adapter_handle,
            (BYTE *) adapter->status_info,
            sizeof(STATUS_INFORMATION)
            );
    }

#ifdef FMPLUS

    if (adapter->dma_test_buf_virt != 0)
    {
        sys_free_dma_phys_buffer( 
            adapter->adapter_handle,
            SCB_TEST_PATTERN_LENGTH + SSB_TEST_PATTERN_LENGTH + 1,
            adapter->dma_test_buf_phys,
            adapter->dma_test_buf_virt
            );
    }

#endif

    /*
     * Already know adapter allocate was successful hence always free it.
     */

    sys_free_adapter_structure(
        adapter_handle,
        (BYTE *) adapter,
        sizeof(ADAPTER)
        );

    /*
     * Clear entry in adapter pointers array.
     */

    adapter_record[adapter_handle] = NULL;

    /*
     * Complete successfully.
     */

    return TRUE;
}

/*---------------------------------------------------------------------------
|
|                      driver_wait_for_adapter_open
|                      ============================
|
| The driver_wait_for_adapter_open routine waits at least 40  seconds  for
| the  adapter  to  open.  It  discovers  whether  the  adapter has opened
| successfully or not by looking in the Fastmac status block (STB). If the
| adapter fails to open then this  routine  fills  in  the  adapter  error
| record.
|
---------------------------------------------------------------------------*/

#ifdef FTK_INIT_FUNCTION
#pragma FTK_INIT_FUNCTION(driver_wait_for_adapter_open)
#endif

local WBOOLEAN 
driver_wait_for_adapter_open(
    UINT    * open_status,
    ADAPTER * adapter
    )
{
    ADAPTER_HANDLE adapter_handle = adapter->adapter_handle;
    WBOOLEAN       open_okay;
    UINT           open_error;
    UINT           index;

    /*
     * Wait at least a total of 40 seconds for adapter to open.
     */

    for (index = 0; index < 160; index++)
    {
        /*
         * Set up DIO address to open status field in STB (status block).
         */

        sys_outsw(
            adapter_handle, 
            adapter->sif_adr,
            (WORD) (card_t) &adapter->stb_dio_addr->adapter_open
            );

        /*
         * Read open status field from DIO space. If successfully 
         * opened then complete successfully.
         */

        open_okay = (WBOOLEAN) sys_insw(
                                   adapter_handle,
	                           adapter->sif_datinc
                                   );

        if (open_okay)
        {
            *open_status = EAGLE_OPEN_ERROR_SUCCESS;
            return TRUE;
        }

        /*
         * If not opened, see if an error has occured to prevent opening.
         */

        open_error   = sys_insw(adapter_handle, adapter->sif_datinc);
        *open_status = open_error;

        if (open_error != EAGLE_OPEN_ERROR_SUCCESS)
        {
            adapter->error_record.type  = ERROR_TYPE_AUTO_OPEN;
            adapter->error_record.value = AUTO_OPEN_E_01_OPEN_ERROR;

            return FALSE;
        }

        /*
         * Opening procedure not completed. Wait at least 250 milliseconds 
         * before checkig again. Disable and re-enable accessing IO locations 
         * around wait so delay can reschedule this task and not effect others 
         * running.
         */

#ifndef FTK_NO_IO_ENABLE
        macro_disable_io( adapter);
#endif

        sys_wait_at_least_milliseconds(250);

#ifndef FTK_NO_IO_ENABLE
        macro_enable_io( adapter);
#endif

    }

    /*
     * At least 40 seconds have gone so return time out failure.
     */

    adapter->error_record.type = ERROR_TYPE_AUTO_OPEN;
    adapter->error_record.value = AUTO_OPEN_E_80_TIME_OUT;

    return FALSE;
}


/*---------------------------------------------------------------------------
|
|                      driver_get_max_frame_size
|                      =========================
|
| The driver_get_max_frame_size routine calculates the maximum sized frame
| that can be transmitted or received. This calculation is  based  on  the
| maximum  frame  size  determined  by  ring  speed alone, the size of the
| Fastmac buffers, and the fact that Fastmac pointers  have  to  be  DWORD
| aligned.
|
---------------------------------------------------------------------------*/

#ifdef FTK_INIT_FUNCTION
#pragma FTK_INIT_FUNCTION(driver_get_max_frame_size)
#endif

local WORD      
driver_get_max_frame_size(
    ADAPTER            * adapter,
    FASTMAC_INIT_PARMS * fastmac_parms
    )
{
#ifdef FMPLUS

    return adapter->max_frame_size;

#else

    WORD tx_max_frame_size;
    WORD rx_max_frame_size;
    WORD max_frame_size;

    /*
     * Calculate max transmit frame size from size of buffer, size of
     * header and knowing that one frame must leave space such that host
     * and adapter ptrs into buffer are not the same.
     */

    tx_max_frame_size = 
        fastmac_parms->tx_buf_size - macro_dword_align(
                                         FASTMAC_BUFFER_HEADER_SIZE +
                                             fastmac_parms->tx_buf_space + 
                                             sizeof(DWORD)
                                         );

    /*
     * Calculate max receive frame size from size of buffer, size of
     * header and knowing that one frame must leave space such that host
     * and adapter ptrs into buffer are not the same.
     */

    rx_max_frame_size = 
        fastmac_parms->rx_buf_size - macro_dword_align(
                                         FASTMAC_BUFFER_HEADER_SIZE +
                                             fastmac_parms->rx_buf_space + 
                                             sizeof(DWORD)
                                         );

    /*
     * Actual max frame size is minimum of max transmit and receive frame
     * sizes and max frame size for adapter (ring speed dependent).
     */

    max_frame_size = util_minimum( 
                         tx_max_frame_size,
                         rx_max_frame_size,
                         adapter->max_frame_size
                         );

    return max_frame_size;

#endif
}

/**** End of DRV_INIT.C file ***********************************************/