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