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