]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Universal/Network/SnpDxe/start.c
1. Sync the latest network stack. Add NetLibCreateIPv4DPathNode () in netlib library.
[mirror_edk2.git] / MdeModulePkg / Universal / Network / SnpDxe / start.c
CommitLineData
8a67d61d 1/** @file\r
2Copyright (c) 2004 - 2007, Intel Corporation\r
3All rights reserved. This program and the accompanying materials\r
4are licensed and made available under the terms and conditions of the BSD License\r
5which accompanies this distribution. The full text of the license may be found at\r
6http://opensource.org/licenses/bsd-license.php\r
7\r
8THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
9WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
10\r
11Module name:\r
12 start.c\r
13\r
14Abstract:\r
15\r
16Revision history:\r
17 2000-Feb-07 M(f)J Genesis.\r
18\r
19**/\r
20\r
21#include "Snp.h"\r
22\r
23\r
24/**\r
25 this routine calls undi to start the interface and changes the snp state!\r
26\r
27 @param snp pointer to snp driver structure\r
28\r
29\r
30**/\r
31EFI_STATUS\r
32pxe_start (\r
33 SNP_DRIVER *snp\r
34 )\r
35{\r
772db4bb 36 PXE_CPB_START_30 *cpb;\r
8a67d61d 37 PXE_CPB_START_31 *cpb_31;\r
38\r
39 cpb = snp->cpb;\r
40 cpb_31 = snp->cpb;\r
41 //\r
42 // Initialize UNDI Start CDB for H/W UNDI\r
43 //\r
44 snp->cdb.OpCode = PXE_OPCODE_START;\r
45 snp->cdb.OpFlags = PXE_OPFLAGS_NOT_USED;\r
46 snp->cdb.CPBsize = PXE_CPBSIZE_NOT_USED;\r
47 snp->cdb.DBsize = PXE_DBSIZE_NOT_USED;\r
48 snp->cdb.CPBaddr = PXE_CPBADDR_NOT_USED;\r
49 snp->cdb.DBaddr = PXE_DBADDR_NOT_USED;\r
50 snp->cdb.StatCode = PXE_STATCODE_INITIALIZE;\r
51 snp->cdb.StatFlags = PXE_STATFLAGS_INITIALIZE;\r
52 snp->cdb.IFnum = snp->if_num;\r
53 snp->cdb.Control = PXE_CONTROL_LAST_CDB_IN_LIST;\r
54\r
55 //\r
56 // Make changes to H/W UNDI Start CDB if this is\r
57 // a S/W UNDI.\r
58 //\r
59 if (snp->is_swundi) {\r
60 if (snp->IsOldUndi) {\r
61 snp->cdb.CPBsize = sizeof (PXE_CPB_START_30);\r
62 snp->cdb.CPBaddr = (UINT64)(UINTN) cpb;\r
63\r
64 cpb->Delay = (UINT64)(UINTN) &snp_undi32_callback_delay_30;\r
65 cpb->Block = (UINT64)(UINTN) &snp_undi32_callback_block_30;\r
66\r
67 //\r
68 // Virtual == Physical. This can be set to zero.\r
69 //\r
70 cpb->Virt2Phys = (UINT64)(UINTN) &snp_undi32_callback_v2p_30;\r
71 cpb->Mem_IO = (UINT64)(UINTN) &snp_undi32_callback_memio_30;\r
72 } else {\r
73 snp->cdb.CPBsize = sizeof (PXE_CPB_START_31);\r
74 snp->cdb.CPBaddr = (UINT64)(UINTN) cpb_31;\r
75\r
76 cpb_31->Delay = (UINT64)(UINTN) &snp_undi32_callback_delay;\r
77 cpb_31->Block = (UINT64)(UINTN) &snp_undi32_callback_block;\r
78\r
79 //\r
80 // Virtual == Physical. This can be set to zero.\r
81 //\r
82 cpb_31->Virt2Phys = (UINT64)(UINTN) 0;\r
83 cpb_31->Mem_IO = (UINT64)(UINTN) &snp_undi32_callback_memio;\r
84\r
85 cpb_31->Map_Mem = (UINT64)(UINTN) &snp_undi32_callback_map;\r
86 cpb_31->UnMap_Mem = (UINT64)(UINTN) &snp_undi32_callback_unmap;\r
87 cpb_31->Sync_Mem = (UINT64)(UINTN) &snp_undi32_callback_sync;\r
88\r
89 cpb_31->Unique_ID = (UINT64)(UINTN) snp;\r
90 }\r
91 }\r
92 //\r
93 // Issue UNDI command and check result.\r
94 //\r
95 DEBUG ((EFI_D_NET, "\nsnp->undi.start() "));\r
96\r
97 (*snp->issue_undi32_command) ((UINT64)(UINTN) &snp->cdb);\r
98\r
99 if (snp->cdb.StatCode != PXE_STATCODE_SUCCESS) {\r
100 //\r
101 // UNDI could not be started. Return UNDI error.\r
102 //\r
103 DEBUG (\r
104 (EFI_D_ERROR,\r
105 "\nsnp->undi.start() %xh:%xh\n",\r
106 snp->cdb.StatCode,\r
107 snp->cdb.StatFlags)\r
108 );\r
109\r
110 return EFI_DEVICE_ERROR;\r
111 }\r
112 //\r
113 // Set simple network state to Started and return success.\r
114 //\r
115 snp->mode.State = EfiSimpleNetworkStarted;\r
116\r
117 return EFI_SUCCESS;\r
118}\r
119\r
120\r
121/**\r
122 This is the SNP interface routine for starting the interface\r
123 This routine basically retrieves snp structure, checks the SNP state and\r
124 calls the pxe_start routine to actually do start undi interface\r
125\r
126 @param This context pointer\r
127\r
128 @retval EFI_INVALID_PARAMETER "This" is Null\r
129 @retval No SNP driver can be extracted from "This"\r
130 @retval EFI_ALREADY_STARTED The state of SNP is EfiSimpleNetworkStarted or\r
131 EfiSimpleNetworkInitialized\r
132 @retval EFI_DEVICE_ERROR The state of SNP is other than\r
133 EfiSimpleNetworkStarted,\r
134 EfiSimpleNetworkInitialized, and\r
135 EfiSimpleNetworkStopped\r
136 @retval EFI_SUCCESS UNDI interface is succesfully started\r
137 @retval Other Error occurs while calling pxe_start function.\r
138\r
139**/\r
140EFI_STATUS\r
141EFIAPI\r
142snp_undi32_start (\r
143 IN EFI_SIMPLE_NETWORK_PROTOCOL *This\r
144 )\r
145{\r
146 SNP_DRIVER *Snp;\r
147 EFI_STATUS Status;\r
148 UINTN Index;\r
149 EFI_TPL OldTpl;\r
150\r
151 if (This == NULL) {\r
152 return EFI_INVALID_PARAMETER;\r
153 }\r
154\r
155 Snp = EFI_SIMPLE_NETWORK_DEV_FROM_THIS (This);\r
156\r
157 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
158\r
159 switch (Snp->mode.State) {\r
160 case EfiSimpleNetworkStopped:\r
161 break;\r
162\r
163 case EfiSimpleNetworkStarted:\r
164 case EfiSimpleNetworkInitialized:\r
165 Status = EFI_ALREADY_STARTED;\r
166 goto ON_EXIT;\r
167\r
168 default:\r
169 Status = EFI_DEVICE_ERROR;\r
170 goto ON_EXIT;\r
171 }\r
172\r
173 Status = pxe_start (Snp);\r
174 if (EFI_ERROR (Status)) {\r
175 goto ON_EXIT;\r
176 }\r
177 //\r
178 // clear the map_list in SNP structure\r
179 //\r
180 for (Index = 0; Index < MAX_MAP_LENGTH; Index++) {\r
181 Snp->map_list[Index].virt = 0;\r
182 Snp->map_list[Index].map_cookie = 0;\r
183 }\r
184\r
185 Snp->mode.MCastFilterCount = 0;\r
186\r
187ON_EXIT:\r
188 gBS->RestoreTPL (OldTpl);\r
189\r
190 return Status;\r
191}\r