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