]>
Commit | Line | Data |
---|---|---|
b6dfc654 LE |
1 | /** @file\r |
2 | \r | |
3 | Implementation of the SNP.GetStatus() function and its private helpers if\r | |
4 | any.\r | |
5 | \r | |
6 | Copyright (C) 2013, Red Hat, Inc.\r | |
c4046161 | 7 | Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.<BR>\r |
b6dfc654 LE |
8 | \r |
9 | This program and the accompanying materials are licensed and made available\r | |
10 | under the terms and conditions of the BSD License which accompanies this\r | |
11 | distribution. The full text of the license may be found at\r | |
12 | http://opensource.org/licenses/bsd-license.php\r | |
13 | \r | |
14 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT\r | |
15 | WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
16 | \r | |
17 | **/\r | |
18 | \r | |
19 | #include <Library/BaseLib.h>\r | |
20 | #include <Library/UefiBootServicesTableLib.h>\r | |
21 | \r | |
22 | #include "VirtioNet.h"\r | |
23 | \r | |
24 | /**\r | |
25 | Reads the current interrupt status and recycled transmit buffer status from\r | |
26 | a network interface.\r | |
27 | \r | |
28 | @param This The protocol instance pointer.\r | |
29 | @param InterruptStatus A pointer to the bit mask of the currently active\r | |
30 | interrupts If this is NULL, the interrupt status will\r | |
31 | not be read from the device. If this is not NULL, the\r | |
32 | interrupt status will be read from the device. When\r | |
33 | the interrupt status is read, it will also be\r | |
34 | cleared. Clearing the transmit interrupt does not\r | |
35 | empty the recycled transmit buffer array.\r | |
36 | @param TxBuf Recycled transmit buffer address. The network\r | |
37 | interface will not transmit if its internal recycled\r | |
38 | transmit buffer array is full. Reading the transmit\r | |
39 | buffer does not clear the transmit interrupt. If this\r | |
40 | is NULL, then the transmit buffer status will not be\r | |
41 | read. If there are no transmit buffers to recycle and\r | |
42 | TxBuf is not NULL, * TxBuf will be set to NULL.\r | |
43 | \r | |
44 | @retval EFI_SUCCESS The status of the network interface was\r | |
45 | retrieved.\r | |
46 | @retval EFI_NOT_STARTED The network interface has not been started.\r | |
47 | @retval EFI_INVALID_PARAMETER One or more of the parameters has an\r | |
48 | unsupported value.\r | |
49 | @retval EFI_DEVICE_ERROR The command could not be sent to the network\r | |
50 | interface.\r | |
51 | @retval EFI_UNSUPPORTED This function is not supported by the network\r | |
52 | interface.\r | |
53 | \r | |
54 | **/\r | |
55 | \r | |
56 | EFI_STATUS\r | |
57 | EFIAPI\r | |
58 | VirtioNetGetStatus (\r | |
59 | IN EFI_SIMPLE_NETWORK_PROTOCOL *This,\r | |
60 | OUT UINT32 *InterruptStatus OPTIONAL,\r | |
61 | OUT VOID **TxBuf OPTIONAL\r | |
62 | )\r | |
63 | {\r | |
64 | VNET_DEV *Dev;\r | |
65 | EFI_TPL OldTpl;\r | |
66 | EFI_STATUS Status;\r | |
67 | UINT16 RxCurUsed;\r | |
68 | UINT16 TxCurUsed;\r | |
69 | \r | |
70 | if (This == NULL) {\r | |
71 | return EFI_INVALID_PARAMETER;\r | |
72 | }\r | |
73 | \r | |
74 | Dev = VIRTIO_NET_FROM_SNP (This);\r | |
75 | OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r | |
76 | switch (Dev->Snm.State) {\r | |
77 | case EfiSimpleNetworkStopped:\r | |
78 | Status = EFI_NOT_STARTED;\r | |
79 | goto Exit;\r | |
80 | case EfiSimpleNetworkStarted:\r | |
81 | Status = EFI_DEVICE_ERROR;\r | |
82 | goto Exit;\r | |
83 | default:\r | |
84 | break;\r | |
85 | }\r | |
86 | \r | |
87 | //\r | |
88 | // update link status\r | |
89 | //\r | |
90 | if (Dev->Snm.MediaPresentSupported) {\r | |
91 | UINT16 LinkStatus;\r | |
92 | \r | |
56f65ed8 | 93 | Status = VIRTIO_CFG_READ (Dev, LinkStatus, &LinkStatus);\r |
b6dfc654 LE |
94 | if (EFI_ERROR (Status)) {\r |
95 | goto Exit;\r | |
96 | }\r | |
c4046161 JJ |
97 | Dev->Snm.MediaPresent =\r |
98 | (BOOLEAN) ((LinkStatus & VIRTIO_NET_S_LINK_UP) != 0);\r | |
b6dfc654 LE |
99 | }\r |
100 | \r | |
101 | //\r | |
102 | // virtio-0.9.5, 2.4.2 Receiving Used Buffers From the Device\r | |
103 | //\r | |
104 | MemoryFence ();\r | |
105 | RxCurUsed = *Dev->RxRing.Used.Idx;\r | |
106 | TxCurUsed = *Dev->TxRing.Used.Idx;\r | |
dc9447bd | 107 | MemoryFence ();\r |
b6dfc654 LE |
108 | \r |
109 | if (InterruptStatus != NULL) {\r | |
110 | //\r | |
111 | // report the receive interrupt if there is data available for reception,\r | |
112 | // report the transmit interrupt if we have transmitted at least one buffer\r | |
113 | //\r | |
114 | *InterruptStatus = 0;\r | |
115 | if (Dev->RxLastUsed != RxCurUsed) {\r | |
116 | *InterruptStatus |= EFI_SIMPLE_NETWORK_RECEIVE_INTERRUPT;\r | |
117 | }\r | |
118 | if (Dev->TxLastUsed != TxCurUsed) {\r | |
119 | ASSERT (Dev->TxCurPending > 0);\r | |
120 | *InterruptStatus |= EFI_SIMPLE_NETWORK_TRANSMIT_INTERRUPT;\r | |
121 | }\r | |
122 | }\r | |
123 | \r | |
124 | if (TxBuf != NULL) {\r | |
125 | if (Dev->TxLastUsed == TxCurUsed) {\r | |
126 | *TxBuf = NULL;\r | |
127 | }\r | |
128 | else {\r | |
129 | UINT16 UsedElemIdx;\r | |
130 | UINT32 DescIdx;\r | |
131 | \r | |
132 | //\r | |
133 | // fetch the first descriptor among those that the hypervisor reports\r | |
134 | // completed\r | |
135 | //\r | |
136 | ASSERT (Dev->TxCurPending > 0);\r | |
137 | ASSERT (Dev->TxCurPending <= Dev->TxMaxPending);\r | |
138 | \r | |
139 | UsedElemIdx = Dev->TxLastUsed++ % Dev->TxRing.QueueSize;\r | |
140 | DescIdx = Dev->TxRing.Used.UsedElem[UsedElemIdx].Id;\r | |
8258c4e6 | 141 | ASSERT (DescIdx < (UINT32) (2 * Dev->TxMaxPending - 1));\r |
b6dfc654 LE |
142 | \r |
143 | //\r | |
144 | // report buffer address to caller that has been enqueued by caller\r | |
145 | //\r | |
8258c4e6 | 146 | *TxBuf = (VOID *)(UINTN) Dev->TxRing.Desc[DescIdx + 1].Addr;\r |
b6dfc654 LE |
147 | \r |
148 | //\r | |
149 | // now this descriptor can be used again to enqueue a transmit buffer\r | |
150 | //\r | |
151 | Dev->TxFreeStack[--Dev->TxCurPending] = (UINT16) DescIdx;\r | |
152 | }\r | |
153 | }\r | |
154 | \r | |
155 | Status = EFI_SUCCESS;\r | |
156 | \r | |
157 | Exit:\r | |
158 | gBS->RestoreTPL (OldTpl);\r | |
159 | return Status;\r | |
160 | }\r |