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