Move SmmLib from IntelFrameworkPkg to MdePkg because this library is useful to both...
[mirror_edk2.git] / OptionRomPkg / UndiRuntimeDxe / Decode.c
CommitLineData
51ebae6b 1/** @file\r
2 Provides the basic UNID functions.\r
3\r
cd417925 4Copyright (c) 2006 - 2009, Intel Corporation\r
51ebae6b 5All rights reserved. This program and the accompanying materials\r
6are licensed and made available under the terms and conditions of the BSD License\r
7which accompanies this distribution. The full text of the license may be found at\r
8http://opensource.org/licenses/bsd-license.php\r
9\r
10THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
13**/\r
14\r
15#include "Undi32.h"\r
16\r
17//\r
18// Global variables defined in this file\r
19//\r
20UNDI_CALL_TABLE api_table[PXE_OPCODE_LAST_VALID+1] = { \\r
21 {PXE_CPBSIZE_NOT_USED,PXE_DBSIZE_NOT_USED,0, (UINT16)(ANY_STATE),UNDI_GetState },\\r
22 {(UINT16)(DONT_CHECK),PXE_DBSIZE_NOT_USED,0,(UINT16)(ANY_STATE),UNDI_Start },\\r
23 {PXE_CPBSIZE_NOT_USED,PXE_DBSIZE_NOT_USED,0,MUST_BE_STARTED,UNDI_Stop },\\r
24 {PXE_CPBSIZE_NOT_USED,sizeof(PXE_DB_GET_INIT_INFO),0,MUST_BE_STARTED, UNDI_GetInitInfo },\\r
25 {PXE_CPBSIZE_NOT_USED,sizeof(PXE_DB_GET_CONFIG_INFO),0,MUST_BE_STARTED, UNDI_GetConfigInfo },\\r
26 {sizeof(PXE_CPB_INITIALIZE),(UINT16)(DONT_CHECK),(UINT16)(DONT_CHECK),MUST_BE_STARTED,UNDI_Initialize },\\r
27 {PXE_CPBSIZE_NOT_USED,PXE_DBSIZE_NOT_USED,(UINT16)(DONT_CHECK), MUST_BE_INITIALIZED,UNDI_Reset },\\r
28 {PXE_CPBSIZE_NOT_USED,PXE_DBSIZE_NOT_USED,0, MUST_BE_INITIALIZED,UNDI_Shutdown },\\r
29 {PXE_CPBSIZE_NOT_USED,PXE_DBSIZE_NOT_USED,(UINT16)(DONT_CHECK), MUST_BE_INITIALIZED,UNDI_Interrupt },\\r
30 {(UINT16)(DONT_CHECK),(UINT16)(DONT_CHECK),(UINT16)(DONT_CHECK), MUST_BE_INITIALIZED, UNDI_RecFilter },\\r
31 {(UINT16)(DONT_CHECK),(UINT16)(DONT_CHECK),(UINT16)(DONT_CHECK), MUST_BE_INITIALIZED, UNDI_StnAddr },\\r
32 {PXE_CPBSIZE_NOT_USED, (UINT16)(DONT_CHECK), (UINT16)(DONT_CHECK), MUST_BE_INITIALIZED, UNDI_Statistics },\\r
33 {sizeof(PXE_CPB_MCAST_IP_TO_MAC),sizeof(PXE_DB_MCAST_IP_TO_MAC), (UINT16)(DONT_CHECK),MUST_BE_INITIALIZED, UNDI_ip2mac },\\r
34 {(UINT16)(DONT_CHECK),(UINT16)(DONT_CHECK),(UINT16)(DONT_CHECK), MUST_BE_INITIALIZED, UNDI_NVData },\\r
35 {PXE_CPBSIZE_NOT_USED,(UINT16)(DONT_CHECK),(UINT16)(DONT_CHECK), MUST_BE_INITIALIZED, UNDI_Status },\\r
36 {(UINT16)(DONT_CHECK),PXE_DBSIZE_NOT_USED,(UINT16)(DONT_CHECK), MUST_BE_INITIALIZED, UNDI_FillHeader },\\r
37 {(UINT16)(DONT_CHECK),PXE_DBSIZE_NOT_USED,(UINT16)(DONT_CHECK), MUST_BE_INITIALIZED, UNDI_Transmit },\\r
38 {sizeof(PXE_CPB_RECEIVE),sizeof(PXE_DB_RECEIVE),0,MUST_BE_INITIALIZED, UNDI_Receive } \\r
39};\r
40\r
41//\r
42// end of global variables\r
43//\r
44\r
45\r
46/**\r
47 This routine determines the operational state of the UNDI. It updates the state flags in the\r
48 Command Descriptor Block based on information derived from the AdapterInfo instance data.\r
49 To ensure the command has completed successfully, CdbPtr->StatCode will contain the result of\r
50 the command execution.\r
51 The CdbPtr->StatFlags will contain a STOPPED, STARTED, or INITIALIZED state once the command\r
52 has successfully completed.\r
53 Keep in mind the AdapterInfo->State is the active state of the adapter (based on software\r
54 interrogation), and the CdbPtr->StateFlags is the passed back information that is reflected\r
55 to the caller of the UNDI API.\r
56\r
57 @param CdbPtr Pointer to the command descriptor block.\r
58 @param AdapterInfo Pointer to the NIC data structure information which\r
59 the UNDI driver is layering on..\r
60\r
61 @return None\r
62\r
63**/\r
64VOID\r
65UNDI_GetState (\r
66 IN PXE_CDB *CdbPtr,\r
67 IN NIC_DATA_INSTANCE *AdapterInfo\r
68 )\r
69{\r
70 CdbPtr->StatFlags = (PXE_STATFLAGS) (CdbPtr->StatFlags | AdapterInfo->State);\r
71 return ;\r
72}\r
73\r
74\r
75/**\r
76 This routine is used to change the operational state of the UNDI from stopped to started.\r
77 It will do this as long as the adapter's state is PXE_STATFLAGS_GET_STATE_STOPPED, otherwise\r
78 the CdbPtr->StatFlags will reflect a command failure, and the CdbPtr->StatCode will reflect the\r
79 UNDI as having already been started.\r
80 This routine is modified to reflect the undi 1.1 specification changes. The\r
81 changes in the spec are mainly in the callback routines, the new spec adds\r
82 3 more callbacks and a unique id.\r
83 Since this UNDI supports both old and new undi specifications,\r
84 The NIC's data structure is filled in with the callback routines (depending\r
85 on the version) pointed to in the caller's CpbPtr. This seeds the Delay,\r
86 Virt2Phys, Block, and Mem_IO for old and new versions and Map_Mem, UnMap_Mem\r
87 and Sync_Mem routines and a unique id variable for the new version.\r
88 This is the function which an external entity (SNP, O/S, etc) would call\r
89 to provide it's I/O abstraction to the UNDI.\r
90 It's final action is to change the AdapterInfo->State to PXE_STATFLAGS_GET_STATE_STARTED.\r
91\r
92 @param CdbPtr Pointer to the command descriptor block.\r
93 @param AdapterInfo Pointer to the NIC data structure information which\r
94 the UNDI driver is layering on..\r
95\r
96 @return None\r
97\r
98**/\r
99VOID\r
100UNDI_Start (\r
101 IN PXE_CDB *CdbPtr,\r
102 IN NIC_DATA_INSTANCE *AdapterInfo\r
103 )\r
104{\r
105 PXE_CPB_START_30 *CpbPtr;\r
106 PXE_CPB_START_31 *CpbPtr_31;\r
107\r
108 //\r
109 // check if it is already started.\r
110 //\r
111 if (AdapterInfo->State != PXE_STATFLAGS_GET_STATE_STOPPED) {\r
112 CdbPtr->StatFlags = PXE_STATFLAGS_COMMAND_FAILED;\r
113 CdbPtr->StatCode = PXE_STATCODE_ALREADY_STARTED;\r
114 return ;\r
115 }\r
116\r
117 if (CdbPtr->CPBsize != sizeof(PXE_CPB_START_30) &&\r
118 CdbPtr->CPBsize != sizeof(PXE_CPB_START_31)) {\r
119\r
120 CdbPtr->StatFlags = PXE_STATFLAGS_COMMAND_FAILED;\r
121 CdbPtr->StatCode = PXE_STATCODE_INVALID_CDB;\r
122 return ;\r
123 }\r
124\r
125 CpbPtr = (PXE_CPB_START_30 *) (UINTN) (CdbPtr->CPBaddr);\r
126 CpbPtr_31 = (PXE_CPB_START_31 *) (UINTN) (CdbPtr->CPBaddr);\r
127\r
128 if (AdapterInfo->VersionFlag == 0x30) {\r
129 AdapterInfo->Delay_30 = (bsptr_30) (UINTN) CpbPtr->Delay;\r
130 AdapterInfo->Virt2Phys_30 = (virtphys_30) (UINTN) CpbPtr->Virt2Phys;\r
131 AdapterInfo->Block_30 = (block_30) (UINTN) CpbPtr->Block;\r
132 //\r
133 // patch for old buggy 3.0 code:\r
134 // In EFI1.0 undi used to provide the full (absolute) I/O address to the\r
135 // i/o calls and SNP used to provide a callback that used GlobalIoFncs and\r
136 // everything worked fine! In EFI 1.1, UNDI is not using the full\r
137 // i/o or memory address to access the device, The base values for the i/o\r
138 // and memory address is abstracted by the device specific PciIoFncs and\r
139 // UNDI only uses the offset values. Since UNDI3.0 cannot provide any\r
140 // identification to SNP, SNP cannot use nic specific PciIoFncs callback!\r
141 //\r
142 // To fix this and make undi3.0 work with SNP in EFI1.1 we\r
143 // use a TmpMemIo function that is defined in init.c\r
144 // This breaks the runtime driver feature of undi, but what to do\r
145 // if we have to provide the 3.0 compatibility (including the 3.0 bugs)\r
146 //\r
147 // This TmpMemIo function also takes a UniqueId parameter\r
148 // (as in undi3.1 design) and so initialize the UniqueId as well here\r
149 // Note: AdapterInfo->Mem_Io_30 is just filled for consistency with other\r
150 // parameters but never used, we only use Mem_Io field in the In/Out routines\r
151 // inside e100b.c.\r
152 //\r
153 AdapterInfo->Mem_Io_30 = (mem_io_30) (UINTN) CpbPtr->Mem_IO;\r
154 AdapterInfo->Mem_Io = (mem_io) (UINTN) TmpMemIo;\r
155 AdapterInfo->Unique_ID = (UINT64) (UINTN) AdapterInfo;\r
156\r
157 } else {\r
158 AdapterInfo->Delay = (bsptr) (UINTN) CpbPtr_31->Delay;\r
159 AdapterInfo->Virt2Phys = (virtphys) (UINTN) CpbPtr_31->Virt2Phys;\r
160 AdapterInfo->Block = (block) (UINTN) CpbPtr_31->Block;\r
161 AdapterInfo->Mem_Io = (mem_io) (UINTN) CpbPtr_31->Mem_IO;\r
162\r
163 AdapterInfo->Map_Mem = (map_mem) (UINTN) CpbPtr_31->Map_Mem;\r
164 AdapterInfo->UnMap_Mem = (unmap_mem) (UINTN) CpbPtr_31->UnMap_Mem;\r
165 AdapterInfo->Sync_Mem = (sync_mem) (UINTN) CpbPtr_31->Sync_Mem;\r
166 AdapterInfo->Unique_ID = CpbPtr_31->Unique_ID;\r
167 }\r
168\r
169 AdapterInfo->State = PXE_STATFLAGS_GET_STATE_STARTED;\r
170\r
171 return ;\r
172}\r
173\r
174\r
175/**\r
176 This routine is used to change the operational state of the UNDI from started to stopped.\r
177 It will not do this if the adapter's state is PXE_STATFLAGS_GET_STATE_INITIALIZED, otherwise\r
178 the CdbPtr->StatFlags will reflect a command failure, and the CdbPtr->StatCode will reflect the\r
179 UNDI as having already not been shut down.\r
180 The NIC's data structure will have the Delay, Virt2Phys, and Block, pointers zero'd out..\r
181 It's final action is to change the AdapterInfo->State to PXE_STATFLAGS_GET_STATE_STOPPED.\r
182\r
183 @param CdbPtr Pointer to the command descriptor block.\r
184 @param AdapterInfo Pointer to the NIC data structure information which\r
185 the UNDI driver is layering on..\r
186\r
187 @return None\r
188\r
189**/\r
190VOID\r
191UNDI_Stop (\r
192 IN PXE_CDB *CdbPtr,\r
193 IN NIC_DATA_INSTANCE *AdapterInfo\r
194 )\r
195{\r
196 if (AdapterInfo->State == PXE_STATFLAGS_GET_STATE_INITIALIZED) {\r
197 CdbPtr->StatFlags = PXE_STATFLAGS_COMMAND_FAILED;\r
198 CdbPtr->StatCode = PXE_STATCODE_NOT_SHUTDOWN;\r
199 return ;\r
200 }\r
201\r
202 AdapterInfo->Delay_30 = 0;\r
203 AdapterInfo->Virt2Phys_30 = 0;\r
204 AdapterInfo->Block_30 = 0;\r
205\r
206 AdapterInfo->Delay = 0;\r
207 AdapterInfo->Virt2Phys = 0;\r
208 AdapterInfo->Block = 0;\r
209\r
210 AdapterInfo->Map_Mem = 0;\r
211 AdapterInfo->UnMap_Mem = 0;\r
212 AdapterInfo->Sync_Mem = 0;\r
213\r
214 AdapterInfo->State = PXE_STATFLAGS_GET_STATE_STOPPED;\r
215\r
216 return ;\r
217}\r
218\r
219\r
220/**\r
221 This routine is used to retrieve the initialization information that is needed by drivers and\r
222 applications to initialize the UNDI. This will fill in data in the Data Block structure that is\r
223 pointed to by the caller's CdbPtr->DBaddr. The fields filled in are as follows:\r
224 MemoryRequired, FrameDataLen, LinkSpeeds[0-3], NvCount, NvWidth, MediaHeaderLen, HWaddrLen,\r
225 MCastFilterCnt, TxBufCnt, TxBufSize, RxBufCnt, RxBufSize, IFtype, Duplex, and LoopBack.\r
226 In addition, the CdbPtr->StatFlags ORs in that this NIC supports cable detection. (APRIORI knowledge)\r
227\r
228 @param CdbPtr Pointer to the command descriptor block.\r
229 @param AdapterInfo Pointer to the NIC data structure information which\r
230 the UNDI driver is layering on..\r
231\r
232 @return None\r
233\r
234**/\r
235VOID\r
236UNDI_GetInitInfo (\r
237 IN PXE_CDB *CdbPtr,\r
238 IN NIC_DATA_INSTANCE *AdapterInfo\r
239 )\r
240{\r
241 PXE_DB_GET_INIT_INFO *DbPtr;\r
242\r
243 DbPtr = (PXE_DB_GET_INIT_INFO *) (UINTN) (CdbPtr->DBaddr);\r
244\r
245 DbPtr->MemoryRequired = MEMORY_NEEDED;\r
246 DbPtr->FrameDataLen = PXE_MAX_TXRX_UNIT_ETHER;\r
247 DbPtr->LinkSpeeds[0] = 10;\r
248 DbPtr->LinkSpeeds[1] = 100;\r
249 DbPtr->LinkSpeeds[2] = DbPtr->LinkSpeeds[3] = 0;\r
250 DbPtr->NvCount = MAX_EEPROM_LEN;\r
251 DbPtr->NvWidth = 4;\r
252 DbPtr->MediaHeaderLen = PXE_MAC_HEADER_LEN_ETHER;\r
253 DbPtr->HWaddrLen = PXE_HWADDR_LEN_ETHER;\r
254 DbPtr->MCastFilterCnt = MAX_MCAST_ADDRESS_CNT;\r
255\r
256 DbPtr->TxBufCnt = TX_BUFFER_COUNT;\r
257 DbPtr->TxBufSize = sizeof (TxCB);\r
258 DbPtr->RxBufCnt = RX_BUFFER_COUNT;\r
259 DbPtr->RxBufSize = sizeof (RxFD);\r
260\r
261 DbPtr->IFtype = PXE_IFTYPE_ETHERNET;\r
262 DbPtr->SupportedDuplexModes = PXE_DUPLEX_ENABLE_FULL_SUPPORTED |\r
263 PXE_DUPLEX_FORCE_FULL_SUPPORTED;\r
264 DbPtr->SupportedLoopBackModes = PXE_LOOPBACK_INTERNAL_SUPPORTED |\r
265 PXE_LOOPBACK_EXTERNAL_SUPPORTED;\r
266\r
267 CdbPtr->StatFlags |= PXE_STATFLAGS_CABLE_DETECT_SUPPORTED;\r
268 return ;\r
269}\r
270\r
271\r
272/**\r
273 This routine is used to retrieve the configuration information about the NIC being controlled by\r
274 this driver. This will fill in data in the Data Block structure that is pointed to by the caller's CdbPtr->DBaddr.\r
275 The fields filled in are as follows:\r
276 DbPtr->pci.BusType, DbPtr->pci.Bus, DbPtr->pci.Device, and DbPtr->pci.\r
277 In addition, the DbPtr->pci.Config.Dword[0-63] grabs a copy of this NIC's PCI configuration space.\r
278\r
279 @param CdbPtr Pointer to the command descriptor block.\r
280 @param AdapterInfo Pointer to the NIC data structure information which\r
281 the UNDI driver is layering on..\r
282\r
283 @return None\r
284\r
285**/\r
286VOID\r
287UNDI_GetConfigInfo (\r
288 IN PXE_CDB *CdbPtr,\r
289 IN NIC_DATA_INSTANCE *AdapterInfo\r
290 )\r
291{\r
292 UINT16 Index;\r
293 PXE_DB_GET_CONFIG_INFO *DbPtr;\r
294\r
295 DbPtr = (PXE_DB_GET_CONFIG_INFO *) (UINTN) (CdbPtr->DBaddr);\r
296\r
297 DbPtr->pci.BusType = PXE_BUSTYPE_PCI;\r
298 DbPtr->pci.Bus = AdapterInfo->Bus;\r
299 DbPtr->pci.Device = AdapterInfo->Device;\r
300 DbPtr->pci.Function = AdapterInfo->Function;\r
301\r
302 for (Index = 0; Index < MAX_PCI_CONFIG_LEN; Index++) {\r
303 DbPtr->pci.Config.Dword[Index] = AdapterInfo->Config[Index];\r
304 }\r
305\r
306 return ;\r
307}\r
308\r
309\r
310/**\r
311 This routine resets the network adapter and initializes the UNDI using the parameters supplied in\r
312 the CPB. This command must be issued before the network adapter can be setup to transmit and\r
313 receive packets.\r
314 Once the memory requirements of the UNDI are obtained by using the GetInitInfo command, a block\r
315 of non-swappable memory may need to be allocated. The address of this memory must be passed to\r
316 UNDI during the Initialize in the CPB. This memory is used primarily for transmit and receive buffers.\r
317 The fields CableDetect, LinkSpeed, Duplex, LoopBack, MemoryPtr, and MemoryLength are set with information\r
318 that was passed in the CPB and the NIC is initialized.\r
319 If the NIC initialization fails, the CdbPtr->StatFlags are updated with PXE_STATFLAGS_COMMAND_FAILED\r
320 Otherwise, AdapterInfo->State is updated with PXE_STATFLAGS_GET_STATE_INITIALIZED showing the state of\r
321 the UNDI is now initialized.\r
322\r
323 @param CdbPtr Pointer to the command descriptor block.\r
324 @param AdapterInfo Pointer to the NIC data structure information which\r
325 the UNDI driver is layering on..\r
326\r
327 @return None\r
328\r
329**/\r
330VOID\r
331UNDI_Initialize (\r
332 IN PXE_CDB *CdbPtr,\r
333 NIC_DATA_INSTANCE *AdapterInfo\r
334 )\r
335{\r
336 PXE_CPB_INITIALIZE *CpbPtr;\r
337\r
338 if ((CdbPtr->OpFlags != PXE_OPFLAGS_INITIALIZE_DETECT_CABLE) &&\r
339 (CdbPtr->OpFlags != PXE_OPFLAGS_INITIALIZE_DO_NOT_DETECT_CABLE)) {\r
340 CdbPtr->StatFlags = PXE_STATFLAGS_COMMAND_FAILED;\r
341 CdbPtr->StatCode = PXE_STATCODE_INVALID_CDB;\r
342 return ;\r
343 }\r
344\r
345 //\r
346 // check if it is already initialized\r
347 //\r
348 if (AdapterInfo->State == PXE_STATFLAGS_GET_STATE_INITIALIZED) {\r
349 CdbPtr->StatFlags = PXE_STATFLAGS_COMMAND_FAILED;\r
350 CdbPtr->StatCode = PXE_STATCODE_ALREADY_INITIALIZED;\r
351 return ;\r
352 }\r
353\r
354 CpbPtr = (PXE_CPB_INITIALIZE *) (UINTN) CdbPtr->CPBaddr;\r
355\r
356 if (CpbPtr->MemoryLength < (UINT32) MEMORY_NEEDED) {\r
357 CdbPtr->StatFlags = PXE_STATFLAGS_COMMAND_FAILED;\r
358 CdbPtr->StatCode = PXE_STATCODE_INVALID_CPB;\r
359 return ;\r
360 }\r
361\r
362 //\r
363 // default behaviour is to detect the cable, if the 3rd param is 1,\r
364 // do not do that\r
365 //\r
366 AdapterInfo->CableDetect = (UINT8) ((CdbPtr->OpFlags == (UINT16) PXE_OPFLAGS_INITIALIZE_DO_NOT_DETECT_CABLE) ? (UINT8) 0 : (UINT8) 1);\r
367 AdapterInfo->LinkSpeedReq = (UINT16) CpbPtr->LinkSpeed;\r
368 AdapterInfo->DuplexReq = CpbPtr->DuplexMode;\r
369 AdapterInfo->LoopBack = CpbPtr->LoopBackMode;\r
370 AdapterInfo->MemoryPtr = CpbPtr->MemoryAddr;\r
371 AdapterInfo->MemoryLength = CpbPtr->MemoryLength;\r
372\r
373 CdbPtr->StatCode = (PXE_STATCODE) E100bInit (AdapterInfo);\r
374\r
375 if (CdbPtr->StatCode != PXE_STATCODE_SUCCESS) {\r
376 CdbPtr->StatFlags = PXE_STATFLAGS_COMMAND_FAILED;\r
377 } else {\r
378 AdapterInfo->State = PXE_STATFLAGS_GET_STATE_INITIALIZED;\r
379 }\r
380\r
381 return ;\r
382}\r
383\r
384\r
385/**\r
386 This routine resets the network adapter and initializes the UNDI using the parameters supplied in\r
387 the CPB. The transmit and receive queues are emptied and any pending interrupts are cleared.\r
388 If the NIC reset fails, the CdbPtr->StatFlags are updated with PXE_STATFLAGS_COMMAND_FAILED\r
389\r
390 @param CdbPtr Pointer to the command descriptor block.\r
391 @param AdapterInfo Pointer to the NIC data structure information which\r
392 the UNDI driver is layering on..\r
393\r
394 @return None\r
395\r
396**/\r
397VOID\r
398UNDI_Reset (\r
399 IN PXE_CDB *CdbPtr,\r
400 IN NIC_DATA_INSTANCE *AdapterInfo\r
401 )\r
402{\r
403 if (CdbPtr->OpFlags != PXE_OPFLAGS_NOT_USED &&\r
404 CdbPtr->OpFlags != PXE_OPFLAGS_RESET_DISABLE_INTERRUPTS &&\r
405 CdbPtr->OpFlags != PXE_OPFLAGS_RESET_DISABLE_FILTERS ) {\r
406\r
407 CdbPtr->StatFlags = PXE_STATFLAGS_COMMAND_FAILED;\r
408 CdbPtr->StatCode = PXE_STATCODE_INVALID_CDB;\r
409 return ;\r
410 }\r
411\r
412 CdbPtr->StatCode = (UINT16) E100bReset (AdapterInfo, CdbPtr->OpFlags);\r
413\r
414 if (CdbPtr->StatCode != PXE_STATCODE_SUCCESS) {\r
415 CdbPtr->StatFlags = PXE_STATFLAGS_COMMAND_FAILED;\r
416 }\r
417}\r
418\r
419\r
420/**\r
421 This routine resets the network adapter and leaves it in a safe state for another driver to\r
422 initialize. Any pending transmits or receives are lost. Receive filters and external\r
423 interrupt enables are disabled. Once the UNDI has been shutdown, it can then be stopped\r
424 or initialized again.\r
425 If the NIC reset fails, the CdbPtr->StatFlags are updated with PXE_STATFLAGS_COMMAND_FAILED\r
426 Otherwise, AdapterInfo->State is updated with PXE_STATFLAGS_GET_STATE_STARTED showing the state of\r
427 the NIC as being started.\r
428\r
429 @param CdbPtr Pointer to the command descriptor block.\r
430 @param AdapterInfo Pointer to the NIC data structure information which\r
431 the UNDI driver is layering on..\r
432\r
433 @return None\r
434\r
435**/\r
436VOID\r
437UNDI_Shutdown (\r
438 IN PXE_CDB *CdbPtr,\r
439 IN NIC_DATA_INSTANCE *AdapterInfo\r
440 )\r
441{\r
442 //\r
443 // do the shutdown stuff here\r
444 //\r
445 CdbPtr->StatCode = (UINT16) E100bShutdown (AdapterInfo);\r
446\r
447 if (CdbPtr->StatCode != PXE_STATCODE_SUCCESS) {\r
448 CdbPtr->StatFlags = PXE_STATFLAGS_COMMAND_FAILED;\r
449 } else {\r
450 AdapterInfo->State = PXE_STATFLAGS_GET_STATE_STARTED;\r
451 }\r
452\r
453 return ;\r
454}\r
455\r
456\r
457/**\r
458 This routine can be used to read and/or change the current external interrupt enable\r
459 settings. Disabling an external interrupt enable prevents and external (hardware)\r
460 interrupt from being signaled by the network device. Internally the interrupt events\r
461 can still be polled by using the UNDI_GetState command.\r
462 The resulting information on the interrupt state will be passed back in the CdbPtr->StatFlags.\r
463\r
464 @param CdbPtr Pointer to the command descriptor block.\r
465 @param AdapterInfo Pointer to the NIC data structure information which\r
466 the UNDI driver is layering on..\r
467\r
468 @return None\r
469\r
470**/\r
471VOID\r
472UNDI_Interrupt (\r
473 IN PXE_CDB *CdbPtr,\r
474 IN NIC_DATA_INSTANCE *AdapterInfo\r
475 )\r
476{\r
477 UINT8 IntMask;\r
478\r
479 IntMask = (UINT8)(UINTN)(CdbPtr->OpFlags & (PXE_OPFLAGS_INTERRUPT_RECEIVE |\r
480 PXE_OPFLAGS_INTERRUPT_TRANSMIT |\r
481 PXE_OPFLAGS_INTERRUPT_COMMAND |\r
482 PXE_OPFLAGS_INTERRUPT_SOFTWARE));\r
483\r
484 switch (CdbPtr->OpFlags & PXE_OPFLAGS_INTERRUPT_OPMASK) {\r
485 case PXE_OPFLAGS_INTERRUPT_READ:\r
486 break;\r
487\r
488 case PXE_OPFLAGS_INTERRUPT_ENABLE:\r
489 if (IntMask == 0) {\r
490 CdbPtr->StatFlags = PXE_STATFLAGS_COMMAND_FAILED;\r
491 CdbPtr->StatCode = PXE_STATCODE_INVALID_CDB;\r
492 return ;\r
493 }\r
494\r
495 AdapterInfo->int_mask = IntMask;\r
496 E100bSetInterruptState (AdapterInfo);\r
497 break;\r
498\r
499 case PXE_OPFLAGS_INTERRUPT_DISABLE:\r
500 if (IntMask != 0) {\r
501 AdapterInfo->int_mask = (UINT16) (AdapterInfo->int_mask & ~(IntMask));\r
502 E100bSetInterruptState (AdapterInfo);\r
503 break;\r
504 }\r
505\r
506 //\r
507 // else fall thru.\r
508 //\r
509 default:\r
510 CdbPtr->StatFlags = PXE_STATFLAGS_COMMAND_FAILED;\r
511 CdbPtr->StatCode = PXE_STATCODE_INVALID_CDB;\r
512 return ;\r
513 }\r
514\r
515 if ((AdapterInfo->int_mask & PXE_OPFLAGS_INTERRUPT_RECEIVE) != 0) {\r
516 CdbPtr->StatFlags |= PXE_STATFLAGS_INTERRUPT_RECEIVE;\r
517\r
518 }\r
519\r
520 if ((AdapterInfo->int_mask & PXE_OPFLAGS_INTERRUPT_TRANSMIT) != 0) {\r
521 CdbPtr->StatFlags |= PXE_STATFLAGS_INTERRUPT_TRANSMIT;\r
522\r
523 }\r
524\r
525 if ((AdapterInfo->int_mask & PXE_OPFLAGS_INTERRUPT_COMMAND) != 0) {\r
526 CdbPtr->StatFlags |= PXE_STATFLAGS_INTERRUPT_COMMAND;\r
527\r
528 }\r
529\r
530 return ;\r
531}\r
532\r
533\r
534/**\r
535 This routine is used to read and change receive filters and, if supported, read\r
536 and change multicast MAC address filter list.\r
537\r
538 @param CdbPtr Pointer to the command descriptor block.\r
539 @param AdapterInfo Pointer to the NIC data structure information which\r
540 the UNDI driver is layering on..\r
541\r
542 @return None\r
543\r
544**/\r
545VOID\r
546UNDI_RecFilter (\r
547 IN PXE_CDB *CdbPtr,\r
548 IN NIC_DATA_INSTANCE *AdapterInfo\r
549 )\r
550{\r
551 UINT16 NewFilter;\r
552 UINT16 OpFlags;\r
553 PXE_DB_RECEIVE_FILTERS *DbPtr;\r
554 UINT8 *MacAddr;\r
555 UINTN MacCount;\r
556 UINT16 Index;\r
557 UINT16 copy_len;\r
558 UINT8 *ptr1;\r
559 UINT8 *ptr2;\r
cd417925 560 BOOLEAN InvalidMacAddr;\r
561 \r
51ebae6b 562 OpFlags = CdbPtr->OpFlags;\r
563 NewFilter = (UINT16) (OpFlags & 0x1F);\r
564\r
565 switch (OpFlags & PXE_OPFLAGS_RECEIVE_FILTER_OPMASK) {\r
566 case PXE_OPFLAGS_RECEIVE_FILTER_READ:\r
567\r
568 //\r
569 // not expecting a cpb, not expecting any filter bits\r
570 //\r
571 if ((NewFilter != 0) || (CdbPtr->CPBsize != 0)) {\r
572 goto BadCdb;\r
573\r
574 }\r
575\r
576 if ((NewFilter & PXE_OPFLAGS_RECEIVE_FILTER_RESET_MCAST_LIST) == 0) {\r
577 goto JustRead;\r
578\r
579 }\r
580\r
581 NewFilter = (UINT16) (NewFilter | AdapterInfo->Rx_Filter);\r
582 //\r
583 // all other flags are ignored except mcast_reset\r
584 //\r
585 break;\r
586\r
587 case PXE_OPFLAGS_RECEIVE_FILTER_ENABLE:\r
588 //\r
589 // there should be atleast one other filter bit set.\r
590 //\r
591 if (NewFilter == 0) {\r
592 //\r
593 // nothing to enable\r
594 //\r
595 goto BadCdb;\r
596 }\r
597\r
598 if (CdbPtr->CPBsize != 0) {\r
599 //\r
600 // this must be a multicast address list!\r
601 // don't accept the list unless selective_mcast is set\r
602 // don't accept confusing mcast settings with this\r
603 //\r
604 if (((NewFilter & PXE_OPFLAGS_RECEIVE_FILTER_FILTERED_MULTICAST) == 0) ||\r
605 ((NewFilter & PXE_OPFLAGS_RECEIVE_FILTER_RESET_MCAST_LIST) != 0) ||\r
606 ((NewFilter & PXE_OPFLAGS_RECEIVE_FILTER_ALL_MULTICAST) != 0) ||\r
607 ((CdbPtr->CPBsize % sizeof (PXE_MAC_ADDR)) != 0) ) {\r
608 goto BadCdb;\r
609 }\r
610\r
611 MacAddr = (UINT8 *) ((UINTN) (CdbPtr->CPBaddr));\r
612 MacCount = CdbPtr->CPBsize / sizeof (PXE_MAC_ADDR);\r
613\r
cd417925 614 //\r
615 // The format of Ethernet multicast address for IPv6 is defined in RFC2464,\r
616 // for IPv4 is defined in RFC1112. Check whether the address is valid.\r
617 //\r
618 InvalidMacAddr = FALSE;\r
619 \r
51ebae6b 620 for (; MacCount-- != 0; MacAddr += sizeof (PXE_MAC_ADDR)) {\r
cd417925 621 if (MacAddr[0] == 0x01) {\r
622 //\r
623 // This multicast MAC address is mapped from IPv4 address.\r
624 //\r
625 if (MacAddr[1] != 0x00 || MacAddr[2] != 0x5E || (MacAddr[3] & 0x80) != 0) {\r
626 InvalidMacAddr = TRUE;\r
627 } \r
628 } else if (MacAddr[0] == 0x33) {\r
629 //\r
630 // This multicast MAC address is mapped from IPv6 address.\r
631 //\r
632 if (MacAddr[1] != 0x33) {\r
633 InvalidMacAddr = TRUE;\r
634 }\r
635 } else {\r
636 InvalidMacAddr = TRUE;\r
637 }\r
638\r
639 if (InvalidMacAddr) {\r
51ebae6b 640 CdbPtr->StatFlags = PXE_STATFLAGS_COMMAND_FAILED;\r
641 CdbPtr->StatCode = PXE_STATCODE_INVALID_CPB;\r
642 return ;\r
643 }\r
644 }\r
645 }\r
646\r
647 //\r
648 // check selective mcast case enable case\r
649 //\r
650 if ((OpFlags & PXE_OPFLAGS_RECEIVE_FILTER_FILTERED_MULTICAST) != 0) {\r
651 if (((OpFlags & PXE_OPFLAGS_RECEIVE_FILTER_RESET_MCAST_LIST) != 0) ||\r
652 ((OpFlags & PXE_OPFLAGS_RECEIVE_FILTER_ALL_MULTICAST) != 0) ) {\r
653 goto BadCdb;\r
654\r
655 }\r
656 //\r
657 // if no cpb, make sure we have an old list\r
658 //\r
659 if ((CdbPtr->CPBsize == 0) && (AdapterInfo->mcast_list.list_len == 0)) {\r
660 goto BadCdb;\r
661 }\r
662 }\r
663 //\r
664 // if you want to enable anything, you got to have unicast\r
665 // and you have what you already enabled!\r
666 //\r
667 NewFilter = (UINT16) (NewFilter | (PXE_OPFLAGS_RECEIVE_FILTER_UNICAST | AdapterInfo->Rx_Filter));\r
668\r
669 break;\r
670\r
671 case PXE_OPFLAGS_RECEIVE_FILTER_DISABLE:\r
672\r
673 //\r
674 // mcast list not expected, i.e. no cpb here!\r
675 //\r
676 if (CdbPtr->CPBsize != PXE_CPBSIZE_NOT_USED) {\r
677 goto BadCdb;\r
678 }\r
679\r
680 NewFilter = (UINT16) ((~(CdbPtr->OpFlags & 0x1F)) & AdapterInfo->Rx_Filter);\r
681\r
682 break;\r
683\r
684 default:\r
685 goto BadCdb;\r
686 }\r
687\r
688 if ((OpFlags & PXE_OPFLAGS_RECEIVE_FILTER_RESET_MCAST_LIST) != 0) {\r
689 AdapterInfo->mcast_list.list_len = 0;\r
690 NewFilter &= (~PXE_OPFLAGS_RECEIVE_FILTER_FILTERED_MULTICAST);\r
691 }\r
692\r
693 E100bSetfilter (AdapterInfo, NewFilter, CdbPtr->CPBaddr, CdbPtr->CPBsize);\r
694\r
695JustRead:\r
696 //\r
697 // give the current mcast list\r
698 //\r
699 if ((CdbPtr->DBsize != 0) && (AdapterInfo->mcast_list.list_len != 0)) {\r
700 //\r
701 // copy the mc list to db\r
702 //\r
703\r
704 DbPtr = (PXE_DB_RECEIVE_FILTERS *) (UINTN) CdbPtr->DBaddr;\r
705 ptr1 = (UINT8 *) (&DbPtr->MCastList[0]);\r
706\r
707 //\r
708 // DbPtr->mc_count = AdapterInfo->mcast_list.list_len;\r
709 //\r
710 copy_len = (UINT16) (AdapterInfo->mcast_list.list_len * PXE_MAC_LENGTH);\r
711\r
712 if (copy_len > CdbPtr->DBsize) {\r
713 copy_len = CdbPtr->DBsize;\r
714\r
715 }\r
716\r
717 ptr2 = (UINT8 *) (&AdapterInfo->mcast_list.mc_list[0]);\r
718 for (Index = 0; Index < copy_len; Index++) {\r
719 ptr1[Index] = ptr2[Index];\r
720 }\r
721 }\r
722 //\r
723 // give the stat flags here\r
724 //\r
725 if (AdapterInfo->Receive_Started) {\r
726 CdbPtr->StatFlags = (PXE_STATFLAGS) (CdbPtr->StatFlags | AdapterInfo->Rx_Filter);\r
727\r
728 }\r
729\r
730 return ;\r
731\r
732BadCdb:\r
733 CdbPtr->StatFlags = PXE_STATFLAGS_COMMAND_FAILED;\r
734 CdbPtr->StatCode = PXE_STATCODE_INVALID_CDB;\r
735}\r
736\r
737\r
738/**\r
739 This routine is used to get the current station and broadcast MAC addresses, and to change the\r
740 current station MAC address.\r
741\r
742 @param CdbPtr Pointer to the command descriptor block.\r
743 @param AdapterInfo Pointer to the NIC data structure information which\r
744 the UNDI driver is layering on..\r
745\r
746 @return None\r
747\r
748**/\r
749VOID\r
750UNDI_StnAddr (\r
751 IN PXE_CDB *CdbPtr,\r
752 IN NIC_DATA_INSTANCE *AdapterInfo\r
753 )\r
754{\r
755 PXE_CPB_STATION_ADDRESS *CpbPtr;\r
756 PXE_DB_STATION_ADDRESS *DbPtr;\r
757 UINT16 Index;\r
758\r
759 if (CdbPtr->OpFlags == PXE_OPFLAGS_STATION_ADDRESS_RESET) {\r
760 //\r
761 // configure the permanent address.\r
762 // change the AdapterInfo->CurrentNodeAddress field.\r
763 //\r
764 if (CompareMem (\r
765 &AdapterInfo->CurrentNodeAddress[0],\r
766 &AdapterInfo->PermNodeAddress[0],\r
767 PXE_MAC_LENGTH\r
768 ) != 0) {\r
769 for (Index = 0; Index < PXE_MAC_LENGTH; Index++) {\r
770 AdapterInfo->CurrentNodeAddress[Index] = AdapterInfo->PermNodeAddress[Index];\r
771 }\r
772\r
773 E100bSetupIAAddr (AdapterInfo);\r
774 }\r
775 }\r
776\r
777 if (CdbPtr->CPBaddr != (UINT64) 0) {\r
778 CpbPtr = (PXE_CPB_STATION_ADDRESS *) (UINTN) (CdbPtr->CPBaddr);\r
779 //\r
780 // configure the new address\r
781 //\r
782 for (Index = 0; Index < PXE_MAC_LENGTH; Index++) {\r
783 AdapterInfo->CurrentNodeAddress[Index] = CpbPtr->StationAddr[Index];\r
784 }\r
785\r
786 E100bSetupIAAddr (AdapterInfo);\r
787 }\r
788\r
789 if (CdbPtr->DBaddr != (UINT64) 0) {\r
790 DbPtr = (PXE_DB_STATION_ADDRESS *) (UINTN) (CdbPtr->DBaddr);\r
791 //\r
792 // fill it with the new values\r
793 //\r
794 for (Index = 0; Index < PXE_MAC_LENGTH; Index++) {\r
795 DbPtr->StationAddr[Index] = AdapterInfo->CurrentNodeAddress[Index];\r
796 DbPtr->BroadcastAddr[Index] = AdapterInfo->BroadcastNodeAddress[Index];\r
797 DbPtr->PermanentAddr[Index] = AdapterInfo->PermNodeAddress[Index];\r
798 }\r
799 }\r
800\r
801 return ;\r
802}\r
803\r
804\r
805/**\r
806 This routine is used to read and clear the NIC traffic statistics. This command is supported only\r
807 if the !PXE structure's Implementation flags say so.\r
808 Results will be parsed out in the following manner:\r
809 CdbPtr->DBaddr.Data[0] R Total Frames (Including frames with errors and dropped frames)\r
810 CdbPtr->DBaddr.Data[1] R Good Frames (All frames copied into receive buffer)\r
811 CdbPtr->DBaddr.Data[2] R Undersize Frames (Frames below minimum length for media <64 for ethernet)\r
812 CdbPtr->DBaddr.Data[4] R Dropped Frames (Frames that were dropped because receive buffers were full)\r
813 CdbPtr->DBaddr.Data[8] R CRC Error Frames (Frames with alignment or CRC errors)\r
814 CdbPtr->DBaddr.Data[A] T Total Frames (Including frames with errors and dropped frames)\r
815 CdbPtr->DBaddr.Data[B] T Good Frames (All frames copied into transmit buffer)\r
816 CdbPtr->DBaddr.Data[C] T Undersize Frames (Frames below minimum length for media <64 for ethernet)\r
817 CdbPtr->DBaddr.Data[E] T Dropped Frames (Frames that were dropped because of collisions)\r
818 CdbPtr->DBaddr.Data[14] T Total Collision Frames (Total collisions on this subnet)\r
819\r
820 @param CdbPtr Pointer to the command descriptor block.\r
821 @param AdapterInfo Pointer to the NIC data structure information which\r
822 the UNDI driver is layering on..\r
823\r
824 @return None\r
825\r
826**/\r
827VOID\r
828UNDI_Statistics (\r
829 IN PXE_CDB *CdbPtr,\r
830 IN NIC_DATA_INSTANCE *AdapterInfo\r
831 )\r
832{\r
833 if ((CdbPtr->OpFlags &~(PXE_OPFLAGS_STATISTICS_RESET)) != 0) {\r
834 CdbPtr->StatFlags = PXE_STATFLAGS_COMMAND_FAILED;\r
835 CdbPtr->StatCode = PXE_STATCODE_INVALID_CDB;\r
836 return ;\r
837 }\r
838\r
839 if ((CdbPtr->OpFlags & PXE_OPFLAGS_STATISTICS_RESET) != 0) {\r
840 //\r
841 // Reset the statistics\r
842 //\r
843 CdbPtr->StatCode = (UINT16) E100bStatistics (AdapterInfo, 0, 0);\r
844 } else {\r
845 CdbPtr->StatCode = (UINT16) E100bStatistics (AdapterInfo, CdbPtr->DBaddr, CdbPtr->DBsize);\r
846 }\r
847\r
848 return ;\r
849}\r
850\r
851\r
852/**\r
853 This routine is used to translate a multicast IP address to a multicast MAC address.\r
854 This results in a MAC address composed of 25 bits of fixed data with the upper 23 bits of the IP\r
855 address being appended to it. Results passed back in the equivalent of CdbPtr->DBaddr->MAC[0-5].\r
856\r
857 @param CdbPtr Pointer to the command descriptor block.\r
858 @param AdapterInfo Pointer to the NIC data structure information which\r
859 the UNDI driver is layering on..\r
860\r
861 @return None\r
862\r
863**/\r
864VOID\r
865UNDI_ip2mac (\r
866 IN PXE_CDB *CdbPtr,\r
867 IN NIC_DATA_INSTANCE *AdapterInfo\r
868 )\r
869{\r
870 PXE_CPB_MCAST_IP_TO_MAC *CpbPtr;\r
871 PXE_DB_MCAST_IP_TO_MAC *DbPtr;\r
872 UINT8 *TmpPtr;\r
873\r
874 CpbPtr = (PXE_CPB_MCAST_IP_TO_MAC *) (UINTN) CdbPtr->CPBaddr;\r
875 DbPtr = (PXE_DB_MCAST_IP_TO_MAC *) (UINTN) CdbPtr->DBaddr;\r
876\r
877 if ((CdbPtr->OpFlags & PXE_OPFLAGS_MCAST_IPV6_TO_MAC) != 0) {\r
878 //\r
879 // for now this is not supported\r
880 //\r
881 CdbPtr->StatFlags = PXE_STATFLAGS_COMMAND_FAILED;\r
882 CdbPtr->StatCode = PXE_STATCODE_UNSUPPORTED;\r
883 return ;\r
884 }\r
885\r
886 TmpPtr = (UINT8 *) (&CpbPtr->IP.IPv4);\r
887 //\r
888 // check if the ip given is a mcast IP\r
889 //\r
890 if ((TmpPtr[0] & 0xF0) != 0xE0) {\r
891 CdbPtr->StatFlags = PXE_STATFLAGS_COMMAND_FAILED;\r
892 CdbPtr->StatCode = PXE_STATCODE_INVALID_CPB;\r
893 }\r
894 //\r
895 // take the last 23 bits in IP.\r
896 // be very careful. accessing word on a non-word boundary will hang motherboard codenamed Big Sur\r
897 // casting the mac array (in the middle) to a UINT32 pointer and accessing\r
898 // the UINT32 content hung the system...\r
899 //\r
900 DbPtr->MAC[0] = 0x01;\r
901 DbPtr->MAC[1] = 0x00;\r
902 DbPtr->MAC[2] = 0x5e;\r
903 DbPtr->MAC[3] = (UINT8) (TmpPtr[1] & 0x7f);\r
904 DbPtr->MAC[4] = (UINT8) TmpPtr[2];\r
905 DbPtr->MAC[5] = (UINT8) TmpPtr[3];\r
906\r
907 return ;\r
908}\r
909\r
910\r
911/**\r
912 This routine is used to read and write non-volatile storage on the NIC (if supported). The NVRAM\r
913 could be EEPROM, FLASH, or battery backed RAM.\r
914 This is an optional function according to the UNDI specification (or will be......)\r
915\r
916 @param CdbPtr Pointer to the command descriptor block.\r
917 @param AdapterInfo Pointer to the NIC data structure information which\r
918 the UNDI driver is layering on..\r
919\r
920 @return None\r
921\r
922**/\r
923VOID\r
924UNDI_NVData (\r
925 IN PXE_CDB *CdbPtr,\r
926 IN NIC_DATA_INSTANCE *AdapterInfo\r
927 )\r
928{\r
929 PXE_DB_NVDATA *DbPtr;\r
930 UINT16 Index;\r
931\r
932 if ((CdbPtr->OpFlags == PXE_OPFLAGS_NVDATA_READ) != 0) {\r
933\r
934 if ((CdbPtr->DBsize == PXE_DBSIZE_NOT_USED) != 0) {\r
935 CdbPtr->StatFlags = PXE_STATFLAGS_COMMAND_FAILED;\r
936 CdbPtr->StatCode = PXE_STATCODE_INVALID_CDB;\r
937 return ;\r
938 }\r
939\r
940 DbPtr = (PXE_DB_NVDATA *) (UINTN) CdbPtr->DBaddr;\r
941\r
942 for (Index = 0; Index < MAX_PCI_CONFIG_LEN; Index++) {\r
943 DbPtr->Data.Dword[Index] = AdapterInfo->NVData[Index];\r
944\r
945 }\r
946\r
947 } else {\r
948 //\r
949 // no write for now\r
950 //\r
951 CdbPtr->StatFlags = PXE_STATFLAGS_COMMAND_FAILED;\r
952 CdbPtr->StatCode = PXE_STATCODE_UNSUPPORTED;\r
953 }\r
954\r
955 return ;\r
956}\r
957\r
958\r
959/**\r
960 This routine returns the current interrupt status and/or the transmitted buffer addresses.\r
961 If the current interrupt status is returned, pending interrupts will be acknowledged by this\r
962 command. Transmitted buffer addresses that are written to the DB are removed from the transmit\r
963 buffer queue.\r
964 Normally, this command would be polled with interrupts disabled.\r
965 The transmit buffers are returned in CdbPtr->DBaddr->TxBufer[0 - NumEntries].\r
966 The interrupt status is returned in CdbPtr->StatFlags.\r
967\r
968 @param CdbPtr Pointer to the command descriptor block.\r
969 @param AdapterInfo Pointer to the NIC data structure information which\r
970 the UNDI driver is layering on..\r
971\r
972 @return None\r
973\r
974**/\r
975VOID\r
976UNDI_Status (\r
977 IN PXE_CDB *CdbPtr,\r
978 IN NIC_DATA_INSTANCE *AdapterInfo\r
979 )\r
980{\r
981 PXE_DB_GET_STATUS *DbPtr;\r
982 PXE_DB_GET_STATUS TmpGetStatus;\r
983 UINT16 Index;\r
984 UINT16 Status;\r
985 UINT16 NumEntries;\r
986 RxFD *RxPtr;\r
987\r
988 //\r
989 // Fill in temporary GetStatus storage.\r
990 //\r
991 RxPtr = &AdapterInfo->rx_ring[AdapterInfo->cur_rx_ind];\r
992\r
993 if ((RxPtr->cb_header.status & RX_COMPLETE) != 0) {\r
994 TmpGetStatus.RxFrameLen = RxPtr->ActualCount & 0x3fff;\r
995 } else {\r
996 TmpGetStatus.RxFrameLen = 0;\r
997 }\r
998\r
999 TmpGetStatus.reserved = 0;\r
1000\r
1001 //\r
1002 // Fill in size of next available receive packet and\r
1003 // reserved field in caller's DB storage.\r
1004 //\r
1005 DbPtr = (PXE_DB_GET_STATUS *) (UINTN) CdbPtr->DBaddr;\r
1006\r
1007 if (CdbPtr->DBsize > 0 && CdbPtr->DBsize < sizeof (UINT32) * 2) {\r
1008 CopyMem (DbPtr, &TmpGetStatus, CdbPtr->DBsize);\r
1009 } else {\r
1010 CopyMem (DbPtr, &TmpGetStatus, sizeof (UINT32) * 2);\r
1011 }\r
1012\r
1013 //\r
1014 //\r
1015 //\r
1016 if ((CdbPtr->OpFlags & PXE_OPFLAGS_GET_TRANSMITTED_BUFFERS) != 0) {\r
1017 //\r
1018 // DBsize of zero is invalid if Tx buffers are requested.\r
1019 //\r
1020 if (CdbPtr->DBsize == 0) {\r
1021 CdbPtr->StatFlags = PXE_STATFLAGS_COMMAND_FAILED;\r
1022 CdbPtr->StatCode = PXE_STATCODE_INVALID_CDB;\r
1023 return ;\r
1024 }\r
1025\r
1026 //\r
1027 // remember this b4 we overwrite\r
1028 //\r
1029 NumEntries = (UINT16) (CdbPtr->DBsize - sizeof (UINT64));\r
1030\r
1031 //\r
1032 // We already filled in 2 UINT32s.\r
1033 //\r
1034 CdbPtr->DBsize = sizeof (UINT32) * 2;\r
1035\r
1036 //\r
1037 // will claim any hanging free CBs\r
1038 //\r
1039 CheckCBList (AdapterInfo);\r
1040\r
1041 if (AdapterInfo->xmit_done_head == AdapterInfo->xmit_done_tail) {\r
1042 CdbPtr->StatFlags |= PXE_STATFLAGS_GET_STATUS_TXBUF_QUEUE_EMPTY;\r
1043 } else {\r
1044 for (Index = 0; NumEntries >= sizeof (UINT64); Index++, NumEntries -= sizeof (UINT64)) {\r
1045 if (AdapterInfo->xmit_done_head != AdapterInfo->xmit_done_tail) {\r
1046 DbPtr->TxBuffer[Index] = AdapterInfo->xmit_done[AdapterInfo->xmit_done_head];\r
1047 AdapterInfo->xmit_done_head = next (AdapterInfo->xmit_done_head);\r
1048 CdbPtr->DBsize += sizeof (UINT64);\r
1049 } else {\r
1050 break;\r
1051 }\r
1052 }\r
1053 }\r
1054\r
1055 if (AdapterInfo->xmit_done_head != AdapterInfo->xmit_done_tail) {\r
1056 CdbPtr->StatFlags |= PXE_STATFLAGS_DB_WRITE_TRUNCATED;\r
1057\r
1058 }\r
1059 //\r
1060 // check for a receive buffer and give it's size in db\r
1061 //\r
1062 }\r
1063 //\r
1064 //\r
1065 //\r
1066 if ((CdbPtr->OpFlags & PXE_OPFLAGS_GET_INTERRUPT_STATUS) != 0) {\r
1067\r
1068 Status = InWord (AdapterInfo, AdapterInfo->ioaddr + SCBStatus);\r
1069 AdapterInfo->Int_Status = (UINT16) (AdapterInfo->Int_Status | Status);\r
1070\r
1071 //\r
1072 // acknoledge the interrupts\r
1073 //\r
1074 OutWord (AdapterInfo, (UINT16) (Status & 0xfc00), (UINT32) (AdapterInfo->ioaddr + SCBStatus));\r
1075\r
1076 //\r
1077 // report all the outstanding interrupts\r
1078 //\r
1079 Status = AdapterInfo->Int_Status;\r
1080 if ((Status & SCB_STATUS_FR) != 0) {\r
1081 CdbPtr->StatFlags |= PXE_STATFLAGS_GET_STATUS_RECEIVE;\r
1082 }\r
1083\r
1084 if ((Status & SCB_STATUS_SWI) != 0) {\r
1085 CdbPtr->StatFlags |= PXE_STATFLAGS_GET_STATUS_SOFTWARE;\r
1086 }\r
1087 }\r
1088\r
1089 return ;\r
1090}\r
1091\r
1092\r
1093/**\r
1094 This routine is used to fill media header(s) in transmit packet(s).\r
1095 Copies the MAC address into the media header whether it is dealing\r
1096 with fragmented or non-fragmented packets.\r
1097\r
1098 @param CdbPtr Pointer to the command descriptor block.\r
1099 @param AdapterInfo Pointer to the NIC data structure information which\r
1100 the UNDI driver is layering on..\r
1101\r
1102 @return None\r
1103\r
1104**/\r
1105VOID\r
1106UNDI_FillHeader (\r
1107 IN PXE_CDB *CdbPtr,\r
1108 IN NIC_DATA_INSTANCE *AdapterInfo\r
1109 )\r
1110{\r
1111 PXE_CPB_FILL_HEADER *Cpb;\r
1112 PXE_CPB_FILL_HEADER_FRAGMENTED *Cpbf;\r
1113 EtherHeader *MacHeader;\r
1114 UINTN Index;\r
1115\r
1116 if (CdbPtr->CPBsize == PXE_CPBSIZE_NOT_USED) {\r
1117 CdbPtr->StatFlags = PXE_STATFLAGS_COMMAND_FAILED;\r
1118 CdbPtr->StatCode = PXE_STATCODE_INVALID_CDB;\r
1119 return ;\r
1120 }\r
1121\r
1122 if ((CdbPtr->OpFlags & PXE_OPFLAGS_FILL_HEADER_FRAGMENTED) != 0) {\r
1123 Cpbf = (PXE_CPB_FILL_HEADER_FRAGMENTED *) (UINTN) CdbPtr->CPBaddr;\r
1124\r
1125 //\r
1126 // assume 1st fragment is big enough for the mac header\r
1127 //\r
1128 if ((Cpbf->FragCnt == 0) || (Cpbf->FragDesc[0].FragLen < PXE_MAC_HEADER_LEN_ETHER)) {\r
1129 //\r
1130 // no buffers given\r
1131 //\r
1132 CdbPtr->StatFlags = PXE_STATFLAGS_COMMAND_FAILED;\r
1133 CdbPtr->StatCode = PXE_STATCODE_INVALID_CDB;\r
1134 return ;\r
1135 }\r
1136\r
1137 MacHeader = (EtherHeader *) (UINTN) Cpbf->FragDesc[0].FragAddr;\r
1138 //\r
1139 // we don't swap the protocol bytes\r
1140 //\r
1141 MacHeader->type = Cpbf->Protocol;\r
1142\r
1143 for (Index = 0; Index < PXE_HWADDR_LEN_ETHER; Index++) {\r
1144 MacHeader->dest_addr[Index] = Cpbf->DestAddr[Index];\r
1145 MacHeader->src_addr[Index] = Cpbf->SrcAddr[Index];\r
1146 }\r
1147 } else {\r
1148 Cpb = (PXE_CPB_FILL_HEADER *) (UINTN) CdbPtr->CPBaddr;\r
1149\r
1150 MacHeader = (EtherHeader *) (UINTN) Cpb->MediaHeader;\r
1151 //\r
1152 // we don't swap the protocol bytes\r
1153 //\r
1154 MacHeader->type = Cpb->Protocol;\r
1155\r
1156 for (Index = 0; Index < PXE_HWADDR_LEN_ETHER; Index++) {\r
1157 MacHeader->dest_addr[Index] = Cpb->DestAddr[Index];\r
1158 MacHeader->src_addr[Index] = Cpb->SrcAddr[Index];\r
1159 }\r
1160 }\r
1161\r
1162 return ;\r
1163}\r
1164\r
1165\r
1166/**\r
1167 This routine is used to place a packet into the transmit queue. The data buffers given to\r
1168 this command are to be considered locked and the application or network driver loses\r
1169 ownership of these buffers and must not free or relocate them until the ownership returns.\r
1170 When the packets are transmitted, a transmit complete interrupt is generated (if interrupts\r
1171 are disabled, the transmit interrupt status is still set and can be checked using the UNDI_Status\r
1172 command.\r
1173 Some implementations and adapters support transmitting multiple packets with one transmit\r
1174 command. If this feature is supported, the transmit CPBs can be linked in one transmit\r
1175 command.\r
1176 All UNDIs support fragmented frames, now all network devices or protocols do. If a fragmented\r
1177 frame CPB is given to UNDI and the network device does not support fragmented frames\r
1178 (see !PXE.Implementation flag), the UNDI will have to copy the fragments into a local buffer\r
1179 before transmitting.\r
1180\r
1181 @param CdbPtr Pointer to the command descriptor block.\r
1182 @param AdapterInfo Pointer to the NIC data structure information which\r
1183 the UNDI driver is layering on..\r
1184\r
1185 @return None\r
1186\r
1187**/\r
1188VOID\r
1189UNDI_Transmit (\r
1190 IN PXE_CDB *CdbPtr,\r
1191 IN NIC_DATA_INSTANCE *AdapterInfo\r
1192 )\r
1193{\r
1194\r
1195 if (CdbPtr->CPBsize == PXE_CPBSIZE_NOT_USED) {\r
1196 CdbPtr->StatFlags = PXE_STATFLAGS_COMMAND_FAILED;\r
1197 CdbPtr->StatCode = PXE_STATCODE_INVALID_CDB;\r
1198 return ;\r
1199 }\r
1200\r
1201 CdbPtr->StatCode = (PXE_STATCODE) E100bTransmit (AdapterInfo, CdbPtr->CPBaddr, CdbPtr->OpFlags);\r
1202\r
1203 if (CdbPtr->StatCode != PXE_STATCODE_SUCCESS) {\r
1204 CdbPtr->StatFlags = PXE_STATFLAGS_COMMAND_FAILED;\r
1205 }\r
1206\r
1207 return ;\r
1208}\r
1209\r
1210\r
1211/**\r
1212 When the network adapter has received a frame, this command is used to copy the frame\r
1213 into the driver/application storage location. Once a frame has been copied, it is\r
1214 removed from the receive queue.\r
1215\r
1216 @param CdbPtr Pointer to the command descriptor block.\r
1217 @param AdapterInfo Pointer to the NIC data structure information which\r
1218 the UNDI driver is layering on..\r
1219\r
1220 @return None\r
1221\r
1222**/\r
1223VOID\r
1224UNDI_Receive (\r
1225 IN PXE_CDB *CdbPtr,\r
1226 IN NIC_DATA_INSTANCE *AdapterInfo\r
1227 )\r
1228{\r
1229\r
1230 //\r
1231 // check if RU has started...\r
1232 //\r
1233 if (!AdapterInfo->Receive_Started) {\r
1234 CdbPtr->StatFlags = PXE_STATFLAGS_COMMAND_FAILED;\r
1235 CdbPtr->StatCode = PXE_STATCODE_NOT_INITIALIZED;\r
1236 return ;\r
1237 }\r
1238\r
1239\r
1240 CdbPtr->StatCode = (UINT16) E100bReceive (AdapterInfo, CdbPtr->CPBaddr, CdbPtr->DBaddr);\r
1241 if (CdbPtr->StatCode != PXE_STATCODE_SUCCESS) {\r
1242 CdbPtr->StatFlags = PXE_STATFLAGS_COMMAND_FAILED;\r
1243\r
1244 }\r
1245\r
1246 return ;\r
1247}\r
1248\r
1249\r
1250\r
1251/**\r
1252 This is the main SW UNDI API entry using the newer nii protocol.\r
1253 The parameter passed in is a 64 bit flat model virtual\r
1254 address of the cdb. We then jump into the common routine for both old and\r
1255 new nii protocol entries.\r
1256\r
1257 @param CdbPtr Pointer to the command descriptor block.\r
1258 @param AdapterInfo Pointer to the NIC data structure information which\r
1259 the UNDI driver is layering on..\r
1260\r
1261 @return None\r
1262\r
1263**/\r
1264// TODO: cdb - add argument and description to function comment\r
1265VOID\r
1266UNDI_APIEntry_new (\r
1267 IN UINT64 cdb\r
1268 )\r
1269{\r
1270 PXE_CDB *CdbPtr;\r
1271 NIC_DATA_INSTANCE *AdapterInfo;\r
1272\r
1273 if (cdb == (UINT64) 0) {\r
1274 return ;\r
1275\r
1276 }\r
1277\r
1278 CdbPtr = (PXE_CDB *) (UINTN) cdb;\r
1279\r
1280 if (CdbPtr->IFnum >= pxe_31->IFcnt) {\r
1281 CdbPtr->StatFlags = PXE_STATFLAGS_COMMAND_FAILED;\r
1282 CdbPtr->StatCode = PXE_STATCODE_INVALID_CDB;\r
1283 return ;\r
1284 }\r
1285\r
1286 AdapterInfo = &(UNDI32DeviceList[CdbPtr->IFnum]->NicInfo);\r
1287 //\r
1288 // entering from older entry point\r
1289 //\r
1290 AdapterInfo->VersionFlag = 0x31;\r
1291 UNDI_APIEntry_Common (cdb);\r
1292}\r
1293\r
1294\r
1295/**\r
1296 This is the common routine for both old and new entry point procedures.\r
1297 The parameter passed in is a 64 bit flat model virtual\r
1298 address of the cdb. We then jump into the service routine pointed to by the\r
1299 Api_Table[OpCode].\r
1300\r
1301 @param CdbPtr Pointer to the command descriptor block.\r
1302 @param AdapterInfo Pointer to the NIC data structure information which\r
1303 the UNDI driver is layering on..\r
1304\r
1305 @return None\r
1306\r
1307**/\r
1308// TODO: cdb - add argument and description to function comment\r
1309VOID\r
1310UNDI_APIEntry_Common (\r
1311 IN UINT64 cdb\r
1312 )\r
1313{\r
1314 PXE_CDB *CdbPtr;\r
1315 NIC_DATA_INSTANCE *AdapterInfo;\r
1316 UNDI_CALL_TABLE *tab_ptr;\r
1317\r
1318 CdbPtr = (PXE_CDB *) (UINTN) cdb;\r
1319\r
1320 //\r
1321 // check the OPCODE range\r
1322 //\r
1323 if ((CdbPtr->OpCode > PXE_OPCODE_LAST_VALID) ||\r
1324 (CdbPtr->StatCode != PXE_STATCODE_INITIALIZE) ||\r
1325 (CdbPtr->StatFlags != PXE_STATFLAGS_INITIALIZE) ||\r
1326 (CdbPtr->IFnum >= pxe_31->IFcnt) ) {\r
1327 goto badcdb;\r
1328\r
1329 }\r
1330\r
1331 if (CdbPtr->CPBsize == PXE_CPBSIZE_NOT_USED) {\r
1332 if (CdbPtr->CPBaddr != PXE_CPBADDR_NOT_USED) {\r
1333 goto badcdb;\r
1334 }\r
1335 } else if (CdbPtr->CPBaddr == PXE_CPBADDR_NOT_USED) {\r
1336 goto badcdb;\r
1337 }\r
1338\r
1339 if (CdbPtr->DBsize == PXE_DBSIZE_NOT_USED) {\r
1340 if (CdbPtr->DBaddr != PXE_DBADDR_NOT_USED) {\r
1341 goto badcdb;\r
1342 }\r
1343 } else if (CdbPtr->DBaddr == PXE_DBADDR_NOT_USED) {\r
1344 goto badcdb;\r
1345 }\r
1346\r
1347 //\r
1348 // check if cpbsize and dbsize are as needed\r
1349 // check if opflags are as expected\r
1350 //\r
1351 tab_ptr = &api_table[CdbPtr->OpCode];\r
1352\r
1353 if (tab_ptr->cpbsize != (UINT16) (DONT_CHECK) && tab_ptr->cpbsize != CdbPtr->CPBsize) {\r
1354 goto badcdb;\r
1355 }\r
1356\r
1357 if (tab_ptr->dbsize != (UINT16) (DONT_CHECK) && tab_ptr->dbsize != CdbPtr->DBsize) {\r
1358 goto badcdb;\r
1359 }\r
1360\r
1361 if (tab_ptr->opflags != (UINT16) (DONT_CHECK) && tab_ptr->opflags != CdbPtr->OpFlags) {\r
1362 goto badcdb;\r
1363\r
1364 }\r
1365\r
1366 AdapterInfo = &(UNDI32DeviceList[CdbPtr->IFnum]->NicInfo);\r
1367\r
1368 //\r
1369 // check if UNDI_State is valid for this call\r
1370 //\r
1371 if (tab_ptr->state != (UINT16) (-1)) {\r
1372 //\r
1373 // should atleast be started\r
1374 //\r
1375 if (AdapterInfo->State == PXE_STATFLAGS_GET_STATE_STOPPED) {\r
1376 CdbPtr->StatFlags = PXE_STATFLAGS_COMMAND_FAILED;\r
1377 CdbPtr->StatCode = PXE_STATCODE_NOT_STARTED;\r
1378 return ;\r
1379 }\r
1380 //\r
1381 // check if it should be initialized\r
1382 //\r
1383 if (tab_ptr->state == 2) {\r
1384 if (AdapterInfo->State != PXE_STATFLAGS_GET_STATE_INITIALIZED) {\r
1385 CdbPtr->StatCode = PXE_STATCODE_NOT_INITIALIZED;\r
1386 CdbPtr->StatFlags = PXE_STATFLAGS_COMMAND_FAILED;\r
1387 return ;\r
1388 }\r
1389 }\r
1390 }\r
1391 //\r
1392 // set the return variable for success case here\r
1393 //\r
1394 CdbPtr->StatFlags = PXE_STATFLAGS_COMMAND_COMPLETE;\r
1395 CdbPtr->StatCode = PXE_STATCODE_SUCCESS;\r
1396\r
1397 tab_ptr->api_ptr (CdbPtr, AdapterInfo);\r
1398 return ;\r
1399 //\r
1400 // %% AVL - check for command linking\r
1401 //\r
1402badcdb:\r
1403 CdbPtr->StatFlags = PXE_STATFLAGS_COMMAND_FAILED;\r
1404 CdbPtr->StatCode = PXE_STATCODE_INVALID_CDB;\r
1405 return ;\r
1406}\r
1407\r
1408\r
1409/**\r
1410 When called with a null NicPtr, this routine decrements the number of NICs\r
1411 this UNDI is supporting and removes the NIC_DATA_POINTER from the array.\r
1412 Otherwise, it increments the number of NICs this UNDI is supported and\r
1413 updates the pxe.Fudge to ensure a proper check sum results.\r
1414\r
1415 @param NicPtr Pointer to the NIC data structure.\r
1416\r
1417 @return None\r
1418\r
1419**/\r
1420VOID\r
1421PxeUpdate (\r
1422 IN NIC_DATA_INSTANCE *NicPtr,\r
1423 IN PXE_SW_UNDI *PxePtr\r
1424 )\r
1425{\r
1426 if (NicPtr == NULL) {\r
1427 if (PxePtr->IFcnt > 0) {\r
1428 //\r
1429 // number of NICs this undi supports\r
1430 //\r
1431 PxePtr->IFcnt--;\r
1432 }\r
1433\r
1434 PxePtr->Fudge = (UINT8) (PxePtr->Fudge - CalculateSum8 ((VOID *) PxePtr, PxePtr->Len));\r
1435 return ;\r
1436 }\r
1437\r
1438 //\r
1439 // number of NICs this undi supports\r
1440 //\r
1441 PxePtr->IFcnt++;\r
1442 PxePtr->Fudge = (UINT8) (PxePtr->Fudge - CalculateSum8 ((VOID *) PxePtr, PxePtr->Len));\r
1443\r
1444 return ;\r
1445}\r
1446\r
1447\r
1448/**\r
1449 Initialize the !PXE structure\r
1450\r
1451 @param PxePtr Pointer to SW_UNDI data structure.\r
1452\r
1453 @retval EFI_SUCCESS This driver is added to Controller.\r
1454 @retval other This driver does not support this device.\r
1455\r
1456**/\r
1457VOID\r
1458PxeStructInit (\r
1459 IN PXE_SW_UNDI *PxePtr\r
1460 )\r
1461{\r
1462 //\r
1463 // Initialize the !PXE structure\r
1464 //\r
1465 PxePtr->Signature = PXE_ROMID_SIGNATURE;\r
1466 PxePtr->Len = sizeof (PXE_SW_UNDI);\r
1467 //\r
1468 // cksum\r
1469 //\r
1470 PxePtr->Fudge = 0;\r
1471 //\r
1472 // number of NICs this undi supports\r
1473 //\r
1474 PxePtr->IFcnt = 0;\r
1475 PxePtr->Rev = PXE_ROMID_REV;\r
1476 PxePtr->MajorVer = PXE_ROMID_MAJORVER;\r
1477 PxePtr->MinorVer = PXE_ROMID_MINORVER;\r
1478 PxePtr->reserved1 = 0;\r
1479\r
1480 PxePtr->Implementation = PXE_ROMID_IMP_SW_VIRT_ADDR |\r
1481 PXE_ROMID_IMP_FRAG_SUPPORTED |\r
1482 PXE_ROMID_IMP_CMD_LINK_SUPPORTED |\r
1483 PXE_ROMID_IMP_NVDATA_READ_ONLY |\r
1484 PXE_ROMID_IMP_STATION_ADDR_SETTABLE |\r
1485 PXE_ROMID_IMP_PROMISCUOUS_MULTICAST_RX_SUPPORTED |\r
1486 PXE_ROMID_IMP_PROMISCUOUS_RX_SUPPORTED |\r
1487 PXE_ROMID_IMP_BROADCAST_RX_SUPPORTED |\r
1488 PXE_ROMID_IMP_FILTERED_MULTICAST_RX_SUPPORTED |\r
1489 PXE_ROMID_IMP_SOFTWARE_INT_SUPPORTED |\r
1490 PXE_ROMID_IMP_PACKET_RX_INT_SUPPORTED;\r
1491\r
1492 PxePtr->EntryPoint = (UINT64) (UINTN) UNDI_APIEntry_new;\r
1493 PxePtr->MinorVer = PXE_ROMID_MINORVER_31;\r
1494\r
1495 PxePtr->reserved2[0] = 0;\r
1496 PxePtr->reserved2[1] = 0;\r
1497 PxePtr->reserved2[2] = 0;\r
1498 PxePtr->BusCnt = 1;\r
1499 PxePtr->BusType[0] = PXE_BUSTYPE_PCI;\r
1500\r
1501 PxePtr->Fudge = (UINT8) (PxePtr->Fudge - CalculateSum8 ((VOID *) PxePtr, PxePtr->Len));\r
1502}\r
1503\r