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