1 /** @file 2 Declaration of strctures and functions for MnpDxe driver. 3 4 Copyright (c) 2005 - 2016, Intel Corporation. All rights reserved.<BR> 5 SPDX-License-Identifier: BSD-2-Clause-Patent 6 7 **/ 8 9 #ifndef _MNP_DRIVER_H_ 10 #define _MNP_DRIVER_H_ 11 12 #include <Uefi.h> 13 14 #include <Protocol/ManagedNetwork.h> 15 #include <Protocol/SimpleNetwork.h> 16 #include <Protocol/ServiceBinding.h> 17 #include <Protocol/VlanConfig.h> 18 19 #include <Library/BaseLib.h> 20 #include <Library/BaseMemoryLib.h> 21 #include <Library/DebugLib.h> 22 #include <Library/MemoryAllocationLib.h> 23 #include <Library/UefiBootServicesTableLib.h> 24 #include <Library/UefiLib.h> 25 #include <Library/NetLib.h> 26 #include <Library/DpcLib.h> 27 #include <Library/UefiRuntimeServicesTableLib.h> 28 #include <Library/DevicePathLib.h> 29 #include <Library/PrintLib.h> 30 31 #include "ComponentName.h" 32 33 #define MNP_DEVICE_DATA_SIGNATURE SIGNATURE_32 ('M', 'n', 'p', 'D') 34 35 // 36 // Global Variables 37 // 38 extern EFI_DRIVER_BINDING_PROTOCOL gMnpDriverBinding; 39 40 typedef struct { 41 UINT32 Signature; 42 43 EFI_HANDLE ControllerHandle; 44 EFI_HANDLE ImageHandle; 45 46 EFI_VLAN_CONFIG_PROTOCOL VlanConfig; 47 UINTN NumberOfVlan; 48 CHAR16 *MacString; 49 EFI_SIMPLE_NETWORK_PROTOCOL *Snp; 50 51 // 52 // List of MNP_SERVICE_DATA 53 // 54 LIST_ENTRY ServiceList; 55 // 56 // Number of configured MNP Service Binding child 57 // 58 UINTN ConfiguredChildrenNumber; 59 60 LIST_ENTRY GroupAddressList; 61 UINT32 GroupAddressCount; 62 63 LIST_ENTRY FreeTxBufList; 64 LIST_ENTRY AllTxBufList; 65 UINT32 TxBufCount; 66 67 NET_BUF_QUEUE FreeNbufQue; 68 INTN NbufCnt; 69 70 EFI_EVENT PollTimer; 71 BOOLEAN EnableSystemPoll; 72 73 EFI_EVENT TimeoutCheckTimer; 74 EFI_EVENT MediaDetectTimer; 75 76 UINT32 UnicastCount; 77 UINT32 BroadcastCount; 78 UINT32 MulticastCount; 79 UINT32 PromiscuousCount; 80 81 // 82 // The size of the data buffer in the MNP_PACKET_BUFFER used to 83 // store a packet. 84 // 85 UINT32 BufferLength; 86 UINT32 PaddingSize; 87 NET_BUF *RxNbufCache; 88 } MNP_DEVICE_DATA; 89 90 #define MNP_DEVICE_DATA_FROM_THIS(a) \ 91 CR ( \ 92 (a), \ 93 MNP_DEVICE_DATA, \ 94 VlanConfig, \ 95 MNP_DEVICE_DATA_SIGNATURE \ 96 ) 97 98 #define MNP_SERVICE_DATA_SIGNATURE SIGNATURE_32 ('M', 'n', 'p', 'S') 99 100 typedef struct { 101 UINT32 Signature; 102 103 LIST_ENTRY Link; 104 105 MNP_DEVICE_DATA *MnpDeviceData; 106 EFI_HANDLE ServiceHandle; 107 EFI_SERVICE_BINDING_PROTOCOL ServiceBinding; 108 EFI_DEVICE_PATH_PROTOCOL *DevicePath; 109 110 LIST_ENTRY ChildrenList; 111 UINTN ChildrenNumber; 112 113 UINT32 Mtu; 114 115 UINT16 VlanId; 116 UINT8 Priority; 117 } MNP_SERVICE_DATA; 118 119 120 #define MNP_SERVICE_DATA_FROM_THIS(a) \ 121 CR ( \ 122 (a), \ 123 MNP_SERVICE_DATA, \ 124 ServiceBinding, \ 125 MNP_SERVICE_DATA_SIGNATURE \ 126 ) 127 128 #define MNP_SERVICE_DATA_FROM_LINK(a) \ 129 CR ( \ 130 (a), \ 131 MNP_SERVICE_DATA, \ 132 Link, \ 133 MNP_SERVICE_DATA_SIGNATURE \ 134 ) 135 136 137 /** 138 Test to see if this driver supports ControllerHandle. This service 139 is called by the EFI boot service ConnectController(). In 140 order to make drivers as small as possible, there are a few calling 141 restrictions for this service. ConnectController() must 142 follow these calling restrictions. If any other agent wishes to call 143 Supported() it must also follow these calling restrictions. 144 145 @param[in] This Protocol instance pointer. 146 @param[in] ControllerHandle Handle of device to test. 147 @param[in] RemainingDevicePath Optional parameter use to pick a specific 148 child device to start. 149 150 @retval EFI_SUCCESS This driver supports this device. 151 @retval EFI_ALREADY_STARTED This driver is already running on this device. 152 @retval Others This driver does not support this device. 153 154 **/ 155 EFI_STATUS 156 EFIAPI 157 MnpDriverBindingSupported ( 158 IN EFI_DRIVER_BINDING_PROTOCOL *This, 159 IN EFI_HANDLE ControllerHandle, 160 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL 161 ); 162 163 /** 164 Start this driver on ControllerHandle. This service is called by the 165 EFI boot service ConnectController(). In order to make drivers as small 166 as possible, there are a few calling restrictions for this service. 167 ConnectController() must follow these calling restrictions. If any other 168 agent wishes to call Start() it must also follow these calling restrictions. 169 170 @param[in] This Protocol instance pointer. 171 @param[in] ControllerHandle Handle of device to bind driver to. 172 @param[in] RemainingDevicePath Optional parameter use to pick a specific 173 child device to start. 174 175 @retval EFI_SUCCESS This driver is added to ControllerHandle. 176 @retval EFI_ALREADY_STARTED This driver is already running on ControllerHandle. 177 @retval EFI_OUT_OF_RESOURCES Failed to allocate memory for Mnp Service Data. 178 @retval Others This driver does not support this device. 179 180 **/ 181 EFI_STATUS 182 EFIAPI 183 MnpDriverBindingStart ( 184 IN EFI_DRIVER_BINDING_PROTOCOL *This, 185 IN EFI_HANDLE ControllerHandle, 186 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL 187 ); 188 189 190 /** 191 Stop this driver on ControllerHandle. This service is called by the 192 EFI boot service DisconnectController(). In order to make drivers as 193 small as possible, there are a few calling restrictions for this service. 194 DisconnectController() must follow these calling restrictions. If any other 195 agent wishes to call Stop() it must also follow these calling restrictions. 196 197 @param[in] This Protocol instance pointer. 198 @param[in] ControllerHandle Handle of device to stop driver on. 199 @param[in] NumberOfChildren Number of Handles in ChildHandleBuffer. If 200 number of children is zero stop the entire 201 bus driver. 202 @param[in] ChildHandleBuffer List of Child Handles to Stop. 203 204 @retval EFI_SUCCESS This driver is removed ControllerHandle. 205 @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error. 206 207 **/ 208 EFI_STATUS 209 EFIAPI 210 MnpDriverBindingStop ( 211 IN EFI_DRIVER_BINDING_PROTOCOL *This, 212 IN EFI_HANDLE ControllerHandle, 213 IN UINTN NumberOfChildren, 214 IN EFI_HANDLE *ChildHandleBuffer OPTIONAL 215 ); 216 217 /** 218 Creates a child handle with a set of I/O services. 219 220 @param[in] This Protocol instance pointer. 221 @param[in, out] ChildHandle Pointer to the handle of the child to create. If 222 it is NULL, then a new handle is created. If 223 it is not NULL, then the I/O services are added 224 to the existing child handle. 225 226 @retval EFI_SUCCES The protocol was added to ChildHandle. 227 @retval EFI_INVALID_PARAMETER ChildHandle is NULL. 228 @retval EFI_OUT_OF_RESOURCES There are not enough resources available to 229 create the child. 230 @retval Others The child handle was not created. 231 232 **/ 233 EFI_STATUS 234 EFIAPI 235 MnpServiceBindingCreateChild ( 236 IN EFI_SERVICE_BINDING_PROTOCOL *This, 237 IN OUT EFI_HANDLE *ChildHandle 238 ); 239 240 /** 241 Destroys a child handle with a set of I/O services. 242 243 The DestroyChild() function does the opposite of CreateChild(). It removes a 244 protocol that was installed by CreateChild() from ChildHandle. If the removed 245 protocol is the last protocol on ChildHandle, then ChildHandle is destroyed. 246 247 @param[in] This Pointer to the EFI_SERVICE_BINDING_PROTOCOL 248 instance. 249 @param[in] ChildHandle Handle of the child to destroy. 250 251 @retval EFI_SUCCES The protocol was removed from ChildHandle. 252 @retval EFI_UNSUPPORTED ChildHandle does not support the protocol that 253 is being removed. 254 @retval EFI_INVALID_PARAMETER ChildHandle is NULL. 255 @retval EFI_ACCESS_DENIED The protocol could not be removed from the 256 ChildHandle because its services are being 257 used. 258 @retval Others The child handle was not destroyed. 259 260 **/ 261 EFI_STATUS 262 EFIAPI 263 MnpServiceBindingDestroyChild ( 264 IN EFI_SERVICE_BINDING_PROTOCOL *This, 265 IN EFI_HANDLE ChildHandle 266 ); 267 268 #endif 269