summaryrefslogblamecommitdiffstats
path: root/private/ntos/ndis/madge/driver/ftk_user.c
blob: 5a58b90d45b5c775ed1cf711972da8add6cb7a39 (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
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187










































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































                                                                                            
/****************************************************************************
*
* FTK_USER.C
*
* FastMAC Plus based NDIS3 miniport driver FTK interface. This module 
* contains all of the routines required to interface with the FastMAC 
* Plus FTK. This is includes the routines traditionally found in transmit.c 
* and receive.c.
*                                                                          
* Copyright (c) Madge Networks Ltd 1994                                    
*    
* COMPANY CONFIDENTIAL
*
* Created: PBA 21/06/1994
*                                                                           
****************************************************************************/

#include <ndis.h>

#include "ftk_defs.h"
#include "ftk_extr.h"
#include "ftk_intr.h"

#include "mdgmport.upd"
#include "ndismod.h"


/*---------------------------------------------------------------------------
|
|                      LOCAL VARIABLES                                  
|                                                                       
---------------------------------------------------------------------------*/

//
// To cut down on accesses to the slot structures on the card we keep
// a host cache of various detaisl we need.
//

typedef struct
{
    DWORD PhysicalAddress;
    PVOID VirtualAddress;
}
RX_SLOT_CACHE, *PRX_SLOT_CACHE;


typedef struct
{
    ULONG         BufferSize;
    ULONG         SharedMemoryAllocation;
    PVOID         SharedMemoryVirtAddr;
    DWORD         SharedMemoryPhysAddr;

    RX_SLOT_CACHE rx_slot_cache[FMPLUS_MAX_RX_SLOTS];

    UINT          active_rx_slot; /* Used to count through the slot array */
} 
RX_SLOT_MGMNT, *PRX_SLOT_MGMNT;


typedef struct 
{
    DWORD PhysicalAddress;
    PVOID VirtualAddress;
} 
TX_SLOT_CACHE, *PTX_SLOT_CACHE;


typedef struct 
{
    ULONG         BufferSize;
    ULONG         SharedMemoryAllocation;
    PVOID         SharedMemoryVirtAddr;
    DWORD         SharedMemoryPhysAddr;

    TX_SLOT_CACHE tx_slot_cache[FMPLUS_MAX_TX_SLOTS];

    UINT          active_tx_slot; 
    UINT          first_tx_in_use;   
    UINT          number_tx_in_use;
} 
TX_SLOT_MGMNT, *PTX_SLOT_MGMNT;


#define FRAME_TYPE_MASK    ((BYTE) 0xC0)   // What is ANDed with FC byte.
#define FRAME_TYPE_MAC     ((BYTE) 0x00)   // What's left for a MAC frame.


typedef struct
{
    ADAPTER_HANDLE   adapter_handle;
    ADAPTER        * adapter;
    TX_SLOT        * tx_slot_ptr;
    RX_SLOT        * rx_slot_ptr;
    UINT             frame_length;
    UINT             result1;
    UINT             result2;
}
MPSAFE_INFO;


#if 0

typedef struct
{
    ADAPTER_HANDLE handle;
    WORD           location;
    WORD           result;
}
RDIO;

WORD
_madge_rdio(
    void * ptr
    )
{
    RDIO * rdio;

    rdio = (RDIO *) ptr;

    sys_outsw(
        rdio->handle,
        adapter_record[rdio->handle]->sif_adr,
        rdio->location
        );

    rdio->result = sys_insw(
                       rdio->handle,
                       adapter_record[rdio->handle]->sif_dat
                       );

    return 0;
}


WORD
madge_rdio(
    ADAPTER_HANDLE adapter_handle,
    WORD           dio_location
    )
{
    RDIO rdio;

    rdio.handle   = adapter_handle;
    rdio.location = dio_location;

    sys_sync_with_interrupt(
        adapter_handle, 
        _madge_rdio,
        (void *) &rdio
        );

    return rdio.result;
}


void
madge_dump_fmplus_info(
    ADAPTER_HANDLE adapter_handle
    )
{
    ADAPTER          * adapter;
    PRX_SLOT_MGMNT     rx_slot_mgmnt;
    PTX_SLOT_MGMNT     tx_slot_mgmnt;
    PMADGE_ADAPTER     ndisAdap;
    RX_SLOT        * * rx_slot_array;
    TX_SLOT        * * tx_slot_array;
    UINT               active_rx_slot;
    UINT               active_tx_slot;
    UINT               first_tx_slot;
    UINT               rx_slots;
    UINT               tx_slots;
    UINT               i;

    adapter        = adapter_record[adapter_handle];

    rx_slot_array  = adapter->rx_slot_array;
    rx_slot_mgmnt  = (PRX_SLOT_MGMNT) adapter->rx_slot_mgmnt;
    active_rx_slot = rx_slot_mgmnt->active_rx_slot;
    rx_slots       = adapter->init_block->fastmac_parms.rx_slots;

    tx_slot_array  = adapter->tx_slot_array;
    tx_slot_mgmnt  = (PTX_SLOT_MGMNT) adapter->tx_slot_mgmnt;
    active_tx_slot = tx_slot_mgmnt->active_tx_slot;
    first_tx_slot  = tx_slot_mgmnt->first_tx_in_use;
    tx_slots       = adapter->init_block->fastmac_parms.tx_slots;

    DbgPrint("----------------------------------------------------------\n");

    DbgPrint(
        "SIFADR high word = %04x\n\n", 
        sys_insw(adapter_handle, adapter->sif_adx)
        );

    DbgPrint("RX SLOTS:\n\n");
    DbgPrint("Active slot = %d\n", active_rx_slot);

    DbgPrint("      Len  Res  Buffer    Stat Next\n");
    DbgPrint("      ---- ---- --------- ---- ----\n");

    for (i = 0; i < rx_slots; i++)
    {
        DbgPrint(
            "%04x: %04x %04x %04x %04x %04x %04x\n",
            (WORD) (card_t) rx_slot_array[i],
	    madge_rdio(adapter_handle, (WORD) (card_t) &rx_slot_array[i]->buffer_len),
	    madge_rdio(adapter_handle, (WORD) (card_t) &rx_slot_array[i]->reserved),
	    madge_rdio(adapter_handle, (WORD) (card_t) &rx_slot_array[i]->buffer_hiw),
	    madge_rdio(adapter_handle, (WORD) (card_t) &rx_slot_array[i]->buffer_low),
            madge_rdio(adapter_handle, (WORD) (card_t) &rx_slot_array[i]->rx_status),
	    madge_rdio(adapter_handle, (WORD) (card_t) &rx_slot_array[i]->next_slot)
            );
    }

    DbgPrint("\n");

    DbgPrint("TX SLOTS:\n\n");
    DbgPrint("Active slot     = %d\n", active_tx_slot);
    DbgPrint("First used slot = %d\n", first_tx_slot);

    DbgPrint("      Stat SLen LLen Res1 Res2 Sbuffer   Next LBuffer\n");
    DbgPrint("      ---- ---- ---- ---- ---- --------- ---- ---------\n");

    for (i = 0; i < tx_slots; i++)
    {
        DbgPrint(
            "%04x: %04x %04x %04x %04x %04x %04x %04x %04x %04x %04x\n",
            (WORD) (card_t) tx_slot_array[i],
   	    madge_rdio(adapter_handle, (WORD) (card_t) &tx_slot_array[i]->tx_status),
	    madge_rdio(adapter_handle, (WORD) (card_t) &tx_slot_array[i]->small_buffer_len),
	    madge_rdio(adapter_handle, (WORD) (card_t) &tx_slot_array[i]->large_buffer_len),
	    madge_rdio(adapter_handle, (WORD) (card_t) &tx_slot_array[i]->reserved[0]),
	    madge_rdio(adapter_handle, (WORD) (card_t) &tx_slot_array[i]->reserved[1]),
            madge_rdio(adapter_handle, (WORD) (card_t) &tx_slot_array[i]->small_buffer_hiw),
	    madge_rdio(adapter_handle, (WORD) (card_t) &tx_slot_array[i]->small_buffer_low),
	    madge_rdio(adapter_handle, (WORD) (card_t) &tx_slot_array[i]->next_slot),
	    madge_rdio(adapter_handle, (WORD) (card_t) &tx_slot_array[i]->large_buffer_hiw),
	    madge_rdio(adapter_handle, (WORD) (card_t) &tx_slot_array[i]->large_buffer_low)
            );
    }

    DbgPrint("\n");

    DbgPrint("DIO LOCATION 0x0CE0\n\n");

    for (i = 0; i < 32; i++)
    {
        DbgPrint(" %04x", madge_rdio(adapter_handle, (WORD) (0x0ce0 + i * 2)));
        if (i == 15)
        {
            DbgPrint("\n");
        }
    }

    DbgPrint("\n");
}

#endif

/***************************************************************************
*
* Function    - rxtx_allocate_rx_buffers
*
* Parameters  - adapter            -> Pointer to an FTK adapter structure.
*               max_frame_size     -> Maximum frame size.
*               number_of_slots    -> Number of receive slots.
*               
* Purpose     - Allocate buffer space for the receive slots.
*                                                                         
* Returns     - TRUE if it succeeds or FALSE otherwise.
*                                                                        
****************************************************************************/

WBOOLEAN
rxtx_allocate_rx_buffers(
    ADAPTER * adapter, 
    WORD      max_frame_size,
    WORD      number_of_slots
    );

#pragma FTK_INIT_FUNCTION(rxtx_allocate_rx_buffers)

WBOOLEAN
rxtx_allocate_rx_buffers(
    ADAPTER * adapter, 
    WORD      max_frame_size,
    WORD      number_of_slots
    )
{
    PRX_SLOT_MGMNT rx_slot_mgmnt;
    NDIS_STATUS    status;
    ADAPTER_HANDLE adapter_handle;
    PMADGE_ADAPTER ndisAdap;
    DWORD          SharedMemVirtAddr;
    DWORD          SharedMemPhysAddr;

    //
    // Pre-calculate some commonly used values.
    //
    
    rx_slot_mgmnt = (PRX_SLOT_MGMNT) adapter->rx_slot_mgmnt;

    //
    // Only want to allocate the receive buffers and slot management once 
    // per adapter.
    //

    if (rx_slot_mgmnt == NULL)
    {
        //
        // Pre-calculate some commonly used values.
        //

        adapter_handle = adapter->adapter_handle;
        ndisAdap       = PMADGE_ADAPTER_FROM_ADAPTER_HANDLE(adapter_handle);

        //
        // Allocate the slot management structure.
        //

        MADGE_ALLOC_MEMORY(
            &status,
            &adapter->rx_slot_mgmnt,
            sizeof(RX_SLOT_MGMNT)
            );

        if (status != NDIS_STATUS_SUCCESS)
        {
            return FALSE;
        }

        MADGE_ZERO_MEMORY(adapter->rx_slot_mgmnt, sizeof(RX_SLOT_MGMNT));

        rx_slot_mgmnt = (PRX_SLOT_MGMNT) adapter->rx_slot_mgmnt;

        //
        // Work out how big the buffer should be. Remember to add 
        // four to the buffer allocation for the CRC. The addition
        // of 32 provides a little space between receive buffers
        // for those naughty transport protocols that read more
        // then the indicated lookahead.
        //

        rx_slot_mgmnt->BufferSize = (max_frame_size + 4 + 32 + 3) & ~3;

        rx_slot_mgmnt->SharedMemoryAllocation = 
            rx_slot_mgmnt->BufferSize * number_of_slots;

        //
        // Allocate the buffer.
        //

        if (!sys_alloc_dma_phys_buffer(
                 adapter_handle,
                 rx_slot_mgmnt->SharedMemoryAllocation,
                 &SharedMemPhysAddr,
                 &SharedMemVirtAddr
                 )) 
        {
            return FALSE;
        }

        rx_slot_mgmnt->SharedMemoryVirtAddr = (VOID *) SharedMemVirtAddr;
        rx_slot_mgmnt->SharedMemoryPhysAddr = SharedMemPhysAddr;
    }

    return TRUE;
}


/***************************************************************************
*
* Function    - rxtx_setup_rx_buffers
*
* Parameters  - adapter            -> Pointer to an FTK adapter structure.
*               physical_addresses -> Use physical addresses?
*               number_of_slots    -> Number of receive slots.
*
* Purpose     - Set up the adapter receive slots.
*                                                                         
* Returns     - TRUE if it succeeds or FALSE otherwise.
*                                                                        
****************************************************************************/

void
rxtx_setup_rx_buffers(
    ADAPTER  * adapter, 
    WBOOLEAN   physical_addresses,
    WORD       number_of_slots
    );

#pragma FTK_INIT_FUNCTION(rxtx_setup_rx_buffers)

void
rxtx_setup_rx_buffers(
    ADAPTER  * adapter, 
    WBOOLEAN   physical_addresses,
    WORD       number_of_slots
    )
{
    PRX_SLOT_MGMNT     rx_slot_mgmnt;
    NDIS_STATUS        status;
    ADAPTER_HANDLE     adapter_handle;
    PMADGE_ADAPTER     ndisAdap;
    PVOID              SharedMemVirtAddr;
    DWORD              SharedMemPhysAddr;
    PRX_SLOT_CACHE     rx_slot_cache;
    RX_SLOT        * * rx_slot_array;
    DWORD              phys_addr;
    WORD               slot_index;
    WORD               sifadr;
    WORD               sifdat;
    WORD               sifdatinc;
    UINT               buffer_size;

    //
    // Pre-calculate some commonly used values.
    //
    
    adapter_handle    = adapter->adapter_handle;
    ndisAdap          = PMADGE_ADAPTER_FROM_ADAPTER_HANDLE(adapter_handle);

    rx_slot_array     = adapter->rx_slot_array;
    rx_slot_mgmnt     = (PRX_SLOT_MGMNT) adapter->rx_slot_mgmnt;
    rx_slot_cache     = rx_slot_mgmnt->rx_slot_cache;
    SharedMemVirtAddr = rx_slot_mgmnt->SharedMemoryVirtAddr;
    SharedMemPhysAddr = rx_slot_mgmnt->SharedMemoryPhysAddr;
    buffer_size       = rx_slot_mgmnt->BufferSize;

    sifadr            = adapter->sif_adr;
    sifdat            = adapter->sif_dat;
    sifdatinc         = adapter->sif_datinc;

    MadgePrint2("rxtx_setup_rx_buffers number_of_slots = %d\n", number_of_slots);
    MadgePrint2("rxtx_setup_rx_buffers buffer_size = %d\n", buffer_size);

    //
    // Work out the physical and virtual address of each buffer.
    //

    for (slot_index = 0; slot_index < number_of_slots; slot_index++)
    {
        rx_slot_cache[slot_index].VirtualAddress  = SharedMemVirtAddr;
        (PUCHAR) SharedMemVirtAddr               += buffer_size;

        rx_slot_cache[slot_index].PhysicalAddress = SharedMemPhysAddr;
        SharedMemPhysAddr                        += buffer_size; 

        phys_addr = (physical_addresses)
            ? (DWORD) rx_slot_cache[slot_index].PhysicalAddress
            : (DWORD) rx_slot_cache[slot_index].VirtualAddress;

        //
        // Write the buffer locations into the slots.
        //

        sys_outsw(
            adapter_handle,
            sifadr,
            (WORD) (card_t) &rx_slot_array[slot_index]->buffer_hiw
            );

        sys_outsw(
            adapter_handle,
            sifdatinc,
            (WORD) (phys_addr >> 16)
            );

        sys_outsw(
            adapter_handle,
            sifdat,
            (WORD) (phys_addr & 0x0FFFF)
            );
    }

    ndisAdap->RxTxBufferState    |= MADGE_RX_INITIALIZED;
    rx_slot_mgmnt->active_rx_slot = 0;
}


/***************************************************************************
*
* Function    - rxtx_free_rx_buffers
*
* Parameters  - adapter         -> Pointer to an FTK adapter structure.
*               max_frame_size  -> Maximum frame size.
*               number_of_slots -> Number of receive slots.
*
* Purpose     - Free the previously allocated receive buffers.
*                                                                         
* Returns     - Nothing.
*                                                                        
****************************************************************************/

void
rxtx_free_rx_buffers(
    ADAPTER * adapter,
    WORD      max_frame_size,
    WORD      number_of_slots
    )
{
    ADAPTER_HANDLE adapter_handle;
    PMADGE_ADAPTER ndisAdap;
    PRX_SLOT_MGMNT rx_slot_mgmnt;

    //
    // Pre-calculate some commonly used values.
    //

    adapter_handle  = adapter->adapter_handle;
    ndisAdap        = PMADGE_ADAPTER_FROM_ADAPTER_HANDLE(adapter_handle);
    rx_slot_mgmnt   = (PRX_SLOT_MGMNT) adapter->rx_slot_mgmnt;

    //
    // If the slot management structure exists them free it 
    // and the buffers.
    //

    if (rx_slot_mgmnt != NULL)
    {
        if (rx_slot_mgmnt->SharedMemoryVirtAddr != NULL)
        {
            sys_free_dma_phys_buffer(
                adapter_handle,
                rx_slot_mgmnt->SharedMemoryAllocation,
                (DWORD) rx_slot_mgmnt->SharedMemoryPhysAddr,
                (DWORD) rx_slot_mgmnt->SharedMemoryVirtAddr
                );
        }

        MADGE_FREE_MEMORY(adapter->rx_slot_mgmnt, sizeof(RX_SLOT_MGMNT));

        adapter->rx_slot_mgmnt = NULL;

        ndisAdap->RxTxBufferState &= ~MADGE_RX_INITIALIZED;
    }
}


/***************************************************************************
*
* Function    - rxtx_allocate_tx_buffers
*
* Parameters  - adapter            -> Pointer to an FTK adapter structure.
*               max_frame_size     -> Maximum frame size.
*               number_of_slots    -> Number of transmit slots.
*               
* Purpose     - Allocate buffer space for the transmit slots.
*                                                                         
* Returns     - TRUE if it succeeds or FALSE otherwise.
*                                                                        
****************************************************************************/

WBOOLEAN
rxtx_allocate_tx_buffers(
    ADAPTER * adapter, 
    WORD      max_frame_size,
    WORD      number_of_slots
    );

#pragma FTK_INIT_FUNCTION(rxtx_allocate_tx_buffers)

WBOOLEAN
rxtx_allocate_tx_buffers(
    ADAPTER * adapter, 
    WORD      max_frame_size,
    WORD      number_of_slots
    )
{
    PTX_SLOT_MGMNT tx_slot_mgmnt;
    NDIS_STATUS    status;
    ADAPTER_HANDLE adapter_handle;
    PMADGE_ADAPTER ndisAdap;
    DWORD          SharedMemVirtAddr;
    DWORD          SharedMemPhysAddr;

    //
    // Pre-calculate some commonly used values.
    //
    
    tx_slot_mgmnt = (PTX_SLOT_MGMNT) adapter->tx_slot_mgmnt;

    //
    // Only want to allocate the receive buffers and slot management once 
    // per adapter.
    //

    if (tx_slot_mgmnt == NULL)
    {
        //
        // Pre-calculate some commonly used values.
        //

        adapter_handle = adapter->adapter_handle;
        ndisAdap       = PMADGE_ADAPTER_FROM_ADAPTER_HANDLE(adapter_handle);

        //
        // Allocate the slot management structure.
        //

        MADGE_ALLOC_MEMORY(
            &status,
            &adapter->tx_slot_mgmnt,
            sizeof(TX_SLOT_MGMNT)
            );

        if (status != NDIS_STATUS_SUCCESS)
        {
            return FALSE;
        }

        MADGE_ZERO_MEMORY(adapter->tx_slot_mgmnt, sizeof(TX_SLOT_MGMNT));

        tx_slot_mgmnt = (PTX_SLOT_MGMNT) adapter->tx_slot_mgmnt;

        //
        // Work out how big the buffer should be.
        //

        tx_slot_mgmnt->BufferSize = (max_frame_size + 3) & ~3;

        tx_slot_mgmnt->SharedMemoryAllocation = 
            tx_slot_mgmnt->BufferSize * number_of_slots;

        //
        // Allocate the buffer.
        //

        if (!sys_alloc_dma_phys_buffer(
                 adapter_handle,
                 tx_slot_mgmnt->SharedMemoryAllocation,
                 &SharedMemPhysAddr,
                 &SharedMemVirtAddr
                 )) 
        {
            return FALSE;
        }

        tx_slot_mgmnt->SharedMemoryVirtAddr = (VOID *) SharedMemVirtAddr;
        tx_slot_mgmnt->SharedMemoryPhysAddr = SharedMemPhysAddr;
    }

    return TRUE;
}


/***************************************************************************
*
* Function    - rxtx_setup_tx_buffers
*
* Parameters  - adapter            -> Pointer to an FTK adapter structure.
*               physical_addresses -> Use physical addresses?
*               number_of_slots    -> Number of transmit slots.
*
* Purpose     - Set up the adapter transmit slots.
*                                                                         
* Returns     - TRUE if it succeeds or FALSE otherwise.
*                                                                        
****************************************************************************/

void
rxtx_setup_tx_buffers(
    ADAPTER  * adapter, 
    WBOOLEAN   physical_addresses,
    WORD       number_of_slots
    );

#pragma FTK_INIT_FUNCTION(rxtx_setup_tx_buffers)

void
rxtx_setup_tx_buffers(
    ADAPTER  * adapter, 
    WBOOLEAN   physical_addresses,
    WORD       number_of_slots
    )
{
    PTX_SLOT_MGMNT     tx_slot_mgmnt;
    NDIS_STATUS        status;
    ADAPTER_HANDLE     adapter_handle;
    PMADGE_ADAPTER     ndisAdap;
    PVOID              SharedMemVirtAddr;
    DWORD              SharedMemPhysAddr;
    PTX_SLOT_CACHE     tx_slot_cache;
    TX_SLOT        * * tx_slot_array;
    DWORD              phys_addr;
    WORD               slot_index;
    WORD               sifadr;
    WORD               sifdat;
    WORD               sifdatinc;
    UINT               buffer_size;

    //
    // Pre-calculate some commonly used values.
    //
    
    adapter_handle    = adapter->adapter_handle;
    ndisAdap          = PMADGE_ADAPTER_FROM_ADAPTER_HANDLE(adapter_handle);

    tx_slot_array     = adapter->tx_slot_array;
    tx_slot_mgmnt     = (PTX_SLOT_MGMNT) adapter->tx_slot_mgmnt;
    tx_slot_cache     = tx_slot_mgmnt->tx_slot_cache;
    SharedMemVirtAddr = tx_slot_mgmnt->SharedMemoryVirtAddr;
    SharedMemPhysAddr = tx_slot_mgmnt->SharedMemoryPhysAddr;
    buffer_size       = tx_slot_mgmnt->BufferSize;

    sifadr            = adapter->sif_adr;
    sifdat            = adapter->sif_dat;
    sifdatinc         = adapter->sif_datinc;

    MadgePrint2("rxtx_setup_tx_buffers number_of_slots = %d\n", number_of_slots);
    MadgePrint2("rxtx_setup_tx_buffers buffer_size = %d\n", buffer_size);

    //
    // Work out the physical and virtual address of each buffer.
    //

    for (slot_index = 0; slot_index < number_of_slots; slot_index++)
    {
        tx_slot_cache[slot_index].VirtualAddress  = SharedMemVirtAddr;
        (PUCHAR) SharedMemVirtAddr               += buffer_size;

        tx_slot_cache[slot_index].PhysicalAddress = SharedMemPhysAddr;
        SharedMemPhysAddr                        += buffer_size;

        phys_addr = (physical_addresses)
            ? (DWORD) tx_slot_cache[slot_index].PhysicalAddress
            : (DWORD) tx_slot_cache[slot_index].VirtualAddress;

        //
        // Write the buffer locations into the slots.
        //

        sys_outsw(
            adapter_handle,
            sifadr,
            (WORD) (card_t) &tx_slot_array[slot_index]->large_buffer_hiw
            );

        sys_outsw(
            adapter_handle,
            sifdatinc,
            (WORD) (phys_addr >> 16)
            );

        sys_outsw(
            adapter_handle,
            sifdat,
            (WORD) (phys_addr & 0x0FFFF)
            );
    }

    ndisAdap->RxTxBufferState      |= MADGE_TX_INITIALIZED;
    tx_slot_mgmnt->active_tx_slot   = 0;
    tx_slot_mgmnt->first_tx_in_use  = 0;
    tx_slot_mgmnt->number_tx_in_use = 0;
}


/***************************************************************************
*
* Function    - rxtx_free_tx_buffers
*
* Parameters  - adapter         -> Pointer to an FTK adapter structure.
*               max_frame_size  -> Maximum frame size.
*               number_of_slots -> Number of transmit slots.
*
* Purpose     - Free the previously allocated transmit buffers.
*                                                                         
* Returns     - Nothing.
*                                                                        
****************************************************************************/

void
rxtx_free_tx_buffers(
    ADAPTER * adapter,
    WORD      max_frame_size,
    WORD      number_of_slots
    )
{
    ADAPTER_HANDLE adapter_handle;
    PMADGE_ADAPTER ndisAdap;
    PTX_SLOT_MGMNT tx_slot_mgmnt;

    //
    // Pre-calculate some commonly used values.
    //

    adapter_handle  = adapter->adapter_handle;
    ndisAdap        = PMADGE_ADAPTER_FROM_ADAPTER_HANDLE(adapter_handle);
    tx_slot_mgmnt   = (PTX_SLOT_MGMNT) adapter->tx_slot_mgmnt;

    //
    // If the slot management structure exists them free it 
    // and the buffers.
    //

    if (tx_slot_mgmnt != NULL)
    {
        if (tx_slot_mgmnt->SharedMemoryVirtAddr != NULL)
        {
            sys_free_dma_phys_buffer(
                adapter_handle,
                tx_slot_mgmnt->SharedMemoryAllocation,
                (DWORD) tx_slot_mgmnt->SharedMemoryPhysAddr,
                (DWORD) tx_slot_mgmnt->SharedMemoryVirtAddr
                );
        }

        MADGE_FREE_MEMORY(adapter->tx_slot_mgmnt, sizeof(TX_SLOT_MGMNT));

        adapter->tx_slot_mgmnt = NULL;

        ndisAdap->RxTxBufferState &= ~MADGE_TX_INITIALIZED;
    }
}


/*--------------------------------------------------------------------------
|
| Function    - MPSafeReadTxStatus
|
| Paramters   - ptr -> Pointer to an MPSAFE_INFO structure.
|
| Purpose     - Reads the transmit status from the next slot to use. This
|               function is called via NdisSynchronizeWithInterrupt when
|               in PIO mode so that we don't get SIF register contention
|               on a multiprocessor.
|
| Returns     - Nothing.
|
--------------------------------------------------------------------------*/

STATIC BOOLEAN
MPSafeReadTxStatus(PVOID ptr)
{
    MPSAFE_INFO * info = (MPSAFE_INFO *) ptr;

    //
    // Read the transmit status from the slot.
    //

    sys_outsw(
        info->adapter_handle, 
        info->adapter->sif_adr,
        (WORD) (card_t) &(info->tx_slot_ptr)->tx_status
        );

    info->result1 = sys_insw(
                        info->adapter_handle, 
                        info->adapter->sif_dat
                        );

    return FALSE;
}


/***************************************************************************
*
* Function    - rxtx_irq_tx_completion_check
*
* Parameters  - adapter_handle -> FTK adapter handle.
*               adapter        -> Pointer to FTK adapter structure.
*
* Purpose     - Complete any outstanding transmits.
*                                                                         
* Returns     - Nothing.
*                                                                        
****************************************************************************/

void
rxtx_irq_tx_completion_check(
    ADAPTER_HANDLE   adapter_handle,
    ADAPTER        * adapter
    )
{
    UINT                tx_slots;
    PTX_SLOT_MGMNT      tx_slot_mgmnt;
    PTX_SLOT_CACHE      tx_slot_cache;
    TX_SLOT         * * tx_slot_array;
    PMADGE_ADAPTER      ndisAdap;
    UINT                tx_status;
    MPSAFE_INFO         info;
    WORD                sifadr;
    WORD                sifdat;

    //
    // Pre-calculate some commonly used values.
    //
            
    tx_slot_mgmnt  = (PTX_SLOT_MGMNT) adapter->tx_slot_mgmnt;
    tx_slot_cache  = tx_slot_mgmnt->tx_slot_cache;
    tx_slot_array  = adapter->tx_slot_array;
    ndisAdap       = PMADGE_ADAPTER_FROM_ADAPTER_HANDLE(adapter_handle);
    tx_slots       = adapter->init_block->fastmac_parms.tx_slots;
    sifadr         = adapter->sif_adr;
    sifdat         = adapter->sif_dat;

    //
    // If we're doing multiprocessor safe PIO then we need to set up
    // the info structure.
    //

    if (ndisAdap->UseMPSafePIO)
    {
        info.adapter_handle = adapter_handle;
        info.adapter        = adapter;
    }

    //
    // Iterate around the transmit slots that are are marked as in use
    // checking if they are now free. Note: we must work with the 
    // global coopies of the first_tx_in_use and number_tx_in_use
    // in case rxtx_transmit_frame is called during our up-call
    // to the wrapper.
    //

    while (tx_slot_mgmnt->number_tx_in_use > 0)
    {
        //
        // Read the transmit status from the slot. If we're doing 
        // multiprocessor safe PIO we must do the DIO via an ISR 
        // synchronized function.
        //

        if (ndisAdap->UseMPSafePIO)
        {
            info.tx_slot_ptr = tx_slot_array[tx_slot_mgmnt->first_tx_in_use];

            NdisMSynchronizeWithInterrupt(
                &ndisAdap->Interrupt,
                MPSafeReadTxStatus,
                &info
                );

            tx_status = info.result1;
        }
        else
        {
            sys_outsw(
                adapter_handle, 
                sifadr,
                (WORD) (card_t) &tx_slot_array[
                                    tx_slot_mgmnt->first_tx_in_use
                                    ]->tx_status
                );

            tx_status = sys_insw(
                            adapter_handle, 
                            sifdat
                            );
        }

        //
        // If the slot is still in use then we must give up. This will
        // also work if a PCMCIA adapter has been removed because
        // tx_status will have been read as 0xffff.
        //

        if (tx_status >= 0x8000 || tx_status == 0)
        {
            break;
        }

        //
        // Update the appropriate counters from the frame transmit
        // status.
        //

        if ((tx_status & TX_RECEIVE_STATUS_MASK) == TX_RECEIVE_LOST_FRAME)
        {
            ndisAdap->LostFrames++;
        }
        else if ((tx_status & GOOD_TX_FRAME_MASK) != GOOD_TX_FRAME_VALUE)
        {
            ndisAdap->FrameTransmitErrors++;
        }

        //
        // Update the slot usage.
        //

        tx_slot_mgmnt->number_tx_in_use--;

        if (++tx_slot_mgmnt->first_tx_in_use == tx_slots)
        {
            tx_slot_mgmnt->first_tx_in_use = 0;
        }

        //
        // Tell the wrapper that there is a free slot.
        //

        NdisMSendResourcesAvailable(ndisAdap->UsedInISR.MiniportHandle);
    }

    //
    // If there are any frames we have queued for transmit that
    // have not been completed then arm the timer so we are guaranteed
    // to be called again. Under normal operation our DPR gets called
    // often enough that this function is called frequently enough to
    // complete all of the frames. However if we have an adapter in a 
    // fast bus (PCI/EISA) with a lot of RAM and we are not
    // getting any recieve interrupts we can occasionally miss
    // completing a frame. Hence the timer.
    //
    
    if (tx_slot_mgmnt->number_tx_in_use > 0)
    {
        NdisMSetTimer(&ndisAdap->CompletionTimer, 20);
    }
}


/*--------------------------------------------------------------------------
|
| Function    - MPSafeStartTx
|
| Paramters   - ptr -> Pointer to an MPSAFE_INFO structure.
|
| Purpose     - Set up a tx slot and start the transmit going. This
|               function is called via NdisSynchronizeWithInterrupt when
|               in PIO mode so that we don't get SIF register contention
|               on a multiprocessor.
|
| Returns     - Nothing.
|
--------------------------------------------------------------------------*/

STATIC BOOLEAN
MPSafeStartTx(PVOID ptr)
{
    MPSAFE_INFO * info = (MPSAFE_INFO *) ptr;

    //
    // Reset the transmit status in the transmit slot.
    //

    sys_outsw(
        info->adapter_handle, 
        info->adapter->sif_adr,
        (WORD) (card_t) &(info->tx_slot_ptr)->tx_status
        );

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

    //
    // Write in the length of the buffer into the transmit slot
    // (large buffer).
    //

    sys_outsw(
        info->adapter_handle, 
        info->adapter->sif_adr,
        (WORD) (card_t) &(info->tx_slot_ptr)->large_buffer_len
        );

    sys_outsw(
        info->adapter_handle, 
        info->adapter->sif_dat, 
        (WORD) info->frame_length
        );

    //
    // Write the length of the small buffer in the transmit slot to 
    // start the transmit going.
    //

    sys_outsw(
        info->adapter_handle, 
        info->adapter->sif_adr,
        (WORD) (card_t) &(info->tx_slot_ptr)->small_buffer_len
        );

    sys_outsw(
        info->adapter_handle, 
        info->adapter->sif_dat, 
        FMPLUS_SBUFF_ZERO_LENGTH
        );

    return FALSE;
}


/***************************************************************************
*
* Function    - rxtx_transmit_frame
*
* Parameters  - adapter_handle      -> FTK adapter handle.
*               tx_frame_identifier -> NDIS packet handle or a pointer
*                                      to some data to send.
*               tx_frame_length     -> Length of the frame.
*               tx_is_packet        -> TRUE if tx_frame_identifier is
*                                      an NDIS packet handle.
*
* Purpose     - Attempts to transmit a frame by copying it into a transmit
*               buffer and activating a FastMAC Plus tx slot.
*                                                                         
* Returns     - DRIVER_TRANSMIT_SUCCESS if it succeeds or 
*               DRIVER_TRANSMIT_FAILURE if it does not.
*                                                                        
****************************************************************************/

WORD 
rxtx_transmit_frame(
    ADAPTER_HANDLE adapter_handle,
    DWORD          tx_frame_identifier,
    WORD           tx_frame_length,
    WORD           tx_is_packet
    )
{
    ADAPTER            * adapter;
    PTX_SLOT_MGMNT       tx_slot_mgmnt;
    PTX_SLOT_CACHE       tx_slot_cache;
    TX_SLOT            * tx_slot_ptr;
    UINT                 active_tx_slot;
    UINT                 tx_slots;
    PMADGE_ADAPTER       ndisAdap;
    UINT                 bytes_copied;
    UINT                 tx_status;
    MPSAFE_INFO          info;
    WORD                 sifadr;
    WORD                 sifdat;

    //
    // Pre-calculate some commonly used values.
    //
            
    adapter        = adapter_record[adapter_handle];
    tx_slot_mgmnt  = (PTX_SLOT_MGMNT) adapter->tx_slot_mgmnt;
    tx_slot_cache  = tx_slot_mgmnt->tx_slot_cache;
    active_tx_slot = tx_slot_mgmnt->active_tx_slot;
    tx_slot_ptr    = adapter->tx_slot_array[active_tx_slot];
    tx_slots       = adapter->init_block->fastmac_parms.tx_slots;
    ndisAdap       = PMADGE_ADAPTER_FROM_ADAPTER_HANDLE(adapter_handle);
    sifadr         = adapter->sif_adr;
    sifdat         = adapter->sif_dat;

    //
    // If we are a PCMCIA adapter it is possible that the adapter
    // may have been removed. To detect this we check if SIFADR
    // is 0xffff since this should not normally be true.
    //

    if (adapter->adapter_card_bus_type == ADAPTER_CARD_PCMCIA_BUS_TYPE)
    {
        if (sys_insw(adapter_handle, sifadr) == 0xffff)
        {
            rxtx_adapter_removed(adapter_handle);

            return DRIVER_TRANSMIT_SUCCEED;
        }
    }

    //
    // If the next slot to be used is still in use then we must 
    // give up.
    //

    if (tx_slot_mgmnt->number_tx_in_use == tx_slots)
    {

#ifdef OID_MADGE_MONITOR
        (ndisAdap->MonitorInfo).FailedToTransmit++;
#endif

        return DRIVER_TRANSMIT_FAIL;
    }

    //
    // Copy the frame into the transmit buffer.
    //

    if (tx_is_packet)
    {
        MadgeCopyFromPacketToBuffer(
            (PNDIS_PACKET) tx_frame_identifier,
            0,
            tx_frame_length,
            (PUCHAR) tx_slot_cache[active_tx_slot].VirtualAddress,
            &bytes_copied
            );
    }
    else
    {
        MADGE_MOVE_MEMORY(
            tx_slot_cache[active_tx_slot].VirtualAddress,
            (PUCHAR) tx_frame_identifier,
            tx_frame_length
            );
    }

    //
    // Set up the tx slot and start the transmit. If we're using 
    // multiprocessor safe PIO then we must do the DIO via an ISR
    // synchronised function.
    //

    if (ndisAdap->UseMPSafePIO)
    {
        info.adapter_handle = adapter_handle;
        info.adapter        = adapter;
        info.tx_slot_ptr    = tx_slot_ptr;
        info.frame_length   = tx_frame_length;

        NdisMSynchronizeWithInterrupt(
            &ndisAdap->Interrupt,
            MPSafeStartTx,
            &info
            );
    }
    else
    {
        //
        // Reset the transmit status in the transmit slot.
        //

        sys_outsw(
            adapter_handle, 
            sifadr,
            (WORD) (card_t) &tx_slot_ptr->tx_status
            );

        sys_outsw(
            adapter_handle, 
            sifdat, 
            (WORD) 0x8000
            );

        //
        // Write in the length of the buffer into the transmit slot
        // (large buffer).
        //

        sys_outsw(
            adapter_handle, 
            sifadr,
            (WORD) (card_t) &tx_slot_ptr->large_buffer_len
            );

        sys_outsw(
            adapter_handle, 
            sifdat, 
            (WORD) tx_frame_length
            );

        //
        // Write the length of the small buffer in the transmit slot to 
        // start the transmit going.
        //

        sys_outsw(
            adapter_handle, 
            sifadr,
            (WORD) (card_t) &tx_slot_ptr->small_buffer_len
            );

        sys_outsw(
            adapter_handle, 
            sifdat, 
            FMPLUS_SBUFF_ZERO_LENGTH
            );
    }

    //
    // Note that the slot is in use.
    //

    tx_slot_mgmnt->number_tx_in_use++;

    //
    // Update the slot counter ready for the next transmit.
    //

    if (++tx_slot_mgmnt->active_tx_slot == tx_slots)
    {
        tx_slot_mgmnt->active_tx_slot = 0;
    }

    return DRIVER_TRANSMIT_SUCCEED;
}


/*--------------------------------------------------------------------------
|
| Function    - ProcessTestAndXIDFrames
|
| Paramters   - adapHnd   -> An FTK adapter handle.
|               framePtr  -> Pointer to the start of the frame.
|               frameLen  -> The length of the frame.
|               headerLen -> The length of the frame header.
|
| Purpose     - Process LLC Test and XID frames in the same way as IBM
|               adapter hardware.
|
| Returns     - TRUE if the frame was processed or FALSE if not.
|
|-------------------------------------------------------------------------*/

STATIC BOOLEAN
ProcessTestAndXIDFrames(
    ADAPTER_HANDLE  adapHnd, 
    UCHAR          *framePtr,
    UINT            frameLen,
    UINT            headerLen
    )
{
    UINT         llcCmd;     
    UINT         sSAP; 
    NODE_ADDRESS tempNodeAddr;
    BOOLEAN      doneFrame;

    doneFrame = FALSE;

    //
    // We are only interested in frames that are LLC (i.e. frame
    // control byte is 0x40), have a null destination SAP and are
    // commands (i.e. 0x01 bit of the source SAP is clear).
    //

    sSAP = framePtr[headerLen + 1];
    
    if (framePtr[1]         == 0x40 && 
        framePtr[headerLen] == 0x00 &&
        (sSAP & 0x01)       == 0x00)
    {
        llcCmd = framePtr[headerLen + 2] & 0xef;

        //
        // Test frames have an LLC command byte of 0b111x0011.
        //

        if (llcCmd == 0xe3)
        {
            MadgePrint1("Got TEST frame\n");
            
            //
            // We don't need to do anything to a test frame
            // other than send it back.
            //

            doneFrame = TRUE;
        }

        //
        // XID frames have an LLC command byte of 0b101x1111 and
        // a standard IEEE defined XID frame will have 3 data
        // bytes and its first data byte set to 0x81. 
        //

        else if (llcCmd                  == 0xaf          && 
                 frameLen                == headerLen + 6 &&
                 framePtr[headerLen + 3] == 0x81)
        {
            MadgePrint1("Got XID frame\n");

            //
            // Fill in the XID frame data with 0x81 0x01 0x00
            // (Standard XID frame, type 1 only and 0 sized
            // receive window).
            //

            framePtr[headerLen + 4] = 0x01;
            framePtr[headerLen + 5] = 0x00;

            doneFrame = TRUE;
        }

        //
        // If we've had a TEST or a XID frame then doneFrame will
        // be TRUE and we should send a frame back.
        //

        if (doneFrame)
        {
            //
            // Flip the direction bit in the source routing 
            // control word and switch the source routing flag 
            // from the source to destination address.
            //

            if ((framePtr[8] & 0x80) != 0)
            {                                    
                framePtr[14] &= 0x1f;  // Clear broadcast bits.
                framePtr[15] ^= 0x80;  // Flip direction bit.
                framePtr[8]  &= 0x7f;  // Clear source routing bit.
                framePtr[2]  |= 0x80;  // Set source routing bit.
            }

            //
            // Swap the node addresses around.
            //

            tempNodeAddr                     = *((NODE_ADDRESS *) &framePtr[2]);
            *((NODE_ADDRESS *) &framePtr[2]) = *((NODE_ADDRESS *) &framePtr[8]);
            *((NODE_ADDRESS *) &framePtr[8]) = tempNodeAddr;

            //
            // Swap the SAPs around and set the response bit in the 
            // new source SAP.
            //

            framePtr[headerLen + 1] = 0x01;
            framePtr[headerLen]     = sSAP;
            framePtr[0]             = 0x10;

            //
            // And now send the frame.
            //

            rxtx_transmit_frame(
                adapHnd, 
                (DWORD) framePtr,
                (WORD) frameLen,
                FALSE
                );
        }
    }

    return doneFrame;
}


/*--------------------------------------------------------------------------
|
| Function    - MPSafeReadRxStatus
|
| Paramters   - ptr -> Pointer to an MPSAFE_INFO structure.
|
| Purpose     - Read the status and length of the current rx slot. This
|               function is called via NdisSynchronizeWithInterrupt when
|               in PIO mode so that we don't get SIF register contention
|               on a multiprocessor.
|
| Returns     - Nothing.
|
--------------------------------------------------------------------------*/

STATIC BOOLEAN
MPSafeReadRxStatus(PVOID ptr)
{
    MPSAFE_INFO * info = (MPSAFE_INFO *) ptr;

    sys_outsw( 
        info->adapter_handle,
        info->adapter->sif_adr,
        (WORD) (card_t) &(info->rx_slot_ptr)->buffer_len
        );

    info->result1 = sys_insw( 
                        info->adapter_handle,
                        info->adapter->sif_dat
                        );

    sys_outsw(
        info->adapter_handle,
        info->adapter->sif_adr,
        (WORD) (card_t) &(info->rx_slot_ptr)->rx_status
        );

    info->result2 = sys_insw(
                        info->adapter_handle, 
                        info->adapter->sif_dat
                        );

    return FALSE;
}

/*--------------------------------------------------------------------------
|
| Function    - MPSafeFreeRxSlot
|
| Paramters   - ptr -> Pointer to an MPSAFE_INFO structure.
|
| Purpose     - Free an rx slot. This
|               function is called via NdisSynchronizeWithInterrupt when
|               in PIO mode so that we don't get SIF register contention
|               on a multiprocessor.
|
| Returns     - Nothing.
|
--------------------------------------------------------------------------*/

STATIC BOOLEAN
MPSafeFreeRxSlot(PVOID ptr)
{
    MPSAFE_INFO * info = (MPSAFE_INFO *) ptr;

    sys_outsw(
        info->adapter_handle,
        info->adapter->sif_adr,
        (WORD) (card_t) &(info->rx_slot_ptr)->buffer_len
        );

    sys_outsw( 
        info->adapter_handle,
        info->adapter->sif_dat, 
        (WORD) 0x0000
        );

    return FALSE;
}


/***************************************************************************
*
* Function    - rxtx_irq_rx_frame_handler
*
* Parameters  - adapter_handle -> FTK adapter handle.
*               adapter        -> Pointer to an FTK adapter structure.
*
* Purpose     - Called out of the back or our DPR route via 
*               driver_get_outstanding_receive() to process received
*               frames. 
*
*               Note we preserve the value of SIFADR so that the transmit
*               code does not have to worry about it changing under its
*               feet. No we don't because we are called out of a DPR
*               and the wrapper will have grabbed a spin lock so 
*               we can't be executing at the same time as the transmit
*               code.
*                                                                         
* Returns     - Nothing.
*                                                                        
****************************************************************************/

#define PROM_OR_MAC \
    (NDIS_PACKET_TYPE_PROMISCUOUS | NDIS_PACKET_TYPE_MAC_FRAME)

void     
rxtx_irq_rx_frame_handler(
    ADAPTER_HANDLE adapter_handle,
    ADAPTER *      adapter
    )
{
    BYTE *               rx_frame_addr;
    UINT                 rx_frame_stat;
    UINT                 rx_frame_length;
    UINT                 slot_count;
    UINT                 active_rx_slot;
    PRX_SLOT_MGMNT       rx_slot_mgmnt;
    PRX_SLOT_CACHE       rx_slot_cache;
    RX_SLOT          * * rx_slot_array;
    RX_SLOT            * rx_slot_ptr;
    UINT                 rx_slots;
    PMADGE_ADAPTER       ndisAdap;
    UINT                 packet_filter;
    UINT                 header_len;
    BOOLEAN              done_frame;
    BOOLEAN              ignore_frame;
    BOOLEAN              test_and_xid;
    MPSAFE_INFO          info;
    WORD                 sifadr;
    WORD                 sifdat;

    //
    // Pre-calculate some commonly used values.
    //

    rx_slot_array  = adapter->rx_slot_array;
    rx_slot_mgmnt  = (PRX_SLOT_MGMNT) adapter->rx_slot_mgmnt;
    active_rx_slot = rx_slot_mgmnt->active_rx_slot;
    rx_slot_cache  = rx_slot_mgmnt->rx_slot_cache;
    rx_slots       = adapter->init_block->fastmac_parms.rx_slots;
    ndisAdap       = PMADGE_ADAPTER_FROM_ADAPTER_HANDLE(adapter_handle);
    packet_filter  = ndisAdap->CurrentPacketFilter;
    test_and_xid   = ndisAdap->TestAndXIDEnabled;
    done_frame     = FALSE;
    sifadr         = adapter->sif_adr;
    sifdat         = adapter->sif_dat;

    //
    // If we're doing multiprocessor safe PIO then we need to set up
    // the info structure.
    //

    if (ndisAdap->UseMPSafePIO)
    {
        info.adapter_handle = adapter_handle;
        info.adapter        = adapter;
    }

    //
    // Now read the length and status fields of the current receive slot. 
    // If we are doing multiprocessor safe PIO then we must do the DIO via 
    // an ISR synchronised function.
    //

    rx_slot_ptr = rx_slot_array[active_rx_slot];

    if (ndisAdap->UseMPSafePIO)
    {
        info.rx_slot_ptr = rx_slot_ptr;

        NdisMSynchronizeWithInterrupt(
            &ndisAdap->Interrupt,
            MPSafeReadRxStatus,
            &info
            );

        rx_frame_length = info.result1;
        rx_frame_stat   = info.result2;
    }
    else
    {
        sys_outsw( 
            adapter_handle,
            sifadr,
            (WORD) (card_t) &rx_slot_ptr->buffer_len
            );
          
        rx_frame_length = sys_insw( 
                              adapter_handle,
                              sifdat
                              );
        sys_outsw(
            adapter_handle,
            sifadr,
            (WORD) (card_t) &rx_slot_ptr->rx_status
            );

        rx_frame_stat = sys_insw(
                            adapter_handle, 
                            sifdat
                            );

    }

    //
    // Try to receive as many frames as possible, but only examine as many 
    // slots as we have, otherwise we might end up going round this loop   
    // forever! If we do stop and there is still a frame to be received, we
    // will be re-interrupted anyway.                                      
    //

    slot_count = 0;

    while (rx_frame_length != 0 && slot_count++ < rx_slots)
    {
        //
        // It is possible that a PCMCIA adapter may have been removed
        // in which case we must not wait forever. If an adapter has
        // been removed we would expect to read 0xffff from any IO
        // location occupied by the adapter. 0xffff is not a valid
        // value for an FMP RX status.
        //

        if (rx_frame_stat == 0xffff)
        {
            MadgePrint1("Rx frame: RX status == 0xffff\n");
            ndisAdap->AdapterRemoved = TRUE;
            return;
        }

        //
        // FastMAC Plus includes the CRC in the frame length.
        //

        rx_frame_length -= 4;

        if ((rx_frame_stat & GOOD_RX_FRAME_MASK) == 0)
        {
            //
            // We have got a good frame here. 
            //

            rx_frame_addr = rx_slot_cache[active_rx_slot].VirtualAddress;

            header_len = (FRAME_IS_SOURCE_ROUTED(rx_frame_addr))
                ? FRAME_HEADER_SIZE + FRAME_SOURCE_ROUTING_BYTES(rx_frame_addr)
                : FRAME_HEADER_SIZE;

            //
            // Check for a frame copied error.
            //

            if ((rx_frame_addr[2] & 0x80) && (rx_frame_stat & 0x80))
            {
                ndisAdap->FrameCopiedErrors++;
            }

            //
            // We may have to behave like the hardware of an IBM adapter
            // and process LLC TEST and XID frames ourselves.
            //

            if (test_and_xid)
            {
                ignore_frame = ProcessTestAndXIDFrames(
                                   adapter_handle,
                                   rx_frame_addr,
                                   rx_frame_length,
                                   header_len
                                   );
            }
            else
            {
                ignore_frame = FALSE;
            }
                
            //
            // If we've got a valid frame then pass it up to the user.
            //

            if (!ignore_frame && 
                ((rx_frame_addr[1] & FRAME_TYPE_MASK) != FRAME_TYPE_MAC ||
                 (packet_filter & PROM_OR_MAC)        != 0))
            {
                //
                // When indicating the frame, we can pass all of it 
                // as lookahead if we want, but we ought to take 
                // account of the current lookahead setting in case it 
                // is less than the frame size. This becomes important in 
                // WFWG, where it is unable to cope with large lookaheads. The 
                // lookahead length used to be : 
                // (UINT) rx_frame_length - header_len    
                //

                NdisMTrIndicateReceive(
                        ndisAdap->UsedInISR.MiniportHandle,
                        (NDIS_HANDLE) (rx_frame_addr + header_len),
                        (PVOID) rx_frame_addr,
                        (UINT) header_len,
                        (PVOID) (rx_frame_addr + header_len),
                        (UINT) MIN(
                            ndisAdap->CurrentLookahead, 
                            (rx_frame_length - header_len)
                            ),
                        (UINT) (rx_frame_length - header_len)
                        );
    
	        //
                // Note that we've given the upper protocol at
                // least one frame.
                //

                done_frame = TRUE;

                ndisAdap->FramesReceived++;

#ifdef OID_MADGE_MONITOR
                //
                // Update the appropriate parts of the monitor structure
                //
                (ndisAdap->MonitorInfo).ReceiveFrames++;
                (ndisAdap->MonitorInfo).ReceiveFrameSize[rx_frame_length/128]++;
                (ndisAdap->MonitorInfo).CurrentFrameSize = rx_frame_length;
                (ndisAdap->MonitorInfo).ReceiveFlag = 1;
#endif
            }
        }

        //
        // Otherwise we have some sort of receive error.
        //

        else
        {
            ndisAdap->FrameReceiveErrors++;
        }

        //
        // Zero the frame length so that FastMAC Plus can reuse the buffer.
        // If we're doing multiprocessor safe PIO then we must do the DIO
        // via an ISR synchronised function.
        //

        if (ndisAdap->UseMPSafePIO)
        {
            info.rx_slot_ptr = rx_slot_ptr;

            NdisMSynchronizeWithInterrupt(
                &ndisAdap->Interrupt,
                MPSafeFreeRxSlot,
                &info
                );
        }
        else
        {
            sys_outsw(
                adapter_handle,
                sifadr,
                (WORD) (card_t) &rx_slot_ptr->buffer_len
                );

            sys_outsw( 
                adapter_handle,
                sifdat,
                0x0000
                );
        }

        //
        // Update the active receive slot pointer.                         
        //

        if (++active_rx_slot == rx_slots)
        {
            active_rx_slot = 0;
        }

        rx_slot_mgmnt->active_rx_slot = active_rx_slot;

        //
        // Now we had better look at the next slot in case another frame
        // has been received.
        //

        rx_slot_ptr = rx_slot_array[active_rx_slot];

        if (ndisAdap->UseMPSafePIO)
        {
            info.rx_slot_ptr = rx_slot_ptr;

            NdisMSynchronizeWithInterrupt(
                &ndisAdap->Interrupt,
                MPSafeReadRxStatus,
                &info
                );

            rx_frame_length = info.result1;
            rx_frame_stat   = info.result2;
        }
        else
        {
            sys_outsw( 
                adapter_handle,
                sifadr,
                (WORD) (card_t) &rx_slot_ptr->buffer_len
                );
          
            rx_frame_length = sys_insw( 
                                  adapter_handle,
                                  sifdat
                                  );
            sys_outsw(
                adapter_handle,
                sifadr,
                (WORD) (card_t) &rx_slot_ptr->rx_status
                );

            rx_frame_stat = sys_insw(
                                adapter_handle, 
                                sifdat
                                );

        }
    }

    //
    // If we've given the upper protocol a frame then call the
    // receive completion routine.
    //

    if (done_frame)
    {
        NdisMTrIndicateReceiveComplete(ndisAdap->UsedInISR.MiniportHandle);
    }
}



/***************************************************************************
*
* Function    - rxtx_abort_txing_frames
*
* Parameters  - adapter_handle -> FTK adapter handle.
*
* Purpose     - Stop sending frames.
*                                                                         
* Returns     - Nothing.
*                                                                        
****************************************************************************/

void
rxtx_abort_txing_frames(ADAPTER_HANDLE adapter_handle)
{
    //
    // Nothing to do here.
    //
}


/***************************************************************************
*
* Function    - rxtx_await_empty_tx_slots
*
* Parameters  - adapter_handle -> FTK adapter handle.
*
* Purpose     - Wait until all of the tx slots are empty.
*                                                                         
* Returns     - Nothing.
*                                                                        
****************************************************************************/

void
rxtx_await_empty_tx_slots(ADAPTER_HANDLE adapter_handle)
{
    ADAPTER            * adapter;
    FASTMAC_INIT_PARMS * fastmac_parms;
    TX_SLOT          * * tx_slot_array;
    UINT                 i;
    UINT                 status;
    PMADGE_ADAPTER       ndisAdap;
    MPSAFE_INFO          info;
    WORD                 sifadr;
    WORD                 sifdat;

    if (!driver_check_adapter(adapter_handle, ADAPTER_RUNNING, SRB_ANY_STATE))
    {
        MadgePrint1("rxtx_await_empty_tx_slots: adapter not running\n");
        return;
    }

    //
    // Pre-calculate some commonly used values.
    //

    adapter             = adapter_record[adapter_handle];
    fastmac_parms       = &adapter->init_block->fastmac_parms;
    tx_slot_array       = adapter->tx_slot_array;
    info.adapter_handle = adapter_handle;
    info.adapter        = adapter;
    ndisAdap            = PMADGE_ADAPTER_FROM_ADAPTER_HANDLE(adapter_handle);
    sifadr              = adapter->sif_adr;
    sifdat              = adapter->sif_dat;

    for (i = 0; i < fastmac_parms->tx_slots; i++)
    {
        do
        {
            //
            // Get the slot status. If we are doing multiprocessor safe
            // PIO then we must do this with an ISR synchronised function.
            //

            if (ndisAdap->UseMPSafePIO)
            {
                info.tx_slot_ptr = tx_slot_array[i];

                NdisMSynchronizeWithInterrupt(
                    &ndisAdap->Interrupt,
                    MPSafeReadTxStatus,
                    &info
                    );

                status = info.result1;
            }
            else
            {
                sys_outsw(
                    adapter_handle,
                    sifadr,
                    (WORD) (card_t) &tx_slot_array[i]->tx_status
                    );

                status = sys_insw(adapter_handle, sifdat);
            }

            //
            // It is possible that a PCMCIA adapter may have been removed
            // in which case we must not wait forever. If an adapter has
            // been removed we would expect to read 0xffff from any IO
            // location occupied by the adapter. 0xffff is not a valid
            // value for an FMP TX status.
            //

            if (status == 0xffff)
            {
                MadgePrint1("Await empty tx: TX status == 0xffff\n");
                return;
            }
        }
        while (status >= 0x8000 || status == 0);
    }
}


/***************************************************************************
*
* Function    - user_completed_srb
*
* Parameters  - adapter_handle             -> FTK adapter handle.
*               srb_completed_successfully -> SRB successful?
*
* Purpose     - Record that an SRB has completed and arrange for our
*               DPR to be scheduled.
*                                                                         
* Returns     - Nothing.
*                                                                        
****************************************************************************/

void
user_completed_srb(
    ADAPTER_HANDLE adapter_handle,
    WBOOLEAN       srb_completed_successfully
    )
{
    PMADGE_ADAPTER ndisAdap;

    ndisAdap = PMADGE_ADAPTER_FROM_ADAPTER_HANDLE(adapter_handle);

    //
    // If we have issued a private SRB then we just clear the 
    // private SRB flag. Otherwise we need to arrange for our
    // DPR to be told about the SRB.
    //

    if (ndisAdap->PrivateSrbInProgress)
    {
        ndisAdap->PrivateSrbInProgress = FALSE;
    }
    else
    {
        ndisAdap->UsedInISR.SrbRequestStatus    = (BOOLEAN) srb_completed_successfully;
        ndisAdap->UsedInISR.SrbRequestCompleted = TRUE;
        ndisAdap->DprRequired                   = TRUE;
    }
}


/***************************************************************************
*
* Function    - user_shedule_receive_process
*
* Parameters  - adapter_handle -> FTK adapter handle.
*
* Purpose     - Arrange for our DPR to be scheduled so that we can deal
*               with received frames.
*                                                                         
* Returns     - Nothing.
*                                                                        
****************************************************************************/


void
user_schedule_receive_process(ADAPTER_HANDLE adapter_handle)
{
    PMADGE_ADAPTER_FROM_ADAPTER_HANDLE(adapter_handle)->DprRequired = TRUE;
}


/***************************************************************************
*
* Function    - user_adapter_removed
*
* Parameters  - adapter_handle -> FTK adapter handle.
*
* Purpose     - Arrange for our DPR to be scheduled so that we can deal
*               with a removed adapter.
*                                                                         
* Returns     - Nothing.
*                                                                        
****************************************************************************/


void
user_adapter_removed(ADAPTER_HANDLE adapter_handle)
{
    PMADGE_ADAPTER_FROM_ADAPTER_HANDLE(adapter_handle)->DprRequired    = TRUE;
    PMADGE_ADAPTER_FROM_ADAPTER_HANDLE(adapter_handle)->AdapterRemoved = TRUE;
}


/***************************************************************************
*
* Function    - user_handle_adapter_check
*
* Parameters  - adapter_handle -> FTK adapter handle.
*
* Purpose     - Called on an adapter check. Not a lot we can do really!
*                                                                         
* Returns     - Nothing.
*                                                                        
****************************************************************************/


void
user_handle_adapter_check(ADAPTER_HANDLE adapter_handle)
{
    MadgePrint1("Adapter Check!!!!\n");
}


//
// Currently we are not supporting transmit modes that require 
// user completion routine.
//

#if 0

/***************************************************************************
*
* Function    - user_transmit_completion
*
* Parameters  - adapter_handle -> FTK adapter handle.
*               identifier     -> NDIS packet handle.
*
* Purpose     - To notify an upper protocol that a transmit has completed.
*
* Returns     - Nothing.
*                                                                        
****************************************************************************/


void
user_transmit_completion(
    ADAPTER_HANDLE adapter_handle,
    DWORD          identifier
    )
{
}

#endif


/***************************************************************************
*
* Function    - rxtx_adapter_removed
*
* Parameters  - adapter_handle -> FTK adapter handle.
*
* Purpose     - Called to tidy up when we find out that the adapter has
*               been removed. All we do is tell the wrapper that we
*               have finished any submitted transmits.
*                                                                         
* Returns     - Nothing.
*                                                                        
****************************************************************************/

void
rxtx_adapter_removed(
    ADAPTER_HANDLE adapter_handle
    )
{
    ADAPTER        * adapter;
    PTX_SLOT_MGMNT   tx_slot_mgmnt;
    UINT             tx_slots;
    PMADGE_ADAPTER   ndisAdap;

    //
    // Pre-calculate some commonly used values.
    //
            
    adapter       = adapter_record[adapter_handle];
    tx_slot_mgmnt = (PTX_SLOT_MGMNT) adapter->tx_slot_mgmnt;
    tx_slots      = adapter->init_block->fastmac_parms.tx_slots;
    ndisAdap      = PMADGE_ADAPTER_FROM_ADAPTER_HANDLE(adapter_handle);

    //
    // Note that the adapter has been removed.
    //

    ndisAdap->AdapterRemoved = TRUE;

    //
    // Iterate around the transmit slots that are in use and 
    // up call to indicate that the transmits are over.
    //

    while (tx_slot_mgmnt->number_tx_in_use > 0)
    {
        //
        // Update the slot usage.
        //

        tx_slot_mgmnt->number_tx_in_use--;

        if (++tx_slot_mgmnt->first_tx_in_use == tx_slots)
        {
            tx_slot_mgmnt->first_tx_in_use = 0;
        }

        //
        // Tell the wrapper that there is a free slot.
        //

        NdisMSendResourcesAvailable(ndisAdap->UsedInISR.MiniportHandle);
    }
}


/******** End of FTK_USER.C ***********************************************/