]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Universal/Network/SnpDxe/Start.c
eaba03c57dbe657cf8c914ab6d7f2d6990843b6d
[mirror_edk2.git] / MdeModulePkg / Universal / Network / SnpDxe / Start.c
1 /** @file
2 Copyright (c) 2004 - 2007, 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
24 /**
25 this routine calls undi to start the interface and changes the snp state!
26
27 @param snp pointer to snp driver structure
28
29
30 **/
31 EFI_STATUS
32 pxe_start (
33 SNP_DRIVER *snp
34 )
35 {
36 PXE_CPB_START_31 *cpb_31;
37
38 cpb_31 = snp->cpb;
39 //
40 // Initialize UNDI Start CDB for H/W UNDI
41 //
42 snp->cdb.OpCode = PXE_OPCODE_START;
43 snp->cdb.OpFlags = PXE_OPFLAGS_NOT_USED;
44 snp->cdb.CPBsize = PXE_CPBSIZE_NOT_USED;
45 snp->cdb.DBsize = PXE_DBSIZE_NOT_USED;
46 snp->cdb.CPBaddr = PXE_CPBADDR_NOT_USED;
47 snp->cdb.DBaddr = PXE_DBADDR_NOT_USED;
48 snp->cdb.StatCode = PXE_STATCODE_INITIALIZE;
49 snp->cdb.StatFlags = PXE_STATFLAGS_INITIALIZE;
50 snp->cdb.IFnum = snp->if_num;
51 snp->cdb.Control = PXE_CONTROL_LAST_CDB_IN_LIST;
52
53 //
54 // Make changes to H/W UNDI Start CDB if this is
55 // a S/W UNDI.
56 //
57 if (snp->is_swundi) {
58 snp->cdb.CPBsize = sizeof (PXE_CPB_START_31);
59 snp->cdb.CPBaddr = (UINT64)(UINTN) cpb_31;
60
61 cpb_31->Delay = (UINT64)(UINTN) &snp_undi32_callback_delay;
62 cpb_31->Block = (UINT64)(UINTN) &snp_undi32_callback_block;
63
64 //
65 // Virtual == Physical. This can be set to zero.
66 //
67 cpb_31->Virt2Phys = (UINT64)(UINTN) 0;
68 cpb_31->Mem_IO = (UINT64)(UINTN) &snp_undi32_callback_memio;
69
70 cpb_31->Map_Mem = (UINT64)(UINTN) &snp_undi32_callback_map;
71 cpb_31->UnMap_Mem = (UINT64)(UINTN) &snp_undi32_callback_unmap;
72 cpb_31->Sync_Mem = (UINT64)(UINTN) &snp_undi32_callback_sync;
73
74 cpb_31->Unique_ID = (UINT64)(UINTN) snp;
75 }
76 //
77 // Issue UNDI command and check result.
78 //
79 DEBUG ((EFI_D_NET, "\nsnp->undi.start() "));
80
81 (*snp->issue_undi32_command) ((UINT64)(UINTN) &snp->cdb);
82
83 if (snp->cdb.StatCode != PXE_STATCODE_SUCCESS) {
84 //
85 // UNDI could not be started. Return UNDI error.
86 //
87 DEBUG (
88 (EFI_D_ERROR,
89 "\nsnp->undi.start() %xh:%xh\n",
90 snp->cdb.StatCode,
91 snp->cdb.StatFlags)
92 );
93
94 return EFI_DEVICE_ERROR;
95 }
96 //
97 // Set simple network state to Started and return success.
98 //
99 snp->mode.State = EfiSimpleNetworkStarted;
100
101 return EFI_SUCCESS;
102 }
103
104
105 /**
106 This is the SNP interface routine for starting the interface
107 This routine basically retrieves snp structure, checks the SNP state and
108 calls the pxe_start routine to actually do start undi interface
109
110 @param This context pointer
111
112 @retval EFI_INVALID_PARAMETER "This" is Null
113 @retval No SNP driver can be extracted from "This"
114 @retval EFI_ALREADY_STARTED The state of SNP is EfiSimpleNetworkStarted or
115 EfiSimpleNetworkInitialized
116 @retval EFI_DEVICE_ERROR The state of SNP is other than
117 EfiSimpleNetworkStarted,
118 EfiSimpleNetworkInitialized, and
119 EfiSimpleNetworkStopped
120 @retval EFI_SUCCESS UNDI interface is succesfully started
121 @retval Other Error occurs while calling pxe_start function.
122
123 **/
124 EFI_STATUS
125 EFIAPI
126 snp_undi32_start (
127 IN EFI_SIMPLE_NETWORK_PROTOCOL *This
128 )
129 {
130 SNP_DRIVER *Snp;
131 EFI_STATUS Status;
132 UINTN Index;
133 EFI_TPL OldTpl;
134
135 if (This == NULL) {
136 return EFI_INVALID_PARAMETER;
137 }
138
139 Snp = EFI_SIMPLE_NETWORK_DEV_FROM_THIS (This);
140
141 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
142
143 switch (Snp->mode.State) {
144 case EfiSimpleNetworkStopped:
145 break;
146
147 case EfiSimpleNetworkStarted:
148 case EfiSimpleNetworkInitialized:
149 Status = EFI_ALREADY_STARTED;
150 goto ON_EXIT;
151
152 default:
153 Status = EFI_DEVICE_ERROR;
154 goto ON_EXIT;
155 }
156
157 Status = pxe_start (Snp);
158 if (EFI_ERROR (Status)) {
159 goto ON_EXIT;
160 }
161 //
162 // clear the map_list in SNP structure
163 //
164 for (Index = 0; Index < MAX_MAP_LENGTH; Index++) {
165 Snp->map_list[Index].virt = 0;
166 Snp->map_list[Index].map_cookie = 0;
167 }
168
169 Snp->mode.MCastFilterCount = 0;
170
171 ON_EXIT:
172 gBS->RestoreTPL (OldTpl);
173
174 return Status;
175 }