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