Commit | Line | Data |
---|---|---|
4e9042e6 FL |
1 | /******************************************************************************* |
2 | * | |
3 | * Copyright (c) 2015-2016 Intel Corporation. All rights reserved. | |
4 | * | |
5 | * This software is available to you under a choice of one of two | |
6 | * licenses. You may choose to be licensed under the terms of the GNU | |
7 | * General Public License (GPL) Version 2, available from the file | |
8 | * COPYING in the main directory of this source tree, or the | |
9 | * OpenFabrics.org BSD license below: | |
10 | * | |
11 | * Redistribution and use in source and binary forms, with or | |
12 | * without modification, are permitted provided that the following | |
13 | * conditions are met: | |
14 | * | |
15 | * - Redistributions of source code must retain the above | |
16 | * copyright notice, this list of conditions and the following | |
17 | * disclaimer. | |
18 | * | |
19 | * - Redistributions in binary form must reproduce the above | |
20 | * copyright notice, this list of conditions and the following | |
21 | * disclaimer in the documentation and/or other materials | |
22 | * provided with the distribution. | |
23 | * | |
24 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | |
25 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | |
26 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | |
27 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS | |
28 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN | |
29 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | |
30 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |
31 | * SOFTWARE. | |
32 | * | |
33 | *******************************************************************************/ | |
34 | ||
35 | #include <linux/module.h> | |
36 | #include <linux/moduleparam.h> | |
37 | #include <linux/netdevice.h> | |
38 | #include <linux/etherdevice.h> | |
39 | #include <linux/ethtool.h> | |
40 | #include <linux/mii.h> | |
41 | #include <linux/if_vlan.h> | |
42 | #include <linux/crc32.h> | |
43 | #include <linux/in.h> | |
44 | #include <linux/ip.h> | |
45 | #include <linux/tcp.h> | |
46 | #include <linux/init.h> | |
47 | #include <linux/io.h> | |
48 | #include <asm/irq.h> | |
49 | #include <asm/byteorder.h> | |
50 | #include <net/netevent.h> | |
51 | #include <net/neighbour.h> | |
52 | #include "i40iw.h" | |
53 | ||
54 | /** | |
55 | * i40iw_arp_table - manage arp table | |
56 | * @iwdev: iwarp device | |
57 | * @ip_addr: ip address for device | |
58 | * @mac_addr: mac address ptr | |
59 | * @action: modify, delete or add | |
60 | */ | |
61 | int i40iw_arp_table(struct i40iw_device *iwdev, | |
20c61f7e | 62 | u32 *ip_addr, |
4e9042e6 FL |
63 | bool ipv4, |
64 | u8 *mac_addr, | |
65 | u32 action) | |
66 | { | |
67 | int arp_index; | |
68 | int err; | |
69 | u32 ip[4]; | |
70 | ||
71 | if (ipv4) { | |
72 | memset(ip, 0, sizeof(ip)); | |
73 | ip[0] = *ip_addr; | |
74 | } else { | |
75 | memcpy(ip, ip_addr, sizeof(ip)); | |
76 | } | |
77 | ||
78 | for (arp_index = 0; (u32)arp_index < iwdev->arp_table_size; arp_index++) | |
79 | if (memcmp(iwdev->arp_table[arp_index].ip_addr, ip, sizeof(ip)) == 0) | |
80 | break; | |
81 | switch (action) { | |
82 | case I40IW_ARP_ADD: | |
83 | if (arp_index != iwdev->arp_table_size) | |
84 | return -1; | |
85 | ||
86 | arp_index = 0; | |
87 | err = i40iw_alloc_resource(iwdev, iwdev->allocated_arps, | |
88 | iwdev->arp_table_size, | |
89 | (u32 *)&arp_index, | |
90 | &iwdev->next_arp_index); | |
91 | ||
92 | if (err) | |
93 | return err; | |
94 | ||
95 | memcpy(iwdev->arp_table[arp_index].ip_addr, ip, sizeof(ip)); | |
96 | ether_addr_copy(iwdev->arp_table[arp_index].mac_addr, mac_addr); | |
97 | break; | |
98 | case I40IW_ARP_RESOLVE: | |
99 | if (arp_index == iwdev->arp_table_size) | |
100 | return -1; | |
101 | break; | |
102 | case I40IW_ARP_DELETE: | |
103 | if (arp_index == iwdev->arp_table_size) | |
104 | return -1; | |
105 | memset(iwdev->arp_table[arp_index].ip_addr, 0, | |
106 | sizeof(iwdev->arp_table[arp_index].ip_addr)); | |
107 | eth_zero_addr(iwdev->arp_table[arp_index].mac_addr); | |
108 | i40iw_free_resource(iwdev, iwdev->allocated_arps, arp_index); | |
109 | break; | |
110 | default: | |
111 | return -1; | |
112 | } | |
113 | return arp_index; | |
114 | } | |
115 | ||
116 | /** | |
117 | * i40iw_wr32 - write 32 bits to hw register | |
118 | * @hw: hardware information including registers | |
119 | * @reg: register offset | |
120 | * @value: vvalue to write to register | |
121 | */ | |
122 | inline void i40iw_wr32(struct i40iw_hw *hw, u32 reg, u32 value) | |
123 | { | |
124 | writel(value, hw->hw_addr + reg); | |
125 | } | |
126 | ||
127 | /** | |
128 | * i40iw_rd32 - read a 32 bit hw register | |
129 | * @hw: hardware information including registers | |
130 | * @reg: register offset | |
131 | * | |
132 | * Return value of register content | |
133 | */ | |
134 | inline u32 i40iw_rd32(struct i40iw_hw *hw, u32 reg) | |
135 | { | |
136 | return readl(hw->hw_addr + reg); | |
137 | } | |
138 | ||
139 | /** | |
140 | * i40iw_inetaddr_event - system notifier for netdev events | |
141 | * @notfier: not used | |
142 | * @event: event for notifier | |
143 | * @ptr: if address | |
144 | */ | |
145 | int i40iw_inetaddr_event(struct notifier_block *notifier, | |
146 | unsigned long event, | |
147 | void *ptr) | |
148 | { | |
149 | struct in_ifaddr *ifa = ptr; | |
150 | struct net_device *event_netdev = ifa->ifa_dev->dev; | |
151 | struct net_device *netdev; | |
152 | struct net_device *upper_dev; | |
153 | struct i40iw_device *iwdev; | |
154 | struct i40iw_handler *hdl; | |
20c61f7e | 155 | u32 local_ipaddr; |
4e9042e6 FL |
156 | |
157 | hdl = i40iw_find_netdev(event_netdev); | |
158 | if (!hdl) | |
159 | return NOTIFY_DONE; | |
160 | ||
161 | iwdev = &hdl->device; | |
162 | netdev = iwdev->ldev->netdev; | |
163 | upper_dev = netdev_master_upper_dev_get(netdev); | |
164 | if (netdev != event_netdev) | |
165 | return NOTIFY_DONE; | |
166 | ||
167 | switch (event) { | |
168 | case NETDEV_DOWN: | |
169 | if (upper_dev) | |
20c61f7e IM |
170 | local_ipaddr = ntohl( |
171 | ((struct in_device *)upper_dev->ip_ptr)->ifa_list->ifa_address); | |
4e9042e6 | 172 | else |
20c61f7e | 173 | local_ipaddr = ntohl(ifa->ifa_address); |
4e9042e6 FL |
174 | i40iw_manage_arp_cache(iwdev, |
175 | netdev->dev_addr, | |
176 | &local_ipaddr, | |
177 | true, | |
178 | I40IW_ARP_DELETE); | |
179 | return NOTIFY_OK; | |
180 | case NETDEV_UP: | |
181 | if (upper_dev) | |
20c61f7e IM |
182 | local_ipaddr = ntohl( |
183 | ((struct in_device *)upper_dev->ip_ptr)->ifa_list->ifa_address); | |
4e9042e6 | 184 | else |
20c61f7e | 185 | local_ipaddr = ntohl(ifa->ifa_address); |
4e9042e6 FL |
186 | i40iw_manage_arp_cache(iwdev, |
187 | netdev->dev_addr, | |
188 | &local_ipaddr, | |
189 | true, | |
190 | I40IW_ARP_ADD); | |
191 | break; | |
192 | case NETDEV_CHANGEADDR: | |
193 | /* Add the address to the IP table */ | |
194 | if (upper_dev) | |
20c61f7e IM |
195 | local_ipaddr = ntohl( |
196 | ((struct in_device *)upper_dev->ip_ptr)->ifa_list->ifa_address); | |
4e9042e6 | 197 | else |
20c61f7e | 198 | local_ipaddr = ntohl(ifa->ifa_address); |
4e9042e6 | 199 | |
4e9042e6 FL |
200 | i40iw_manage_arp_cache(iwdev, |
201 | netdev->dev_addr, | |
202 | &local_ipaddr, | |
203 | true, | |
204 | I40IW_ARP_ADD); | |
205 | break; | |
206 | default: | |
207 | break; | |
208 | } | |
209 | return NOTIFY_DONE; | |
210 | } | |
211 | ||
212 | /** | |
213 | * i40iw_inet6addr_event - system notifier for ipv6 netdev events | |
214 | * @notfier: not used | |
215 | * @event: event for notifier | |
216 | * @ptr: if address | |
217 | */ | |
218 | int i40iw_inet6addr_event(struct notifier_block *notifier, | |
219 | unsigned long event, | |
220 | void *ptr) | |
221 | { | |
222 | struct inet6_ifaddr *ifa = (struct inet6_ifaddr *)ptr; | |
223 | struct net_device *event_netdev = ifa->idev->dev; | |
224 | struct net_device *netdev; | |
225 | struct i40iw_device *iwdev; | |
226 | struct i40iw_handler *hdl; | |
20c61f7e | 227 | u32 local_ipaddr6[4]; |
4e9042e6 FL |
228 | |
229 | hdl = i40iw_find_netdev(event_netdev); | |
230 | if (!hdl) | |
231 | return NOTIFY_DONE; | |
232 | ||
233 | iwdev = &hdl->device; | |
234 | netdev = iwdev->ldev->netdev; | |
235 | if (netdev != event_netdev) | |
236 | return NOTIFY_DONE; | |
237 | ||
238 | switch (event) { | |
239 | case NETDEV_DOWN: | |
240 | i40iw_copy_ip_ntohl(local_ipaddr6, ifa->addr.in6_u.u6_addr32); | |
241 | i40iw_manage_arp_cache(iwdev, | |
242 | netdev->dev_addr, | |
243 | local_ipaddr6, | |
244 | false, | |
245 | I40IW_ARP_DELETE); | |
246 | return NOTIFY_OK; | |
247 | case NETDEV_UP: | |
248 | /* Fall through */ | |
249 | case NETDEV_CHANGEADDR: | |
250 | i40iw_copy_ip_ntohl(local_ipaddr6, ifa->addr.in6_u.u6_addr32); | |
251 | i40iw_manage_arp_cache(iwdev, | |
252 | netdev->dev_addr, | |
253 | local_ipaddr6, | |
254 | false, | |
255 | I40IW_ARP_ADD); | |
256 | break; | |
257 | default: | |
258 | break; | |
259 | } | |
260 | return NOTIFY_DONE; | |
261 | } | |
262 | ||
263 | /** | |
264 | * i40iw_net_event - system notifier for net events | |
265 | * @notfier: not used | |
266 | * @event: event for notifier | |
267 | * @ptr: neighbor | |
268 | */ | |
269 | int i40iw_net_event(struct notifier_block *notifier, unsigned long event, void *ptr) | |
270 | { | |
271 | struct neighbour *neigh = ptr; | |
272 | struct i40iw_device *iwdev; | |
273 | struct i40iw_handler *iwhdl; | |
274 | __be32 *p; | |
275 | u32 local_ipaddr[4]; | |
276 | ||
277 | switch (event) { | |
278 | case NETEVENT_NEIGH_UPDATE: | |
279 | iwhdl = i40iw_find_netdev((struct net_device *)neigh->dev); | |
280 | if (!iwhdl) | |
281 | return NOTIFY_DONE; | |
282 | iwdev = &iwhdl->device; | |
283 | p = (__be32 *)neigh->primary_key; | |
284 | i40iw_copy_ip_ntohl(local_ipaddr, p); | |
285 | if (neigh->nud_state & NUD_VALID) { | |
286 | i40iw_manage_arp_cache(iwdev, | |
287 | neigh->ha, | |
288 | local_ipaddr, | |
289 | false, | |
290 | I40IW_ARP_ADD); | |
291 | ||
292 | } else { | |
293 | i40iw_manage_arp_cache(iwdev, | |
294 | neigh->ha, | |
295 | local_ipaddr, | |
296 | false, | |
297 | I40IW_ARP_DELETE); | |
298 | } | |
299 | break; | |
300 | default: | |
301 | break; | |
302 | } | |
303 | return NOTIFY_DONE; | |
304 | } | |
305 | ||
306 | /** | |
307 | * i40iw_get_cqp_request - get cqp struct | |
308 | * @cqp: device cqp ptr | |
309 | * @wait: cqp to be used in wait mode | |
310 | */ | |
311 | struct i40iw_cqp_request *i40iw_get_cqp_request(struct i40iw_cqp *cqp, bool wait) | |
312 | { | |
313 | struct i40iw_cqp_request *cqp_request = NULL; | |
314 | unsigned long flags; | |
315 | ||
316 | spin_lock_irqsave(&cqp->req_lock, flags); | |
317 | if (!list_empty(&cqp->cqp_avail_reqs)) { | |
318 | cqp_request = list_entry(cqp->cqp_avail_reqs.next, | |
319 | struct i40iw_cqp_request, list); | |
320 | list_del_init(&cqp_request->list); | |
321 | } | |
322 | spin_unlock_irqrestore(&cqp->req_lock, flags); | |
323 | if (!cqp_request) { | |
324 | cqp_request = kzalloc(sizeof(*cqp_request), GFP_ATOMIC); | |
325 | if (cqp_request) { | |
326 | cqp_request->dynamic = true; | |
327 | INIT_LIST_HEAD(&cqp_request->list); | |
328 | init_waitqueue_head(&cqp_request->waitq); | |
329 | } | |
330 | } | |
331 | if (!cqp_request) { | |
332 | i40iw_pr_err("CQP Request Fail: No Memory"); | |
333 | return NULL; | |
334 | } | |
335 | ||
336 | if (wait) { | |
337 | atomic_set(&cqp_request->refcount, 2); | |
338 | cqp_request->waiting = true; | |
339 | } else { | |
340 | atomic_set(&cqp_request->refcount, 1); | |
341 | } | |
342 | return cqp_request; | |
343 | } | |
344 | ||
345 | /** | |
346 | * i40iw_free_cqp_request - free cqp request | |
347 | * @cqp: cqp ptr | |
348 | * @cqp_request: to be put back in cqp list | |
349 | */ | |
350 | void i40iw_free_cqp_request(struct i40iw_cqp *cqp, struct i40iw_cqp_request *cqp_request) | |
351 | { | |
352 | unsigned long flags; | |
353 | ||
354 | if (cqp_request->dynamic) { | |
355 | kfree(cqp_request); | |
356 | } else { | |
357 | cqp_request->request_done = false; | |
358 | cqp_request->callback_fcn = NULL; | |
359 | cqp_request->waiting = false; | |
360 | ||
361 | spin_lock_irqsave(&cqp->req_lock, flags); | |
362 | list_add_tail(&cqp_request->list, &cqp->cqp_avail_reqs); | |
363 | spin_unlock_irqrestore(&cqp->req_lock, flags); | |
364 | } | |
365 | } | |
366 | ||
367 | /** | |
368 | * i40iw_put_cqp_request - dec ref count and free if 0 | |
369 | * @cqp: cqp ptr | |
370 | * @cqp_request: to be put back in cqp list | |
371 | */ | |
372 | void i40iw_put_cqp_request(struct i40iw_cqp *cqp, | |
373 | struct i40iw_cqp_request *cqp_request) | |
374 | { | |
375 | if (atomic_dec_and_test(&cqp_request->refcount)) | |
376 | i40iw_free_cqp_request(cqp, cqp_request); | |
377 | } | |
378 | ||
379 | /** | |
380 | * i40iw_free_qp - callback after destroy cqp completes | |
381 | * @cqp_request: cqp request for destroy qp | |
382 | * @num: not used | |
383 | */ | |
384 | static void i40iw_free_qp(struct i40iw_cqp_request *cqp_request, u32 num) | |
385 | { | |
386 | struct i40iw_sc_qp *qp = (struct i40iw_sc_qp *)cqp_request->param; | |
387 | struct i40iw_qp *iwqp = (struct i40iw_qp *)qp->back_qp; | |
388 | struct i40iw_device *iwdev; | |
389 | u32 qp_num = iwqp->ibqp.qp_num; | |
390 | ||
391 | iwdev = iwqp->iwdev; | |
392 | ||
393 | i40iw_rem_pdusecount(iwqp->iwpd, iwdev); | |
394 | i40iw_free_qp_resources(iwdev, iwqp, qp_num); | |
395 | } | |
396 | ||
397 | /** | |
398 | * i40iw_wait_event - wait for completion | |
399 | * @iwdev: iwarp device | |
400 | * @cqp_request: cqp request to wait | |
401 | */ | |
402 | static int i40iw_wait_event(struct i40iw_device *iwdev, | |
403 | struct i40iw_cqp_request *cqp_request) | |
404 | { | |
405 | struct cqp_commands_info *info = &cqp_request->info; | |
406 | struct i40iw_cqp *iwcqp = &iwdev->cqp; | |
407 | bool cqp_error = false; | |
408 | int err_code = 0; | |
409 | int timeout_ret = 0; | |
410 | ||
411 | timeout_ret = wait_event_timeout(cqp_request->waitq, | |
412 | cqp_request->request_done, | |
413 | I40IW_EVENT_TIMEOUT); | |
414 | if (!timeout_ret) { | |
415 | i40iw_pr_err("error cqp command 0x%x timed out ret = %d\n", | |
416 | info->cqp_cmd, timeout_ret); | |
417 | err_code = -ETIME; | |
418 | i40iw_request_reset(iwdev); | |
419 | goto done; | |
420 | } | |
421 | cqp_error = cqp_request->compl_info.error; | |
422 | if (cqp_error) { | |
423 | i40iw_pr_err("error cqp command 0x%x completion maj = 0x%x min=0x%x\n", | |
424 | info->cqp_cmd, cqp_request->compl_info.maj_err_code, | |
425 | cqp_request->compl_info.min_err_code); | |
426 | err_code = -EPROTO; | |
427 | goto done; | |
428 | } | |
429 | done: | |
430 | i40iw_put_cqp_request(iwcqp, cqp_request); | |
431 | return err_code; | |
432 | } | |
433 | ||
434 | /** | |
435 | * i40iw_handle_cqp_op - process cqp command | |
436 | * @iwdev: iwarp device | |
437 | * @cqp_request: cqp request to process | |
438 | */ | |
439 | enum i40iw_status_code i40iw_handle_cqp_op(struct i40iw_device *iwdev, | |
440 | struct i40iw_cqp_request | |
441 | *cqp_request) | |
442 | { | |
443 | struct i40iw_sc_dev *dev = &iwdev->sc_dev; | |
444 | enum i40iw_status_code status; | |
445 | struct cqp_commands_info *info = &cqp_request->info; | |
446 | int err_code = 0; | |
447 | ||
448 | status = i40iw_process_cqp_cmd(dev, info); | |
449 | if (status) { | |
450 | i40iw_pr_err("error cqp command 0x%x failed\n", info->cqp_cmd); | |
451 | i40iw_free_cqp_request(&iwdev->cqp, cqp_request); | |
452 | return status; | |
453 | } | |
454 | if (cqp_request->waiting) | |
455 | err_code = i40iw_wait_event(iwdev, cqp_request); | |
456 | if (err_code) | |
457 | status = I40IW_ERR_CQP_COMPL_ERROR; | |
458 | return status; | |
459 | } | |
460 | ||
461 | /** | |
462 | * i40iw_add_pdusecount - add pd refcount | |
463 | * @iwpd: pd for refcount | |
464 | */ | |
465 | void i40iw_add_pdusecount(struct i40iw_pd *iwpd) | |
466 | { | |
467 | atomic_inc(&iwpd->usecount); | |
468 | } | |
469 | ||
470 | /** | |
471 | * i40iw_rem_pdusecount - decrement refcount for pd and free if 0 | |
472 | * @iwpd: pd for refcount | |
473 | * @iwdev: iwarp device | |
474 | */ | |
475 | void i40iw_rem_pdusecount(struct i40iw_pd *iwpd, struct i40iw_device *iwdev) | |
476 | { | |
477 | if (!atomic_dec_and_test(&iwpd->usecount)) | |
478 | return; | |
479 | i40iw_free_resource(iwdev, iwdev->allocated_pds, iwpd->sc_pd.pd_id); | |
480 | kfree(iwpd); | |
481 | } | |
482 | ||
483 | /** | |
484 | * i40iw_add_ref - add refcount for qp | |
485 | * @ibqp: iqarp qp | |
486 | */ | |
487 | void i40iw_add_ref(struct ib_qp *ibqp) | |
488 | { | |
489 | struct i40iw_qp *iwqp = (struct i40iw_qp *)ibqp; | |
490 | ||
491 | atomic_inc(&iwqp->refcount); | |
492 | } | |
493 | ||
494 | /** | |
495 | * i40iw_rem_ref - rem refcount for qp and free if 0 | |
496 | * @ibqp: iqarp qp | |
497 | */ | |
498 | void i40iw_rem_ref(struct ib_qp *ibqp) | |
499 | { | |
500 | struct i40iw_qp *iwqp; | |
501 | enum i40iw_status_code status; | |
502 | struct i40iw_cqp_request *cqp_request; | |
503 | struct cqp_commands_info *cqp_info; | |
504 | struct i40iw_device *iwdev; | |
505 | u32 qp_num; | |
996abf0a | 506 | unsigned long flags; |
4e9042e6 FL |
507 | |
508 | iwqp = to_iwqp(ibqp); | |
996abf0a IM |
509 | iwdev = iwqp->iwdev; |
510 | spin_lock_irqsave(&iwdev->qptable_lock, flags); | |
511 | if (!atomic_dec_and_test(&iwqp->refcount)) { | |
512 | spin_unlock_irqrestore(&iwdev->qptable_lock, flags); | |
4e9042e6 | 513 | return; |
996abf0a | 514 | } |
4e9042e6 | 515 | |
4e9042e6 FL |
516 | qp_num = iwqp->ibqp.qp_num; |
517 | iwdev->qp_table[qp_num] = NULL; | |
996abf0a | 518 | spin_unlock_irqrestore(&iwdev->qptable_lock, flags); |
4e9042e6 FL |
519 | cqp_request = i40iw_get_cqp_request(&iwdev->cqp, false); |
520 | if (!cqp_request) | |
521 | return; | |
522 | ||
523 | cqp_request->callback_fcn = i40iw_free_qp; | |
524 | cqp_request->param = (void *)&iwqp->sc_qp; | |
525 | cqp_info = &cqp_request->info; | |
526 | cqp_info->cqp_cmd = OP_QP_DESTROY; | |
527 | cqp_info->post_sq = 1; | |
528 | cqp_info->in.u.qp_destroy.qp = &iwqp->sc_qp; | |
529 | cqp_info->in.u.qp_destroy.scratch = (uintptr_t)cqp_request; | |
530 | cqp_info->in.u.qp_destroy.remove_hash_idx = true; | |
531 | status = i40iw_handle_cqp_op(iwdev, cqp_request); | |
532 | if (status) | |
533 | i40iw_pr_err("CQP-OP Destroy QP fail"); | |
534 | } | |
535 | ||
536 | /** | |
537 | * i40iw_get_qp - get qp address | |
538 | * @device: iwarp device | |
539 | * @qpn: qp number | |
540 | */ | |
541 | struct ib_qp *i40iw_get_qp(struct ib_device *device, int qpn) | |
542 | { | |
543 | struct i40iw_device *iwdev = to_iwdev(device); | |
544 | ||
545 | if ((qpn < IW_FIRST_QPN) || (qpn >= iwdev->max_qp)) | |
546 | return NULL; | |
547 | ||
548 | return &iwdev->qp_table[qpn]->ibqp; | |
549 | } | |
550 | ||
551 | /** | |
552 | * i40iw_debug_buf - print debug msg and buffer is mask set | |
553 | * @dev: hardware control device structure | |
554 | * @mask: mask to compare if to print debug buffer | |
555 | * @buf: points buffer addr | |
556 | * @size: saize of buffer to print | |
557 | */ | |
558 | void i40iw_debug_buf(struct i40iw_sc_dev *dev, | |
559 | enum i40iw_debug_flag mask, | |
560 | char *desc, | |
561 | u64 *buf, | |
562 | u32 size) | |
563 | { | |
564 | u32 i; | |
565 | ||
566 | if (!(dev->debug_mask & mask)) | |
567 | return; | |
568 | i40iw_debug(dev, mask, "%s\n", desc); | |
569 | i40iw_debug(dev, mask, "starting address virt=%p phy=%llxh\n", buf, | |
570 | (unsigned long long)virt_to_phys(buf)); | |
571 | ||
572 | for (i = 0; i < size; i += 8) | |
573 | i40iw_debug(dev, mask, "index %03d val: %016llx\n", i, buf[i / 8]); | |
574 | } | |
575 | ||
576 | /** | |
577 | * i40iw_get_hw_addr - return hw addr | |
578 | * @par: points to shared dev | |
579 | */ | |
580 | u8 __iomem *i40iw_get_hw_addr(void *par) | |
581 | { | |
582 | struct i40iw_sc_dev *dev = (struct i40iw_sc_dev *)par; | |
583 | ||
584 | return dev->hw->hw_addr; | |
585 | } | |
586 | ||
587 | /** | |
588 | * i40iw_remove_head - return head entry and remove from list | |
589 | * @list: list for entry | |
590 | */ | |
591 | void *i40iw_remove_head(struct list_head *list) | |
592 | { | |
593 | struct list_head *entry; | |
594 | ||
595 | if (list_empty(list)) | |
596 | return NULL; | |
597 | ||
598 | entry = (void *)list->next; | |
599 | list_del(entry); | |
600 | return (void *)entry; | |
601 | } | |
602 | ||
603 | /** | |
604 | * i40iw_allocate_dma_mem - Memory alloc helper fn | |
605 | * @hw: pointer to the HW structure | |
606 | * @mem: ptr to mem struct to fill out | |
607 | * @size: size of memory requested | |
608 | * @alignment: what to align the allocation to | |
609 | */ | |
610 | enum i40iw_status_code i40iw_allocate_dma_mem(struct i40iw_hw *hw, | |
611 | struct i40iw_dma_mem *mem, | |
612 | u64 size, | |
613 | u32 alignment) | |
614 | { | |
615 | struct pci_dev *pcidev = (struct pci_dev *)hw->dev_context; | |
616 | ||
617 | if (!mem) | |
618 | return I40IW_ERR_PARAM; | |
619 | mem->size = ALIGN(size, alignment); | |
620 | mem->va = dma_zalloc_coherent(&pcidev->dev, mem->size, | |
621 | (dma_addr_t *)&mem->pa, GFP_KERNEL); | |
622 | if (!mem->va) | |
623 | return I40IW_ERR_NO_MEMORY; | |
624 | return 0; | |
625 | } | |
626 | ||
627 | /** | |
628 | * i40iw_free_dma_mem - Memory free helper fn | |
629 | * @hw: pointer to the HW structure | |
630 | * @mem: ptr to mem struct to free | |
631 | */ | |
632 | void i40iw_free_dma_mem(struct i40iw_hw *hw, struct i40iw_dma_mem *mem) | |
633 | { | |
634 | struct pci_dev *pcidev = (struct pci_dev *)hw->dev_context; | |
635 | ||
636 | if (!mem || !mem->va) | |
637 | return; | |
638 | ||
639 | dma_free_coherent(&pcidev->dev, mem->size, | |
640 | mem->va, (dma_addr_t)mem->pa); | |
641 | mem->va = NULL; | |
642 | } | |
643 | ||
644 | /** | |
645 | * i40iw_allocate_virt_mem - virtual memory alloc helper fn | |
646 | * @hw: pointer to the HW structure | |
647 | * @mem: ptr to mem struct to fill out | |
648 | * @size: size of memory requested | |
649 | */ | |
650 | enum i40iw_status_code i40iw_allocate_virt_mem(struct i40iw_hw *hw, | |
651 | struct i40iw_virt_mem *mem, | |
652 | u32 size) | |
653 | { | |
654 | if (!mem) | |
655 | return I40IW_ERR_PARAM; | |
656 | ||
657 | mem->size = size; | |
658 | mem->va = kzalloc(size, GFP_KERNEL); | |
659 | ||
660 | if (mem->va) | |
661 | return 0; | |
662 | else | |
663 | return I40IW_ERR_NO_MEMORY; | |
664 | } | |
665 | ||
666 | /** | |
667 | * i40iw_free_virt_mem - virtual memory free helper fn | |
668 | * @hw: pointer to the HW structure | |
669 | * @mem: ptr to mem struct to free | |
670 | */ | |
671 | enum i40iw_status_code i40iw_free_virt_mem(struct i40iw_hw *hw, | |
672 | struct i40iw_virt_mem *mem) | |
673 | { | |
674 | if (!mem) | |
675 | return I40IW_ERR_PARAM; | |
676 | kfree(mem->va); | |
677 | mem->va = NULL; | |
678 | return 0; | |
679 | } | |
680 | ||
681 | /** | |
682 | * i40iw_cqp_sds_cmd - create cqp command for sd | |
683 | * @dev: hardware control device structure | |
684 | * @sd_info: information for sd cqp | |
685 | * | |
686 | */ | |
687 | enum i40iw_status_code i40iw_cqp_sds_cmd(struct i40iw_sc_dev *dev, | |
688 | struct i40iw_update_sds_info *sdinfo) | |
689 | { | |
690 | enum i40iw_status_code status; | |
691 | struct i40iw_cqp_request *cqp_request; | |
692 | struct cqp_commands_info *cqp_info; | |
693 | struct i40iw_device *iwdev = (struct i40iw_device *)dev->back_dev; | |
694 | ||
695 | cqp_request = i40iw_get_cqp_request(&iwdev->cqp, true); | |
696 | if (!cqp_request) | |
697 | return I40IW_ERR_NO_MEMORY; | |
698 | cqp_info = &cqp_request->info; | |
699 | memcpy(&cqp_info->in.u.update_pe_sds.info, sdinfo, | |
700 | sizeof(cqp_info->in.u.update_pe_sds.info)); | |
701 | cqp_info->cqp_cmd = OP_UPDATE_PE_SDS; | |
702 | cqp_info->post_sq = 1; | |
703 | cqp_info->in.u.update_pe_sds.dev = dev; | |
704 | cqp_info->in.u.update_pe_sds.scratch = (uintptr_t)cqp_request; | |
705 | status = i40iw_handle_cqp_op(iwdev, cqp_request); | |
706 | if (status) | |
707 | i40iw_pr_err("CQP-OP Update SD's fail"); | |
708 | return status; | |
709 | } | |
710 | ||
711 | /** | |
712 | * i40iw_term_modify_qp - modify qp for term message | |
713 | * @qp: hardware control qp | |
714 | * @next_state: qp's next state | |
715 | * @term: terminate code | |
716 | * @term_len: length | |
717 | */ | |
718 | void i40iw_term_modify_qp(struct i40iw_sc_qp *qp, u8 next_state, u8 term, u8 term_len) | |
719 | { | |
720 | struct i40iw_qp *iwqp; | |
721 | ||
722 | iwqp = (struct i40iw_qp *)qp->back_qp; | |
723 | i40iw_next_iw_state(iwqp, next_state, 0, term, term_len); | |
724 | }; | |
725 | ||
726 | /** | |
727 | * i40iw_terminate_done - after terminate is completed | |
728 | * @qp: hardware control qp | |
729 | * @timeout_occurred: indicates if terminate timer expired | |
730 | */ | |
731 | void i40iw_terminate_done(struct i40iw_sc_qp *qp, int timeout_occurred) | |
732 | { | |
733 | struct i40iw_qp *iwqp; | |
734 | u32 next_iwarp_state = I40IW_QP_STATE_ERROR; | |
735 | u8 hte = 0; | |
736 | bool first_time; | |
737 | unsigned long flags; | |
738 | ||
739 | iwqp = (struct i40iw_qp *)qp->back_qp; | |
740 | spin_lock_irqsave(&iwqp->lock, flags); | |
741 | if (iwqp->hte_added) { | |
742 | iwqp->hte_added = 0; | |
743 | hte = 1; | |
744 | } | |
745 | first_time = !(qp->term_flags & I40IW_TERM_DONE); | |
746 | qp->term_flags |= I40IW_TERM_DONE; | |
747 | spin_unlock_irqrestore(&iwqp->lock, flags); | |
748 | if (first_time) { | |
749 | if (!timeout_occurred) | |
750 | i40iw_terminate_del_timer(qp); | |
751 | else | |
752 | next_iwarp_state = I40IW_QP_STATE_CLOSING; | |
753 | ||
754 | i40iw_next_iw_state(iwqp, next_iwarp_state, hte, 0, 0); | |
755 | i40iw_cm_disconn(iwqp); | |
756 | } | |
757 | } | |
758 | ||
759 | /** | |
760 | * i40iw_terminate_imeout - timeout happened | |
761 | * @context: points to iwarp qp | |
762 | */ | |
763 | static void i40iw_terminate_timeout(unsigned long context) | |
764 | { | |
765 | struct i40iw_qp *iwqp = (struct i40iw_qp *)context; | |
766 | struct i40iw_sc_qp *qp = (struct i40iw_sc_qp *)&iwqp->sc_qp; | |
767 | ||
768 | i40iw_terminate_done(qp, 1); | |
769 | } | |
770 | ||
771 | /** | |
772 | * i40iw_terminate_start_timer - start terminate timeout | |
773 | * @qp: hardware control qp | |
774 | */ | |
775 | void i40iw_terminate_start_timer(struct i40iw_sc_qp *qp) | |
776 | { | |
777 | struct i40iw_qp *iwqp; | |
778 | ||
779 | iwqp = (struct i40iw_qp *)qp->back_qp; | |
780 | init_timer(&iwqp->terminate_timer); | |
781 | iwqp->terminate_timer.function = i40iw_terminate_timeout; | |
782 | iwqp->terminate_timer.expires = jiffies + HZ; | |
783 | iwqp->terminate_timer.data = (unsigned long)iwqp; | |
784 | add_timer(&iwqp->terminate_timer); | |
785 | } | |
786 | ||
787 | /** | |
788 | * i40iw_terminate_del_timer - delete terminate timeout | |
789 | * @qp: hardware control qp | |
790 | */ | |
791 | void i40iw_terminate_del_timer(struct i40iw_sc_qp *qp) | |
792 | { | |
793 | struct i40iw_qp *iwqp; | |
794 | ||
795 | iwqp = (struct i40iw_qp *)qp->back_qp; | |
796 | del_timer(&iwqp->terminate_timer); | |
797 | } | |
798 | ||
799 | /** | |
800 | * i40iw_cqp_generic_worker - generic worker for cqp | |
801 | * @work: work pointer | |
802 | */ | |
803 | static void i40iw_cqp_generic_worker(struct work_struct *work) | |
804 | { | |
805 | struct i40iw_virtchnl_work_info *work_info = | |
806 | &((struct virtchnl_work *)work)->work_info; | |
807 | ||
808 | if (work_info->worker_vf_dev) | |
809 | work_info->callback_fcn(work_info->worker_vf_dev); | |
810 | } | |
811 | ||
812 | /** | |
813 | * i40iw_cqp_spawn_worker - spawn worket thread | |
814 | * @iwdev: device struct pointer | |
815 | * @work_info: work request info | |
816 | * @iw_vf_idx: virtual function index | |
817 | */ | |
818 | void i40iw_cqp_spawn_worker(struct i40iw_sc_dev *dev, | |
819 | struct i40iw_virtchnl_work_info *work_info, | |
820 | u32 iw_vf_idx) | |
821 | { | |
822 | struct virtchnl_work *work; | |
823 | struct i40iw_device *iwdev = (struct i40iw_device *)dev->back_dev; | |
824 | ||
825 | work = &iwdev->virtchnl_w[iw_vf_idx]; | |
826 | memcpy(&work->work_info, work_info, sizeof(*work_info)); | |
827 | INIT_WORK(&work->work, i40iw_cqp_generic_worker); | |
828 | queue_work(iwdev->virtchnl_wq, &work->work); | |
829 | } | |
830 | ||
831 | /** | |
832 | * i40iw_cqp_manage_hmc_fcn_worker - | |
833 | * @work: work pointer for hmc info | |
834 | */ | |
835 | static void i40iw_cqp_manage_hmc_fcn_worker(struct work_struct *work) | |
836 | { | |
837 | struct i40iw_cqp_request *cqp_request = | |
838 | ((struct virtchnl_work *)work)->cqp_request; | |
839 | struct i40iw_ccq_cqe_info ccq_cqe_info; | |
840 | struct i40iw_hmc_fcn_info *hmcfcninfo = | |
841 | &cqp_request->info.in.u.manage_hmc_pm.info; | |
842 | struct i40iw_device *iwdev = | |
843 | (struct i40iw_device *)cqp_request->info.in.u.manage_hmc_pm.dev->back_dev; | |
844 | ||
845 | ccq_cqe_info.cqp = NULL; | |
846 | ccq_cqe_info.maj_err_code = cqp_request->compl_info.maj_err_code; | |
847 | ccq_cqe_info.min_err_code = cqp_request->compl_info.min_err_code; | |
848 | ccq_cqe_info.op_code = cqp_request->compl_info.op_code; | |
849 | ccq_cqe_info.op_ret_val = cqp_request->compl_info.op_ret_val; | |
850 | ccq_cqe_info.scratch = 0; | |
851 | ccq_cqe_info.error = cqp_request->compl_info.error; | |
852 | hmcfcninfo->callback_fcn(cqp_request->info.in.u.manage_hmc_pm.dev, | |
853 | hmcfcninfo->cqp_callback_param, &ccq_cqe_info); | |
854 | i40iw_put_cqp_request(&iwdev->cqp, cqp_request); | |
855 | } | |
856 | ||
857 | /** | |
858 | * i40iw_cqp_manage_hmc_fcn_callback - called function after cqp completion | |
859 | * @cqp_request: cqp request info struct for hmc fun | |
860 | * @unused: unused param of callback | |
861 | */ | |
862 | static void i40iw_cqp_manage_hmc_fcn_callback(struct i40iw_cqp_request *cqp_request, | |
863 | u32 unused) | |
864 | { | |
865 | struct virtchnl_work *work; | |
866 | struct i40iw_hmc_fcn_info *hmcfcninfo = | |
867 | &cqp_request->info.in.u.manage_hmc_pm.info; | |
868 | struct i40iw_device *iwdev = | |
869 | (struct i40iw_device *)cqp_request->info.in.u.manage_hmc_pm.dev-> | |
870 | back_dev; | |
871 | ||
872 | if (hmcfcninfo && hmcfcninfo->callback_fcn) { | |
873 | i40iw_debug(&iwdev->sc_dev, I40IW_DEBUG_HMC, "%s1\n", __func__); | |
874 | atomic_inc(&cqp_request->refcount); | |
875 | work = &iwdev->virtchnl_w[hmcfcninfo->iw_vf_idx]; | |
876 | work->cqp_request = cqp_request; | |
877 | INIT_WORK(&work->work, i40iw_cqp_manage_hmc_fcn_worker); | |
878 | queue_work(iwdev->virtchnl_wq, &work->work); | |
879 | i40iw_debug(&iwdev->sc_dev, I40IW_DEBUG_HMC, "%s2\n", __func__); | |
880 | } else { | |
881 | i40iw_debug(&iwdev->sc_dev, I40IW_DEBUG_HMC, "%s: Something wrong\n", __func__); | |
882 | } | |
883 | } | |
884 | ||
885 | /** | |
886 | * i40iw_cqp_manage_hmc_fcn_cmd - issue cqp command to manage hmc | |
887 | * @dev: hardware control device structure | |
888 | * @hmcfcninfo: info for hmc | |
889 | */ | |
890 | enum i40iw_status_code i40iw_cqp_manage_hmc_fcn_cmd(struct i40iw_sc_dev *dev, | |
891 | struct i40iw_hmc_fcn_info *hmcfcninfo) | |
892 | { | |
893 | enum i40iw_status_code status; | |
894 | struct i40iw_cqp_request *cqp_request; | |
895 | struct cqp_commands_info *cqp_info; | |
896 | struct i40iw_device *iwdev = (struct i40iw_device *)dev->back_dev; | |
897 | ||
898 | i40iw_debug(&iwdev->sc_dev, I40IW_DEBUG_HMC, "%s\n", __func__); | |
899 | cqp_request = i40iw_get_cqp_request(&iwdev->cqp, false); | |
900 | if (!cqp_request) | |
901 | return I40IW_ERR_NO_MEMORY; | |
902 | cqp_info = &cqp_request->info; | |
903 | cqp_request->callback_fcn = i40iw_cqp_manage_hmc_fcn_callback; | |
904 | cqp_request->param = hmcfcninfo; | |
905 | memcpy(&cqp_info->in.u.manage_hmc_pm.info, hmcfcninfo, | |
906 | sizeof(*hmcfcninfo)); | |
907 | cqp_info->in.u.manage_hmc_pm.dev = dev; | |
908 | cqp_info->cqp_cmd = OP_MANAGE_HMC_PM_FUNC_TABLE; | |
909 | cqp_info->post_sq = 1; | |
910 | cqp_info->in.u.manage_hmc_pm.scratch = (uintptr_t)cqp_request; | |
911 | status = i40iw_handle_cqp_op(iwdev, cqp_request); | |
912 | if (status) | |
913 | i40iw_pr_err("CQP-OP Manage HMC fail"); | |
914 | return status; | |
915 | } | |
916 | ||
917 | /** | |
918 | * i40iw_cqp_query_fpm_values_cmd - send cqp command for fpm | |
919 | * @iwdev: function device struct | |
920 | * @values_mem: buffer for fpm | |
921 | * @hmc_fn_id: function id for fpm | |
922 | */ | |
923 | enum i40iw_status_code i40iw_cqp_query_fpm_values_cmd(struct i40iw_sc_dev *dev, | |
924 | struct i40iw_dma_mem *values_mem, | |
925 | u8 hmc_fn_id) | |
926 | { | |
927 | enum i40iw_status_code status; | |
928 | struct i40iw_cqp_request *cqp_request; | |
929 | struct cqp_commands_info *cqp_info; | |
930 | struct i40iw_device *iwdev = (struct i40iw_device *)dev->back_dev; | |
931 | ||
932 | cqp_request = i40iw_get_cqp_request(&iwdev->cqp, true); | |
933 | if (!cqp_request) | |
934 | return I40IW_ERR_NO_MEMORY; | |
935 | cqp_info = &cqp_request->info; | |
936 | cqp_request->param = NULL; | |
937 | cqp_info->in.u.query_fpm_values.cqp = dev->cqp; | |
938 | cqp_info->in.u.query_fpm_values.fpm_values_pa = values_mem->pa; | |
939 | cqp_info->in.u.query_fpm_values.fpm_values_va = values_mem->va; | |
940 | cqp_info->in.u.query_fpm_values.hmc_fn_id = hmc_fn_id; | |
941 | cqp_info->cqp_cmd = OP_QUERY_FPM_VALUES; | |
942 | cqp_info->post_sq = 1; | |
943 | cqp_info->in.u.query_fpm_values.scratch = (uintptr_t)cqp_request; | |
944 | status = i40iw_handle_cqp_op(iwdev, cqp_request); | |
945 | if (status) | |
946 | i40iw_pr_err("CQP-OP Query FPM fail"); | |
947 | return status; | |
948 | } | |
949 | ||
950 | /** | |
951 | * i40iw_cqp_commit_fpm_values_cmd - commit fpm values in hw | |
952 | * @dev: hardware control device structure | |
953 | * @values_mem: buffer with fpm values | |
954 | * @hmc_fn_id: function id for fpm | |
955 | */ | |
956 | enum i40iw_status_code i40iw_cqp_commit_fpm_values_cmd(struct i40iw_sc_dev *dev, | |
957 | struct i40iw_dma_mem *values_mem, | |
958 | u8 hmc_fn_id) | |
959 | { | |
960 | enum i40iw_status_code status; | |
961 | struct i40iw_cqp_request *cqp_request; | |
962 | struct cqp_commands_info *cqp_info; | |
963 | struct i40iw_device *iwdev = (struct i40iw_device *)dev->back_dev; | |
964 | ||
965 | cqp_request = i40iw_get_cqp_request(&iwdev->cqp, true); | |
966 | if (!cqp_request) | |
967 | return I40IW_ERR_NO_MEMORY; | |
968 | cqp_info = &cqp_request->info; | |
969 | cqp_request->param = NULL; | |
970 | cqp_info->in.u.commit_fpm_values.cqp = dev->cqp; | |
971 | cqp_info->in.u.commit_fpm_values.fpm_values_pa = values_mem->pa; | |
972 | cqp_info->in.u.commit_fpm_values.fpm_values_va = values_mem->va; | |
973 | cqp_info->in.u.commit_fpm_values.hmc_fn_id = hmc_fn_id; | |
974 | cqp_info->cqp_cmd = OP_COMMIT_FPM_VALUES; | |
975 | cqp_info->post_sq = 1; | |
976 | cqp_info->in.u.commit_fpm_values.scratch = (uintptr_t)cqp_request; | |
977 | status = i40iw_handle_cqp_op(iwdev, cqp_request); | |
978 | if (status) | |
979 | i40iw_pr_err("CQP-OP Commit FPM fail"); | |
980 | return status; | |
981 | } | |
982 | ||
983 | /** | |
984 | * i40iw_vf_wait_vchnl_resp - wait for channel msg | |
985 | * @iwdev: function's device struct | |
986 | */ | |
987 | enum i40iw_status_code i40iw_vf_wait_vchnl_resp(struct i40iw_sc_dev *dev) | |
988 | { | |
989 | struct i40iw_device *iwdev = dev->back_dev; | |
4e9042e6 FL |
990 | int timeout_ret; |
991 | ||
992 | i40iw_debug(dev, I40IW_DEBUG_VIRT, "%s[%u] dev %p, iwdev %p\n", | |
993 | __func__, __LINE__, dev, iwdev); | |
f69c3331 IM |
994 | |
995 | atomic_set(&iwdev->vchnl_msgs, 2); | |
4e9042e6 FL |
996 | timeout_ret = wait_event_timeout(iwdev->vchnl_waitq, |
997 | (atomic_read(&iwdev->vchnl_msgs) == 1), | |
998 | I40IW_VCHNL_EVENT_TIMEOUT); | |
999 | atomic_dec(&iwdev->vchnl_msgs); | |
1000 | if (!timeout_ret) { | |
1001 | i40iw_pr_err("virt channel completion timeout = 0x%x\n", timeout_ret); | |
f69c3331 IM |
1002 | atomic_set(&iwdev->vchnl_msgs, 0); |
1003 | dev->vchnl_up = false; | |
1004 | return I40IW_ERR_TIMEOUT; | |
4e9042e6 | 1005 | } |
f69c3331 IM |
1006 | wake_up(&dev->vf_reqs); |
1007 | return 0; | |
4e9042e6 FL |
1008 | } |
1009 | ||
1010 | /** | |
1011 | * i40iw_ieq_mpa_crc_ae - generate AE for crc error | |
1012 | * @dev: hardware control device structure | |
1013 | * @qp: hardware control qp | |
1014 | */ | |
1015 | void i40iw_ieq_mpa_crc_ae(struct i40iw_sc_dev *dev, struct i40iw_sc_qp *qp) | |
1016 | { | |
1017 | struct i40iw_qp_flush_info info; | |
1018 | struct i40iw_device *iwdev = (struct i40iw_device *)dev->back_dev; | |
1019 | ||
1020 | i40iw_debug(dev, I40IW_DEBUG_AEQ, "%s entered\n", __func__); | |
1021 | memset(&info, 0, sizeof(info)); | |
1022 | info.ae_code = I40IW_AE_LLP_RECEIVED_MPA_CRC_ERROR; | |
1023 | info.generate_ae = true; | |
1024 | info.ae_source = 0x3; | |
1025 | (void)i40iw_hw_flush_wqes(iwdev, qp, &info, false); | |
1026 | } | |
1027 | ||
1028 | /** | |
1029 | * i40iw_init_hash_desc - initialize hash for crc calculation | |
1030 | * @desc: cryption type | |
1031 | */ | |
34abf9ed | 1032 | enum i40iw_status_code i40iw_init_hash_desc(struct shash_desc **desc) |
4e9042e6 | 1033 | { |
34abf9ed TN |
1034 | struct crypto_shash *tfm; |
1035 | struct shash_desc *tdesc; | |
1036 | ||
1037 | tfm = crypto_alloc_shash("crc32c", 0, 0); | |
1038 | if (IS_ERR(tfm)) | |
1039 | return I40IW_ERR_MPA_CRC; | |
1040 | ||
1041 | tdesc = kzalloc(sizeof(*tdesc) + crypto_shash_descsize(tfm), | |
1042 | GFP_KERNEL); | |
1043 | if (!tdesc) { | |
1044 | crypto_free_shash(tfm); | |
4e9042e6 | 1045 | return I40IW_ERR_MPA_CRC; |
34abf9ed TN |
1046 | } |
1047 | tdesc->tfm = tfm; | |
1048 | *desc = tdesc; | |
1049 | ||
4e9042e6 FL |
1050 | return 0; |
1051 | } | |
1052 | ||
1053 | /** | |
1054 | * i40iw_free_hash_desc - free hash desc | |
1055 | * @desc: to be freed | |
1056 | */ | |
34abf9ed | 1057 | void i40iw_free_hash_desc(struct shash_desc *desc) |
4e9042e6 | 1058 | { |
34abf9ed TN |
1059 | if (desc) { |
1060 | crypto_free_shash(desc->tfm); | |
1061 | kfree(desc); | |
1062 | } | |
4e9042e6 FL |
1063 | } |
1064 | ||
1065 | /** | |
1066 | * i40iw_alloc_query_fpm_buf - allocate buffer for fpm | |
1067 | * @dev: hardware control device structure | |
1068 | * @mem: buffer ptr for fpm to be allocated | |
1069 | * @return: memory allocation status | |
1070 | */ | |
1071 | enum i40iw_status_code i40iw_alloc_query_fpm_buf(struct i40iw_sc_dev *dev, | |
1072 | struct i40iw_dma_mem *mem) | |
1073 | { | |
1074 | enum i40iw_status_code status; | |
1075 | struct i40iw_device *iwdev = (struct i40iw_device *)dev->back_dev; | |
1076 | ||
1077 | status = i40iw_obj_aligned_mem(iwdev, mem, I40IW_QUERY_FPM_BUF_SIZE, | |
1078 | I40IW_FPM_QUERY_BUF_ALIGNMENT_MASK); | |
1079 | return status; | |
1080 | } | |
1081 | ||
1082 | /** | |
1083 | * i40iw_ieq_check_mpacrc - check if mpa crc is OK | |
1084 | * @desc: desc for hash | |
1085 | * @addr: address of buffer for crc | |
1086 | * @length: length of buffer | |
1087 | * @value: value to be compared | |
1088 | */ | |
34abf9ed | 1089 | enum i40iw_status_code i40iw_ieq_check_mpacrc(struct shash_desc *desc, |
4e9042e6 FL |
1090 | void *addr, |
1091 | u32 length, | |
1092 | u32 value) | |
1093 | { | |
4e9042e6 FL |
1094 | u32 crc = 0; |
1095 | int ret; | |
1096 | enum i40iw_status_code ret_code = 0; | |
1097 | ||
34abf9ed TN |
1098 | crypto_shash_init(desc); |
1099 | ret = crypto_shash_update(desc, addr, length); | |
4e9042e6 | 1100 | if (!ret) |
34abf9ed | 1101 | crypto_shash_final(desc, (u8 *)&crc); |
4e9042e6 FL |
1102 | if (crc != value) { |
1103 | i40iw_pr_err("mpa crc check fail\n"); | |
1104 | ret_code = I40IW_ERR_MPA_CRC; | |
1105 | } | |
1106 | return ret_code; | |
1107 | } | |
1108 | ||
1109 | /** | |
1110 | * i40iw_ieq_get_qp - get qp based on quad in puda buffer | |
1111 | * @dev: hardware control device structure | |
1112 | * @buf: receive puda buffer on exception q | |
1113 | */ | |
1114 | struct i40iw_sc_qp *i40iw_ieq_get_qp(struct i40iw_sc_dev *dev, | |
1115 | struct i40iw_puda_buf *buf) | |
1116 | { | |
1117 | struct i40iw_device *iwdev = (struct i40iw_device *)dev->back_dev; | |
1118 | struct i40iw_qp *iwqp; | |
1119 | struct i40iw_cm_node *cm_node; | |
1120 | u32 loc_addr[4], rem_addr[4]; | |
1121 | u16 loc_port, rem_port; | |
1122 | struct ipv6hdr *ip6h; | |
1123 | struct iphdr *iph = (struct iphdr *)buf->iph; | |
1124 | struct tcphdr *tcph = (struct tcphdr *)buf->tcph; | |
1125 | ||
1126 | if (iph->version == 4) { | |
1127 | memset(loc_addr, 0, sizeof(loc_addr)); | |
1128 | loc_addr[0] = ntohl(iph->daddr); | |
1129 | memset(rem_addr, 0, sizeof(rem_addr)); | |
1130 | rem_addr[0] = ntohl(iph->saddr); | |
1131 | } else { | |
1132 | ip6h = (struct ipv6hdr *)buf->iph; | |
1133 | i40iw_copy_ip_ntohl(loc_addr, ip6h->daddr.in6_u.u6_addr32); | |
1134 | i40iw_copy_ip_ntohl(rem_addr, ip6h->saddr.in6_u.u6_addr32); | |
1135 | } | |
1136 | loc_port = ntohs(tcph->dest); | |
1137 | rem_port = ntohs(tcph->source); | |
1138 | ||
1139 | cm_node = i40iw_find_node(&iwdev->cm_core, rem_port, rem_addr, loc_port, | |
1140 | loc_addr, false); | |
1141 | if (!cm_node) | |
1142 | return NULL; | |
1143 | iwqp = cm_node->iwqp; | |
1144 | return &iwqp->sc_qp; | |
1145 | } | |
1146 | ||
1147 | /** | |
1148 | * i40iw_ieq_update_tcpip_info - update tcpip in the buffer | |
1149 | * @buf: puda to update | |
1150 | * @length: length of buffer | |
1151 | * @seqnum: seq number for tcp | |
1152 | */ | |
1153 | void i40iw_ieq_update_tcpip_info(struct i40iw_puda_buf *buf, u16 length, u32 seqnum) | |
1154 | { | |
1155 | struct tcphdr *tcph; | |
1156 | struct iphdr *iph; | |
1157 | u16 iphlen; | |
1158 | u16 packetsize; | |
1159 | u8 *addr = (u8 *)buf->mem.va; | |
1160 | ||
1161 | iphlen = (buf->ipv4) ? 20 : 40; | |
1162 | iph = (struct iphdr *)(addr + buf->maclen); | |
1163 | tcph = (struct tcphdr *)(addr + buf->maclen + iphlen); | |
1164 | packetsize = length + buf->tcphlen + iphlen; | |
1165 | ||
1166 | iph->tot_len = htons(packetsize); | |
1167 | tcph->seq = htonl(seqnum); | |
1168 | } | |
1169 | ||
1170 | /** | |
1171 | * i40iw_puda_get_tcpip_info - get tcpip info from puda buffer | |
1172 | * @info: to get information | |
1173 | * @buf: puda buffer | |
1174 | */ | |
1175 | enum i40iw_status_code i40iw_puda_get_tcpip_info(struct i40iw_puda_completion_info *info, | |
1176 | struct i40iw_puda_buf *buf) | |
1177 | { | |
1178 | struct iphdr *iph; | |
1179 | struct ipv6hdr *ip6h; | |
1180 | struct tcphdr *tcph; | |
1181 | u16 iphlen; | |
1182 | u16 pkt_len; | |
1183 | u8 *mem = (u8 *)buf->mem.va; | |
1184 | struct ethhdr *ethh = (struct ethhdr *)buf->mem.va; | |
1185 | ||
1186 | if (ethh->h_proto == htons(0x8100)) { | |
1187 | info->vlan_valid = true; | |
1188 | buf->vlan_id = ntohs(((struct vlan_ethhdr *)ethh)->h_vlan_TCI) & VLAN_VID_MASK; | |
1189 | } | |
1190 | buf->maclen = (info->vlan_valid) ? 18 : 14; | |
1191 | iphlen = (info->l3proto) ? 40 : 20; | |
1192 | buf->ipv4 = (info->l3proto) ? false : true; | |
1193 | buf->iph = mem + buf->maclen; | |
1194 | iph = (struct iphdr *)buf->iph; | |
1195 | ||
1196 | buf->tcph = buf->iph + iphlen; | |
1197 | tcph = (struct tcphdr *)buf->tcph; | |
1198 | ||
1199 | if (buf->ipv4) { | |
1200 | pkt_len = ntohs(iph->tot_len); | |
1201 | } else { | |
1202 | ip6h = (struct ipv6hdr *)buf->iph; | |
1203 | pkt_len = ntohs(ip6h->payload_len) + iphlen; | |
1204 | } | |
1205 | ||
1206 | buf->totallen = pkt_len + buf->maclen; | |
1207 | ||
1208 | if (info->payload_len < buf->totallen - 4) { | |
1209 | i40iw_pr_err("payload_len = 0x%x totallen expected0x%x\n", | |
1210 | info->payload_len, buf->totallen); | |
1211 | return I40IW_ERR_INVALID_SIZE; | |
1212 | } | |
1213 | ||
1214 | buf->tcphlen = (tcph->doff) << 2; | |
1215 | buf->datalen = pkt_len - iphlen - buf->tcphlen; | |
1216 | buf->data = (buf->datalen) ? buf->tcph + buf->tcphlen : NULL; | |
1217 | buf->hdrlen = buf->maclen + iphlen + buf->tcphlen; | |
1218 | buf->seqnum = ntohl(tcph->seq); | |
1219 | return 0; | |
1220 | } | |
1221 | ||
1222 | /** | |
1223 | * i40iw_hw_stats_timeout - Stats timer-handler which updates all HW stats | |
1224 | * @dev: hardware control device structure | |
1225 | */ | |
1226 | static void i40iw_hw_stats_timeout(unsigned long dev) | |
1227 | { | |
1228 | struct i40iw_sc_dev *pf_dev = (struct i40iw_sc_dev *)dev; | |
1229 | struct i40iw_dev_pestat *pf_devstat = &pf_dev->dev_pestat; | |
1230 | struct i40iw_dev_pestat *vf_devstat = NULL; | |
1231 | u16 iw_vf_idx; | |
1232 | unsigned long flags; | |
1233 | ||
1234 | /*PF*/ | |
1235 | pf_devstat->ops.iw_hw_stat_read_all(pf_devstat, &pf_devstat->hw_stats); | |
1236 | for (iw_vf_idx = 0; iw_vf_idx < I40IW_MAX_PE_ENABLED_VF_COUNT; iw_vf_idx++) { | |
1237 | spin_lock_irqsave(&pf_devstat->stats_lock, flags); | |
1238 | if (pf_dev->vf_dev[iw_vf_idx]) { | |
1239 | if (pf_dev->vf_dev[iw_vf_idx]->stats_initialized) { | |
1240 | vf_devstat = &pf_dev->vf_dev[iw_vf_idx]->dev_pestat; | |
1241 | vf_devstat->ops.iw_hw_stat_read_all(vf_devstat, &vf_devstat->hw_stats); | |
1242 | } | |
1243 | } | |
1244 | spin_unlock_irqrestore(&pf_devstat->stats_lock, flags); | |
1245 | } | |
1246 | ||
1247 | mod_timer(&pf_devstat->stats_timer, | |
1248 | jiffies + msecs_to_jiffies(STATS_TIMER_DELAY)); | |
1249 | } | |
1250 | ||
1251 | /** | |
1252 | * i40iw_hw_stats_start_timer - Start periodic stats timer | |
1253 | * @dev: hardware control device structure | |
1254 | */ | |
1255 | void i40iw_hw_stats_start_timer(struct i40iw_sc_dev *dev) | |
1256 | { | |
1257 | struct i40iw_dev_pestat *devstat = &dev->dev_pestat; | |
1258 | ||
1259 | init_timer(&devstat->stats_timer); | |
1260 | devstat->stats_timer.function = i40iw_hw_stats_timeout; | |
1261 | devstat->stats_timer.data = (unsigned long)dev; | |
1262 | mod_timer(&devstat->stats_timer, | |
1263 | jiffies + msecs_to_jiffies(STATS_TIMER_DELAY)); | |
1264 | } | |
1265 | ||
1266 | /** | |
1267 | * i40iw_hw_stats_del_timer - Delete periodic stats timer | |
1268 | * @dev: hardware control device structure | |
1269 | */ | |
1270 | void i40iw_hw_stats_del_timer(struct i40iw_sc_dev *dev) | |
1271 | { | |
1272 | struct i40iw_dev_pestat *devstat = &dev->dev_pestat; | |
1273 | ||
1274 | del_timer_sync(&devstat->stats_timer); | |
1275 | } |