]>
Commit | Line | Data |
---|---|---|
fceaf24a | 1 | /* |
fceaf24a HJ |
2 | * Copyright (c) 2009, Microsoft Corporation. |
3 | * | |
4 | * This program is free software; you can redistribute it and/or modify it | |
5 | * under the terms and conditions of the GNU General Public License, | |
6 | * version 2, as published by the Free Software Foundation. | |
7 | * | |
8 | * This program is distributed in the hope it will be useful, but WITHOUT | |
9 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
10 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | |
11 | * more details. | |
12 | * | |
13 | * You should have received a copy of the GNU General Public License along with | |
14 | * this program; if not, write to the Free Software Foundation, Inc., 59 Temple | |
15 | * Place - Suite 330, Boston, MA 02111-1307 USA. | |
16 | * | |
17 | * Authors: | |
18 | * Haiyang Zhang <haiyangz@microsoft.com> | |
19 | * Hank Janssen <hjanssen@microsoft.com> | |
fceaf24a | 20 | */ |
5654e932 | 21 | #include <linux/kernel.h> |
0c3b7b2f S |
22 | #include <linux/sched.h> |
23 | #include <linux/wait.h> | |
45da89e5 | 24 | #include <linux/highmem.h> |
5a0e3ad6 | 25 | #include <linux/slab.h> |
0120ee0d | 26 | #include <linux/io.h> |
9f8bd8ba SH |
27 | #include <linux/if_ether.h> |
28 | ||
645954c5 | 29 | #include "logging.h" |
e3fe0bb6 | 30 | #include "hv_api.h" |
a82c7a2a | 31 | #include "netvsc_api.h" |
043efcc3 | 32 | #include "rndis_filter.h" |
fceaf24a | 33 | |
454f18a9 | 34 | /* Data types */ |
e681b954 | 35 | struct rndis_filter_driver_object { |
454f18a9 | 36 | /* The original driver */ |
c2a4efdd | 37 | struct netvsc_driver inner_drv; |
e681b954 | 38 | }; |
fceaf24a | 39 | |
e681b954 | 40 | enum rndis_device_state { |
fceaf24a HJ |
41 | RNDIS_DEV_UNINITIALIZED = 0, |
42 | RNDIS_DEV_INITIALIZING, | |
43 | RNDIS_DEV_INITIALIZED, | |
44 | RNDIS_DEV_DATAINITIALIZED, | |
e681b954 | 45 | }; |
fceaf24a | 46 | |
e681b954 | 47 | struct rndis_device { |
c2a4efdd | 48 | struct netvsc_device *net_dev; |
fceaf24a | 49 | |
c2a4efdd HZ |
50 | enum rndis_device_state state; |
51 | u32 link_stat; | |
52 | atomic_t new_req_id; | |
fceaf24a | 53 | |
880fb89c | 54 | spinlock_t request_lock; |
c2a4efdd | 55 | struct list_head req_list; |
fceaf24a | 56 | |
c2a4efdd | 57 | unsigned char hw_mac_adr[ETH_ALEN]; |
e681b954 | 58 | }; |
fceaf24a | 59 | |
e681b954 | 60 | struct rndis_request { |
c2a4efdd | 61 | struct list_head list_ent; |
0c3b7b2f S |
62 | int wait_condition; |
63 | wait_queue_head_t wait_event; | |
fceaf24a | 64 | |
0120ee0d GKH |
65 | /* |
66 | * FIXME: We assumed a fixed size response here. If we do ever need to | |
67 | * handle a bigger response, we can either define a max response | |
68 | * message or add a response buffer variable above this field | |
69 | */ | |
c2a4efdd | 70 | struct rndis_message response_msg; |
fceaf24a | 71 | |
454f18a9 | 72 | /* Simplify allocation by having a netvsc packet inline */ |
c2a4efdd HZ |
73 | struct hv_netvsc_packet pkt; |
74 | struct hv_page_buffer buf; | |
454f18a9 | 75 | /* FIXME: We assumed a fixed size request here. */ |
c2a4efdd | 76 | struct rndis_message request_msg; |
e681b954 | 77 | }; |
fceaf24a HJ |
78 | |
79 | ||
e681b954 | 80 | struct rndis_filter_packet { |
c2a4efdd HZ |
81 | void *completion_ctx; |
82 | void (*completion)(void *context); | |
83 | struct rndis_message msg; | |
e681b954 | 84 | }; |
fceaf24a | 85 | |
454f18a9 | 86 | |
9c26aa0d | 87 | static int rndis_filte_device_add(struct hv_device *dev, |
c2a4efdd | 88 | void *additional_info); |
454f18a9 | 89 | |
9c26aa0d | 90 | static int rndis_filter_device_remove(struct hv_device *dev); |
fceaf24a | 91 | |
9c26aa0d | 92 | static void rndis_filter_cleanup(struct hv_driver *drv); |
fceaf24a | 93 | |
9c26aa0d | 94 | static int rndis_filter_send(struct hv_device *dev, |
c2a4efdd | 95 | struct hv_netvsc_packet *pkt); |
0120ee0d | 96 | |
9c26aa0d | 97 | static void rndis_filter_send_completion(void *ctx); |
0120ee0d | 98 | |
9c26aa0d | 99 | static void rndis_filter_send_request_completion(void *ctx); |
454f18a9 BP |
100 | |
101 | ||
102 | /* The one and only */ | |
c2a4efdd | 103 | static struct rndis_filter_driver_object rndis_filter; |
fceaf24a | 104 | |
9c26aa0d | 105 | static struct rndis_device *get_rndis_device(void) |
fceaf24a | 106 | { |
e681b954 | 107 | struct rndis_device *device; |
fceaf24a | 108 | |
e681b954 | 109 | device = kzalloc(sizeof(struct rndis_device), GFP_KERNEL); |
fceaf24a | 110 | if (!device) |
fceaf24a | 111 | return NULL; |
fceaf24a | 112 | |
880fb89c | 113 | spin_lock_init(&device->request_lock); |
fceaf24a | 114 | |
c2a4efdd | 115 | INIT_LIST_HEAD(&device->req_list); |
fceaf24a | 116 | |
c2a4efdd | 117 | device->state = RNDIS_DEV_UNINITIALIZED; |
fceaf24a HJ |
118 | |
119 | return device; | |
120 | } | |
121 | ||
9c26aa0d | 122 | static struct rndis_request *get_rndis_request(struct rndis_device *dev, |
c2a4efdd HZ |
123 | u32 msg_type, |
124 | u32 msg_len) | |
fceaf24a | 125 | { |
e681b954 | 126 | struct rndis_request *request; |
c2a4efdd | 127 | struct rndis_message *rndis_msg; |
9f33d054 | 128 | struct rndis_set_request *set; |
880fb89c | 129 | unsigned long flags; |
fceaf24a | 130 | |
e681b954 | 131 | request = kzalloc(sizeof(struct rndis_request), GFP_KERNEL); |
fceaf24a | 132 | if (!request) |
fceaf24a | 133 | return NULL; |
fceaf24a | 134 | |
0c3b7b2f | 135 | init_waitqueue_head(&request->wait_event); |
fceaf24a | 136 | |
c2a4efdd | 137 | rndis_msg = &request->request_msg; |
a388eb17 HZ |
138 | rndis_msg->ndis_msg_type = msg_type; |
139 | rndis_msg->msg_len = msg_len; | |
fceaf24a | 140 | |
0120ee0d GKH |
141 | /* |
142 | * Set the request id. This field is always after the rndis header for | |
143 | * request/response packet types so we just used the SetRequest as a | |
144 | * template | |
145 | */ | |
a388eb17 HZ |
146 | set = &rndis_msg->msg.set_req; |
147 | set->req_id = atomic_inc_return(&dev->new_req_id); | |
fceaf24a | 148 | |
454f18a9 | 149 | /* Add to the request list */ |
c2a4efdd HZ |
150 | spin_lock_irqsave(&dev->request_lock, flags); |
151 | list_add_tail(&request->list_ent, &dev->req_list); | |
152 | spin_unlock_irqrestore(&dev->request_lock, flags); | |
fceaf24a HJ |
153 | |
154 | return request; | |
155 | } | |
156 | ||
9c26aa0d | 157 | static void put_rndis_request(struct rndis_device *dev, |
c2a4efdd | 158 | struct rndis_request *req) |
fceaf24a | 159 | { |
880fb89c GKH |
160 | unsigned long flags; |
161 | ||
c2a4efdd HZ |
162 | spin_lock_irqsave(&dev->request_lock, flags); |
163 | list_del(&req->list_ent); | |
164 | spin_unlock_irqrestore(&dev->request_lock, flags); | |
fceaf24a | 165 | |
c2a4efdd | 166 | kfree(req); |
fceaf24a HJ |
167 | } |
168 | ||
9c26aa0d | 169 | static void dump_rndis_message(struct rndis_message *rndis_msg) |
fceaf24a | 170 | { |
a388eb17 | 171 | switch (rndis_msg->ndis_msg_type) { |
fceaf24a | 172 | case REMOTE_NDIS_PACKET_MSG: |
0120ee0d GKH |
173 | DPRINT_DBG(NETVSC, "REMOTE_NDIS_PACKET_MSG (len %u, " |
174 | "data offset %u data len %u, # oob %u, " | |
175 | "oob offset %u, oob len %u, pkt offset %u, " | |
176 | "pkt len %u", | |
a388eb17 HZ |
177 | rndis_msg->msg_len, |
178 | rndis_msg->msg.pkt.data_offset, | |
179 | rndis_msg->msg.pkt.data_len, | |
180 | rndis_msg->msg.pkt.num_oob_data_elements, | |
181 | rndis_msg->msg.pkt.oob_data_offset, | |
182 | rndis_msg->msg.pkt.oob_data_len, | |
183 | rndis_msg->msg.pkt.per_pkt_info_offset, | |
184 | rndis_msg->msg.pkt.per_pkt_info_len); | |
fceaf24a HJ |
185 | break; |
186 | ||
187 | case REMOTE_NDIS_INITIALIZE_CMPLT: | |
0120ee0d GKH |
188 | DPRINT_DBG(NETVSC, "REMOTE_NDIS_INITIALIZE_CMPLT " |
189 | "(len %u, id 0x%x, status 0x%x, major %d, minor %d, " | |
190 | "device flags %d, max xfer size 0x%x, max pkts %u, " | |
191 | "pkt aligned %u)", | |
a388eb17 HZ |
192 | rndis_msg->msg_len, |
193 | rndis_msg->msg.init_complete.req_id, | |
194 | rndis_msg->msg.init_complete.status, | |
195 | rndis_msg->msg.init_complete.major_ver, | |
196 | rndis_msg->msg.init_complete.minor_ver, | |
197 | rndis_msg->msg.init_complete.dev_flags, | |
198 | rndis_msg->msg.init_complete.max_xfer_size, | |
199 | rndis_msg->msg.init_complete. | |
200 | max_pkt_per_msg, | |
201 | rndis_msg->msg.init_complete. | |
202 | pkt_alignment_factor); | |
fceaf24a HJ |
203 | break; |
204 | ||
205 | case REMOTE_NDIS_QUERY_CMPLT: | |
0120ee0d GKH |
206 | DPRINT_DBG(NETVSC, "REMOTE_NDIS_QUERY_CMPLT " |
207 | "(len %u, id 0x%x, status 0x%x, buf len %u, " | |
208 | "buf offset %u)", | |
a388eb17 HZ |
209 | rndis_msg->msg_len, |
210 | rndis_msg->msg.query_complete.req_id, | |
211 | rndis_msg->msg.query_complete.status, | |
212 | rndis_msg->msg.query_complete. | |
213 | info_buflen, | |
214 | rndis_msg->msg.query_complete. | |
215 | info_buf_offset); | |
fceaf24a HJ |
216 | break; |
217 | ||
218 | case REMOTE_NDIS_SET_CMPLT: | |
0120ee0d GKH |
219 | DPRINT_DBG(NETVSC, |
220 | "REMOTE_NDIS_SET_CMPLT (len %u, id 0x%x, status 0x%x)", | |
a388eb17 HZ |
221 | rndis_msg->msg_len, |
222 | rndis_msg->msg.set_complete.req_id, | |
223 | rndis_msg->msg.set_complete.status); | |
fceaf24a HJ |
224 | break; |
225 | ||
226 | case REMOTE_NDIS_INDICATE_STATUS_MSG: | |
0120ee0d GKH |
227 | DPRINT_DBG(NETVSC, "REMOTE_NDIS_INDICATE_STATUS_MSG " |
228 | "(len %u, status 0x%x, buf len %u, buf offset %u)", | |
a388eb17 HZ |
229 | rndis_msg->msg_len, |
230 | rndis_msg->msg.indicate_status.status, | |
231 | rndis_msg->msg.indicate_status.status_buflen, | |
232 | rndis_msg->msg.indicate_status.status_buf_offset); | |
fceaf24a HJ |
233 | break; |
234 | ||
235 | default: | |
236 | DPRINT_DBG(NETVSC, "0x%x (len %u)", | |
a388eb17 HZ |
237 | rndis_msg->ndis_msg_type, |
238 | rndis_msg->msg_len); | |
fceaf24a HJ |
239 | break; |
240 | } | |
241 | } | |
242 | ||
9c26aa0d | 243 | static int rndis_filter_send_request(struct rndis_device *dev, |
c2a4efdd | 244 | struct rndis_request *req) |
fceaf24a | 245 | { |
0120ee0d | 246 | int ret; |
4193d4f4 | 247 | struct hv_netvsc_packet *packet; |
fceaf24a | 248 | |
454f18a9 | 249 | /* Setup the packet to send it */ |
c2a4efdd | 250 | packet = &req->pkt; |
fceaf24a | 251 | |
72a2f5bd | 252 | packet->is_data_pkt = false; |
a388eb17 | 253 | packet->total_data_buflen = req->request_msg.msg_len; |
72a2f5bd | 254 | packet->page_buf_cnt = 1; |
fceaf24a | 255 | |
ca623ad3 | 256 | packet->page_buf[0].pfn = virt_to_phys(&req->request_msg) >> |
0120ee0d | 257 | PAGE_SHIFT; |
ca623ad3 HZ |
258 | packet->page_buf[0].len = req->request_msg.msg_len; |
259 | packet->page_buf[0].offset = | |
c2a4efdd | 260 | (unsigned long)&req->request_msg & (PAGE_SIZE - 1); |
fceaf24a | 261 | |
72a2f5bd HZ |
262 | packet->completion.send.send_completion_ctx = req;/* packet; */ |
263 | packet->completion.send.send_completion = | |
9c26aa0d | 264 | rndis_filter_send_request_completion; |
72a2f5bd | 265 | packet->completion.send.send_completion_tid = (unsigned long)dev; |
fceaf24a | 266 | |
53d21fdb | 267 | ret = rndis_filter.inner_drv.send(dev->net_dev->dev, packet); |
fceaf24a HJ |
268 | return ret; |
269 | } | |
270 | ||
9c26aa0d | 271 | static void rndis_filter_receive_response(struct rndis_device *dev, |
c2a4efdd | 272 | struct rndis_message *resp) |
fceaf24a | 273 | { |
e681b954 | 274 | struct rndis_request *request = NULL; |
0e727613 | 275 | bool found = false; |
880fb89c | 276 | unsigned long flags; |
fceaf24a | 277 | |
c2a4efdd HZ |
278 | spin_lock_irqsave(&dev->request_lock, flags); |
279 | list_for_each_entry(request, &dev->req_list, list_ent) { | |
0120ee0d GKH |
280 | /* |
281 | * All request/response message contains RequestId as the 1st | |
282 | * field | |
283 | */ | |
a388eb17 HZ |
284 | if (request->request_msg.msg.init_req.req_id |
285 | == resp->msg.init_complete.req_id) { | |
0120ee0d GKH |
286 | DPRINT_DBG(NETVSC, "found rndis request for " |
287 | "this response (id 0x%x req type 0x%x res " | |
288 | "type 0x%x)", | |
a388eb17 HZ |
289 | request->request_msg.msg. |
290 | init_req.req_id, | |
291 | request->request_msg.ndis_msg_type, | |
292 | resp->ndis_msg_type); | |
fceaf24a | 293 | |
0e727613 | 294 | found = true; |
fceaf24a HJ |
295 | break; |
296 | } | |
297 | } | |
c2a4efdd | 298 | spin_unlock_irqrestore(&dev->request_lock, flags); |
fceaf24a | 299 | |
0120ee0d | 300 | if (found) { |
a388eb17 | 301 | if (resp->msg_len <= sizeof(struct rndis_message)) { |
c2a4efdd | 302 | memcpy(&request->response_msg, resp, |
a388eb17 | 303 | resp->msg_len); |
0120ee0d GKH |
304 | } else { |
305 | DPRINT_ERR(NETVSC, "rndis response buffer overflow " | |
306 | "detected (size %u max %zu)", | |
a388eb17 | 307 | resp->msg_len, |
0120ee0d GKH |
308 | sizeof(struct rndis_filter_packet)); |
309 | ||
a388eb17 | 310 | if (resp->ndis_msg_type == |
0120ee0d GKH |
311 | REMOTE_NDIS_RESET_CMPLT) { |
312 | /* does not have a request id field */ | |
a388eb17 HZ |
313 | request->response_msg.msg.reset_complete. |
314 | status = STATUS_BUFFER_OVERFLOW; | |
0120ee0d | 315 | } else { |
a388eb17 HZ |
316 | request->response_msg.msg. |
317 | init_complete.status = | |
c2a4efdd | 318 | STATUS_BUFFER_OVERFLOW; |
fceaf24a HJ |
319 | } |
320 | } | |
321 | ||
0c3b7b2f S |
322 | request->wait_condition = 1; |
323 | wake_up(&request->wait_event); | |
0120ee0d GKH |
324 | } else { |
325 | DPRINT_ERR(NETVSC, "no rndis request found for this response " | |
326 | "(id 0x%x res type 0x%x)", | |
a388eb17 HZ |
327 | resp->msg.init_complete.req_id, |
328 | resp->ndis_msg_type); | |
fceaf24a | 329 | } |
fceaf24a HJ |
330 | } |
331 | ||
9c26aa0d | 332 | static void rndis_filter_receive_indicate_status(struct rndis_device *dev, |
c2a4efdd | 333 | struct rndis_message *resp) |
fceaf24a | 334 | { |
0120ee0d | 335 | struct rndis_indicate_status *indicate = |
a388eb17 | 336 | &resp->msg.indicate_status; |
fceaf24a | 337 | |
a388eb17 | 338 | if (indicate->status == RNDIS_STATUS_MEDIA_CONNECT) { |
72a2f5bd | 339 | rndis_filter.inner_drv.link_status_change( |
53d21fdb | 340 | dev->net_dev->dev, 1); |
a388eb17 | 341 | } else if (indicate->status == RNDIS_STATUS_MEDIA_DISCONNECT) { |
72a2f5bd | 342 | rndis_filter.inner_drv.link_status_change( |
53d21fdb | 343 | dev->net_dev->dev, 0); |
0120ee0d GKH |
344 | } else { |
345 | /* | |
346 | * TODO: | |
347 | */ | |
fceaf24a HJ |
348 | } |
349 | } | |
350 | ||
9c26aa0d | 351 | static void rndis_filter_receive_data(struct rndis_device *dev, |
c2a4efdd HZ |
352 | struct rndis_message *msg, |
353 | struct hv_netvsc_packet *pkt) | |
fceaf24a | 354 | { |
c2a4efdd HZ |
355 | struct rndis_packet *rndis_pkt; |
356 | u32 data_offset; | |
fceaf24a | 357 | |
a388eb17 | 358 | rndis_pkt = &msg->msg.pkt; |
fceaf24a | 359 | |
0120ee0d GKH |
360 | /* |
361 | * FIXME: Handle multiple rndis pkt msgs that maybe enclosed in this | |
362 | * netvsc packet (ie TotalDataBufferLength != MessageLength) | |
363 | */ | |
fceaf24a | 364 | |
454f18a9 | 365 | /* Remove the rndis header and pass it back up the stack */ |
a388eb17 | 366 | data_offset = RNDIS_HEADER_SIZE + rndis_pkt->data_offset; |
fceaf24a | 367 | |
72a2f5bd | 368 | pkt->total_data_buflen -= data_offset; |
ca623ad3 HZ |
369 | pkt->page_buf[0].offset += data_offset; |
370 | pkt->page_buf[0].len -= data_offset; | |
fceaf24a | 371 | |
72a2f5bd | 372 | pkt->is_data_pkt = true; |
fceaf24a | 373 | |
53d21fdb | 374 | rndis_filter.inner_drv.recv_cb(dev->net_dev->dev, |
c2a4efdd | 375 | pkt); |
fceaf24a HJ |
376 | } |
377 | ||
9c26aa0d | 378 | static int rndis_filter_receive(struct hv_device *dev, |
c2a4efdd | 379 | struct hv_netvsc_packet *pkt) |
fceaf24a | 380 | { |
ca623ad3 | 381 | struct netvsc_device *net_dev = dev->ext; |
c2a4efdd HZ |
382 | struct rndis_device *rndis_dev; |
383 | struct rndis_message rndis_msg; | |
384 | struct rndis_message *rndis_hdr; | |
fceaf24a | 385 | |
c2a4efdd | 386 | if (!net_dev) |
8a62d716 BP |
387 | return -EINVAL; |
388 | ||
454f18a9 | 389 | /* Make sure the rndis device state is initialized */ |
53d21fdb | 390 | if (!net_dev->extension) { |
0120ee0d GKH |
391 | DPRINT_ERR(NETVSC, "got rndis message but no rndis device..." |
392 | "dropping this message!"); | |
fceaf24a HJ |
393 | return -1; |
394 | } | |
395 | ||
53d21fdb | 396 | rndis_dev = (struct rndis_device *)net_dev->extension; |
c2a4efdd | 397 | if (rndis_dev->state == RNDIS_DEV_UNINITIALIZED) { |
0120ee0d GKH |
398 | DPRINT_ERR(NETVSC, "got rndis message but rndis device " |
399 | "uninitialized...dropping this message!"); | |
fceaf24a HJ |
400 | return -1; |
401 | } | |
402 | ||
c2a4efdd | 403 | rndis_hdr = (struct rndis_message *)kmap_atomic( |
ca623ad3 | 404 | pfn_to_page(pkt->page_buf[0].pfn), KM_IRQ0); |
fceaf24a | 405 | |
c2a4efdd | 406 | rndis_hdr = (void *)((unsigned long)rndis_hdr + |
ca623ad3 | 407 | pkt->page_buf[0].offset); |
fceaf24a | 408 | |
454f18a9 | 409 | /* Make sure we got a valid rndis message */ |
0120ee0d GKH |
410 | /* |
411 | * FIXME: There seems to be a bug in set completion msg where its | |
412 | * MessageLength is 16 bytes but the ByteCount field in the xfer page | |
413 | * range shows 52 bytes | |
414 | * */ | |
fceaf24a | 415 | #if 0 |
a388eb17 | 416 | if (pkt->total_data_buflen != rndis_hdr->msg_len) { |
ca623ad3 | 417 | kunmap_atomic(rndis_hdr - pkt->page_buf[0].offset, |
0120ee0d GKH |
418 | KM_IRQ0); |
419 | ||
420 | DPRINT_ERR(NETVSC, "invalid rndis message? (expected %u " | |
421 | "bytes got %u)...dropping this message!", | |
a388eb17 | 422 | rndis_hdr->msg_len, |
72a2f5bd | 423 | pkt->total_data_buflen); |
fceaf24a HJ |
424 | return -1; |
425 | } | |
426 | #endif | |
427 | ||
a388eb17 HZ |
428 | if ((rndis_hdr->ndis_msg_type != REMOTE_NDIS_PACKET_MSG) && |
429 | (rndis_hdr->msg_len > sizeof(struct rndis_message))) { | |
0120ee0d GKH |
430 | DPRINT_ERR(NETVSC, "incoming rndis message buffer overflow " |
431 | "detected (got %u, max %zu)...marking it an error!", | |
a388eb17 | 432 | rndis_hdr->msg_len, |
0120ee0d | 433 | sizeof(struct rndis_message)); |
fceaf24a HJ |
434 | } |
435 | ||
c2a4efdd | 436 | memcpy(&rndis_msg, rndis_hdr, |
a388eb17 | 437 | (rndis_hdr->msg_len > sizeof(struct rndis_message)) ? |
0120ee0d | 438 | sizeof(struct rndis_message) : |
a388eb17 | 439 | rndis_hdr->msg_len); |
fceaf24a | 440 | |
ca623ad3 | 441 | kunmap_atomic(rndis_hdr - pkt->page_buf[0].offset, KM_IRQ0); |
fceaf24a | 442 | |
9c26aa0d | 443 | dump_rndis_message(&rndis_msg); |
fceaf24a | 444 | |
a388eb17 | 445 | switch (rndis_msg.ndis_msg_type) { |
fceaf24a | 446 | case REMOTE_NDIS_PACKET_MSG: |
0120ee0d | 447 | /* data msg */ |
9c26aa0d | 448 | rndis_filter_receive_data(rndis_dev, &rndis_msg, pkt); |
fceaf24a HJ |
449 | break; |
450 | ||
fceaf24a HJ |
451 | case REMOTE_NDIS_INITIALIZE_CMPLT: |
452 | case REMOTE_NDIS_QUERY_CMPLT: | |
453 | case REMOTE_NDIS_SET_CMPLT: | |
0120ee0d | 454 | /* completion msgs */ |
9c26aa0d | 455 | rndis_filter_receive_response(rndis_dev, &rndis_msg); |
fceaf24a HJ |
456 | break; |
457 | ||
fceaf24a | 458 | case REMOTE_NDIS_INDICATE_STATUS_MSG: |
0120ee0d | 459 | /* notification msgs */ |
9c26aa0d | 460 | rndis_filter_receive_indicate_status(rndis_dev, &rndis_msg); |
fceaf24a HJ |
461 | break; |
462 | default: | |
0120ee0d | 463 | DPRINT_ERR(NETVSC, "unhandled rndis message (type %u len %u)", |
a388eb17 HZ |
464 | rndis_msg.ndis_msg_type, |
465 | rndis_msg.msg_len); | |
fceaf24a HJ |
466 | break; |
467 | } | |
468 | ||
fceaf24a HJ |
469 | return 0; |
470 | } | |
471 | ||
9c26aa0d | 472 | static int rndis_filter_query_device(struct rndis_device *dev, u32 oid, |
c2a4efdd | 473 | void *result, u32 *result_size) |
fceaf24a | 474 | { |
e681b954 | 475 | struct rndis_request *request; |
c2a4efdd | 476 | u32 inresult_size = *result_size; |
9f33d054 | 477 | struct rndis_query_request *query; |
c2a4efdd | 478 | struct rndis_query_complete *query_complete; |
0120ee0d | 479 | int ret = 0; |
fceaf24a | 480 | |
c2a4efdd | 481 | if (!result) |
8a62d716 | 482 | return -EINVAL; |
fceaf24a | 483 | |
c2a4efdd | 484 | *result_size = 0; |
9c26aa0d | 485 | request = get_rndis_request(dev, REMOTE_NDIS_QUERY_MSG, |
0120ee0d GKH |
486 | RNDIS_MESSAGE_SIZE(struct rndis_query_request)); |
487 | if (!request) { | |
fceaf24a HJ |
488 | ret = -1; |
489 | goto Cleanup; | |
490 | } | |
491 | ||
454f18a9 | 492 | /* Setup the rndis query */ |
a388eb17 HZ |
493 | query = &request->request_msg.msg.query_req; |
494 | query->oid = oid; | |
495 | query->info_buf_offset = sizeof(struct rndis_query_request); | |
496 | query->info_buflen = 0; | |
497 | query->dev_vc_handle = 0; | |
fceaf24a | 498 | |
0c3b7b2f | 499 | request->wait_condition = 0; |
9c26aa0d | 500 | ret = rndis_filter_send_request(dev, request); |
fceaf24a | 501 | if (ret != 0) |
fceaf24a | 502 | goto Cleanup; |
fceaf24a | 503 | |
0c3b7b2f S |
504 | wait_event_timeout(request->wait_event, request->wait_condition, |
505 | msecs_to_jiffies(1000)); | |
506 | if (request->wait_condition == 0) { | |
507 | ret = -ETIMEDOUT; | |
508 | goto Cleanup; | |
509 | } | |
fceaf24a | 510 | |
454f18a9 | 511 | /* Copy the response back */ |
a388eb17 | 512 | query_complete = &request->response_msg.msg.query_complete; |
fceaf24a | 513 | |
a388eb17 | 514 | if (query_complete->info_buflen > inresult_size) { |
fceaf24a HJ |
515 | ret = -1; |
516 | goto Cleanup; | |
517 | } | |
518 | ||
c2a4efdd HZ |
519 | memcpy(result, |
520 | (void *)((unsigned long)query_complete + | |
a388eb17 HZ |
521 | query_complete->info_buf_offset), |
522 | query_complete->info_buflen); | |
fceaf24a | 523 | |
a388eb17 | 524 | *result_size = query_complete->info_buflen; |
fceaf24a HJ |
525 | |
526 | Cleanup: | |
527 | if (request) | |
9c26aa0d | 528 | put_rndis_request(dev, request); |
fceaf24a HJ |
529 | |
530 | return ret; | |
531 | } | |
532 | ||
9c26aa0d | 533 | static int rndis_filter_query_device_mac(struct rndis_device *dev) |
fceaf24a | 534 | { |
9f8bd8ba | 535 | u32 size = ETH_ALEN; |
fceaf24a | 536 | |
9c26aa0d | 537 | return rndis_filter_query_device(dev, |
0120ee0d | 538 | RNDIS_OID_802_3_PERMANENT_ADDRESS, |
c2a4efdd | 539 | dev->hw_mac_adr, &size); |
fceaf24a HJ |
540 | } |
541 | ||
9c26aa0d | 542 | static int rndis_filter_query_device_link_status(struct rndis_device *dev) |
fceaf24a | 543 | { |
0120ee0d | 544 | u32 size = sizeof(u32); |
fceaf24a | 545 | |
9c26aa0d | 546 | return rndis_filter_query_device(dev, |
0120ee0d | 547 | RNDIS_OID_GEN_MEDIA_CONNECT_STATUS, |
c2a4efdd | 548 | &dev->link_stat, &size); |
fceaf24a HJ |
549 | } |
550 | ||
9c26aa0d | 551 | static int rndis_filter_set_packet_filter(struct rndis_device *dev, |
c2a4efdd | 552 | u32 new_filter) |
fceaf24a | 553 | { |
e681b954 | 554 | struct rndis_request *request; |
9f33d054 | 555 | struct rndis_set_request *set; |
c2a4efdd | 556 | struct rndis_set_complete *set_complete; |
4d643114 | 557 | u32 status; |
fceaf24a HJ |
558 | int ret; |
559 | ||
9c26aa0d | 560 | request = get_rndis_request(dev, REMOTE_NDIS_SET_MSG, |
0120ee0d GKH |
561 | RNDIS_MESSAGE_SIZE(struct rndis_set_request) + |
562 | sizeof(u32)); | |
563 | if (!request) { | |
fceaf24a HJ |
564 | ret = -1; |
565 | goto Cleanup; | |
566 | } | |
567 | ||
454f18a9 | 568 | /* Setup the rndis set */ |
a388eb17 HZ |
569 | set = &request->request_msg.msg.set_req; |
570 | set->oid = RNDIS_OID_GEN_CURRENT_PACKET_FILTER; | |
571 | set->info_buflen = sizeof(u32); | |
572 | set->info_buf_offset = sizeof(struct rndis_set_request); | |
fceaf24a | 573 | |
0120ee0d | 574 | memcpy((void *)(unsigned long)set + sizeof(struct rndis_set_request), |
c2a4efdd | 575 | &new_filter, sizeof(u32)); |
fceaf24a | 576 | |
0c3b7b2f | 577 | request->wait_condition = 0; |
9c26aa0d | 578 | ret = rndis_filter_send_request(dev, request); |
fceaf24a | 579 | if (ret != 0) |
fceaf24a | 580 | goto Cleanup; |
fceaf24a | 581 | |
0c3b7b2f S |
582 | wait_event_timeout(request->wait_event, request->wait_condition, |
583 | msecs_to_jiffies(2000)); | |
584 | if (request->wait_condition == 0) { | |
fceaf24a HJ |
585 | ret = -1; |
586 | DPRINT_ERR(NETVSC, "timeout before we got a set response..."); | |
0120ee0d GKH |
587 | /* |
588 | * We cant deallocate the request since we may still receive a | |
589 | * send completion for it. | |
590 | */ | |
fceaf24a | 591 | goto Exit; |
0120ee0d | 592 | } else { |
fceaf24a | 593 | if (ret > 0) |
fceaf24a | 594 | ret = 0; |
a388eb17 HZ |
595 | set_complete = &request->response_msg.msg.set_complete; |
596 | status = set_complete->status; | |
fceaf24a HJ |
597 | } |
598 | ||
599 | Cleanup: | |
600 | if (request) | |
9c26aa0d | 601 | put_rndis_request(dev, request); |
fceaf24a | 602 | Exit: |
fceaf24a HJ |
603 | return ret; |
604 | } | |
605 | ||
9c26aa0d | 606 | int rndis_filter_init(struct netvsc_driver *drv) |
fceaf24a | 607 | { |
0120ee0d GKH |
608 | DPRINT_DBG(NETVSC, "sizeof(struct rndis_filter_packet) == %zd", |
609 | sizeof(struct rndis_filter_packet)); | |
fceaf24a | 610 | |
72a2f5bd | 611 | drv->req_ext_size = sizeof(struct rndis_filter_packet); |
fceaf24a | 612 | |
454f18a9 | 613 | /* Driver->Context = rndisDriver; */ |
fceaf24a | 614 | |
c2a4efdd | 615 | memset(&rndis_filter, 0, sizeof(struct rndis_filter_driver_object)); |
fceaf24a HJ |
616 | |
617 | /*rndisDriver->Driver = Driver; | |
618 | ||
619 | ASSERT(Driver->OnLinkStatusChanged); | |
620 | rndisDriver->OnLinkStatusChanged = Driver->OnLinkStatusChanged;*/ | |
621 | ||
454f18a9 | 622 | /* Save the original dispatch handlers before we override it */ |
ca623ad3 HZ |
623 | rndis_filter.inner_drv.base.dev_add = drv->base.dev_add; |
624 | rndis_filter.inner_drv.base.dev_rm = | |
625 | drv->base.dev_rm; | |
626 | rndis_filter.inner_drv.base.cleanup = drv->base.cleanup; | |
fceaf24a | 627 | |
72a2f5bd HZ |
628 | rndis_filter.inner_drv.send = drv->send; |
629 | rndis_filter.inner_drv.recv_cb = drv->recv_cb; | |
630 | rndis_filter.inner_drv.link_status_change = | |
631 | drv->link_status_change; | |
fceaf24a | 632 | |
454f18a9 | 633 | /* Override */ |
ca623ad3 HZ |
634 | drv->base.dev_add = rndis_filte_device_add; |
635 | drv->base.dev_rm = rndis_filter_device_remove; | |
636 | drv->base.cleanup = rndis_filter_cleanup; | |
72a2f5bd | 637 | drv->send = rndis_filter_send; |
72a2f5bd | 638 | drv->recv_cb = rndis_filter_receive; |
fceaf24a | 639 | |
fceaf24a HJ |
640 | return 0; |
641 | } | |
642 | ||
9c26aa0d | 643 | static int rndis_filter_init_device(struct rndis_device *dev) |
fceaf24a | 644 | { |
e681b954 | 645 | struct rndis_request *request; |
9f33d054 | 646 | struct rndis_initialize_request *init; |
c2a4efdd | 647 | struct rndis_initialize_complete *init_complete; |
4d643114 | 648 | u32 status; |
fceaf24a HJ |
649 | int ret; |
650 | ||
9c26aa0d | 651 | request = get_rndis_request(dev, REMOTE_NDIS_INITIALIZE_MSG, |
0120ee0d GKH |
652 | RNDIS_MESSAGE_SIZE(struct rndis_initialize_request)); |
653 | if (!request) { | |
fceaf24a HJ |
654 | ret = -1; |
655 | goto Cleanup; | |
656 | } | |
657 | ||
454f18a9 | 658 | /* Setup the rndis set */ |
a388eb17 HZ |
659 | init = &request->request_msg.msg.init_req; |
660 | init->major_ver = RNDIS_MAJOR_VERSION; | |
661 | init->minor_ver = RNDIS_MINOR_VERSION; | |
0120ee0d | 662 | /* FIXME: Use 1536 - rounded ethernet frame size */ |
a388eb17 | 663 | init->max_xfer_size = 2048; |
fceaf24a | 664 | |
c2a4efdd | 665 | dev->state = RNDIS_DEV_INITIALIZING; |
fceaf24a | 666 | |
0c3b7b2f | 667 | request->wait_condition = 0; |
9c26aa0d | 668 | ret = rndis_filter_send_request(dev, request); |
0120ee0d | 669 | if (ret != 0) { |
c2a4efdd | 670 | dev->state = RNDIS_DEV_UNINITIALIZED; |
fceaf24a HJ |
671 | goto Cleanup; |
672 | } | |
673 | ||
0c3b7b2f S |
674 | |
675 | wait_event_timeout(request->wait_event, request->wait_condition, | |
676 | msecs_to_jiffies(1000)); | |
677 | if (request->wait_condition == 0) { | |
678 | ret = -ETIMEDOUT; | |
679 | goto Cleanup; | |
680 | } | |
fceaf24a | 681 | |
a388eb17 HZ |
682 | init_complete = &request->response_msg.msg.init_complete; |
683 | status = init_complete->status; | |
0120ee0d | 684 | if (status == RNDIS_STATUS_SUCCESS) { |
c2a4efdd | 685 | dev->state = RNDIS_DEV_INITIALIZED; |
fceaf24a | 686 | ret = 0; |
0120ee0d | 687 | } else { |
c2a4efdd | 688 | dev->state = RNDIS_DEV_UNINITIALIZED; |
fceaf24a HJ |
689 | ret = -1; |
690 | } | |
691 | ||
692 | Cleanup: | |
693 | if (request) | |
9c26aa0d | 694 | put_rndis_request(dev, request); |
fceaf24a HJ |
695 | |
696 | return ret; | |
697 | } | |
698 | ||
9c26aa0d | 699 | static void rndis_filter_halt_device(struct rndis_device *dev) |
fceaf24a | 700 | { |
e681b954 | 701 | struct rndis_request *request; |
9f33d054 | 702 | struct rndis_halt_request *halt; |
fceaf24a | 703 | |
454f18a9 | 704 | /* Attempt to do a rndis device halt */ |
9c26aa0d | 705 | request = get_rndis_request(dev, REMOTE_NDIS_HALT_MSG, |
0120ee0d | 706 | RNDIS_MESSAGE_SIZE(struct rndis_halt_request)); |
fceaf24a | 707 | if (!request) |
fceaf24a | 708 | goto Cleanup; |
fceaf24a | 709 | |
454f18a9 | 710 | /* Setup the rndis set */ |
a388eb17 HZ |
711 | halt = &request->request_msg.msg.halt_req; |
712 | halt->req_id = atomic_inc_return(&dev->new_req_id); | |
fceaf24a | 713 | |
454f18a9 | 714 | /* Ignore return since this msg is optional. */ |
9c26aa0d | 715 | rndis_filter_send_request(dev, request); |
fceaf24a | 716 | |
c2a4efdd | 717 | dev->state = RNDIS_DEV_UNINITIALIZED; |
fceaf24a HJ |
718 | |
719 | Cleanup: | |
720 | if (request) | |
9c26aa0d | 721 | put_rndis_request(dev, request); |
fceaf24a HJ |
722 | return; |
723 | } | |
724 | ||
9c26aa0d | 725 | static int rndis_filter_open_device(struct rndis_device *dev) |
fceaf24a | 726 | { |
0120ee0d | 727 | int ret; |
fceaf24a | 728 | |
c2a4efdd | 729 | if (dev->state != RNDIS_DEV_INITIALIZED) |
fceaf24a HJ |
730 | return 0; |
731 | ||
9c26aa0d | 732 | ret = rndis_filter_set_packet_filter(dev, |
0120ee0d | 733 | NDIS_PACKET_TYPE_BROADCAST | |
95beae90 | 734 | NDIS_PACKET_TYPE_ALL_MULTICAST | |
0120ee0d | 735 | NDIS_PACKET_TYPE_DIRECTED); |
fceaf24a | 736 | if (ret == 0) |
c2a4efdd | 737 | dev->state = RNDIS_DEV_DATAINITIALIZED; |
fceaf24a | 738 | |
fceaf24a HJ |
739 | return ret; |
740 | } | |
741 | ||
9c26aa0d | 742 | static int rndis_filter_close_device(struct rndis_device *dev) |
fceaf24a HJ |
743 | { |
744 | int ret; | |
745 | ||
c2a4efdd | 746 | if (dev->state != RNDIS_DEV_DATAINITIALIZED) |
fceaf24a HJ |
747 | return 0; |
748 | ||
9c26aa0d | 749 | ret = rndis_filter_set_packet_filter(dev, 0); |
fceaf24a | 750 | if (ret == 0) |
c2a4efdd | 751 | dev->state = RNDIS_DEV_INITIALIZED; |
fceaf24a | 752 | |
fceaf24a HJ |
753 | return ret; |
754 | } | |
755 | ||
9c26aa0d | 756 | static int rndis_filte_device_add(struct hv_device *dev, |
c2a4efdd | 757 | void *additional_info) |
fceaf24a HJ |
758 | { |
759 | int ret; | |
ce9ea4cf | 760 | struct netvsc_device *netDevice; |
e681b954 | 761 | struct rndis_device *rndisDevice; |
c2a4efdd | 762 | struct netvsc_device_info *deviceInfo = additional_info; |
fceaf24a | 763 | |
9c26aa0d | 764 | rndisDevice = get_rndis_device(); |
83c720ea | 765 | if (!rndisDevice) |
fceaf24a | 766 | return -1; |
fceaf24a HJ |
767 | |
768 | DPRINT_DBG(NETVSC, "rndis device object allocated - %p", rndisDevice); | |
769 | ||
0120ee0d GKH |
770 | /* |
771 | * Let the inner driver handle this first to create the netvsc channel | |
772 | * NOTE! Once the channel is created, we may get a receive callback | |
773 | * (RndisFilterOnReceive()) before this call is completed | |
774 | */ | |
ca623ad3 | 775 | ret = rndis_filter.inner_drv.base.dev_add(dev, additional_info); |
0120ee0d GKH |
776 | if (ret != 0) { |
777 | kfree(rndisDevice); | |
fceaf24a HJ |
778 | return ret; |
779 | } | |
780 | ||
454f18a9 BP |
781 | |
782 | /* Initialize the rndis device */ | |
ca623ad3 | 783 | netDevice = dev->ext; |
fceaf24a | 784 | |
53d21fdb | 785 | netDevice->extension = rndisDevice; |
c2a4efdd | 786 | rndisDevice->net_dev = netDevice; |
fceaf24a | 787 | |
454f18a9 | 788 | /* Send the rndis initialization message */ |
9c26aa0d | 789 | ret = rndis_filter_init_device(rndisDevice); |
0120ee0d GKH |
790 | if (ret != 0) { |
791 | /* | |
792 | * TODO: If rndis init failed, we will need to shut down the | |
793 | * channel | |
794 | */ | |
fceaf24a HJ |
795 | } |
796 | ||
454f18a9 | 797 | /* Get the mac address */ |
9c26aa0d | 798 | ret = rndis_filter_query_device_mac(rndisDevice); |
0120ee0d GKH |
799 | if (ret != 0) { |
800 | /* | |
801 | * TODO: shutdown rndis device and the channel | |
802 | */ | |
fceaf24a HJ |
803 | } |
804 | ||
9f8bd8ba | 805 | DPRINT_INFO(NETVSC, "Device 0x%p mac addr %pM", |
c2a4efdd | 806 | rndisDevice, rndisDevice->hw_mac_adr); |
fceaf24a | 807 | |
72a2f5bd | 808 | memcpy(deviceInfo->mac_adr, rndisDevice->hw_mac_adr, ETH_ALEN); |
fceaf24a | 809 | |
9c26aa0d | 810 | rndis_filter_query_device_link_status(rndisDevice); |
fceaf24a | 811 | |
72a2f5bd | 812 | deviceInfo->link_state = rndisDevice->link_stat; |
0120ee0d | 813 | DPRINT_INFO(NETVSC, "Device 0x%p link state %s", rndisDevice, |
72a2f5bd | 814 | ((deviceInfo->link_state) ? ("down") : ("up"))); |
fceaf24a | 815 | |
fceaf24a HJ |
816 | return ret; |
817 | } | |
818 | ||
9c26aa0d | 819 | static int rndis_filter_device_remove(struct hv_device *dev) |
fceaf24a | 820 | { |
ca623ad3 | 821 | struct netvsc_device *net_dev = dev->ext; |
53d21fdb | 822 | struct rndis_device *rndis_dev = net_dev->extension; |
fceaf24a | 823 | |
454f18a9 | 824 | /* Halt and release the rndis device */ |
9c26aa0d | 825 | rndis_filter_halt_device(rndis_dev); |
fceaf24a | 826 | |
c2a4efdd | 827 | kfree(rndis_dev); |
53d21fdb | 828 | net_dev->extension = NULL; |
fceaf24a | 829 | |
454f18a9 | 830 | /* Pass control to inner driver to remove the device */ |
ca623ad3 | 831 | rndis_filter.inner_drv.base.dev_rm(dev); |
fceaf24a | 832 | |
fceaf24a HJ |
833 | return 0; |
834 | } | |
835 | ||
9c26aa0d | 836 | static void rndis_filter_cleanup(struct hv_driver *drv) |
fceaf24a | 837 | { |
fceaf24a HJ |
838 | } |
839 | ||
9c26aa0d | 840 | int rndis_filter_open(struct hv_device *dev) |
fceaf24a | 841 | { |
ca623ad3 | 842 | struct netvsc_device *netDevice = dev->ext; |
fceaf24a | 843 | |
8a62d716 BP |
844 | if (!netDevice) |
845 | return -EINVAL; | |
846 | ||
53d21fdb | 847 | return rndis_filter_open_device(netDevice->extension); |
fceaf24a HJ |
848 | } |
849 | ||
9c26aa0d | 850 | int rndis_filter_close(struct hv_device *dev) |
fceaf24a | 851 | { |
ca623ad3 | 852 | struct netvsc_device *netDevice = dev->ext; |
fceaf24a | 853 | |
8a62d716 BP |
854 | if (!netDevice) |
855 | return -EINVAL; | |
856 | ||
53d21fdb | 857 | return rndis_filter_close_device(netDevice->extension); |
fceaf24a HJ |
858 | } |
859 | ||
9c26aa0d | 860 | static int rndis_filter_send(struct hv_device *dev, |
c2a4efdd | 861 | struct hv_netvsc_packet *pkt) |
fceaf24a | 862 | { |
0120ee0d | 863 | int ret; |
e681b954 | 864 | struct rndis_filter_packet *filterPacket; |
9f33d054 GKH |
865 | struct rndis_message *rndisMessage; |
866 | struct rndis_packet *rndisPacket; | |
4d643114 | 867 | u32 rndisMessageSize; |
fceaf24a | 868 | |
454f18a9 | 869 | /* Add the rndis header */ |
72a2f5bd | 870 | filterPacket = (struct rndis_filter_packet *)pkt->extension; |
fceaf24a | 871 | |
e681b954 | 872 | memset(filterPacket, 0, sizeof(struct rndis_filter_packet)); |
fceaf24a | 873 | |
c2a4efdd | 874 | rndisMessage = &filterPacket->msg; |
9f33d054 | 875 | rndisMessageSize = RNDIS_MESSAGE_SIZE(struct rndis_packet); |
fceaf24a | 876 | |
a388eb17 HZ |
877 | rndisMessage->ndis_msg_type = REMOTE_NDIS_PACKET_MSG; |
878 | rndisMessage->msg_len = pkt->total_data_buflen + | |
0120ee0d | 879 | rndisMessageSize; |
fceaf24a | 880 | |
a388eb17 HZ |
881 | rndisPacket = &rndisMessage->msg.pkt; |
882 | rndisPacket->data_offset = sizeof(struct rndis_packet); | |
883 | rndisPacket->data_len = pkt->total_data_buflen; | |
fceaf24a | 884 | |
72a2f5bd | 885 | pkt->is_data_pkt = true; |
ca623ad3 HZ |
886 | pkt->page_buf[0].pfn = virt_to_phys(rndisMessage) >> PAGE_SHIFT; |
887 | pkt->page_buf[0].offset = | |
0120ee0d | 888 | (unsigned long)rndisMessage & (PAGE_SIZE-1); |
ca623ad3 | 889 | pkt->page_buf[0].len = rndisMessageSize; |
fceaf24a | 890 | |
454f18a9 | 891 | /* Save the packet send completion and context */ |
72a2f5bd | 892 | filterPacket->completion = pkt->completion.send.send_completion; |
c2a4efdd | 893 | filterPacket->completion_ctx = |
72a2f5bd | 894 | pkt->completion.send.send_completion_ctx; |
fceaf24a | 895 | |
454f18a9 | 896 | /* Use ours */ |
72a2f5bd HZ |
897 | pkt->completion.send.send_completion = rndis_filter_send_completion; |
898 | pkt->completion.send.send_completion_ctx = filterPacket; | |
fceaf24a | 899 | |
72a2f5bd | 900 | ret = rndis_filter.inner_drv.send(dev, pkt); |
0120ee0d GKH |
901 | if (ret != 0) { |
902 | /* | |
903 | * Reset the completion to originals to allow retries from | |
904 | * above | |
905 | */ | |
72a2f5bd | 906 | pkt->completion.send.send_completion = |
c2a4efdd | 907 | filterPacket->completion; |
72a2f5bd | 908 | pkt->completion.send.send_completion_ctx = |
c2a4efdd | 909 | filterPacket->completion_ctx; |
fceaf24a HJ |
910 | } |
911 | ||
fceaf24a HJ |
912 | return ret; |
913 | } | |
914 | ||
9c26aa0d | 915 | static void rndis_filter_send_completion(void *ctx) |
fceaf24a | 916 | { |
c2a4efdd | 917 | struct rndis_filter_packet *filterPacket = ctx; |
fceaf24a | 918 | |
454f18a9 | 919 | /* Pass it back to the original handler */ |
c2a4efdd | 920 | filterPacket->completion(filterPacket->completion_ctx); |
fceaf24a HJ |
921 | } |
922 | ||
923 | ||
9c26aa0d | 924 | static void rndis_filter_send_request_completion(void *ctx) |
fceaf24a | 925 | { |
454f18a9 | 926 | /* Noop */ |
fceaf24a | 927 | } |