TianoCore EDK2 master
Loading...
Searching...
No Matches
Snp.c
Go to the documentation of this file.
1
10#include "Snp.h"
11
19VOID
20EFIAPI
22 EFI_EVENT Event,
23 VOID *Context
24 )
25{
26 SNP_DRIVER *Snp;
27
28 Snp = (SNP_DRIVER *)Context;
29
30 //
31 // Shutdown and stop UNDI driver
32 //
33 PxeShutdown (Snp);
34 PxeStop (Snp);
35}
36
48EFIAPI
50 UINT64 Cdb
51 )
52{
53 DEBUG ((DEBUG_ERROR, "\nIssueHwUndiCommand() - This should not be called!"));
54
55 if (Cdb == 0) {
56 return EFI_INVALID_PARAMETER;
57 }
58
59 //
60 // %%TBD - For now, nothing is done.
61 //
62 return EFI_UNSUPPORTED;
63}
64
75UINT8
77 VOID *Buffer,
78 UINTN Length
79 )
80{
81 UINT8 *Ptr;
82 UINT8 Cksum;
83
84 Ptr = Buffer;
85 Cksum = 0;
86
87 if ((Ptr == NULL) || (Length == 0)) {
88 return 0;
89 }
90
91 while (Length-- != 0) {
92 Cksum = (UINT8)(Cksum + *Ptr++);
93 }
94
95 return Cksum;
96}
97
117EFIAPI
120 IN EFI_HANDLE Controller,
121 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
122 )
123{
124 EFI_STATUS Status;
126 PXE_UNDI *Pxe;
127
128 Status = gBS->OpenProtocol (
129 Controller,
130 &gEfiDevicePathProtocolGuid,
131 NULL,
132 This->DriverBindingHandle,
133 Controller,
134 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
135 );
136 if (EFI_ERROR (Status)) {
137 return Status;
138 }
139
140 Status = gBS->OpenProtocol (
141 Controller,
142 &gEfiNetworkInterfaceIdentifierProtocolGuid_31,
143 (VOID **)&NiiProtocol,
144 This->DriverBindingHandle,
145 Controller,
146 EFI_OPEN_PROTOCOL_BY_DRIVER
147 );
148
149 if (EFI_ERROR (Status)) {
150 if (Status == EFI_ALREADY_STARTED) {
151 DEBUG ((DEBUG_INFO, "Support(): Already Started. on handle %p\n", Controller));
152 }
153
154 return Status;
155 }
156
157 DEBUG ((DEBUG_INFO, "Support(): UNDI3.1 found on handle %p\n", Controller));
158
159 //
160 // check the version, we don't want to connect to the undi16
161 //
162 if (NiiProtocol->Type != EfiNetworkInterfaceUndi) {
163 Status = EFI_UNSUPPORTED;
164 goto Done;
165 }
166
167 //
168 // Check to see if !PXE structure is valid. Paragraph alignment of !PXE structure is required.
169 //
170 if ((NiiProtocol->Id & 0x0F) != 0) {
171 DEBUG ((DEBUG_NET, "\n!PXE structure is not paragraph aligned.\n"));
172 Status = EFI_UNSUPPORTED;
173 goto Done;
174 }
175
176 Pxe = (PXE_UNDI *)(UINTN)(NiiProtocol->Id);
177
178 //
179 // Verify !PXE revisions.
180 //
181 if (Pxe->hw.Signature != PXE_ROMID_SIGNATURE) {
182 DEBUG ((DEBUG_NET, "\n!PXE signature is not valid.\n"));
183 Status = EFI_UNSUPPORTED;
184 goto Done;
185 }
186
187 if (Pxe->hw.Rev < PXE_ROMID_REV) {
188 DEBUG ((DEBUG_NET, "\n!PXE.Rev is not supported.\n"));
189 Status = EFI_UNSUPPORTED;
190 goto Done;
191 }
192
193 if (Pxe->hw.MajorVer < PXE_ROMID_MAJORVER) {
194 DEBUG ((DEBUG_NET, "\n!PXE.MajorVer is not supported.\n"));
195 Status = EFI_UNSUPPORTED;
196 goto Done;
197 } else if ((Pxe->hw.MajorVer == PXE_ROMID_MAJORVER) && (Pxe->hw.MinorVer < PXE_ROMID_MINORVER)) {
198 DEBUG ((DEBUG_NET, "\n!PXE.MinorVer is not supported."));
199 Status = EFI_UNSUPPORTED;
200 goto Done;
201 }
202
203 //
204 // Do S/W UNDI specific checks.
205 //
206 if ((Pxe->hw.Implementation & PXE_ROMID_IMP_HW_UNDI) == 0) {
207 if (Pxe->sw.EntryPoint < Pxe->sw.Len) {
208 DEBUG ((DEBUG_NET, "\n!PXE S/W entry point is not valid."));
209 Status = EFI_UNSUPPORTED;
210 goto Done;
211 }
212
213 if (Pxe->sw.BusCnt == 0) {
214 DEBUG ((DEBUG_NET, "\n!PXE.BusCnt is zero."));
215 Status = EFI_UNSUPPORTED;
216 goto Done;
217 }
218 }
219
220 Status = EFI_SUCCESS;
221 DEBUG ((DEBUG_INFO, "Support(): supported on %p\n", Controller));
222
223Done:
224 gBS->CloseProtocol (
225 Controller,
226 &gEfiNetworkInterfaceIdentifierProtocolGuid_31,
227 This->DriverBindingHandle,
228 Controller
229 );
230
231 return Status;
232}
233
253EFIAPI
256 IN EFI_HANDLE Controller,
257 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
258 )
259{
261 EFI_DEVICE_PATH_PROTOCOL *NiiDevicePath;
262 EFI_STATUS Status;
263 PXE_UNDI *Pxe;
264 SNP_DRIVER *Snp;
265 VOID *Address;
266 EFI_HANDLE Handle;
267 UINT8 BarIndex;
268 PXE_STATFLAGS InitStatFlags;
269 EFI_PCI_IO_PROTOCOL *PciIo;
271 BOOLEAN FoundIoBar;
272 BOOLEAN FoundMemoryBar;
273
274 DEBUG ((DEBUG_NET, "\nSnpNotifyNetworkInterfaceIdentifier() "));
275
276 Status = gBS->OpenProtocol (
277 Controller,
278 &gEfiDevicePathProtocolGuid,
279 (VOID **)&NiiDevicePath,
280 This->DriverBindingHandle,
281 Controller,
282 EFI_OPEN_PROTOCOL_BY_DRIVER
283 );
284
285 if (EFI_ERROR (Status)) {
286 return Status;
287 }
288
289 Status = gBS->LocateDevicePath (
290 &gEfiPciIoProtocolGuid,
291 &NiiDevicePath,
292 &Handle
293 );
294
295 if (EFI_ERROR (Status)) {
296 return Status;
297 }
298
299 Status = gBS->OpenProtocol (
300 Handle,
301 &gEfiPciIoProtocolGuid,
302 (VOID **)&PciIo,
303 This->DriverBindingHandle,
304 Controller,
305 EFI_OPEN_PROTOCOL_GET_PROTOCOL
306 );
307 if (EFI_ERROR (Status)) {
308 return Status;
309 }
310
311 //
312 // Get the NII interface.
313 //
314 Status = gBS->OpenProtocol (
315 Controller,
316 &gEfiNetworkInterfaceIdentifierProtocolGuid_31,
317 (VOID **)&Nii,
318 This->DriverBindingHandle,
319 Controller,
320 EFI_OPEN_PROTOCOL_BY_DRIVER
321 );
322 if (EFI_ERROR (Status)) {
323 gBS->CloseProtocol (
324 Controller,
325 &gEfiDevicePathProtocolGuid,
326 This->DriverBindingHandle,
327 Controller
328 );
329 return Status;
330 }
331
332 DEBUG ((DEBUG_INFO, "Start(): UNDI3.1 found\n"));
333
334 Pxe = (PXE_UNDI *)(UINTN)(Nii->Id);
335
336 if (Calc8BitCksum (Pxe, Pxe->hw.Len) != 0) {
337 DEBUG ((DEBUG_NET, "\n!PXE checksum is not correct.\n"));
338 goto NiiError;
339 }
340
341 if ((Pxe->hw.Implementation & PXE_ROMID_IMP_PROMISCUOUS_RX_SUPPORTED) != 0) {
342 //
343 // We can get any packets.
344 //
345 } else if ((Pxe->hw.Implementation & PXE_ROMID_IMP_BROADCAST_RX_SUPPORTED) != 0) {
346 //
347 // We need to be able to get broadcast packets for DHCP.
348 // If we do not have promiscuous support, we must at least have
349 // broadcast support or we cannot do DHCP!
350 //
351 } else {
352 DEBUG ((DEBUG_NET, "\nUNDI does not have promiscuous or broadcast support."));
353 goto NiiError;
354 }
355
356 //
357 // OK, we like this UNDI, and we know snp is not already there on this handle
358 // Allocate and initialize a new simple network protocol structure.
359 //
360 Status = PciIo->AllocateBuffer (
361 PciIo,
364 SNP_MEM_PAGES (sizeof (SNP_DRIVER)),
365 &Address,
366 0
367 );
368
369 if (Status != EFI_SUCCESS) {
370 DEBUG ((DEBUG_NET, "\nCould not allocate SNP_DRIVER structure.\n"));
371 goto NiiError;
372 }
373
374 Snp = (SNP_DRIVER *)(UINTN)Address;
375
376 ZeroMem (Snp, sizeof (SNP_DRIVER));
377
378 Snp->PciIo = PciIo;
379 Snp->Signature = SNP_DRIVER_SIGNATURE;
380
381 EfiInitializeLock (&Snp->Lock, TPL_NOTIFY);
382
383 Snp->Snp.Revision = EFI_SIMPLE_NETWORK_PROTOCOL_REVISION;
384 Snp->Snp.Start = SnpUndi32Start;
385 Snp->Snp.Stop = SnpUndi32Stop;
386 Snp->Snp.Initialize = SnpUndi32Initialize;
387 Snp->Snp.Reset = SnpUndi32Reset;
388 Snp->Snp.Shutdown = SnpUndi32Shutdown;
389 Snp->Snp.ReceiveFilters = SnpUndi32ReceiveFilters;
390 Snp->Snp.StationAddress = SnpUndi32StationAddress;
391 Snp->Snp.Statistics = SnpUndi32Statistics;
392 Snp->Snp.MCastIpToMac = SnpUndi32McastIpToMac;
393 Snp->Snp.NvData = SnpUndi32NvData;
394 Snp->Snp.GetStatus = SnpUndi32GetStatus;
395 Snp->Snp.Transmit = SnpUndi32Transmit;
396 Snp->Snp.Receive = SnpUndi32Receive;
397 Snp->Snp.WaitForPacket = NULL;
398
399 Snp->Snp.Mode = &Snp->Mode;
400
401 Snp->TxRxBufferSize = 0;
402 Snp->TxRxBuffer = NULL;
403
404 Snp->RecycledTxBuf = AllocatePool (sizeof (UINT64) * SNP_TX_BUFFER_INCREASEMENT);
405 if (Snp->RecycledTxBuf == NULL) {
406 Status = EFI_OUT_OF_RESOURCES;
407 goto Error_DeleteSNP;
408 }
409
410 Snp->MaxRecycledTxBuf = SNP_TX_BUFFER_INCREASEMENT;
411 Snp->RecycledTxBufCount = 0;
412
413 if (Nii->Revision >= EFI_NETWORK_INTERFACE_IDENTIFIER_PROTOCOL_REVISION) {
414 Snp->IfNum = Nii->IfNum;
415 } else {
416 Snp->IfNum = (UINT8)(Nii->IfNum & 0xFF);
417 }
418
419 if ((Pxe->hw.Implementation & PXE_ROMID_IMP_HW_UNDI) != 0) {
420 Snp->IsSwUndi = FALSE;
421 Snp->IssueUndi32Command = &IssueHwUndiCommand;
422 } else {
423 Snp->IsSwUndi = TRUE;
424
425 if ((Pxe->sw.Implementation & PXE_ROMID_IMP_SW_VIRT_ADDR) != 0) {
426 Snp->IssueUndi32Command = (ISSUE_UNDI32_COMMAND)(UINTN)Pxe->sw.EntryPoint;
427 } else {
428 Snp->IssueUndi32Command = (ISSUE_UNDI32_COMMAND)(UINTN)((UINT8)(UINTN)Pxe + Pxe->sw.EntryPoint);
429 }
430 }
431
432 //
433 // Allocate a global CPB and DB buffer for this UNDI interface.
434 // we do this because:
435 //
436 // -UNDI 3.0 wants all the addresses passed to it (even the cpb and db) to be
437 // within 2GB limit, create them here and map them so that when undi calls
438 // v2p callback to check if the physical address is < 2gb, we will pass.
439 //
440 // -This is not a requirement for 3.1 or later UNDIs but the code looks
441 // simpler if we use the same cpb, db variables for both old and new undi
442 // interfaces from all the SNP interface calls (we don't map the buffers
443 // for the newer undi interfaces though)
444 // .
445 // -it is OK to allocate one global set of CPB, DB pair for each UNDI
446 // interface as EFI does not multi-task and so SNP will not be re-entered!
447 //
448 Status = PciIo->AllocateBuffer (
449 PciIo,
452 SNP_MEM_PAGES (4096),
453 &Address,
454 0
455 );
456
457 if (Status != EFI_SUCCESS) {
458 DEBUG ((DEBUG_NET, "\nCould not allocate CPB and DB structures.\n"));
459 goto Error_DeleteSNP;
460 }
461
462 Snp->Cpb = (VOID *)(UINTN)Address;
463 Snp->Db = (VOID *)((UINTN)Address + 2048);
464
465 //
466 // Find the correct BAR to do IO.
467 //
468 // Enumerate through the PCI BARs for the device to determine which one is
469 // the IO BAR. Save the index of the BAR into the adapter info structure.
470 // for regular 32bit BARs, 0 is memory mapped, 1 is io mapped
471 //
472 Snp->MemoryBarIndex = PCI_MAX_BAR;
473 Snp->IoBarIndex = PCI_MAX_BAR;
474 FoundMemoryBar = FALSE;
475 FoundIoBar = FALSE;
476 for (BarIndex = 0; BarIndex < PCI_MAX_BAR; BarIndex++) {
477 Status = PciIo->GetBarAttributes (
478 PciIo,
479 BarIndex,
480 NULL,
481 (VOID **)&BarDesc
482 );
483 if (Status == EFI_UNSUPPORTED) {
484 continue;
485 } else if (EFI_ERROR (Status)) {
486 goto Error_DeleteSNP;
487 }
488
489 if ((!FoundMemoryBar) && (BarDesc->ResType == ACPI_ADDRESS_SPACE_TYPE_MEM)) {
490 Snp->MemoryBarIndex = BarIndex;
491 FoundMemoryBar = TRUE;
492 } else if ((!FoundIoBar) && (BarDesc->ResType == ACPI_ADDRESS_SPACE_TYPE_IO)) {
493 Snp->IoBarIndex = BarIndex;
494 FoundIoBar = TRUE;
495 }
496
497 FreePool (BarDesc);
498
499 if (FoundMemoryBar && FoundIoBar) {
500 break;
501 }
502 }
503
504 Status = PxeStart (Snp);
505
506 if (Status != EFI_SUCCESS) {
507 goto Error_DeleteSNP;
508 }
509
510 Snp->Cdb.OpCode = PXE_OPCODE_GET_INIT_INFO;
511 Snp->Cdb.OpFlags = PXE_OPFLAGS_NOT_USED;
512
513 Snp->Cdb.CPBsize = PXE_CPBSIZE_NOT_USED;
514 Snp->Cdb.CPBaddr = PXE_DBADDR_NOT_USED;
515
516 Snp->Cdb.DBsize = (UINT16)sizeof (Snp->InitInfo);
517 Snp->Cdb.DBaddr = (UINT64)(UINTN)(&Snp->InitInfo);
518
519 Snp->Cdb.StatCode = PXE_STATCODE_INITIALIZE;
520 Snp->Cdb.StatFlags = PXE_STATFLAGS_INITIALIZE;
521
522 Snp->Cdb.IFnum = Snp->IfNum;
523 Snp->Cdb.Control = PXE_CONTROL_LAST_CDB_IN_LIST;
524
525 DEBUG ((DEBUG_NET, "\nSnp->undi.get_init_info() "));
526
527 (*Snp->IssueUndi32Command)((UINT64)(UINTN)&Snp->Cdb);
528
529 //
530 // Save the INIT Stat Code...
531 //
532 InitStatFlags = Snp->Cdb.StatFlags;
533
534 if (Snp->Cdb.StatCode != PXE_STATCODE_SUCCESS) {
535 DEBUG ((DEBUG_NET, "\nSnp->undi.init_info() %xh:%xh\n", Snp->Cdb.StatFlags, Snp->Cdb.StatCode));
536 PxeStop (Snp);
537 goto Error_DeleteSNP;
538 }
539
540 //
541 // Initialize simple network protocol mode structure
542 //
543 Snp->Mode.State = EfiSimpleNetworkStopped;
544 Snp->Mode.HwAddressSize = Snp->InitInfo.HWaddrLen;
545 Snp->Mode.MediaHeaderSize = Snp->InitInfo.MediaHeaderLen;
546 Snp->Mode.MaxPacketSize = Snp->InitInfo.FrameDataLen;
547 Snp->Mode.NvRamAccessSize = Snp->InitInfo.NvWidth;
548 Snp->Mode.NvRamSize = Snp->InitInfo.NvCount * Snp->Mode.NvRamAccessSize;
549 Snp->Mode.IfType = Snp->InitInfo.IFtype;
550 Snp->Mode.MaxMCastFilterCount = Snp->InitInfo.MCastFilterCnt;
551 Snp->Mode.MCastFilterCount = 0;
552
553 switch (InitStatFlags & PXE_STATFLAGS_CABLE_DETECT_MASK) {
554 case PXE_STATFLAGS_CABLE_DETECT_SUPPORTED:
555 Snp->CableDetectSupported = TRUE;
556 break;
557
558 case PXE_STATFLAGS_CABLE_DETECT_NOT_SUPPORTED:
559 default:
560 Snp->CableDetectSupported = FALSE;
561 }
562
563 switch (InitStatFlags & PXE_STATFLAGS_GET_STATUS_NO_MEDIA_MASK) {
564 case PXE_STATFLAGS_GET_STATUS_NO_MEDIA_SUPPORTED:
565 Snp->MediaStatusSupported = TRUE;
566 break;
567
568 case PXE_STATFLAGS_GET_STATUS_NO_MEDIA_NOT_SUPPORTED:
569 default:
570 Snp->MediaStatusSupported = FALSE;
571 }
572
573 if (Snp->CableDetectSupported || Snp->MediaStatusSupported) {
574 Snp->Mode.MediaPresentSupported = TRUE;
575 }
576
577 if ((Pxe->hw.Implementation & PXE_ROMID_IMP_STATION_ADDR_SETTABLE) != 0) {
578 Snp->Mode.MacAddressChangeable = TRUE;
579 } else {
580 Snp->Mode.MacAddressChangeable = FALSE;
581 }
582
583 if ((Pxe->hw.Implementation & PXE_ROMID_IMP_MULTI_FRAME_SUPPORTED) != 0) {
584 Snp->Mode.MultipleTxSupported = TRUE;
585 } else {
586 Snp->Mode.MultipleTxSupported = FALSE;
587 }
588
589 Snp->Mode.ReceiveFilterMask = EFI_SIMPLE_NETWORK_RECEIVE_UNICAST;
590
591 if ((Pxe->hw.Implementation & PXE_ROMID_IMP_PROMISCUOUS_MULTICAST_RX_SUPPORTED) != 0) {
592 Snp->Mode.ReceiveFilterMask |= EFI_SIMPLE_NETWORK_RECEIVE_PROMISCUOUS_MULTICAST;
593 }
594
595 if ((Pxe->hw.Implementation & PXE_ROMID_IMP_PROMISCUOUS_RX_SUPPORTED) != 0) {
596 Snp->Mode.ReceiveFilterMask |= EFI_SIMPLE_NETWORK_RECEIVE_PROMISCUOUS;
597 }
598
599 if ((Pxe->hw.Implementation & PXE_ROMID_IMP_BROADCAST_RX_SUPPORTED) != 0) {
600 Snp->Mode.ReceiveFilterMask |= EFI_SIMPLE_NETWORK_RECEIVE_BROADCAST;
601 }
602
603 if ((Pxe->hw.Implementation & PXE_ROMID_IMP_FILTERED_MULTICAST_RX_SUPPORTED) != 0) {
604 Snp->Mode.ReceiveFilterMask |= EFI_SIMPLE_NETWORK_RECEIVE_MULTICAST;
605 }
606
607 if ((Pxe->hw.Implementation & PXE_ROMID_IMP_PROMISCUOUS_MULTICAST_RX_SUPPORTED) != 0) {
608 Snp->Mode.ReceiveFilterMask |= EFI_SIMPLE_NETWORK_RECEIVE_PROMISCUOUS_MULTICAST;
609 }
610
611 Snp->Mode.ReceiveFilterSetting = 0;
612
613 //
614 // need to get the station address to save in the mode structure. we need to
615 // initialize the UNDI first for this.
616 //
617 Snp->TxRxBufferSize = Snp->InitInfo.MemoryRequired;
618 Status = PxeInit (Snp, PXE_OPFLAGS_INITIALIZE_DO_NOT_DETECT_CABLE);
619
620 if (EFI_ERROR (Status)) {
621 PxeStop (Snp);
622 goto Error_DeleteSNP;
623 }
624
625 Status = PxeGetStnAddr (Snp);
626
627 if (Status != EFI_SUCCESS) {
628 DEBUG ((DEBUG_ERROR, "\nSnp->undi.get_station_addr() failed.\n"));
629 PxeShutdown (Snp);
630 PxeStop (Snp);
631 goto Error_DeleteSNP;
632 }
633
634 Snp->Mode.MediaPresent = FALSE;
635
636 //
637 // We should not leave UNDI started and initialized here. this DriverStart()
638 // routine must only find and attach the SNP interface to UNDI layer that it
639 // finds on the given handle!
640 // The UNDI layer will be started when upper layers call Snp->start.
641 // How ever, this DriverStart() must fill up the snp mode structure which
642 // contains the MAC address of the NIC. For this reason we started and
643 // initialized UNDI here, now we are done, do a shutdown and stop of the
644 // UNDI interface!
645 //
646 PxeShutdown (Snp);
647 PxeStop (Snp);
648
649 if (PcdGetBool (PcdSnpCreateExitBootServicesEvent)) {
650 //
651 // Create EXIT_BOOT_SERIVES Event
652 //
653 Status = gBS->CreateEventEx (
654 EVT_NOTIFY_SIGNAL,
655 TPL_CALLBACK,
657 Snp,
658 &gEfiEventExitBootServicesGuid,
659 &Snp->ExitBootServicesEvent
660 );
661 if (EFI_ERROR (Status)) {
662 goto Error_DeleteSNP;
663 }
664 }
665
666 //
667 // add SNP to the undi handle
668 //
669 Status = gBS->InstallProtocolInterface (
670 &Controller,
671 &gEfiSimpleNetworkProtocolGuid,
673 &(Snp->Snp)
674 );
675
676 if (!EFI_ERROR (Status)) {
677 return Status;
678 }
679
680 PciIo->FreeBuffer (
681 PciIo,
682 SNP_MEM_PAGES (4096),
683 Snp->Cpb
684 );
685
686Error_DeleteSNP:
687
688 if (Snp->RecycledTxBuf != NULL) {
689 FreePool (Snp->RecycledTxBuf);
690 }
691
692 PciIo->FreeBuffer (
693 PciIo,
694 SNP_MEM_PAGES (sizeof (SNP_DRIVER)),
695 Snp
696 );
697NiiError:
698 gBS->CloseProtocol (
699 Controller,
700 &gEfiNetworkInterfaceIdentifierProtocolGuid_31,
701 This->DriverBindingHandle,
702 Controller
703 );
704
705 gBS->CloseProtocol (
706 Controller,
707 &gEfiDevicePathProtocolGuid,
708 This->DriverBindingHandle,
709 Controller
710 );
711
712 //
713 // If we got here that means we are in error state.
714 //
715 if (!EFI_ERROR (Status)) {
716 Status = EFI_DEVICE_ERROR;
717 }
718
719 return Status;
720}
721
741EFIAPI
744 IN EFI_HANDLE Controller,
745 IN UINTN NumberOfChildren,
746 IN EFI_HANDLE *ChildHandleBuffer
747 )
748{
749 EFI_STATUS Status;
750 EFI_SIMPLE_NETWORK_PROTOCOL *SnpProtocol;
751 SNP_DRIVER *Snp;
752 EFI_PCI_IO_PROTOCOL *PciIo;
753
754 //
755 // Get our context back.
756 //
757 Status = gBS->OpenProtocol (
758 Controller,
759 &gEfiSimpleNetworkProtocolGuid,
760 (VOID **)&SnpProtocol,
761 This->DriverBindingHandle,
762 Controller,
763 EFI_OPEN_PROTOCOL_GET_PROTOCOL
764 );
765
766 if (EFI_ERROR (Status)) {
767 return EFI_UNSUPPORTED;
768 }
769
770 Snp = EFI_SIMPLE_NETWORK_DEV_FROM_THIS (SnpProtocol);
771
772 Status = gBS->UninstallProtocolInterface (
773 Controller,
774 &gEfiSimpleNetworkProtocolGuid,
775 &Snp->Snp
776 );
777
778 if (EFI_ERROR (Status)) {
779 return Status;
780 }
781
782 if (PcdGetBool (PcdSnpCreateExitBootServicesEvent)) {
783 //
784 // Close EXIT_BOOT_SERVICES Event
785 //
786 gBS->CloseEvent (Snp->ExitBootServicesEvent);
787 }
788
789 Status = gBS->CloseProtocol (
790 Controller,
791 &gEfiNetworkInterfaceIdentifierProtocolGuid_31,
792 This->DriverBindingHandle,
793 Controller
794 );
795
796 Status = gBS->CloseProtocol (
797 Controller,
798 &gEfiDevicePathProtocolGuid,
799 This->DriverBindingHandle,
800 Controller
801 );
802
803 PxeShutdown (Snp);
804 PxeStop (Snp);
805
806 FreePool (Snp->RecycledTxBuf);
807
808 PciIo = Snp->PciIo;
809 PciIo->FreeBuffer (
810 PciIo,
811 SNP_MEM_PAGES (4096),
812 Snp->Cpb
813 );
814
815 PciIo->FreeBuffer (
816 PciIo,
817 SNP_MEM_PAGES (sizeof (SNP_DRIVER)),
818 Snp
819 );
820
821 return Status;
822}
823
824//
825// Simple Network Protocol Driver Global Variables
826//
827EFI_DRIVER_BINDING_PROTOCOL gSimpleNetworkDriverBinding = {
831 0xa,
832 NULL,
833 NULL
834};
835
851EFIAPI
853 IN EFI_HANDLE ImageHandle,
854 IN EFI_SYSTEM_TABLE *SystemTable
855 )
856{
858 ImageHandle,
859 SystemTable,
860 &gSimpleNetworkDriverBinding,
861 ImageHandle,
862 &gSimpleNetworkComponentName,
863 &gSimpleNetworkComponentName2
864 );
865}
UINT64 UINTN
PACKED struct @89 EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
VOID *EFIAPI ZeroMem(OUT VOID *Buffer, IN UINTN Length)
VOID EFIAPI FreePool(IN VOID *Buffer)
EFI_STATUS EFIAPI SnpUndi32GetStatus(IN EFI_SIMPLE_NETWORK_PROTOCOL *This, OUT UINT32 *InterruptStatus OPTIONAL, OUT VOID **TxBuf OPTIONAL)
Definition: Get_status.c:199
EFI_STATUS EFIAPI SnpUndi32McastIpToMac(IN EFI_SIMPLE_NETWORK_PROTOCOL *This, IN BOOLEAN IPv6, IN EFI_IP_ADDRESS *IP, OUT EFI_MAC_ADDRESS *MAC)
#define NULL
Definition: Base.h:319
#define TRUE
Definition: Base.h:301
#define FALSE
Definition: Base.h:307
#define IN
Definition: Base.h:279
#define DEBUG(Expression)
Definition: DebugLib.h:434
EFI_STATUS PxeInit(SNP_DRIVER *Snp, UINT16 CableDetectFlag)
Definition: Initialize.c:24
EFI_STATUS EFIAPI SnpUndi32Initialize(IN EFI_SIMPLE_NETWORK_PROTOCOL *This, IN UINTN ExtraRxBufferSize OPTIONAL, IN UINTN ExtraTxBufferSize OPTIONAL)
Definition: Initialize.c:181
EFI_STATUS EFIAPI SnpUndi32Reset(IN EFI_SIMPLE_NETWORK_PROTOCOL *This, IN BOOLEAN ExtendedVerification)
Definition: Reset.c:87
EFI_STATUS EFIAPI SnpUndi32NvData(IN EFI_SIMPLE_NETWORK_PROTOCOL *This, IN BOOLEAN ReadWrite, IN UINTN Offset, IN UINTN BufferSize, IN OUT VOID *Buffer)
Definition: Nvdata.c:144
#define PcdGetBool(TokenName)
Definition: PcdLib.h:401
VOID *EFIAPI AllocatePool(IN UINTN AllocationSize)
EFI_STATUS EFIAPI SnpUndi32Receive(IN EFI_SIMPLE_NETWORK_PROTOCOL *This, OUT UINTN *HeaderSize OPTIONAL, IN OUT UINTN *BufferSize, OUT VOID *Buffer, OUT EFI_MAC_ADDRESS *SrcAddr OPTIONAL, OUT EFI_MAC_ADDRESS *DestAddr OPTIONAL, OUT UINT16 *Protocol OPTIONAL)
Definition: Receive.c:191
EFI_STATUS EFIAPI SnpUndi32ReceiveFilters(IN EFI_SIMPLE_NETWORK_PROTOCOL *This, IN UINT32 Enable, IN UINT32 Disable, IN BOOLEAN ResetMCastFilter, IN UINTN MCastFilterCnt OPTIONAL, IN EFI_MAC_ADDRESS *MCastFilter OPTIONAL)
EFI_STATUS EFIAPI SnpUndi32Shutdown(IN EFI_SIMPLE_NETWORK_PROTOCOL *This)
Definition: Shutdown.c:90
EFI_STATUS PxeShutdown(IN SNP_DRIVER *Snp)
Definition: Shutdown.c:21
EFI_STATUS EFIAPI SimpleNetworkDriverSupported(IN EFI_DRIVER_BINDING_PROTOCOL *This, IN EFI_HANDLE Controller, IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath)
Definition: Snp.c:118
EFI_STATUS EFIAPI InitializeSnpNiiDriver(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
Definition: Snp.c:852
UINT8 Calc8BitCksum(VOID *Buffer, UINTN Length)
Definition: Snp.c:76
VOID EFIAPI SnpNotifyExitBootServices(EFI_EVENT Event, VOID *Context)
Definition: Snp.c:21
EFI_STATUS EFIAPI IssueHwUndiCommand(UINT64 Cdb)
Definition: Snp.c:49
EFI_STATUS EFIAPI SimpleNetworkDriverStop(IN EFI_DRIVER_BINDING_PROTOCOL *This, IN EFI_HANDLE Controller, IN UINTN NumberOfChildren, IN EFI_HANDLE *ChildHandleBuffer)
Definition: Snp.c:742
EFI_STATUS EFIAPI SimpleNetworkDriverStart(IN EFI_DRIVER_BINDING_PROTOCOL *This, IN EFI_HANDLE Controller, IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath)
Definition: Snp.c:254
EFI_STATUS PxeStop(SNP_DRIVER *Snp)
Definition: Stop.c:21
EFI_STATUS PxeGetStnAddr(SNP_DRIVER *Snp)
EFI_STATUS PxeStart(IN SNP_DRIVER *Snp)
Definition: Start.c:21
EFI_STATUS EFIAPI SnpUndi32Stop(IN EFI_SIMPLE_NETWORK_PROTOCOL *This)
Definition: Stop.c:84
EFI_STATUS EFIAPI SnpUndi32Statistics(IN EFI_SIMPLE_NETWORK_PROTOCOL *This, IN BOOLEAN Reset, IN OUT UINTN *StatisticsSize OPTIONAL, IN OUT EFI_NETWORK_STATISTICS *StatisticsTable OPTIONAL)
Definition: Statistics.c:60
EFI_STATUS EFIAPI SnpUndi32Transmit(IN EFI_SIMPLE_NETWORK_PROTOCOL *This, IN UINTN HeaderSize, IN UINTN BufferSize, IN VOID *Buffer, IN EFI_MAC_ADDRESS *SrcAddr OPTIONAL, IN EFI_MAC_ADDRESS *DestAddr OPTIONAL, IN UINT16 *Protocol OPTIONAL)
Definition: Transmit.c:270
EFI_STATUS EFIAPI SnpUndi32StationAddress(IN EFI_SIMPLE_NETWORK_PROTOCOL *This, IN BOOLEAN Reset, IN EFI_MAC_ADDRESS *New OPTIONAL)
EFI_STATUS EFIAPI SnpUndi32Start(IN EFI_SIMPLE_NETWORK_PROTOCOL *This)
Definition: Start.c:113
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
VOID * EFI_EVENT
Definition: UefiBaseType.h:37
VOID * EFI_HANDLE
Definition: UefiBaseType.h:33
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
EFI_BOOT_SERVICES * gBS
EFI_LOCK *EFIAPI EfiInitializeLock(IN OUT EFI_LOCK *Lock, IN EFI_TPL Priority)
Definition: UefiLib.c:405
EFI_STATUS EFIAPI EfiLibInstallDriverBindingComponentName2(IN CONST EFI_HANDLE ImageHandle, IN CONST EFI_SYSTEM_TABLE *SystemTable, IN EFI_DRIVER_BINDING_PROTOCOL *DriverBinding, IN EFI_HANDLE DriverBindingHandle, IN CONST EFI_COMPONENT_NAME_PROTOCOL *ComponentName OPTIONAL, IN CONST EFI_COMPONENT_NAME2_PROTOCOL *ComponentName2 OPTIONAL)
@ EfiBootServicesData
#define PXE_ROMID_MAJORVER
Definition: UefiPxe.h:844
#define PXE_CPBSIZE_NOT_USED
zero
Definition: UefiPxe.h:57
PXE_UINT16 PXE_STATFLAGS
Definition: UefiPxe.h:401
#define PXE_ROMID_REV
Definition: UefiPxe.h:837
#define PXE_ROMID_SIGNATURE
Definition: UefiPxe.h:832
#define PXE_DBADDR_NOT_USED
zero
Definition: UefiPxe.h:60
#define PXE_ROMID_IMP_HW_UNDI
Definition: UefiPxe.h:850
#define PXE_STATFLAGS_CABLE_DETECT_MASK
Definition: UefiPxe.h:435
#define PXE_OPCODE_GET_INIT_INFO
Definition: UefiPxe.h:100
#define PXE_STATCODE_SUCCESS
Definition: UefiPxe.h:602
@ EFI_NATIVE_INTERFACE
Definition: UefiSpec.h:1193
@ AllocateAnyPages
Definition: UefiSpec.h:33
UINT64 Revision
The revision of the EFI_NETWORK_INTERFACE_IDENTIFIER protocol.
EFI_SIMPLE_NETWORK_MODE * Mode
Definition: Snp.h:55
PXE_UINT16 NvWidth
Definition: UefiPxe.h:1122
PXE_UINT32 MemoryRequired
Definition: UefiPxe.h:1100
PXE_UINT32 FrameDataLen
Definition: UefiPxe.h:1105
PXE_UINT32 NvCount
Definition: UefiPxe.h:1117
PXE_UINT16 HWaddrLen
Definition: UefiPxe.h:1134
PXE_UINT16 MCastFilterCnt
Definition: UefiPxe.h:1140
PXE_UINT16 MediaHeaderLen
Definition: UefiPxe.h:1129
PXE_UINT32 Implementation
Definition: UefiPxe.h:720
PXE_UINT8 Len
sizeof(PXE_HW_UNDI).
Definition: UefiPxe.h:712
PXE_UINT32 Signature
PXE_ROMID_SIGNATURE.
Definition: UefiPxe.h:711
PXE_UINT8 Rev
PXE_ROMID_REV.
Definition: UefiPxe.h:714
PXE_UINT8 MinorVer
PXE_ROMID_MINORVER.
Definition: UefiPxe.h:717
PXE_UINT8 MajorVer
PXE_ROMID_MAJORVER.
Definition: UefiPxe.h:716
PXE_UINT32 Implementation
Implementation flags.
Definition: UefiPxe.h:817
PXE_UINT64 EntryPoint
API entry point.
Definition: UefiPxe.h:818
PXE_UINT8 Len
sizeof(PXE_SW_UNDI).
Definition: UefiPxe.h:809
PXE_UINT8 BusCnt
number of bustypes supported.
Definition: UefiPxe.h:820