1 /*******************************************************************************
3 * Copyright (c) 2015-2016 Intel Corporation. All rights reserved.
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:
11 * Redistribution and use in source and binary forms, with or
12 * without modification, are permitted provided that the following
15 * - Redistributions of source code must retain the above
16 * copyright notice, this list of conditions and the following
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.
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
33 *******************************************************************************/
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>
45 #include <linux/tcp.h>
46 #include <linux/init.h>
49 #include <asm/byteorder.h>
50 #include <net/netevent.h>
51 #include <net/neighbour.h>
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
61 int i40iw_arp_table(struct i40iw_device
*iwdev
,
72 memset(ip
, 0, sizeof(ip
));
75 memcpy(ip
, ip_addr
, sizeof(ip
));
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)
83 if (arp_index
!= iwdev
->arp_table_size
)
87 err
= i40iw_alloc_resource(iwdev
, iwdev
->allocated_arps
,
88 iwdev
->arp_table_size
,
90 &iwdev
->next_arp_index
);
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
);
98 case I40IW_ARP_RESOLVE
:
99 if (arp_index
== iwdev
->arp_table_size
)
102 case I40IW_ARP_DELETE
:
103 if (arp_index
== iwdev
->arp_table_size
)
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
);
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
122 inline void i40iw_wr32(struct i40iw_hw
*hw
, u32 reg
, u32 value
)
124 writel(value
, hw
->hw_addr
+ reg
);
128 * i40iw_rd32 - read a 32 bit hw register
129 * @hw: hardware information including registers
130 * @reg: register offset
132 * Return value of register content
134 inline u32
i40iw_rd32(struct i40iw_hw
*hw
, u32 reg
)
136 return readl(hw
->hw_addr
+ reg
);
140 * i40iw_inetaddr_event - system notifier for netdev events
142 * @event: event for notifier
145 int i40iw_inetaddr_event(struct notifier_block
*notifier
,
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
;
156 u32 action
= I40IW_ARP_ADD
;
158 hdl
= i40iw_find_netdev(event_netdev
);
162 iwdev
= &hdl
->device
;
163 if (iwdev
->init_state
< IP_ADDR_REGISTERED
|| iwdev
->closing
)
166 netdev
= iwdev
->ldev
->netdev
;
167 upper_dev
= netdev_master_upper_dev_get(netdev
);
168 if (netdev
!= event_netdev
)
172 local_ipaddr
= ntohl(
173 ((struct in_device
*)upper_dev
->ip_ptr
)->ifa_list
->ifa_address
);
175 local_ipaddr
= ntohl(ifa
->ifa_address
);
178 action
= I40IW_ARP_DELETE
;
182 case NETDEV_CHANGEADDR
:
183 i40iw_manage_arp_cache(iwdev
,
188 i40iw_if_notify(iwdev
, netdev
, &local_ipaddr
, true,
189 (action
== I40IW_ARP_ADD
) ? true : false);
198 * i40iw_inet6addr_event - system notifier for ipv6 netdev events
200 * @event: event for notifier
203 int i40iw_inet6addr_event(struct notifier_block
*notifier
,
207 struct inet6_ifaddr
*ifa
= (struct inet6_ifaddr
*)ptr
;
208 struct net_device
*event_netdev
= ifa
->idev
->dev
;
209 struct net_device
*netdev
;
210 struct i40iw_device
*iwdev
;
211 struct i40iw_handler
*hdl
;
212 u32 local_ipaddr6
[4];
213 u32 action
= I40IW_ARP_ADD
;
215 hdl
= i40iw_find_netdev(event_netdev
);
219 iwdev
= &hdl
->device
;
220 if (iwdev
->init_state
< IP_ADDR_REGISTERED
|| iwdev
->closing
)
223 netdev
= iwdev
->ldev
->netdev
;
224 if (netdev
!= event_netdev
)
227 i40iw_copy_ip_ntohl(local_ipaddr6
, ifa
->addr
.in6_u
.u6_addr32
);
230 action
= I40IW_ARP_DELETE
;
234 case NETDEV_CHANGEADDR
:
235 i40iw_manage_arp_cache(iwdev
,
240 i40iw_if_notify(iwdev
, netdev
, local_ipaddr6
, false,
241 (action
== I40IW_ARP_ADD
) ? true : false);
250 * i40iw_net_event - system notifier for net events
252 * @event: event for notifier
255 int i40iw_net_event(struct notifier_block
*notifier
, unsigned long event
, void *ptr
)
257 struct neighbour
*neigh
= ptr
;
258 struct i40iw_device
*iwdev
;
259 struct i40iw_handler
*iwhdl
;
264 case NETEVENT_NEIGH_UPDATE
:
265 iwhdl
= i40iw_find_netdev((struct net_device
*)neigh
->dev
);
268 iwdev
= &iwhdl
->device
;
269 if (iwdev
->init_state
< IP_ADDR_REGISTERED
|| iwdev
->closing
)
271 p
= (__be32
*)neigh
->primary_key
;
272 i40iw_copy_ip_ntohl(local_ipaddr
, p
);
273 if (neigh
->nud_state
& NUD_VALID
) {
274 i40iw_manage_arp_cache(iwdev
,
281 i40iw_manage_arp_cache(iwdev
,
295 * i40iw_get_cqp_request - get cqp struct
296 * @cqp: device cqp ptr
297 * @wait: cqp to be used in wait mode
299 struct i40iw_cqp_request
*i40iw_get_cqp_request(struct i40iw_cqp
*cqp
, bool wait
)
301 struct i40iw_cqp_request
*cqp_request
= NULL
;
304 spin_lock_irqsave(&cqp
->req_lock
, flags
);
305 if (!list_empty(&cqp
->cqp_avail_reqs
)) {
306 cqp_request
= list_entry(cqp
->cqp_avail_reqs
.next
,
307 struct i40iw_cqp_request
, list
);
308 list_del_init(&cqp_request
->list
);
310 spin_unlock_irqrestore(&cqp
->req_lock
, flags
);
312 cqp_request
= kzalloc(sizeof(*cqp_request
), GFP_ATOMIC
);
314 cqp_request
->dynamic
= true;
315 INIT_LIST_HEAD(&cqp_request
->list
);
316 init_waitqueue_head(&cqp_request
->waitq
);
320 i40iw_pr_err("CQP Request Fail: No Memory");
325 atomic_set(&cqp_request
->refcount
, 2);
326 cqp_request
->waiting
= true;
328 atomic_set(&cqp_request
->refcount
, 1);
334 * i40iw_free_cqp_request - free cqp request
336 * @cqp_request: to be put back in cqp list
338 void i40iw_free_cqp_request(struct i40iw_cqp
*cqp
, struct i40iw_cqp_request
*cqp_request
)
340 struct i40iw_device
*iwdev
= container_of(cqp
, struct i40iw_device
, cqp
);
343 if (cqp_request
->dynamic
) {
346 cqp_request
->request_done
= false;
347 cqp_request
->callback_fcn
= NULL
;
348 cqp_request
->waiting
= false;
350 spin_lock_irqsave(&cqp
->req_lock
, flags
);
351 list_add_tail(&cqp_request
->list
, &cqp
->cqp_avail_reqs
);
352 spin_unlock_irqrestore(&cqp
->req_lock
, flags
);
354 wake_up(&iwdev
->close_wq
);
358 * i40iw_put_cqp_request - dec ref count and free if 0
360 * @cqp_request: to be put back in cqp list
362 void i40iw_put_cqp_request(struct i40iw_cqp
*cqp
,
363 struct i40iw_cqp_request
*cqp_request
)
365 if (atomic_dec_and_test(&cqp_request
->refcount
))
366 i40iw_free_cqp_request(cqp
, cqp_request
);
370 * i40iw_free_pending_cqp_request -free pending cqp request objs
372 * @cqp_request: to be put back in cqp list
374 static void i40iw_free_pending_cqp_request(struct i40iw_cqp
*cqp
,
375 struct i40iw_cqp_request
*cqp_request
)
377 struct i40iw_device
*iwdev
= container_of(cqp
, struct i40iw_device
, cqp
);
379 if (cqp_request
->waiting
) {
380 cqp_request
->compl_info
.error
= true;
381 cqp_request
->request_done
= true;
382 wake_up(&cqp_request
->waitq
);
384 i40iw_put_cqp_request(cqp
, cqp_request
);
385 wait_event_timeout(iwdev
->close_wq
,
386 !atomic_read(&cqp_request
->refcount
),
391 * i40iw_cleanup_pending_cqp_op - clean-up cqp with no completions
392 * @iwdev: iwarp device
394 void i40iw_cleanup_pending_cqp_op(struct i40iw_device
*iwdev
)
396 struct i40iw_sc_dev
*dev
= &iwdev
->sc_dev
;
397 struct i40iw_cqp
*cqp
= &iwdev
->cqp
;
398 struct i40iw_cqp_request
*cqp_request
= NULL
;
399 struct cqp_commands_info
*pcmdinfo
= NULL
;
400 u32 i
, pending_work
, wqe_idx
;
402 pending_work
= I40IW_RING_WORK_AVAILABLE(cqp
->sc_cqp
.sq_ring
);
403 wqe_idx
= I40IW_RING_GETCURRENT_TAIL(cqp
->sc_cqp
.sq_ring
);
404 for (i
= 0; i
< pending_work
; i
++) {
405 cqp_request
= (struct i40iw_cqp_request
*)(unsigned long)cqp
->scratch_array
[wqe_idx
];
407 i40iw_free_pending_cqp_request(cqp
, cqp_request
);
408 wqe_idx
= (wqe_idx
+ 1) % I40IW_RING_GETSIZE(cqp
->sc_cqp
.sq_ring
);
411 while (!list_empty(&dev
->cqp_cmd_head
)) {
412 pcmdinfo
= (struct cqp_commands_info
*)i40iw_remove_head(&dev
->cqp_cmd_head
);
413 cqp_request
= container_of(pcmdinfo
, struct i40iw_cqp_request
, info
);
415 i40iw_free_pending_cqp_request(cqp
, cqp_request
);
420 * i40iw_free_qp - callback after destroy cqp completes
421 * @cqp_request: cqp request for destroy qp
424 static void i40iw_free_qp(struct i40iw_cqp_request
*cqp_request
, u32 num
)
426 struct i40iw_sc_qp
*qp
= (struct i40iw_sc_qp
*)cqp_request
->param
;
427 struct i40iw_qp
*iwqp
= (struct i40iw_qp
*)qp
->back_qp
;
428 struct i40iw_device
*iwdev
;
429 u32 qp_num
= iwqp
->ibqp
.qp_num
;
433 i40iw_rem_pdusecount(iwqp
->iwpd
, iwdev
);
434 i40iw_free_qp_resources(iwdev
, iwqp
, qp_num
);
435 i40iw_rem_devusecount(iwdev
);
439 * i40iw_wait_event - wait for completion
440 * @iwdev: iwarp device
441 * @cqp_request: cqp request to wait
443 static int i40iw_wait_event(struct i40iw_device
*iwdev
,
444 struct i40iw_cqp_request
*cqp_request
)
446 struct cqp_commands_info
*info
= &cqp_request
->info
;
447 struct i40iw_cqp
*iwcqp
= &iwdev
->cqp
;
448 struct i40iw_cqp_timeout cqp_timeout
;
449 bool cqp_error
= false;
451 memset(&cqp_timeout
, 0, sizeof(cqp_timeout
));
452 cqp_timeout
.compl_cqp_cmds
= iwdev
->sc_dev
.cqp_cmd_stats
[OP_COMPLETED_COMMANDS
];
454 if (wait_event_timeout(cqp_request
->waitq
,
455 cqp_request
->request_done
, CQP_COMPL_WAIT_TIME
))
458 i40iw_check_cqp_progress(&cqp_timeout
, &iwdev
->sc_dev
);
460 if (cqp_timeout
.count
< CQP_TIMEOUT_THRESHOLD
)
463 i40iw_pr_err("error cqp command 0x%x timed out", info
->cqp_cmd
);
467 i40iw_request_reset(iwdev
);
471 cqp_error
= cqp_request
->compl_info
.error
;
473 i40iw_pr_err("error cqp command 0x%x completion maj = 0x%x min=0x%x\n",
474 info
->cqp_cmd
, cqp_request
->compl_info
.maj_err_code
,
475 cqp_request
->compl_info
.min_err_code
);
480 i40iw_put_cqp_request(iwcqp
, cqp_request
);
485 * i40iw_handle_cqp_op - process cqp command
486 * @iwdev: iwarp device
487 * @cqp_request: cqp request to process
489 enum i40iw_status_code
i40iw_handle_cqp_op(struct i40iw_device
*iwdev
,
490 struct i40iw_cqp_request
493 struct i40iw_sc_dev
*dev
= &iwdev
->sc_dev
;
494 enum i40iw_status_code status
;
495 struct cqp_commands_info
*info
= &cqp_request
->info
;
499 i40iw_free_cqp_request(&iwdev
->cqp
, cqp_request
);
500 return I40IW_ERR_CQP_COMPL_ERROR
;
503 status
= i40iw_process_cqp_cmd(dev
, info
);
505 i40iw_pr_err("error cqp command 0x%x failed\n", info
->cqp_cmd
);
506 i40iw_free_cqp_request(&iwdev
->cqp
, cqp_request
);
509 if (cqp_request
->waiting
)
510 err_code
= i40iw_wait_event(iwdev
, cqp_request
);
512 status
= I40IW_ERR_CQP_COMPL_ERROR
;
517 * i40iw_add_devusecount - add dev refcount
518 * @iwdev: dev for refcount
520 void i40iw_add_devusecount(struct i40iw_device
*iwdev
)
522 atomic64_inc(&iwdev
->use_count
);
526 * i40iw_rem_devusecount - decrement refcount for dev
529 void i40iw_rem_devusecount(struct i40iw_device
*iwdev
)
531 if (!atomic64_dec_and_test(&iwdev
->use_count
))
533 wake_up(&iwdev
->close_wq
);
537 * i40iw_add_pdusecount - add pd refcount
538 * @iwpd: pd for refcount
540 void i40iw_add_pdusecount(struct i40iw_pd
*iwpd
)
542 atomic_inc(&iwpd
->usecount
);
546 * i40iw_rem_pdusecount - decrement refcount for pd and free if 0
547 * @iwpd: pd for refcount
548 * @iwdev: iwarp device
550 void i40iw_rem_pdusecount(struct i40iw_pd
*iwpd
, struct i40iw_device
*iwdev
)
552 if (!atomic_dec_and_test(&iwpd
->usecount
))
554 i40iw_free_resource(iwdev
, iwdev
->allocated_pds
, iwpd
->sc_pd
.pd_id
);
559 * i40iw_add_ref - add refcount for qp
562 void i40iw_add_ref(struct ib_qp
*ibqp
)
564 struct i40iw_qp
*iwqp
= (struct i40iw_qp
*)ibqp
;
566 atomic_inc(&iwqp
->refcount
);
570 * i40iw_rem_ref - rem refcount for qp and free if 0
573 void i40iw_rem_ref(struct ib_qp
*ibqp
)
575 struct i40iw_qp
*iwqp
;
576 enum i40iw_status_code status
;
577 struct i40iw_cqp_request
*cqp_request
;
578 struct cqp_commands_info
*cqp_info
;
579 struct i40iw_device
*iwdev
;
583 iwqp
= to_iwqp(ibqp
);
585 spin_lock_irqsave(&iwdev
->qptable_lock
, flags
);
586 if (!atomic_dec_and_test(&iwqp
->refcount
)) {
587 spin_unlock_irqrestore(&iwdev
->qptable_lock
, flags
);
591 qp_num
= iwqp
->ibqp
.qp_num
;
592 iwdev
->qp_table
[qp_num
] = NULL
;
593 spin_unlock_irqrestore(&iwdev
->qptable_lock
, flags
);
594 cqp_request
= i40iw_get_cqp_request(&iwdev
->cqp
, false);
598 cqp_request
->callback_fcn
= i40iw_free_qp
;
599 cqp_request
->param
= (void *)&iwqp
->sc_qp
;
600 cqp_info
= &cqp_request
->info
;
601 cqp_info
->cqp_cmd
= OP_QP_DESTROY
;
602 cqp_info
->post_sq
= 1;
603 cqp_info
->in
.u
.qp_destroy
.qp
= &iwqp
->sc_qp
;
604 cqp_info
->in
.u
.qp_destroy
.scratch
= (uintptr_t)cqp_request
;
605 cqp_info
->in
.u
.qp_destroy
.remove_hash_idx
= true;
606 status
= i40iw_handle_cqp_op(iwdev
, cqp_request
);
610 i40iw_rem_pdusecount(iwqp
->iwpd
, iwdev
);
611 i40iw_free_qp_resources(iwdev
, iwqp
, qp_num
);
612 i40iw_rem_devusecount(iwdev
);
616 * i40iw_get_qp - get qp address
617 * @device: iwarp device
620 struct ib_qp
*i40iw_get_qp(struct ib_device
*device
, int qpn
)
622 struct i40iw_device
*iwdev
= to_iwdev(device
);
624 if ((qpn
< IW_FIRST_QPN
) || (qpn
>= iwdev
->max_qp
))
627 return &iwdev
->qp_table
[qpn
]->ibqp
;
631 * i40iw_debug_buf - print debug msg and buffer is mask set
632 * @dev: hardware control device structure
633 * @mask: mask to compare if to print debug buffer
634 * @buf: points buffer addr
635 * @size: saize of buffer to print
637 void i40iw_debug_buf(struct i40iw_sc_dev
*dev
,
638 enum i40iw_debug_flag mask
,
645 if (!(dev
->debug_mask
& mask
))
647 i40iw_debug(dev
, mask
, "%s\n", desc
);
648 i40iw_debug(dev
, mask
, "starting address virt=%p phy=%llxh\n", buf
,
649 (unsigned long long)virt_to_phys(buf
));
651 for (i
= 0; i
< size
; i
+= 8)
652 i40iw_debug(dev
, mask
, "index %03d val: %016llx\n", i
, buf
[i
/ 8]);
656 * i40iw_get_hw_addr - return hw addr
657 * @par: points to shared dev
659 u8 __iomem
*i40iw_get_hw_addr(void *par
)
661 struct i40iw_sc_dev
*dev
= (struct i40iw_sc_dev
*)par
;
663 return dev
->hw
->hw_addr
;
667 * i40iw_remove_head - return head entry and remove from list
668 * @list: list for entry
670 void *i40iw_remove_head(struct list_head
*list
)
672 struct list_head
*entry
;
674 if (list_empty(list
))
677 entry
= (void *)list
->next
;
679 return (void *)entry
;
683 * i40iw_allocate_dma_mem - Memory alloc helper fn
684 * @hw: pointer to the HW structure
685 * @mem: ptr to mem struct to fill out
686 * @size: size of memory requested
687 * @alignment: what to align the allocation to
689 enum i40iw_status_code
i40iw_allocate_dma_mem(struct i40iw_hw
*hw
,
690 struct i40iw_dma_mem
*mem
,
694 struct pci_dev
*pcidev
= (struct pci_dev
*)hw
->dev_context
;
697 return I40IW_ERR_PARAM
;
698 mem
->size
= ALIGN(size
, alignment
);
699 mem
->va
= dma_zalloc_coherent(&pcidev
->dev
, mem
->size
,
700 (dma_addr_t
*)&mem
->pa
, GFP_KERNEL
);
702 return I40IW_ERR_NO_MEMORY
;
707 * i40iw_free_dma_mem - Memory free helper fn
708 * @hw: pointer to the HW structure
709 * @mem: ptr to mem struct to free
711 void i40iw_free_dma_mem(struct i40iw_hw
*hw
, struct i40iw_dma_mem
*mem
)
713 struct pci_dev
*pcidev
= (struct pci_dev
*)hw
->dev_context
;
715 if (!mem
|| !mem
->va
)
718 dma_free_coherent(&pcidev
->dev
, mem
->size
,
719 mem
->va
, (dma_addr_t
)mem
->pa
);
724 * i40iw_allocate_virt_mem - virtual memory alloc helper fn
725 * @hw: pointer to the HW structure
726 * @mem: ptr to mem struct to fill out
727 * @size: size of memory requested
729 enum i40iw_status_code
i40iw_allocate_virt_mem(struct i40iw_hw
*hw
,
730 struct i40iw_virt_mem
*mem
,
734 return I40IW_ERR_PARAM
;
737 mem
->va
= kzalloc(size
, GFP_KERNEL
);
742 return I40IW_ERR_NO_MEMORY
;
746 * i40iw_free_virt_mem - virtual memory free helper fn
747 * @hw: pointer to the HW structure
748 * @mem: ptr to mem struct to free
750 enum i40iw_status_code
i40iw_free_virt_mem(struct i40iw_hw
*hw
,
751 struct i40iw_virt_mem
*mem
)
754 return I40IW_ERR_PARAM
;
756 * mem->va points to the parent of mem, so both mem and mem->va
757 * can not be touched once mem->va is freed
764 * i40iw_cqp_sds_cmd - create cqp command for sd
765 * @dev: hardware control device structure
766 * @sd_info: information for sd cqp
769 enum i40iw_status_code
i40iw_cqp_sds_cmd(struct i40iw_sc_dev
*dev
,
770 struct i40iw_update_sds_info
*sdinfo
)
772 enum i40iw_status_code status
;
773 struct i40iw_cqp_request
*cqp_request
;
774 struct cqp_commands_info
*cqp_info
;
775 struct i40iw_device
*iwdev
= (struct i40iw_device
*)dev
->back_dev
;
777 cqp_request
= i40iw_get_cqp_request(&iwdev
->cqp
, true);
779 return I40IW_ERR_NO_MEMORY
;
780 cqp_info
= &cqp_request
->info
;
781 memcpy(&cqp_info
->in
.u
.update_pe_sds
.info
, sdinfo
,
782 sizeof(cqp_info
->in
.u
.update_pe_sds
.info
));
783 cqp_info
->cqp_cmd
= OP_UPDATE_PE_SDS
;
784 cqp_info
->post_sq
= 1;
785 cqp_info
->in
.u
.update_pe_sds
.dev
= dev
;
786 cqp_info
->in
.u
.update_pe_sds
.scratch
= (uintptr_t)cqp_request
;
787 status
= i40iw_handle_cqp_op(iwdev
, cqp_request
);
789 i40iw_pr_err("CQP-OP Update SD's fail");
794 * i40iw_qp_suspend_resume - cqp command for suspend/resume
795 * @dev: hardware control device structure
796 * @qp: hardware control qp
797 * @suspend: flag if suspend or resume
799 void i40iw_qp_suspend_resume(struct i40iw_sc_dev
*dev
, struct i40iw_sc_qp
*qp
, bool suspend
)
801 struct i40iw_device
*iwdev
= (struct i40iw_device
*)dev
->back_dev
;
802 struct i40iw_cqp_request
*cqp_request
;
803 struct i40iw_sc_cqp
*cqp
= dev
->cqp
;
804 struct cqp_commands_info
*cqp_info
;
805 enum i40iw_status_code status
;
807 cqp_request
= i40iw_get_cqp_request(&iwdev
->cqp
, false);
811 cqp_info
= &cqp_request
->info
;
812 cqp_info
->cqp_cmd
= (suspend
) ? OP_SUSPEND
: OP_RESUME
;
813 cqp_info
->in
.u
.suspend_resume
.cqp
= cqp
;
814 cqp_info
->in
.u
.suspend_resume
.qp
= qp
;
815 cqp_info
->in
.u
.suspend_resume
.scratch
= (uintptr_t)cqp_request
;
816 status
= i40iw_handle_cqp_op(iwdev
, cqp_request
);
818 i40iw_pr_err("CQP-OP QP Suspend/Resume fail");
822 * i40iw_term_modify_qp - modify qp for term message
823 * @qp: hardware control qp
824 * @next_state: qp's next state
825 * @term: terminate code
828 void i40iw_term_modify_qp(struct i40iw_sc_qp
*qp
, u8 next_state
, u8 term
, u8 term_len
)
830 struct i40iw_qp
*iwqp
;
832 iwqp
= (struct i40iw_qp
*)qp
->back_qp
;
833 i40iw_next_iw_state(iwqp
, next_state
, 0, term
, term_len
);
837 * i40iw_terminate_done - after terminate is completed
838 * @qp: hardware control qp
839 * @timeout_occurred: indicates if terminate timer expired
841 void i40iw_terminate_done(struct i40iw_sc_qp
*qp
, int timeout_occurred
)
843 struct i40iw_qp
*iwqp
;
844 u32 next_iwarp_state
= I40IW_QP_STATE_ERROR
;
849 iwqp
= (struct i40iw_qp
*)qp
->back_qp
;
850 spin_lock_irqsave(&iwqp
->lock
, flags
);
851 if (iwqp
->hte_added
) {
855 first_time
= !(qp
->term_flags
& I40IW_TERM_DONE
);
856 qp
->term_flags
|= I40IW_TERM_DONE
;
857 spin_unlock_irqrestore(&iwqp
->lock
, flags
);
859 if (!timeout_occurred
)
860 i40iw_terminate_del_timer(qp
);
862 next_iwarp_state
= I40IW_QP_STATE_CLOSING
;
864 i40iw_next_iw_state(iwqp
, next_iwarp_state
, hte
, 0, 0);
865 i40iw_cm_disconn(iwqp
);
870 * i40iw_terminate_imeout - timeout happened
871 * @context: points to iwarp qp
873 static void i40iw_terminate_timeout(unsigned long context
)
875 struct i40iw_qp
*iwqp
= (struct i40iw_qp
*)context
;
876 struct i40iw_sc_qp
*qp
= (struct i40iw_sc_qp
*)&iwqp
->sc_qp
;
878 i40iw_terminate_done(qp
, 1);
879 i40iw_rem_ref(&iwqp
->ibqp
);
883 * i40iw_terminate_start_timer - start terminate timeout
884 * @qp: hardware control qp
886 void i40iw_terminate_start_timer(struct i40iw_sc_qp
*qp
)
888 struct i40iw_qp
*iwqp
;
890 iwqp
= (struct i40iw_qp
*)qp
->back_qp
;
891 i40iw_add_ref(&iwqp
->ibqp
);
892 setup_timer(&iwqp
->terminate_timer
, i40iw_terminate_timeout
,
893 (unsigned long)iwqp
);
894 iwqp
->terminate_timer
.expires
= jiffies
+ HZ
;
895 add_timer(&iwqp
->terminate_timer
);
899 * i40iw_terminate_del_timer - delete terminate timeout
900 * @qp: hardware control qp
902 void i40iw_terminate_del_timer(struct i40iw_sc_qp
*qp
)
904 struct i40iw_qp
*iwqp
;
906 iwqp
= (struct i40iw_qp
*)qp
->back_qp
;
907 if (del_timer(&iwqp
->terminate_timer
))
908 i40iw_rem_ref(&iwqp
->ibqp
);
912 * i40iw_cqp_generic_worker - generic worker for cqp
913 * @work: work pointer
915 static void i40iw_cqp_generic_worker(struct work_struct
*work
)
917 struct i40iw_virtchnl_work_info
*work_info
=
918 &((struct virtchnl_work
*)work
)->work_info
;
920 if (work_info
->worker_vf_dev
)
921 work_info
->callback_fcn(work_info
->worker_vf_dev
);
925 * i40iw_cqp_spawn_worker - spawn worket thread
926 * @iwdev: device struct pointer
927 * @work_info: work request info
928 * @iw_vf_idx: virtual function index
930 void i40iw_cqp_spawn_worker(struct i40iw_sc_dev
*dev
,
931 struct i40iw_virtchnl_work_info
*work_info
,
934 struct virtchnl_work
*work
;
935 struct i40iw_device
*iwdev
= (struct i40iw_device
*)dev
->back_dev
;
937 work
= &iwdev
->virtchnl_w
[iw_vf_idx
];
938 memcpy(&work
->work_info
, work_info
, sizeof(*work_info
));
939 INIT_WORK(&work
->work
, i40iw_cqp_generic_worker
);
940 queue_work(iwdev
->virtchnl_wq
, &work
->work
);
944 * i40iw_cqp_manage_hmc_fcn_worker -
945 * @work: work pointer for hmc info
947 static void i40iw_cqp_manage_hmc_fcn_worker(struct work_struct
*work
)
949 struct i40iw_cqp_request
*cqp_request
=
950 ((struct virtchnl_work
*)work
)->cqp_request
;
951 struct i40iw_ccq_cqe_info ccq_cqe_info
;
952 struct i40iw_hmc_fcn_info
*hmcfcninfo
=
953 &cqp_request
->info
.in
.u
.manage_hmc_pm
.info
;
954 struct i40iw_device
*iwdev
=
955 (struct i40iw_device
*)cqp_request
->info
.in
.u
.manage_hmc_pm
.dev
->back_dev
;
957 ccq_cqe_info
.cqp
= NULL
;
958 ccq_cqe_info
.maj_err_code
= cqp_request
->compl_info
.maj_err_code
;
959 ccq_cqe_info
.min_err_code
= cqp_request
->compl_info
.min_err_code
;
960 ccq_cqe_info
.op_code
= cqp_request
->compl_info
.op_code
;
961 ccq_cqe_info
.op_ret_val
= cqp_request
->compl_info
.op_ret_val
;
962 ccq_cqe_info
.scratch
= 0;
963 ccq_cqe_info
.error
= cqp_request
->compl_info
.error
;
964 hmcfcninfo
->callback_fcn(cqp_request
->info
.in
.u
.manage_hmc_pm
.dev
,
965 hmcfcninfo
->cqp_callback_param
, &ccq_cqe_info
);
966 i40iw_put_cqp_request(&iwdev
->cqp
, cqp_request
);
970 * i40iw_cqp_manage_hmc_fcn_callback - called function after cqp completion
971 * @cqp_request: cqp request info struct for hmc fun
972 * @unused: unused param of callback
974 static void i40iw_cqp_manage_hmc_fcn_callback(struct i40iw_cqp_request
*cqp_request
,
977 struct virtchnl_work
*work
;
978 struct i40iw_hmc_fcn_info
*hmcfcninfo
=
979 &cqp_request
->info
.in
.u
.manage_hmc_pm
.info
;
980 struct i40iw_device
*iwdev
=
981 (struct i40iw_device
*)cqp_request
->info
.in
.u
.manage_hmc_pm
.dev
->
984 if (hmcfcninfo
&& hmcfcninfo
->callback_fcn
) {
985 i40iw_debug(&iwdev
->sc_dev
, I40IW_DEBUG_HMC
, "%s1\n", __func__
);
986 atomic_inc(&cqp_request
->refcount
);
987 work
= &iwdev
->virtchnl_w
[hmcfcninfo
->iw_vf_idx
];
988 work
->cqp_request
= cqp_request
;
989 INIT_WORK(&work
->work
, i40iw_cqp_manage_hmc_fcn_worker
);
990 queue_work(iwdev
->virtchnl_wq
, &work
->work
);
991 i40iw_debug(&iwdev
->sc_dev
, I40IW_DEBUG_HMC
, "%s2\n", __func__
);
993 i40iw_debug(&iwdev
->sc_dev
, I40IW_DEBUG_HMC
, "%s: Something wrong\n", __func__
);
998 * i40iw_cqp_manage_hmc_fcn_cmd - issue cqp command to manage hmc
999 * @dev: hardware control device structure
1000 * @hmcfcninfo: info for hmc
1002 enum i40iw_status_code
i40iw_cqp_manage_hmc_fcn_cmd(struct i40iw_sc_dev
*dev
,
1003 struct i40iw_hmc_fcn_info
*hmcfcninfo
)
1005 enum i40iw_status_code status
;
1006 struct i40iw_cqp_request
*cqp_request
;
1007 struct cqp_commands_info
*cqp_info
;
1008 struct i40iw_device
*iwdev
= (struct i40iw_device
*)dev
->back_dev
;
1010 i40iw_debug(&iwdev
->sc_dev
, I40IW_DEBUG_HMC
, "%s\n", __func__
);
1011 cqp_request
= i40iw_get_cqp_request(&iwdev
->cqp
, false);
1013 return I40IW_ERR_NO_MEMORY
;
1014 cqp_info
= &cqp_request
->info
;
1015 cqp_request
->callback_fcn
= i40iw_cqp_manage_hmc_fcn_callback
;
1016 cqp_request
->param
= hmcfcninfo
;
1017 memcpy(&cqp_info
->in
.u
.manage_hmc_pm
.info
, hmcfcninfo
,
1018 sizeof(*hmcfcninfo
));
1019 cqp_info
->in
.u
.manage_hmc_pm
.dev
= dev
;
1020 cqp_info
->cqp_cmd
= OP_MANAGE_HMC_PM_FUNC_TABLE
;
1021 cqp_info
->post_sq
= 1;
1022 cqp_info
->in
.u
.manage_hmc_pm
.scratch
= (uintptr_t)cqp_request
;
1023 status
= i40iw_handle_cqp_op(iwdev
, cqp_request
);
1025 i40iw_pr_err("CQP-OP Manage HMC fail");
1030 * i40iw_cqp_query_fpm_values_cmd - send cqp command for fpm
1031 * @iwdev: function device struct
1032 * @values_mem: buffer for fpm
1033 * @hmc_fn_id: function id for fpm
1035 enum i40iw_status_code
i40iw_cqp_query_fpm_values_cmd(struct i40iw_sc_dev
*dev
,
1036 struct i40iw_dma_mem
*values_mem
,
1039 enum i40iw_status_code status
;
1040 struct i40iw_cqp_request
*cqp_request
;
1041 struct cqp_commands_info
*cqp_info
;
1042 struct i40iw_device
*iwdev
= (struct i40iw_device
*)dev
->back_dev
;
1044 cqp_request
= i40iw_get_cqp_request(&iwdev
->cqp
, true);
1046 return I40IW_ERR_NO_MEMORY
;
1047 cqp_info
= &cqp_request
->info
;
1048 cqp_request
->param
= NULL
;
1049 cqp_info
->in
.u
.query_fpm_values
.cqp
= dev
->cqp
;
1050 cqp_info
->in
.u
.query_fpm_values
.fpm_values_pa
= values_mem
->pa
;
1051 cqp_info
->in
.u
.query_fpm_values
.fpm_values_va
= values_mem
->va
;
1052 cqp_info
->in
.u
.query_fpm_values
.hmc_fn_id
= hmc_fn_id
;
1053 cqp_info
->cqp_cmd
= OP_QUERY_FPM_VALUES
;
1054 cqp_info
->post_sq
= 1;
1055 cqp_info
->in
.u
.query_fpm_values
.scratch
= (uintptr_t)cqp_request
;
1056 status
= i40iw_handle_cqp_op(iwdev
, cqp_request
);
1058 i40iw_pr_err("CQP-OP Query FPM fail");
1063 * i40iw_cqp_commit_fpm_values_cmd - commit fpm values in hw
1064 * @dev: hardware control device structure
1065 * @values_mem: buffer with fpm values
1066 * @hmc_fn_id: function id for fpm
1068 enum i40iw_status_code
i40iw_cqp_commit_fpm_values_cmd(struct i40iw_sc_dev
*dev
,
1069 struct i40iw_dma_mem
*values_mem
,
1072 enum i40iw_status_code status
;
1073 struct i40iw_cqp_request
*cqp_request
;
1074 struct cqp_commands_info
*cqp_info
;
1075 struct i40iw_device
*iwdev
= (struct i40iw_device
*)dev
->back_dev
;
1077 cqp_request
= i40iw_get_cqp_request(&iwdev
->cqp
, true);
1079 return I40IW_ERR_NO_MEMORY
;
1080 cqp_info
= &cqp_request
->info
;
1081 cqp_request
->param
= NULL
;
1082 cqp_info
->in
.u
.commit_fpm_values
.cqp
= dev
->cqp
;
1083 cqp_info
->in
.u
.commit_fpm_values
.fpm_values_pa
= values_mem
->pa
;
1084 cqp_info
->in
.u
.commit_fpm_values
.fpm_values_va
= values_mem
->va
;
1085 cqp_info
->in
.u
.commit_fpm_values
.hmc_fn_id
= hmc_fn_id
;
1086 cqp_info
->cqp_cmd
= OP_COMMIT_FPM_VALUES
;
1087 cqp_info
->post_sq
= 1;
1088 cqp_info
->in
.u
.commit_fpm_values
.scratch
= (uintptr_t)cqp_request
;
1089 status
= i40iw_handle_cqp_op(iwdev
, cqp_request
);
1091 i40iw_pr_err("CQP-OP Commit FPM fail");
1096 * i40iw_vf_wait_vchnl_resp - wait for channel msg
1097 * @iwdev: function's device struct
1099 enum i40iw_status_code
i40iw_vf_wait_vchnl_resp(struct i40iw_sc_dev
*dev
)
1101 struct i40iw_device
*iwdev
= dev
->back_dev
;
1104 i40iw_debug(dev
, I40IW_DEBUG_VIRT
, "%s[%u] dev %p, iwdev %p\n",
1105 __func__
, __LINE__
, dev
, iwdev
);
1107 atomic_set(&iwdev
->vchnl_msgs
, 2);
1108 timeout_ret
= wait_event_timeout(iwdev
->vchnl_waitq
,
1109 (atomic_read(&iwdev
->vchnl_msgs
) == 1),
1110 I40IW_VCHNL_EVENT_TIMEOUT
);
1111 atomic_dec(&iwdev
->vchnl_msgs
);
1113 i40iw_pr_err("virt channel completion timeout = 0x%x\n", timeout_ret
);
1114 atomic_set(&iwdev
->vchnl_msgs
, 0);
1115 dev
->vchnl_up
= false;
1116 return I40IW_ERR_TIMEOUT
;
1118 wake_up(&dev
->vf_reqs
);
1123 * i40iw_cqp_cq_create_cmd - create a cq for the cqp
1124 * @dev: device pointer
1125 * @cq: pointer to created cq
1127 enum i40iw_status_code
i40iw_cqp_cq_create_cmd(struct i40iw_sc_dev
*dev
,
1128 struct i40iw_sc_cq
*cq
)
1130 struct i40iw_device
*iwdev
= (struct i40iw_device
*)dev
->back_dev
;
1131 struct i40iw_cqp
*iwcqp
= &iwdev
->cqp
;
1132 struct i40iw_cqp_request
*cqp_request
;
1133 struct cqp_commands_info
*cqp_info
;
1134 enum i40iw_status_code status
;
1136 cqp_request
= i40iw_get_cqp_request(iwcqp
, true);
1138 return I40IW_ERR_NO_MEMORY
;
1140 cqp_info
= &cqp_request
->info
;
1141 cqp_info
->cqp_cmd
= OP_CQ_CREATE
;
1142 cqp_info
->post_sq
= 1;
1143 cqp_info
->in
.u
.cq_create
.cq
= cq
;
1144 cqp_info
->in
.u
.cq_create
.scratch
= (uintptr_t)cqp_request
;
1145 status
= i40iw_handle_cqp_op(iwdev
, cqp_request
);
1147 i40iw_pr_err("CQP-OP Create QP fail");
1153 * i40iw_cqp_qp_create_cmd - create a qp for the cqp
1154 * @dev: device pointer
1155 * @qp: pointer to created qp
1157 enum i40iw_status_code
i40iw_cqp_qp_create_cmd(struct i40iw_sc_dev
*dev
,
1158 struct i40iw_sc_qp
*qp
)
1160 struct i40iw_device
*iwdev
= (struct i40iw_device
*)dev
->back_dev
;
1161 struct i40iw_cqp
*iwcqp
= &iwdev
->cqp
;
1162 struct i40iw_cqp_request
*cqp_request
;
1163 struct cqp_commands_info
*cqp_info
;
1164 struct i40iw_create_qp_info
*qp_info
;
1165 enum i40iw_status_code status
;
1167 cqp_request
= i40iw_get_cqp_request(iwcqp
, true);
1169 return I40IW_ERR_NO_MEMORY
;
1171 cqp_info
= &cqp_request
->info
;
1172 qp_info
= &cqp_request
->info
.in
.u
.qp_create
.info
;
1174 memset(qp_info
, 0, sizeof(*qp_info
));
1176 qp_info
->cq_num_valid
= true;
1177 qp_info
->next_iwarp_state
= I40IW_QP_STATE_RTS
;
1179 cqp_info
->cqp_cmd
= OP_QP_CREATE
;
1180 cqp_info
->post_sq
= 1;
1181 cqp_info
->in
.u
.qp_create
.qp
= qp
;
1182 cqp_info
->in
.u
.qp_create
.scratch
= (uintptr_t)cqp_request
;
1183 status
= i40iw_handle_cqp_op(iwdev
, cqp_request
);
1185 i40iw_pr_err("CQP-OP QP create fail");
1190 * i40iw_cqp_cq_destroy_cmd - destroy the cqp cq
1191 * @dev: device pointer
1192 * @cq: pointer to cq
1194 void i40iw_cqp_cq_destroy_cmd(struct i40iw_sc_dev
*dev
, struct i40iw_sc_cq
*cq
)
1196 struct i40iw_device
*iwdev
= (struct i40iw_device
*)dev
->back_dev
;
1198 i40iw_cq_wq_destroy(iwdev
, cq
);
1202 * i40iw_cqp_qp_destroy_cmd - destroy the cqp
1203 * @dev: device pointer
1204 * @qp: pointer to qp
1206 void i40iw_cqp_qp_destroy_cmd(struct i40iw_sc_dev
*dev
, struct i40iw_sc_qp
*qp
)
1208 struct i40iw_device
*iwdev
= (struct i40iw_device
*)dev
->back_dev
;
1209 struct i40iw_cqp
*iwcqp
= &iwdev
->cqp
;
1210 struct i40iw_cqp_request
*cqp_request
;
1211 struct cqp_commands_info
*cqp_info
;
1212 enum i40iw_status_code status
;
1214 cqp_request
= i40iw_get_cqp_request(iwcqp
, true);
1218 cqp_info
= &cqp_request
->info
;
1219 memset(cqp_info
, 0, sizeof(*cqp_info
));
1221 cqp_info
->cqp_cmd
= OP_QP_DESTROY
;
1222 cqp_info
->post_sq
= 1;
1223 cqp_info
->in
.u
.qp_destroy
.qp
= qp
;
1224 cqp_info
->in
.u
.qp_destroy
.scratch
= (uintptr_t)cqp_request
;
1225 cqp_info
->in
.u
.qp_destroy
.remove_hash_idx
= true;
1226 status
= i40iw_handle_cqp_op(iwdev
, cqp_request
);
1228 i40iw_pr_err("CQP QP_DESTROY fail");
1233 * i40iw_ieq_mpa_crc_ae - generate AE for crc error
1234 * @dev: hardware control device structure
1235 * @qp: hardware control qp
1237 void i40iw_ieq_mpa_crc_ae(struct i40iw_sc_dev
*dev
, struct i40iw_sc_qp
*qp
)
1239 struct i40iw_qp_flush_info info
;
1240 struct i40iw_device
*iwdev
= (struct i40iw_device
*)dev
->back_dev
;
1242 i40iw_debug(dev
, I40IW_DEBUG_AEQ
, "%s entered\n", __func__
);
1243 memset(&info
, 0, sizeof(info
));
1244 info
.ae_code
= I40IW_AE_LLP_RECEIVED_MPA_CRC_ERROR
;
1245 info
.generate_ae
= true;
1246 info
.ae_source
= 0x3;
1247 (void)i40iw_hw_flush_wqes(iwdev
, qp
, &info
, false);
1251 * i40iw_init_hash_desc - initialize hash for crc calculation
1252 * @desc: cryption type
1254 enum i40iw_status_code
i40iw_init_hash_desc(struct shash_desc
**desc
)
1256 struct crypto_shash
*tfm
;
1257 struct shash_desc
*tdesc
;
1259 tfm
= crypto_alloc_shash("crc32c", 0, 0);
1261 return I40IW_ERR_MPA_CRC
;
1263 tdesc
= kzalloc(sizeof(*tdesc
) + crypto_shash_descsize(tfm
),
1266 crypto_free_shash(tfm
);
1267 return I40IW_ERR_MPA_CRC
;
1276 * i40iw_free_hash_desc - free hash desc
1277 * @desc: to be freed
1279 void i40iw_free_hash_desc(struct shash_desc
*desc
)
1282 crypto_free_shash(desc
->tfm
);
1288 * i40iw_alloc_query_fpm_buf - allocate buffer for fpm
1289 * @dev: hardware control device structure
1290 * @mem: buffer ptr for fpm to be allocated
1291 * @return: memory allocation status
1293 enum i40iw_status_code
i40iw_alloc_query_fpm_buf(struct i40iw_sc_dev
*dev
,
1294 struct i40iw_dma_mem
*mem
)
1296 enum i40iw_status_code status
;
1297 struct i40iw_device
*iwdev
= (struct i40iw_device
*)dev
->back_dev
;
1299 status
= i40iw_obj_aligned_mem(iwdev
, mem
, I40IW_QUERY_FPM_BUF_SIZE
,
1300 I40IW_FPM_QUERY_BUF_ALIGNMENT_MASK
);
1305 * i40iw_ieq_check_mpacrc - check if mpa crc is OK
1306 * @desc: desc for hash
1307 * @addr: address of buffer for crc
1308 * @length: length of buffer
1309 * @value: value to be compared
1311 enum i40iw_status_code
i40iw_ieq_check_mpacrc(struct shash_desc
*desc
,
1318 enum i40iw_status_code ret_code
= 0;
1320 crypto_shash_init(desc
);
1321 ret
= crypto_shash_update(desc
, addr
, length
);
1323 crypto_shash_final(desc
, (u8
*)&crc
);
1325 i40iw_pr_err("mpa crc check fail\n");
1326 ret_code
= I40IW_ERR_MPA_CRC
;
1332 * i40iw_ieq_get_qp - get qp based on quad in puda buffer
1333 * @dev: hardware control device structure
1334 * @buf: receive puda buffer on exception q
1336 struct i40iw_sc_qp
*i40iw_ieq_get_qp(struct i40iw_sc_dev
*dev
,
1337 struct i40iw_puda_buf
*buf
)
1339 struct i40iw_device
*iwdev
= (struct i40iw_device
*)dev
->back_dev
;
1340 struct i40iw_qp
*iwqp
;
1341 struct i40iw_cm_node
*cm_node
;
1342 u32 loc_addr
[4], rem_addr
[4];
1343 u16 loc_port
, rem_port
;
1344 struct ipv6hdr
*ip6h
;
1345 struct iphdr
*iph
= (struct iphdr
*)buf
->iph
;
1346 struct tcphdr
*tcph
= (struct tcphdr
*)buf
->tcph
;
1348 if (iph
->version
== 4) {
1349 memset(loc_addr
, 0, sizeof(loc_addr
));
1350 loc_addr
[0] = ntohl(iph
->daddr
);
1351 memset(rem_addr
, 0, sizeof(rem_addr
));
1352 rem_addr
[0] = ntohl(iph
->saddr
);
1354 ip6h
= (struct ipv6hdr
*)buf
->iph
;
1355 i40iw_copy_ip_ntohl(loc_addr
, ip6h
->daddr
.in6_u
.u6_addr32
);
1356 i40iw_copy_ip_ntohl(rem_addr
, ip6h
->saddr
.in6_u
.u6_addr32
);
1358 loc_port
= ntohs(tcph
->dest
);
1359 rem_port
= ntohs(tcph
->source
);
1361 cm_node
= i40iw_find_node(&iwdev
->cm_core
, rem_port
, rem_addr
, loc_port
,
1365 iwqp
= cm_node
->iwqp
;
1366 return &iwqp
->sc_qp
;
1370 * i40iw_ieq_update_tcpip_info - update tcpip in the buffer
1371 * @buf: puda to update
1372 * @length: length of buffer
1373 * @seqnum: seq number for tcp
1375 void i40iw_ieq_update_tcpip_info(struct i40iw_puda_buf
*buf
, u16 length
, u32 seqnum
)
1377 struct tcphdr
*tcph
;
1381 u8
*addr
= (u8
*)buf
->mem
.va
;
1383 iphlen
= (buf
->ipv4
) ? 20 : 40;
1384 iph
= (struct iphdr
*)(addr
+ buf
->maclen
);
1385 tcph
= (struct tcphdr
*)(addr
+ buf
->maclen
+ iphlen
);
1386 packetsize
= length
+ buf
->tcphlen
+ iphlen
;
1388 iph
->tot_len
= htons(packetsize
);
1389 tcph
->seq
= htonl(seqnum
);
1393 * i40iw_puda_get_tcpip_info - get tcpip info from puda buffer
1394 * @info: to get information
1397 enum i40iw_status_code
i40iw_puda_get_tcpip_info(struct i40iw_puda_completion_info
*info
,
1398 struct i40iw_puda_buf
*buf
)
1401 struct ipv6hdr
*ip6h
;
1402 struct tcphdr
*tcph
;
1405 u8
*mem
= (u8
*)buf
->mem
.va
;
1406 struct ethhdr
*ethh
= (struct ethhdr
*)buf
->mem
.va
;
1408 if (ethh
->h_proto
== htons(0x8100)) {
1409 info
->vlan_valid
= true;
1410 buf
->vlan_id
= ntohs(((struct vlan_ethhdr
*)ethh
)->h_vlan_TCI
) & VLAN_VID_MASK
;
1412 buf
->maclen
= (info
->vlan_valid
) ? 18 : 14;
1413 iphlen
= (info
->l3proto
) ? 40 : 20;
1414 buf
->ipv4
= (info
->l3proto
) ? false : true;
1415 buf
->iph
= mem
+ buf
->maclen
;
1416 iph
= (struct iphdr
*)buf
->iph
;
1418 buf
->tcph
= buf
->iph
+ iphlen
;
1419 tcph
= (struct tcphdr
*)buf
->tcph
;
1422 pkt_len
= ntohs(iph
->tot_len
);
1424 ip6h
= (struct ipv6hdr
*)buf
->iph
;
1425 pkt_len
= ntohs(ip6h
->payload_len
) + iphlen
;
1428 buf
->totallen
= pkt_len
+ buf
->maclen
;
1430 if (info
->payload_len
< buf
->totallen
) {
1431 i40iw_pr_err("payload_len = 0x%x totallen expected0x%x\n",
1432 info
->payload_len
, buf
->totallen
);
1433 return I40IW_ERR_INVALID_SIZE
;
1436 buf
->tcphlen
= (tcph
->doff
) << 2;
1437 buf
->datalen
= pkt_len
- iphlen
- buf
->tcphlen
;
1438 buf
->data
= (buf
->datalen
) ? buf
->tcph
+ buf
->tcphlen
: NULL
;
1439 buf
->hdrlen
= buf
->maclen
+ iphlen
+ buf
->tcphlen
;
1440 buf
->seqnum
= ntohl(tcph
->seq
);
1445 * i40iw_hw_stats_timeout - Stats timer-handler which updates all HW stats
1446 * @vsi: pointer to the vsi structure
1448 static void i40iw_hw_stats_timeout(unsigned long vsi
)
1450 struct i40iw_sc_vsi
*sc_vsi
= (struct i40iw_sc_vsi
*)vsi
;
1451 struct i40iw_sc_dev
*pf_dev
= sc_vsi
->dev
;
1452 struct i40iw_vsi_pestat
*pf_devstat
= sc_vsi
->pestat
;
1453 struct i40iw_vsi_pestat
*vf_devstat
= NULL
;
1455 unsigned long flags
;
1458 i40iw_hw_stats_read_all(pf_devstat
, &pf_devstat
->hw_stats
);
1460 for (iw_vf_idx
= 0; iw_vf_idx
< I40IW_MAX_PE_ENABLED_VF_COUNT
; iw_vf_idx
++) {
1461 spin_lock_irqsave(&pf_devstat
->lock
, flags
);
1462 if (pf_dev
->vf_dev
[iw_vf_idx
]) {
1463 if (pf_dev
->vf_dev
[iw_vf_idx
]->stats_initialized
) {
1464 vf_devstat
= &pf_dev
->vf_dev
[iw_vf_idx
]->pestat
;
1465 i40iw_hw_stats_read_all(vf_devstat
, &vf_devstat
->hw_stats
);
1468 spin_unlock_irqrestore(&pf_devstat
->lock
, flags
);
1471 mod_timer(&pf_devstat
->stats_timer
,
1472 jiffies
+ msecs_to_jiffies(STATS_TIMER_DELAY
));
1476 * i40iw_hw_stats_start_timer - Start periodic stats timer
1477 * @vsi: pointer to the vsi structure
1479 void i40iw_hw_stats_start_timer(struct i40iw_sc_vsi
*vsi
)
1481 struct i40iw_vsi_pestat
*devstat
= vsi
->pestat
;
1483 setup_timer(&devstat
->stats_timer
, i40iw_hw_stats_timeout
,
1484 (unsigned long)vsi
);
1485 mod_timer(&devstat
->stats_timer
,
1486 jiffies
+ msecs_to_jiffies(STATS_TIMER_DELAY
));
1490 * i40iw_hw_stats_stop_timer - Delete periodic stats timer
1491 * @vsi: pointer to the vsi structure
1493 void i40iw_hw_stats_stop_timer(struct i40iw_sc_vsi
*vsi
)
1495 struct i40iw_vsi_pestat
*devstat
= vsi
->pestat
;
1497 del_timer_sync(&devstat
->stats_timer
);