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