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