/
Decode.c
1522 lines (1243 loc) · 46.8 KB
/
Decode.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/** @file
Provides the basic UNID functions.
Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#include "Undi32.h"
//
// Global variables defined in this file
//
UNDI_CALL_TABLE api_table[PXE_OPCODE_LAST_VALID+1] = { \
{PXE_CPBSIZE_NOT_USED,PXE_DBSIZE_NOT_USED,0, (UINT16)(ANY_STATE),UNDI_GetState },\
{(UINT16)(DONT_CHECK),PXE_DBSIZE_NOT_USED,0,(UINT16)(ANY_STATE),UNDI_Start },\
{PXE_CPBSIZE_NOT_USED,PXE_DBSIZE_NOT_USED,0,MUST_BE_STARTED,UNDI_Stop },\
{PXE_CPBSIZE_NOT_USED,sizeof(PXE_DB_GET_INIT_INFO),0,MUST_BE_STARTED, UNDI_GetInitInfo },\
{PXE_CPBSIZE_NOT_USED,sizeof(PXE_DB_GET_CONFIG_INFO),0,MUST_BE_STARTED, UNDI_GetConfigInfo },\
{sizeof(PXE_CPB_INITIALIZE),(UINT16)(DONT_CHECK),(UINT16)(DONT_CHECK),MUST_BE_STARTED,UNDI_Initialize },\
{PXE_CPBSIZE_NOT_USED,PXE_DBSIZE_NOT_USED,(UINT16)(DONT_CHECK), MUST_BE_INITIALIZED,UNDI_Reset },\
{PXE_CPBSIZE_NOT_USED,PXE_DBSIZE_NOT_USED,0, MUST_BE_INITIALIZED,UNDI_Shutdown },\
{PXE_CPBSIZE_NOT_USED,PXE_DBSIZE_NOT_USED,(UINT16)(DONT_CHECK), MUST_BE_INITIALIZED,UNDI_Interrupt },\
{(UINT16)(DONT_CHECK),(UINT16)(DONT_CHECK),(UINT16)(DONT_CHECK), MUST_BE_INITIALIZED, UNDI_RecFilter },\
{(UINT16)(DONT_CHECK),(UINT16)(DONT_CHECK),(UINT16)(DONT_CHECK), MUST_BE_INITIALIZED, UNDI_StnAddr },\
{PXE_CPBSIZE_NOT_USED, (UINT16)(DONT_CHECK), (UINT16)(DONT_CHECK), MUST_BE_INITIALIZED, UNDI_Statistics },\
{sizeof(PXE_CPB_MCAST_IP_TO_MAC),sizeof(PXE_DB_MCAST_IP_TO_MAC), (UINT16)(DONT_CHECK),MUST_BE_INITIALIZED, UNDI_ip2mac },\
{(UINT16)(DONT_CHECK),(UINT16)(DONT_CHECK),(UINT16)(DONT_CHECK), MUST_BE_INITIALIZED, UNDI_NVData },\
{PXE_CPBSIZE_NOT_USED,(UINT16)(DONT_CHECK),(UINT16)(DONT_CHECK), MUST_BE_INITIALIZED, UNDI_Status },\
{(UINT16)(DONT_CHECK),PXE_DBSIZE_NOT_USED,(UINT16)(DONT_CHECK), MUST_BE_INITIALIZED, UNDI_FillHeader },\
{(UINT16)(DONT_CHECK),PXE_DBSIZE_NOT_USED,(UINT16)(DONT_CHECK), MUST_BE_INITIALIZED, UNDI_Transmit },\
{sizeof(PXE_CPB_RECEIVE),sizeof(PXE_DB_RECEIVE),0,MUST_BE_INITIALIZED, UNDI_Receive } \
};
//
// end of global variables
//
/**
This routine determines the operational state of the UNDI. It updates the state flags in the
Command Descriptor Block based on information derived from the AdapterInfo instance data.
To ensure the command has completed successfully, CdbPtr->StatCode will contain the result of
the command execution.
The CdbPtr->StatFlags will contain a STOPPED, STARTED, or INITIALIZED state once the command
has successfully completed.
Keep in mind the AdapterInfo->State is the active state of the adapter (based on software
interrogation), and the CdbPtr->StateFlags is the passed back information that is reflected
to the caller of the UNDI API.
@param CdbPtr Pointer to the command descriptor block.
@param AdapterInfo Pointer to the NIC data structure information which
the UNDI driver is layering on..
@return None
**/
VOID
UNDI_GetState (
IN PXE_CDB *CdbPtr,
IN NIC_DATA_INSTANCE *AdapterInfo
)
{
CdbPtr->StatFlags = (PXE_STATFLAGS) (CdbPtr->StatFlags | AdapterInfo->State);
return ;
}
/**
This routine is used to change the operational state of the UNDI from stopped to started.
It will do this as long as the adapter's state is PXE_STATFLAGS_GET_STATE_STOPPED, otherwise
the CdbPtr->StatFlags will reflect a command failure, and the CdbPtr->StatCode will reflect the
UNDI as having already been started.
This routine is modified to reflect the undi 1.1 specification changes. The
changes in the spec are mainly in the callback routines, the new spec adds
3 more callbacks and a unique id.
Since this UNDI supports both old and new undi specifications,
The NIC's data structure is filled in with the callback routines (depending
on the version) pointed to in the caller's CpbPtr. This seeds the Delay,
Virt2Phys, Block, and Mem_IO for old and new versions and Map_Mem, UnMap_Mem
and Sync_Mem routines and a unique id variable for the new version.
This is the function which an external entity (SNP, O/S, etc) would call
to provide it's I/O abstraction to the UNDI.
It's final action is to change the AdapterInfo->State to PXE_STATFLAGS_GET_STATE_STARTED.
@param CdbPtr Pointer to the command descriptor block.
@param AdapterInfo Pointer to the NIC data structure information which
the UNDI driver is layering on..
@return None
**/
VOID
UNDI_Start (
IN PXE_CDB *CdbPtr,
IN NIC_DATA_INSTANCE *AdapterInfo
)
{
PXE_CPB_START_30 *CpbPtr;
PXE_CPB_START_31 *CpbPtr_31;
//
// check if it is already started.
//
if (AdapterInfo->State != PXE_STATFLAGS_GET_STATE_STOPPED) {
CdbPtr->StatFlags = PXE_STATFLAGS_COMMAND_FAILED;
CdbPtr->StatCode = PXE_STATCODE_ALREADY_STARTED;
return ;
}
if (CdbPtr->CPBsize != sizeof(PXE_CPB_START_30) &&
CdbPtr->CPBsize != sizeof(PXE_CPB_START_31)) {
CdbPtr->StatFlags = PXE_STATFLAGS_COMMAND_FAILED;
CdbPtr->StatCode = PXE_STATCODE_INVALID_CDB;
return ;
}
CpbPtr = (PXE_CPB_START_30 *) (UINTN) (CdbPtr->CPBaddr);
CpbPtr_31 = (PXE_CPB_START_31 *) (UINTN) (CdbPtr->CPBaddr);
if (AdapterInfo->VersionFlag == 0x30) {
AdapterInfo->Delay_30 = (bsptr_30) (UINTN) CpbPtr->Delay;
AdapterInfo->Virt2Phys_30 = (virtphys_30) (UINTN) CpbPtr->Virt2Phys;
AdapterInfo->Block_30 = (block_30) (UINTN) CpbPtr->Block;
//
// patch for old buggy 3.0 code:
// In EFI1.0 undi used to provide the full (absolute) I/O address to the
// i/o calls and SNP used to provide a callback that used GlobalIoFncs and
// everything worked fine! In EFI 1.1, UNDI is not using the full
// i/o or memory address to access the device, The base values for the i/o
// and memory address is abstracted by the device specific PciIoFncs and
// UNDI only uses the offset values. Since UNDI3.0 cannot provide any
// identification to SNP, SNP cannot use nic specific PciIoFncs callback!
//
// To fix this and make undi3.0 work with SNP in EFI1.1 we
// use a TmpMemIo function that is defined in init.c
// This breaks the runtime driver feature of undi, but what to do
// if we have to provide the 3.0 compatibility (including the 3.0 bugs)
//
// This TmpMemIo function also takes a UniqueId parameter
// (as in undi3.1 design) and so initialize the UniqueId as well here
// Note: AdapterInfo->Mem_Io_30 is just filled for consistency with other
// parameters but never used, we only use Mem_Io field in the In/Out routines
// inside e100b.c.
//
AdapterInfo->Mem_Io_30 = (mem_io_30) (UINTN) CpbPtr->Mem_IO;
AdapterInfo->Mem_Io = (mem_io) (UINTN) TmpMemIo;
AdapterInfo->Unique_ID = (UINT64) (UINTN) AdapterInfo;
} else {
AdapterInfo->Delay = (bsptr) (UINTN) CpbPtr_31->Delay;
AdapterInfo->Virt2Phys = (virtphys) (UINTN) CpbPtr_31->Virt2Phys;
AdapterInfo->Block = (block) (UINTN) CpbPtr_31->Block;
AdapterInfo->Mem_Io = (mem_io) (UINTN) CpbPtr_31->Mem_IO;
AdapterInfo->Map_Mem = (map_mem) (UINTN) CpbPtr_31->Map_Mem;
AdapterInfo->UnMap_Mem = (unmap_mem) (UINTN) CpbPtr_31->UnMap_Mem;
AdapterInfo->Sync_Mem = (sync_mem) (UINTN) CpbPtr_31->Sync_Mem;
AdapterInfo->Unique_ID = CpbPtr_31->Unique_ID;
}
AdapterInfo->State = PXE_STATFLAGS_GET_STATE_STARTED;
return ;
}
/**
This routine is used to change the operational state of the UNDI from started to stopped.
It will not do this if the adapter's state is PXE_STATFLAGS_GET_STATE_INITIALIZED, otherwise
the CdbPtr->StatFlags will reflect a command failure, and the CdbPtr->StatCode will reflect the
UNDI as having already not been shut down.
The NIC's data structure will have the Delay, Virt2Phys, and Block, pointers zero'd out..
It's final action is to change the AdapterInfo->State to PXE_STATFLAGS_GET_STATE_STOPPED.
@param CdbPtr Pointer to the command descriptor block.
@param AdapterInfo Pointer to the NIC data structure information which
the UNDI driver is layering on..
@return None
**/
VOID
UNDI_Stop (
IN PXE_CDB *CdbPtr,
IN NIC_DATA_INSTANCE *AdapterInfo
)
{
if (AdapterInfo->State == PXE_STATFLAGS_GET_STATE_INITIALIZED) {
CdbPtr->StatFlags = PXE_STATFLAGS_COMMAND_FAILED;
CdbPtr->StatCode = PXE_STATCODE_NOT_SHUTDOWN;
return ;
}
AdapterInfo->Delay_30 = 0;
AdapterInfo->Virt2Phys_30 = 0;
AdapterInfo->Block_30 = 0;
AdapterInfo->Delay = 0;
AdapterInfo->Virt2Phys = 0;
AdapterInfo->Block = 0;
AdapterInfo->Map_Mem = 0;
AdapterInfo->UnMap_Mem = 0;
AdapterInfo->Sync_Mem = 0;
AdapterInfo->State = PXE_STATFLAGS_GET_STATE_STOPPED;
return ;
}
/**
This routine is used to retrieve the initialization information that is needed by drivers and
applications to initialize the UNDI. This will fill in data in the Data Block structure that is
pointed to by the caller's CdbPtr->DBaddr. The fields filled in are as follows:
MemoryRequired, FrameDataLen, LinkSpeeds[0-3], NvCount, NvWidth, MediaHeaderLen, HWaddrLen,
MCastFilterCnt, TxBufCnt, TxBufSize, RxBufCnt, RxBufSize, IFtype, Duplex, and LoopBack.
In addition, the CdbPtr->StatFlags ORs in that this NIC supports cable detection. (APRIORI knowledge)
@param CdbPtr Pointer to the command descriptor block.
@param AdapterInfo Pointer to the NIC data structure information which
the UNDI driver is layering on..
@return None
**/
VOID
UNDI_GetInitInfo (
IN PXE_CDB *CdbPtr,
IN NIC_DATA_INSTANCE *AdapterInfo
)
{
PXE_DB_GET_INIT_INFO *DbPtr;
DbPtr = (PXE_DB_GET_INIT_INFO *) (UINTN) (CdbPtr->DBaddr);
DbPtr->MemoryRequired = MEMORY_NEEDED;
DbPtr->FrameDataLen = PXE_MAX_TXRX_UNIT_ETHER;
DbPtr->LinkSpeeds[0] = 10;
DbPtr->LinkSpeeds[1] = 100;
DbPtr->LinkSpeeds[2] = DbPtr->LinkSpeeds[3] = 0;
DbPtr->NvCount = MAX_EEPROM_LEN;
DbPtr->NvWidth = 4;
DbPtr->MediaHeaderLen = PXE_MAC_HEADER_LEN_ETHER;
DbPtr->HWaddrLen = PXE_HWADDR_LEN_ETHER;
DbPtr->MCastFilterCnt = MAX_MCAST_ADDRESS_CNT;
DbPtr->TxBufCnt = TX_BUFFER_COUNT;
DbPtr->TxBufSize = (UINT16) sizeof (TxCB);
DbPtr->RxBufCnt = RX_BUFFER_COUNT;
DbPtr->RxBufSize = (UINT16) sizeof (RxFD);
DbPtr->IFtype = PXE_IFTYPE_ETHERNET;
DbPtr->SupportedDuplexModes = PXE_DUPLEX_ENABLE_FULL_SUPPORTED |
PXE_DUPLEX_FORCE_FULL_SUPPORTED;
DbPtr->SupportedLoopBackModes = PXE_LOOPBACK_INTERNAL_SUPPORTED |
PXE_LOOPBACK_EXTERNAL_SUPPORTED;
CdbPtr->StatFlags |= (PXE_STATFLAGS_CABLE_DETECT_SUPPORTED |
PXE_STATFLAGS_GET_STATUS_NO_MEDIA_SUPPORTED);
return ;
}
/**
This routine is used to retrieve the configuration information about the NIC being controlled by
this driver. This will fill in data in the Data Block structure that is pointed to by the caller's CdbPtr->DBaddr.
The fields filled in are as follows:
DbPtr->pci.BusType, DbPtr->pci.Bus, DbPtr->pci.Device, and DbPtr->pci.
In addition, the DbPtr->pci.Config.Dword[0-63] grabs a copy of this NIC's PCI configuration space.
@param CdbPtr Pointer to the command descriptor block.
@param AdapterInfo Pointer to the NIC data structure information which
the UNDI driver is layering on..
@return None
**/
VOID
UNDI_GetConfigInfo (
IN PXE_CDB *CdbPtr,
IN NIC_DATA_INSTANCE *AdapterInfo
)
{
UINT16 Index;
PXE_DB_GET_CONFIG_INFO *DbPtr;
DbPtr = (PXE_DB_GET_CONFIG_INFO *) (UINTN) (CdbPtr->DBaddr);
DbPtr->pci.BusType = PXE_BUSTYPE_PCI;
DbPtr->pci.Bus = AdapterInfo->Bus;
DbPtr->pci.Device = AdapterInfo->Device;
DbPtr->pci.Function = AdapterInfo->Function;
for (Index = 0; Index < MAX_PCI_CONFIG_LEN; Index++) {
DbPtr->pci.Config.Dword[Index] = AdapterInfo->Config[Index];
}
return ;
}
/**
This routine resets the network adapter and initializes the UNDI using the parameters supplied in
the CPB. This command must be issued before the network adapter can be setup to transmit and
receive packets.
Once the memory requirements of the UNDI are obtained by using the GetInitInfo command, a block
of non-swappable memory may need to be allocated. The address of this memory must be passed to
UNDI during the Initialize in the CPB. This memory is used primarily for transmit and receive buffers.
The fields CableDetect, LinkSpeed, Duplex, LoopBack, MemoryPtr, and MemoryLength are set with information
that was passed in the CPB and the NIC is initialized.
If the NIC initialization fails, the CdbPtr->StatFlags are updated with PXE_STATFLAGS_COMMAND_FAILED
Otherwise, AdapterInfo->State is updated with PXE_STATFLAGS_GET_STATE_INITIALIZED showing the state of
the UNDI is now initialized.
@param CdbPtr Pointer to the command descriptor block.
@param AdapterInfo Pointer to the NIC data structure information which
the UNDI driver is layering on..
@return None
**/
VOID
UNDI_Initialize (
IN PXE_CDB *CdbPtr,
NIC_DATA_INSTANCE *AdapterInfo
)
{
PXE_CPB_INITIALIZE *CpbPtr;
if ((CdbPtr->OpFlags != PXE_OPFLAGS_INITIALIZE_DETECT_CABLE) &&
(CdbPtr->OpFlags != PXE_OPFLAGS_INITIALIZE_DO_NOT_DETECT_CABLE)) {
CdbPtr->StatFlags = PXE_STATFLAGS_COMMAND_FAILED;
CdbPtr->StatCode = PXE_STATCODE_INVALID_CDB;
return ;
}
//
// check if it is already initialized
//
if (AdapterInfo->State == PXE_STATFLAGS_GET_STATE_INITIALIZED) {
CdbPtr->StatFlags = PXE_STATFLAGS_COMMAND_FAILED;
CdbPtr->StatCode = PXE_STATCODE_ALREADY_INITIALIZED;
return ;
}
CpbPtr = (PXE_CPB_INITIALIZE *) (UINTN) CdbPtr->CPBaddr;
if (CpbPtr->MemoryLength < (UINT32) MEMORY_NEEDED) {
CdbPtr->StatFlags = PXE_STATFLAGS_COMMAND_FAILED;
CdbPtr->StatCode = PXE_STATCODE_INVALID_CPB;
return ;
}
//
// default behaviour is to detect the cable, if the 3rd param is 1,
// do not do that
//
AdapterInfo->CableDetect = (UINT8) ((CdbPtr->OpFlags == (UINT16) PXE_OPFLAGS_INITIALIZE_DO_NOT_DETECT_CABLE) ? (UINT8) 0 : (UINT8) 1);
AdapterInfo->LinkSpeedReq = (UINT16) CpbPtr->LinkSpeed;
AdapterInfo->DuplexReq = CpbPtr->DuplexMode;
AdapterInfo->LoopBack = CpbPtr->LoopBackMode;
AdapterInfo->MemoryPtr = CpbPtr->MemoryAddr;
AdapterInfo->MemoryLength = CpbPtr->MemoryLength;
CdbPtr->StatCode = (PXE_STATCODE) E100bInit (AdapterInfo);
if (CdbPtr->StatCode != PXE_STATCODE_SUCCESS) {
CdbPtr->StatFlags = PXE_STATFLAGS_COMMAND_FAILED;
} else {
AdapterInfo->State = PXE_STATFLAGS_GET_STATE_INITIALIZED;
}
return ;
}
/**
This routine resets the network adapter and initializes the UNDI using the parameters supplied in
the CPB. The transmit and receive queues are emptied and any pending interrupts are cleared.
If the NIC reset fails, the CdbPtr->StatFlags are updated with PXE_STATFLAGS_COMMAND_FAILED
@param CdbPtr Pointer to the command descriptor block.
@param AdapterInfo Pointer to the NIC data structure information which
the UNDI driver is layering on..
@return None
**/
VOID
UNDI_Reset (
IN PXE_CDB *CdbPtr,
IN NIC_DATA_INSTANCE *AdapterInfo
)
{
if (CdbPtr->OpFlags != PXE_OPFLAGS_NOT_USED &&
CdbPtr->OpFlags != PXE_OPFLAGS_RESET_DISABLE_INTERRUPTS &&
CdbPtr->OpFlags != PXE_OPFLAGS_RESET_DISABLE_FILTERS ) {
CdbPtr->StatFlags = PXE_STATFLAGS_COMMAND_FAILED;
CdbPtr->StatCode = PXE_STATCODE_INVALID_CDB;
return ;
}
CdbPtr->StatCode = (UINT16) E100bReset (AdapterInfo, CdbPtr->OpFlags);
if (CdbPtr->StatCode != PXE_STATCODE_SUCCESS) {
CdbPtr->StatFlags = PXE_STATFLAGS_COMMAND_FAILED;
}
}
/**
This routine resets the network adapter and leaves it in a safe state for another driver to
initialize. Any pending transmits or receives are lost. Receive filters and external
interrupt enables are disabled. Once the UNDI has been shutdown, it can then be stopped
or initialized again.
If the NIC reset fails, the CdbPtr->StatFlags are updated with PXE_STATFLAGS_COMMAND_FAILED
Otherwise, AdapterInfo->State is updated with PXE_STATFLAGS_GET_STATE_STARTED showing the state of
the NIC as being started.
@param CdbPtr Pointer to the command descriptor block.
@param AdapterInfo Pointer to the NIC data structure information which
the UNDI driver is layering on..
@return None
**/
VOID
UNDI_Shutdown (
IN PXE_CDB *CdbPtr,
IN NIC_DATA_INSTANCE *AdapterInfo
)
{
//
// do the shutdown stuff here
//
CdbPtr->StatCode = (UINT16) E100bShutdown (AdapterInfo);
if (CdbPtr->StatCode != PXE_STATCODE_SUCCESS) {
CdbPtr->StatFlags = PXE_STATFLAGS_COMMAND_FAILED;
} else {
AdapterInfo->State = PXE_STATFLAGS_GET_STATE_STARTED;
}
return ;
}
/**
This routine can be used to read and/or change the current external interrupt enable
settings. Disabling an external interrupt enable prevents and external (hardware)
interrupt from being signaled by the network device. Internally the interrupt events
can still be polled by using the UNDI_GetState command.
The resulting information on the interrupt state will be passed back in the CdbPtr->StatFlags.
@param CdbPtr Pointer to the command descriptor block.
@param AdapterInfo Pointer to the NIC data structure information which
the UNDI driver is layering on..
@return None
**/
VOID
UNDI_Interrupt (
IN PXE_CDB *CdbPtr,
IN NIC_DATA_INSTANCE *AdapterInfo
)
{
UINT8 IntMask;
IntMask = (UINT8)(UINTN)(CdbPtr->OpFlags & (PXE_OPFLAGS_INTERRUPT_RECEIVE |
PXE_OPFLAGS_INTERRUPT_TRANSMIT |
PXE_OPFLAGS_INTERRUPT_COMMAND |
PXE_OPFLAGS_INTERRUPT_SOFTWARE));
switch (CdbPtr->OpFlags & PXE_OPFLAGS_INTERRUPT_OPMASK) {
case PXE_OPFLAGS_INTERRUPT_READ:
break;
case PXE_OPFLAGS_INTERRUPT_ENABLE:
if (IntMask == 0) {
CdbPtr->StatFlags = PXE_STATFLAGS_COMMAND_FAILED;
CdbPtr->StatCode = PXE_STATCODE_INVALID_CDB;
return ;
}
AdapterInfo->int_mask = IntMask;
E100bSetInterruptState (AdapterInfo);
break;
case PXE_OPFLAGS_INTERRUPT_DISABLE:
if (IntMask != 0) {
AdapterInfo->int_mask = (UINT16) (AdapterInfo->int_mask & ~(IntMask));
E100bSetInterruptState (AdapterInfo);
break;
}
//
// else fall thru.
//
default:
CdbPtr->StatFlags = PXE_STATFLAGS_COMMAND_FAILED;
CdbPtr->StatCode = PXE_STATCODE_INVALID_CDB;
return ;
}
if ((AdapterInfo->int_mask & PXE_OPFLAGS_INTERRUPT_RECEIVE) != 0) {
CdbPtr->StatFlags |= PXE_STATFLAGS_INTERRUPT_RECEIVE;
}
if ((AdapterInfo->int_mask & PXE_OPFLAGS_INTERRUPT_TRANSMIT) != 0) {
CdbPtr->StatFlags |= PXE_STATFLAGS_INTERRUPT_TRANSMIT;
}
if ((AdapterInfo->int_mask & PXE_OPFLAGS_INTERRUPT_COMMAND) != 0) {
CdbPtr->StatFlags |= PXE_STATFLAGS_INTERRUPT_COMMAND;
}
return ;
}
/**
This routine is used to read and change receive filters and, if supported, read
and change multicast MAC address filter list.
@param CdbPtr Pointer to the command descriptor block.
@param AdapterInfo Pointer to the NIC data structure information which
the UNDI driver is layering on..
@return None
**/
VOID
UNDI_RecFilter (
IN PXE_CDB *CdbPtr,
IN NIC_DATA_INSTANCE *AdapterInfo
)
{
UINT16 NewFilter;
UINT16 OpFlags;
PXE_DB_RECEIVE_FILTERS *DbPtr;
UINT8 *MacAddr;
UINTN MacCount;
UINT16 Index;
UINT16 copy_len;
UINT8 *ptr1;
UINT8 *ptr2;
BOOLEAN InvalidMacAddr;
OpFlags = CdbPtr->OpFlags;
NewFilter = (UINT16) (OpFlags & 0x1F);
switch (OpFlags & PXE_OPFLAGS_RECEIVE_FILTER_OPMASK) {
case PXE_OPFLAGS_RECEIVE_FILTER_READ:
//
// not expecting a cpb, not expecting any filter bits
//
if ((NewFilter != 0) || (CdbPtr->CPBsize != 0)) {
goto BadCdb;
}
if ((NewFilter & PXE_OPFLAGS_RECEIVE_FILTER_RESET_MCAST_LIST) == 0) {
goto JustRead;
}
NewFilter = (UINT16) (NewFilter | AdapterInfo->Rx_Filter);
//
// all other flags are ignored except mcast_reset
//
break;
case PXE_OPFLAGS_RECEIVE_FILTER_ENABLE:
//
// there should be atleast one other filter bit set.
//
if (NewFilter == 0) {
//
// nothing to enable
//
goto BadCdb;
}
if (CdbPtr->CPBsize != 0) {
//
// this must be a multicast address list!
// don't accept the list unless selective_mcast is set
// don't accept confusing mcast settings with this
//
if (((NewFilter & PXE_OPFLAGS_RECEIVE_FILTER_FILTERED_MULTICAST) == 0) ||
((NewFilter & PXE_OPFLAGS_RECEIVE_FILTER_RESET_MCAST_LIST) != 0) ||
((NewFilter & PXE_OPFLAGS_RECEIVE_FILTER_ALL_MULTICAST) != 0) ||
((CdbPtr->CPBsize % sizeof (PXE_MAC_ADDR)) != 0) ) {
goto BadCdb;
}
MacAddr = (UINT8 *) ((UINTN) (CdbPtr->CPBaddr));
MacCount = CdbPtr->CPBsize / sizeof (PXE_MAC_ADDR);
//
// The format of Ethernet multicast address for IPv6 is defined in RFC2464,
// for IPv4 is defined in RFC1112. Check whether the address is valid.
//
InvalidMacAddr = FALSE;
for (; MacCount-- != 0; MacAddr += sizeof (PXE_MAC_ADDR)) {
if (MacAddr[0] == 0x01) {
//
// This multicast MAC address is mapped from IPv4 address.
//
if (MacAddr[1] != 0x00 || MacAddr[2] != 0x5E || (MacAddr[3] & 0x80) != 0) {
InvalidMacAddr = TRUE;
}
} else if (MacAddr[0] == 0x33) {
//
// This multicast MAC address is mapped from IPv6 address.
//
if (MacAddr[1] != 0x33) {
InvalidMacAddr = TRUE;
}
} else {
InvalidMacAddr = TRUE;
}
if (InvalidMacAddr) {
CdbPtr->StatFlags = PXE_STATFLAGS_COMMAND_FAILED;
CdbPtr->StatCode = PXE_STATCODE_INVALID_CPB;
return ;
}
}
}
//
// check selective mcast case enable case
//
if ((OpFlags & PXE_OPFLAGS_RECEIVE_FILTER_FILTERED_MULTICAST) != 0) {
if (((OpFlags & PXE_OPFLAGS_RECEIVE_FILTER_RESET_MCAST_LIST) != 0) ||
((OpFlags & PXE_OPFLAGS_RECEIVE_FILTER_ALL_MULTICAST) != 0) ) {
goto BadCdb;
}
//
// if no cpb, make sure we have an old list
//
if ((CdbPtr->CPBsize == 0) && (AdapterInfo->mcast_list.list_len == 0)) {
goto BadCdb;
}
}
//
// if you want to enable anything, you got to have unicast
// and you have what you already enabled!
//
NewFilter = (UINT16) (NewFilter | (PXE_OPFLAGS_RECEIVE_FILTER_UNICAST | AdapterInfo->Rx_Filter));
break;
case PXE_OPFLAGS_RECEIVE_FILTER_DISABLE:
//
// mcast list not expected, i.e. no cpb here!
//
if (CdbPtr->CPBsize != PXE_CPBSIZE_NOT_USED) {
goto BadCdb;
}
NewFilter = (UINT16) ((~(CdbPtr->OpFlags & 0x1F)) & AdapterInfo->Rx_Filter);
break;
default:
goto BadCdb;
}
if ((OpFlags & PXE_OPFLAGS_RECEIVE_FILTER_RESET_MCAST_LIST) != 0) {
AdapterInfo->mcast_list.list_len = 0;
NewFilter &= (~PXE_OPFLAGS_RECEIVE_FILTER_FILTERED_MULTICAST);
}
E100bSetfilter (AdapterInfo, NewFilter, CdbPtr->CPBaddr, CdbPtr->CPBsize);
JustRead:
//
// give the current mcast list
//
if ((CdbPtr->DBsize != 0) && (AdapterInfo->mcast_list.list_len != 0)) {
//
// copy the mc list to db
//
DbPtr = (PXE_DB_RECEIVE_FILTERS *) (UINTN) CdbPtr->DBaddr;
ptr1 = (UINT8 *) (&DbPtr->MCastList[0]);
//
// DbPtr->mc_count = AdapterInfo->mcast_list.list_len;
//
copy_len = (UINT16) (AdapterInfo->mcast_list.list_len * PXE_MAC_LENGTH);
if (copy_len > CdbPtr->DBsize) {
copy_len = CdbPtr->DBsize;
}
ptr2 = (UINT8 *) (&AdapterInfo->mcast_list.mc_list[0]);
for (Index = 0; Index < copy_len; Index++) {
ptr1[Index] = ptr2[Index];
}
}
//
// give the stat flags here
//
if (AdapterInfo->Receive_Started) {
CdbPtr->StatFlags = (PXE_STATFLAGS) (CdbPtr->StatFlags | AdapterInfo->Rx_Filter);
}
return ;
BadCdb:
CdbPtr->StatFlags = PXE_STATFLAGS_COMMAND_FAILED;
CdbPtr->StatCode = PXE_STATCODE_INVALID_CDB;
}
/**
This routine is used to get the current station and broadcast MAC addresses, and to change the
current station MAC address.
@param CdbPtr Pointer to the command descriptor block.
@param AdapterInfo Pointer to the NIC data structure information which
the UNDI driver is layering on..
@return None
**/
VOID
UNDI_StnAddr (
IN PXE_CDB *CdbPtr,
IN NIC_DATA_INSTANCE *AdapterInfo
)
{
PXE_CPB_STATION_ADDRESS *CpbPtr;
PXE_DB_STATION_ADDRESS *DbPtr;
UINT16 Index;
if (CdbPtr->OpFlags == PXE_OPFLAGS_STATION_ADDRESS_RESET) {
//
// configure the permanent address.
// change the AdapterInfo->CurrentNodeAddress field.
//
if (CompareMem (
&AdapterInfo->CurrentNodeAddress[0],
&AdapterInfo->PermNodeAddress[0],
PXE_MAC_LENGTH
) != 0) {
for (Index = 0; Index < PXE_MAC_LENGTH; Index++) {
AdapterInfo->CurrentNodeAddress[Index] = AdapterInfo->PermNodeAddress[Index];
}
E100bSetupIAAddr (AdapterInfo);
}
}
if (CdbPtr->CPBaddr != (UINT64) 0) {
CpbPtr = (PXE_CPB_STATION_ADDRESS *) (UINTN) (CdbPtr->CPBaddr);
//
// configure the new address
//
for (Index = 0; Index < PXE_MAC_LENGTH; Index++) {
AdapterInfo->CurrentNodeAddress[Index] = CpbPtr->StationAddr[Index];
}
E100bSetupIAAddr (AdapterInfo);
}
if (CdbPtr->DBaddr != (UINT64) 0) {
DbPtr = (PXE_DB_STATION_ADDRESS *) (UINTN) (CdbPtr->DBaddr);
//
// fill it with the new values
//
for (Index = 0; Index < PXE_MAC_LENGTH; Index++) {
DbPtr->StationAddr[Index] = AdapterInfo->CurrentNodeAddress[Index];
DbPtr->BroadcastAddr[Index] = AdapterInfo->BroadcastNodeAddress[Index];
DbPtr->PermanentAddr[Index] = AdapterInfo->PermNodeAddress[Index];
}
}
return ;
}
/**
This routine is used to read and clear the NIC traffic statistics. This command is supported only
if the !PXE structure's Implementation flags say so.
Results will be parsed out in the following manner:
CdbPtr->DBaddr.Data[0] R Total Frames (Including frames with errors and dropped frames)
CdbPtr->DBaddr.Data[1] R Good Frames (All frames copied into receive buffer)
CdbPtr->DBaddr.Data[2] R Undersize Frames (Frames below minimum length for media <64 for ethernet)
CdbPtr->DBaddr.Data[4] R Dropped Frames (Frames that were dropped because receive buffers were full)
CdbPtr->DBaddr.Data[8] R CRC Error Frames (Frames with alignment or CRC errors)
CdbPtr->DBaddr.Data[A] T Total Frames (Including frames with errors and dropped frames)
CdbPtr->DBaddr.Data[B] T Good Frames (All frames copied into transmit buffer)
CdbPtr->DBaddr.Data[C] T Undersize Frames (Frames below minimum length for media <64 for ethernet)
CdbPtr->DBaddr.Data[E] T Dropped Frames (Frames that were dropped because of collisions)
CdbPtr->DBaddr.Data[14] T Total Collision Frames (Total collisions on this subnet)
@param CdbPtr Pointer to the command descriptor block.
@param AdapterInfo Pointer to the NIC data structure information which
the UNDI driver is layering on..
@return None
**/
VOID
UNDI_Statistics (
IN PXE_CDB *CdbPtr,
IN NIC_DATA_INSTANCE *AdapterInfo
)
{
if ((CdbPtr->OpFlags &~(PXE_OPFLAGS_STATISTICS_RESET)) != 0) {
CdbPtr->StatFlags = PXE_STATFLAGS_COMMAND_FAILED;
CdbPtr->StatCode = PXE_STATCODE_INVALID_CDB;
return ;
}
if ((CdbPtr->OpFlags & PXE_OPFLAGS_STATISTICS_RESET) != 0) {
//
// Reset the statistics
//
CdbPtr->StatCode = (UINT16) E100bStatistics (AdapterInfo, 0, 0);
} else {
CdbPtr->StatCode = (UINT16) E100bStatistics (AdapterInfo, CdbPtr->DBaddr, CdbPtr->DBsize);
}
return ;
}
/**
This routine is used to translate a multicast IP address to a multicast MAC address.
This results in a MAC address composed of 25 bits of fixed data with the upper 23 bits of the IP
address being appended to it. Results passed back in the equivalent of CdbPtr->DBaddr->MAC[0-5].
@param CdbPtr Pointer to the command descriptor block.
@param AdapterInfo Pointer to the NIC data structure information which
the UNDI driver is layering on..
@return None
**/
VOID
UNDI_ip2mac (
IN PXE_CDB *CdbPtr,
IN NIC_DATA_INSTANCE *AdapterInfo
)
{
PXE_CPB_MCAST_IP_TO_MAC *CpbPtr;
PXE_DB_MCAST_IP_TO_MAC *DbPtr;
UINT8 *TmpPtr;
CpbPtr = (PXE_CPB_MCAST_IP_TO_MAC *) (UINTN) CdbPtr->CPBaddr;
DbPtr = (PXE_DB_MCAST_IP_TO_MAC *) (UINTN) CdbPtr->DBaddr;
if ((CdbPtr->OpFlags & PXE_OPFLAGS_MCAST_IPV6_TO_MAC) != 0) {
//
// for now this is not supported
//
CdbPtr->StatFlags = PXE_STATFLAGS_COMMAND_FAILED;
CdbPtr->StatCode = PXE_STATCODE_UNSUPPORTED;
return ;
}
TmpPtr = (UINT8 *) (&CpbPtr->IP.IPv4);
//
// check if the ip given is a mcast IP
//
if ((TmpPtr[0] & 0xF0) != 0xE0) {
CdbPtr->StatFlags = PXE_STATFLAGS_COMMAND_FAILED;
CdbPtr->StatCode = PXE_STATCODE_INVALID_CPB;
}
//
// take the last 23 bits in IP.
// be very careful. accessing word on a non-word boundary will hang motherboard codenamed Big Sur
// casting the mac array (in the middle) to a UINT32 pointer and accessing
// the UINT32 content hung the system...
//
DbPtr->MAC[0] = 0x01;
DbPtr->MAC[1] = 0x00;
DbPtr->MAC[2] = 0x5e;
DbPtr->MAC[3] = (UINT8) (TmpPtr[1] & 0x7f);
DbPtr->MAC[4] = (UINT8) TmpPtr[2];
DbPtr->MAC[5] = (UINT8) TmpPtr[3];
return ;
}
/**
This routine is used to read and write non-volatile storage on the NIC (if supported). The NVRAM
could be EEPROM, FLASH, or battery backed RAM.
This is an optional function according to the UNDI specification (or will be......)
@param CdbPtr Pointer to the command descriptor block.
@param AdapterInfo Pointer to the NIC data structure information which
the UNDI driver is layering on..
@return None
**/
VOID
UNDI_NVData (
IN PXE_CDB *CdbPtr,
IN NIC_DATA_INSTANCE *AdapterInfo
)
{
PXE_DB_NVDATA *DbPtr;
UINT16 Index;
if ((CdbPtr->OpFlags == PXE_OPFLAGS_NVDATA_READ) != 0) {
if ((CdbPtr->DBsize == PXE_DBSIZE_NOT_USED) != 0) {
CdbPtr->StatFlags = PXE_STATFLAGS_COMMAND_FAILED;
CdbPtr->StatCode = PXE_STATCODE_INVALID_CDB;
return ;
}
DbPtr = (PXE_DB_NVDATA *) (UINTN) CdbPtr->DBaddr;
for (Index = 0; Index < MAX_PCI_CONFIG_LEN; Index++) {
DbPtr->Data.Dword[Index] = AdapterInfo->NVData[Index];
}
} else {
//
// no write for now
//
CdbPtr->StatFlags = PXE_STATFLAGS_COMMAND_FAILED;
CdbPtr->StatCode = PXE_STATCODE_UNSUPPORTED;
}
return ;
}
/**
This routine returns the current interrupt status and/or the transmitted buffer addresses.
If the current interrupt status is returned, pending interrupts will be acknowledged by this
command. Transmitted buffer addresses that are written to the DB are removed from the transmit
buffer queue.
Normally, this command would be polled with interrupts disabled.
The transmit buffers are returned in CdbPtr->DBaddr->TxBufer[0 - NumEntries].
The interrupt status is returned in CdbPtr->StatFlags.
@param CdbPtr Pointer to the command descriptor block.
@param AdapterInfo Pointer to the NIC data structure information which
the UNDI driver is layering on..
@return None
**/
VOID
UNDI_Status (
IN PXE_CDB *CdbPtr,
IN NIC_DATA_INSTANCE *AdapterInfo
)
{
PXE_DB_GET_STATUS *DbPtr;
PXE_DB_GET_STATUS TmpGetStatus;
UINT16 Index;
UINT16 Status;
UINT16 NumEntries;
RxFD *RxPtr;
//
// Fill in temporary GetStatus storage.
//
RxPtr = &AdapterInfo->rx_ring[AdapterInfo->cur_rx_ind];
if ((RxPtr->cb_header.status & RX_COMPLETE) != 0) {
TmpGetStatus.RxFrameLen = RxPtr->ActualCount & 0x3fff;
} else {
TmpGetStatus.RxFrameLen = 0;
}
TmpGetStatus.reserved = 0;