]> git.proxmox.com Git - mirror_edk2.git/blob - EdkModulePkg/Bus/Pci/Undi/RuntimeDxe/Decode.c
c42865612ac9d988e1c92ec6cc835234dd6103c7
[mirror_edk2.git] / EdkModulePkg / Bus / Pci / Undi / RuntimeDxe / Decode.c
1 /*++
2
3 Copyright (c) 2006, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
8
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
11
12 Module name:
13 decode.c
14
15 Abstract:
16
17 Revision history:
18
19 --*/
20
21 // TODO: fix comment to add: Module Name: DECODE.C
22 #include "Undi32.h"
23
24
25 //
26 // #pragma data_seg("rtdata") is only recognized by MSFT C compiler.
27 // But EBC compiler "Intel(R) C Compiler for EFI Byte Code, Version 1.2 Build 20040123"
28 // does not recognize this pragma.
29 //
30 #if defined(_MSC_EXTENSIONS) && !defined(MDE_CPU_EBC)
31 #pragma data_seg("rtdata")
32 #endif
33
34 //
35 // Global variables defined in this file
36 //
37 UNDI_CALL_TABLE api_table[PXE_OPCODE_LAST_VALID+1] = { \
38 {PXE_CPBSIZE_NOT_USED,PXE_DBSIZE_NOT_USED,0, (UINT16)(ANY_STATE),UNDI_GetState },\
39 {(UINT16)(DONT_CHECK),PXE_DBSIZE_NOT_USED,0,(UINT16)(ANY_STATE),UNDI_Start },\
40 {PXE_CPBSIZE_NOT_USED,PXE_DBSIZE_NOT_USED,0,MUST_BE_STARTED,UNDI_Stop },\
41 {PXE_CPBSIZE_NOT_USED,sizeof(PXE_DB_GET_INIT_INFO),0,MUST_BE_STARTED, UNDI_GetInitInfo },\
42 {PXE_CPBSIZE_NOT_USED,sizeof(PXE_DB_GET_CONFIG_INFO),0,MUST_BE_STARTED, UNDI_GetConfigInfo },\
43 {sizeof(PXE_CPB_INITIALIZE),(UINT16)(DONT_CHECK),(UINT16)(DONT_CHECK),MUST_BE_STARTED,UNDI_Initialize },\
44 {PXE_CPBSIZE_NOT_USED,PXE_DBSIZE_NOT_USED,(UINT16)(DONT_CHECK), MUST_BE_INITIALIZED,UNDI_Reset },\
45 {PXE_CPBSIZE_NOT_USED,PXE_DBSIZE_NOT_USED,0, MUST_BE_INITIALIZED,UNDI_Shutdown },\
46 {PXE_CPBSIZE_NOT_USED,PXE_DBSIZE_NOT_USED,(UINT16)(DONT_CHECK), MUST_BE_INITIALIZED,UNDI_Interrupt },\
47 {(UINT16)(DONT_CHECK),(UINT16)(DONT_CHECK),(UINT16)(DONT_CHECK), MUST_BE_INITIALIZED, UNDI_RecFilter },\
48 {(UINT16)(DONT_CHECK),(UINT16)(DONT_CHECK),(UINT16)(DONT_CHECK), MUST_BE_INITIALIZED, UNDI_StnAddr },\
49 {PXE_CPBSIZE_NOT_USED, (UINT16)(DONT_CHECK), (UINT16)(DONT_CHECK), MUST_BE_INITIALIZED, UNDI_Statistics },\
50 {sizeof(PXE_CPB_MCAST_IP_TO_MAC),sizeof(PXE_DB_MCAST_IP_TO_MAC), (UINT16)(DONT_CHECK),MUST_BE_INITIALIZED, UNDI_ip2mac },\
51 {(UINT16)(DONT_CHECK),(UINT16)(DONT_CHECK),(UINT16)(DONT_CHECK), MUST_BE_INITIALIZED, UNDI_NVData },\
52 {PXE_CPBSIZE_NOT_USED,(UINT16)(DONT_CHECK),(UINT16)(DONT_CHECK), MUST_BE_INITIALIZED, UNDI_Status },\
53 {(UINT16)(DONT_CHECK),PXE_DBSIZE_NOT_USED,(UINT16)(DONT_CHECK), MUST_BE_INITIALIZED, UNDI_FillHeader },\
54 {(UINT16)(DONT_CHECK),PXE_DBSIZE_NOT_USED,(UINT16)(DONT_CHECK), MUST_BE_INITIALIZED, UNDI_Transmit },\
55 {sizeof(PXE_CPB_RECEIVE),sizeof(PXE_DB_RECEIVE),0,MUST_BE_INITIALIZED, UNDI_Receive } \
56 };
57
58 //
59 // end of global variables
60 //
61
62 VOID
63 UNDI_GetState (
64 IN PXE_CDB *CdbPtr,
65 IN NIC_DATA_INSTANCE *AdapterInfo
66 )
67 /*++
68
69 Routine Description:
70 This routine determines the operational state of the UNDI. It updates the state flags in the
71 Command Descriptor Block based on information derived from the AdapterInfo instance data.
72
73 To ensure the command has completed successfully, CdbPtr->StatCode will contain the result of
74 the command execution.
75
76 The CdbPtr->StatFlags will contain a STOPPED, STARTED, or INITIALIZED state once the command
77 has successfully completed.
78
79 Keep in mind the AdapterInfo->State is the active state of the adapter (based on software
80 interrogation), and the CdbPtr->StateFlags is the passed back information that is reflected
81 to the caller of the UNDI API.
82
83 Arguments:
84 CdbPtr - Pointer to the command descriptor block.
85 AdapterInfo - Pointer to the NIC data structure information which the UNDI driver is layering on..
86
87 Returns:
88 None
89
90 --*/
91 {
92 CdbPtr->StatFlags = (PXE_STATFLAGS) (CdbPtr->StatFlags | AdapterInfo->State);
93 return ;
94 }
95
96 VOID
97 UNDI_Start (
98 IN PXE_CDB *CdbPtr,
99 IN NIC_DATA_INSTANCE *AdapterInfo
100 )
101 /*++
102
103 Routine Description:
104 This routine is used to change the operational state of the UNDI from stopped to started.
105 It will do this as long as the adapter's state is PXE_STATFLAGS_GET_STATE_STOPPED, otherwise
106 the CdbPtr->StatFlags will reflect a command failure, and the CdbPtr->StatCode will reflect the
107 UNDI as having already been started.
108
109 This routine is modified to reflect the undi 1.1 specification changes. The
110 changes in the spec are mainly in the callback routines, the new spec adds
111 3 more callbacks and a unique id.
112 Since this UNDI supports both old and new undi specifications,
113 The NIC's data structure is filled in with the callback routines (depending
114 on the version) pointed to in the caller's CpbPtr. This seeds the Delay,
115 Virt2Phys, Block, and Mem_IO for old and new versions and Map_Mem, UnMap_Mem
116 and Sync_Mem routines and a unique id variable for the new version.
117 This is the function which an external entity (SNP, O/S, etc) would call
118 to provide it's I/O abstraction to the UNDI.
119
120 It's final action is to change the AdapterInfo->State to PXE_STATFLAGS_GET_STATE_STARTED.
121
122 Arguments:
123 CdbPtr - Pointer to the command descriptor block.
124 AdapterInfo - Pointer to the NIC data structure information which the UNDI driver is layering on..
125
126 Returns:
127 None
128
129 --*/
130 {
131 PXE_CPB_START_30 *CpbPtr;
132 PXE_CPB_START_31 *CpbPtr_31;
133
134 //
135 // check if it is already started.
136 //
137 if (AdapterInfo->State != PXE_STATFLAGS_GET_STATE_STOPPED) {
138 CdbPtr->StatFlags = PXE_STATFLAGS_COMMAND_FAILED;
139 CdbPtr->StatCode = PXE_STATCODE_ALREADY_STARTED;
140 return ;
141 }
142
143 if (CdbPtr->CPBsize != sizeof(PXE_CPB_START_30) &&
144 CdbPtr->CPBsize != sizeof(PXE_CPB_START_31)) {
145
146 CdbPtr->StatFlags = PXE_STATFLAGS_COMMAND_FAILED;
147 CdbPtr->StatCode = PXE_STATCODE_INVALID_CDB;
148 return ;
149 }
150
151 CpbPtr = (PXE_CPB_START_30 *) (UINTN) (CdbPtr->CPBaddr);
152 CpbPtr_31 = (PXE_CPB_START_31 *) (UINTN) (CdbPtr->CPBaddr);
153
154 if (AdapterInfo->VersionFlag == 0x30) {
155 AdapterInfo->Delay_30 = (bsptr_30) (UINTN) CpbPtr->Delay;
156 AdapterInfo->Virt2Phys_30 = (virtphys_30) (UINTN) CpbPtr->Virt2Phys;
157 AdapterInfo->Block_30 = (block_30) (UINTN) CpbPtr->Block;
158 //
159 // patch for old buggy 3.0 code:
160 // In EFI1.0 undi used to provide the full (absolute) I/O address to the
161 // i/o calls and SNP used to provide a callback that used GlobalIoFncs and
162 // everything worked fine! In EFI 1.1, UNDI is not using the full
163 // i/o or memory address to access the device, The base values for the i/o
164 // and memory address is abstracted by the device specific PciIoFncs and
165 // UNDI only uses the offset values. Since UNDI3.0 cannot provide any
166 // identification to SNP, SNP cannot use nic specific PciIoFncs callback!
167 //
168 // To fix this and make undi3.0 work with SNP in EFI1.1 we
169 // use a TmpMemIo function that is defined in init.c
170 // This breaks the runtime driver feature of undi, but what to do
171 // if we have to provide the 3.0 compatibility (including the 3.0 bugs)
172 //
173 // This TmpMemIo function also takes a UniqueId parameter
174 // (as in undi3.1 design) and so initialize the UniqueId as well here
175 // Note: AdapterInfo->Mem_Io_30 is just filled for consistency with other
176 // parameters but never used, we only use Mem_Io field in the In/Out routines
177 // inside e100b.c.
178 //
179 AdapterInfo->Mem_Io_30 = (mem_io_30) (UINTN) CpbPtr->Mem_IO;
180 AdapterInfo->Mem_Io = (mem_io) (UINTN) TmpMemIo;
181 AdapterInfo->Unique_ID = (UINT64) (UINTN) AdapterInfo;
182
183 } else {
184 AdapterInfo->Delay = (bsptr) (UINTN) CpbPtr_31->Delay;
185 AdapterInfo->Virt2Phys = (virtphys) (UINTN) CpbPtr_31->Virt2Phys;
186 AdapterInfo->Block = (block) (UINTN) CpbPtr_31->Block;
187 AdapterInfo->Mem_Io = (mem_io) (UINTN) CpbPtr_31->Mem_IO;
188
189 AdapterInfo->Map_Mem = (map_mem) (UINTN) CpbPtr_31->Map_Mem;
190 AdapterInfo->UnMap_Mem = (unmap_mem) (UINTN) CpbPtr_31->UnMap_Mem;
191 AdapterInfo->Sync_Mem = (sync_mem) (UINTN) CpbPtr_31->Sync_Mem;
192 AdapterInfo->Unique_ID = CpbPtr_31->Unique_ID;
193 }
194
195 AdapterInfo->State = PXE_STATFLAGS_GET_STATE_STARTED;
196
197 return ;
198 }
199
200 VOID
201 UNDI_Stop (
202 IN PXE_CDB *CdbPtr,
203 IN NIC_DATA_INSTANCE *AdapterInfo
204 )
205 /*++
206
207 Routine Description:
208 This routine is used to change the operational state of the UNDI from started to stopped.
209 It will not do this if the adapter's state is PXE_STATFLAGS_GET_STATE_INITIALIZED, otherwise
210 the CdbPtr->StatFlags will reflect a command failure, and the CdbPtr->StatCode will reflect the
211 UNDI as having already not been shut down.
212
213 The NIC's data structure will have the Delay, Virt2Phys, and Block, pointers zero'd out..
214
215 It's final action is to change the AdapterInfo->State to PXE_STATFLAGS_GET_STATE_STOPPED.
216
217 Arguments:
218 CdbPtr - Pointer to the command descriptor block.
219 AdapterInfo - Pointer to the NIC data structure information which the UNDI driver is layering on..
220
221 Returns:
222 None
223
224 --*/
225 {
226 if (AdapterInfo->State == PXE_STATFLAGS_GET_STATE_INITIALIZED) {
227 CdbPtr->StatFlags = PXE_STATFLAGS_COMMAND_FAILED;
228 CdbPtr->StatCode = PXE_STATCODE_NOT_SHUTDOWN;
229 return ;
230 }
231
232 AdapterInfo->Delay_30 = 0;
233 AdapterInfo->Virt2Phys_30 = 0;
234 AdapterInfo->Block_30 = 0;
235
236 AdapterInfo->Delay = 0;
237 AdapterInfo->Virt2Phys = 0;
238 AdapterInfo->Block = 0;
239
240 AdapterInfo->Map_Mem = 0;
241 AdapterInfo->UnMap_Mem = 0;
242 AdapterInfo->Sync_Mem = 0;
243
244 AdapterInfo->State = PXE_STATFLAGS_GET_STATE_STOPPED;
245
246 return ;
247 }
248
249 VOID
250 UNDI_GetInitInfo (
251 IN PXE_CDB *CdbPtr,
252 IN NIC_DATA_INSTANCE *AdapterInfo
253 )
254 /*++
255
256 Routine Description:
257 This routine is used to retrieve the initialization information that is needed by drivers and
258 applications to initialize the UNDI. This will fill in data in the Data Block structure that is
259 pointed to by the caller's CdbPtr->DBaddr. The fields filled in are as follows:
260
261 MemoryRequired, FrameDataLen, LinkSpeeds[0-3], NvCount, NvWidth, MediaHeaderLen, HWaddrLen,
262 MCastFilterCnt, TxBufCnt, TxBufSize, RxBufCnt, RxBufSize, IFtype, Duplex, and LoopBack.
263
264 In addition, the CdbPtr->StatFlags ORs in that this NIC supports cable detection. (APRIORI knowledge)
265
266 Arguments:
267 CdbPtr - Pointer to the command descriptor block.
268 AdapterInfo - Pointer to the NIC data structure information which the UNDI driver is layering on..
269
270 Returns:
271 None
272
273 --*/
274 {
275 PXE_DB_GET_INIT_INFO *DbPtr;
276
277 DbPtr = (PXE_DB_GET_INIT_INFO *) (UINTN) (CdbPtr->DBaddr);
278
279 DbPtr->MemoryRequired = MEMORY_NEEDED;
280 DbPtr->FrameDataLen = PXE_MAX_TXRX_UNIT_ETHER;
281 DbPtr->LinkSpeeds[0] = 10;
282 DbPtr->LinkSpeeds[1] = 100;
283 DbPtr->LinkSpeeds[2] = DbPtr->LinkSpeeds[3] = 0;
284 DbPtr->NvCount = MAX_EEPROM_LEN;
285 DbPtr->NvWidth = 4;
286 DbPtr->MediaHeaderLen = PXE_MAC_HEADER_LEN_ETHER;
287 DbPtr->HWaddrLen = PXE_HWADDR_LEN_ETHER;
288 DbPtr->MCastFilterCnt = MAX_MCAST_ADDRESS_CNT;
289
290 DbPtr->TxBufCnt = TX_BUFFER_COUNT;
291 DbPtr->TxBufSize = sizeof (TxCB);
292 DbPtr->RxBufCnt = RX_BUFFER_COUNT;
293 DbPtr->RxBufSize = sizeof (RxFD);
294
295 DbPtr->IFtype = PXE_IFTYPE_ETHERNET;
296 DbPtr->SupportedDuplexModes = PXE_DUPLEX_ENABLE_FULL_SUPPORTED |
297 PXE_DUPLEX_FORCE_FULL_SUPPORTED;
298 DbPtr->SupportedLoopBackModes = PXE_LOOPBACK_INTERNAL_SUPPORTED |
299 PXE_LOOPBACK_EXTERNAL_SUPPORTED;
300
301 CdbPtr->StatFlags |= PXE_STATFLAGS_CABLE_DETECT_SUPPORTED;
302 return ;
303 }
304
305 VOID
306 UNDI_GetConfigInfo (
307 IN PXE_CDB *CdbPtr,
308 IN NIC_DATA_INSTANCE *AdapterInfo
309 )
310 /*++
311
312 Routine Description:
313 This routine is used to retrieve the configuration information about the NIC being controlled by
314 this driver. This will fill in data in the Data Block structure that is pointed to by the caller's CdbPtr->DBaddr.
315 The fields filled in are as follows:
316
317 DbPtr->pci.BusType, DbPtr->pci.Bus, DbPtr->pci.Device, and DbPtr->pci.
318
319 In addition, the DbPtr->pci.Config.Dword[0-63] grabs a copy of this NIC's PCI configuration space.
320
321 Arguments:
322 CdbPtr - Pointer to the command descriptor block.
323 AdapterInfo - Pointer to the NIC data structure information which the UNDI driver is layering on..
324
325 Returns:
326 None
327
328 --*/
329 {
330 UINT16 Index;
331 PXE_DB_GET_CONFIG_INFO *DbPtr;
332
333 DbPtr = (PXE_DB_GET_CONFIG_INFO *) (UINTN) (CdbPtr->DBaddr);
334
335 DbPtr->pci.BusType = PXE_BUSTYPE_PCI;
336 DbPtr->pci.Bus = AdapterInfo->Bus;
337 DbPtr->pci.Device = AdapterInfo->Device;
338 DbPtr->pci.Function = AdapterInfo->Function;
339
340 for (Index = 0; Index < MAX_PCI_CONFIG_LEN; Index++) {
341 DbPtr->pci.Config.Dword[Index] = AdapterInfo->Config[Index];
342 }
343
344 return ;
345 }
346
347 VOID
348 UNDI_Initialize (
349 IN PXE_CDB *CdbPtr,
350 NIC_DATA_INSTANCE *AdapterInfo
351 )
352 /*++
353
354 Routine Description:
355 This routine resets the network adapter and initializes the UNDI using the parameters supplied in
356 the CPB. This command must be issued before the network adapter can be setup to transmit and
357 receive packets.
358
359 Once the memory requirements of the UNDI are obtained by using the GetInitInfo command, a block
360 of non-swappable memory may need to be allocated. The address of this memory must be passed to
361 UNDI during the Initialize in the CPB. This memory is used primarily for transmit and receive buffers.
362
363 The fields CableDetect, LinkSpeed, Duplex, LoopBack, MemoryPtr, and MemoryLength are set with information
364 that was passed in the CPB and the NIC is initialized.
365
366 If the NIC initialization fails, the CdbPtr->StatFlags are updated with PXE_STATFLAGS_COMMAND_FAILED
367 Otherwise, AdapterInfo->State is updated with PXE_STATFLAGS_GET_STATE_INITIALIZED showing the state of
368 the UNDI is now initialized.
369
370 Arguments:
371 CdbPtr - Pointer to the command descriptor block.
372 AdapterInfo - Pointer to the NIC data structure information which the UNDI driver is layering on..
373
374 Returns:
375 None
376
377 --*/
378 {
379 PXE_CPB_INITIALIZE *CpbPtr;
380
381 if ((CdbPtr->OpFlags != PXE_OPFLAGS_INITIALIZE_DETECT_CABLE) &&
382 (CdbPtr->OpFlags != PXE_OPFLAGS_INITIALIZE_DO_NOT_DETECT_CABLE)) {
383 CdbPtr->StatFlags = PXE_STATFLAGS_COMMAND_FAILED;
384 CdbPtr->StatCode = PXE_STATCODE_INVALID_CDB;
385 return ;
386 }
387
388 //
389 // check if it is already initialized
390 //
391 if (AdapterInfo->State == PXE_STATFLAGS_GET_STATE_INITIALIZED) {
392 CdbPtr->StatFlags = PXE_STATFLAGS_COMMAND_FAILED;
393 CdbPtr->StatCode = PXE_STATCODE_ALREADY_INITIALIZED;
394 return ;
395 }
396
397 CpbPtr = (PXE_CPB_INITIALIZE *) (UINTN) CdbPtr->CPBaddr;
398
399 if (CpbPtr->MemoryLength < (UINT32) MEMORY_NEEDED) {
400 CdbPtr->StatFlags = PXE_STATFLAGS_COMMAND_FAILED;
401 CdbPtr->StatCode = PXE_STATCODE_INVALID_CPB;
402 return ;
403 }
404
405 //
406 // default behaviour is to detect the cable, if the 3rd param is 1,
407 // do not do that
408 //
409 AdapterInfo->CableDetect = (UINT8) ((CdbPtr->OpFlags == (UINT16) PXE_OPFLAGS_INITIALIZE_DO_NOT_DETECT_CABLE) ? (UINT8) 0 : (UINT8) 1);
410 AdapterInfo->LinkSpeedReq = (UINT16) CpbPtr->LinkSpeed;
411 AdapterInfo->DuplexReq = CpbPtr->DuplexMode;
412 AdapterInfo->LoopBack = CpbPtr->LoopBackMode;
413 AdapterInfo->MemoryPtr = CpbPtr->MemoryAddr;
414 AdapterInfo->MemoryLength = CpbPtr->MemoryLength;
415
416 CdbPtr->StatCode = (PXE_STATCODE) E100bInit (AdapterInfo);
417
418 if (CdbPtr->StatCode != PXE_STATCODE_SUCCESS) {
419 CdbPtr->StatFlags = PXE_STATFLAGS_COMMAND_FAILED;
420 } else {
421 AdapterInfo->State = PXE_STATFLAGS_GET_STATE_INITIALIZED;
422 }
423
424 return ;
425 }
426
427 VOID
428 UNDI_Reset (
429 IN PXE_CDB *CdbPtr,
430 IN NIC_DATA_INSTANCE *AdapterInfo
431 )
432 /*++
433
434 Routine Description:
435 This routine resets the network adapter and initializes the UNDI using the parameters supplied in
436 the CPB. The transmit and receive queues are emptied and any pending interrupts are cleared.
437
438 If the NIC reset fails, the CdbPtr->StatFlags are updated with PXE_STATFLAGS_COMMAND_FAILED
439
440 Arguments:
441 CdbPtr - Pointer to the command descriptor block.
442 AdapterInfo - Pointer to the NIC data structure information which the UNDI driver is layering on..
443
444 Returns:
445 None
446
447 --*/
448 {
449 if (CdbPtr->OpFlags != PXE_OPFLAGS_NOT_USED &&
450 CdbPtr->OpFlags != PXE_OPFLAGS_RESET_DISABLE_INTERRUPTS &&
451 CdbPtr->OpFlags != PXE_OPFLAGS_RESET_DISABLE_FILTERS ) {
452
453 CdbPtr->StatFlags = PXE_STATFLAGS_COMMAND_FAILED;
454 CdbPtr->StatCode = PXE_STATCODE_INVALID_CDB;
455 return ;
456 }
457
458 CdbPtr->StatCode = (UINT16) E100bReset (AdapterInfo, CdbPtr->OpFlags);
459
460 if (CdbPtr->StatCode != PXE_STATCODE_SUCCESS) {
461 CdbPtr->StatFlags = PXE_STATFLAGS_COMMAND_FAILED;
462 }
463 }
464
465 VOID
466 UNDI_Shutdown (
467 IN PXE_CDB *CdbPtr,
468 IN NIC_DATA_INSTANCE *AdapterInfo
469 )
470 /*++
471
472 Routine Description:
473 This routine resets the network adapter and leaves it in a safe state for another driver to
474 initialize. Any pending transmits or receives are lost. Receive filters and external
475 interrupt enables are disabled. Once the UNDI has been shutdown, it can then be stopped
476 or initialized again.
477
478 If the NIC reset fails, the CdbPtr->StatFlags are updated with PXE_STATFLAGS_COMMAND_FAILED
479
480 Otherwise, AdapterInfo->State is updated with PXE_STATFLAGS_GET_STATE_STARTED showing the state of
481 the NIC as being started.
482
483 Arguments:
484 CdbPtr - Pointer to the command descriptor block.
485 AdapterInfo - Pointer to the NIC data structure information which the UNDI driver is layering on..
486
487 Returns:
488 None
489
490 --*/
491 {
492 //
493 // do the shutdown stuff here
494 //
495 CdbPtr->StatCode = (UINT16) E100bShutdown (AdapterInfo);
496
497 if (CdbPtr->StatCode != PXE_STATCODE_SUCCESS) {
498 CdbPtr->StatFlags = PXE_STATFLAGS_COMMAND_FAILED;
499 } else {
500 AdapterInfo->State = PXE_STATFLAGS_GET_STATE_STARTED;
501 }
502
503 return ;
504 }
505
506 VOID
507 UNDI_Interrupt (
508 IN PXE_CDB *CdbPtr,
509 IN NIC_DATA_INSTANCE *AdapterInfo
510 )
511 /*++
512
513 Routine Description:
514 This routine can be used to read and/or change the current external interrupt enable
515 settings. Disabling an external interrupt enable prevents and external (hardware)
516 interrupt from being signaled by the network device. Internally the interrupt events
517 can still be polled by using the UNDI_GetState command.
518
519 The resulting information on the interrupt state will be passed back in the CdbPtr->StatFlags.
520
521 Arguments:
522 CdbPtr - Pointer to the command descriptor block.
523 AdapterInfo - Pointer to the NIC data structure information which the UNDI driver is layering on..
524
525 Returns:
526 None
527
528 --*/
529 {
530 UINT8 IntMask;
531
532 IntMask = (UINT8)(UINTN)(CdbPtr->OpFlags & (PXE_OPFLAGS_INTERRUPT_RECEIVE |
533 PXE_OPFLAGS_INTERRUPT_TRANSMIT |
534 PXE_OPFLAGS_INTERRUPT_COMMAND |
535 PXE_OPFLAGS_INTERRUPT_SOFTWARE));
536
537 switch (CdbPtr->OpFlags & PXE_OPFLAGS_INTERRUPT_OPMASK) {
538 case PXE_OPFLAGS_INTERRUPT_READ:
539 break;
540
541 case PXE_OPFLAGS_INTERRUPT_ENABLE:
542 if (IntMask == 0) {
543 CdbPtr->StatFlags = PXE_STATFLAGS_COMMAND_FAILED;
544 CdbPtr->StatCode = PXE_STATCODE_INVALID_CDB;
545 return ;
546 }
547
548 AdapterInfo->int_mask = IntMask;
549 E100bSetInterruptState (AdapterInfo);
550 break;
551
552 case PXE_OPFLAGS_INTERRUPT_DISABLE:
553 if (IntMask != 0) {
554 AdapterInfo->int_mask = (UINT16) (AdapterInfo->int_mask & ~(IntMask));
555 E100bSetInterruptState (AdapterInfo);
556 break;
557 }
558
559 //
560 // else fall thru.
561 //
562 default:
563 CdbPtr->StatFlags = PXE_STATFLAGS_COMMAND_FAILED;
564 CdbPtr->StatCode = PXE_STATCODE_INVALID_CDB;
565 return ;
566 }
567
568 if ((AdapterInfo->int_mask & PXE_OPFLAGS_INTERRUPT_RECEIVE) != 0) {
569 CdbPtr->StatFlags |= PXE_STATFLAGS_INTERRUPT_RECEIVE;
570
571 }
572
573 if ((AdapterInfo->int_mask & PXE_OPFLAGS_INTERRUPT_TRANSMIT) != 0) {
574 CdbPtr->StatFlags |= PXE_STATFLAGS_INTERRUPT_TRANSMIT;
575
576 }
577
578 if ((AdapterInfo->int_mask & PXE_OPFLAGS_INTERRUPT_COMMAND) != 0) {
579 CdbPtr->StatFlags |= PXE_STATFLAGS_INTERRUPT_COMMAND;
580
581 }
582
583 return ;
584 }
585
586 VOID
587 UNDI_RecFilter (
588 IN PXE_CDB *CdbPtr,
589 IN NIC_DATA_INSTANCE *AdapterInfo
590 )
591 /*++
592
593 Routine Description:
594 This routine is used to read and change receive filters and, if supported, read
595 and change multicast MAC address filter list.
596
597 Arguments:
598 CdbPtr - Pointer to the command descriptor block.
599 AdapterInfo - Pointer to the NIC data structure information which the UNDI driver is layering on..
600
601 Returns:
602 None
603
604 --*/
605 {
606 UINT16 NewFilter;
607 UINT16 OpFlags;
608 PXE_DB_RECEIVE_FILTERS *DbPtr;
609 UINT8 *MacAddr;
610 UINTN MacCount;
611 UINT16 Index;
612 UINT16 copy_len;
613 UINT8 *ptr1;
614 UINT8 *ptr2;
615 OpFlags = CdbPtr->OpFlags;
616 NewFilter = (UINT16) (OpFlags & 0x1F);
617
618 switch (OpFlags & PXE_OPFLAGS_RECEIVE_FILTER_OPMASK) {
619 case PXE_OPFLAGS_RECEIVE_FILTER_READ:
620
621 //
622 // not expecting a cpb, not expecting any filter bits
623 //
624 if ((NewFilter != 0) || (CdbPtr->CPBsize != 0)) {
625 goto BadCdb;
626
627 }
628
629 if ((NewFilter & PXE_OPFLAGS_RECEIVE_FILTER_RESET_MCAST_LIST) == 0) {
630 goto JustRead;
631
632 }
633
634 NewFilter = (UINT16) (NewFilter | AdapterInfo->Rx_Filter);
635 //
636 // all other flags are ignored except mcast_reset
637 //
638 break;
639
640 case PXE_OPFLAGS_RECEIVE_FILTER_ENABLE:
641 //
642 // there should be atleast one other filter bit set.
643 //
644 if (NewFilter == 0) {
645 //
646 // nothing to enable
647 //
648 goto BadCdb;
649 }
650
651 if (CdbPtr->CPBsize != 0) {
652 //
653 // this must be a multicast address list!
654 // don't accept the list unless selective_mcast is set
655 // don't accept confusing mcast settings with this
656 //
657 if (((NewFilter & PXE_OPFLAGS_RECEIVE_FILTER_FILTERED_MULTICAST) == 0) ||
658 ((NewFilter & PXE_OPFLAGS_RECEIVE_FILTER_RESET_MCAST_LIST) != 0) ||
659 ((NewFilter & PXE_OPFLAGS_RECEIVE_FILTER_ALL_MULTICAST) != 0) ||
660 ((CdbPtr->CPBsize % sizeof (PXE_MAC_ADDR)) != 0) ) {
661 goto BadCdb;
662 }
663
664 MacAddr = (UINT8 *) ((UINTN) (CdbPtr->CPBaddr));
665 MacCount = CdbPtr->CPBsize / sizeof (PXE_MAC_ADDR);
666
667 for (; MacCount-- != 0; MacAddr += sizeof (PXE_MAC_ADDR)) {
668 if (MacAddr[0] != 0x01 || MacAddr[1] != 0x00 || MacAddr[2] != 0x5E || (MacAddr[3] & 0x80) != 0) {
669 CdbPtr->StatFlags = PXE_STATFLAGS_COMMAND_FAILED;
670 CdbPtr->StatCode = PXE_STATCODE_INVALID_CPB;
671 return ;
672 }
673 }
674 }
675
676 //
677 // check selective mcast case enable case
678 //
679 if ((OpFlags & PXE_OPFLAGS_RECEIVE_FILTER_FILTERED_MULTICAST) != 0) {
680 if (((OpFlags & PXE_OPFLAGS_RECEIVE_FILTER_RESET_MCAST_LIST) != 0) ||
681 ((OpFlags & PXE_OPFLAGS_RECEIVE_FILTER_ALL_MULTICAST) != 0) ) {
682 goto BadCdb;
683
684 }
685 //
686 // if no cpb, make sure we have an old list
687 //
688 if ((CdbPtr->CPBsize == 0) && (AdapterInfo->mcast_list.list_len == 0)) {
689 goto BadCdb;
690 }
691 }
692 //
693 // if you want to enable anything, you got to have unicast
694 // and you have what you already enabled!
695 //
696 NewFilter = (UINT16) (NewFilter | (PXE_OPFLAGS_RECEIVE_FILTER_UNICAST | AdapterInfo->Rx_Filter));
697
698 break;
699
700 case PXE_OPFLAGS_RECEIVE_FILTER_DISABLE:
701
702 //
703 // mcast list not expected, i.e. no cpb here!
704 //
705 if (CdbPtr->CPBsize != PXE_CPBSIZE_NOT_USED) {
706 goto BadCdb;
707 }
708
709 NewFilter = (UINT16) ((~(CdbPtr->OpFlags & 0x1F)) & AdapterInfo->Rx_Filter);
710
711 break;
712
713 default:
714 goto BadCdb;
715 }
716
717 if ((OpFlags & PXE_OPFLAGS_RECEIVE_FILTER_RESET_MCAST_LIST) != 0) {
718 AdapterInfo->mcast_list.list_len = 0;
719 NewFilter &= (~PXE_OPFLAGS_RECEIVE_FILTER_FILTERED_MULTICAST);
720 }
721
722 E100bSetfilter (AdapterInfo, NewFilter, CdbPtr->CPBaddr, CdbPtr->CPBsize);
723
724 JustRead:
725 //
726 // give the current mcast list
727 //
728 if ((CdbPtr->DBsize != 0) && (AdapterInfo->mcast_list.list_len != 0)) {
729 //
730 // copy the mc list to db
731 //
732
733 DbPtr = (PXE_DB_RECEIVE_FILTERS *) (UINTN) CdbPtr->DBaddr;
734 ptr1 = (UINT8 *) (&DbPtr->MCastList[0]);
735
736 //
737 // DbPtr->mc_count = AdapterInfo->mcast_list.list_len;
738 //
739 copy_len = (UINT16) (AdapterInfo->mcast_list.list_len * PXE_MAC_LENGTH);
740
741 if (copy_len > CdbPtr->DBsize) {
742 copy_len = CdbPtr->DBsize;
743
744 }
745
746 ptr2 = (UINT8 *) (&AdapterInfo->mcast_list.mc_list[0]);
747 for (Index = 0; Index < copy_len; Index++) {
748 ptr1[Index] = ptr2[Index];
749 }
750 }
751 //
752 // give the stat flags here
753 //
754 if (AdapterInfo->Receive_Started) {
755 CdbPtr->StatFlags = (PXE_STATFLAGS) (CdbPtr->StatFlags | AdapterInfo->Rx_Filter);
756
757 }
758
759 return ;
760
761 BadCdb:
762 CdbPtr->StatFlags = PXE_STATFLAGS_COMMAND_FAILED;
763 CdbPtr->StatCode = PXE_STATCODE_INVALID_CDB;
764 }
765
766 VOID
767 UNDI_StnAddr (
768 IN PXE_CDB *CdbPtr,
769 IN NIC_DATA_INSTANCE *AdapterInfo
770 )
771 /*++
772
773 Routine Description:
774 This routine is used to get the current station and broadcast MAC addresses, and to change the
775 current station MAC address.
776
777 Arguments:
778 CdbPtr - Pointer to the command descriptor block.
779 AdapterInfo - Pointer to the NIC data structure information which the UNDI driver is layering on..
780
781 Returns:
782 None
783
784 --*/
785 {
786 PXE_CPB_STATION_ADDRESS *CpbPtr;
787 PXE_DB_STATION_ADDRESS *DbPtr;
788 UINT16 Index;
789
790 if (CdbPtr->OpFlags == PXE_OPFLAGS_STATION_ADDRESS_RESET) {
791 //
792 // configure the permanent address.
793 // change the AdapterInfo->CurrentNodeAddress field.
794 //
795 if (CompareMem (
796 &AdapterInfo->CurrentNodeAddress[0],
797 &AdapterInfo->PermNodeAddress[0],
798 PXE_MAC_LENGTH
799 ) != 0) {
800 for (Index = 0; Index < PXE_MAC_LENGTH; Index++) {
801 AdapterInfo->CurrentNodeAddress[Index] = AdapterInfo->PermNodeAddress[Index];
802 }
803
804 E100bSetupIAAddr (AdapterInfo);
805 }
806 }
807
808 if (CdbPtr->CPBaddr != (UINT64) 0) {
809 CpbPtr = (PXE_CPB_STATION_ADDRESS *) (UINTN) (CdbPtr->CPBaddr);
810 //
811 // configure the new address
812 //
813 for (Index = 0; Index < PXE_MAC_LENGTH; Index++) {
814 AdapterInfo->CurrentNodeAddress[Index] = CpbPtr->StationAddr[Index];
815 }
816
817 E100bSetupIAAddr (AdapterInfo);
818 }
819
820 if (CdbPtr->DBaddr != (UINT64) 0) {
821 DbPtr = (PXE_DB_STATION_ADDRESS *) (UINTN) (CdbPtr->DBaddr);
822 //
823 // fill it with the new values
824 //
825 for (Index = 0; Index < PXE_MAC_LENGTH; Index++) {
826 DbPtr->StationAddr[Index] = AdapterInfo->CurrentNodeAddress[Index];
827 DbPtr->BroadcastAddr[Index] = AdapterInfo->BroadcastNodeAddress[Index];
828 DbPtr->PermanentAddr[Index] = AdapterInfo->PermNodeAddress[Index];
829 }
830 }
831
832 return ;
833 }
834
835 VOID
836 UNDI_Statistics (
837 IN PXE_CDB *CdbPtr,
838 IN NIC_DATA_INSTANCE *AdapterInfo
839 )
840 /*++
841
842 Routine Description:
843 This routine is used to read and clear the NIC traffic statistics. This command is supported only
844 if the !PXE structure's Implementation flags say so.
845
846 Results will be parsed out in the following manner:
847 CdbPtr->DBaddr.Data[0] R Total Frames (Including frames with errors and dropped frames)
848 CdbPtr->DBaddr.Data[1] R Good Frames (All frames copied into receive buffer)
849 CdbPtr->DBaddr.Data[2] R Undersize Frames (Frames below minimum length for media <64 for ethernet)
850 CdbPtr->DBaddr.Data[4] R Dropped Frames (Frames that were dropped because receive buffers were full)
851 CdbPtr->DBaddr.Data[8] R CRC Error Frames (Frames with alignment or CRC errors)
852 CdbPtr->DBaddr.Data[A] T Total Frames (Including frames with errors and dropped frames)
853 CdbPtr->DBaddr.Data[B] T Good Frames (All frames copied into transmit buffer)
854 CdbPtr->DBaddr.Data[C] T Undersize Frames (Frames below minimum length for media <64 for ethernet)
855 CdbPtr->DBaddr.Data[E] T Dropped Frames (Frames that were dropped because of collisions)
856 CdbPtr->DBaddr.Data[14] T Total Collision Frames (Total collisions on this subnet)
857
858 Arguments:
859 CdbPtr - Pointer to the command descriptor block.
860 AdapterInfo - Pointer to the NIC data structure information which the UNDI driver is layering on..
861
862 Returns:
863 None
864
865 --*/
866 {
867 if ((CdbPtr->OpFlags &~(PXE_OPFLAGS_STATISTICS_RESET)) != 0) {
868 CdbPtr->StatFlags = PXE_STATFLAGS_COMMAND_FAILED;
869 CdbPtr->StatCode = PXE_STATCODE_INVALID_CDB;
870 return ;
871 }
872
873 if ((CdbPtr->OpFlags & PXE_OPFLAGS_STATISTICS_RESET) != 0) {
874 //
875 // Reset the statistics
876 //
877 CdbPtr->StatCode = (UINT16) E100bStatistics (AdapterInfo, 0, 0);
878 } else {
879 CdbPtr->StatCode = (UINT16) E100bStatistics (AdapterInfo, CdbPtr->DBaddr, CdbPtr->DBsize);
880 }
881
882 return ;
883 }
884
885 VOID
886 UNDI_ip2mac (
887 IN PXE_CDB *CdbPtr,
888 IN NIC_DATA_INSTANCE *AdapterInfo
889 )
890 /*++
891
892 Routine Description:
893 This routine is used to translate a multicast IP address to a multicast MAC address.
894
895 This results in a MAC address composed of 25 bits of fixed data with the upper 23 bits of the IP
896 address being appended to it. Results passed back in the equivalent of CdbPtr->DBaddr->MAC[0-5].
897
898 Arguments:
899 CdbPtr - Pointer to the command descriptor block.
900 AdapterInfo - Pointer to the NIC data structure information which the UNDI driver is layering on..
901
902 Returns:
903 None
904
905 --*/
906 {
907 PXE_CPB_MCAST_IP_TO_MAC *CpbPtr;
908 PXE_DB_MCAST_IP_TO_MAC *DbPtr;
909 UINT8 *TmpPtr;
910
911 CpbPtr = (PXE_CPB_MCAST_IP_TO_MAC *) (UINTN) CdbPtr->CPBaddr;
912 DbPtr = (PXE_DB_MCAST_IP_TO_MAC *) (UINTN) CdbPtr->DBaddr;
913
914 if ((CdbPtr->OpFlags & PXE_OPFLAGS_MCAST_IPV6_TO_MAC) != 0) {
915 //
916 // for now this is not supported
917 //
918 CdbPtr->StatFlags = PXE_STATFLAGS_COMMAND_FAILED;
919 CdbPtr->StatCode = PXE_STATCODE_UNSUPPORTED;
920 return ;
921 }
922
923 TmpPtr = (UINT8 *) (&CpbPtr->IP.IPv4);
924 //
925 // check if the ip given is a mcast IP
926 //
927 if ((TmpPtr[0] & 0xF0) != 0xE0) {
928 CdbPtr->StatFlags = PXE_STATFLAGS_COMMAND_FAILED;
929 CdbPtr->StatCode = PXE_STATCODE_INVALID_CPB;
930 }
931 //
932 // take the last 23 bits in IP.
933 // be very careful. accessing word on a non-word boundary will hang motherboard codenamed Big Sur
934 // casting the mac array (in the middle) to a UINT32 pointer and accessing
935 // the UINT32 content hung the system...
936 //
937 DbPtr->MAC[0] = 0x01;
938 DbPtr->MAC[1] = 0x00;
939 DbPtr->MAC[2] = 0x5e;
940 DbPtr->MAC[3] = (UINT8) (TmpPtr[1] & 0x7f);
941 DbPtr->MAC[4] = (UINT8) TmpPtr[2];
942 DbPtr->MAC[5] = (UINT8) TmpPtr[3];
943
944 return ;
945 }
946
947 VOID
948 UNDI_NVData (
949 IN PXE_CDB *CdbPtr,
950 IN NIC_DATA_INSTANCE *AdapterInfo
951 )
952 /*++
953
954 Routine Description:
955 This routine is used to read and write non-volatile storage on the NIC (if supported). The NVRAM
956 could be EEPROM, FLASH, or battery backed RAM.
957
958 This is an optional function according to the UNDI specification (or will be......)
959
960 Arguments:
961 CdbPtr - Pointer to the command descriptor block.
962 AdapterInfo - Pointer to the NIC data structure information which the UNDI driver is layering on..
963
964 Returns:
965 None
966
967 --*/
968 {
969 PXE_DB_NVDATA *DbPtr;
970 UINT16 Index;
971
972 if ((CdbPtr->OpFlags == PXE_OPFLAGS_NVDATA_READ) != 0) {
973
974 if ((CdbPtr->DBsize == PXE_DBSIZE_NOT_USED) != 0) {
975 CdbPtr->StatFlags = PXE_STATFLAGS_COMMAND_FAILED;
976 CdbPtr->StatCode = PXE_STATCODE_INVALID_CDB;
977 return ;
978 }
979
980 DbPtr = (PXE_DB_NVDATA *) (UINTN) CdbPtr->DBaddr;
981
982 for (Index = 0; Index < MAX_PCI_CONFIG_LEN; Index++) {
983 DbPtr->Data.Dword[Index] = AdapterInfo->NVData[Index];
984
985 }
986
987 } else {
988 //
989 // no write for now
990 //
991 CdbPtr->StatFlags = PXE_STATFLAGS_COMMAND_FAILED;
992 CdbPtr->StatCode = PXE_STATCODE_UNSUPPORTED;
993 }
994
995 return ;
996 }
997
998 VOID
999 UNDI_Status (
1000 IN PXE_CDB *CdbPtr,
1001 IN NIC_DATA_INSTANCE *AdapterInfo
1002 )
1003 /*++
1004
1005 Routine Description:
1006 This routine returns the current interrupt status and/or the transmitted buffer addresses.
1007 If the current interrupt status is returned, pending interrupts will be acknowledged by this
1008 command. Transmitted buffer addresses that are written to the DB are removed from the transmit
1009 buffer queue.
1010
1011 Normally, this command would be polled with interrupts disabled.
1012
1013 The transmit buffers are returned in CdbPtr->DBaddr->TxBufer[0 - NumEntries].
1014 The interrupt status is returned in CdbPtr->StatFlags.
1015
1016 Arguments:
1017 CdbPtr - Pointer to the command descriptor block.
1018 AdapterInfo - Pointer to the NIC data structure information which the UNDI driver is layering on..
1019
1020 Returns:
1021 None
1022
1023 --*/
1024 {
1025 PXE_DB_GET_STATUS *DbPtr;
1026 PXE_DB_GET_STATUS TmpGetStatus;
1027 UINT16 Index;
1028 UINT16 Status;
1029 UINT16 NumEntries;
1030 RxFD *RxPtr;
1031
1032 //
1033 // Fill in temporary GetStatus storage.
1034 //
1035 RxPtr = &AdapterInfo->rx_ring[AdapterInfo->cur_rx_ind];
1036
1037 if ((RxPtr->cb_header.status & RX_COMPLETE) != 0) {
1038 TmpGetStatus.RxFrameLen = RxPtr->ActualCount & 0x3fff;
1039 } else {
1040 TmpGetStatus.RxFrameLen = 0;
1041 }
1042
1043 TmpGetStatus.reserved = 0;
1044
1045 //
1046 // Fill in size of next available receive packet and
1047 // reserved field in caller's DB storage.
1048 //
1049 DbPtr = (PXE_DB_GET_STATUS *) (UINTN) CdbPtr->DBaddr;
1050
1051 if (CdbPtr->DBsize > 0 && CdbPtr->DBsize < sizeof (UINT32) * 2) {
1052 CopyMem (DbPtr, &TmpGetStatus, CdbPtr->DBsize);
1053 } else {
1054 CopyMem (DbPtr, &TmpGetStatus, sizeof (UINT32) * 2);
1055 }
1056
1057 //
1058 //
1059 //
1060 if ((CdbPtr->OpFlags & PXE_OPFLAGS_GET_TRANSMITTED_BUFFERS) != 0) {
1061 //
1062 // DBsize of zero is invalid if Tx buffers are requested.
1063 //
1064 if (CdbPtr->DBsize == 0) {
1065 CdbPtr->StatFlags = PXE_STATFLAGS_COMMAND_FAILED;
1066 CdbPtr->StatCode = PXE_STATCODE_INVALID_CDB;
1067 return ;
1068 }
1069
1070 //
1071 // remember this b4 we overwrite
1072 //
1073 NumEntries = (UINT16) (CdbPtr->DBsize - sizeof (UINT64));
1074
1075 //
1076 // We already filled in 2 UINT32s.
1077 //
1078 CdbPtr->DBsize = sizeof (UINT32) * 2;
1079
1080 //
1081 // will claim any hanging free CBs
1082 //
1083 CheckCBList (AdapterInfo);
1084
1085 if (AdapterInfo->xmit_done_head == AdapterInfo->xmit_done_tail) {
1086 CdbPtr->StatFlags |= PXE_STATFLAGS_GET_STATUS_TXBUF_QUEUE_EMPTY;
1087 } else {
1088 for (Index = 0; NumEntries >= sizeof (UINT64); Index++, NumEntries -= sizeof (UINT64)) {
1089 if (AdapterInfo->xmit_done_head != AdapterInfo->xmit_done_tail) {
1090 DbPtr->TxBuffer[Index] = AdapterInfo->xmit_done[AdapterInfo->xmit_done_head];
1091 AdapterInfo->xmit_done_head = next (AdapterInfo->xmit_done_head);
1092 CdbPtr->DBsize += sizeof (UINT64);
1093 } else {
1094 break;
1095 }
1096 }
1097 }
1098
1099 if (AdapterInfo->xmit_done_head != AdapterInfo->xmit_done_tail) {
1100 CdbPtr->StatFlags |= PXE_STATFLAGS_DB_WRITE_TRUNCATED;
1101
1102 }
1103 //
1104 // check for a receive buffer and give it's size in db
1105 //
1106 }
1107 //
1108 //
1109 //
1110 if ((CdbPtr->OpFlags & PXE_OPFLAGS_GET_INTERRUPT_STATUS) != 0) {
1111
1112 Status = InWord (AdapterInfo, AdapterInfo->ioaddr + SCBStatus);
1113 AdapterInfo->Int_Status = (UINT16) (AdapterInfo->Int_Status | Status);
1114
1115 //
1116 // acknoledge the interrupts
1117 //
1118 OutWord (AdapterInfo, (UINT16) (Status & 0xfc00), (UINT32) (AdapterInfo->ioaddr + SCBStatus));
1119
1120 //
1121 // report all the outstanding interrupts
1122 //
1123 Status = AdapterInfo->Int_Status;
1124 if ((Status & SCB_STATUS_FR) != 0) {
1125 CdbPtr->StatFlags |= PXE_STATFLAGS_GET_STATUS_RECEIVE;
1126 }
1127
1128 if ((Status & SCB_STATUS_SWI) != 0) {
1129 CdbPtr->StatFlags |= PXE_STATFLAGS_GET_STATUS_SOFTWARE;
1130 }
1131 }
1132
1133 return ;
1134 }
1135
1136 VOID
1137 UNDI_FillHeader (
1138 IN PXE_CDB *CdbPtr,
1139 IN NIC_DATA_INSTANCE *AdapterInfo
1140 )
1141 /*++
1142
1143 Routine Description:
1144 This routine is used to fill media header(s) in transmit packet(s).
1145 Copies the MAC address into the media header whether it is dealing
1146 with fragmented or non-fragmented packets.
1147
1148 Arguments:
1149 CdbPtr - Pointer to the command descriptor block.
1150 AdapterInfo - Pointer to the NIC data structure information which the UNDI driver is layering on..
1151
1152 Returns:
1153 None
1154
1155 --*/
1156 {
1157 PXE_CPB_FILL_HEADER *Cpb;
1158 PXE_CPB_FILL_HEADER_FRAGMENTED *Cpbf;
1159 EtherHeader *MacHeader;
1160 UINTN Index;
1161
1162 if (CdbPtr->CPBsize == PXE_CPBSIZE_NOT_USED) {
1163 CdbPtr->StatFlags = PXE_STATFLAGS_COMMAND_FAILED;
1164 CdbPtr->StatCode = PXE_STATCODE_INVALID_CDB;
1165 return ;
1166 }
1167
1168 if ((CdbPtr->OpFlags & PXE_OPFLAGS_FILL_HEADER_FRAGMENTED) != 0) {
1169 Cpbf = (PXE_CPB_FILL_HEADER_FRAGMENTED *) (UINTN) CdbPtr->CPBaddr;
1170
1171 //
1172 // assume 1st fragment is big enough for the mac header
1173 //
1174 if ((Cpbf->FragCnt == 0) || (Cpbf->FragDesc[0].FragLen < PXE_MAC_HEADER_LEN_ETHER)) {
1175 //
1176 // no buffers given
1177 //
1178 CdbPtr->StatFlags = PXE_STATFLAGS_COMMAND_FAILED;
1179 CdbPtr->StatCode = PXE_STATCODE_INVALID_CDB;
1180 return ;
1181 }
1182
1183 MacHeader = (EtherHeader *) (UINTN) Cpbf->FragDesc[0].FragAddr;
1184 //
1185 // we don't swap the protocol bytes
1186 //
1187 MacHeader->type = Cpbf->Protocol;
1188
1189 for (Index = 0; Index < PXE_HWADDR_LEN_ETHER; Index++) {
1190 MacHeader->dest_addr[Index] = Cpbf->DestAddr[Index];
1191 MacHeader->src_addr[Index] = Cpbf->SrcAddr[Index];
1192 }
1193 } else {
1194 Cpb = (PXE_CPB_FILL_HEADER *) (UINTN) CdbPtr->CPBaddr;
1195
1196 MacHeader = (EtherHeader *) (UINTN) Cpb->MediaHeader;
1197 //
1198 // we don't swap the protocol bytes
1199 //
1200 MacHeader->type = Cpb->Protocol;
1201
1202 for (Index = 0; Index < PXE_HWADDR_LEN_ETHER; Index++) {
1203 MacHeader->dest_addr[Index] = Cpb->DestAddr[Index];
1204 MacHeader->src_addr[Index] = Cpb->SrcAddr[Index];
1205 }
1206 }
1207
1208 return ;
1209 }
1210
1211 VOID
1212 UNDI_Transmit (
1213 IN PXE_CDB *CdbPtr,
1214 IN NIC_DATA_INSTANCE *AdapterInfo
1215 )
1216 /*++
1217
1218 Routine Description:
1219 This routine is used to place a packet into the transmit queue. The data buffers given to
1220 this command are to be considered locked and the application or network driver loses
1221 ownership of these buffers and must not free or relocate them until the ownership returns.
1222
1223 When the packets are transmitted, a transmit complete interrupt is generated (if interrupts
1224 are disabled, the transmit interrupt status is still set and can be checked using the UNDI_Status
1225 command.
1226
1227 Some implementations and adapters support transmitting multiple packets with one transmit
1228 command. If this feature is supported, the transmit CPBs can be linked in one transmit
1229 command.
1230
1231 All UNDIs support fragmented frames, now all network devices or protocols do. If a fragmented
1232 frame CPB is given to UNDI and the network device does not support fragmented frames
1233 (see !PXE.Implementation flag), the UNDI will have to copy the fragments into a local buffer
1234 before transmitting.
1235
1236
1237 Arguments:
1238 CdbPtr - Pointer to the command descriptor block.
1239 AdapterInfo - Pointer to the NIC data structure information which the UNDI driver is layering on..
1240
1241 Returns:
1242 None
1243
1244 --*/
1245 {
1246
1247 if (CdbPtr->CPBsize == PXE_CPBSIZE_NOT_USED) {
1248 CdbPtr->StatFlags = PXE_STATFLAGS_COMMAND_FAILED;
1249 CdbPtr->StatCode = PXE_STATCODE_INVALID_CDB;
1250 return ;
1251 }
1252
1253 CdbPtr->StatCode = (PXE_STATCODE) E100bTransmit (AdapterInfo, CdbPtr->CPBaddr, CdbPtr->OpFlags);
1254
1255 if (CdbPtr->StatCode != PXE_STATCODE_SUCCESS) {
1256 CdbPtr->StatFlags = PXE_STATFLAGS_COMMAND_FAILED;
1257 }
1258
1259 return ;
1260 }
1261
1262 VOID
1263 UNDI_Receive (
1264 IN PXE_CDB *CdbPtr,
1265 IN NIC_DATA_INSTANCE *AdapterInfo
1266 )
1267 /*++
1268
1269 Routine Description:
1270 When the network adapter has received a frame, this command is used to copy the frame
1271 into the driver/application storage location. Once a frame has been copied, it is
1272 removed from the receive queue.
1273
1274 Arguments:
1275 CdbPtr - Pointer to the command descriptor block.
1276 AdapterInfo - Pointer to the NIC data structure information which the UNDI driver is layering on..
1277
1278 Returns:
1279 None
1280
1281 --*/
1282 {
1283
1284 //
1285 // check if RU has started...
1286 //
1287 if (!AdapterInfo->Receive_Started) {
1288 CdbPtr->StatFlags = PXE_STATFLAGS_COMMAND_FAILED;
1289 CdbPtr->StatCode = PXE_STATCODE_NOT_INITIALIZED;
1290 return ;
1291 }
1292
1293
1294 CdbPtr->StatCode = (UINT16) E100bReceive (AdapterInfo, CdbPtr->CPBaddr, CdbPtr->DBaddr);
1295 if (CdbPtr->StatCode != PXE_STATCODE_SUCCESS) {
1296 CdbPtr->StatFlags = PXE_STATFLAGS_COMMAND_FAILED;
1297
1298 }
1299
1300 return ;
1301 }
1302
1303 VOID
1304 UNDI_APIEntry_old (
1305 IN UINT64 cdb
1306 )
1307 /*++
1308
1309 Routine Description:
1310 This is the main SW UNDI API entry using the older nii protocol.
1311 The parameter passed in is a 64 bit flat model virtual
1312 address of the cdb. We then jump into the common routine for both old and
1313 new nii protocol entries.
1314
1315 Arguments:
1316 CdbPtr - Pointer to the command descriptor block.
1317 AdapterInfo - Pointer to the NIC data structure information which the UNDI driver is layering on..
1318
1319 Returns:
1320 None
1321
1322 --*/
1323 // TODO: cdb - add argument and description to function comment
1324 {
1325 PXE_CDB *CdbPtr;
1326 NIC_DATA_INSTANCE *AdapterInfo;
1327
1328 if (cdb == (UINT64) 0) {
1329 return ;
1330
1331 }
1332
1333 CdbPtr = (PXE_CDB *) (UINTN) cdb;
1334
1335 if (CdbPtr->IFnum >= pxe->IFcnt) {
1336 CdbPtr->StatFlags = PXE_STATFLAGS_COMMAND_FAILED;
1337 CdbPtr->StatCode = PXE_STATCODE_INVALID_CDB;
1338 return ;
1339 }
1340
1341 AdapterInfo = &(UNDI32DeviceList[CdbPtr->IFnum]->NicInfo);
1342
1343 //
1344 // entering from older entry point
1345 //
1346 AdapterInfo->VersionFlag = 0x30;
1347 UNDI_APIEntry_Common (cdb);
1348 }
1349
1350 VOID
1351 UNDI_APIEntry_new (
1352 IN UINT64 cdb
1353 )
1354 /*++
1355
1356 Routine Description:
1357 This is the main SW UNDI API entry using the newer nii protocol.
1358 The parameter passed in is a 64 bit flat model virtual
1359 address of the cdb. We then jump into the common routine for both old and
1360 new nii protocol entries.
1361
1362 Arguments:
1363 CdbPtr - Pointer to the command descriptor block.
1364 AdapterInfo - Pointer to the NIC data structure information which the UNDI driver is layering on..
1365
1366 Returns:
1367 None
1368
1369 --*/
1370 // TODO: cdb - add argument and description to function comment
1371 {
1372 PXE_CDB *CdbPtr;
1373 NIC_DATA_INSTANCE *AdapterInfo;
1374
1375 if (cdb == (UINT64) 0) {
1376 return ;
1377
1378 }
1379
1380 CdbPtr = (PXE_CDB *) (UINTN) cdb;
1381
1382 if (CdbPtr->IFnum >= pxe_31->IFcnt) {
1383 CdbPtr->StatFlags = PXE_STATFLAGS_COMMAND_FAILED;
1384 CdbPtr->StatCode = PXE_STATCODE_INVALID_CDB;
1385 return ;
1386 }
1387
1388 AdapterInfo = &(UNDI32DeviceList[CdbPtr->IFnum]->NicInfo);
1389 //
1390 // entering from older entry point
1391 //
1392 AdapterInfo->VersionFlag = 0x31;
1393 UNDI_APIEntry_Common (cdb);
1394 }
1395
1396 VOID
1397 UNDI_APIEntry_Common (
1398 IN UINT64 cdb
1399 )
1400 /*++
1401
1402 Routine Description:
1403 This is the common routine for both old and new entry point procedures.
1404 The parameter passed in is a 64 bit flat model virtual
1405 address of the cdb. We then jump into the service routine pointed to by the
1406 Api_Table[OpCode].
1407
1408 Arguments:
1409 CdbPtr - Pointer to the command descriptor block.
1410 AdapterInfo - Pointer to the NIC data structure information which the UNDI driver is layering on..
1411
1412 Returns:
1413 None
1414
1415 --*/
1416 // TODO: cdb - add argument and description to function comment
1417 {
1418 PXE_CDB *CdbPtr;
1419 NIC_DATA_INSTANCE *AdapterInfo;
1420 UNDI_CALL_TABLE *tab_ptr;
1421
1422 CdbPtr = (PXE_CDB *) (UINTN) cdb;
1423
1424 //
1425 // check the OPCODE range
1426 //
1427 if ((CdbPtr->OpCode > PXE_OPCODE_LAST_VALID) ||
1428 (CdbPtr->StatCode != PXE_STATCODE_INITIALIZE) ||
1429 (CdbPtr->StatFlags != PXE_STATFLAGS_INITIALIZE) ||
1430 (CdbPtr->IFnum >= pxe_31->IFcnt) ) {
1431 goto badcdb;
1432
1433 }
1434
1435 if (CdbPtr->CPBsize == PXE_CPBSIZE_NOT_USED) {
1436 if (CdbPtr->CPBaddr != PXE_CPBADDR_NOT_USED) {
1437 goto badcdb;
1438 }
1439 } else if (CdbPtr->CPBaddr == PXE_CPBADDR_NOT_USED) {
1440 goto badcdb;
1441 }
1442
1443 if (CdbPtr->DBsize == PXE_DBSIZE_NOT_USED) {
1444 if (CdbPtr->DBaddr != PXE_DBADDR_NOT_USED) {
1445 goto badcdb;
1446 }
1447 } else if (CdbPtr->DBaddr == PXE_DBADDR_NOT_USED) {
1448 goto badcdb;
1449 }
1450
1451 //
1452 // check if cpbsize and dbsize are as needed
1453 // check if opflags are as expected
1454 //
1455 tab_ptr = &api_table[CdbPtr->OpCode];
1456
1457 if (tab_ptr->cpbsize != (UINT16) (DONT_CHECK) && tab_ptr->cpbsize != CdbPtr->CPBsize) {
1458 goto badcdb;
1459 }
1460
1461 if (tab_ptr->dbsize != (UINT16) (DONT_CHECK) && tab_ptr->dbsize != CdbPtr->DBsize) {
1462 goto badcdb;
1463 }
1464
1465 if (tab_ptr->opflags != (UINT16) (DONT_CHECK) && tab_ptr->opflags != CdbPtr->OpFlags) {
1466 goto badcdb;
1467
1468 }
1469
1470 AdapterInfo = &(UNDI32DeviceList[CdbPtr->IFnum]->NicInfo);
1471
1472 //
1473 // check if UNDI_State is valid for this call
1474 //
1475 if (tab_ptr->state != (UINT16) (-1)) {
1476 //
1477 // should atleast be started
1478 //
1479 if (AdapterInfo->State == PXE_STATFLAGS_GET_STATE_STOPPED) {
1480 CdbPtr->StatFlags = PXE_STATFLAGS_COMMAND_FAILED;
1481 CdbPtr->StatCode = PXE_STATCODE_NOT_STARTED;
1482 return ;
1483 }
1484 //
1485 // check if it should be initialized
1486 //
1487 if (tab_ptr->state == 2) {
1488 if (AdapterInfo->State != PXE_STATFLAGS_GET_STATE_INITIALIZED) {
1489 CdbPtr->StatCode = PXE_STATCODE_NOT_INITIALIZED;
1490 CdbPtr->StatFlags = PXE_STATFLAGS_COMMAND_FAILED;
1491 return ;
1492 }
1493 }
1494 }
1495 //
1496 // set the return variable for success case here
1497 //
1498 CdbPtr->StatFlags = PXE_STATFLAGS_COMMAND_COMPLETE;
1499 CdbPtr->StatCode = PXE_STATCODE_SUCCESS;
1500
1501 tab_ptr->api_ptr (CdbPtr, AdapterInfo);
1502 return ;
1503 //
1504 // %% AVL - check for command linking
1505 //
1506 badcdb:
1507 CdbPtr->StatFlags = PXE_STATFLAGS_COMMAND_FAILED;
1508 CdbPtr->StatCode = PXE_STATCODE_INVALID_CDB;
1509 return ;
1510 }
1511
1512 STATIC
1513 UINT8
1514 ChkSum (
1515 IN VOID *Buffer,
1516 IN UINT16 Len
1517 )
1518 /*++
1519
1520 Routine Description:
1521 This does an 8 bit check sum of the passed in buffer for Len bytes.
1522 This is primarily used to update the check sum in the SW UNDI header.
1523
1524 Arguments:
1525 Buffer - Pointer to the passed in buffer to check sum
1526 Len - Length of buffer to be check summed in bytes.
1527
1528 Returns:
1529 None
1530
1531 --*/
1532 {
1533 UINT8 Chksum;
1534 INT8 *Bp;
1535
1536 Chksum = 0;
1537 if ((Bp = Buffer) != NULL) {
1538 while (Len--) {
1539 Chksum = (UINT8) (Chksum +*Bp++);
1540
1541 }
1542
1543 }
1544
1545 return Chksum;
1546 }
1547
1548 VOID
1549 PxeUpdate (
1550 IN NIC_DATA_INSTANCE *NicPtr,
1551 IN PXE_SW_UNDI *PxePtr
1552 )
1553 /*++
1554
1555 Routine Description:
1556 When called with a null NicPtr, this routine decrements the number of NICs
1557 this UNDI is supporting and removes the NIC_DATA_POINTER from the array.
1558 Otherwise, it increments the number of NICs this UNDI is supported and
1559 updates the pxe.Fudge to ensure a proper check sum results.
1560
1561 Arguments:
1562 NicPtr - Pointer to the NIC data structure.
1563
1564 Returns:
1565 None
1566
1567 --*/
1568 // TODO: PxePtr - add argument and description to function comment
1569 {
1570 if (NicPtr == NULL) {
1571 if (PxePtr->IFcnt > 0) {
1572 //
1573 // number of NICs this undi supports
1574 //
1575 PxePtr->IFcnt--;
1576 }
1577
1578 PxePtr->Fudge = (UINT8) (PxePtr->Fudge - ChkSum ((VOID *) PxePtr, PxePtr->Len));
1579 return ;
1580 }
1581
1582 //
1583 // number of NICs this undi supports
1584 //
1585 PxePtr->IFcnt++;
1586 PxePtr->Fudge = (UINT8) (PxePtr->Fudge - ChkSum ((VOID *) PxePtr, PxePtr->Len));
1587
1588 return ;
1589 }
1590
1591 VOID
1592 PxeStructInit (
1593 IN PXE_SW_UNDI *PxePtr,
1594 IN UINTN VersionFlag
1595 )
1596 /*++
1597
1598 Routine Description:
1599 Initialize the !PXE structure
1600
1601 Arguments:
1602 RemainingDevicePath - Not used, always produce all possible children.
1603
1604 Returns:
1605 EFI_SUCCESS - This driver is added to Controller.
1606 other - This driver does not support this device.
1607
1608 --*/
1609 // TODO: PxePtr - add argument and description to function comment
1610 // TODO: VersionFlag - add argument and description to function comment
1611 {
1612 //
1613 // Initialize the !PXE structure
1614 //
1615 PxePtr->Signature = PXE_ROMID_SIGNATURE;
1616 PxePtr->Len = sizeof (PXE_SW_UNDI);
1617 //
1618 // cksum
1619 //
1620 PxePtr->Fudge = 0;
1621 //
1622 // number of NICs this undi supports
1623 //
1624 PxePtr->IFcnt = 0;
1625 PxePtr->Rev = PXE_ROMID_REV;
1626 PxePtr->MajorVer = PXE_ROMID_MAJORVER;
1627 PxePtr->MinorVer = PXE_ROMID_MINORVER;
1628 PxePtr->reserved1 = 0;
1629
1630 PxePtr->Implementation = PXE_ROMID_IMP_SW_VIRT_ADDR |
1631 PXE_ROMID_IMP_FRAG_SUPPORTED |
1632 PXE_ROMID_IMP_CMD_LINK_SUPPORTED |
1633 PXE_ROMID_IMP_NVDATA_READ_ONLY |
1634 PXE_ROMID_IMP_STATION_ADDR_SETTABLE |
1635 PXE_ROMID_IMP_PROMISCUOUS_MULTICAST_RX_SUPPORTED |
1636 PXE_ROMID_IMP_PROMISCUOUS_RX_SUPPORTED |
1637 PXE_ROMID_IMP_BROADCAST_RX_SUPPORTED |
1638 PXE_ROMID_IMP_FILTERED_MULTICAST_RX_SUPPORTED |
1639 PXE_ROMID_IMP_SOFTWARE_INT_SUPPORTED |
1640 PXE_ROMID_IMP_PACKET_RX_INT_SUPPORTED;
1641
1642 if (VersionFlag == 0x30) {
1643 PxePtr->EntryPoint = (UINT64) UNDI_APIEntry_old;
1644 } else {
1645 PxePtr->EntryPoint = (UINT64) UNDI_APIEntry_new;
1646 PxePtr->MinorVer = PXE_ROMID_MINORVER_31;
1647 }
1648
1649 PxePtr->reserved2[0] = 0;
1650 PxePtr->reserved2[1] = 0;
1651 PxePtr->reserved2[2] = 0;
1652 PxePtr->BusCnt = 1;
1653 PxePtr->BusType[0] = PXE_BUSTYPE_PCI;
1654
1655 PxePtr->Fudge = (UINT8) (PxePtr->Fudge - ChkSum ((VOID *) PxePtr, PxePtr->Len));
1656 }
1657
1658 //
1659 // #pragma data_seg("rtdata") is only recognized by MSFT C compiler.
1660 // But EBC compiler "Intel(R) C Compiler for EFI Byte Code, Version 1.2 Build 20040123"
1661 // does not recognize this pragma.
1662 //
1663 #if defined(_MSC_EXTENSIONS) && !defined(MDE_CPU_EBC)
1664 #pragma data_seg()
1665 #endif