summaryrefslogblamecommitdiffstats
path: root/private/ntos/ndis/sonic/request.c
blob: d17d677913a2da4fae78335abf304e5de2acca1f (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

























































































































































































































































































































































































































































































































































































































































































































































































































































































































                                                                                                    
/*++

Copyright (c) 1990-1992  Microsoft Corporation

Module Name:

    request.c

Abstract:

    This is the cose to handle requests for the National Semiconductor
    SONIC Ethernet controller.  This driver conforms to the NDIS 3.0
    miniport interface.

Author:

    Adam Barr (adamba) 14-Nov-1990

Environment:

    Kernel Mode - Or whatever is the equivalent.

Revision History:


--*/

#include <ndis.h>

#include <sonichrd.h>
#include <sonicsft.h>



//
// This macro determines if the directed address
// filtering in the CAM is actually necessary given
// the current filter.
//

#define CAM_DIRECTED_SIGNIFICANT(_Filter) \
    ((((_Filter) & NDIS_PACKET_TYPE_DIRECTED) && \
    (!((_Filter) & NDIS_PACKET_TYPE_PROMISCUOUS))) ? 1 : 0)


//
// This macro determines if the multicast filtering in
// the CAM are actually necessary given the current filter.
//

#define CAM_MULTICAST_SIGNIFICANT(_Filter) \
    ((((_Filter) & NDIS_PACKET_TYPE_MULTICAST) && \
    (!((_Filter) & (NDIS_PACKET_TYPE_ALL_MULTICAST | \
                    NDIS_PACKET_TYPE_PROMISCUOUS)))) ? 1 : 0)


STATIC
NDIS_STATUS
ChangeClassDispatch(
    IN PSONIC_ADAPTER Adapter,
    IN UINT NewFilterClasses
    );

STATIC
NDIS_STATUS
ChangeAddressDispatch(
    IN PSONIC_ADAPTER Adapter,
    IN UINT AddressCount,
    IN CHAR Addresses[][ETH_LENGTH_OF_ADDRESS]
    );




extern
NDIS_STATUS
SonicQueryInformation(
    IN NDIS_HANDLE MiniportAdapterContext,
    IN NDIS_OID Oid,
    IN PVOID InformationBuffer,
    IN ULONG InformationBufferLength,
    OUT PULONG BytesWritten,
    OUT PULONG BytesNeeded
    )

/*++

Routine Description:

    SonicQueryInformation handles a query operation for a
    single OID.

Arguments:

    MiniportAdapterContext - Context registered with the wrapper, really
        a pointer to the adapter.

    Oid - The OID of the query.

    InformationBuffer - Holds the result of the query.

    InformationBufferLength - The length of InformationBuffer.

    BytesWritten - If the call is successful, returns the number
        of bytes written to InformationBuffer.

    BytesNeeded - If there is not enough room in InformationBuffer
        to satisfy the OID, returns the amount of storage needed.

Return Value:

    NDIS_STATUS_SUCCESS
    NDIS_STATUS_PENDING
    NDIS_STATUS_INVALID_LENGTH
    NDIS_STATUS_INVALID_OID

--*/

{
    PSONIC_ADAPTER Adapter = PSONIC_ADAPTER_FROM_CONTEXT_HANDLE(MiniportAdapterContext);
    INT i;
    INT SupportedOids;
    NDIS_OID MaskOid;
    PVOID SourceBuffer;
    ULONG SourceBufferLength;
    ULONG GenericUlong;
    USHORT GenericUshort;
    UCHAR VendorId[4];
#ifdef SONIC_EISA
    static const UCHAR EisaDescriptor[] = "SONIC EISA Bus Master Ethernet Adapter (DP83932EB-EISA)";
#endif
#ifdef SONIC_INTERNAL
    static const UCHAR InternalDescriptor[] = "MIPS R4000 on-board network controller";
#endif

    static const NDIS_OID SonicSupportedOids[] = {
        OID_GEN_SUPPORTED_LIST,
        OID_GEN_HARDWARE_STATUS,
        OID_GEN_MEDIA_SUPPORTED,
        OID_GEN_MEDIA_IN_USE,
        OID_GEN_MAXIMUM_LOOKAHEAD,
        OID_GEN_MAXIMUM_FRAME_SIZE,
        OID_GEN_MAXIMUM_TOTAL_SIZE,
        OID_GEN_MAC_OPTIONS,
        OID_GEN_PROTOCOL_OPTIONS,
        OID_GEN_LINK_SPEED,
        OID_GEN_TRANSMIT_BUFFER_SPACE,
        OID_GEN_RECEIVE_BUFFER_SPACE,
        OID_GEN_TRANSMIT_BLOCK_SIZE,
        OID_GEN_RECEIVE_BLOCK_SIZE,
        OID_GEN_VENDOR_ID,
        OID_GEN_VENDOR_DESCRIPTION,
        OID_GEN_DRIVER_VERSION,
        OID_GEN_CURRENT_PACKET_FILTER,
        OID_GEN_CURRENT_LOOKAHEAD,
        OID_GEN_XMIT_OK,
        OID_GEN_RCV_OK,
        OID_GEN_XMIT_ERROR,
        OID_GEN_RCV_ERROR,
        OID_GEN_RCV_NO_BUFFER,
        OID_GEN_DIRECTED_BYTES_XMIT,
        OID_GEN_DIRECTED_FRAMES_XMIT,
        OID_GEN_MULTICAST_BYTES_XMIT,
        OID_GEN_MULTICAST_FRAMES_XMIT,
        OID_GEN_BROADCAST_BYTES_XMIT,
        OID_GEN_BROADCAST_FRAMES_XMIT,
        OID_GEN_DIRECTED_BYTES_RCV,
        OID_GEN_DIRECTED_FRAMES_RCV,
        OID_GEN_MULTICAST_BYTES_RCV,
        OID_GEN_MULTICAST_FRAMES_RCV,
        OID_GEN_BROADCAST_BYTES_RCV,
        OID_GEN_BROADCAST_FRAMES_RCV,
        OID_GEN_RCV_CRC_ERROR,
        OID_GEN_TRANSMIT_QUEUE_LENGTH,
        OID_802_3_PERMANENT_ADDRESS,
        OID_802_3_CURRENT_ADDRESS,
        OID_802_3_MULTICAST_LIST,
        OID_802_3_MAXIMUM_LIST_SIZE,
        OID_802_3_RCV_ERROR_ALIGNMENT,
        OID_802_3_XMIT_ONE_COLLISION,
        OID_802_3_XMIT_MORE_COLLISIONS,
        OID_802_3_XMIT_DEFERRED,
        OID_802_3_XMIT_MAX_COLLISIONS,
        OID_802_3_RCV_OVERRUN,
        OID_802_3_XMIT_UNDERRUN,
        OID_802_3_XMIT_HEARTBEAT_FAILURE,
        OID_802_3_XMIT_TIMES_CRS_LOST,
        OID_802_3_XMIT_LATE_COLLISIONS
        };

    //
    // Check that the OID is valid.
    //

    SupportedOids = sizeof(SonicSupportedOids)/sizeof(ULONG);

    for (i=0; i<SupportedOids; i++) {
        if (Oid == SonicSupportedOids[i]) {
            break;
        }
    }

    if (i == SupportedOids) {
        *BytesWritten = 0;
        return NDIS_STATUS_INVALID_OID;
    }

    //
    // Initialize these once, since this is the majority
    // of cases.
    //

    SourceBuffer = &GenericUlong;
    SourceBufferLength = sizeof(ULONG);

    switch (Oid & OID_TYPE_MASK) {

    case OID_TYPE_GENERAL_OPERATIONAL:

        switch (Oid) {

        case OID_GEN_MAC_OPTIONS:

            GenericUlong = (ULONG)(NDIS_MAC_OPTION_TRANSFERS_NOT_PEND   |
                                   NDIS_MAC_OPTION_COPY_LOOKAHEAD_DATA  |
                                   NDIS_MAC_OPTION_RECEIVE_SERIALIZED |
                                   NDIS_MAC_OPTION_NO_LOOPBACK
                                  );

            break;

        case OID_GEN_SUPPORTED_LIST:

            SourceBuffer = (PVOID)SonicSupportedOids;
            SourceBufferLength = SupportedOids * sizeof(ULONG);
            break;

        case OID_GEN_HARDWARE_STATUS:

            GenericUlong = NdisHardwareStatusReady;
            break;

        case OID_GEN_MEDIA_SUPPORTED:

            GenericUlong = NdisMedium802_3;
            break;

        case OID_GEN_MEDIA_IN_USE:

            GenericUlong = NdisMedium802_3;
            break;

        case OID_GEN_MAXIMUM_LOOKAHEAD:

            GenericUlong = (SONIC_INDICATE_MAXIMUM-14 < SONIC_LOOPBACK_MAXIMUM) ?
                            SONIC_INDICATE_MAXIMUM-14 : SONIC_LOOPBACK_MAXIMUM;
            break;

        case OID_GEN_MAXIMUM_FRAME_SIZE:

            GenericUlong = 1500;
            break;

        case OID_GEN_MAXIMUM_TOTAL_SIZE:

            GenericUlong = 1514;
            break;

        case OID_GEN_LINK_SPEED:

            GenericUlong = 100000;    // 10 Mbps in 100 bps units
            break;

        case OID_GEN_TRANSMIT_BUFFER_SPACE:

            GenericUlong = SONIC_LARGE_BUFFER_SIZE * SONIC_NUMBER_OF_TRANSMIT_DESCRIPTORS;
            break;

        case OID_GEN_RECEIVE_BUFFER_SPACE:

            GenericUlong = SONIC_LARGE_BUFFER_SIZE * SONIC_NUMBER_OF_RECEIVE_DESCRIPTORS;
            break;

        case OID_GEN_TRANSMIT_BLOCK_SIZE:

            GenericUlong = SONIC_LARGE_BUFFER_SIZE;
            break;

        case OID_GEN_RECEIVE_BLOCK_SIZE:

            GenericUlong = SONIC_LARGE_BUFFER_SIZE;
            break;

        case OID_GEN_VENDOR_ID:

            SONIC_MOVE_MEMORY(VendorId, Adapter->PermanentNetworkAddress, 3);
            VendorId[3] = 0x0;
            SourceBuffer = VendorId;
            SourceBufferLength = sizeof(VendorId);
            break;

        case OID_GEN_VENDOR_DESCRIPTION:

            switch (Adapter->AdapterType) {
#ifdef SONIC_EISA
            case SONIC_ADAPTER_TYPE_EISA:
                SourceBuffer = (PVOID)EisaDescriptor;
                SourceBufferLength = sizeof(EisaDescriptor);
                break;
#endif
#ifdef SONIC_INTERNAL
            case SONIC_ADAPTER_TYPE_INTERNAL:
                SourceBuffer = (PVOID)InternalDescriptor;
                SourceBufferLength = sizeof(InternalDescriptor);
                break;
#endif
            default:
                ASSERT(FALSE);
                break;
            }
            break;

        case OID_GEN_DRIVER_VERSION:

            GenericUshort = (SONIC_NDIS_MAJOR_VERSION << 8) + SONIC_NDIS_MINOR_VERSION;
            SourceBuffer = &GenericUshort;
            SourceBufferLength = sizeof(USHORT);
            break;

        case OID_GEN_CURRENT_PACKET_FILTER:

            GenericUlong = Adapter->CurrentPacketFilter;
            break;

        case OID_GEN_CURRENT_LOOKAHEAD:

            GenericUlong = (SONIC_INDICATE_MAXIMUM-14 < SONIC_LOOPBACK_MAXIMUM) ?
                            SONIC_INDICATE_MAXIMUM-14 : SONIC_LOOPBACK_MAXIMUM;
            break;

        default:

            ASSERT(FALSE);
            break;

        }

        break;

    case OID_TYPE_GENERAL_STATISTICS:

        MaskOid = (Oid & OID_INDEX_MASK) - 1;

        switch (Oid & OID_REQUIRED_MASK) {

        case OID_REQUIRED_MANDATORY:

            ASSERT (MaskOid < GM_ARRAY_SIZE);

            if (MaskOid == GM_RECEIVE_NO_BUFFER) {

                //
                // This one is read off the card, update unless our
                // counter is more (which indicates an imminent
                // overflow interrupt, so we don't update).
                //

                USHORT MissedPacket;
                SONIC_READ_PORT(Adapter, SONIC_FRAME_ALIGNMENT_ERROR, &MissedPacket);

                if ((Adapter->GeneralMandatory[GM_RECEIVE_NO_BUFFER] & 0xffff) <
                        MissedPacket) {

                    Adapter->GeneralMandatory[GM_RECEIVE_NO_BUFFER] =
                        (Adapter->GeneralMandatory[GM_RECEIVE_NO_BUFFER] & 0xffff0000) +
                        MissedPacket;

                }
            }

            GenericUlong = Adapter->GeneralMandatory[MaskOid];
            break;

        case OID_REQUIRED_OPTIONAL:

            ASSERT (MaskOid < GO_ARRAY_SIZE);

            if (MaskOid == GO_RECEIVE_CRC) {

                //
                // This one is read off the card, update unless our
                // counter is more (which indicates an imminent
                // overflow interrupt, so we don't update).
                //

                USHORT CrcError;
                SONIC_READ_PORT(Adapter, SONIC_FRAME_ALIGNMENT_ERROR, &CrcError);

                if ((Adapter->GeneralOptional[GO_RECEIVE_CRC - GO_ARRAY_START] & 0xffff) <
                        CrcError) {

                    Adapter->GeneralOptional[GO_RECEIVE_CRC - GO_ARRAY_START] =
                        (Adapter->GeneralOptional[GO_RECEIVE_CRC - GO_ARRAY_START] & 0xffff0000) +
                        CrcError;

                }
            }

            if ((MaskOid / 2) < GO_COUNT_ARRAY_SIZE) {

                if (MaskOid & 0x01) {
                    // Frame count
                    GenericUlong = Adapter->GeneralOptionalFrameCount[MaskOid / 2];
                } else {
                    // Byte count
                    SourceBuffer = &Adapter->GeneralOptionalByteCount[MaskOid / 2];
                    SourceBufferLength = sizeof(LARGE_INTEGER);
                }

            } else {

                GenericUlong = Adapter->GeneralOptional[MaskOid - GO_ARRAY_START];

            }

            break;

        default:

            ASSERT(FALSE);
            break;

        }

        break;

    case OID_TYPE_802_3_OPERATIONAL:

        switch (Oid) {

        case OID_802_3_PERMANENT_ADDRESS:

            SourceBuffer = Adapter->PermanentNetworkAddress;
            SourceBufferLength = 6;
            break;

        case OID_802_3_CURRENT_ADDRESS:

            SourceBuffer = Adapter->CurrentNetworkAddress;
            SourceBufferLength = 6;
            break;

        case OID_802_3_MAXIMUM_LIST_SIZE:

            GenericUlong = SONIC_CAM_ENTRIES - 1;
            break;

        default:

            ASSERT(FALSE);
            break;

        }

        break;

    case OID_TYPE_802_3_STATISTICS:

        MaskOid = (Oid & OID_INDEX_MASK) - 1;

        switch (Oid & OID_REQUIRED_MASK) {

        case OID_REQUIRED_MANDATORY:

            ASSERT (MaskOid < MM_ARRAY_SIZE);

            if (MaskOid == MM_RECEIVE_ERROR_ALIGNMENT) {

                //
                // This one is read off the card, update unless our
                // counter is more (which indicates an imminent
                // overflow interrupt, so we don't update).
                //

                USHORT FaError;
                SONIC_READ_PORT(Adapter, SONIC_FRAME_ALIGNMENT_ERROR, &FaError);

                if ((Adapter->MediaMandatory[MM_RECEIVE_ERROR_ALIGNMENT] & 0xffff) <
                        FaError) {

                    Adapter->MediaMandatory[MM_RECEIVE_ERROR_ALIGNMENT] =
                        (Adapter->MediaMandatory[MM_RECEIVE_ERROR_ALIGNMENT] & 0xffff0000) +
                        FaError;

                }
            }

            GenericUlong = Adapter->MediaMandatory[MaskOid];
            break;

        case OID_REQUIRED_OPTIONAL:

            ASSERT (MaskOid < MO_ARRAY_SIZE);
            GenericUlong = Adapter->MediaOptional[MaskOid];
            break;

        default:

            ASSERT(FALSE);
            break;

        }

        break;

    }

    if (SourceBufferLength > InformationBufferLength) {
        *BytesNeeded = SourceBufferLength;
        return NDIS_STATUS_INVALID_LENGTH;
    }

    SONIC_MOVE_MEMORY (InformationBuffer, SourceBuffer, SourceBufferLength);
    *BytesWritten = SourceBufferLength;

    return NDIS_STATUS_SUCCESS;

}


STATIC
NDIS_STATUS
SonicSetInformation(
    IN NDIS_HANDLE MiniportAdapterContext,
    IN NDIS_OID Oid,
    IN PVOID InformationBuffer,
    IN ULONG InformationBufferLength,
    OUT PULONG BytesRead,
    OUT PULONG BytesNeeded
    )

/*++

Routine Description:

    SonicQueryInformation handles a set operation for a
    single OID.

Arguments:

    MiniportAdapterContext - Context registered with the wrapper, really
        a pointer to the adapter.

    Oid - The OID of the set.

    InformationBuffer - Holds the data to be set.

    InformationBufferLength - The length of InformationBuffer.

    BytesRead - If the call is successful, returns the number
        of bytes read from InformationBuffer.

    BytesNeeded - If there is not enough data in InformationBuffer
        to satisfy the OID, returns the amount of storage needed.

Return Value:

    NDIS_STATUS_SUCCESS
    NDIS_STATUS_PENDING
    NDIS_STATUS_INVALID_LENGTH
    NDIS_STATUS_INVALID_OID

--*/

{

    PSONIC_ADAPTER Adapter = PSONIC_ADAPTER_FROM_CONTEXT_HANDLE(MiniportAdapterContext);
    NDIS_STATUS Status;
    ULONG PacketFilter;

    //
    // Now check for the most common OIDs
    //

    switch (Oid) {

    case OID_802_3_MULTICAST_LIST:

        if (InformationBufferLength % ETH_LENGTH_OF_ADDRESS != 0) {

            //
            // The data must be a multiple of the Ethernet
            // address size.
            //

            return NDIS_STATUS_INVALID_DATA;

        }
#if DBG
            if (SonicDbg) {
                DbgPrint("Processing Change Multicast List request\n");
            }
#endif

        //
        // Now make the change.
        //

        Status = ChangeAddressDispatch(
                      Adapter,
                      InformationBufferLength / ETH_LENGTH_OF_ADDRESS,
                      InformationBuffer
                      );

        *BytesRead = InformationBufferLength;

        return Status;

        break;

    case OID_GEN_CURRENT_PACKET_FILTER:

        if (InformationBufferLength != 4) {

           *BytesNeeded = 4;
           return NDIS_STATUS_INVALID_LENGTH;

        }

#if DBG
            if (SonicDbg) {
                DbgPrint("Processing Change Packet Filter request\n");
            }
#endif

        //
        // Now call the filter package to set the packet filter.
        //

        SONIC_MOVE_MEMORY ((PVOID)&PacketFilter, InformationBuffer, sizeof(ULONG));

        //
        // Verify bits
        //

        if (PacketFilter & (NDIS_PACKET_TYPE_SOURCE_ROUTING |
                            NDIS_PACKET_TYPE_SMT |
                            NDIS_PACKET_TYPE_MAC_FRAME |
                            NDIS_PACKET_TYPE_FUNCTIONAL |
                            NDIS_PACKET_TYPE_ALL_FUNCTIONAL |
                            NDIS_PACKET_TYPE_GROUP
                           )) {

            *BytesRead = 4;
            *BytesNeeded = 0;

            return NDIS_STATUS_NOT_SUPPORTED;

        }

        Status = ChangeClassDispatch(
                    Adapter,
                    PacketFilter
                    );

        *BytesRead = 4;
        return Status;

        break;

    case OID_GEN_CURRENT_LOOKAHEAD:

        //
        // No need to record requested lookahead length since we
        // always indicate the whole packet.
        //

        *BytesRead = 4;
        return NDIS_STATUS_SUCCESS;
        break;

    default:

        return NDIS_STATUS_INVALID_OID;
        break;

    }

}

STATIC
NDIS_STATUS
ChangeClassDispatch(
    IN PSONIC_ADAPTER Adapter,
    IN UINT NewFilterClasses
    )

/*++

Routine Description:

    Modifies the Receive Control Register and Cam Enable registers,
    then re-loads the CAM if necessary.

Arguments:

    Adapter - The adapter.

    NewFilterClasses - New set of filters.

Return Value:

    NDIS_STATUS_PENDING - if the CAM was reloaded.
    NDIS_STATUS_SUCCESS - otherwise.

--*/

{
    //
    // The new value for the RCR.
    //
    USHORT NewReceiveControl = SONIC_RCR_DEFAULT_VALUE;

    //
    // First take care of the Receive Control Register.
    //

    if (NewFilterClasses & NDIS_PACKET_TYPE_PROMISCUOUS) {

        NewReceiveControl |= SONIC_RCR_PROMISCUOUS_PHYSICAL |
                             SONIC_RCR_ACCEPT_BROADCAST |
                             SONIC_RCR_ACCEPT_ALL_MULTICAST;

    } else {

        if (NewFilterClasses & NDIS_PACKET_TYPE_ALL_MULTICAST) {

            NewReceiveControl |= SONIC_RCR_ACCEPT_ALL_MULTICAST;

        }

        if (NewFilterClasses & NDIS_PACKET_TYPE_BROADCAST) {

            NewReceiveControl |= SONIC_RCR_ACCEPT_BROADCAST;

        }

    }

    Adapter->ReceiveControlRegister = NewReceiveControl;

    SONIC_WRITE_PORT(Adapter, SONIC_RECEIVE_CONTROL,
            Adapter->ReceiveControlRegister
            );

    if (CAM_DIRECTED_SIGNIFICANT(NewFilterClasses)) {

        Adapter->CamDescriptorArea->CamEnable |= 1;

    } else {

        Adapter->CamDescriptorArea->CamEnable &= ~1;

    }

    if (CAM_MULTICAST_SIGNIFICANT(NewFilterClasses)) {

        Adapter->CamDescriptorArea->CamEnable |=
                                Adapter->MulticastCamEnableBits;

    } else {

        Adapter->CamDescriptorArea->CamEnable &= 1;

    }

    //
    // This will cause a LOAD_CAM interrupt when it is done.
    //

    SonicStartCamReload(Adapter);

    Adapter->CurrentPacketFilter = NewFilterClasses;

    return NDIS_STATUS_PENDING;

}

STATIC
NDIS_STATUS
ChangeAddressDispatch(
    IN PSONIC_ADAPTER Adapter,
    IN UINT AddressCount,
    IN CHAR Addresses[][ETH_LENGTH_OF_ADDRESS]
    )

/*++

Routine Description:

    Modifies the Receive Control Register and Cam Enable registers,
    then re-loads the CAM if necessary.

Arguments:

    Adapter - The adapter.

    AddressCount - The number of addresses in Addresses

    Addresses - The new multicast address list.

Return Value:

    NDIS_STATUS_PENDING - if the CAM was reloaded.
    NDIS_STATUS_SUCCESS - otherwise.

--*/

{

    ULONG EnableBit;
    NDIS_STATUS Status;
    UINT i;

    //
    // The first entry in the CAM is for our address.
    //

    Adapter->MulticastCamEnableBits = 1;
    EnableBit = 1;

    //
    // Loop through, copying the addresses into the CAM.
    //

    for (i=0; i<AddressCount; i++) {

        EnableBit <<= 1;
        Adapter->MulticastCamEnableBits |= EnableBit;

        SONIC_LOAD_CAM_FRAGMENT(
            &Adapter->CamDescriptorArea->CamFragments[i+1],
            i+1,
            Addresses[i]
            );

    }

    Adapter->CamDescriptorAreaSize = AddressCount + 1;

    //
    // Now see if we have to worry about re-loading the
    // CAM also.
    //

    if (CAM_MULTICAST_SIGNIFICANT(Adapter->CurrentPacketFilter)) {

        Adapter->CamDescriptorArea->CamEnable = Adapter->MulticastCamEnableBits;

        //
        // This will cause a LOAD_CAM interrupt when it is done.
        //

        SonicStartCamReload(Adapter);

#if DBG
        if (SonicDbg) {
            DbgPrint("Processing Address request pended\n");
        }
#endif


        Status = NDIS_STATUS_PENDING;

    } else {

#if DBG
        if (SonicDbg) {
            DbgPrint("Processing Address request succeeded\n");
        }
#endif

        Status = NDIS_STATUS_SUCCESS;

    }

    return Status;

}