]> git.proxmox.com Git - mirror_edk2.git/blame - NetworkPkg/SnpDxe/Start.c
NetworkPkg: Apply uncrustify changes
[mirror_edk2.git] / NetworkPkg / SnpDxe / Start.c
CommitLineData
b32e18f2 1/** @file\r
4cda7726 2 Implementation of starting a network adapter.\r
d1102dba
LG
3\r
4Copyright (c) 2004 - 2018, Intel Corporation. All rights reserved.<BR>\r
9d510e61 5SPDX-License-Identifier: BSD-2-Clause-Patent\r
b32e18f2 6\r
b32e18f2 7**/\r
8\r
9#include "Snp.h"\r
10\r
b32e18f2 11/**\r
f3816027 12 Call UNDI to start the interface and changes the snp state.\r
b32e18f2 13\r
f3816027 14 @param Snp pointer to snp driver structure.\r
b32e18f2 15\r
f3816027 16 @retval EFI_SUCCESS UNDI is started successfully.\r
17 @retval EFI_DEVICE_ERROR UNDI could not be started.\r
d1102dba 18\r
b32e18f2 19**/\r
20EFI_STATUS\r
4cda7726 21PxeStart (\r
d1050b9d 22 IN SNP_DRIVER *Snp\r
b32e18f2 23 )\r
24{\r
4cda7726 25 PXE_CPB_START_31 *Cpb31;\r
b32e18f2 26\r
d1050b9d 27 Cpb31 = Snp->Cpb;\r
b32e18f2 28 //\r
29 // Initialize UNDI Start CDB for H/W UNDI\r
30 //\r
d1050b9d
MK
31 Snp->Cdb.OpCode = PXE_OPCODE_START;\r
32 Snp->Cdb.OpFlags = PXE_OPFLAGS_NOT_USED;\r
33 Snp->Cdb.CPBsize = PXE_CPBSIZE_NOT_USED;\r
34 Snp->Cdb.DBsize = PXE_DBSIZE_NOT_USED;\r
35 Snp->Cdb.CPBaddr = PXE_CPBADDR_NOT_USED;\r
36 Snp->Cdb.DBaddr = PXE_DBADDR_NOT_USED;\r
37 Snp->Cdb.StatCode = PXE_STATCODE_INITIALIZE;\r
38 Snp->Cdb.StatFlags = PXE_STATFLAGS_INITIALIZE;\r
39 Snp->Cdb.IFnum = Snp->IfNum;\r
40 Snp->Cdb.Control = PXE_CONTROL_LAST_CDB_IN_LIST;\r
b32e18f2 41\r
42 //\r
43 // Make changes to H/W UNDI Start CDB if this is\r
44 // a S/W UNDI.\r
45 //\r
4cda7726 46 if (Snp->IsSwUndi) {\r
d1050b9d
MK
47 Snp->Cdb.CPBsize = (UINT16)sizeof (PXE_CPB_START_31);\r
48 Snp->Cdb.CPBaddr = (UINT64)(UINTN)Cpb31;\r
b32e18f2 49\r
d1050b9d
MK
50 Cpb31->Delay = (UINT64)(UINTN)&SnpUndi32CallbackDelay;\r
51 Cpb31->Block = (UINT64)(UINTN)&SnpUndi32CallbackBlock;\r
b32e18f2 52\r
53 //\r
54 // Virtual == Physical. This can be set to zero.\r
55 //\r
d1050b9d
MK
56 Cpb31->Virt2Phys = (UINT64)(UINTN)0;\r
57 Cpb31->Mem_IO = (UINT64)(UINTN)&SnpUndi32CallbackMemio;\r
b32e18f2 58\r
d1050b9d
MK
59 Cpb31->Map_Mem = (UINT64)(UINTN)&SnpUndi32CallbackMap;\r
60 Cpb31->UnMap_Mem = (UINT64)(UINTN)&SnpUndi32CallbackUnmap;\r
61 Cpb31->Sync_Mem = (UINT64)(UINTN)&SnpUndi32CallbackSync;\r
b32e18f2 62\r
d1050b9d 63 Cpb31->Unique_ID = (UINT64)(UINTN)Snp;\r
b32e18f2 64 }\r
d1050b9d 65\r
b32e18f2 66 //\r
67 // Issue UNDI command and check result.\r
68 //\r
c49ca4a2 69 DEBUG ((DEBUG_NET, "\nsnp->undi.start() "));\r
b32e18f2 70\r
d1050b9d 71 (*Snp->IssueUndi32Command)((UINT64)(UINTN)&Snp->Cdb);\r
b32e18f2 72\r
4cda7726 73 if (Snp->Cdb.StatCode != PXE_STATCODE_SUCCESS) {\r
b32e18f2 74 //\r
75 // UNDI could not be started. Return UNDI error.\r
76 //\r
77 DEBUG (\r
c49ca4a2 78 (DEBUG_ERROR,\r
d1050b9d
MK
79 "\nsnp->undi.start() %xh:%xh\n",\r
80 Snp->Cdb.StatCode,\r
81 Snp->Cdb.StatFlags)\r
b32e18f2 82 );\r
83\r
84 return EFI_DEVICE_ERROR;\r
85 }\r
d1050b9d 86\r
b32e18f2 87 //\r
88 // Set simple network state to Started and return success.\r
89 //\r
4cda7726 90 Snp->Mode.State = EfiSimpleNetworkStarted;\r
b32e18f2 91\r
92 return EFI_SUCCESS;\r
93}\r
94\r
b32e18f2 95/**\r
f3816027 96 Change the state of a network interface from "stopped" to "started."\r
d1102dba 97\r
4cda7726 98 This function starts a network interface. If the network interface successfully\r
99 starts, then EFI_SUCCESS will be returned.\r
100\r
101 @param This A pointer to the EFI_SIMPLE_NETWORK_PROTOCOL instance.\r
102\r
103 @retval EFI_SUCCESS The network interface was started.\r
104 @retval EFI_ALREADY_STARTED The network interface is already in the started state.\r
d1102dba 105 @retval EFI_INVALID_PARAMETER This parameter was NULL or did not point to a valid\r
4cda7726 106 EFI_SIMPLE_NETWORK_PROTOCOL structure.\r
107 @retval EFI_DEVICE_ERROR The command could not be sent to the network interface.\r
108 @retval EFI_UNSUPPORTED This function is not supported by the network interface.\r
b32e18f2 109\r
110**/\r
111EFI_STATUS\r
112EFIAPI\r
4cda7726 113SnpUndi32Start (\r
d1050b9d 114 IN EFI_SIMPLE_NETWORK_PROTOCOL *This\r
b32e18f2 115 )\r
116{\r
117 SNP_DRIVER *Snp;\r
118 EFI_STATUS Status;\r
119 UINTN Index;\r
120 EFI_TPL OldTpl;\r
121\r
122 if (This == NULL) {\r
123 return EFI_INVALID_PARAMETER;\r
124 }\r
125\r
126 Snp = EFI_SIMPLE_NETWORK_DEV_FROM_THIS (This);\r
127\r
128 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
129\r
4cda7726 130 switch (Snp->Mode.State) {\r
d1050b9d
MK
131 case EfiSimpleNetworkStopped:\r
132 break;\r
b32e18f2 133\r
d1050b9d
MK
134 case EfiSimpleNetworkStarted:\r
135 case EfiSimpleNetworkInitialized:\r
136 Status = EFI_ALREADY_STARTED;\r
137 goto ON_EXIT;\r
b32e18f2 138\r
d1050b9d
MK
139 default:\r
140 Status = EFI_DEVICE_ERROR;\r
141 goto ON_EXIT;\r
b32e18f2 142 }\r
143\r
4cda7726 144 Status = PxeStart (Snp);\r
b32e18f2 145 if (EFI_ERROR (Status)) {\r
146 goto ON_EXIT;\r
147 }\r
d1050b9d 148\r
b32e18f2 149 //\r
150 // clear the map_list in SNP structure\r
151 //\r
152 for (Index = 0; Index < MAX_MAP_LENGTH; Index++) {\r
4cda7726 153 Snp->MapList[Index].VirtualAddress = 0;\r
154 Snp->MapList[Index].MapCookie = 0;\r
b32e18f2 155 }\r
156\r
4cda7726 157 Snp->Mode.MCastFilterCount = 0;\r
b32e18f2 158\r
159ON_EXIT:\r
160 gBS->RestoreTPL (OldTpl);\r
161\r
162 return Status;\r
163}\r