]>
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> |
d6472302 | 30 | #include <linux/vmalloc.h> |
27f5aa92 | 31 | #include <linux/rtnetlink.h> |
3f335ea2 | 32 | |
5ca7252a | 33 | #include "hyperv_net.h" |
fceaf24a | 34 | |
4f19c0d8 | 35 | static void rndis_set_multicast(struct work_struct *w); |
fceaf24a | 36 | |
5b54dac8 | 37 | #define RNDIS_EXT_LEN PAGE_SIZE |
e681b954 | 38 | struct rndis_request { |
c2a4efdd | 39 | struct list_head list_ent; |
98d79690 | 40 | struct completion wait_event; |
fceaf24a | 41 | |
a3a6cab5 | 42 | struct rndis_message response_msg; |
0120ee0d | 43 | /* |
a3a6cab5 HZ |
44 | * The buffer for extended info after the RNDIS response message. It's |
45 | * referenced based on the data offset in the RNDIS message. Its size | |
46 | * is enough for current needs, and should be sufficient for the near | |
47 | * future. | |
0120ee0d | 48 | */ |
a3a6cab5 | 49 | u8 response_ext[RNDIS_EXT_LEN]; |
fceaf24a | 50 | |
454f18a9 | 51 | /* Simplify allocation by having a netvsc packet inline */ |
c2a4efdd | 52 | struct hv_netvsc_packet pkt; |
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 | |
962f3fee | 62 | static const u8 netvsc_hash_key[NETVSC_HASH_KEYLEN] = { |
63 | 0x6d, 0x5a, 0x56, 0xda, 0x25, 0x5b, 0x0e, 0xc2, | |
64 | 0x41, 0x67, 0x25, 0x3d, 0x43, 0xa3, 0x8f, 0xb0, | |
65 | 0xd0, 0xca, 0x2b, 0xcb, 0xae, 0x7b, 0x30, 0xb4, | |
66 | 0x77, 0xcb, 0x2d, 0xa3, 0x80, 0x30, 0xf2, 0x0c, | |
67 | 0x6a, 0x42, 0xb7, 0x3b, 0xbe, 0xac, 0x01, 0xfa | |
68 | }; | |
69 | ||
9c26aa0d | 70 | static struct rndis_device *get_rndis_device(void) |
fceaf24a | 71 | { |
e681b954 | 72 | struct rndis_device *device; |
fceaf24a | 73 | |
e681b954 | 74 | device = kzalloc(sizeof(struct rndis_device), GFP_KERNEL); |
fceaf24a | 75 | if (!device) |
fceaf24a | 76 | return NULL; |
fceaf24a | 77 | |
880fb89c | 78 | spin_lock_init(&device->request_lock); |
fceaf24a | 79 | |
c2a4efdd | 80 | INIT_LIST_HEAD(&device->req_list); |
4f19c0d8 | 81 | INIT_WORK(&device->mcast_work, rndis_set_multicast); |
fceaf24a | 82 | |
c2a4efdd | 83 | device->state = RNDIS_DEV_UNINITIALIZED; |
fceaf24a HJ |
84 | |
85 | return device; | |
86 | } | |
87 | ||
9c26aa0d | 88 | static struct rndis_request *get_rndis_request(struct rndis_device *dev, |
c2a4efdd HZ |
89 | u32 msg_type, |
90 | u32 msg_len) | |
fceaf24a | 91 | { |
e681b954 | 92 | struct rndis_request *request; |
c2a4efdd | 93 | struct rndis_message *rndis_msg; |
9f33d054 | 94 | struct rndis_set_request *set; |
880fb89c | 95 | unsigned long flags; |
fceaf24a | 96 | |
e681b954 | 97 | request = kzalloc(sizeof(struct rndis_request), GFP_KERNEL); |
fceaf24a | 98 | if (!request) |
fceaf24a | 99 | return NULL; |
fceaf24a | 100 | |
98d79690 | 101 | init_completion(&request->wait_event); |
fceaf24a | 102 | |
c2a4efdd | 103 | rndis_msg = &request->request_msg; |
a388eb17 HZ |
104 | rndis_msg->ndis_msg_type = msg_type; |
105 | rndis_msg->msg_len = msg_len; | |
fceaf24a | 106 | |
5b54dac8 HZ |
107 | request->pkt.q_idx = 0; |
108 | ||
0120ee0d GKH |
109 | /* |
110 | * Set the request id. This field is always after the rndis header for | |
111 | * request/response packet types so we just used the SetRequest as a | |
112 | * template | |
113 | */ | |
a388eb17 HZ |
114 | set = &rndis_msg->msg.set_req; |
115 | set->req_id = atomic_inc_return(&dev->new_req_id); | |
fceaf24a | 116 | |
454f18a9 | 117 | /* Add to the request list */ |
c2a4efdd HZ |
118 | spin_lock_irqsave(&dev->request_lock, flags); |
119 | list_add_tail(&request->list_ent, &dev->req_list); | |
120 | spin_unlock_irqrestore(&dev->request_lock, flags); | |
fceaf24a HJ |
121 | |
122 | return request; | |
123 | } | |
124 | ||
9c26aa0d | 125 | static void put_rndis_request(struct rndis_device *dev, |
c2a4efdd | 126 | struct rndis_request *req) |
fceaf24a | 127 | { |
880fb89c GKH |
128 | unsigned long flags; |
129 | ||
c2a4efdd HZ |
130 | spin_lock_irqsave(&dev->request_lock, flags); |
131 | list_del(&req->list_ent); | |
132 | spin_unlock_irqrestore(&dev->request_lock, flags); | |
fceaf24a | 133 | |
c2a4efdd | 134 | kfree(req); |
fceaf24a HJ |
135 | } |
136 | ||
729a2849 | 137 | static void dump_rndis_message(struct hv_device *hv_dev, |
dc54a08c | 138 | const struct rndis_message *rndis_msg) |
fceaf24a | 139 | { |
3d541ac5 | 140 | struct net_device *netdev = hv_get_drvdata(hv_dev); |
729a2849 | 141 | |
a388eb17 | 142 | switch (rndis_msg->ndis_msg_type) { |
51491167 LW |
143 | case RNDIS_MSG_PACKET: |
144 | netdev_dbg(netdev, "RNDIS_MSG_PACKET (len %u, " | |
0120ee0d GKH |
145 | "data offset %u data len %u, # oob %u, " |
146 | "oob offset %u, oob len %u, pkt offset %u, " | |
729a2849 | 147 | "pkt len %u\n", |
a388eb17 HZ |
148 | rndis_msg->msg_len, |
149 | rndis_msg->msg.pkt.data_offset, | |
150 | rndis_msg->msg.pkt.data_len, | |
151 | rndis_msg->msg.pkt.num_oob_data_elements, | |
152 | rndis_msg->msg.pkt.oob_data_offset, | |
153 | rndis_msg->msg.pkt.oob_data_len, | |
154 | rndis_msg->msg.pkt.per_pkt_info_offset, | |
155 | rndis_msg->msg.pkt.per_pkt_info_len); | |
fceaf24a HJ |
156 | break; |
157 | ||
51491167 LW |
158 | case RNDIS_MSG_INIT_C: |
159 | netdev_dbg(netdev, "RNDIS_MSG_INIT_C " | |
0120ee0d GKH |
160 | "(len %u, id 0x%x, status 0x%x, major %d, minor %d, " |
161 | "device flags %d, max xfer size 0x%x, max pkts %u, " | |
729a2849 | 162 | "pkt aligned %u)\n", |
a388eb17 HZ |
163 | rndis_msg->msg_len, |
164 | rndis_msg->msg.init_complete.req_id, | |
165 | rndis_msg->msg.init_complete.status, | |
166 | rndis_msg->msg.init_complete.major_ver, | |
167 | rndis_msg->msg.init_complete.minor_ver, | |
168 | rndis_msg->msg.init_complete.dev_flags, | |
169 | rndis_msg->msg.init_complete.max_xfer_size, | |
170 | rndis_msg->msg.init_complete. | |
171 | max_pkt_per_msg, | |
172 | rndis_msg->msg.init_complete. | |
173 | pkt_alignment_factor); | |
fceaf24a HJ |
174 | break; |
175 | ||
51491167 LW |
176 | case RNDIS_MSG_QUERY_C: |
177 | netdev_dbg(netdev, "RNDIS_MSG_QUERY_C " | |
0120ee0d | 178 | "(len %u, id 0x%x, status 0x%x, buf len %u, " |
729a2849 | 179 | "buf offset %u)\n", |
a388eb17 HZ |
180 | rndis_msg->msg_len, |
181 | rndis_msg->msg.query_complete.req_id, | |
182 | rndis_msg->msg.query_complete.status, | |
183 | rndis_msg->msg.query_complete. | |
184 | info_buflen, | |
185 | rndis_msg->msg.query_complete. | |
186 | info_buf_offset); | |
fceaf24a HJ |
187 | break; |
188 | ||
51491167 | 189 | case RNDIS_MSG_SET_C: |
729a2849 | 190 | netdev_dbg(netdev, |
51491167 | 191 | "RNDIS_MSG_SET_C (len %u, id 0x%x, status 0x%x)\n", |
a388eb17 HZ |
192 | rndis_msg->msg_len, |
193 | rndis_msg->msg.set_complete.req_id, | |
194 | rndis_msg->msg.set_complete.status); | |
fceaf24a HJ |
195 | break; |
196 | ||
51491167 LW |
197 | case RNDIS_MSG_INDICATE: |
198 | netdev_dbg(netdev, "RNDIS_MSG_INDICATE " | |
729a2849 | 199 | "(len %u, status 0x%x, buf len %u, buf offset %u)\n", |
a388eb17 HZ |
200 | rndis_msg->msg_len, |
201 | rndis_msg->msg.indicate_status.status, | |
202 | rndis_msg->msg.indicate_status.status_buflen, | |
203 | rndis_msg->msg.indicate_status.status_buf_offset); | |
fceaf24a HJ |
204 | break; |
205 | ||
206 | default: | |
729a2849 | 207 | netdev_dbg(netdev, "0x%x (len %u)\n", |
a388eb17 HZ |
208 | rndis_msg->ndis_msg_type, |
209 | rndis_msg->msg_len); | |
fceaf24a HJ |
210 | break; |
211 | } | |
212 | } | |
213 | ||
9c26aa0d | 214 | static int rndis_filter_send_request(struct rndis_device *dev, |
c2a4efdd | 215 | struct rndis_request *req) |
fceaf24a | 216 | { |
4193d4f4 | 217 | struct hv_netvsc_packet *packet; |
b08cc791 | 218 | struct hv_page_buffer page_buf[2]; |
a9f2e2d6 | 219 | struct hv_page_buffer *pb = page_buf; |
02b6de01 | 220 | int ret; |
fceaf24a | 221 | |
454f18a9 | 222 | /* Setup the packet to send it */ |
c2a4efdd | 223 | packet = &req->pkt; |
fceaf24a | 224 | |
a388eb17 | 225 | packet->total_data_buflen = req->request_msg.msg_len; |
72a2f5bd | 226 | packet->page_buf_cnt = 1; |
fceaf24a | 227 | |
a9f2e2d6 | 228 | pb[0].pfn = virt_to_phys(&req->request_msg) >> |
0120ee0d | 229 | PAGE_SHIFT; |
a9f2e2d6 KS |
230 | pb[0].len = req->request_msg.msg_len; |
231 | pb[0].offset = | |
c2a4efdd | 232 | (unsigned long)&req->request_msg & (PAGE_SIZE - 1); |
fceaf24a | 233 | |
99e3fcfa | 234 | /* Add one page_buf when request_msg crossing page boundary */ |
a9f2e2d6 | 235 | if (pb[0].offset + pb[0].len > PAGE_SIZE) { |
99e3fcfa | 236 | packet->page_buf_cnt++; |
a9f2e2d6 KS |
237 | pb[0].len = PAGE_SIZE - |
238 | pb[0].offset; | |
239 | pb[1].pfn = virt_to_phys((void *)&req->request_msg | |
240 | + pb[0].len) >> PAGE_SHIFT; | |
241 | pb[1].offset = 0; | |
242 | pb[1].len = req->request_msg.msg_len - | |
243 | pb[0].len; | |
99e3fcfa HZ |
244 | } |
245 | ||
867047c4 | 246 | rcu_read_lock_bh(); |
706b71d5 | 247 | ret = netvsc_send(dev->ndev, packet, NULL, pb, NULL); |
867047c4 | 248 | rcu_read_unlock_bh(); |
249 | ||
fceaf24a HJ |
250 | return ret; |
251 | } | |
252 | ||
1b07da51 HZ |
253 | static void rndis_set_link_state(struct rndis_device *rdev, |
254 | struct rndis_request *request) | |
255 | { | |
256 | u32 link_status; | |
257 | struct rndis_query_complete *query_complete; | |
258 | ||
259 | query_complete = &request->response_msg.msg.query_complete; | |
260 | ||
261 | if (query_complete->status == RNDIS_STATUS_SUCCESS && | |
262 | query_complete->info_buflen == sizeof(u32)) { | |
263 | memcpy(&link_status, (void *)((unsigned long)query_complete + | |
264 | query_complete->info_buf_offset), sizeof(u32)); | |
265 | rdev->link_state = link_status != 0; | |
266 | } | |
267 | } | |
268 | ||
592de81e SH |
269 | static void rndis_filter_receive_response(struct net_device *ndev, |
270 | struct netvsc_device *nvdev, | |
271 | const struct rndis_message *resp) | |
fceaf24a | 272 | { |
592de81e | 273 | struct rndis_device *dev = nvdev->extension; |
e681b954 | 274 | struct rndis_request *request = NULL; |
0e727613 | 275 | bool found = false; |
880fb89c | 276 | unsigned long flags; |
592de81e SH |
277 | |
278 | /* This should never happen, it means control message | |
279 | * response received after device removed. | |
280 | */ | |
281 | if (dev->state == RNDIS_DEV_UNINITIALIZED) { | |
282 | netdev_err(ndev, | |
283 | "got rndis message uninitialized\n"); | |
284 | return; | |
285 | } | |
fceaf24a | 286 | |
c2a4efdd HZ |
287 | spin_lock_irqsave(&dev->request_lock, flags); |
288 | list_for_each_entry(request, &dev->req_list, list_ent) { | |
0120ee0d GKH |
289 | /* |
290 | * All request/response message contains RequestId as the 1st | |
291 | * field | |
292 | */ | |
a388eb17 HZ |
293 | if (request->request_msg.msg.init_req.req_id |
294 | == resp->msg.init_complete.req_id) { | |
0e727613 | 295 | found = true; |
fceaf24a HJ |
296 | break; |
297 | } | |
298 | } | |
c2a4efdd | 299 | spin_unlock_irqrestore(&dev->request_lock, flags); |
fceaf24a | 300 | |
0120ee0d | 301 | if (found) { |
a3a6cab5 HZ |
302 | if (resp->msg_len <= |
303 | sizeof(struct rndis_message) + RNDIS_EXT_LEN) { | |
c2a4efdd | 304 | memcpy(&request->response_msg, resp, |
a388eb17 | 305 | resp->msg_len); |
1b07da51 HZ |
306 | if (request->request_msg.ndis_msg_type == |
307 | RNDIS_MSG_QUERY && request->request_msg.msg. | |
308 | query_req.oid == RNDIS_OID_GEN_MEDIA_CONNECT_STATUS) | |
309 | rndis_set_link_state(dev, request); | |
0120ee0d | 310 | } else { |
d9871158 | 311 | netdev_err(ndev, |
eb335bc4 HJ |
312 | "rndis response buffer overflow " |
313 | "detected (size %u max %zu)\n", | |
314 | resp->msg_len, | |
86eedacc | 315 | sizeof(struct rndis_message)); |
0120ee0d | 316 | |
a388eb17 | 317 | if (resp->ndis_msg_type == |
51491167 | 318 | RNDIS_MSG_RESET_C) { |
0120ee0d | 319 | /* does not have a request id field */ |
a388eb17 | 320 | request->response_msg.msg.reset_complete. |
007e5c8e | 321 | status = RNDIS_STATUS_BUFFER_OVERFLOW; |
0120ee0d | 322 | } else { |
a388eb17 HZ |
323 | request->response_msg.msg. |
324 | init_complete.status = | |
007e5c8e | 325 | RNDIS_STATUS_BUFFER_OVERFLOW; |
fceaf24a HJ |
326 | } |
327 | } | |
328 | ||
98d79690 | 329 | complete(&request->wait_event); |
0120ee0d | 330 | } else { |
d9871158 | 331 | netdev_err(ndev, |
eb335bc4 HJ |
332 | "no rndis request found for this response " |
333 | "(id 0x%x res type 0x%x)\n", | |
334 | resp->msg.init_complete.req_id, | |
335 | resp->ndis_msg_type); | |
fceaf24a | 336 | } |
fceaf24a HJ |
337 | } |
338 | ||
1f5f3a75 HZ |
339 | /* |
340 | * Get the Per-Packet-Info with the specified type | |
341 | * return NULL if not found. | |
342 | */ | |
343 | static inline void *rndis_get_ppi(struct rndis_packet *rpkt, u32 type) | |
344 | { | |
345 | struct rndis_per_packet_info *ppi; | |
346 | int len; | |
347 | ||
348 | if (rpkt->per_pkt_info_offset == 0) | |
349 | return NULL; | |
350 | ||
351 | ppi = (struct rndis_per_packet_info *)((ulong)rpkt + | |
352 | rpkt->per_pkt_info_offset); | |
353 | len = rpkt->per_pkt_info_len; | |
354 | ||
355 | while (len > 0) { | |
356 | if (ppi->type == type) | |
357 | return (void *)((ulong)ppi + ppi->ppi_offset); | |
358 | len -= ppi->size; | |
359 | ppi = (struct rndis_per_packet_info *)((ulong)ppi + ppi->size); | |
360 | } | |
361 | ||
362 | return NULL; | |
363 | } | |
364 | ||
dc54a08c | 365 | static int rndis_filter_receive_data(struct net_device *ndev, |
592de81e | 366 | struct netvsc_device *nvdev, |
dc54a08c | 367 | struct rndis_message *msg, |
368 | struct vmbus_channel *channel, | |
369 | void *data, u32 data_buflen) | |
fceaf24a | 370 | { |
dc54a08c | 371 | struct rndis_packet *rndis_pkt = &msg->msg.pkt; |
372 | const struct ndis_tcp_ip_checksum_info *csum_info; | |
373 | const struct ndis_pkt_8021q_info *vlan; | |
c2a4efdd | 374 | u32 data_offset; |
fceaf24a | 375 | |
454f18a9 | 376 | /* Remove the rndis header and pass it back up the stack */ |
a388eb17 | 377 | data_offset = RNDIS_HEADER_SIZE + rndis_pkt->data_offset; |
fceaf24a | 378 | |
dc54a08c | 379 | data_buflen -= data_offset; |
4b8a8bc9 WY |
380 | |
381 | /* | |
382 | * Make sure we got a valid RNDIS message, now total_data_buflen | |
383 | * should be the data packet size plus the trailer padding size | |
384 | */ | |
dc54a08c | 385 | if (unlikely(data_buflen < rndis_pkt->data_len)) { |
592de81e | 386 | netdev_err(ndev, "rndis message buffer " |
4b8a8bc9 WY |
387 | "overflow detected (got %u, min %u)" |
388 | "...dropping this message!\n", | |
dc54a08c | 389 | data_buflen, rndis_pkt->data_len); |
10082f98 | 390 | return NVSP_STAT_FAIL; |
4b8a8bc9 WY |
391 | } |
392 | ||
dc54a08c | 393 | vlan = rndis_get_ppi(rndis_pkt, IEEE_8021Q_INFO); |
394 | ||
4b8a8bc9 WY |
395 | /* |
396 | * Remove the rndis trailer padding from rndis packet message | |
397 | * rndis_pkt->data_len tell us the real data length, we only copy | |
398 | * the data packet to the stack, without the rndis trailer padding | |
399 | */ | |
dc54a08c | 400 | data = (void *)((unsigned long)data + data_offset); |
e3d605ed | 401 | csum_info = rndis_get_ppi(rndis_pkt, TCPIP_CHKSUM_PKTINFO); |
dc54a08c | 402 | return netvsc_recv_callback(ndev, channel, |
403 | data, rndis_pkt->data_len, | |
404 | csum_info, vlan); | |
fceaf24a HJ |
405 | } |
406 | ||
dc54a08c | 407 | int rndis_filter_receive(struct net_device *ndev, |
408 | struct netvsc_device *net_dev, | |
409 | struct hv_device *dev, | |
410 | struct vmbus_channel *channel, | |
411 | void *data, u32 buflen) | |
fceaf24a | 412 | { |
3d541ac5 | 413 | struct net_device_context *net_device_ctx = netdev_priv(ndev); |
dc54a08c | 414 | struct rndis_message *rndis_msg = data; |
8a62d716 | 415 | |
dc54a08c | 416 | if (netif_msg_rx_status(net_device_ctx)) |
3f300ff4 | 417 | dump_rndis_message(dev, rndis_msg); |
fceaf24a | 418 | |
ef31bef6 | 419 | switch (rndis_msg->ndis_msg_type) { |
51491167 | 420 | case RNDIS_MSG_PACKET: |
592de81e | 421 | return rndis_filter_receive_data(ndev, net_dev, rndis_msg, |
dc54a08c | 422 | channel, data, buflen); |
51491167 LW |
423 | case RNDIS_MSG_INIT_C: |
424 | case RNDIS_MSG_QUERY_C: | |
425 | case RNDIS_MSG_SET_C: | |
0120ee0d | 426 | /* completion msgs */ |
592de81e | 427 | rndis_filter_receive_response(ndev, net_dev, rndis_msg); |
fceaf24a HJ |
428 | break; |
429 | ||
51491167 | 430 | case RNDIS_MSG_INDICATE: |
0120ee0d | 431 | /* notification msgs */ |
3a494e71 | 432 | netvsc_linkstatus_callback(dev, rndis_msg); |
fceaf24a HJ |
433 | break; |
434 | default: | |
d9871158 | 435 | netdev_err(ndev, |
eb335bc4 | 436 | "unhandled rndis message (type %u len %u)\n", |
ef31bef6 HZ |
437 | rndis_msg->ndis_msg_type, |
438 | rndis_msg->msg_len); | |
8139bb20 | 439 | return NVSP_STAT_FAIL; |
fceaf24a HJ |
440 | } |
441 | ||
8139bb20 | 442 | return NVSP_STAT_SUCCESS; |
fceaf24a HJ |
443 | } |
444 | ||
867047c4 | 445 | static int rndis_filter_query_device(struct rndis_device *dev, |
446 | struct netvsc_device *nvdev, | |
447 | u32 oid, void *result, u32 *result_size) | |
fceaf24a | 448 | { |
e681b954 | 449 | struct rndis_request *request; |
c2a4efdd | 450 | u32 inresult_size = *result_size; |
9f33d054 | 451 | struct rndis_query_request *query; |
c2a4efdd | 452 | struct rndis_query_complete *query_complete; |
0120ee0d | 453 | int ret = 0; |
fceaf24a | 454 | |
c2a4efdd | 455 | if (!result) |
8a62d716 | 456 | return -EINVAL; |
fceaf24a | 457 | |
c2a4efdd | 458 | *result_size = 0; |
51491167 | 459 | request = get_rndis_request(dev, RNDIS_MSG_QUERY, |
0120ee0d GKH |
460 | RNDIS_MESSAGE_SIZE(struct rndis_query_request)); |
461 | if (!request) { | |
de6e0580 | 462 | ret = -ENOMEM; |
1c627870 | 463 | goto cleanup; |
fceaf24a HJ |
464 | } |
465 | ||
454f18a9 | 466 | /* Setup the rndis query */ |
a388eb17 HZ |
467 | query = &request->request_msg.msg.query_req; |
468 | query->oid = oid; | |
469 | query->info_buf_offset = sizeof(struct rndis_query_request); | |
470 | query->info_buflen = 0; | |
471 | query->dev_vc_handle = 0; | |
fceaf24a | 472 | |
23312a3b | 473 | if (oid == OID_TCP_OFFLOAD_HARDWARE_CAPABILITIES) { |
23312a3b | 474 | struct ndis_offload *hwcaps; |
475 | u32 nvsp_version = nvdev->nvsp_version; | |
476 | u8 ndis_rev; | |
477 | size_t size; | |
478 | ||
479 | if (nvsp_version >= NVSP_PROTOCOL_VERSION_5) { | |
480 | ndis_rev = NDIS_OFFLOAD_PARAMETERS_REVISION_3; | |
481 | size = NDIS_OFFLOAD_SIZE; | |
482 | } else if (nvsp_version >= NVSP_PROTOCOL_VERSION_4) { | |
483 | ndis_rev = NDIS_OFFLOAD_PARAMETERS_REVISION_2; | |
484 | size = NDIS_OFFLOAD_SIZE_6_1; | |
485 | } else { | |
486 | ndis_rev = NDIS_OFFLOAD_PARAMETERS_REVISION_1; | |
487 | size = NDIS_OFFLOAD_SIZE_6_0; | |
488 | } | |
489 | ||
490 | request->request_msg.msg_len += size; | |
491 | query->info_buflen = size; | |
492 | hwcaps = (struct ndis_offload *) | |
493 | ((unsigned long)query + query->info_buf_offset); | |
494 | ||
495 | hwcaps->header.type = NDIS_OBJECT_TYPE_OFFLOAD; | |
496 | hwcaps->header.revision = ndis_rev; | |
497 | hwcaps->header.size = size; | |
498 | ||
499 | } else if (oid == OID_GEN_RECEIVE_SCALE_CAPABILITIES) { | |
5b54dac8 HZ |
500 | struct ndis_recv_scale_cap *cap; |
501 | ||
502 | request->request_msg.msg_len += | |
503 | sizeof(struct ndis_recv_scale_cap); | |
504 | query->info_buflen = sizeof(struct ndis_recv_scale_cap); | |
505 | cap = (struct ndis_recv_scale_cap *)((unsigned long)query + | |
506 | query->info_buf_offset); | |
507 | cap->hdr.type = NDIS_OBJECT_TYPE_RSS_CAPABILITIES; | |
508 | cap->hdr.rev = NDIS_RECEIVE_SCALE_CAPABILITIES_REVISION_2; | |
509 | cap->hdr.size = sizeof(struct ndis_recv_scale_cap); | |
510 | } | |
511 | ||
9c26aa0d | 512 | ret = rndis_filter_send_request(dev, request); |
fceaf24a | 513 | if (ret != 0) |
1c627870 | 514 | goto cleanup; |
fceaf24a | 515 | |
5362855a | 516 | wait_for_completion(&request->wait_event); |
fceaf24a | 517 | |
454f18a9 | 518 | /* Copy the response back */ |
a388eb17 | 519 | query_complete = &request->response_msg.msg.query_complete; |
fceaf24a | 520 | |
a388eb17 | 521 | if (query_complete->info_buflen > inresult_size) { |
fceaf24a | 522 | ret = -1; |
1c627870 | 523 | goto cleanup; |
fceaf24a HJ |
524 | } |
525 | ||
c2a4efdd HZ |
526 | memcpy(result, |
527 | (void *)((unsigned long)query_complete + | |
a388eb17 HZ |
528 | query_complete->info_buf_offset), |
529 | query_complete->info_buflen); | |
fceaf24a | 530 | |
a388eb17 | 531 | *result_size = query_complete->info_buflen; |
fceaf24a | 532 | |
1c627870 | 533 | cleanup: |
fceaf24a | 534 | if (request) |
9c26aa0d | 535 | put_rndis_request(dev, request); |
fceaf24a HJ |
536 | |
537 | return ret; | |
538 | } | |
539 | ||
23312a3b | 540 | /* Get the hardware offload capabilities */ |
541 | static int | |
867047c4 | 542 | rndis_query_hwcaps(struct rndis_device *dev, struct netvsc_device *net_device, |
543 | struct ndis_offload *caps) | |
23312a3b | 544 | { |
545 | u32 caps_len = sizeof(*caps); | |
546 | int ret; | |
547 | ||
548 | memset(caps, 0, sizeof(*caps)); | |
549 | ||
867047c4 | 550 | ret = rndis_filter_query_device(dev, net_device, |
23312a3b | 551 | OID_TCP_OFFLOAD_HARDWARE_CAPABILITIES, |
552 | caps, &caps_len); | |
553 | if (ret) | |
554 | return ret; | |
555 | ||
556 | if (caps->header.type != NDIS_OBJECT_TYPE_OFFLOAD) { | |
557 | netdev_warn(dev->ndev, "invalid NDIS objtype %#x\n", | |
558 | caps->header.type); | |
559 | return -EINVAL; | |
560 | } | |
561 | ||
562 | if (caps->header.revision < NDIS_OFFLOAD_PARAMETERS_REVISION_1) { | |
563 | netdev_warn(dev->ndev, "invalid NDIS objrev %x\n", | |
564 | caps->header.revision); | |
565 | return -EINVAL; | |
566 | } | |
567 | ||
568 | if (caps->header.size > caps_len || | |
569 | caps->header.size < NDIS_OFFLOAD_SIZE_6_0) { | |
570 | netdev_warn(dev->ndev, | |
571 | "invalid NDIS objsize %u, data size %u\n", | |
572 | caps->header.size, caps_len); | |
573 | return -EINVAL; | |
574 | } | |
575 | ||
576 | return 0; | |
577 | } | |
578 | ||
867047c4 | 579 | static int rndis_filter_query_device_mac(struct rndis_device *dev, |
580 | struct netvsc_device *net_device) | |
fceaf24a | 581 | { |
9f8bd8ba | 582 | u32 size = ETH_ALEN; |
fceaf24a | 583 | |
867047c4 | 584 | return rndis_filter_query_device(dev, net_device, |
0120ee0d | 585 | RNDIS_OID_802_3_PERMANENT_ADDRESS, |
c2a4efdd | 586 | dev->hw_mac_adr, &size); |
fceaf24a HJ |
587 | } |
588 | ||
1ce09e89 HZ |
589 | #define NWADR_STR "NetworkAddress" |
590 | #define NWADR_STRLEN 14 | |
591 | ||
867047c4 | 592 | int rndis_filter_set_device_mac(struct netvsc_device *nvdev, |
593 | const char *mac) | |
1ce09e89 | 594 | { |
1ce09e89 | 595 | struct rndis_device *rdev = nvdev->extension; |
1ce09e89 HZ |
596 | struct rndis_request *request; |
597 | struct rndis_set_request *set; | |
598 | struct rndis_config_parameter_info *cpi; | |
599 | wchar_t *cfg_nwadr, *cfg_mac; | |
600 | struct rndis_set_complete *set_complete; | |
601 | char macstr[2*ETH_ALEN+1]; | |
602 | u32 extlen = sizeof(struct rndis_config_parameter_info) + | |
603 | 2*NWADR_STRLEN + 4*ETH_ALEN; | |
999028cc | 604 | int ret; |
1ce09e89 HZ |
605 | |
606 | request = get_rndis_request(rdev, RNDIS_MSG_SET, | |
607 | RNDIS_MESSAGE_SIZE(struct rndis_set_request) + extlen); | |
608 | if (!request) | |
609 | return -ENOMEM; | |
610 | ||
611 | set = &request->request_msg.msg.set_req; | |
612 | set->oid = RNDIS_OID_GEN_RNDIS_CONFIG_PARAMETER; | |
613 | set->info_buflen = extlen; | |
614 | set->info_buf_offset = sizeof(struct rndis_set_request); | |
615 | set->dev_vc_handle = 0; | |
616 | ||
617 | cpi = (struct rndis_config_parameter_info *)((ulong)set + | |
618 | set->info_buf_offset); | |
619 | cpi->parameter_name_offset = | |
620 | sizeof(struct rndis_config_parameter_info); | |
621 | /* Multiply by 2 because host needs 2 bytes (utf16) for each char */ | |
622 | cpi->parameter_name_length = 2*NWADR_STRLEN; | |
623 | cpi->parameter_type = RNDIS_CONFIG_PARAM_TYPE_STRING; | |
624 | cpi->parameter_value_offset = | |
625 | cpi->parameter_name_offset + cpi->parameter_name_length; | |
626 | /* Multiply by 4 because each MAC byte displayed as 2 utf16 chars */ | |
627 | cpi->parameter_value_length = 4*ETH_ALEN; | |
628 | ||
629 | cfg_nwadr = (wchar_t *)((ulong)cpi + cpi->parameter_name_offset); | |
630 | cfg_mac = (wchar_t *)((ulong)cpi + cpi->parameter_value_offset); | |
631 | ret = utf8s_to_utf16s(NWADR_STR, NWADR_STRLEN, UTF16_HOST_ENDIAN, | |
632 | cfg_nwadr, NWADR_STRLEN); | |
633 | if (ret < 0) | |
634 | goto cleanup; | |
635 | snprintf(macstr, 2*ETH_ALEN+1, "%pm", mac); | |
636 | ret = utf8s_to_utf16s(macstr, 2*ETH_ALEN, UTF16_HOST_ENDIAN, | |
637 | cfg_mac, 2*ETH_ALEN); | |
638 | if (ret < 0) | |
639 | goto cleanup; | |
640 | ||
641 | ret = rndis_filter_send_request(rdev, request); | |
642 | if (ret != 0) | |
643 | goto cleanup; | |
644 | ||
5362855a VK |
645 | wait_for_completion(&request->wait_event); |
646 | ||
647 | set_complete = &request->response_msg.msg.set_complete; | |
867047c4 | 648 | if (set_complete->status != RNDIS_STATUS_SUCCESS) |
649 | ret = -EIO; | |
1ce09e89 HZ |
650 | |
651 | cleanup: | |
652 | put_rndis_request(rdev, request); | |
653 | return ret; | |
654 | } | |
655 | ||
da19fcd0 | 656 | static int |
426d9541 | 657 | rndis_filter_set_offload_params(struct net_device *ndev, |
9749fed5 | 658 | struct netvsc_device *nvdev, |
4a0e70ae KS |
659 | struct ndis_offload_params *req_offloads) |
660 | { | |
4a0e70ae | 661 | struct rndis_device *rdev = nvdev->extension; |
4a0e70ae KS |
662 | struct rndis_request *request; |
663 | struct rndis_set_request *set; | |
664 | struct ndis_offload_params *offload_params; | |
665 | struct rndis_set_complete *set_complete; | |
666 | u32 extlen = sizeof(struct ndis_offload_params); | |
999028cc | 667 | int ret; |
af9893a3 KS |
668 | u32 vsp_version = nvdev->nvsp_version; |
669 | ||
670 | if (vsp_version <= NVSP_PROTOCOL_VERSION_4) { | |
671 | extlen = VERSION_4_OFFLOAD_SIZE; | |
672 | /* On NVSP_PROTOCOL_VERSION_4 and below, we do not support | |
673 | * UDP checksum offload. | |
674 | */ | |
675 | req_offloads->udp_ip_v4_csum = 0; | |
676 | req_offloads->udp_ip_v6_csum = 0; | |
677 | } | |
4a0e70ae KS |
678 | |
679 | request = get_rndis_request(rdev, RNDIS_MSG_SET, | |
680 | RNDIS_MESSAGE_SIZE(struct rndis_set_request) + extlen); | |
681 | if (!request) | |
682 | return -ENOMEM; | |
683 | ||
684 | set = &request->request_msg.msg.set_req; | |
685 | set->oid = OID_TCP_OFFLOAD_PARAMETERS; | |
686 | set->info_buflen = extlen; | |
687 | set->info_buf_offset = sizeof(struct rndis_set_request); | |
688 | set->dev_vc_handle = 0; | |
689 | ||
690 | offload_params = (struct ndis_offload_params *)((ulong)set + | |
691 | set->info_buf_offset); | |
692 | *offload_params = *req_offloads; | |
693 | offload_params->header.type = NDIS_OBJECT_TYPE_DEFAULT; | |
694 | offload_params->header.revision = NDIS_OFFLOAD_PARAMETERS_REVISION_3; | |
695 | offload_params->header.size = extlen; | |
696 | ||
697 | ret = rndis_filter_send_request(rdev, request); | |
698 | if (ret != 0) | |
699 | goto cleanup; | |
700 | ||
5362855a VK |
701 | wait_for_completion(&request->wait_event); |
702 | set_complete = &request->response_msg.msg.set_complete; | |
703 | if (set_complete->status != RNDIS_STATUS_SUCCESS) { | |
704 | netdev_err(ndev, "Fail to set offload on host side:0x%x\n", | |
705 | set_complete->status); | |
706 | ret = -EINVAL; | |
4a0e70ae KS |
707 | } |
708 | ||
709 | cleanup: | |
710 | put_rndis_request(rdev, request); | |
711 | return ret; | |
712 | } | |
1ce09e89 | 713 | |
962f3fee | 714 | int rndis_filter_set_rss_param(struct rndis_device *rdev, |
715e2ec5 | 715 | const u8 *rss_key) |
5b54dac8 | 716 | { |
3d541ac5 | 717 | struct net_device *ndev = rdev->ndev; |
5b54dac8 HZ |
718 | struct rndis_request *request; |
719 | struct rndis_set_request *set; | |
720 | struct rndis_set_complete *set_complete; | |
721 | u32 extlen = sizeof(struct ndis_recv_scale_param) + | |
962f3fee | 722 | 4 * ITAB_NUM + NETVSC_HASH_KEYLEN; |
5b54dac8 HZ |
723 | struct ndis_recv_scale_param *rssp; |
724 | u32 *itab; | |
725 | u8 *keyp; | |
999028cc | 726 | int i, ret; |
5b54dac8 HZ |
727 | |
728 | request = get_rndis_request( | |
729 | rdev, RNDIS_MSG_SET, | |
730 | RNDIS_MESSAGE_SIZE(struct rndis_set_request) + extlen); | |
731 | if (!request) | |
732 | return -ENOMEM; | |
733 | ||
734 | set = &request->request_msg.msg.set_req; | |
735 | set->oid = OID_GEN_RECEIVE_SCALE_PARAMETERS; | |
736 | set->info_buflen = extlen; | |
737 | set->info_buf_offset = sizeof(struct rndis_set_request); | |
738 | set->dev_vc_handle = 0; | |
739 | ||
740 | rssp = (struct ndis_recv_scale_param *)(set + 1); | |
741 | rssp->hdr.type = NDIS_OBJECT_TYPE_RSS_PARAMETERS; | |
742 | rssp->hdr.rev = NDIS_RECEIVE_SCALE_PARAMETERS_REVISION_2; | |
743 | rssp->hdr.size = sizeof(struct ndis_recv_scale_param); | |
744 | rssp->flag = 0; | |
745 | rssp->hashinfo = NDIS_HASH_FUNC_TOEPLITZ | NDIS_HASH_IPV4 | | |
4c87454a HZ |
746 | NDIS_HASH_TCP_IPV4 | NDIS_HASH_IPV6 | |
747 | NDIS_HASH_TCP_IPV6; | |
5b54dac8 HZ |
748 | rssp->indirect_tabsize = 4*ITAB_NUM; |
749 | rssp->indirect_taboffset = sizeof(struct ndis_recv_scale_param); | |
962f3fee | 750 | rssp->hashkey_size = NETVSC_HASH_KEYLEN; |
5b54dac8 HZ |
751 | rssp->kashkey_offset = rssp->indirect_taboffset + |
752 | rssp->indirect_tabsize; | |
753 | ||
754 | /* Set indirection table entries */ | |
755 | itab = (u32 *)(rssp + 1); | |
756 | for (i = 0; i < ITAB_NUM; i++) | |
47371300 | 757 | itab[i] = rdev->rx_table[i]; |
5b54dac8 HZ |
758 | |
759 | /* Set hask key values */ | |
760 | keyp = (u8 *)((unsigned long)rssp + rssp->kashkey_offset); | |
962f3fee | 761 | memcpy(keyp, rss_key, NETVSC_HASH_KEYLEN); |
5b54dac8 | 762 | |
5b54dac8 HZ |
763 | ret = rndis_filter_send_request(rdev, request); |
764 | if (ret != 0) | |
765 | goto cleanup; | |
766 | ||
5362855a VK |
767 | wait_for_completion(&request->wait_event); |
768 | set_complete = &request->response_msg.msg.set_complete; | |
962f3fee | 769 | if (set_complete->status == RNDIS_STATUS_SUCCESS) |
770 | memcpy(rdev->rss_key, rss_key, NETVSC_HASH_KEYLEN); | |
771 | else { | |
5362855a VK |
772 | netdev_err(ndev, "Fail to set RSS parameters:0x%x\n", |
773 | set_complete->status); | |
774 | ret = -EINVAL; | |
5b54dac8 HZ |
775 | } |
776 | ||
777 | cleanup: | |
778 | put_rndis_request(rdev, request); | |
779 | return ret; | |
780 | } | |
781 | ||
867047c4 | 782 | static int rndis_filter_query_device_link_status(struct rndis_device *dev, |
783 | struct netvsc_device *net_device) | |
fceaf24a | 784 | { |
0120ee0d | 785 | u32 size = sizeof(u32); |
6f27457b | 786 | u32 link_status; |
fceaf24a | 787 | |
867047c4 | 788 | return rndis_filter_query_device(dev, net_device, |
789 | RNDIS_OID_GEN_MEDIA_CONNECT_STATUS, | |
790 | &link_status, &size); | |
fceaf24a HJ |
791 | } |
792 | ||
867047c4 | 793 | static int rndis_filter_query_link_speed(struct rndis_device *dev, |
794 | struct netvsc_device *net_device) | |
b37879e6 HZ |
795 | { |
796 | u32 size = sizeof(u32); | |
797 | u32 link_speed; | |
798 | struct net_device_context *ndc; | |
799 | int ret; | |
800 | ||
867047c4 | 801 | ret = rndis_filter_query_device(dev, net_device, |
802 | RNDIS_OID_GEN_LINK_SPEED, | |
b37879e6 HZ |
803 | &link_speed, &size); |
804 | ||
805 | if (!ret) { | |
806 | ndc = netdev_priv(dev->ndev); | |
807 | ||
808 | /* The link speed reported from host is in 100bps unit, so | |
809 | * we convert it to Mbps here. | |
810 | */ | |
811 | ndc->speed = link_speed / 10000; | |
812 | } | |
813 | ||
814 | return ret; | |
815 | } | |
816 | ||
4f19c0d8 | 817 | static int rndis_filter_set_packet_filter(struct rndis_device *dev, |
818 | u32 new_filter) | |
fceaf24a | 819 | { |
e681b954 | 820 | struct rndis_request *request; |
9f33d054 | 821 | struct rndis_set_request *set; |
999028cc | 822 | int ret; |
fceaf24a | 823 | |
51491167 | 824 | request = get_rndis_request(dev, RNDIS_MSG_SET, |
0120ee0d GKH |
825 | RNDIS_MESSAGE_SIZE(struct rndis_set_request) + |
826 | sizeof(u32)); | |
ce12b810 | 827 | if (!request) |
828 | return -ENOMEM; | |
829 | ||
fceaf24a | 830 | |
454f18a9 | 831 | /* Setup the rndis set */ |
a388eb17 HZ |
832 | set = &request->request_msg.msg.set_req; |
833 | set->oid = RNDIS_OID_GEN_CURRENT_PACKET_FILTER; | |
834 | set->info_buflen = sizeof(u32); | |
835 | set->info_buf_offset = sizeof(struct rndis_set_request); | |
fceaf24a | 836 | |
0120ee0d | 837 | memcpy((void *)(unsigned long)set + sizeof(struct rndis_set_request), |
c2a4efdd | 838 | &new_filter, sizeof(u32)); |
fceaf24a | 839 | |
9c26aa0d | 840 | ret = rndis_filter_send_request(dev, request); |
ce12b810 | 841 | if (ret == 0) |
842 | wait_for_completion(&request->wait_event); | |
fceaf24a | 843 | |
ce12b810 | 844 | put_rndis_request(dev, request); |
98d79690 | 845 | |
fceaf24a HJ |
846 | return ret; |
847 | } | |
848 | ||
4f19c0d8 | 849 | static void rndis_set_multicast(struct work_struct *w) |
850 | { | |
851 | struct rndis_device *rdev | |
852 | = container_of(w, struct rndis_device, mcast_work); | |
dffccd27 SH |
853 | u32 filter = NDIS_PACKET_TYPE_DIRECTED; |
854 | unsigned int flags = rdev->ndev->flags; | |
4f19c0d8 | 855 | |
dffccd27 SH |
856 | if (flags & IFF_PROMISC) { |
857 | filter = NDIS_PACKET_TYPE_PROMISCUOUS; | |
858 | } else { | |
4c093c0c | 859 | if (!netdev_mc_empty(rdev->ndev) || (flags & IFF_ALLMULTI)) |
d166e586 | 860 | filter |= NDIS_PACKET_TYPE_ALL_MULTICAST; |
dffccd27 | 861 | if (flags & IFF_BROADCAST) |
d166e586 | 862 | filter |= NDIS_PACKET_TYPE_BROADCAST; |
dffccd27 SH |
863 | } |
864 | ||
865 | rndis_filter_set_packet_filter(rdev, filter); | |
4f19c0d8 | 866 | } |
867 | ||
868 | void rndis_filter_update(struct netvsc_device *nvdev) | |
869 | { | |
870 | struct rndis_device *rdev = nvdev->extension; | |
871 | ||
872 | schedule_work(&rdev->mcast_work); | |
873 | } | |
874 | ||
867047c4 | 875 | static int rndis_filter_init_device(struct rndis_device *dev, |
876 | struct netvsc_device *nvdev) | |
fceaf24a | 877 | { |
e681b954 | 878 | struct rndis_request *request; |
9f33d054 | 879 | struct rndis_initialize_request *init; |
c2a4efdd | 880 | struct rndis_initialize_complete *init_complete; |
4d643114 | 881 | u32 status; |
999028cc | 882 | int ret; |
fceaf24a | 883 | |
51491167 | 884 | request = get_rndis_request(dev, RNDIS_MSG_INIT, |
0120ee0d GKH |
885 | RNDIS_MESSAGE_SIZE(struct rndis_initialize_request)); |
886 | if (!request) { | |
bc49b926 | 887 | ret = -ENOMEM; |
1c627870 | 888 | goto cleanup; |
fceaf24a HJ |
889 | } |
890 | ||
454f18a9 | 891 | /* Setup the rndis set */ |
a388eb17 HZ |
892 | init = &request->request_msg.msg.init_req; |
893 | init->major_ver = RNDIS_MAJOR_VERSION; | |
894 | init->minor_ver = RNDIS_MINOR_VERSION; | |
fb1d074e | 895 | init->max_xfer_size = 0x4000; |
fceaf24a | 896 | |
c2a4efdd | 897 | dev->state = RNDIS_DEV_INITIALIZING; |
fceaf24a | 898 | |
9c26aa0d | 899 | ret = rndis_filter_send_request(dev, request); |
0120ee0d | 900 | if (ret != 0) { |
c2a4efdd | 901 | dev->state = RNDIS_DEV_UNINITIALIZED; |
1c627870 | 902 | goto cleanup; |
fceaf24a HJ |
903 | } |
904 | ||
5362855a | 905 | wait_for_completion(&request->wait_event); |
fceaf24a | 906 | |
a388eb17 HZ |
907 | init_complete = &request->response_msg.msg.init_complete; |
908 | status = init_complete->status; | |
0120ee0d | 909 | if (status == RNDIS_STATUS_SUCCESS) { |
c2a4efdd | 910 | dev->state = RNDIS_DEV_INITIALIZED; |
7c3877f2 HZ |
911 | nvdev->max_pkt = init_complete->max_pkt_per_msg; |
912 | nvdev->pkt_align = 1 << init_complete->pkt_alignment_factor; | |
fceaf24a | 913 | ret = 0; |
0120ee0d | 914 | } else { |
c2a4efdd | 915 | dev->state = RNDIS_DEV_UNINITIALIZED; |
bc49b926 | 916 | ret = -EINVAL; |
fceaf24a HJ |
917 | } |
918 | ||
1c627870 | 919 | cleanup: |
fceaf24a | 920 | if (request) |
9c26aa0d | 921 | put_rndis_request(dev, request); |
fceaf24a HJ |
922 | |
923 | return ret; | |
924 | } | |
925 | ||
46b4f7f5 | 926 | static bool netvsc_device_idle(const struct netvsc_device *nvdev) |
927 | { | |
928 | int i; | |
929 | ||
46b4f7f5 | 930 | for (i = 0; i < nvdev->num_chn; i++) { |
931 | const struct netvsc_channel *nvchan = &nvdev->chan_table[i]; | |
932 | ||
7426b1a5 | 933 | if (nvchan->mrc.first != nvchan->mrc.next) |
934 | return false; | |
935 | ||
46b4f7f5 | 936 | if (atomic_read(&nvchan->queue_sends) > 0) |
937 | return false; | |
938 | } | |
939 | ||
940 | return true; | |
941 | } | |
942 | ||
9c26aa0d | 943 | static void rndis_filter_halt_device(struct rndis_device *dev) |
fceaf24a | 944 | { |
e681b954 | 945 | struct rndis_request *request; |
9f33d054 | 946 | struct rndis_halt_request *halt; |
3d541ac5 | 947 | struct net_device_context *net_device_ctx = netdev_priv(dev->ndev); |
3962981f | 948 | struct netvsc_device *nvdev = rtnl_dereference(net_device_ctx->nvdev); |
fceaf24a | 949 | |
454f18a9 | 950 | /* Attempt to do a rndis device halt */ |
51491167 | 951 | request = get_rndis_request(dev, RNDIS_MSG_HALT, |
0120ee0d | 952 | RNDIS_MESSAGE_SIZE(struct rndis_halt_request)); |
fceaf24a | 953 | if (!request) |
1c627870 | 954 | goto cleanup; |
fceaf24a | 955 | |
454f18a9 | 956 | /* Setup the rndis set */ |
a388eb17 HZ |
957 | halt = &request->request_msg.msg.halt_req; |
958 | halt->req_id = atomic_inc_return(&dev->new_req_id); | |
fceaf24a | 959 | |
454f18a9 | 960 | /* Ignore return since this msg is optional. */ |
9c26aa0d | 961 | rndis_filter_send_request(dev, request); |
fceaf24a | 962 | |
c2a4efdd | 963 | dev->state = RNDIS_DEV_UNINITIALIZED; |
fceaf24a | 964 | |
1c627870 | 965 | cleanup: |
ae9e63bb | 966 | nvdev->destroy = true; |
00ecfb3b | 967 | |
968 | /* Force flag to be ordered before waiting */ | |
969 | wmb(); | |
ae9e63bb HZ |
970 | |
971 | /* Wait for all send completions */ | |
46b4f7f5 | 972 | wait_event(nvdev->wait_drain, netvsc_device_idle(nvdev)); |
ae9e63bb | 973 | |
fceaf24a | 974 | if (request) |
9c26aa0d | 975 | put_rndis_request(dev, request); |
fceaf24a HJ |
976 | } |
977 | ||
9c26aa0d | 978 | static int rndis_filter_open_device(struct rndis_device *dev) |
fceaf24a | 979 | { |
0120ee0d | 980 | int ret; |
fceaf24a | 981 | |
c2a4efdd | 982 | if (dev->state != RNDIS_DEV_INITIALIZED) |
fceaf24a HJ |
983 | return 0; |
984 | ||
9c26aa0d | 985 | ret = rndis_filter_set_packet_filter(dev, |
0120ee0d | 986 | NDIS_PACKET_TYPE_BROADCAST | |
95beae90 | 987 | NDIS_PACKET_TYPE_ALL_MULTICAST | |
0120ee0d | 988 | NDIS_PACKET_TYPE_DIRECTED); |
fceaf24a | 989 | if (ret == 0) |
c2a4efdd | 990 | dev->state = RNDIS_DEV_DATAINITIALIZED; |
fceaf24a | 991 | |
fceaf24a HJ |
992 | return ret; |
993 | } | |
994 | ||
9c26aa0d | 995 | static int rndis_filter_close_device(struct rndis_device *dev) |
fceaf24a HJ |
996 | { |
997 | int ret; | |
998 | ||
c2a4efdd | 999 | if (dev->state != RNDIS_DEV_DATAINITIALIZED) |
fceaf24a HJ |
1000 | return 0; |
1001 | ||
4f19c0d8 | 1002 | /* Make sure rndis_set_multicast doesn't re-enable filter! */ |
1003 | cancel_work_sync(&dev->mcast_work); | |
1004 | ||
9c26aa0d | 1005 | ret = rndis_filter_set_packet_filter(dev, 0); |
c3582a2c HZ |
1006 | if (ret == -ENODEV) |
1007 | ret = 0; | |
1008 | ||
fceaf24a | 1009 | if (ret == 0) |
c2a4efdd | 1010 | dev->state = RNDIS_DEV_INITIALIZED; |
fceaf24a | 1011 | |
fceaf24a HJ |
1012 | return ret; |
1013 | } | |
1014 | ||
5b54dac8 HZ |
1015 | static void netvsc_sc_open(struct vmbus_channel *new_sc) |
1016 | { | |
3d541ac5 VK |
1017 | struct net_device *ndev = |
1018 | hv_get_drvdata(new_sc->primary_channel->device_obj); | |
867047c4 | 1019 | struct net_device_context *ndev_ctx = netdev_priv(ndev); |
1020 | struct netvsc_device *nvscdev; | |
5b54dac8 | 1021 | u16 chn_index = new_sc->offermsg.offer.sub_channel_index; |
6de38af6 | 1022 | struct netvsc_channel *nvchan; |
6de38af6 | 1023 | int ret; |
5b54dac8 | 1024 | |
867047c4 | 1025 | /* This is safe because this callback only happens when |
1026 | * new device is being setup and waiting on the channel_init_wait. | |
1027 | */ | |
1028 | nvscdev = rcu_dereference_raw(ndev_ctx->nvdev); | |
1029 | if (!nvscdev || chn_index >= nvscdev->num_chn) | |
5b54dac8 HZ |
1030 | return; |
1031 | ||
6de38af6 | 1032 | nvchan = nvscdev->chan_table + chn_index; |
6de38af6 | 1033 | |
b1dd90ce S |
1034 | /* Because the device uses NAPI, all the interrupt batching and |
1035 | * control is done via Net softirq, not the channel handling | |
1036 | */ | |
1037 | set_channel_read_mode(new_sc, HV_CALL_ISR); | |
1038 | ||
bffb1842 S |
1039 | /* Set the channel before opening.*/ |
1040 | nvchan->channel = new_sc; | |
1041 | ||
5b54dac8 HZ |
1042 | ret = vmbus_open(new_sc, nvscdev->ring_size * PAGE_SIZE, |
1043 | nvscdev->ring_size * PAGE_SIZE, NULL, 0, | |
6de38af6 | 1044 | netvsc_channel_cb, nvchan); |
76bb5db5 | 1045 | if (ret == 0) |
1046 | napi_enable(&nvchan->napi); | |
1047 | else | |
8195b139 | 1048 | netdev_notice(ndev, "sub channel open failed: %d\n", ret); |
15a863bf | 1049 | |
8f2bb1de SH |
1050 | if (atomic_inc_return(&nvscdev->open_chn) == nvscdev->num_chn) |
1051 | wake_up(&nvscdev->subchan_open); | |
5b54dac8 HZ |
1052 | } |
1053 | ||
8195b139 SH |
1054 | /* Open sub-channels after completing the handling of the device probe. |
1055 | * This breaks overlap of processing the host message for the | |
1056 | * new primary channel with the initialization of sub-channels. | |
1057 | */ | |
2950481a | 1058 | int rndis_set_subchannel(struct net_device *ndev, struct netvsc_device *nvdev) |
8195b139 | 1059 | { |
8195b139 | 1060 | struct nvsp_message *init_packet = &nvdev->channel_init_pkt; |
2950481a SH |
1061 | struct net_device_context *ndev_ctx = netdev_priv(ndev); |
1062 | struct hv_device *hv_dev = ndev_ctx->device_ctx; | |
1063 | struct rndis_device *rdev = nvdev->extension; | |
8195b139 SH |
1064 | int i, ret; |
1065 | ||
2950481a | 1066 | ASSERT_RTNL(); |
8195b139 SH |
1067 | |
1068 | memset(init_packet, 0, sizeof(struct nvsp_message)); | |
1069 | init_packet->hdr.msg_type = NVSP_MSG5_TYPE_SUBCHANNEL; | |
1070 | init_packet->msg.v5_msg.subchn_req.op = NVSP_SUBCHANNEL_ALLOCATE; | |
1071 | init_packet->msg.v5_msg.subchn_req.num_subchannels = | |
1072 | nvdev->num_chn - 1; | |
1073 | ret = vmbus_sendpacket(hv_dev->channel, init_packet, | |
1074 | sizeof(struct nvsp_message), | |
1075 | (unsigned long)init_packet, | |
1076 | VM_PKT_DATA_INBAND, | |
1077 | VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED); | |
1078 | if (ret) { | |
1079 | netdev_err(ndev, "sub channel allocate send failed: %d\n", ret); | |
2950481a | 1080 | return ret; |
8195b139 SH |
1081 | } |
1082 | ||
1083 | wait_for_completion(&nvdev->channel_init_wait); | |
1084 | if (init_packet->msg.v5_msg.subchn_comp.status != NVSP_STAT_SUCCESS) { | |
1085 | netdev_err(ndev, "sub channel request failed\n"); | |
2950481a | 1086 | return -EIO; |
8195b139 SH |
1087 | } |
1088 | ||
1089 | nvdev->num_chn = 1 + | |
1090 | init_packet->msg.v5_msg.subchn_comp.num_subchannels; | |
1091 | ||
1092 | /* wait for all sub channels to open */ | |
1093 | wait_event(nvdev->subchan_open, | |
1094 | atomic_read(&nvdev->open_chn) == nvdev->num_chn); | |
1095 | ||
1096 | /* ignore failues from setting rss parameters, still have channels */ | |
1097 | rndis_filter_set_rss_param(rdev, netvsc_hash_key); | |
1098 | ||
1099 | netif_set_real_num_tx_queues(ndev, nvdev->num_chn); | |
1100 | netif_set_real_num_rx_queues(ndev, nvdev->num_chn); | |
1101 | ||
a6fb6aa3 HZ |
1102 | for (i = 0; i < VRSS_SEND_TAB_SIZE; i++) |
1103 | ndev_ctx->tx_table[i] = i % nvdev->num_chn; | |
1104 | ||
2950481a | 1105 | return 0; |
8195b139 SH |
1106 | } |
1107 | ||
aefd80e8 VK |
1108 | static int rndis_netdev_set_hwcaps(struct rndis_device *rndis_device, |
1109 | struct netvsc_device *nvdev) | |
fceaf24a | 1110 | { |
aefd80e8 | 1111 | struct net_device *net = rndis_device->ndev; |
3d541ac5 | 1112 | struct net_device_context *net_device_ctx = netdev_priv(net); |
23312a3b | 1113 | struct ndis_offload hwcaps; |
4a0e70ae | 1114 | struct ndis_offload_params offloads; |
23312a3b | 1115 | unsigned int gso_max_size = GSO_MAX_SIZE; |
aefd80e8 | 1116 | int ret; |
fceaf24a | 1117 | |
23312a3b | 1118 | /* Find HW offload capabilities */ |
aefd80e8 | 1119 | ret = rndis_query_hwcaps(rndis_device, nvdev, &hwcaps); |
9749fed5 | 1120 | if (ret != 0) |
aefd80e8 | 1121 | return ret; |
23312a3b | 1122 | |
1123 | /* A value of zero means "no change"; now turn on what we want. */ | |
4a0e70ae | 1124 | memset(&offloads, 0, sizeof(struct ndis_offload_params)); |
23312a3b | 1125 | |
1126 | /* Linux does not care about IP checksum, always does in kernel */ | |
1127 | offloads.ip_v4_csum = NDIS_OFFLOAD_PARAMETERS_TX_RX_DISABLED; | |
1128 | ||
aefd80e8 VK |
1129 | /* Reset previously set hw_features flags */ |
1130 | net->hw_features &= ~NETVSC_SUPPORTED_HW_FEATURES; | |
1131 | net_device_ctx->tx_checksum_mask = 0; | |
1132 | ||
23312a3b | 1133 | /* Compute tx offload settings based on hw capabilities */ |
aefd80e8 | 1134 | net->hw_features |= NETIF_F_RXCSUM; |
23312a3b | 1135 | |
1136 | if ((hwcaps.csum.ip4_txcsum & NDIS_TXCSUM_ALL_TCP4) == NDIS_TXCSUM_ALL_TCP4) { | |
1137 | /* Can checksum TCP */ | |
1138 | net->hw_features |= NETIF_F_IP_CSUM; | |
1139 | net_device_ctx->tx_checksum_mask |= TRANSPORT_INFO_IPV4_TCP; | |
1140 | ||
1141 | offloads.tcp_ip_v4_csum = NDIS_OFFLOAD_PARAMETERS_TX_RX_ENABLED; | |
1142 | ||
1143 | if (hwcaps.lsov2.ip4_encap & NDIS_OFFLOAD_ENCAP_8023) { | |
1144 | offloads.lso_v2_ipv4 = NDIS_OFFLOAD_PARAMETERS_LSOV2_ENABLED; | |
1145 | net->hw_features |= NETIF_F_TSO; | |
1146 | ||
1147 | if (hwcaps.lsov2.ip4_maxsz < gso_max_size) | |
1148 | gso_max_size = hwcaps.lsov2.ip4_maxsz; | |
1149 | } | |
1150 | ||
1151 | if (hwcaps.csum.ip4_txcsum & NDIS_TXCSUM_CAP_UDP4) { | |
1152 | offloads.udp_ip_v4_csum = NDIS_OFFLOAD_PARAMETERS_TX_RX_ENABLED; | |
1153 | net_device_ctx->tx_checksum_mask |= TRANSPORT_INFO_IPV4_UDP; | |
1154 | } | |
1155 | } | |
1156 | ||
1157 | if ((hwcaps.csum.ip6_txcsum & NDIS_TXCSUM_ALL_TCP6) == NDIS_TXCSUM_ALL_TCP6) { | |
1158 | net->hw_features |= NETIF_F_IPV6_CSUM; | |
1159 | ||
1160 | offloads.tcp_ip_v6_csum = NDIS_OFFLOAD_PARAMETERS_TX_RX_ENABLED; | |
1161 | net_device_ctx->tx_checksum_mask |= TRANSPORT_INFO_IPV6_TCP; | |
1162 | ||
1163 | if ((hwcaps.lsov2.ip6_encap & NDIS_OFFLOAD_ENCAP_8023) && | |
1164 | (hwcaps.lsov2.ip6_opts & NDIS_LSOV2_CAP_IP6) == NDIS_LSOV2_CAP_IP6) { | |
1165 | offloads.lso_v2_ipv6 = NDIS_OFFLOAD_PARAMETERS_LSOV2_ENABLED; | |
1166 | net->hw_features |= NETIF_F_TSO6; | |
1167 | ||
1168 | if (hwcaps.lsov2.ip6_maxsz < gso_max_size) | |
1169 | gso_max_size = hwcaps.lsov2.ip6_maxsz; | |
1170 | } | |
1171 | ||
1172 | if (hwcaps.csum.ip6_txcsum & NDIS_TXCSUM_CAP_UDP6) { | |
1173 | offloads.udp_ip_v6_csum = NDIS_OFFLOAD_PARAMETERS_TX_RX_ENABLED; | |
1174 | net_device_ctx->tx_checksum_mask |= TRANSPORT_INFO_IPV6_UDP; | |
1175 | } | |
1176 | } | |
1177 | ||
aefd80e8 VK |
1178 | /* In case some hw_features disappeared we need to remove them from |
1179 | * net->features list as they're no longer supported. | |
1180 | */ | |
1181 | net->features &= ~NETVSC_SUPPORTED_HW_FEATURES | net->hw_features; | |
1182 | ||
23312a3b | 1183 | netif_set_gso_max_size(net, gso_max_size); |
4a0e70ae | 1184 | |
aefd80e8 VK |
1185 | ret = rndis_filter_set_offload_params(net, nvdev, &offloads); |
1186 | ||
1187 | return ret; | |
1188 | } | |
1189 | ||
1190 | struct netvsc_device *rndis_filter_device_add(struct hv_device *dev, | |
1191 | struct netvsc_device_info *device_info) | |
1192 | { | |
1193 | struct net_device *net = hv_get_drvdata(dev); | |
1194 | struct netvsc_device *net_device; | |
1195 | struct rndis_device *rndis_device; | |
1196 | struct ndis_recv_scale_cap rsscap; | |
1197 | u32 rsscap_size = sizeof(struct ndis_recv_scale_cap); | |
1198 | u32 mtu, size; | |
aefd80e8 VK |
1199 | u32 num_possible_rss_qs; |
1200 | int i, ret; | |
1201 | ||
1202 | rndis_device = get_rndis_device(); | |
1203 | if (!rndis_device) | |
1204 | return ERR_PTR(-ENODEV); | |
1205 | ||
1206 | /* Let the inner driver handle this first to create the netvsc channel | |
1207 | * NOTE! Once the channel is created, we may get a receive callback | |
1208 | * (RndisFilterOnReceive()) before this call is completed | |
1209 | */ | |
1210 | net_device = netvsc_device_add(dev, device_info); | |
1211 | if (IS_ERR(net_device)) { | |
1212 | kfree(rndis_device); | |
1213 | return net_device; | |
1214 | } | |
1215 | ||
1216 | /* Initialize the rndis device */ | |
1217 | net_device->max_chn = 1; | |
1218 | net_device->num_chn = 1; | |
1219 | ||
1220 | net_device->extension = rndis_device; | |
1221 | rndis_device->ndev = net; | |
1222 | ||
1223 | /* Send the rndis initialization message */ | |
1224 | ret = rndis_filter_init_device(rndis_device, net_device); | |
1225 | if (ret != 0) | |
1226 | goto err_dev_remv; | |
1227 | ||
1228 | /* Get the MTU from the host */ | |
1229 | size = sizeof(u32); | |
1230 | ret = rndis_filter_query_device(rndis_device, net_device, | |
1231 | RNDIS_OID_GEN_MAXIMUM_FRAME_SIZE, | |
1232 | &mtu, &size); | |
1233 | if (ret == 0 && size == sizeof(u32) && mtu < net->mtu) | |
1234 | net->mtu = mtu; | |
1235 | ||
1236 | /* Get the mac address */ | |
1237 | ret = rndis_filter_query_device_mac(rndis_device, net_device); | |
1238 | if (ret != 0) | |
1239 | goto err_dev_remv; | |
1240 | ||
1241 | memcpy(device_info->mac_adr, rndis_device->hw_mac_adr, ETH_ALEN); | |
1242 | ||
1243 | /* Query and set hardware capabilities */ | |
1244 | ret = rndis_netdev_set_hwcaps(rndis_device, net_device); | |
1245 | if (ret != 0) | |
4a0e70ae KS |
1246 | goto err_dev_remv; |
1247 | ||
867047c4 | 1248 | rndis_filter_query_device_link_status(rndis_device, net_device); |
fceaf24a | 1249 | |
93ba2222 VK |
1250 | netdev_dbg(net, "Device MAC %pM link state %s\n", |
1251 | rndis_device->hw_mac_adr, | |
dedb459e | 1252 | rndis_device->link_state ? "down" : "up"); |
fceaf24a | 1253 | |
5b54dac8 | 1254 | if (net_device->nvsp_version < NVSP_PROTOCOL_VERSION_5) |
7b4ba924 | 1255 | goto out; |
5b54dac8 | 1256 | |
867047c4 | 1257 | rndis_filter_query_link_speed(rndis_device, net_device); |
b37879e6 | 1258 | |
5b54dac8 HZ |
1259 | /* vRSS setup */ |
1260 | memset(&rsscap, 0, rsscap_size); | |
867047c4 | 1261 | ret = rndis_filter_query_device(rndis_device, net_device, |
5b54dac8 HZ |
1262 | OID_GEN_RECEIVE_SCALE_CAPABILITIES, |
1263 | &rsscap, &rsscap_size); | |
1264 | if (ret || rsscap.num_recv_que < 2) | |
1265 | goto out; | |
1266 | ||
8a7ddc18 HZ |
1267 | /* This guarantees that num_possible_rss_qs <= num_online_cpus */ |
1268 | num_possible_rss_qs = min_t(u32, num_online_cpus(), | |
3071ada4 | 1269 | rsscap.num_recv_que); |
8ebdcc52 | 1270 | |
3071ada4 | 1271 | net_device->max_chn = min_t(u32, VRSS_CHANNEL_MAX, num_possible_rss_qs); |
e01ec219 | 1272 | |
3071ada4 | 1273 | /* We will use the given number of channels if available. */ |
1274 | net_device->num_chn = min(net_device->max_chn, device_info->num_chn); | |
ff4a4419 | 1275 | |
1276 | for (i = 0; i < ITAB_NUM; i++) | |
47371300 HZ |
1277 | rndis_device->rx_table[i] = ethtool_rxfh_indir_default( |
1278 | i, net_device->num_chn); | |
ff4a4419 | 1279 | |
732e4985 | 1280 | atomic_set(&net_device->open_chn, 1); |
8195b139 | 1281 | vmbus_set_sc_create_callback(dev->channel, netvsc_sc_open); |
5b54dac8 | 1282 | |
7426b1a5 | 1283 | for (i = 1; i < net_device->num_chn; i++) { |
1284 | ret = netvsc_alloc_recv_comp_ring(net_device, i); | |
1285 | if (ret) { | |
1286 | while (--i != 0) | |
1287 | vfree(net_device->chan_table[i].mrc.slots); | |
1288 | goto out; | |
1289 | } | |
1290 | } | |
1291 | ||
8195b139 SH |
1292 | for (i = 1; i < net_device->num_chn; i++) |
1293 | netif_napi_add(net, &net_device->chan_table[i].napi, | |
1294 | netvsc_poll, NAPI_POLL_WEIGHT); | |
5b54dac8 | 1295 | |
2950481a | 1296 | return net_device; |
43c7bd1f | 1297 | |
5b54dac8 | 1298 | out: |
2950481a SH |
1299 | /* setting up multiple channels failed */ |
1300 | net_device->max_chn = 1; | |
1301 | net_device->num_chn = 1; | |
6acec6fa | 1302 | return 0; |
4a0e70ae KS |
1303 | |
1304 | err_dev_remv: | |
2289f0aa | 1305 | rndis_filter_device_remove(dev, net_device); |
9749fed5 | 1306 | return ERR_PTR(ret); |
fceaf24a HJ |
1307 | } |
1308 | ||
2289f0aa | 1309 | void rndis_filter_device_remove(struct hv_device *dev, |
1310 | struct netvsc_device *net_dev) | |
fceaf24a | 1311 | { |
53d21fdb | 1312 | struct rndis_device *rndis_dev = net_dev->extension; |
d66ab514 | 1313 | |
454f18a9 | 1314 | /* Halt and release the rndis device */ |
9c26aa0d | 1315 | rndis_filter_halt_device(rndis_dev); |
fceaf24a | 1316 | |
53d21fdb | 1317 | net_dev->extension = NULL; |
fceaf24a | 1318 | |
3fae5c8f | 1319 | netvsc_device_remove(dev); |
fceaf24a HJ |
1320 | } |
1321 | ||
2f5fa6c8 | 1322 | int rndis_filter_open(struct netvsc_device *nvdev) |
fceaf24a | 1323 | { |
2f5fa6c8 | 1324 | if (!nvdev) |
8a62d716 BP |
1325 | return -EINVAL; |
1326 | ||
2f5fa6c8 | 1327 | if (atomic_inc_return(&nvdev->open_cnt) != 1) |
84bf9cef KS |
1328 | return 0; |
1329 | ||
2f5fa6c8 | 1330 | return rndis_filter_open_device(nvdev->extension); |
fceaf24a HJ |
1331 | } |
1332 | ||
2f5fa6c8 | 1333 | int rndis_filter_close(struct netvsc_device *nvdev) |
fceaf24a | 1334 | { |
5fccab3b | 1335 | if (!nvdev) |
8a62d716 BP |
1336 | return -EINVAL; |
1337 | ||
84bf9cef KS |
1338 | if (atomic_dec_return(&nvdev->open_cnt) != 0) |
1339 | return 0; | |
1340 | ||
5fccab3b | 1341 | return rndis_filter_close_device(nvdev->extension); |
fceaf24a | 1342 | } |