Commit | Line | Data |
---|---|---|
fceaf24a | 1 | /* |
fceaf24a HJ |
2 | * Copyright (c) 2009, Microsoft Corporation. |
3 | * | |
4 | * This program is free software; you can redistribute it and/or modify it | |
5 | * under the terms and conditions of the GNU General Public License, | |
6 | * version 2, as published by the Free Software Foundation. | |
7 | * | |
8 | * This program is distributed in the hope it will be useful, but WITHOUT | |
9 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
10 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | |
11 | * more details. | |
12 | * | |
13 | * You should have received a copy of the GNU General Public License along with | |
14 | * this program; if not, write to the Free Software Foundation, Inc., 59 Temple | |
15 | * Place - Suite 330, Boston, MA 02111-1307 USA. | |
16 | * | |
17 | * Authors: | |
d0e94d17 | 18 | * Haiyang Zhang <haiyangz@microsoft.com> |
fceaf24a | 19 | * Hank Janssen <hjanssen@microsoft.com> |
fceaf24a | 20 | */ |
5654e932 | 21 | #include <linux/kernel.h> |
0ffa63b0 | 22 | #include <linux/mm.h> |
b4362c9c | 23 | #include <linux/delay.h> |
21a80820 | 24 | #include <linux/io.h> |
5a0e3ad6 | 25 | #include <linux/slab.h> |
4983b39a | 26 | #include "osd.h" |
645954c5 | 27 | #include "logging.h" |
af167ae9 | 28 | #include "netvsc.h" |
043efcc3 | 29 | #include "rndis_filter.h" |
fceaf24a HJ |
30 | |
31 | ||
454f18a9 | 32 | /* Globals */ |
21a80820 | 33 | static const char *gDriverName = "netvsc"; |
fceaf24a | 34 | |
454f18a9 | 35 | /* {F8615163-DF3E-46c5-913F-F2D2F965ED0E} */ |
caf26a31 GKH |
36 | static const struct hv_guid gNetVscDeviceType = { |
37 | .data = { | |
38 | 0x63, 0x51, 0x61, 0xF8, 0x3E, 0xDF, 0xc5, 0x46, | |
39 | 0x91, 0x3F, 0xF2, 0xD2, 0xF9, 0x65, 0xED, 0x0E | |
40 | } | |
fceaf24a HJ |
41 | }; |
42 | ||
21a80820 GKH |
43 | static int NetVscOnDeviceAdd(struct hv_device *Device, void *AdditionalInfo); |
44 | ||
45 | static int NetVscOnDeviceRemove(struct hv_device *Device); | |
46 | ||
47 | static void NetVscOnCleanup(struct hv_driver *Driver); | |
48 | ||
49 | static void NetVscOnChannelCallback(void *context); | |
50 | ||
51 | static int NetVscInitializeSendBufferWithNetVsp(struct hv_device *Device); | |
52 | ||
53 | static int NetVscInitializeReceiveBufferWithNetVsp(struct hv_device *Device); | |
54 | ||
ce9ea4cf | 55 | static int NetVscDestroySendBuffer(struct netvsc_device *NetDevice); |
21a80820 | 56 | |
ce9ea4cf | 57 | static int NetVscDestroyReceiveBuffer(struct netvsc_device *NetDevice); |
21a80820 GKH |
58 | |
59 | static int NetVscConnectToVsp(struct hv_device *Device); | |
60 | ||
61 | static void NetVscOnSendCompletion(struct hv_device *Device, | |
62 | struct vmpacket_descriptor *Packet); | |
63 | ||
64 | static int NetVscOnSend(struct hv_device *Device, | |
65 | struct hv_netvsc_packet *Packet); | |
66 | ||
67 | static void NetVscOnReceive(struct hv_device *Device, | |
68 | struct vmpacket_descriptor *Packet); | |
69 | ||
70 | static void NetVscOnReceiveCompletion(void *Context); | |
71 | ||
72 | static void NetVscSendReceiveCompletion(struct hv_device *Device, | |
73 | u64 TransactionId); | |
74 | ||
fceaf24a | 75 | |
ce9ea4cf | 76 | static struct netvsc_device *AllocNetDevice(struct hv_device *Device) |
fceaf24a | 77 | { |
ce9ea4cf | 78 | struct netvsc_device *netDevice; |
fceaf24a | 79 | |
ce9ea4cf | 80 | netDevice = kzalloc(sizeof(struct netvsc_device), GFP_KERNEL); |
fceaf24a HJ |
81 | if (!netDevice) |
82 | return NULL; | |
83 | ||
454f18a9 | 84 | /* Set to 2 to allow both inbound and outbound traffic */ |
f4888417 | 85 | atomic_cmpxchg(&netDevice->RefCount, 0, 2); |
fceaf24a HJ |
86 | |
87 | netDevice->Device = Device; | |
88 | Device->Extension = netDevice; | |
89 | ||
90 | return netDevice; | |
91 | } | |
92 | ||
ce9ea4cf | 93 | static void FreeNetDevice(struct netvsc_device *Device) |
fceaf24a | 94 | { |
7a09876d | 95 | WARN_ON(atomic_read(&Device->RefCount) == 0); |
fceaf24a | 96 | Device->Device->Extension = NULL; |
8c69f52a | 97 | kfree(Device); |
fceaf24a HJ |
98 | } |
99 | ||
100 | ||
454f18a9 | 101 | /* Get the net device object iff exists and its refcount > 1 */ |
ce9ea4cf | 102 | static struct netvsc_device *GetOutboundNetDevice(struct hv_device *Device) |
fceaf24a | 103 | { |
ce9ea4cf | 104 | struct netvsc_device *netDevice; |
fceaf24a | 105 | |
21a80820 | 106 | netDevice = Device->Extension; |
f4888417 BP |
107 | if (netDevice && atomic_read(&netDevice->RefCount) > 1) |
108 | atomic_inc(&netDevice->RefCount); | |
fceaf24a | 109 | else |
fceaf24a | 110 | netDevice = NULL; |
fceaf24a HJ |
111 | |
112 | return netDevice; | |
113 | } | |
114 | ||
454f18a9 | 115 | /* Get the net device object iff exists and its refcount > 0 */ |
ce9ea4cf | 116 | static struct netvsc_device *GetInboundNetDevice(struct hv_device *Device) |
fceaf24a | 117 | { |
ce9ea4cf | 118 | struct netvsc_device *netDevice; |
fceaf24a | 119 | |
21a80820 | 120 | netDevice = Device->Extension; |
f4888417 BP |
121 | if (netDevice && atomic_read(&netDevice->RefCount)) |
122 | atomic_inc(&netDevice->RefCount); | |
fceaf24a | 123 | else |
fceaf24a | 124 | netDevice = NULL; |
fceaf24a HJ |
125 | |
126 | return netDevice; | |
127 | } | |
128 | ||
21a80820 | 129 | static void PutNetDevice(struct hv_device *Device) |
fceaf24a | 130 | { |
ce9ea4cf | 131 | struct netvsc_device *netDevice; |
fceaf24a | 132 | |
21a80820 | 133 | netDevice = Device->Extension; |
972b9529 | 134 | /* ASSERT(netDevice); */ |
fceaf24a | 135 | |
f4888417 | 136 | atomic_dec(&netDevice->RefCount); |
fceaf24a HJ |
137 | } |
138 | ||
ce9ea4cf | 139 | static struct netvsc_device *ReleaseOutboundNetDevice(struct hv_device *Device) |
fceaf24a | 140 | { |
ce9ea4cf | 141 | struct netvsc_device *netDevice; |
fceaf24a | 142 | |
21a80820 | 143 | netDevice = Device->Extension; |
fceaf24a HJ |
144 | if (netDevice == NULL) |
145 | return NULL; | |
146 | ||
454f18a9 | 147 | /* Busy wait until the ref drop to 2, then set it to 1 */ |
f4888417 | 148 | while (atomic_cmpxchg(&netDevice->RefCount, 2, 1) != 2) |
b4362c9c | 149 | udelay(100); |
fceaf24a HJ |
150 | |
151 | return netDevice; | |
152 | } | |
153 | ||
ce9ea4cf | 154 | static struct netvsc_device *ReleaseInboundNetDevice(struct hv_device *Device) |
fceaf24a | 155 | { |
ce9ea4cf | 156 | struct netvsc_device *netDevice; |
fceaf24a | 157 | |
21a80820 | 158 | netDevice = Device->Extension; |
fceaf24a HJ |
159 | if (netDevice == NULL) |
160 | return NULL; | |
161 | ||
454f18a9 | 162 | /* Busy wait until the ref drop to 1, then set it to 0 */ |
f4888417 | 163 | while (atomic_cmpxchg(&netDevice->RefCount, 1, 0) != 1) |
b4362c9c | 164 | udelay(100); |
fceaf24a HJ |
165 | |
166 | Device->Extension = NULL; | |
167 | return netDevice; | |
168 | } | |
169 | ||
3e189519 | 170 | /* |
21a80820 GKH |
171 | * NetVscInitialize - Main entry point |
172 | */ | |
173 | int NetVscInitialize(struct hv_driver *drv) | |
fceaf24a | 174 | { |
7e23a6e9 | 175 | struct netvsc_driver *driver = (struct netvsc_driver *)drv; |
fceaf24a | 176 | |
21a80820 GKH |
177 | DPRINT_DBG(NETVSC, "sizeof(struct hv_netvsc_packet)=%zd, " |
178 | "sizeof(struct nvsp_message)=%zd, " | |
179 | "sizeof(struct vmtransfer_page_packet_header)=%zd", | |
180 | sizeof(struct hv_netvsc_packet), | |
181 | sizeof(struct nvsp_message), | |
182 | sizeof(struct vmtransfer_page_packet_header)); | |
fceaf24a | 183 | |
454f18a9 | 184 | /* Make sure we are at least 2 pages since 1 page is used for control */ |
972b9529 | 185 | /* ASSERT(driver->RingBufferSize >= (PAGE_SIZE << 1)); */ |
fceaf24a HJ |
186 | |
187 | drv->name = gDriverName; | |
caf26a31 | 188 | memcpy(&drv->deviceType, &gNetVscDeviceType, sizeof(struct hv_guid)); |
fceaf24a | 189 | |
454f18a9 | 190 | /* Make sure it is set by the caller */ |
972b9529 BP |
191 | /* FIXME: These probably should still be tested in some way */ |
192 | /* ASSERT(driver->OnReceiveCallback); */ | |
193 | /* ASSERT(driver->OnLinkStatusChanged); */ | |
fceaf24a | 194 | |
454f18a9 | 195 | /* Setup the dispatch table */ |
21a80820 GKH |
196 | driver->Base.OnDeviceAdd = NetVscOnDeviceAdd; |
197 | driver->Base.OnDeviceRemove = NetVscOnDeviceRemove; | |
198 | driver->Base.OnCleanup = NetVscOnCleanup; | |
fceaf24a | 199 | |
21a80820 | 200 | driver->OnSend = NetVscOnSend; |
fceaf24a HJ |
201 | |
202 | RndisFilterInit(driver); | |
21a80820 | 203 | return 0; |
fceaf24a HJ |
204 | } |
205 | ||
21a80820 | 206 | static int NetVscInitializeReceiveBufferWithNetVsp(struct hv_device *Device) |
fceaf24a | 207 | { |
21a80820 | 208 | int ret = 0; |
ce9ea4cf | 209 | struct netvsc_device *netDevice; |
223c1aa6 | 210 | struct nvsp_message *initPacket; |
fceaf24a | 211 | |
fceaf24a | 212 | netDevice = GetOutboundNetDevice(Device); |
21a80820 GKH |
213 | if (!netDevice) { |
214 | DPRINT_ERR(NETVSC, "unable to get net device..." | |
215 | "device being destroyed?"); | |
fceaf24a HJ |
216 | return -1; |
217 | } | |
972b9529 | 218 | /* ASSERT(netDevice->ReceiveBufferSize > 0); */ |
21a80820 | 219 | /* page-size grandularity */ |
972b9529 | 220 | /* ASSERT((netDevice->ReceiveBufferSize & (PAGE_SIZE - 1)) == 0); */ |
fceaf24a | 221 | |
21a80820 GKH |
222 | netDevice->ReceiveBuffer = |
223 | osd_PageAlloc(netDevice->ReceiveBufferSize >> PAGE_SHIFT); | |
224 | if (!netDevice->ReceiveBuffer) { | |
225 | DPRINT_ERR(NETVSC, | |
226 | "unable to allocate receive buffer of size %d", | |
227 | netDevice->ReceiveBufferSize); | |
fceaf24a HJ |
228 | ret = -1; |
229 | goto Cleanup; | |
230 | } | |
21a80820 | 231 | /* page-aligned buffer */ |
972b9529 BP |
232 | /* ASSERT(((unsigned long)netDevice->ReceiveBuffer & (PAGE_SIZE - 1)) == */ |
233 | /* 0); */ | |
fceaf24a HJ |
234 | |
235 | DPRINT_INFO(NETVSC, "Establishing receive buffer's GPADL..."); | |
236 | ||
454f18a9 BP |
237 | /* |
238 | * Establish the gpadl handle for this buffer on this | |
239 | * channel. Note: This call uses the vmbus connection rather | |
240 | * than the channel to establish the gpadl handle. | |
241 | */ | |
fceaf24a | 242 | ret = Device->Driver->VmbusChannelInterface.EstablishGpadl(Device, |
21a80820 GKH |
243 | netDevice->ReceiveBuffer, |
244 | netDevice->ReceiveBufferSize, | |
245 | &netDevice->ReceiveBufferGpadlHandle); | |
246 | if (ret != 0) { | |
247 | DPRINT_ERR(NETVSC, | |
248 | "unable to establish receive buffer's gpadl"); | |
fceaf24a HJ |
249 | goto Cleanup; |
250 | } | |
251 | ||
bfc30aae | 252 | /* osd_WaitEventWait(ext->ChannelInitEvent); */ |
fceaf24a | 253 | |
454f18a9 | 254 | /* Notify the NetVsp of the gpadl handle */ |
fceaf24a HJ |
255 | DPRINT_INFO(NETVSC, "Sending NvspMessage1TypeSendReceiveBuffer..."); |
256 | ||
257 | initPacket = &netDevice->ChannelInitPacket; | |
258 | ||
223c1aa6 | 259 | memset(initPacket, 0, sizeof(struct nvsp_message)); |
fceaf24a | 260 | |
21a80820 GKH |
261 | initPacket->Header.MessageType = NvspMessage1TypeSendReceiveBuffer; |
262 | initPacket->Messages.Version1Messages.SendReceiveBuffer.GpadlHandle = netDevice->ReceiveBufferGpadlHandle; | |
263 | initPacket->Messages.Version1Messages.SendReceiveBuffer.Id = NETVSC_RECEIVE_BUFFER_ID; | |
fceaf24a | 264 | |
454f18a9 | 265 | /* Send the gpadl notification request */ |
fceaf24a | 266 | ret = Device->Driver->VmbusChannelInterface.SendPacket(Device, |
21a80820 GKH |
267 | initPacket, |
268 | sizeof(struct nvsp_message), | |
269 | (unsigned long)initPacket, | |
270 | VmbusPacketTypeDataInBand, | |
271 | VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED); | |
272 | if (ret != 0) { | |
273 | DPRINT_ERR(NETVSC, | |
274 | "unable to send receive buffer's gpadl to netvsp"); | |
fceaf24a HJ |
275 | goto Cleanup; |
276 | } | |
277 | ||
bfc30aae | 278 | osd_WaitEventWait(netDevice->ChannelInitEvent); |
fceaf24a | 279 | |
454f18a9 | 280 | /* Check the response */ |
21a80820 GKH |
281 | if (initPacket->Messages.Version1Messages.SendReceiveBufferComplete.Status != NvspStatusSuccess) { |
282 | DPRINT_ERR(NETVSC, "Unable to complete receive buffer " | |
283 | "initialzation with NetVsp - status %d", | |
284 | initPacket->Messages.Version1Messages.SendReceiveBufferComplete.Status); | |
fceaf24a HJ |
285 | ret = -1; |
286 | goto Cleanup; | |
287 | } | |
288 | ||
454f18a9 | 289 | /* Parse the response */ |
972b9529 BP |
290 | /* ASSERT(netDevice->ReceiveSectionCount == 0); */ |
291 | /* ASSERT(netDevice->ReceiveSections == NULL); */ | |
fceaf24a HJ |
292 | |
293 | netDevice->ReceiveSectionCount = initPacket->Messages.Version1Messages.SendReceiveBufferComplete.NumSections; | |
294 | ||
223c1aa6 | 295 | netDevice->ReceiveSections = kmalloc(netDevice->ReceiveSectionCount * sizeof(struct nvsp_1_receive_buffer_section), GFP_KERNEL); |
21a80820 | 296 | if (netDevice->ReceiveSections == NULL) { |
fceaf24a HJ |
297 | ret = -1; |
298 | goto Cleanup; | |
299 | } | |
300 | ||
301 | memcpy(netDevice->ReceiveSections, | |
302 | initPacket->Messages.Version1Messages.SendReceiveBufferComplete.Sections, | |
223c1aa6 | 303 | netDevice->ReceiveSectionCount * sizeof(struct nvsp_1_receive_buffer_section)); |
fceaf24a | 304 | |
21a80820 GKH |
305 | DPRINT_INFO(NETVSC, "Receive sections info (count %d, offset %d, " |
306 | "endoffset %d, suballoc size %d, num suballocs %d)", | |
307 | netDevice->ReceiveSectionCount, | |
308 | netDevice->ReceiveSections[0].Offset, | |
309 | netDevice->ReceiveSections[0].EndOffset, | |
310 | netDevice->ReceiveSections[0].SubAllocationSize, | |
311 | netDevice->ReceiveSections[0].NumSubAllocations); | |
fceaf24a | 312 | |
21a80820 GKH |
313 | /* |
314 | * For 1st release, there should only be 1 section that represents the | |
315 | * entire receive buffer | |
316 | */ | |
fceaf24a | 317 | if (netDevice->ReceiveSectionCount != 1 || |
21a80820 | 318 | netDevice->ReceiveSections->Offset != 0) { |
fceaf24a HJ |
319 | ret = -1; |
320 | goto Cleanup; | |
321 | } | |
322 | ||
323 | goto Exit; | |
324 | ||
325 | Cleanup: | |
326 | NetVscDestroyReceiveBuffer(netDevice); | |
327 | ||
328 | Exit: | |
329 | PutNetDevice(Device); | |
fceaf24a HJ |
330 | return ret; |
331 | } | |
332 | ||
21a80820 | 333 | static int NetVscInitializeSendBufferWithNetVsp(struct hv_device *Device) |
fceaf24a | 334 | { |
21a80820 | 335 | int ret = 0; |
ce9ea4cf | 336 | struct netvsc_device *netDevice; |
223c1aa6 | 337 | struct nvsp_message *initPacket; |
fceaf24a | 338 | |
fceaf24a | 339 | netDevice = GetOutboundNetDevice(Device); |
21a80820 GKH |
340 | if (!netDevice) { |
341 | DPRINT_ERR(NETVSC, "unable to get net device..." | |
342 | "device being destroyed?"); | |
fceaf24a HJ |
343 | return -1; |
344 | } | |
79069684 BP |
345 | if (netDevice->SendBufferSize <= 0) { |
346 | ret = -EINVAL; | |
347 | goto Cleanup; | |
348 | } | |
349 | ||
21a80820 | 350 | /* page-size grandularity */ |
972b9529 | 351 | /* ASSERT((netDevice->SendBufferSize & (PAGE_SIZE - 1)) == 0); */ |
21a80820 GKH |
352 | |
353 | netDevice->SendBuffer = | |
354 | osd_PageAlloc(netDevice->SendBufferSize >> PAGE_SHIFT); | |
355 | if (!netDevice->SendBuffer) { | |
356 | DPRINT_ERR(NETVSC, "unable to allocate send buffer of size %d", | |
357 | netDevice->SendBufferSize); | |
fceaf24a HJ |
358 | ret = -1; |
359 | goto Cleanup; | |
360 | } | |
21a80820 | 361 | /* page-aligned buffer */ |
972b9529 | 362 | /* ASSERT(((unsigned long)netDevice->SendBuffer & (PAGE_SIZE - 1)) == 0); */ |
fceaf24a HJ |
363 | |
364 | DPRINT_INFO(NETVSC, "Establishing send buffer's GPADL..."); | |
365 | ||
454f18a9 BP |
366 | /* |
367 | * Establish the gpadl handle for this buffer on this | |
368 | * channel. Note: This call uses the vmbus connection rather | |
369 | * than the channel to establish the gpadl handle. | |
370 | */ | |
fceaf24a | 371 | ret = Device->Driver->VmbusChannelInterface.EstablishGpadl(Device, |
21a80820 GKH |
372 | netDevice->SendBuffer, |
373 | netDevice->SendBufferSize, | |
374 | &netDevice->SendBufferGpadlHandle); | |
375 | if (ret != 0) { | |
fceaf24a HJ |
376 | DPRINT_ERR(NETVSC, "unable to establish send buffer's gpadl"); |
377 | goto Cleanup; | |
378 | } | |
379 | ||
bfc30aae | 380 | /* osd_WaitEventWait(ext->ChannelInitEvent); */ |
fceaf24a | 381 | |
454f18a9 | 382 | /* Notify the NetVsp of the gpadl handle */ |
fceaf24a HJ |
383 | DPRINT_INFO(NETVSC, "Sending NvspMessage1TypeSendSendBuffer..."); |
384 | ||
385 | initPacket = &netDevice->ChannelInitPacket; | |
386 | ||
223c1aa6 | 387 | memset(initPacket, 0, sizeof(struct nvsp_message)); |
fceaf24a | 388 | |
21a80820 GKH |
389 | initPacket->Header.MessageType = NvspMessage1TypeSendSendBuffer; |
390 | initPacket->Messages.Version1Messages.SendReceiveBuffer.GpadlHandle = netDevice->SendBufferGpadlHandle; | |
391 | initPacket->Messages.Version1Messages.SendReceiveBuffer.Id = NETVSC_SEND_BUFFER_ID; | |
fceaf24a | 392 | |
454f18a9 | 393 | /* Send the gpadl notification request */ |
fceaf24a | 394 | ret = Device->Driver->VmbusChannelInterface.SendPacket(Device, |
21a80820 GKH |
395 | initPacket, sizeof(struct nvsp_message), |
396 | (unsigned long)initPacket, | |
397 | VmbusPacketTypeDataInBand, | |
398 | VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED); | |
399 | if (ret != 0) { | |
400 | DPRINT_ERR(NETVSC, | |
401 | "unable to send receive buffer's gpadl to netvsp"); | |
fceaf24a HJ |
402 | goto Cleanup; |
403 | } | |
404 | ||
bfc30aae | 405 | osd_WaitEventWait(netDevice->ChannelInitEvent); |
fceaf24a | 406 | |
454f18a9 | 407 | /* Check the response */ |
21a80820 GKH |
408 | if (initPacket->Messages.Version1Messages.SendSendBufferComplete.Status != NvspStatusSuccess) { |
409 | DPRINT_ERR(NETVSC, "Unable to complete send buffer " | |
410 | "initialzation with NetVsp - status %d", | |
411 | initPacket->Messages.Version1Messages.SendSendBufferComplete.Status); | |
fceaf24a HJ |
412 | ret = -1; |
413 | goto Cleanup; | |
414 | } | |
415 | ||
416 | netDevice->SendSectionSize = initPacket->Messages.Version1Messages.SendSendBufferComplete.SectionSize; | |
417 | ||
418 | goto Exit; | |
419 | ||
420 | Cleanup: | |
421 | NetVscDestroySendBuffer(netDevice); | |
422 | ||
423 | Exit: | |
424 | PutNetDevice(Device); | |
fceaf24a HJ |
425 | return ret; |
426 | } | |
427 | ||
ce9ea4cf | 428 | static int NetVscDestroyReceiveBuffer(struct netvsc_device *NetDevice) |
fceaf24a | 429 | { |
223c1aa6 | 430 | struct nvsp_message *revokePacket; |
21a80820 | 431 | int ret = 0; |
fceaf24a | 432 | |
454f18a9 BP |
433 | /* |
434 | * If we got a section count, it means we received a | |
435 | * SendReceiveBufferComplete msg (ie sent | |
436 | * NvspMessage1TypeSendReceiveBuffer msg) therefore, we need | |
437 | * to send a revoke msg here | |
438 | */ | |
21a80820 GKH |
439 | if (NetDevice->ReceiveSectionCount) { |
440 | DPRINT_INFO(NETVSC, | |
441 | "Sending NvspMessage1TypeRevokeReceiveBuffer..."); | |
fceaf24a | 442 | |
454f18a9 | 443 | /* Send the revoke receive buffer */ |
fceaf24a | 444 | revokePacket = &NetDevice->RevokePacket; |
223c1aa6 | 445 | memset(revokePacket, 0, sizeof(struct nvsp_message)); |
fceaf24a HJ |
446 | |
447 | revokePacket->Header.MessageType = NvspMessage1TypeRevokeReceiveBuffer; | |
448 | revokePacket->Messages.Version1Messages.RevokeReceiveBuffer.Id = NETVSC_RECEIVE_BUFFER_ID; | |
449 | ||
21a80820 GKH |
450 | ret = NetDevice->Device->Driver->VmbusChannelInterface.SendPacket( |
451 | NetDevice->Device, | |
452 | revokePacket, | |
453 | sizeof(struct nvsp_message), | |
454 | (unsigned long)revokePacket, | |
455 | VmbusPacketTypeDataInBand, 0); | |
454f18a9 BP |
456 | /* |
457 | * If we failed here, we might as well return and | |
458 | * have a leak rather than continue and a bugchk | |
459 | */ | |
21a80820 GKH |
460 | if (ret != 0) { |
461 | DPRINT_ERR(NETVSC, "unable to send revoke receive " | |
462 | "buffer to netvsp"); | |
fceaf24a HJ |
463 | return -1; |
464 | } | |
465 | } | |
466 | ||
454f18a9 | 467 | /* Teardown the gpadl on the vsp end */ |
21a80820 | 468 | if (NetDevice->ReceiveBufferGpadlHandle) { |
fceaf24a HJ |
469 | DPRINT_INFO(NETVSC, "Tearing down receive buffer's GPADL..."); |
470 | ||
21a80820 GKH |
471 | ret = NetDevice->Device->Driver->VmbusChannelInterface.TeardownGpadl( |
472 | NetDevice->Device, | |
473 | NetDevice->ReceiveBufferGpadlHandle); | |
fceaf24a | 474 | |
454f18a9 | 475 | /* If we failed here, we might as well return and have a leak rather than continue and a bugchk */ |
21a80820 GKH |
476 | if (ret != 0) { |
477 | DPRINT_ERR(NETVSC, | |
478 | "unable to teardown receive buffer's gpadl"); | |
fceaf24a HJ |
479 | return -1; |
480 | } | |
481 | NetDevice->ReceiveBufferGpadlHandle = 0; | |
482 | } | |
483 | ||
21a80820 | 484 | if (NetDevice->ReceiveBuffer) { |
fceaf24a HJ |
485 | DPRINT_INFO(NETVSC, "Freeing up receive buffer..."); |
486 | ||
454f18a9 | 487 | /* Free up the receive buffer */ |
21a80820 GKH |
488 | osd_PageFree(NetDevice->ReceiveBuffer, |
489 | NetDevice->ReceiveBufferSize >> PAGE_SHIFT); | |
fceaf24a HJ |
490 | NetDevice->ReceiveBuffer = NULL; |
491 | } | |
492 | ||
21a80820 GKH |
493 | if (NetDevice->ReceiveSections) { |
494 | NetDevice->ReceiveSectionCount = 0; | |
8c69f52a | 495 | kfree(NetDevice->ReceiveSections); |
fceaf24a | 496 | NetDevice->ReceiveSections = NULL; |
fceaf24a HJ |
497 | } |
498 | ||
fceaf24a HJ |
499 | return ret; |
500 | } | |
501 | ||
ce9ea4cf | 502 | static int NetVscDestroySendBuffer(struct netvsc_device *NetDevice) |
fceaf24a | 503 | { |
223c1aa6 | 504 | struct nvsp_message *revokePacket; |
21a80820 | 505 | int ret = 0; |
fceaf24a | 506 | |
454f18a9 BP |
507 | /* |
508 | * If we got a section count, it means we received a | |
509 | * SendReceiveBufferComplete msg (ie sent | |
510 | * NvspMessage1TypeSendReceiveBuffer msg) therefore, we need | |
511 | * to send a revoke msg here | |
512 | */ | |
21a80820 GKH |
513 | if (NetDevice->SendSectionSize) { |
514 | DPRINT_INFO(NETVSC, | |
515 | "Sending NvspMessage1TypeRevokeSendBuffer..."); | |
fceaf24a | 516 | |
454f18a9 | 517 | /* Send the revoke send buffer */ |
fceaf24a | 518 | revokePacket = &NetDevice->RevokePacket; |
223c1aa6 | 519 | memset(revokePacket, 0, sizeof(struct nvsp_message)); |
fceaf24a HJ |
520 | |
521 | revokePacket->Header.MessageType = NvspMessage1TypeRevokeSendBuffer; | |
522 | revokePacket->Messages.Version1Messages.RevokeSendBuffer.Id = NETVSC_SEND_BUFFER_ID; | |
523 | ||
524 | ret = NetDevice->Device->Driver->VmbusChannelInterface.SendPacket(NetDevice->Device, | |
21a80820 GKH |
525 | revokePacket, |
526 | sizeof(struct nvsp_message), | |
527 | (unsigned long)revokePacket, | |
528 | VmbusPacketTypeDataInBand, 0); | |
529 | /* | |
530 | * If we failed here, we might as well return and have a leak | |
531 | * rather than continue and a bugchk | |
532 | */ | |
533 | if (ret != 0) { | |
534 | DPRINT_ERR(NETVSC, "unable to send revoke send buffer " | |
535 | "to netvsp"); | |
fceaf24a HJ |
536 | return -1; |
537 | } | |
538 | } | |
539 | ||
454f18a9 | 540 | /* Teardown the gpadl on the vsp end */ |
21a80820 | 541 | if (NetDevice->SendBufferGpadlHandle) { |
fceaf24a HJ |
542 | DPRINT_INFO(NETVSC, "Tearing down send buffer's GPADL..."); |
543 | ||
21a80820 | 544 | ret = NetDevice->Device->Driver->VmbusChannelInterface.TeardownGpadl(NetDevice->Device, NetDevice->SendBufferGpadlHandle); |
fceaf24a | 545 | |
21a80820 GKH |
546 | /* |
547 | * If we failed here, we might as well return and have a leak | |
548 | * rather than continue and a bugchk | |
549 | */ | |
550 | if (ret != 0) { | |
551 | DPRINT_ERR(NETVSC, "unable to teardown send buffer's " | |
552 | "gpadl"); | |
fceaf24a HJ |
553 | return -1; |
554 | } | |
555 | NetDevice->SendBufferGpadlHandle = 0; | |
556 | } | |
557 | ||
21a80820 | 558 | if (NetDevice->SendBuffer) { |
fceaf24a HJ |
559 | DPRINT_INFO(NETVSC, "Freeing up send buffer..."); |
560 | ||
454f18a9 | 561 | /* Free up the receive buffer */ |
21a80820 GKH |
562 | osd_PageFree(NetDevice->SendBuffer, |
563 | NetDevice->SendBufferSize >> PAGE_SHIFT); | |
fceaf24a HJ |
564 | NetDevice->SendBuffer = NULL; |
565 | } | |
566 | ||
fceaf24a HJ |
567 | return ret; |
568 | } | |
569 | ||
570 | ||
21a80820 | 571 | static int NetVscConnectToVsp(struct hv_device *Device) |
fceaf24a | 572 | { |
21a80820 | 573 | int ret; |
ce9ea4cf | 574 | struct netvsc_device *netDevice; |
223c1aa6 | 575 | struct nvsp_message *initPacket; |
fceaf24a HJ |
576 | int ndisVersion; |
577 | ||
fceaf24a | 578 | netDevice = GetOutboundNetDevice(Device); |
21a80820 GKH |
579 | if (!netDevice) { |
580 | DPRINT_ERR(NETVSC, "unable to get net device..." | |
581 | "device being destroyed?"); | |
fceaf24a HJ |
582 | return -1; |
583 | } | |
584 | ||
585 | initPacket = &netDevice->ChannelInitPacket; | |
586 | ||
223c1aa6 | 587 | memset(initPacket, 0, sizeof(struct nvsp_message)); |
fceaf24a | 588 | initPacket->Header.MessageType = NvspMessageTypeInit; |
21a80820 GKH |
589 | initPacket->Messages.InitMessages.Init.MinProtocolVersion = NVSP_MIN_PROTOCOL_VERSION; |
590 | initPacket->Messages.InitMessages.Init.MaxProtocolVersion = NVSP_MAX_PROTOCOL_VERSION; | |
fceaf24a HJ |
591 | |
592 | DPRINT_INFO(NETVSC, "Sending NvspMessageTypeInit..."); | |
593 | ||
454f18a9 | 594 | /* Send the init request */ |
fceaf24a | 595 | ret = Device->Driver->VmbusChannelInterface.SendPacket(Device, |
21a80820 GKH |
596 | initPacket, |
597 | sizeof(struct nvsp_message), | |
598 | (unsigned long)initPacket, | |
599 | VmbusPacketTypeDataInBand, | |
600 | VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED); | |
601 | ||
602 | if (ret != 0) { | |
fceaf24a HJ |
603 | DPRINT_ERR(NETVSC, "unable to send NvspMessageTypeInit"); |
604 | goto Cleanup; | |
605 | } | |
606 | ||
bfc30aae | 607 | osd_WaitEventWait(netDevice->ChannelInitEvent); |
fceaf24a | 608 | |
454f18a9 BP |
609 | /* Now, check the response */ |
610 | /* ASSERT(initPacket->Messages.InitMessages.InitComplete.MaximumMdlChainLength <= MAX_MULTIPAGE_BUFFER_COUNT); */ | |
fceaf24a HJ |
611 | DPRINT_INFO(NETVSC, "NvspMessageTypeInit status(%d) max mdl chain (%d)", |
612 | initPacket->Messages.InitMessages.InitComplete.Status, | |
613 | initPacket->Messages.InitMessages.InitComplete.MaximumMdlChainLength); | |
614 | ||
21a80820 GKH |
615 | if (initPacket->Messages.InitMessages.InitComplete.Status != |
616 | NvspStatusSuccess) { | |
617 | DPRINT_ERR(NETVSC, | |
618 | "unable to initialize with netvsp (status 0x%x)", | |
619 | initPacket->Messages.InitMessages.InitComplete.Status); | |
fceaf24a HJ |
620 | ret = -1; |
621 | goto Cleanup; | |
622 | } | |
623 | ||
21a80820 GKH |
624 | if (initPacket->Messages.InitMessages.InitComplete.NegotiatedProtocolVersion != NVSP_PROTOCOL_VERSION_1) { |
625 | DPRINT_ERR(NETVSC, "unable to initialize with netvsp " | |
626 | "(version expected 1 got %d)", | |
627 | initPacket->Messages.InitMessages.InitComplete.NegotiatedProtocolVersion); | |
fceaf24a HJ |
628 | ret = -1; |
629 | goto Cleanup; | |
630 | } | |
631 | DPRINT_INFO(NETVSC, "Sending NvspMessage1TypeSendNdisVersion..."); | |
632 | ||
454f18a9 | 633 | /* Send the ndis version */ |
223c1aa6 | 634 | memset(initPacket, 0, sizeof(struct nvsp_message)); |
fceaf24a | 635 | |
21a80820 | 636 | ndisVersion = 0x00050000; |
fceaf24a | 637 | |
21a80820 GKH |
638 | initPacket->Header.MessageType = NvspMessage1TypeSendNdisVersion; |
639 | initPacket->Messages.Version1Messages.SendNdisVersion.NdisMajorVersion = | |
640 | (ndisVersion & 0xFFFF0000) >> 16; | |
641 | initPacket->Messages.Version1Messages.SendNdisVersion.NdisMinorVersion = | |
642 | ndisVersion & 0xFFFF; | |
fceaf24a | 643 | |
454f18a9 | 644 | /* Send the init request */ |
fceaf24a | 645 | ret = Device->Driver->VmbusChannelInterface.SendPacket(Device, |
21a80820 GKH |
646 | initPacket, |
647 | sizeof(struct nvsp_message), | |
648 | (unsigned long)initPacket, | |
649 | VmbusPacketTypeDataInBand, 0); | |
650 | if (ret != 0) { | |
651 | DPRINT_ERR(NETVSC, | |
652 | "unable to send NvspMessage1TypeSendNdisVersion"); | |
fceaf24a HJ |
653 | ret = -1; |
654 | goto Cleanup; | |
655 | } | |
454f18a9 BP |
656 | /* |
657 | * BUGBUG - We have to wait for the above msg since the | |
658 | * netvsp uses KMCL which acknowledges packet (completion | |
659 | * packet) since our Vmbus always set the | |
660 | * VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED flag | |
661 | */ | |
bfc30aae | 662 | /* osd_WaitEventWait(NetVscChannel->ChannelInitEvent); */ |
454f18a9 BP |
663 | |
664 | /* Post the big receive buffer to NetVSP */ | |
fceaf24a HJ |
665 | ret = NetVscInitializeReceiveBufferWithNetVsp(Device); |
666 | if (ret == 0) | |
fceaf24a | 667 | ret = NetVscInitializeSendBufferWithNetVsp(Device); |
fceaf24a HJ |
668 | |
669 | Cleanup: | |
670 | PutNetDevice(Device); | |
fceaf24a HJ |
671 | return ret; |
672 | } | |
673 | ||
ce9ea4cf | 674 | static void NetVscDisconnectFromVsp(struct netvsc_device *NetDevice) |
fceaf24a | 675 | { |
fceaf24a HJ |
676 | NetVscDestroyReceiveBuffer(NetDevice); |
677 | NetVscDestroySendBuffer(NetDevice); | |
fceaf24a HJ |
678 | } |
679 | ||
3e189519 | 680 | /* |
21a80820 GKH |
681 | * NetVscOnDeviceAdd - Callback when the device belonging to this driver is added |
682 | */ | |
683 | static int NetVscOnDeviceAdd(struct hv_device *Device, void *AdditionalInfo) | |
fceaf24a | 684 | { |
21a80820 | 685 | int ret = 0; |
fceaf24a | 686 | int i; |
ce9ea4cf | 687 | struct netvsc_device *netDevice; |
d29274ef | 688 | struct hv_netvsc_packet *packet, *pos; |
21a80820 GKH |
689 | struct netvsc_driver *netDriver = |
690 | (struct netvsc_driver *)Device->Driver; | |
fceaf24a | 691 | |
fceaf24a | 692 | netDevice = AllocNetDevice(Device); |
21a80820 | 693 | if (!netDevice) { |
fceaf24a HJ |
694 | ret = -1; |
695 | goto Cleanup; | |
696 | } | |
697 | ||
698 | DPRINT_DBG(NETVSC, "netvsc channel object allocated - %p", netDevice); | |
699 | ||
454f18a9 | 700 | /* Initialize the NetVSC channel extension */ |
fceaf24a | 701 | netDevice->ReceiveBufferSize = NETVSC_RECEIVE_BUFFER_SIZE; |
6436873a | 702 | spin_lock_init(&netDevice->receive_packet_list_lock); |
fceaf24a HJ |
703 | |
704 | netDevice->SendBufferSize = NETVSC_SEND_BUFFER_SIZE; | |
705 | ||
d29274ef | 706 | INIT_LIST_HEAD(&netDevice->ReceivePacketList); |
fceaf24a | 707 | |
21a80820 GKH |
708 | for (i = 0; i < NETVSC_RECEIVE_PACKETLIST_COUNT; i++) { |
709 | packet = kzalloc(sizeof(struct hv_netvsc_packet) + | |
710 | (NETVSC_RECEIVE_SG_COUNT * | |
711 | sizeof(struct hv_page_buffer)), GFP_KERNEL); | |
712 | if (!packet) { | |
713 | DPRINT_DBG(NETVSC, "unable to allocate netvsc pkts " | |
714 | "for receive pool (wanted %d got %d)", | |
715 | NETVSC_RECEIVE_PACKETLIST_COUNT, i); | |
fceaf24a HJ |
716 | break; |
717 | } | |
d29274ef BP |
718 | list_add_tail(&packet->ListEntry, |
719 | &netDevice->ReceivePacketList); | |
fceaf24a | 720 | } |
bfc30aae | 721 | netDevice->ChannelInitEvent = osd_WaitEventCreate(); |
80d11b2a BP |
722 | if (!netDevice->ChannelInitEvent) { |
723 | ret = -ENOMEM; | |
724 | goto Cleanup; | |
725 | } | |
fceaf24a | 726 | |
454f18a9 | 727 | /* Open the channel */ |
fceaf24a | 728 | ret = Device->Driver->VmbusChannelInterface.Open(Device, |
21a80820 GKH |
729 | netDriver->RingBufferSize, |
730 | netDriver->RingBufferSize, | |
731 | NULL, 0, | |
732 | NetVscOnChannelCallback, | |
733 | Device); | |
fceaf24a | 734 | |
21a80820 | 735 | if (ret != 0) { |
fceaf24a HJ |
736 | DPRINT_ERR(NETVSC, "unable to open channel: %d", ret); |
737 | ret = -1; | |
738 | goto Cleanup; | |
739 | } | |
740 | ||
454f18a9 | 741 | /* Channel is opened */ |
fceaf24a HJ |
742 | DPRINT_INFO(NETVSC, "*** NetVSC channel opened successfully! ***"); |
743 | ||
454f18a9 | 744 | /* Connect with the NetVsp */ |
fceaf24a | 745 | ret = NetVscConnectToVsp(Device); |
21a80820 | 746 | if (ret != 0) { |
fceaf24a HJ |
747 | DPRINT_ERR(NETVSC, "unable to connect to NetVSP - %d", ret); |
748 | ret = -1; | |
749 | goto Close; | |
750 | } | |
751 | ||
21a80820 GKH |
752 | DPRINT_INFO(NETVSC, "*** NetVSC channel handshake result - %d ***", |
753 | ret); | |
fceaf24a | 754 | |
fceaf24a HJ |
755 | return ret; |
756 | ||
757 | Close: | |
454f18a9 | 758 | /* Now, we can close the channel safely */ |
fceaf24a HJ |
759 | Device->Driver->VmbusChannelInterface.Close(Device); |
760 | ||
761 | Cleanup: | |
762 | ||
21a80820 | 763 | if (netDevice) { |
420beac4 | 764 | kfree(netDevice->ChannelInitEvent); |
fceaf24a | 765 | |
d29274ef BP |
766 | list_for_each_entry_safe(packet, pos, |
767 | &netDevice->ReceivePacketList, | |
768 | ListEntry) { | |
769 | list_del(&packet->ListEntry); | |
8c69f52a | 770 | kfree(packet); |
fceaf24a HJ |
771 | } |
772 | ||
fceaf24a HJ |
773 | ReleaseOutboundNetDevice(Device); |
774 | ReleaseInboundNetDevice(Device); | |
775 | ||
776 | FreeNetDevice(netDevice); | |
777 | } | |
778 | ||
fceaf24a HJ |
779 | return ret; |
780 | } | |
781 | ||
3e189519 | 782 | /* |
21a80820 GKH |
783 | * NetVscOnDeviceRemove - Callback when the root bus device is removed |
784 | */ | |
785 | static int NetVscOnDeviceRemove(struct hv_device *Device) | |
fceaf24a | 786 | { |
ce9ea4cf | 787 | struct netvsc_device *netDevice; |
d29274ef | 788 | struct hv_netvsc_packet *netvscPacket, *pos; |
fceaf24a | 789 | |
21a80820 GKH |
790 | DPRINT_INFO(NETVSC, "Disabling outbound traffic on net device (%p)...", |
791 | Device->Extension); | |
fceaf24a | 792 | |
454f18a9 | 793 | /* Stop outbound traffic ie sends and receives completions */ |
fceaf24a | 794 | netDevice = ReleaseOutboundNetDevice(Device); |
21a80820 | 795 | if (!netDevice) { |
fceaf24a HJ |
796 | DPRINT_ERR(NETVSC, "No net device present!!"); |
797 | return -1; | |
798 | } | |
799 | ||
454f18a9 | 800 | /* Wait for all send completions */ |
21a80820 GKH |
801 | while (atomic_read(&netDevice->NumOutstandingSends)) { |
802 | DPRINT_INFO(NETVSC, "waiting for %d requests to complete...", | |
803 | atomic_read(&netDevice->NumOutstandingSends)); | |
b4362c9c | 804 | udelay(100); |
fceaf24a HJ |
805 | } |
806 | ||
807 | DPRINT_INFO(NETVSC, "Disconnecting from netvsp..."); | |
808 | ||
809 | NetVscDisconnectFromVsp(netDevice); | |
810 | ||
21a80820 GKH |
811 | DPRINT_INFO(NETVSC, "Disabling inbound traffic on net device (%p)...", |
812 | Device->Extension); | |
fceaf24a | 813 | |
454f18a9 | 814 | /* Stop inbound traffic ie receives and sends completions */ |
fceaf24a HJ |
815 | netDevice = ReleaseInboundNetDevice(Device); |
816 | ||
454f18a9 | 817 | /* At this point, no one should be accessing netDevice except in here */ |
fceaf24a HJ |
818 | DPRINT_INFO(NETVSC, "net device (%p) safe to remove", netDevice); |
819 | ||
454f18a9 | 820 | /* Now, we can close the channel safely */ |
fceaf24a HJ |
821 | Device->Driver->VmbusChannelInterface.Close(Device); |
822 | ||
454f18a9 | 823 | /* Release all resources */ |
d29274ef BP |
824 | list_for_each_entry_safe(netvscPacket, pos, |
825 | &netDevice->ReceivePacketList, ListEntry) { | |
826 | list_del(&netvscPacket->ListEntry); | |
8c69f52a | 827 | kfree(netvscPacket); |
fceaf24a HJ |
828 | } |
829 | ||
420beac4 | 830 | kfree(netDevice->ChannelInitEvent); |
fceaf24a | 831 | FreeNetDevice(netDevice); |
21a80820 | 832 | return 0; |
fceaf24a HJ |
833 | } |
834 | ||
3e189519 | 835 | /* |
21a80820 GKH |
836 | * NetVscOnCleanup - Perform any cleanup when the driver is removed |
837 | */ | |
838 | static void NetVscOnCleanup(struct hv_driver *drv) | |
fceaf24a | 839 | { |
fceaf24a HJ |
840 | } |
841 | ||
21a80820 GKH |
842 | static void NetVscOnSendCompletion(struct hv_device *Device, |
843 | struct vmpacket_descriptor *Packet) | |
fceaf24a | 844 | { |
ce9ea4cf | 845 | struct netvsc_device *netDevice; |
223c1aa6 | 846 | struct nvsp_message *nvspPacket; |
4193d4f4 | 847 | struct hv_netvsc_packet *nvscPacket; |
fceaf24a | 848 | |
fceaf24a | 849 | netDevice = GetInboundNetDevice(Device); |
21a80820 GKH |
850 | if (!netDevice) { |
851 | DPRINT_ERR(NETVSC, "unable to get net device..." | |
852 | "device being destroyed?"); | |
fceaf24a HJ |
853 | return; |
854 | } | |
855 | ||
223c1aa6 | 856 | nvspPacket = (struct nvsp_message *)((unsigned long)Packet + (Packet->DataOffset8 << 3)); |
fceaf24a | 857 | |
21a80820 GKH |
858 | DPRINT_DBG(NETVSC, "send completion packet - type %d", |
859 | nvspPacket->Header.MessageType); | |
fceaf24a | 860 | |
21a80820 GKH |
861 | if ((nvspPacket->Header.MessageType == NvspMessageTypeInitComplete) || |
862 | (nvspPacket->Header.MessageType == | |
863 | NvspMessage1TypeSendReceiveBufferComplete) || | |
864 | (nvspPacket->Header.MessageType == | |
865 | NvspMessage1TypeSendSendBufferComplete)) { | |
454f18a9 | 866 | /* Copy the response back */ |
21a80820 GKH |
867 | memcpy(&netDevice->ChannelInitPacket, nvspPacket, |
868 | sizeof(struct nvsp_message)); | |
bfc30aae | 869 | osd_WaitEventSet(netDevice->ChannelInitEvent); |
21a80820 GKH |
870 | } else if (nvspPacket->Header.MessageType == |
871 | NvspMessage1TypeSendRNDISPacketComplete) { | |
454f18a9 | 872 | /* Get the send context */ |
4193d4f4 | 873 | nvscPacket = (struct hv_netvsc_packet *)(unsigned long)Packet->TransactionId; |
972b9529 | 874 | /* ASSERT(nvscPacket); */ |
fceaf24a | 875 | |
454f18a9 | 876 | /* Notify the layer above us */ |
fceaf24a HJ |
877 | nvscPacket->Completion.Send.OnSendCompletion(nvscPacket->Completion.Send.SendCompletionContext); |
878 | ||
f4888417 | 879 | atomic_dec(&netDevice->NumOutstandingSends); |
21a80820 GKH |
880 | } else { |
881 | DPRINT_ERR(NETVSC, "Unknown send completion packet type - " | |
882 | "%d received!!", nvspPacket->Header.MessageType); | |
fceaf24a HJ |
883 | } |
884 | ||
885 | PutNetDevice(Device); | |
fceaf24a HJ |
886 | } |
887 | ||
21a80820 GKH |
888 | static int NetVscOnSend(struct hv_device *Device, |
889 | struct hv_netvsc_packet *Packet) | |
fceaf24a | 890 | { |
ce9ea4cf | 891 | struct netvsc_device *netDevice; |
21a80820 | 892 | int ret = 0; |
fceaf24a | 893 | |
223c1aa6 | 894 | struct nvsp_message sendMessage; |
fceaf24a | 895 | |
fceaf24a | 896 | netDevice = GetOutboundNetDevice(Device); |
21a80820 GKH |
897 | if (!netDevice) { |
898 | DPRINT_ERR(NETVSC, "net device (%p) shutting down..." | |
899 | "ignoring outbound packets", netDevice); | |
fceaf24a HJ |
900 | return -2; |
901 | } | |
902 | ||
903 | sendMessage.Header.MessageType = NvspMessage1TypeSendRNDISPacket; | |
21a80820 GKH |
904 | if (Packet->IsDataPacket) { |
905 | /* 0 is RMC_DATA; */ | |
906 | sendMessage.Messages.Version1Messages.SendRNDISPacket.ChannelType = 0; | |
907 | } else { | |
908 | /* 1 is RMC_CONTROL; */ | |
909 | sendMessage.Messages.Version1Messages.SendRNDISPacket.ChannelType = 1; | |
910 | } | |
fceaf24a | 911 | |
454f18a9 | 912 | /* Not using send buffer section */ |
21a80820 GKH |
913 | sendMessage.Messages.Version1Messages.SendRNDISPacket.SendBufferSectionIndex = 0xFFFFFFFF; |
914 | sendMessage.Messages.Version1Messages.SendRNDISPacket.SendBufferSectionSize = 0; | |
915 | ||
916 | if (Packet->PageBufferCount) { | |
917 | ret = Device->Driver->VmbusChannelInterface.SendPacketPageBuffer( | |
918 | Device, Packet->PageBuffers, | |
919 | Packet->PageBufferCount, | |
920 | &sendMessage, | |
921 | sizeof(struct nvsp_message), | |
922 | (unsigned long)Packet); | |
923 | } else { | |
fceaf24a | 924 | ret = Device->Driver->VmbusChannelInterface.SendPacket(Device, |
21a80820 GKH |
925 | &sendMessage, |
926 | sizeof(struct nvsp_message), | |
927 | (unsigned long)Packet, | |
928 | VmbusPacketTypeDataInBand, | |
929 | VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED); | |
fceaf24a HJ |
930 | |
931 | } | |
932 | ||
933 | if (ret != 0) | |
21a80820 GKH |
934 | DPRINT_ERR(NETVSC, "Unable to send packet %p ret %d", |
935 | Packet, ret); | |
fceaf24a | 936 | |
f4888417 | 937 | atomic_inc(&netDevice->NumOutstandingSends); |
fceaf24a | 938 | PutNetDevice(Device); |
fceaf24a HJ |
939 | return ret; |
940 | } | |
941 | ||
21a80820 GKH |
942 | static void NetVscOnReceive(struct hv_device *Device, |
943 | struct vmpacket_descriptor *Packet) | |
fceaf24a | 944 | { |
ce9ea4cf | 945 | struct netvsc_device *netDevice; |
8dc0a06a | 946 | struct vmtransfer_page_packet_header *vmxferpagePacket; |
223c1aa6 | 947 | struct nvsp_message *nvspPacket; |
21a80820 | 948 | struct hv_netvsc_packet *netvscPacket = NULL; |
c4b0bc94 GKH |
949 | unsigned long start; |
950 | unsigned long end, endVirtual; | |
7e23a6e9 | 951 | /* struct netvsc_driver *netvscDriver; */ |
21a80820 | 952 | struct xferpage_packet *xferpagePacket = NULL; |
21a80820 GKH |
953 | int i, j; |
954 | int count = 0, bytesRemain = 0; | |
6436873a | 955 | unsigned long flags; |
d29274ef | 956 | LIST_HEAD(listHead); |
fceaf24a | 957 | |
fceaf24a | 958 | netDevice = GetInboundNetDevice(Device); |
21a80820 GKH |
959 | if (!netDevice) { |
960 | DPRINT_ERR(NETVSC, "unable to get net device..." | |
961 | "device being destroyed?"); | |
fceaf24a HJ |
962 | return; |
963 | } | |
964 | ||
21a80820 GKH |
965 | /* |
966 | * All inbound packets other than send completion should be xfer page | |
967 | * packet | |
968 | */ | |
969 | if (Packet->Type != VmbusPacketTypeDataUsingTransferPages) { | |
970 | DPRINT_ERR(NETVSC, "Unknown packet type received - %d", | |
971 | Packet->Type); | |
fceaf24a HJ |
972 | PutNetDevice(Device); |
973 | return; | |
974 | } | |
975 | ||
21a80820 GKH |
976 | nvspPacket = (struct nvsp_message *)((unsigned long)Packet + |
977 | (Packet->DataOffset8 << 3)); | |
fceaf24a | 978 | |
454f18a9 | 979 | /* Make sure this is a valid nvsp packet */ |
21a80820 GKH |
980 | if (nvspPacket->Header.MessageType != NvspMessage1TypeSendRNDISPacket) { |
981 | DPRINT_ERR(NETVSC, "Unknown nvsp packet type received - %d", | |
982 | nvspPacket->Header.MessageType); | |
fceaf24a HJ |
983 | PutNetDevice(Device); |
984 | return; | |
985 | } | |
986 | ||
21a80820 GKH |
987 | DPRINT_DBG(NETVSC, "NVSP packet received - type %d", |
988 | nvspPacket->Header.MessageType); | |
fceaf24a | 989 | |
8dc0a06a | 990 | vmxferpagePacket = (struct vmtransfer_page_packet_header *)Packet; |
fceaf24a | 991 | |
21a80820 GKH |
992 | if (vmxferpagePacket->TransferPageSetId != NETVSC_RECEIVE_BUFFER_ID) { |
993 | DPRINT_ERR(NETVSC, "Invalid xfer page set id - " | |
994 | "expecting %x got %x", NETVSC_RECEIVE_BUFFER_ID, | |
995 | vmxferpagePacket->TransferPageSetId); | |
fceaf24a HJ |
996 | PutNetDevice(Device); |
997 | return; | |
998 | } | |
999 | ||
21a80820 GKH |
1000 | DPRINT_DBG(NETVSC, "xfer page - range count %d", |
1001 | vmxferpagePacket->RangeCount); | |
fceaf24a | 1002 | |
454f18a9 BP |
1003 | /* |
1004 | * Grab free packets (range count + 1) to represent this xfer | |
1005 | * page packet. +1 to represent the xfer page packet itself. | |
1006 | * We grab it here so that we know exactly how many we can | |
1007 | * fulfil | |
1008 | */ | |
6436873a | 1009 | spin_lock_irqsave(&netDevice->receive_packet_list_lock, flags); |
d29274ef | 1010 | while (!list_empty(&netDevice->ReceivePacketList)) { |
92ec0893 | 1011 | list_move_tail(netDevice->ReceivePacketList.next, &listHead); |
fceaf24a HJ |
1012 | if (++count == vmxferpagePacket->RangeCount + 1) |
1013 | break; | |
1014 | } | |
6436873a | 1015 | spin_unlock_irqrestore(&netDevice->receive_packet_list_lock, flags); |
fceaf24a | 1016 | |
454f18a9 BP |
1017 | /* |
1018 | * We need at least 2 netvsc pkts (1 to represent the xfer | |
1019 | * page and at least 1 for the range) i.e. we can handled | |
1020 | * some of the xfer page packet ranges... | |
1021 | */ | |
21a80820 GKH |
1022 | if (count < 2) { |
1023 | DPRINT_ERR(NETVSC, "Got only %d netvsc pkt...needed %d pkts. " | |
1024 | "Dropping this xfer page packet completely!", | |
1025 | count, vmxferpagePacket->RangeCount + 1); | |
fceaf24a | 1026 | |
454f18a9 | 1027 | /* Return it to the freelist */ |
6436873a | 1028 | spin_lock_irqsave(&netDevice->receive_packet_list_lock, flags); |
21a80820 | 1029 | for (i = count; i != 0; i--) { |
92ec0893 | 1030 | list_move_tail(listHead.next, |
d29274ef | 1031 | &netDevice->ReceivePacketList); |
fceaf24a | 1032 | } |
21a80820 GKH |
1033 | spin_unlock_irqrestore(&netDevice->receive_packet_list_lock, |
1034 | flags); | |
fceaf24a | 1035 | |
21a80820 GKH |
1036 | NetVscSendReceiveCompletion(Device, |
1037 | vmxferpagePacket->d.TransactionId); | |
fceaf24a HJ |
1038 | |
1039 | PutNetDevice(Device); | |
1040 | return; | |
1041 | } | |
1042 | ||
454f18a9 | 1043 | /* Remove the 1st packet to represent the xfer page packet itself */ |
0686e4f4 | 1044 | xferpagePacket = (struct xferpage_packet *)listHead.next; |
d29274ef BP |
1045 | list_del(&xferpagePacket->ListEntry); |
1046 | ||
21a80820 GKH |
1047 | /* This is how much we can satisfy */ |
1048 | xferpagePacket->Count = count - 1; | |
972b9529 BP |
1049 | /* ASSERT(xferpagePacket->Count > 0 && xferpagePacket->Count <= */ |
1050 | /* vmxferpagePacket->RangeCount); */ | |
21a80820 GKH |
1051 | |
1052 | if (xferpagePacket->Count != vmxferpagePacket->RangeCount) { | |
1053 | DPRINT_INFO(NETVSC, "Needed %d netvsc pkts to satisy this xfer " | |
1054 | "page...got %d", vmxferpagePacket->RangeCount, | |
1055 | xferpagePacket->Count); | |
fceaf24a HJ |
1056 | } |
1057 | ||
454f18a9 | 1058 | /* Each range represents 1 RNDIS pkt that contains 1 ethernet frame */ |
21a80820 | 1059 | for (i = 0; i < (count - 1); i++) { |
0686e4f4 | 1060 | netvscPacket = (struct hv_netvsc_packet *)listHead.next; |
d29274ef | 1061 | list_del(&netvscPacket->ListEntry); |
fceaf24a | 1062 | |
454f18a9 | 1063 | /* Initialize the netvsc packet */ |
fceaf24a | 1064 | netvscPacket->XferPagePacket = xferpagePacket; |
21a80820 GKH |
1065 | netvscPacket->Completion.Recv.OnReceiveCompletion = |
1066 | NetVscOnReceiveCompletion; | |
1067 | netvscPacket->Completion.Recv.ReceiveCompletionContext = | |
1068 | netvscPacket; | |
fceaf24a | 1069 | netvscPacket->Device = Device; |
21a80820 GKH |
1070 | /* Save this so that we can send it back */ |
1071 | netvscPacket->Completion.Recv.ReceiveCompletionTid = | |
1072 | vmxferpagePacket->d.TransactionId; | |
fceaf24a | 1073 | |
21a80820 GKH |
1074 | netvscPacket->TotalDataBufferLength = |
1075 | vmxferpagePacket->Ranges[i].ByteCount; | |
fceaf24a HJ |
1076 | netvscPacket->PageBufferCount = 1; |
1077 | ||
972b9529 BP |
1078 | /* ASSERT(vmxferpagePacket->Ranges[i].ByteOffset + */ |
1079 | /* vmxferpagePacket->Ranges[i].ByteCount < */ | |
1080 | /* netDevice->ReceiveBufferSize); */ | |
fceaf24a | 1081 | |
21a80820 GKH |
1082 | netvscPacket->PageBuffers[0].Length = |
1083 | vmxferpagePacket->Ranges[i].ByteCount; | |
fceaf24a | 1084 | |
21a80820 | 1085 | start = virt_to_phys((void *)((unsigned long)netDevice->ReceiveBuffer + vmxferpagePacket->Ranges[i].ByteOffset)); |
fceaf24a HJ |
1086 | |
1087 | netvscPacket->PageBuffers[0].Pfn = start >> PAGE_SHIFT; | |
c4b0bc94 | 1088 | endVirtual = (unsigned long)netDevice->ReceiveBuffer |
fceaf24a | 1089 | + vmxferpagePacket->Ranges[i].ByteOffset |
21a80820 GKH |
1090 | + vmxferpagePacket->Ranges[i].ByteCount - 1; |
1091 | end = virt_to_phys((void *)endVirtual); | |
fceaf24a | 1092 | |
454f18a9 | 1093 | /* Calculate the page relative offset */ |
21a80820 GKH |
1094 | netvscPacket->PageBuffers[0].Offset = |
1095 | vmxferpagePacket->Ranges[i].ByteOffset & (PAGE_SIZE - 1); | |
1096 | if ((end >> PAGE_SHIFT) != (start >> PAGE_SHIFT)) { | |
1097 | /* Handle frame across multiple pages: */ | |
1098 | netvscPacket->PageBuffers[0].Length = | |
1099 | (netvscPacket->PageBuffers[0].Pfn << PAGE_SHIFT) | |
1100 | + PAGE_SIZE - start; | |
1101 | bytesRemain = netvscPacket->TotalDataBufferLength - | |
1102 | netvscPacket->PageBuffers[0].Length; | |
1103 | for (j = 1; j < NETVSC_PACKET_MAXPAGE; j++) { | |
1104 | netvscPacket->PageBuffers[j].Offset = 0; | |
1105 | if (bytesRemain <= PAGE_SIZE) { | |
1106 | netvscPacket->PageBuffers[j].Length = bytesRemain; | |
1107 | bytesRemain = 0; | |
1108 | } else { | |
1109 | netvscPacket->PageBuffers[j].Length = PAGE_SIZE; | |
1110 | bytesRemain -= PAGE_SIZE; | |
1111 | } | |
1112 | netvscPacket->PageBuffers[j].Pfn = | |
1113 | virt_to_phys((void *)(endVirtual - bytesRemain)) >> PAGE_SHIFT; | |
1114 | netvscPacket->PageBufferCount++; | |
1115 | if (bytesRemain == 0) | |
1116 | break; | |
fceaf24a | 1117 | } |
972b9529 | 1118 | /* ASSERT(bytesRemain == 0); */ |
fceaf24a | 1119 | } |
21a80820 GKH |
1120 | DPRINT_DBG(NETVSC, "[%d] - (abs offset %u len %u) => " |
1121 | "(pfn %llx, offset %u, len %u)", i, | |
1122 | vmxferpagePacket->Ranges[i].ByteOffset, | |
1123 | vmxferpagePacket->Ranges[i].ByteCount, | |
1124 | netvscPacket->PageBuffers[0].Pfn, | |
1125 | netvscPacket->PageBuffers[0].Offset, | |
1126 | netvscPacket->PageBuffers[0].Length); | |
fceaf24a | 1127 | |
454f18a9 | 1128 | /* Pass it to the upper layer */ |
7e23a6e9 | 1129 | ((struct netvsc_driver *)Device->Driver)->OnReceiveCallback(Device, netvscPacket); |
fceaf24a HJ |
1130 | |
1131 | NetVscOnReceiveCompletion(netvscPacket->Completion.Recv.ReceiveCompletionContext); | |
1132 | } | |
1133 | ||
972b9529 | 1134 | /* ASSERT(list_empty(&listHead)); */ |
fceaf24a HJ |
1135 | |
1136 | PutNetDevice(Device); | |
fceaf24a HJ |
1137 | } |
1138 | ||
21a80820 GKH |
1139 | static void NetVscSendReceiveCompletion(struct hv_device *Device, |
1140 | u64 TransactionId) | |
fceaf24a | 1141 | { |
223c1aa6 | 1142 | struct nvsp_message recvcompMessage; |
21a80820 GKH |
1143 | int retries = 0; |
1144 | int ret; | |
fceaf24a | 1145 | |
21a80820 GKH |
1146 | DPRINT_DBG(NETVSC, "Sending receive completion pkt - %llx", |
1147 | TransactionId); | |
fceaf24a | 1148 | |
21a80820 GKH |
1149 | recvcompMessage.Header.MessageType = |
1150 | NvspMessage1TypeSendRNDISPacketComplete; | |
fceaf24a | 1151 | |
454f18a9 | 1152 | /* FIXME: Pass in the status */ |
fceaf24a HJ |
1153 | recvcompMessage.Messages.Version1Messages.SendRNDISPacketComplete.Status = NvspStatusSuccess; |
1154 | ||
1155 | retry_send_cmplt: | |
454f18a9 | 1156 | /* Send the completion */ |
fceaf24a | 1157 | ret = Device->Driver->VmbusChannelInterface.SendPacket(Device, |
21a80820 GKH |
1158 | &recvcompMessage, |
1159 | sizeof(struct nvsp_message), | |
1160 | TransactionId, | |
1161 | VmbusPacketTypeCompletion, 0); | |
1162 | if (ret == 0) { | |
1163 | /* success */ | |
454f18a9 | 1164 | /* no-op */ |
21a80820 GKH |
1165 | } else if (ret == -1) { |
1166 | /* no more room...wait a bit and attempt to retry 3 times */ | |
fceaf24a | 1167 | retries++; |
21a80820 GKH |
1168 | DPRINT_ERR(NETVSC, "unable to send receive completion pkt " |
1169 | "(tid %llx)...retrying %d", TransactionId, retries); | |
fceaf24a | 1170 | |
21a80820 | 1171 | if (retries < 4) { |
b4362c9c | 1172 | udelay(100); |
fceaf24a | 1173 | goto retry_send_cmplt; |
21a80820 GKH |
1174 | } else { |
1175 | DPRINT_ERR(NETVSC, "unable to send receive completion " | |
1176 | "pkt (tid %llx)...give up retrying", | |
1177 | TransactionId); | |
fceaf24a | 1178 | } |
21a80820 GKH |
1179 | } else { |
1180 | DPRINT_ERR(NETVSC, "unable to send receive completion pkt - " | |
1181 | "%llx", TransactionId); | |
fceaf24a HJ |
1182 | } |
1183 | } | |
1184 | ||
454f18a9 | 1185 | /* Send a receive completion packet to RNDIS device (ie NetVsp) */ |
21a80820 | 1186 | static void NetVscOnReceiveCompletion(void *Context) |
fceaf24a | 1187 | { |
21a80820 GKH |
1188 | struct hv_netvsc_packet *packet = Context; |
1189 | struct hv_device *device = (struct hv_device *)packet->Device; | |
ce9ea4cf | 1190 | struct netvsc_device *netDevice; |
21a80820 | 1191 | u64 transactionId = 0; |
0e727613 | 1192 | bool fSendReceiveComp = false; |
6436873a | 1193 | unsigned long flags; |
fceaf24a | 1194 | |
972b9529 | 1195 | /* ASSERT(packet->XferPagePacket); */ |
fceaf24a | 1196 | |
21a80820 GKH |
1197 | /* |
1198 | * Even though it seems logical to do a GetOutboundNetDevice() here to | |
1199 | * send out receive completion, we are using GetInboundNetDevice() | |
1200 | * since we may have disable outbound traffic already. | |
1201 | */ | |
fceaf24a | 1202 | netDevice = GetInboundNetDevice(device); |
21a80820 GKH |
1203 | if (!netDevice) { |
1204 | DPRINT_ERR(NETVSC, "unable to get net device..." | |
1205 | "device being destroyed?"); | |
fceaf24a HJ |
1206 | return; |
1207 | } | |
1208 | ||
454f18a9 | 1209 | /* Overloading use of the lock. */ |
6436873a | 1210 | spin_lock_irqsave(&netDevice->receive_packet_list_lock, flags); |
fceaf24a | 1211 | |
972b9529 | 1212 | /* ASSERT(packet->XferPagePacket->Count > 0); */ |
fceaf24a HJ |
1213 | packet->XferPagePacket->Count--; |
1214 | ||
21a80820 GKH |
1215 | /* |
1216 | * Last one in the line that represent 1 xfer page packet. | |
1217 | * Return the xfer page packet itself to the freelist | |
1218 | */ | |
1219 | if (packet->XferPagePacket->Count == 0) { | |
0e727613 | 1220 | fSendReceiveComp = true; |
fceaf24a | 1221 | transactionId = packet->Completion.Recv.ReceiveCompletionTid; |
d29274ef BP |
1222 | list_add_tail(&packet->XferPagePacket->ListEntry, |
1223 | &netDevice->ReceivePacketList); | |
fceaf24a | 1224 | |
fceaf24a HJ |
1225 | } |
1226 | ||
454f18a9 | 1227 | /* Put the packet back */ |
d29274ef | 1228 | list_add_tail(&packet->ListEntry, &netDevice->ReceivePacketList); |
6436873a | 1229 | spin_unlock_irqrestore(&netDevice->receive_packet_list_lock, flags); |
fceaf24a | 1230 | |
454f18a9 | 1231 | /* Send a receive completion for the xfer page packet */ |
fceaf24a | 1232 | if (fSendReceiveComp) |
fceaf24a | 1233 | NetVscSendReceiveCompletion(device, transactionId); |
fceaf24a HJ |
1234 | |
1235 | PutNetDevice(device); | |
fceaf24a HJ |
1236 | } |
1237 | ||
81b571b7 | 1238 | static void NetVscOnChannelCallback(void *Context) |
fceaf24a | 1239 | { |
21a80820 GKH |
1240 | int ret; |
1241 | struct hv_device *device = Context; | |
ce9ea4cf | 1242 | struct netvsc_device *netDevice; |
4d643114 | 1243 | u32 bytesRecvd; |
59471438 | 1244 | u64 requestId; |
c6fcf0ba | 1245 | unsigned char *packet; |
8dc0a06a | 1246 | struct vmpacket_descriptor *desc; |
c6fcf0ba BP |
1247 | unsigned char *buffer; |
1248 | int bufferlen = NETVSC_PACKET_SIZE; | |
fceaf24a | 1249 | |
972b9529 | 1250 | /* ASSERT(device); */ |
fceaf24a | 1251 | |
c6fcf0ba BP |
1252 | packet = kzalloc(NETVSC_PACKET_SIZE * sizeof(unsigned char), |
1253 | GFP_KERNEL); | |
1254 | if (!packet) | |
1255 | return; | |
1256 | buffer = packet; | |
1257 | ||
fceaf24a | 1258 | netDevice = GetInboundNetDevice(device); |
21a80820 GKH |
1259 | if (!netDevice) { |
1260 | DPRINT_ERR(NETVSC, "net device (%p) shutting down..." | |
1261 | "ignoring inbound packets", netDevice); | |
c6fcf0ba | 1262 | goto out; |
fceaf24a HJ |
1263 | } |
1264 | ||
21a80820 GKH |
1265 | do { |
1266 | ret = device->Driver->VmbusChannelInterface.RecvPacketRaw( | |
1267 | device, buffer, bufferlen, | |
1268 | &bytesRecvd, &requestId); | |
1269 | if (ret == 0) { | |
1270 | if (bytesRecvd > 0) { | |
1271 | DPRINT_DBG(NETVSC, "receive %d bytes, tid %llx", | |
1272 | bytesRecvd, requestId); | |
1273 | ||
1274 | desc = (struct vmpacket_descriptor *)buffer; | |
1275 | switch (desc->Type) { | |
1276 | case VmbusPacketTypeCompletion: | |
1277 | NetVscOnSendCompletion(device, desc); | |
1278 | break; | |
1279 | ||
1280 | case VmbusPacketTypeDataUsingTransferPages: | |
1281 | NetVscOnReceive(device, desc); | |
1282 | break; | |
1283 | ||
1284 | default: | |
1285 | DPRINT_ERR(NETVSC, | |
1286 | "unhandled packet type %d, " | |
1287 | "tid %llx len %d\n", | |
1288 | desc->Type, requestId, | |
1289 | bytesRecvd); | |
1290 | break; | |
fceaf24a HJ |
1291 | } |
1292 | ||
454f18a9 | 1293 | /* reset */ |
c6fcf0ba | 1294 | if (bufferlen > NETVSC_PACKET_SIZE) { |
8c69f52a | 1295 | kfree(buffer); |
fceaf24a | 1296 | buffer = packet; |
c6fcf0ba | 1297 | bufferlen = NETVSC_PACKET_SIZE; |
fceaf24a | 1298 | } |
21a80820 | 1299 | } else { |
454f18a9 | 1300 | /* reset */ |
c6fcf0ba | 1301 | if (bufferlen > NETVSC_PACKET_SIZE) { |
8c69f52a | 1302 | kfree(buffer); |
fceaf24a | 1303 | buffer = packet; |
c6fcf0ba | 1304 | bufferlen = NETVSC_PACKET_SIZE; |
fceaf24a HJ |
1305 | } |
1306 | ||
1307 | break; | |
1308 | } | |
21a80820 GKH |
1309 | } else if (ret == -2) { |
1310 | /* Handle large packet */ | |
0a72f3cf | 1311 | buffer = kmalloc(bytesRecvd, GFP_ATOMIC); |
21a80820 | 1312 | if (buffer == NULL) { |
454f18a9 | 1313 | /* Try again next time around */ |
21a80820 GKH |
1314 | DPRINT_ERR(NETVSC, |
1315 | "unable to allocate buffer of size " | |
1316 | "(%d)!!", bytesRecvd); | |
fceaf24a HJ |
1317 | break; |
1318 | } | |
1319 | ||
1320 | bufferlen = bytesRecvd; | |
fceaf24a HJ |
1321 | } |
1322 | } while (1); | |
1323 | ||
1324 | PutNetDevice(device); | |
c6fcf0ba BP |
1325 | out: |
1326 | kfree(buffer); | |
fceaf24a HJ |
1327 | return; |
1328 | } |