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 | 27 | #include <linux/if_ether.h> |
eb335bc4 | 28 | #include <linux/netdevice.h> |
1f5f3a75 | 29 | #include <linux/if_vlan.h> |
1ce09e89 | 30 | #include <linux/nls.h> |
3f335ea2 | 31 | |
5ca7252a | 32 | #include "hyperv_net.h" |
fceaf24a | 33 | |
fceaf24a | 34 | |
e681b954 | 35 | struct rndis_request { |
c2a4efdd | 36 | struct list_head list_ent; |
98d79690 | 37 | struct completion wait_event; |
fceaf24a | 38 | |
0120ee0d GKH |
39 | /* |
40 | * FIXME: We assumed a fixed size response here. If we do ever need to | |
41 | * handle a bigger response, we can either define a max response | |
42 | * message or add a response buffer variable above this field | |
43 | */ | |
c2a4efdd | 44 | struct rndis_message response_msg; |
fceaf24a | 45 | |
454f18a9 | 46 | /* Simplify allocation by having a netvsc packet inline */ |
c2a4efdd HZ |
47 | struct hv_netvsc_packet pkt; |
48 | struct hv_page_buffer buf; | |
454f18a9 | 49 | /* FIXME: We assumed a fixed size request here. */ |
c2a4efdd | 50 | struct rndis_message request_msg; |
1ce09e89 | 51 | u8 ext[100]; |
e681b954 | 52 | }; |
fceaf24a | 53 | |
9c26aa0d | 54 | static void rndis_filter_send_completion(void *ctx); |
0120ee0d | 55 | |
9c26aa0d | 56 | static void rndis_filter_send_request_completion(void *ctx); |
454f18a9 BP |
57 | |
58 | ||
fceaf24a | 59 | |
9c26aa0d | 60 | static struct rndis_device *get_rndis_device(void) |
fceaf24a | 61 | { |
e681b954 | 62 | struct rndis_device *device; |
fceaf24a | 63 | |
e681b954 | 64 | device = kzalloc(sizeof(struct rndis_device), GFP_KERNEL); |
fceaf24a | 65 | if (!device) |
fceaf24a | 66 | return NULL; |
fceaf24a | 67 | |
880fb89c | 68 | spin_lock_init(&device->request_lock); |
fceaf24a | 69 | |
c2a4efdd | 70 | INIT_LIST_HEAD(&device->req_list); |
fceaf24a | 71 | |
c2a4efdd | 72 | device->state = RNDIS_DEV_UNINITIALIZED; |
fceaf24a HJ |
73 | |
74 | return device; | |
75 | } | |
76 | ||
9c26aa0d | 77 | static struct rndis_request *get_rndis_request(struct rndis_device *dev, |
c2a4efdd HZ |
78 | u32 msg_type, |
79 | u32 msg_len) | |
fceaf24a | 80 | { |
e681b954 | 81 | struct rndis_request *request; |
c2a4efdd | 82 | struct rndis_message *rndis_msg; |
9f33d054 | 83 | struct rndis_set_request *set; |
880fb89c | 84 | unsigned long flags; |
fceaf24a | 85 | |
e681b954 | 86 | request = kzalloc(sizeof(struct rndis_request), GFP_KERNEL); |
fceaf24a | 87 | if (!request) |
fceaf24a | 88 | return NULL; |
fceaf24a | 89 | |
98d79690 | 90 | init_completion(&request->wait_event); |
fceaf24a | 91 | |
c2a4efdd | 92 | rndis_msg = &request->request_msg; |
a388eb17 HZ |
93 | rndis_msg->ndis_msg_type = msg_type; |
94 | rndis_msg->msg_len = msg_len; | |
fceaf24a | 95 | |
0120ee0d GKH |
96 | /* |
97 | * Set the request id. This field is always after the rndis header for | |
98 | * request/response packet types so we just used the SetRequest as a | |
99 | * template | |
100 | */ | |
a388eb17 HZ |
101 | set = &rndis_msg->msg.set_req; |
102 | set->req_id = atomic_inc_return(&dev->new_req_id); | |
fceaf24a | 103 | |
454f18a9 | 104 | /* Add to the request list */ |
c2a4efdd HZ |
105 | spin_lock_irqsave(&dev->request_lock, flags); |
106 | list_add_tail(&request->list_ent, &dev->req_list); | |
107 | spin_unlock_irqrestore(&dev->request_lock, flags); | |
fceaf24a HJ |
108 | |
109 | return request; | |
110 | } | |
111 | ||
9c26aa0d | 112 | static void put_rndis_request(struct rndis_device *dev, |
c2a4efdd | 113 | struct rndis_request *req) |
fceaf24a | 114 | { |
880fb89c GKH |
115 | unsigned long flags; |
116 | ||
c2a4efdd HZ |
117 | spin_lock_irqsave(&dev->request_lock, flags); |
118 | list_del(&req->list_ent); | |
119 | spin_unlock_irqrestore(&dev->request_lock, flags); | |
fceaf24a | 120 | |
c2a4efdd | 121 | kfree(req); |
fceaf24a HJ |
122 | } |
123 | ||
729a2849 HZ |
124 | static void dump_rndis_message(struct hv_device *hv_dev, |
125 | struct rndis_message *rndis_msg) | |
fceaf24a | 126 | { |
2ddd5e5f S |
127 | struct net_device *netdev; |
128 | struct netvsc_device *net_device; | |
129 | ||
130 | net_device = hv_get_drvdata(hv_dev); | |
131 | netdev = net_device->ndev; | |
729a2849 | 132 | |
a388eb17 | 133 | switch (rndis_msg->ndis_msg_type) { |
51491167 LW |
134 | case RNDIS_MSG_PACKET: |
135 | netdev_dbg(netdev, "RNDIS_MSG_PACKET (len %u, " | |
0120ee0d GKH |
136 | "data offset %u data len %u, # oob %u, " |
137 | "oob offset %u, oob len %u, pkt offset %u, " | |
729a2849 | 138 | "pkt len %u\n", |
a388eb17 HZ |
139 | rndis_msg->msg_len, |
140 | rndis_msg->msg.pkt.data_offset, | |
141 | rndis_msg->msg.pkt.data_len, | |
142 | rndis_msg->msg.pkt.num_oob_data_elements, | |
143 | rndis_msg->msg.pkt.oob_data_offset, | |
144 | rndis_msg->msg.pkt.oob_data_len, | |
145 | rndis_msg->msg.pkt.per_pkt_info_offset, | |
146 | rndis_msg->msg.pkt.per_pkt_info_len); | |
fceaf24a HJ |
147 | break; |
148 | ||
51491167 LW |
149 | case RNDIS_MSG_INIT_C: |
150 | netdev_dbg(netdev, "RNDIS_MSG_INIT_C " | |
0120ee0d GKH |
151 | "(len %u, id 0x%x, status 0x%x, major %d, minor %d, " |
152 | "device flags %d, max xfer size 0x%x, max pkts %u, " | |
729a2849 | 153 | "pkt aligned %u)\n", |
a388eb17 HZ |
154 | rndis_msg->msg_len, |
155 | rndis_msg->msg.init_complete.req_id, | |
156 | rndis_msg->msg.init_complete.status, | |
157 | rndis_msg->msg.init_complete.major_ver, | |
158 | rndis_msg->msg.init_complete.minor_ver, | |
159 | rndis_msg->msg.init_complete.dev_flags, | |
160 | rndis_msg->msg.init_complete.max_xfer_size, | |
161 | rndis_msg->msg.init_complete. | |
162 | max_pkt_per_msg, | |
163 | rndis_msg->msg.init_complete. | |
164 | pkt_alignment_factor); | |
fceaf24a HJ |
165 | break; |
166 | ||
51491167 LW |
167 | case RNDIS_MSG_QUERY_C: |
168 | netdev_dbg(netdev, "RNDIS_MSG_QUERY_C " | |
0120ee0d | 169 | "(len %u, id 0x%x, status 0x%x, buf len %u, " |
729a2849 | 170 | "buf offset %u)\n", |
a388eb17 HZ |
171 | rndis_msg->msg_len, |
172 | rndis_msg->msg.query_complete.req_id, | |
173 | rndis_msg->msg.query_complete.status, | |
174 | rndis_msg->msg.query_complete. | |
175 | info_buflen, | |
176 | rndis_msg->msg.query_complete. | |
177 | info_buf_offset); | |
fceaf24a HJ |
178 | break; |
179 | ||
51491167 | 180 | case RNDIS_MSG_SET_C: |
729a2849 | 181 | netdev_dbg(netdev, |
51491167 | 182 | "RNDIS_MSG_SET_C (len %u, id 0x%x, status 0x%x)\n", |
a388eb17 HZ |
183 | rndis_msg->msg_len, |
184 | rndis_msg->msg.set_complete.req_id, | |
185 | rndis_msg->msg.set_complete.status); | |
fceaf24a HJ |
186 | break; |
187 | ||
51491167 LW |
188 | case RNDIS_MSG_INDICATE: |
189 | netdev_dbg(netdev, "RNDIS_MSG_INDICATE " | |
729a2849 | 190 | "(len %u, status 0x%x, buf len %u, buf offset %u)\n", |
a388eb17 HZ |
191 | rndis_msg->msg_len, |
192 | rndis_msg->msg.indicate_status.status, | |
193 | rndis_msg->msg.indicate_status.status_buflen, | |
194 | rndis_msg->msg.indicate_status.status_buf_offset); | |
fceaf24a HJ |
195 | break; |
196 | ||
197 | default: | |
729a2849 | 198 | netdev_dbg(netdev, "0x%x (len %u)\n", |
a388eb17 HZ |
199 | rndis_msg->ndis_msg_type, |
200 | rndis_msg->msg_len); | |
fceaf24a HJ |
201 | break; |
202 | } | |
203 | } | |
204 | ||
9c26aa0d | 205 | static int rndis_filter_send_request(struct rndis_device *dev, |
c2a4efdd | 206 | struct rndis_request *req) |
fceaf24a | 207 | { |
0120ee0d | 208 | int ret; |
4193d4f4 | 209 | struct hv_netvsc_packet *packet; |
fceaf24a | 210 | |
454f18a9 | 211 | /* Setup the packet to send it */ |
c2a4efdd | 212 | packet = &req->pkt; |
fceaf24a | 213 | |
72a2f5bd | 214 | packet->is_data_pkt = false; |
a388eb17 | 215 | packet->total_data_buflen = req->request_msg.msg_len; |
72a2f5bd | 216 | packet->page_buf_cnt = 1; |
fceaf24a | 217 | |
ca623ad3 | 218 | packet->page_buf[0].pfn = virt_to_phys(&req->request_msg) >> |
0120ee0d | 219 | PAGE_SHIFT; |
ca623ad3 HZ |
220 | packet->page_buf[0].len = req->request_msg.msg_len; |
221 | packet->page_buf[0].offset = | |
c2a4efdd | 222 | (unsigned long)&req->request_msg & (PAGE_SIZE - 1); |
fceaf24a | 223 | |
72a2f5bd HZ |
224 | packet->completion.send.send_completion_ctx = req;/* packet; */ |
225 | packet->completion.send.send_completion = | |
9c26aa0d | 226 | rndis_filter_send_request_completion; |
72a2f5bd | 227 | packet->completion.send.send_completion_tid = (unsigned long)dev; |
fceaf24a | 228 | |
0ec6ff40 | 229 | ret = netvsc_send(dev->net_dev->dev, packet); |
fceaf24a HJ |
230 | return ret; |
231 | } | |
232 | ||
9c26aa0d | 233 | static void rndis_filter_receive_response(struct rndis_device *dev, |
c2a4efdd | 234 | struct rndis_message *resp) |
fceaf24a | 235 | { |
e681b954 | 236 | struct rndis_request *request = NULL; |
0e727613 | 237 | bool found = false; |
880fb89c | 238 | unsigned long flags; |
2ddd5e5f S |
239 | struct net_device *ndev; |
240 | ||
241 | ndev = dev->net_dev->ndev; | |
fceaf24a | 242 | |
c2a4efdd HZ |
243 | spin_lock_irqsave(&dev->request_lock, flags); |
244 | list_for_each_entry(request, &dev->req_list, list_ent) { | |
0120ee0d GKH |
245 | /* |
246 | * All request/response message contains RequestId as the 1st | |
247 | * field | |
248 | */ | |
a388eb17 HZ |
249 | if (request->request_msg.msg.init_req.req_id |
250 | == resp->msg.init_complete.req_id) { | |
0e727613 | 251 | found = true; |
fceaf24a HJ |
252 | break; |
253 | } | |
254 | } | |
c2a4efdd | 255 | spin_unlock_irqrestore(&dev->request_lock, flags); |
fceaf24a | 256 | |
0120ee0d | 257 | if (found) { |
a388eb17 | 258 | if (resp->msg_len <= sizeof(struct rndis_message)) { |
c2a4efdd | 259 | memcpy(&request->response_msg, resp, |
a388eb17 | 260 | resp->msg_len); |
0120ee0d | 261 | } else { |
d9871158 | 262 | netdev_err(ndev, |
eb335bc4 HJ |
263 | "rndis response buffer overflow " |
264 | "detected (size %u max %zu)\n", | |
265 | resp->msg_len, | |
266 | sizeof(struct rndis_filter_packet)); | |
0120ee0d | 267 | |
a388eb17 | 268 | if (resp->ndis_msg_type == |
51491167 | 269 | RNDIS_MSG_RESET_C) { |
0120ee0d | 270 | /* does not have a request id field */ |
a388eb17 | 271 | request->response_msg.msg.reset_complete. |
007e5c8e | 272 | status = RNDIS_STATUS_BUFFER_OVERFLOW; |
0120ee0d | 273 | } else { |
a388eb17 HZ |
274 | request->response_msg.msg. |
275 | init_complete.status = | |
007e5c8e | 276 | RNDIS_STATUS_BUFFER_OVERFLOW; |
fceaf24a HJ |
277 | } |
278 | } | |
279 | ||
98d79690 | 280 | complete(&request->wait_event); |
0120ee0d | 281 | } else { |
d9871158 | 282 | netdev_err(ndev, |
eb335bc4 HJ |
283 | "no rndis request found for this response " |
284 | "(id 0x%x res type 0x%x)\n", | |
285 | resp->msg.init_complete.req_id, | |
286 | resp->ndis_msg_type); | |
fceaf24a | 287 | } |
fceaf24a HJ |
288 | } |
289 | ||
9c26aa0d | 290 | static void rndis_filter_receive_indicate_status(struct rndis_device *dev, |
c2a4efdd | 291 | struct rndis_message *resp) |
fceaf24a | 292 | { |
0120ee0d | 293 | struct rndis_indicate_status *indicate = |
a388eb17 | 294 | &resp->msg.indicate_status; |
fceaf24a | 295 | |
a388eb17 | 296 | if (indicate->status == RNDIS_STATUS_MEDIA_CONNECT) { |
39fb6aab | 297 | netvsc_linkstatus_callback( |
53d21fdb | 298 | dev->net_dev->dev, 1); |
a388eb17 | 299 | } else if (indicate->status == RNDIS_STATUS_MEDIA_DISCONNECT) { |
39fb6aab | 300 | netvsc_linkstatus_callback( |
53d21fdb | 301 | dev->net_dev->dev, 0); |
0120ee0d GKH |
302 | } else { |
303 | /* | |
304 | * TODO: | |
305 | */ | |
fceaf24a HJ |
306 | } |
307 | } | |
308 | ||
1f5f3a75 HZ |
309 | /* |
310 | * Get the Per-Packet-Info with the specified type | |
311 | * return NULL if not found. | |
312 | */ | |
313 | static inline void *rndis_get_ppi(struct rndis_packet *rpkt, u32 type) | |
314 | { | |
315 | struct rndis_per_packet_info *ppi; | |
316 | int len; | |
317 | ||
318 | if (rpkt->per_pkt_info_offset == 0) | |
319 | return NULL; | |
320 | ||
321 | ppi = (struct rndis_per_packet_info *)((ulong)rpkt + | |
322 | rpkt->per_pkt_info_offset); | |
323 | len = rpkt->per_pkt_info_len; | |
324 | ||
325 | while (len > 0) { | |
326 | if (ppi->type == type) | |
327 | return (void *)((ulong)ppi + ppi->ppi_offset); | |
328 | len -= ppi->size; | |
329 | ppi = (struct rndis_per_packet_info *)((ulong)ppi + ppi->size); | |
330 | } | |
331 | ||
332 | return NULL; | |
333 | } | |
334 | ||
9c26aa0d | 335 | static void rndis_filter_receive_data(struct rndis_device *dev, |
c2a4efdd HZ |
336 | struct rndis_message *msg, |
337 | struct hv_netvsc_packet *pkt) | |
fceaf24a | 338 | { |
c2a4efdd HZ |
339 | struct rndis_packet *rndis_pkt; |
340 | u32 data_offset; | |
1f5f3a75 | 341 | struct ndis_pkt_8021q_info *vlan; |
fceaf24a | 342 | |
a388eb17 | 343 | rndis_pkt = &msg->msg.pkt; |
fceaf24a | 344 | |
0120ee0d GKH |
345 | /* |
346 | * FIXME: Handle multiple rndis pkt msgs that maybe enclosed in this | |
347 | * netvsc packet (ie TotalDataBufferLength != MessageLength) | |
348 | */ | |
fceaf24a | 349 | |
454f18a9 | 350 | /* Remove the rndis header and pass it back up the stack */ |
a388eb17 | 351 | data_offset = RNDIS_HEADER_SIZE + rndis_pkt->data_offset; |
fceaf24a | 352 | |
72a2f5bd | 353 | pkt->total_data_buflen -= data_offset; |
4b8a8bc9 WY |
354 | |
355 | /* | |
356 | * Make sure we got a valid RNDIS message, now total_data_buflen | |
357 | * should be the data packet size plus the trailer padding size | |
358 | */ | |
359 | if (pkt->total_data_buflen < rndis_pkt->data_len) { | |
360 | netdev_err(dev->net_dev->ndev, "rndis message buffer " | |
361 | "overflow detected (got %u, min %u)" | |
362 | "...dropping this message!\n", | |
363 | pkt->total_data_buflen, rndis_pkt->data_len); | |
364 | return; | |
365 | } | |
366 | ||
367 | /* | |
368 | * Remove the rndis trailer padding from rndis packet message | |
369 | * rndis_pkt->data_len tell us the real data length, we only copy | |
370 | * the data packet to the stack, without the rndis trailer padding | |
371 | */ | |
372 | pkt->total_data_buflen = rndis_pkt->data_len; | |
45326342 | 373 | pkt->data = (void *)((unsigned long)pkt->data + data_offset); |
669c1fc6 | 374 | |
72a2f5bd | 375 | pkt->is_data_pkt = true; |
fceaf24a | 376 | |
1f5f3a75 HZ |
377 | vlan = rndis_get_ppi(rndis_pkt, IEEE_8021Q_INFO); |
378 | if (vlan) { | |
379 | pkt->vlan_tci = VLAN_TAG_PRESENT | vlan->vlanid | | |
380 | (vlan->pri << VLAN_PRIO_SHIFT); | |
381 | } else { | |
382 | pkt->vlan_tci = 0; | |
383 | } | |
384 | ||
a25e1dbe | 385 | netvsc_recv_callback(dev->net_dev->dev, pkt); |
fceaf24a HJ |
386 | } |
387 | ||
5fcc4115 | 388 | int rndis_filter_receive(struct hv_device *dev, |
c2a4efdd | 389 | struct hv_netvsc_packet *pkt) |
fceaf24a | 390 | { |
2ddd5e5f | 391 | struct netvsc_device *net_dev = hv_get_drvdata(dev); |
c2a4efdd | 392 | struct rndis_device *rndis_dev; |
ef31bef6 | 393 | struct rndis_message *rndis_msg; |
2ddd5e5f S |
394 | struct net_device *ndev; |
395 | ||
c2a4efdd | 396 | if (!net_dev) |
8a62d716 BP |
397 | return -EINVAL; |
398 | ||
715a4801 S |
399 | ndev = net_dev->ndev; |
400 | ||
454f18a9 | 401 | /* Make sure the rndis device state is initialized */ |
53d21fdb | 402 | if (!net_dev->extension) { |
d9871158 | 403 | netdev_err(ndev, "got rndis message but no rndis device - " |
eb335bc4 | 404 | "dropping this message!\n"); |
62c0743e | 405 | return -ENODEV; |
fceaf24a HJ |
406 | } |
407 | ||
53d21fdb | 408 | rndis_dev = (struct rndis_device *)net_dev->extension; |
c2a4efdd | 409 | if (rndis_dev->state == RNDIS_DEV_UNINITIALIZED) { |
d9871158 | 410 | netdev_err(ndev, "got rndis message but rndis device " |
eb335bc4 | 411 | "uninitialized...dropping this message!\n"); |
62c0743e | 412 | return -ENODEV; |
fceaf24a HJ |
413 | } |
414 | ||
ef31bef6 | 415 | rndis_msg = pkt->data; |
fceaf24a | 416 | |
ef31bef6 | 417 | dump_rndis_message(dev, rndis_msg); |
fceaf24a | 418 | |
ef31bef6 | 419 | switch (rndis_msg->ndis_msg_type) { |
51491167 | 420 | case RNDIS_MSG_PACKET: |
0120ee0d | 421 | /* data msg */ |
ef31bef6 | 422 | rndis_filter_receive_data(rndis_dev, rndis_msg, pkt); |
fceaf24a HJ |
423 | break; |
424 | ||
51491167 LW |
425 | case RNDIS_MSG_INIT_C: |
426 | case RNDIS_MSG_QUERY_C: | |
427 | case RNDIS_MSG_SET_C: | |
0120ee0d | 428 | /* completion msgs */ |
ef31bef6 | 429 | rndis_filter_receive_response(rndis_dev, rndis_msg); |
fceaf24a HJ |
430 | break; |
431 | ||
51491167 | 432 | case RNDIS_MSG_INDICATE: |
0120ee0d | 433 | /* notification msgs */ |
ef31bef6 | 434 | rndis_filter_receive_indicate_status(rndis_dev, rndis_msg); |
fceaf24a HJ |
435 | break; |
436 | default: | |
d9871158 | 437 | netdev_err(ndev, |
eb335bc4 | 438 | "unhandled rndis message (type %u len %u)\n", |
ef31bef6 HZ |
439 | rndis_msg->ndis_msg_type, |
440 | rndis_msg->msg_len); | |
fceaf24a HJ |
441 | break; |
442 | } | |
443 | ||
fceaf24a HJ |
444 | return 0; |
445 | } | |
446 | ||
9c26aa0d | 447 | static int rndis_filter_query_device(struct rndis_device *dev, u32 oid, |
c2a4efdd | 448 | void *result, u32 *result_size) |
fceaf24a | 449 | { |
e681b954 | 450 | struct rndis_request *request; |
c2a4efdd | 451 | u32 inresult_size = *result_size; |
9f33d054 | 452 | struct rndis_query_request *query; |
c2a4efdd | 453 | struct rndis_query_complete *query_complete; |
0120ee0d | 454 | int ret = 0; |
98d79690 | 455 | int t; |
fceaf24a | 456 | |
c2a4efdd | 457 | if (!result) |
8a62d716 | 458 | return -EINVAL; |
fceaf24a | 459 | |
c2a4efdd | 460 | *result_size = 0; |
51491167 | 461 | request = get_rndis_request(dev, RNDIS_MSG_QUERY, |
0120ee0d GKH |
462 | RNDIS_MESSAGE_SIZE(struct rndis_query_request)); |
463 | if (!request) { | |
de6e0580 | 464 | ret = -ENOMEM; |
1c627870 | 465 | goto cleanup; |
fceaf24a HJ |
466 | } |
467 | ||
454f18a9 | 468 | /* Setup the rndis query */ |
a388eb17 HZ |
469 | query = &request->request_msg.msg.query_req; |
470 | query->oid = oid; | |
471 | query->info_buf_offset = sizeof(struct rndis_query_request); | |
472 | query->info_buflen = 0; | |
473 | query->dev_vc_handle = 0; | |
fceaf24a | 474 | |
9c26aa0d | 475 | ret = rndis_filter_send_request(dev, request); |
fceaf24a | 476 | if (ret != 0) |
1c627870 | 477 | goto cleanup; |
fceaf24a | 478 | |
5c5781b3 | 479 | t = wait_for_completion_timeout(&request->wait_event, 5*HZ); |
98d79690 | 480 | if (t == 0) { |
0c3b7b2f | 481 | ret = -ETIMEDOUT; |
1c627870 | 482 | goto cleanup; |
0c3b7b2f | 483 | } |
fceaf24a | 484 | |
454f18a9 | 485 | /* Copy the response back */ |
a388eb17 | 486 | query_complete = &request->response_msg.msg.query_complete; |
fceaf24a | 487 | |
a388eb17 | 488 | if (query_complete->info_buflen > inresult_size) { |
fceaf24a | 489 | ret = -1; |
1c627870 | 490 | goto cleanup; |
fceaf24a HJ |
491 | } |
492 | ||
c2a4efdd HZ |
493 | memcpy(result, |
494 | (void *)((unsigned long)query_complete + | |
a388eb17 HZ |
495 | query_complete->info_buf_offset), |
496 | query_complete->info_buflen); | |
fceaf24a | 497 | |
a388eb17 | 498 | *result_size = query_complete->info_buflen; |
fceaf24a | 499 | |
1c627870 | 500 | cleanup: |
fceaf24a | 501 | if (request) |
9c26aa0d | 502 | put_rndis_request(dev, request); |
fceaf24a HJ |
503 | |
504 | return ret; | |
505 | } | |
506 | ||
9c26aa0d | 507 | static int rndis_filter_query_device_mac(struct rndis_device *dev) |
fceaf24a | 508 | { |
9f8bd8ba | 509 | u32 size = ETH_ALEN; |
fceaf24a | 510 | |
9c26aa0d | 511 | return rndis_filter_query_device(dev, |
0120ee0d | 512 | RNDIS_OID_802_3_PERMANENT_ADDRESS, |
c2a4efdd | 513 | dev->hw_mac_adr, &size); |
fceaf24a HJ |
514 | } |
515 | ||
1ce09e89 HZ |
516 | #define NWADR_STR "NetworkAddress" |
517 | #define NWADR_STRLEN 14 | |
518 | ||
519 | int rndis_filter_set_device_mac(struct hv_device *hdev, char *mac) | |
520 | { | |
521 | struct netvsc_device *nvdev = hv_get_drvdata(hdev); | |
522 | struct rndis_device *rdev = nvdev->extension; | |
523 | struct net_device *ndev = nvdev->ndev; | |
524 | struct rndis_request *request; | |
525 | struct rndis_set_request *set; | |
526 | struct rndis_config_parameter_info *cpi; | |
527 | wchar_t *cfg_nwadr, *cfg_mac; | |
528 | struct rndis_set_complete *set_complete; | |
529 | char macstr[2*ETH_ALEN+1]; | |
530 | u32 extlen = sizeof(struct rndis_config_parameter_info) + | |
531 | 2*NWADR_STRLEN + 4*ETH_ALEN; | |
532 | int ret, t; | |
533 | ||
534 | request = get_rndis_request(rdev, RNDIS_MSG_SET, | |
535 | RNDIS_MESSAGE_SIZE(struct rndis_set_request) + extlen); | |
536 | if (!request) | |
537 | return -ENOMEM; | |
538 | ||
539 | set = &request->request_msg.msg.set_req; | |
540 | set->oid = RNDIS_OID_GEN_RNDIS_CONFIG_PARAMETER; | |
541 | set->info_buflen = extlen; | |
542 | set->info_buf_offset = sizeof(struct rndis_set_request); | |
543 | set->dev_vc_handle = 0; | |
544 | ||
545 | cpi = (struct rndis_config_parameter_info *)((ulong)set + | |
546 | set->info_buf_offset); | |
547 | cpi->parameter_name_offset = | |
548 | sizeof(struct rndis_config_parameter_info); | |
549 | /* Multiply by 2 because host needs 2 bytes (utf16) for each char */ | |
550 | cpi->parameter_name_length = 2*NWADR_STRLEN; | |
551 | cpi->parameter_type = RNDIS_CONFIG_PARAM_TYPE_STRING; | |
552 | cpi->parameter_value_offset = | |
553 | cpi->parameter_name_offset + cpi->parameter_name_length; | |
554 | /* Multiply by 4 because each MAC byte displayed as 2 utf16 chars */ | |
555 | cpi->parameter_value_length = 4*ETH_ALEN; | |
556 | ||
557 | cfg_nwadr = (wchar_t *)((ulong)cpi + cpi->parameter_name_offset); | |
558 | cfg_mac = (wchar_t *)((ulong)cpi + cpi->parameter_value_offset); | |
559 | ret = utf8s_to_utf16s(NWADR_STR, NWADR_STRLEN, UTF16_HOST_ENDIAN, | |
560 | cfg_nwadr, NWADR_STRLEN); | |
561 | if (ret < 0) | |
562 | goto cleanup; | |
563 | snprintf(macstr, 2*ETH_ALEN+1, "%pm", mac); | |
564 | ret = utf8s_to_utf16s(macstr, 2*ETH_ALEN, UTF16_HOST_ENDIAN, | |
565 | cfg_mac, 2*ETH_ALEN); | |
566 | if (ret < 0) | |
567 | goto cleanup; | |
568 | ||
569 | ret = rndis_filter_send_request(rdev, request); | |
570 | if (ret != 0) | |
571 | goto cleanup; | |
572 | ||
573 | t = wait_for_completion_timeout(&request->wait_event, 5*HZ); | |
574 | if (t == 0) { | |
575 | netdev_err(ndev, "timeout before we got a set response...\n"); | |
576 | /* | |
577 | * can't put_rndis_request, since we may still receive a | |
578 | * send-completion. | |
579 | */ | |
580 | return -EBUSY; | |
581 | } else { | |
582 | set_complete = &request->response_msg.msg.set_complete; | |
583 | if (set_complete->status != RNDIS_STATUS_SUCCESS) | |
584 | ret = -EINVAL; | |
585 | } | |
586 | ||
587 | cleanup: | |
588 | put_rndis_request(rdev, request); | |
589 | return ret; | |
590 | } | |
591 | ||
592 | ||
9c26aa0d | 593 | static int rndis_filter_query_device_link_status(struct rndis_device *dev) |
fceaf24a | 594 | { |
0120ee0d | 595 | u32 size = sizeof(u32); |
6f27457b S |
596 | u32 link_status; |
597 | int ret; | |
fceaf24a | 598 | |
6f27457b | 599 | ret = rndis_filter_query_device(dev, |
0120ee0d | 600 | RNDIS_OID_GEN_MEDIA_CONNECT_STATUS, |
6f27457b S |
601 | &link_status, &size); |
602 | dev->link_state = (link_status != 0) ? true : false; | |
603 | ||
604 | return ret; | |
fceaf24a HJ |
605 | } |
606 | ||
d426b2e3 | 607 | int rndis_filter_set_packet_filter(struct rndis_device *dev, u32 new_filter) |
fceaf24a | 608 | { |
e681b954 | 609 | struct rndis_request *request; |
9f33d054 | 610 | struct rndis_set_request *set; |
c2a4efdd | 611 | struct rndis_set_complete *set_complete; |
4d643114 | 612 | u32 status; |
98d79690 | 613 | int ret, t; |
2ddd5e5f S |
614 | struct net_device *ndev; |
615 | ||
616 | ndev = dev->net_dev->ndev; | |
fceaf24a | 617 | |
51491167 | 618 | request = get_rndis_request(dev, RNDIS_MSG_SET, |
0120ee0d GKH |
619 | RNDIS_MESSAGE_SIZE(struct rndis_set_request) + |
620 | sizeof(u32)); | |
621 | if (!request) { | |
58ef3977 | 622 | ret = -ENOMEM; |
1c627870 | 623 | goto cleanup; |
fceaf24a HJ |
624 | } |
625 | ||
454f18a9 | 626 | /* Setup the rndis set */ |
a388eb17 HZ |
627 | set = &request->request_msg.msg.set_req; |
628 | set->oid = RNDIS_OID_GEN_CURRENT_PACKET_FILTER; | |
629 | set->info_buflen = sizeof(u32); | |
630 | set->info_buf_offset = sizeof(struct rndis_set_request); | |
fceaf24a | 631 | |
0120ee0d | 632 | memcpy((void *)(unsigned long)set + sizeof(struct rndis_set_request), |
c2a4efdd | 633 | &new_filter, sizeof(u32)); |
fceaf24a | 634 | |
9c26aa0d | 635 | ret = rndis_filter_send_request(dev, request); |
fceaf24a | 636 | if (ret != 0) |
1c627870 | 637 | goto cleanup; |
fceaf24a | 638 | |
5c5781b3 | 639 | t = wait_for_completion_timeout(&request->wait_event, 5*HZ); |
98d79690 S |
640 | |
641 | if (t == 0) { | |
d9871158 | 642 | netdev_err(ndev, |
eb335bc4 | 643 | "timeout before we got a set response...\n"); |
0120ee0d | 644 | /* |
25985edc | 645 | * We can't deallocate the request since we may still receive a |
0120ee0d GKH |
646 | * send completion for it. |
647 | */ | |
5585d81e | 648 | goto exit; |
0120ee0d | 649 | } else { |
a388eb17 HZ |
650 | set_complete = &request->response_msg.msg.set_complete; |
651 | status = set_complete->status; | |
fceaf24a HJ |
652 | } |
653 | ||
1c627870 | 654 | cleanup: |
fceaf24a | 655 | if (request) |
9c26aa0d | 656 | put_rndis_request(dev, request); |
5585d81e | 657 | exit: |
fceaf24a HJ |
658 | return ret; |
659 | } | |
660 | ||
fceaf24a | 661 | |
9c26aa0d | 662 | static int rndis_filter_init_device(struct rndis_device *dev) |
fceaf24a | 663 | { |
e681b954 | 664 | struct rndis_request *request; |
9f33d054 | 665 | struct rndis_initialize_request *init; |
c2a4efdd | 666 | struct rndis_initialize_complete *init_complete; |
4d643114 | 667 | u32 status; |
98d79690 | 668 | int ret, t; |
fceaf24a | 669 | |
51491167 | 670 | request = get_rndis_request(dev, RNDIS_MSG_INIT, |
0120ee0d GKH |
671 | RNDIS_MESSAGE_SIZE(struct rndis_initialize_request)); |
672 | if (!request) { | |
bc49b926 | 673 | ret = -ENOMEM; |
1c627870 | 674 | goto cleanup; |
fceaf24a HJ |
675 | } |
676 | ||
454f18a9 | 677 | /* Setup the rndis set */ |
a388eb17 HZ |
678 | init = &request->request_msg.msg.init_req; |
679 | init->major_ver = RNDIS_MAJOR_VERSION; | |
680 | init->minor_ver = RNDIS_MINOR_VERSION; | |
0120ee0d | 681 | /* FIXME: Use 1536 - rounded ethernet frame size */ |
a388eb17 | 682 | init->max_xfer_size = 2048; |
fceaf24a | 683 | |
c2a4efdd | 684 | dev->state = RNDIS_DEV_INITIALIZING; |
fceaf24a | 685 | |
9c26aa0d | 686 | ret = rndis_filter_send_request(dev, request); |
0120ee0d | 687 | if (ret != 0) { |
c2a4efdd | 688 | dev->state = RNDIS_DEV_UNINITIALIZED; |
1c627870 | 689 | goto cleanup; |
fceaf24a HJ |
690 | } |
691 | ||
0c3b7b2f | 692 | |
5c5781b3 | 693 | t = wait_for_completion_timeout(&request->wait_event, 5*HZ); |
98d79690 S |
694 | |
695 | if (t == 0) { | |
0c3b7b2f | 696 | ret = -ETIMEDOUT; |
1c627870 | 697 | goto cleanup; |
0c3b7b2f | 698 | } |
fceaf24a | 699 | |
a388eb17 HZ |
700 | init_complete = &request->response_msg.msg.init_complete; |
701 | status = init_complete->status; | |
0120ee0d | 702 | if (status == RNDIS_STATUS_SUCCESS) { |
c2a4efdd | 703 | dev->state = RNDIS_DEV_INITIALIZED; |
fceaf24a | 704 | ret = 0; |
0120ee0d | 705 | } else { |
c2a4efdd | 706 | dev->state = RNDIS_DEV_UNINITIALIZED; |
bc49b926 | 707 | ret = -EINVAL; |
fceaf24a HJ |
708 | } |
709 | ||
1c627870 | 710 | cleanup: |
fceaf24a | 711 | if (request) |
9c26aa0d | 712 | put_rndis_request(dev, request); |
fceaf24a HJ |
713 | |
714 | return ret; | |
715 | } | |
716 | ||
9c26aa0d | 717 | static void rndis_filter_halt_device(struct rndis_device *dev) |
fceaf24a | 718 | { |
e681b954 | 719 | struct rndis_request *request; |
9f33d054 | 720 | struct rndis_halt_request *halt; |
ae9e63bb HZ |
721 | struct netvsc_device *nvdev = dev->net_dev; |
722 | struct hv_device *hdev = nvdev->dev; | |
723 | ulong flags; | |
fceaf24a | 724 | |
454f18a9 | 725 | /* Attempt to do a rndis device halt */ |
51491167 | 726 | request = get_rndis_request(dev, RNDIS_MSG_HALT, |
0120ee0d | 727 | RNDIS_MESSAGE_SIZE(struct rndis_halt_request)); |
fceaf24a | 728 | if (!request) |
1c627870 | 729 | goto cleanup; |
fceaf24a | 730 | |
454f18a9 | 731 | /* Setup the rndis set */ |
a388eb17 HZ |
732 | halt = &request->request_msg.msg.halt_req; |
733 | halt->req_id = atomic_inc_return(&dev->new_req_id); | |
fceaf24a | 734 | |
454f18a9 | 735 | /* Ignore return since this msg is optional. */ |
9c26aa0d | 736 | rndis_filter_send_request(dev, request); |
fceaf24a | 737 | |
c2a4efdd | 738 | dev->state = RNDIS_DEV_UNINITIALIZED; |
fceaf24a | 739 | |
1c627870 | 740 | cleanup: |
ae9e63bb HZ |
741 | spin_lock_irqsave(&hdev->channel->inbound_lock, flags); |
742 | nvdev->destroy = true; | |
743 | spin_unlock_irqrestore(&hdev->channel->inbound_lock, flags); | |
744 | ||
745 | /* Wait for all send completions */ | |
746 | wait_event(nvdev->wait_drain, | |
747 | atomic_read(&nvdev->num_outstanding_sends) == 0); | |
748 | ||
fceaf24a | 749 | if (request) |
9c26aa0d | 750 | put_rndis_request(dev, request); |
fceaf24a HJ |
751 | return; |
752 | } | |
753 | ||
9c26aa0d | 754 | static int rndis_filter_open_device(struct rndis_device *dev) |
fceaf24a | 755 | { |
0120ee0d | 756 | int ret; |
fceaf24a | 757 | |
c2a4efdd | 758 | if (dev->state != RNDIS_DEV_INITIALIZED) |
fceaf24a HJ |
759 | return 0; |
760 | ||
9c26aa0d | 761 | ret = rndis_filter_set_packet_filter(dev, |
0120ee0d | 762 | NDIS_PACKET_TYPE_BROADCAST | |
95beae90 | 763 | NDIS_PACKET_TYPE_ALL_MULTICAST | |
0120ee0d | 764 | NDIS_PACKET_TYPE_DIRECTED); |
fceaf24a | 765 | if (ret == 0) |
c2a4efdd | 766 | dev->state = RNDIS_DEV_DATAINITIALIZED; |
fceaf24a | 767 | |
fceaf24a HJ |
768 | return ret; |
769 | } | |
770 | ||
9c26aa0d | 771 | static int rndis_filter_close_device(struct rndis_device *dev) |
fceaf24a HJ |
772 | { |
773 | int ret; | |
774 | ||
c2a4efdd | 775 | if (dev->state != RNDIS_DEV_DATAINITIALIZED) |
fceaf24a HJ |
776 | return 0; |
777 | ||
9c26aa0d | 778 | ret = rndis_filter_set_packet_filter(dev, 0); |
fceaf24a | 779 | if (ret == 0) |
c2a4efdd | 780 | dev->state = RNDIS_DEV_INITIALIZED; |
fceaf24a | 781 | |
fceaf24a HJ |
782 | return ret; |
783 | } | |
784 | ||
bdbad576 | 785 | int rndis_filter_device_add(struct hv_device *dev, |
c2a4efdd | 786 | void *additional_info) |
fceaf24a HJ |
787 | { |
788 | int ret; | |
86c921af | 789 | struct netvsc_device *net_device; |
b13cc345 | 790 | struct rndis_device *rndis_device; |
3c4debad | 791 | struct netvsc_device_info *device_info = additional_info; |
fceaf24a | 792 | |
b13cc345 S |
793 | rndis_device = get_rndis_device(); |
794 | if (!rndis_device) | |
327efbae | 795 | return -ENODEV; |
fceaf24a | 796 | |
0120ee0d GKH |
797 | /* |
798 | * Let the inner driver handle this first to create the netvsc channel | |
799 | * NOTE! Once the channel is created, we may get a receive callback | |
800 | * (RndisFilterOnReceive()) before this call is completed | |
801 | */ | |
ce5bf661 | 802 | ret = netvsc_device_add(dev, additional_info); |
0120ee0d | 803 | if (ret != 0) { |
b13cc345 | 804 | kfree(rndis_device); |
fceaf24a HJ |
805 | return ret; |
806 | } | |
807 | ||
454f18a9 BP |
808 | |
809 | /* Initialize the rndis device */ | |
86c921af | 810 | net_device = hv_get_drvdata(dev); |
fceaf24a | 811 | |
b13cc345 S |
812 | net_device->extension = rndis_device; |
813 | rndis_device->net_dev = net_device; | |
fceaf24a | 814 | |
454f18a9 | 815 | /* Send the rndis initialization message */ |
b13cc345 | 816 | ret = rndis_filter_init_device(rndis_device); |
0120ee0d | 817 | if (ret != 0) { |
5243e7bd HZ |
818 | rndis_filter_device_remove(dev); |
819 | return ret; | |
fceaf24a HJ |
820 | } |
821 | ||
454f18a9 | 822 | /* Get the mac address */ |
b13cc345 | 823 | ret = rndis_filter_query_device_mac(rndis_device); |
0120ee0d | 824 | if (ret != 0) { |
5243e7bd HZ |
825 | rndis_filter_device_remove(dev); |
826 | return ret; | |
fceaf24a HJ |
827 | } |
828 | ||
3c4debad | 829 | memcpy(device_info->mac_adr, rndis_device->hw_mac_adr, ETH_ALEN); |
fceaf24a | 830 | |
b13cc345 | 831 | rndis_filter_query_device_link_status(rndis_device); |
fceaf24a | 832 | |
6f27457b | 833 | device_info->link_state = rndis_device->link_state; |
eb335bc4 | 834 | |
6f27457b | 835 | dev_info(&dev->device, "Device MAC %pM link state %s\n", |
b13cc345 | 836 | rndis_device->hw_mac_adr, |
6f27457b | 837 | device_info->link_state ? "down" : "up"); |
fceaf24a | 838 | |
fceaf24a HJ |
839 | return ret; |
840 | } | |
841 | ||
df06bcff | 842 | void rndis_filter_device_remove(struct hv_device *dev) |
fceaf24a | 843 | { |
2ddd5e5f | 844 | struct netvsc_device *net_dev = hv_get_drvdata(dev); |
53d21fdb | 845 | struct rndis_device *rndis_dev = net_dev->extension; |
fceaf24a | 846 | |
454f18a9 | 847 | /* Halt and release the rndis device */ |
9c26aa0d | 848 | rndis_filter_halt_device(rndis_dev); |
fceaf24a | 849 | |
c2a4efdd | 850 | kfree(rndis_dev); |
53d21fdb | 851 | net_dev->extension = NULL; |
fceaf24a | 852 | |
3fae5c8f | 853 | netvsc_device_remove(dev); |
fceaf24a HJ |
854 | } |
855 | ||
fceaf24a | 856 | |
9c26aa0d | 857 | int rndis_filter_open(struct hv_device *dev) |
fceaf24a | 858 | { |
86c921af | 859 | struct netvsc_device *net_device = hv_get_drvdata(dev); |
fceaf24a | 860 | |
86c921af | 861 | if (!net_device) |
8a62d716 BP |
862 | return -EINVAL; |
863 | ||
86c921af | 864 | return rndis_filter_open_device(net_device->extension); |
fceaf24a HJ |
865 | } |
866 | ||
9c26aa0d | 867 | int rndis_filter_close(struct hv_device *dev) |
fceaf24a | 868 | { |
5fccab3b | 869 | struct netvsc_device *nvdev = hv_get_drvdata(dev); |
fceaf24a | 870 | |
5fccab3b | 871 | if (!nvdev) |
8a62d716 BP |
872 | return -EINVAL; |
873 | ||
5fccab3b | 874 | return rndis_filter_close_device(nvdev->extension); |
fceaf24a HJ |
875 | } |
876 | ||
0652aebc | 877 | int rndis_filter_send(struct hv_device *dev, |
c2a4efdd | 878 | struct hv_netvsc_packet *pkt) |
fceaf24a | 879 | { |
0120ee0d | 880 | int ret; |
5fccab3b HZ |
881 | struct rndis_filter_packet *filter_pkt; |
882 | struct rndis_message *rndis_msg; | |
883 | struct rndis_packet *rndis_pkt; | |
884 | u32 rndis_msg_size; | |
1f5f3a75 | 885 | bool isvlan = pkt->vlan_tci & VLAN_TAG_PRESENT; |
fceaf24a | 886 | |
454f18a9 | 887 | /* Add the rndis header */ |
5fccab3b | 888 | filter_pkt = (struct rndis_filter_packet *)pkt->extension; |
fceaf24a | 889 | |
5fccab3b HZ |
890 | rndis_msg = &filter_pkt->msg; |
891 | rndis_msg_size = RNDIS_MESSAGE_SIZE(struct rndis_packet); | |
1f5f3a75 HZ |
892 | if (isvlan) |
893 | rndis_msg_size += NDIS_VLAN_PPI_SIZE; | |
fceaf24a | 894 | |
51491167 | 895 | rndis_msg->ndis_msg_type = RNDIS_MSG_PACKET; |
5fccab3b HZ |
896 | rndis_msg->msg_len = pkt->total_data_buflen + |
897 | rndis_msg_size; | |
fceaf24a | 898 | |
5fccab3b HZ |
899 | rndis_pkt = &rndis_msg->msg.pkt; |
900 | rndis_pkt->data_offset = sizeof(struct rndis_packet); | |
1f5f3a75 HZ |
901 | if (isvlan) |
902 | rndis_pkt->data_offset += NDIS_VLAN_PPI_SIZE; | |
5fccab3b | 903 | rndis_pkt->data_len = pkt->total_data_buflen; |
fceaf24a | 904 | |
1f5f3a75 HZ |
905 | if (isvlan) { |
906 | struct rndis_per_packet_info *ppi; | |
907 | struct ndis_pkt_8021q_info *vlan; | |
908 | ||
909 | rndis_pkt->per_pkt_info_offset = sizeof(struct rndis_packet); | |
910 | rndis_pkt->per_pkt_info_len = NDIS_VLAN_PPI_SIZE; | |
911 | ||
912 | ppi = (struct rndis_per_packet_info *)((ulong)rndis_pkt + | |
913 | rndis_pkt->per_pkt_info_offset); | |
914 | ppi->size = NDIS_VLAN_PPI_SIZE; | |
915 | ppi->type = IEEE_8021Q_INFO; | |
916 | ppi->ppi_offset = sizeof(struct rndis_per_packet_info); | |
917 | ||
918 | vlan = (struct ndis_pkt_8021q_info *)((ulong)ppi + | |
919 | ppi->ppi_offset); | |
920 | vlan->vlanid = pkt->vlan_tci & VLAN_VID_MASK; | |
921 | vlan->pri = (pkt->vlan_tci & VLAN_PRIO_MASK) >> VLAN_PRIO_SHIFT; | |
922 | } | |
923 | ||
72a2f5bd | 924 | pkt->is_data_pkt = true; |
5fccab3b | 925 | pkt->page_buf[0].pfn = virt_to_phys(rndis_msg) >> PAGE_SHIFT; |
ca623ad3 | 926 | pkt->page_buf[0].offset = |
5fccab3b HZ |
927 | (unsigned long)rndis_msg & (PAGE_SIZE-1); |
928 | pkt->page_buf[0].len = rndis_msg_size; | |
fceaf24a | 929 | |
c31c151b | 930 | /* Add one page_buf if the rndis msg goes beyond page boundary */ |
5fccab3b | 931 | if (pkt->page_buf[0].offset + rndis_msg_size > PAGE_SIZE) { |
c31c151b HZ |
932 | int i; |
933 | for (i = pkt->page_buf_cnt; i > 1; i--) | |
934 | pkt->page_buf[i] = pkt->page_buf[i-1]; | |
935 | pkt->page_buf_cnt++; | |
936 | pkt->page_buf[0].len = PAGE_SIZE - pkt->page_buf[0].offset; | |
937 | pkt->page_buf[1].pfn = virt_to_phys((void *)((ulong) | |
5fccab3b | 938 | rndis_msg + pkt->page_buf[0].len)) >> PAGE_SHIFT; |
c31c151b | 939 | pkt->page_buf[1].offset = 0; |
5fccab3b | 940 | pkt->page_buf[1].len = rndis_msg_size - pkt->page_buf[0].len; |
c31c151b HZ |
941 | } |
942 | ||
454f18a9 | 943 | /* Save the packet send completion and context */ |
5fccab3b HZ |
944 | filter_pkt->completion = pkt->completion.send.send_completion; |
945 | filter_pkt->completion_ctx = | |
72a2f5bd | 946 | pkt->completion.send.send_completion_ctx; |
fceaf24a | 947 | |
454f18a9 | 948 | /* Use ours */ |
72a2f5bd | 949 | pkt->completion.send.send_completion = rndis_filter_send_completion; |
5fccab3b | 950 | pkt->completion.send.send_completion_ctx = filter_pkt; |
fceaf24a | 951 | |
0ec6ff40 | 952 | ret = netvsc_send(dev, pkt); |
0120ee0d GKH |
953 | if (ret != 0) { |
954 | /* | |
955 | * Reset the completion to originals to allow retries from | |
956 | * above | |
957 | */ | |
72a2f5bd | 958 | pkt->completion.send.send_completion = |
5fccab3b | 959 | filter_pkt->completion; |
72a2f5bd | 960 | pkt->completion.send.send_completion_ctx = |
5fccab3b | 961 | filter_pkt->completion_ctx; |
fceaf24a HJ |
962 | } |
963 | ||
fceaf24a HJ |
964 | return ret; |
965 | } | |
966 | ||
9c26aa0d | 967 | static void rndis_filter_send_completion(void *ctx) |
fceaf24a | 968 | { |
5fccab3b | 969 | struct rndis_filter_packet *filter_pkt = ctx; |
fceaf24a | 970 | |
454f18a9 | 971 | /* Pass it back to the original handler */ |
5fccab3b | 972 | filter_pkt->completion(filter_pkt->completion_ctx); |
fceaf24a HJ |
973 | } |
974 | ||
975 | ||
9c26aa0d | 976 | static void rndis_filter_send_request_completion(void *ctx) |
fceaf24a | 977 | { |
454f18a9 | 978 | /* Noop */ |
fceaf24a | 979 | } |