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 ipv4 addr 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 struct in_device
*in
;
175 in
= __in_dev_get_rcu(upper_dev
);
176 local_ipaddr
= ntohl(in
->ifa_list
->ifa_address
);
179 local_ipaddr
= ntohl(ifa
->ifa_address
);
183 action
= I40IW_ARP_DELETE
;
187 case NETDEV_CHANGEADDR
:
188 i40iw_manage_arp_cache(iwdev
,
193 i40iw_if_notify(iwdev
, netdev
, &local_ipaddr
, true,
194 (action
== I40IW_ARP_ADD
) ? true : false);
203 * i40iw_inet6addr_event - system notifier for ipv6 addr events
205 * @event: event for notifier
208 int i40iw_inet6addr_event(struct notifier_block
*notifier
,
212 struct inet6_ifaddr
*ifa
= (struct inet6_ifaddr
*)ptr
;
213 struct net_device
*event_netdev
= ifa
->idev
->dev
;
214 struct net_device
*netdev
;
215 struct i40iw_device
*iwdev
;
216 struct i40iw_handler
*hdl
;
217 u32 local_ipaddr6
[4];
218 u32 action
= I40IW_ARP_ADD
;
220 hdl
= i40iw_find_netdev(event_netdev
);
224 iwdev
= &hdl
->device
;
225 if (iwdev
->init_state
< IP_ADDR_REGISTERED
|| iwdev
->closing
)
228 netdev
= iwdev
->ldev
->netdev
;
229 if (netdev
!= event_netdev
)
232 i40iw_copy_ip_ntohl(local_ipaddr6
, ifa
->addr
.in6_u
.u6_addr32
);
235 action
= I40IW_ARP_DELETE
;
239 case NETDEV_CHANGEADDR
:
240 i40iw_manage_arp_cache(iwdev
,
245 i40iw_if_notify(iwdev
, netdev
, local_ipaddr6
, false,
246 (action
== I40IW_ARP_ADD
) ? true : false);
255 * i40iw_net_event - system notifier for netevents
257 * @event: event for notifier
260 int i40iw_net_event(struct notifier_block
*notifier
, unsigned long event
, void *ptr
)
262 struct neighbour
*neigh
= ptr
;
263 struct i40iw_device
*iwdev
;
264 struct i40iw_handler
*iwhdl
;
269 case NETEVENT_NEIGH_UPDATE
:
270 iwhdl
= i40iw_find_netdev((struct net_device
*)neigh
->dev
);
273 iwdev
= &iwhdl
->device
;
274 if (iwdev
->init_state
< IP_ADDR_REGISTERED
|| iwdev
->closing
)
276 p
= (__be32
*)neigh
->primary_key
;
277 i40iw_copy_ip_ntohl(local_ipaddr
, p
);
278 if (neigh
->nud_state
& NUD_VALID
) {
279 i40iw_manage_arp_cache(iwdev
,
286 i40iw_manage_arp_cache(iwdev
,
300 * i40iw_netdevice_event - system notifier for netdev events
302 * @event: event for notifier
305 int i40iw_netdevice_event(struct notifier_block
*notifier
,
309 struct net_device
*event_netdev
;
310 struct net_device
*netdev
;
311 struct i40iw_device
*iwdev
;
312 struct i40iw_handler
*hdl
;
314 event_netdev
= netdev_notifier_info_to_dev(ptr
);
316 hdl
= i40iw_find_netdev(event_netdev
);
320 iwdev
= &hdl
->device
;
321 if (iwdev
->init_state
< RDMA_DEV_REGISTERED
|| iwdev
->closing
)
324 netdev
= iwdev
->ldev
->netdev
;
325 if (netdev
!= event_netdev
)
328 iwdev
->iw_status
= 1;
332 iwdev
->iw_status
= 0;
335 i40iw_port_ibevent(iwdev
);
344 * i40iw_get_cqp_request - get cqp struct
345 * @cqp: device cqp ptr
346 * @wait: cqp to be used in wait mode
348 struct i40iw_cqp_request
*i40iw_get_cqp_request(struct i40iw_cqp
*cqp
, bool wait
)
350 struct i40iw_cqp_request
*cqp_request
= NULL
;
353 spin_lock_irqsave(&cqp
->req_lock
, flags
);
354 if (!list_empty(&cqp
->cqp_avail_reqs
)) {
355 cqp_request
= list_entry(cqp
->cqp_avail_reqs
.next
,
356 struct i40iw_cqp_request
, list
);
357 list_del_init(&cqp_request
->list
);
359 spin_unlock_irqrestore(&cqp
->req_lock
, flags
);
361 cqp_request
= kzalloc(sizeof(*cqp_request
), GFP_ATOMIC
);
363 cqp_request
->dynamic
= true;
364 INIT_LIST_HEAD(&cqp_request
->list
);
365 init_waitqueue_head(&cqp_request
->waitq
);
369 i40iw_pr_err("CQP Request Fail: No Memory");
374 atomic_set(&cqp_request
->refcount
, 2);
375 cqp_request
->waiting
= true;
377 atomic_set(&cqp_request
->refcount
, 1);
383 * i40iw_free_cqp_request - free cqp request
385 * @cqp_request: to be put back in cqp list
387 void i40iw_free_cqp_request(struct i40iw_cqp
*cqp
, struct i40iw_cqp_request
*cqp_request
)
389 struct i40iw_device
*iwdev
= container_of(cqp
, struct i40iw_device
, cqp
);
392 if (cqp_request
->dynamic
) {
395 cqp_request
->request_done
= false;
396 cqp_request
->callback_fcn
= NULL
;
397 cqp_request
->waiting
= false;
399 spin_lock_irqsave(&cqp
->req_lock
, flags
);
400 list_add_tail(&cqp_request
->list
, &cqp
->cqp_avail_reqs
);
401 spin_unlock_irqrestore(&cqp
->req_lock
, flags
);
403 wake_up(&iwdev
->close_wq
);
407 * i40iw_put_cqp_request - dec ref count and free if 0
409 * @cqp_request: to be put back in cqp list
411 void i40iw_put_cqp_request(struct i40iw_cqp
*cqp
,
412 struct i40iw_cqp_request
*cqp_request
)
414 if (atomic_dec_and_test(&cqp_request
->refcount
))
415 i40iw_free_cqp_request(cqp
, cqp_request
);
419 * i40iw_free_pending_cqp_request -free pending cqp request objs
421 * @cqp_request: to be put back in cqp list
423 static void i40iw_free_pending_cqp_request(struct i40iw_cqp
*cqp
,
424 struct i40iw_cqp_request
*cqp_request
)
426 struct i40iw_device
*iwdev
= container_of(cqp
, struct i40iw_device
, cqp
);
428 if (cqp_request
->waiting
) {
429 cqp_request
->compl_info
.error
= true;
430 cqp_request
->request_done
= true;
431 wake_up(&cqp_request
->waitq
);
433 i40iw_put_cqp_request(cqp
, cqp_request
);
434 wait_event_timeout(iwdev
->close_wq
,
435 !atomic_read(&cqp_request
->refcount
),
440 * i40iw_cleanup_pending_cqp_op - clean-up cqp with no completions
441 * @iwdev: iwarp device
443 void i40iw_cleanup_pending_cqp_op(struct i40iw_device
*iwdev
)
445 struct i40iw_sc_dev
*dev
= &iwdev
->sc_dev
;
446 struct i40iw_cqp
*cqp
= &iwdev
->cqp
;
447 struct i40iw_cqp_request
*cqp_request
= NULL
;
448 struct cqp_commands_info
*pcmdinfo
= NULL
;
449 u32 i
, pending_work
, wqe_idx
;
451 pending_work
= I40IW_RING_WORK_AVAILABLE(cqp
->sc_cqp
.sq_ring
);
452 wqe_idx
= I40IW_RING_GETCURRENT_TAIL(cqp
->sc_cqp
.sq_ring
);
453 for (i
= 0; i
< pending_work
; i
++) {
454 cqp_request
= (struct i40iw_cqp_request
*)(unsigned long)cqp
->scratch_array
[wqe_idx
];
456 i40iw_free_pending_cqp_request(cqp
, cqp_request
);
457 wqe_idx
= (wqe_idx
+ 1) % I40IW_RING_GETSIZE(cqp
->sc_cqp
.sq_ring
);
460 while (!list_empty(&dev
->cqp_cmd_head
)) {
461 pcmdinfo
= (struct cqp_commands_info
*)i40iw_remove_head(&dev
->cqp_cmd_head
);
462 cqp_request
= container_of(pcmdinfo
, struct i40iw_cqp_request
, info
);
464 i40iw_free_pending_cqp_request(cqp
, cqp_request
);
469 * i40iw_free_qp - callback after destroy cqp completes
470 * @cqp_request: cqp request for destroy qp
473 static void i40iw_free_qp(struct i40iw_cqp_request
*cqp_request
, u32 num
)
475 struct i40iw_sc_qp
*qp
= (struct i40iw_sc_qp
*)cqp_request
->param
;
476 struct i40iw_qp
*iwqp
= (struct i40iw_qp
*)qp
->back_qp
;
477 struct i40iw_device
*iwdev
;
478 u32 qp_num
= iwqp
->ibqp
.qp_num
;
482 i40iw_rem_pdusecount(iwqp
->iwpd
, iwdev
);
483 i40iw_free_qp_resources(iwdev
, iwqp
, qp_num
);
484 i40iw_rem_devusecount(iwdev
);
488 * i40iw_wait_event - wait for completion
489 * @iwdev: iwarp device
490 * @cqp_request: cqp request to wait
492 static int i40iw_wait_event(struct i40iw_device
*iwdev
,
493 struct i40iw_cqp_request
*cqp_request
)
495 struct cqp_commands_info
*info
= &cqp_request
->info
;
496 struct i40iw_cqp
*iwcqp
= &iwdev
->cqp
;
497 struct i40iw_cqp_timeout cqp_timeout
;
498 bool cqp_error
= false;
500 memset(&cqp_timeout
, 0, sizeof(cqp_timeout
));
501 cqp_timeout
.compl_cqp_cmds
= iwdev
->sc_dev
.cqp_cmd_stats
[OP_COMPLETED_COMMANDS
];
503 if (wait_event_timeout(cqp_request
->waitq
,
504 cqp_request
->request_done
, CQP_COMPL_WAIT_TIME
))
507 i40iw_check_cqp_progress(&cqp_timeout
, &iwdev
->sc_dev
);
509 if (cqp_timeout
.count
< CQP_TIMEOUT_THRESHOLD
)
512 i40iw_pr_err("error cqp command 0x%x timed out", info
->cqp_cmd
);
516 i40iw_request_reset(iwdev
);
520 cqp_error
= cqp_request
->compl_info
.error
;
522 i40iw_pr_err("error cqp command 0x%x completion maj = 0x%x min=0x%x\n",
523 info
->cqp_cmd
, cqp_request
->compl_info
.maj_err_code
,
524 cqp_request
->compl_info
.min_err_code
);
529 i40iw_put_cqp_request(iwcqp
, cqp_request
);
534 * i40iw_handle_cqp_op - process cqp command
535 * @iwdev: iwarp device
536 * @cqp_request: cqp request to process
538 enum i40iw_status_code
i40iw_handle_cqp_op(struct i40iw_device
*iwdev
,
539 struct i40iw_cqp_request
542 struct i40iw_sc_dev
*dev
= &iwdev
->sc_dev
;
543 enum i40iw_status_code status
;
544 struct cqp_commands_info
*info
= &cqp_request
->info
;
548 i40iw_free_cqp_request(&iwdev
->cqp
, cqp_request
);
549 return I40IW_ERR_CQP_COMPL_ERROR
;
552 status
= i40iw_process_cqp_cmd(dev
, info
);
554 i40iw_pr_err("error cqp command 0x%x failed\n", info
->cqp_cmd
);
555 i40iw_free_cqp_request(&iwdev
->cqp
, cqp_request
);
558 if (cqp_request
->waiting
)
559 err_code
= i40iw_wait_event(iwdev
, cqp_request
);
561 status
= I40IW_ERR_CQP_COMPL_ERROR
;
566 * i40iw_add_devusecount - add dev refcount
567 * @iwdev: dev for refcount
569 void i40iw_add_devusecount(struct i40iw_device
*iwdev
)
571 atomic64_inc(&iwdev
->use_count
);
575 * i40iw_rem_devusecount - decrement refcount for dev
578 void i40iw_rem_devusecount(struct i40iw_device
*iwdev
)
580 if (!atomic64_dec_and_test(&iwdev
->use_count
))
582 wake_up(&iwdev
->close_wq
);
586 * i40iw_add_pdusecount - add pd refcount
587 * @iwpd: pd for refcount
589 void i40iw_add_pdusecount(struct i40iw_pd
*iwpd
)
591 atomic_inc(&iwpd
->usecount
);
595 * i40iw_rem_pdusecount - decrement refcount for pd and free if 0
596 * @iwpd: pd for refcount
597 * @iwdev: iwarp device
599 void i40iw_rem_pdusecount(struct i40iw_pd
*iwpd
, struct i40iw_device
*iwdev
)
601 if (!atomic_dec_and_test(&iwpd
->usecount
))
603 i40iw_free_resource(iwdev
, iwdev
->allocated_pds
, iwpd
->sc_pd
.pd_id
);
608 * i40iw_add_ref - add refcount for qp
611 void i40iw_add_ref(struct ib_qp
*ibqp
)
613 struct i40iw_qp
*iwqp
= (struct i40iw_qp
*)ibqp
;
615 atomic_inc(&iwqp
->refcount
);
619 * i40iw_rem_ref - rem refcount for qp and free if 0
622 void i40iw_rem_ref(struct ib_qp
*ibqp
)
624 struct i40iw_qp
*iwqp
;
625 enum i40iw_status_code status
;
626 struct i40iw_cqp_request
*cqp_request
;
627 struct cqp_commands_info
*cqp_info
;
628 struct i40iw_device
*iwdev
;
632 iwqp
= to_iwqp(ibqp
);
634 spin_lock_irqsave(&iwdev
->qptable_lock
, flags
);
635 if (!atomic_dec_and_test(&iwqp
->refcount
)) {
636 spin_unlock_irqrestore(&iwdev
->qptable_lock
, flags
);
640 qp_num
= iwqp
->ibqp
.qp_num
;
641 iwdev
->qp_table
[qp_num
] = NULL
;
642 spin_unlock_irqrestore(&iwdev
->qptable_lock
, flags
);
643 cqp_request
= i40iw_get_cqp_request(&iwdev
->cqp
, false);
647 cqp_request
->callback_fcn
= i40iw_free_qp
;
648 cqp_request
->param
= (void *)&iwqp
->sc_qp
;
649 cqp_info
= &cqp_request
->info
;
650 cqp_info
->cqp_cmd
= OP_QP_DESTROY
;
651 cqp_info
->post_sq
= 1;
652 cqp_info
->in
.u
.qp_destroy
.qp
= &iwqp
->sc_qp
;
653 cqp_info
->in
.u
.qp_destroy
.scratch
= (uintptr_t)cqp_request
;
654 cqp_info
->in
.u
.qp_destroy
.remove_hash_idx
= true;
655 status
= i40iw_handle_cqp_op(iwdev
, cqp_request
);
659 i40iw_rem_pdusecount(iwqp
->iwpd
, iwdev
);
660 i40iw_free_qp_resources(iwdev
, iwqp
, qp_num
);
661 i40iw_rem_devusecount(iwdev
);
665 * i40iw_get_qp - get qp address
666 * @device: iwarp device
669 struct ib_qp
*i40iw_get_qp(struct ib_device
*device
, int qpn
)
671 struct i40iw_device
*iwdev
= to_iwdev(device
);
673 if ((qpn
< IW_FIRST_QPN
) || (qpn
>= iwdev
->max_qp
))
676 return &iwdev
->qp_table
[qpn
]->ibqp
;
680 * i40iw_debug_buf - print debug msg and buffer is mask set
681 * @dev: hardware control device structure
682 * @mask: mask to compare if to print debug buffer
683 * @buf: points buffer addr
684 * @size: saize of buffer to print
686 void i40iw_debug_buf(struct i40iw_sc_dev
*dev
,
687 enum i40iw_debug_flag mask
,
694 if (!(dev
->debug_mask
& mask
))
696 i40iw_debug(dev
, mask
, "%s\n", desc
);
697 i40iw_debug(dev
, mask
, "starting address virt=%p phy=%llxh\n", buf
,
698 (unsigned long long)virt_to_phys(buf
));
700 for (i
= 0; i
< size
; i
+= 8)
701 i40iw_debug(dev
, mask
, "index %03d val: %016llx\n", i
, buf
[i
/ 8]);
705 * i40iw_get_hw_addr - return hw addr
706 * @par: points to shared dev
708 u8 __iomem
*i40iw_get_hw_addr(void *par
)
710 struct i40iw_sc_dev
*dev
= (struct i40iw_sc_dev
*)par
;
712 return dev
->hw
->hw_addr
;
716 * i40iw_remove_head - return head entry and remove from list
717 * @list: list for entry
719 void *i40iw_remove_head(struct list_head
*list
)
721 struct list_head
*entry
;
723 if (list_empty(list
))
726 entry
= (void *)list
->next
;
728 return (void *)entry
;
732 * i40iw_allocate_dma_mem - Memory alloc helper fn
733 * @hw: pointer to the HW structure
734 * @mem: ptr to mem struct to fill out
735 * @size: size of memory requested
736 * @alignment: what to align the allocation to
738 enum i40iw_status_code
i40iw_allocate_dma_mem(struct i40iw_hw
*hw
,
739 struct i40iw_dma_mem
*mem
,
743 struct pci_dev
*pcidev
= (struct pci_dev
*)hw
->dev_context
;
746 return I40IW_ERR_PARAM
;
747 mem
->size
= ALIGN(size
, alignment
);
748 mem
->va
= dma_zalloc_coherent(&pcidev
->dev
, mem
->size
,
749 (dma_addr_t
*)&mem
->pa
, GFP_KERNEL
);
751 return I40IW_ERR_NO_MEMORY
;
756 * i40iw_free_dma_mem - Memory free helper fn
757 * @hw: pointer to the HW structure
758 * @mem: ptr to mem struct to free
760 void i40iw_free_dma_mem(struct i40iw_hw
*hw
, struct i40iw_dma_mem
*mem
)
762 struct pci_dev
*pcidev
= (struct pci_dev
*)hw
->dev_context
;
764 if (!mem
|| !mem
->va
)
767 dma_free_coherent(&pcidev
->dev
, mem
->size
,
768 mem
->va
, (dma_addr_t
)mem
->pa
);
773 * i40iw_allocate_virt_mem - virtual memory alloc helper fn
774 * @hw: pointer to the HW structure
775 * @mem: ptr to mem struct to fill out
776 * @size: size of memory requested
778 enum i40iw_status_code
i40iw_allocate_virt_mem(struct i40iw_hw
*hw
,
779 struct i40iw_virt_mem
*mem
,
783 return I40IW_ERR_PARAM
;
786 mem
->va
= kzalloc(size
, GFP_KERNEL
);
791 return I40IW_ERR_NO_MEMORY
;
795 * i40iw_free_virt_mem - virtual memory free helper fn
796 * @hw: pointer to the HW structure
797 * @mem: ptr to mem struct to free
799 enum i40iw_status_code
i40iw_free_virt_mem(struct i40iw_hw
*hw
,
800 struct i40iw_virt_mem
*mem
)
803 return I40IW_ERR_PARAM
;
805 * mem->va points to the parent of mem, so both mem and mem->va
806 * can not be touched once mem->va is freed
813 * i40iw_cqp_sds_cmd - create cqp command for sd
814 * @dev: hardware control device structure
815 * @sd_info: information for sd cqp
818 enum i40iw_status_code
i40iw_cqp_sds_cmd(struct i40iw_sc_dev
*dev
,
819 struct i40iw_update_sds_info
*sdinfo
)
821 enum i40iw_status_code status
;
822 struct i40iw_cqp_request
*cqp_request
;
823 struct cqp_commands_info
*cqp_info
;
824 struct i40iw_device
*iwdev
= (struct i40iw_device
*)dev
->back_dev
;
826 cqp_request
= i40iw_get_cqp_request(&iwdev
->cqp
, true);
828 return I40IW_ERR_NO_MEMORY
;
829 cqp_info
= &cqp_request
->info
;
830 memcpy(&cqp_info
->in
.u
.update_pe_sds
.info
, sdinfo
,
831 sizeof(cqp_info
->in
.u
.update_pe_sds
.info
));
832 cqp_info
->cqp_cmd
= OP_UPDATE_PE_SDS
;
833 cqp_info
->post_sq
= 1;
834 cqp_info
->in
.u
.update_pe_sds
.dev
= dev
;
835 cqp_info
->in
.u
.update_pe_sds
.scratch
= (uintptr_t)cqp_request
;
836 status
= i40iw_handle_cqp_op(iwdev
, cqp_request
);
838 i40iw_pr_err("CQP-OP Update SD's fail");
843 * i40iw_qp_suspend_resume - cqp command for suspend/resume
844 * @dev: hardware control device structure
845 * @qp: hardware control qp
846 * @suspend: flag if suspend or resume
848 void i40iw_qp_suspend_resume(struct i40iw_sc_dev
*dev
, struct i40iw_sc_qp
*qp
, bool suspend
)
850 struct i40iw_device
*iwdev
= (struct i40iw_device
*)dev
->back_dev
;
851 struct i40iw_cqp_request
*cqp_request
;
852 struct i40iw_sc_cqp
*cqp
= dev
->cqp
;
853 struct cqp_commands_info
*cqp_info
;
854 enum i40iw_status_code status
;
856 cqp_request
= i40iw_get_cqp_request(&iwdev
->cqp
, false);
860 cqp_info
= &cqp_request
->info
;
861 cqp_info
->cqp_cmd
= (suspend
) ? OP_SUSPEND
: OP_RESUME
;
862 cqp_info
->in
.u
.suspend_resume
.cqp
= cqp
;
863 cqp_info
->in
.u
.suspend_resume
.qp
= qp
;
864 cqp_info
->in
.u
.suspend_resume
.scratch
= (uintptr_t)cqp_request
;
865 status
= i40iw_handle_cqp_op(iwdev
, cqp_request
);
867 i40iw_pr_err("CQP-OP QP Suspend/Resume fail");
871 * i40iw_term_modify_qp - modify qp for term message
872 * @qp: hardware control qp
873 * @next_state: qp's next state
874 * @term: terminate code
877 void i40iw_term_modify_qp(struct i40iw_sc_qp
*qp
, u8 next_state
, u8 term
, u8 term_len
)
879 struct i40iw_qp
*iwqp
;
881 iwqp
= (struct i40iw_qp
*)qp
->back_qp
;
882 i40iw_next_iw_state(iwqp
, next_state
, 0, term
, term_len
);
886 * i40iw_terminate_done - after terminate is completed
887 * @qp: hardware control qp
888 * @timeout_occurred: indicates if terminate timer expired
890 void i40iw_terminate_done(struct i40iw_sc_qp
*qp
, int timeout_occurred
)
892 struct i40iw_qp
*iwqp
;
893 u32 next_iwarp_state
= I40IW_QP_STATE_ERROR
;
898 iwqp
= (struct i40iw_qp
*)qp
->back_qp
;
899 spin_lock_irqsave(&iwqp
->lock
, flags
);
900 if (iwqp
->hte_added
) {
904 first_time
= !(qp
->term_flags
& I40IW_TERM_DONE
);
905 qp
->term_flags
|= I40IW_TERM_DONE
;
906 spin_unlock_irqrestore(&iwqp
->lock
, flags
);
908 if (!timeout_occurred
)
909 i40iw_terminate_del_timer(qp
);
911 next_iwarp_state
= I40IW_QP_STATE_CLOSING
;
913 i40iw_next_iw_state(iwqp
, next_iwarp_state
, hte
, 0, 0);
914 i40iw_cm_disconn(iwqp
);
919 * i40iw_terminate_imeout - timeout happened
920 * @context: points to iwarp qp
922 static void i40iw_terminate_timeout(struct timer_list
*t
)
924 struct i40iw_qp
*iwqp
= from_timer(iwqp
, t
, terminate_timer
);
925 struct i40iw_sc_qp
*qp
= (struct i40iw_sc_qp
*)&iwqp
->sc_qp
;
927 i40iw_terminate_done(qp
, 1);
928 i40iw_rem_ref(&iwqp
->ibqp
);
932 * i40iw_terminate_start_timer - start terminate timeout
933 * @qp: hardware control qp
935 void i40iw_terminate_start_timer(struct i40iw_sc_qp
*qp
)
937 struct i40iw_qp
*iwqp
;
939 iwqp
= (struct i40iw_qp
*)qp
->back_qp
;
940 i40iw_add_ref(&iwqp
->ibqp
);
941 timer_setup(&iwqp
->terminate_timer
, i40iw_terminate_timeout
, 0);
942 iwqp
->terminate_timer
.expires
= jiffies
+ HZ
;
943 add_timer(&iwqp
->terminate_timer
);
947 * i40iw_terminate_del_timer - delete terminate timeout
948 * @qp: hardware control qp
950 void i40iw_terminate_del_timer(struct i40iw_sc_qp
*qp
)
952 struct i40iw_qp
*iwqp
;
954 iwqp
= (struct i40iw_qp
*)qp
->back_qp
;
955 if (del_timer(&iwqp
->terminate_timer
))
956 i40iw_rem_ref(&iwqp
->ibqp
);
960 * i40iw_cqp_generic_worker - generic worker for cqp
961 * @work: work pointer
963 static void i40iw_cqp_generic_worker(struct work_struct
*work
)
965 struct i40iw_virtchnl_work_info
*work_info
=
966 &((struct virtchnl_work
*)work
)->work_info
;
968 if (work_info
->worker_vf_dev
)
969 work_info
->callback_fcn(work_info
->worker_vf_dev
);
973 * i40iw_cqp_spawn_worker - spawn worket thread
974 * @iwdev: device struct pointer
975 * @work_info: work request info
976 * @iw_vf_idx: virtual function index
978 void i40iw_cqp_spawn_worker(struct i40iw_sc_dev
*dev
,
979 struct i40iw_virtchnl_work_info
*work_info
,
982 struct virtchnl_work
*work
;
983 struct i40iw_device
*iwdev
= (struct i40iw_device
*)dev
->back_dev
;
985 work
= &iwdev
->virtchnl_w
[iw_vf_idx
];
986 memcpy(&work
->work_info
, work_info
, sizeof(*work_info
));
987 INIT_WORK(&work
->work
, i40iw_cqp_generic_worker
);
988 queue_work(iwdev
->virtchnl_wq
, &work
->work
);
992 * i40iw_cqp_manage_hmc_fcn_worker -
993 * @work: work pointer for hmc info
995 static void i40iw_cqp_manage_hmc_fcn_worker(struct work_struct
*work
)
997 struct i40iw_cqp_request
*cqp_request
=
998 ((struct virtchnl_work
*)work
)->cqp_request
;
999 struct i40iw_ccq_cqe_info ccq_cqe_info
;
1000 struct i40iw_hmc_fcn_info
*hmcfcninfo
=
1001 &cqp_request
->info
.in
.u
.manage_hmc_pm
.info
;
1002 struct i40iw_device
*iwdev
=
1003 (struct i40iw_device
*)cqp_request
->info
.in
.u
.manage_hmc_pm
.dev
->back_dev
;
1005 ccq_cqe_info
.cqp
= NULL
;
1006 ccq_cqe_info
.maj_err_code
= cqp_request
->compl_info
.maj_err_code
;
1007 ccq_cqe_info
.min_err_code
= cqp_request
->compl_info
.min_err_code
;
1008 ccq_cqe_info
.op_code
= cqp_request
->compl_info
.op_code
;
1009 ccq_cqe_info
.op_ret_val
= cqp_request
->compl_info
.op_ret_val
;
1010 ccq_cqe_info
.scratch
= 0;
1011 ccq_cqe_info
.error
= cqp_request
->compl_info
.error
;
1012 hmcfcninfo
->callback_fcn(cqp_request
->info
.in
.u
.manage_hmc_pm
.dev
,
1013 hmcfcninfo
->cqp_callback_param
, &ccq_cqe_info
);
1014 i40iw_put_cqp_request(&iwdev
->cqp
, cqp_request
);
1018 * i40iw_cqp_manage_hmc_fcn_callback - called function after cqp completion
1019 * @cqp_request: cqp request info struct for hmc fun
1020 * @unused: unused param of callback
1022 static void i40iw_cqp_manage_hmc_fcn_callback(struct i40iw_cqp_request
*cqp_request
,
1025 struct virtchnl_work
*work
;
1026 struct i40iw_hmc_fcn_info
*hmcfcninfo
=
1027 &cqp_request
->info
.in
.u
.manage_hmc_pm
.info
;
1028 struct i40iw_device
*iwdev
=
1029 (struct i40iw_device
*)cqp_request
->info
.in
.u
.manage_hmc_pm
.dev
->
1032 if (hmcfcninfo
&& hmcfcninfo
->callback_fcn
) {
1033 i40iw_debug(&iwdev
->sc_dev
, I40IW_DEBUG_HMC
, "%s1\n", __func__
);
1034 atomic_inc(&cqp_request
->refcount
);
1035 work
= &iwdev
->virtchnl_w
[hmcfcninfo
->iw_vf_idx
];
1036 work
->cqp_request
= cqp_request
;
1037 INIT_WORK(&work
->work
, i40iw_cqp_manage_hmc_fcn_worker
);
1038 queue_work(iwdev
->virtchnl_wq
, &work
->work
);
1039 i40iw_debug(&iwdev
->sc_dev
, I40IW_DEBUG_HMC
, "%s2\n", __func__
);
1041 i40iw_debug(&iwdev
->sc_dev
, I40IW_DEBUG_HMC
, "%s: Something wrong\n", __func__
);
1046 * i40iw_cqp_manage_hmc_fcn_cmd - issue cqp command to manage hmc
1047 * @dev: hardware control device structure
1048 * @hmcfcninfo: info for hmc
1050 enum i40iw_status_code
i40iw_cqp_manage_hmc_fcn_cmd(struct i40iw_sc_dev
*dev
,
1051 struct i40iw_hmc_fcn_info
*hmcfcninfo
)
1053 enum i40iw_status_code status
;
1054 struct i40iw_cqp_request
*cqp_request
;
1055 struct cqp_commands_info
*cqp_info
;
1056 struct i40iw_device
*iwdev
= (struct i40iw_device
*)dev
->back_dev
;
1058 i40iw_debug(&iwdev
->sc_dev
, I40IW_DEBUG_HMC
, "%s\n", __func__
);
1059 cqp_request
= i40iw_get_cqp_request(&iwdev
->cqp
, false);
1061 return I40IW_ERR_NO_MEMORY
;
1062 cqp_info
= &cqp_request
->info
;
1063 cqp_request
->callback_fcn
= i40iw_cqp_manage_hmc_fcn_callback
;
1064 cqp_request
->param
= hmcfcninfo
;
1065 memcpy(&cqp_info
->in
.u
.manage_hmc_pm
.info
, hmcfcninfo
,
1066 sizeof(*hmcfcninfo
));
1067 cqp_info
->in
.u
.manage_hmc_pm
.dev
= dev
;
1068 cqp_info
->cqp_cmd
= OP_MANAGE_HMC_PM_FUNC_TABLE
;
1069 cqp_info
->post_sq
= 1;
1070 cqp_info
->in
.u
.manage_hmc_pm
.scratch
= (uintptr_t)cqp_request
;
1071 status
= i40iw_handle_cqp_op(iwdev
, cqp_request
);
1073 i40iw_pr_err("CQP-OP Manage HMC fail");
1078 * i40iw_cqp_query_fpm_values_cmd - send cqp command for fpm
1079 * @iwdev: function device struct
1080 * @values_mem: buffer for fpm
1081 * @hmc_fn_id: function id for fpm
1083 enum i40iw_status_code
i40iw_cqp_query_fpm_values_cmd(struct i40iw_sc_dev
*dev
,
1084 struct i40iw_dma_mem
*values_mem
,
1087 enum i40iw_status_code status
;
1088 struct i40iw_cqp_request
*cqp_request
;
1089 struct cqp_commands_info
*cqp_info
;
1090 struct i40iw_device
*iwdev
= (struct i40iw_device
*)dev
->back_dev
;
1092 cqp_request
= i40iw_get_cqp_request(&iwdev
->cqp
, true);
1094 return I40IW_ERR_NO_MEMORY
;
1095 cqp_info
= &cqp_request
->info
;
1096 cqp_request
->param
= NULL
;
1097 cqp_info
->in
.u
.query_fpm_values
.cqp
= dev
->cqp
;
1098 cqp_info
->in
.u
.query_fpm_values
.fpm_values_pa
= values_mem
->pa
;
1099 cqp_info
->in
.u
.query_fpm_values
.fpm_values_va
= values_mem
->va
;
1100 cqp_info
->in
.u
.query_fpm_values
.hmc_fn_id
= hmc_fn_id
;
1101 cqp_info
->cqp_cmd
= OP_QUERY_FPM_VALUES
;
1102 cqp_info
->post_sq
= 1;
1103 cqp_info
->in
.u
.query_fpm_values
.scratch
= (uintptr_t)cqp_request
;
1104 status
= i40iw_handle_cqp_op(iwdev
, cqp_request
);
1106 i40iw_pr_err("CQP-OP Query FPM fail");
1111 * i40iw_cqp_commit_fpm_values_cmd - commit fpm values in hw
1112 * @dev: hardware control device structure
1113 * @values_mem: buffer with fpm values
1114 * @hmc_fn_id: function id for fpm
1116 enum i40iw_status_code
i40iw_cqp_commit_fpm_values_cmd(struct i40iw_sc_dev
*dev
,
1117 struct i40iw_dma_mem
*values_mem
,
1120 enum i40iw_status_code status
;
1121 struct i40iw_cqp_request
*cqp_request
;
1122 struct cqp_commands_info
*cqp_info
;
1123 struct i40iw_device
*iwdev
= (struct i40iw_device
*)dev
->back_dev
;
1125 cqp_request
= i40iw_get_cqp_request(&iwdev
->cqp
, true);
1127 return I40IW_ERR_NO_MEMORY
;
1128 cqp_info
= &cqp_request
->info
;
1129 cqp_request
->param
= NULL
;
1130 cqp_info
->in
.u
.commit_fpm_values
.cqp
= dev
->cqp
;
1131 cqp_info
->in
.u
.commit_fpm_values
.fpm_values_pa
= values_mem
->pa
;
1132 cqp_info
->in
.u
.commit_fpm_values
.fpm_values_va
= values_mem
->va
;
1133 cqp_info
->in
.u
.commit_fpm_values
.hmc_fn_id
= hmc_fn_id
;
1134 cqp_info
->cqp_cmd
= OP_COMMIT_FPM_VALUES
;
1135 cqp_info
->post_sq
= 1;
1136 cqp_info
->in
.u
.commit_fpm_values
.scratch
= (uintptr_t)cqp_request
;
1137 status
= i40iw_handle_cqp_op(iwdev
, cqp_request
);
1139 i40iw_pr_err("CQP-OP Commit FPM fail");
1144 * i40iw_vf_wait_vchnl_resp - wait for channel msg
1145 * @iwdev: function's device struct
1147 enum i40iw_status_code
i40iw_vf_wait_vchnl_resp(struct i40iw_sc_dev
*dev
)
1149 struct i40iw_device
*iwdev
= dev
->back_dev
;
1152 i40iw_debug(dev
, I40IW_DEBUG_VIRT
, "%s[%u] dev %p, iwdev %p\n",
1153 __func__
, __LINE__
, dev
, iwdev
);
1155 atomic_set(&iwdev
->vchnl_msgs
, 2);
1156 timeout_ret
= wait_event_timeout(iwdev
->vchnl_waitq
,
1157 (atomic_read(&iwdev
->vchnl_msgs
) == 1),
1158 I40IW_VCHNL_EVENT_TIMEOUT
);
1159 atomic_dec(&iwdev
->vchnl_msgs
);
1161 i40iw_pr_err("virt channel completion timeout = 0x%x\n", timeout_ret
);
1162 atomic_set(&iwdev
->vchnl_msgs
, 0);
1163 dev
->vchnl_up
= false;
1164 return I40IW_ERR_TIMEOUT
;
1166 wake_up(&dev
->vf_reqs
);
1171 * i40iw_cqp_cq_create_cmd - create a cq for the cqp
1172 * @dev: device pointer
1173 * @cq: pointer to created cq
1175 enum i40iw_status_code
i40iw_cqp_cq_create_cmd(struct i40iw_sc_dev
*dev
,
1176 struct i40iw_sc_cq
*cq
)
1178 struct i40iw_device
*iwdev
= (struct i40iw_device
*)dev
->back_dev
;
1179 struct i40iw_cqp
*iwcqp
= &iwdev
->cqp
;
1180 struct i40iw_cqp_request
*cqp_request
;
1181 struct cqp_commands_info
*cqp_info
;
1182 enum i40iw_status_code status
;
1184 cqp_request
= i40iw_get_cqp_request(iwcqp
, true);
1186 return I40IW_ERR_NO_MEMORY
;
1188 cqp_info
= &cqp_request
->info
;
1189 cqp_info
->cqp_cmd
= OP_CQ_CREATE
;
1190 cqp_info
->post_sq
= 1;
1191 cqp_info
->in
.u
.cq_create
.cq
= cq
;
1192 cqp_info
->in
.u
.cq_create
.scratch
= (uintptr_t)cqp_request
;
1193 status
= i40iw_handle_cqp_op(iwdev
, cqp_request
);
1195 i40iw_pr_err("CQP-OP Create QP fail");
1201 * i40iw_cqp_qp_create_cmd - create a qp for the cqp
1202 * @dev: device pointer
1203 * @qp: pointer to created qp
1205 enum i40iw_status_code
i40iw_cqp_qp_create_cmd(struct i40iw_sc_dev
*dev
,
1206 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 struct i40iw_create_qp_info
*qp_info
;
1213 enum i40iw_status_code status
;
1215 cqp_request
= i40iw_get_cqp_request(iwcqp
, true);
1217 return I40IW_ERR_NO_MEMORY
;
1219 cqp_info
= &cqp_request
->info
;
1220 qp_info
= &cqp_request
->info
.in
.u
.qp_create
.info
;
1222 memset(qp_info
, 0, sizeof(*qp_info
));
1224 qp_info
->cq_num_valid
= true;
1225 qp_info
->next_iwarp_state
= I40IW_QP_STATE_RTS
;
1227 cqp_info
->cqp_cmd
= OP_QP_CREATE
;
1228 cqp_info
->post_sq
= 1;
1229 cqp_info
->in
.u
.qp_create
.qp
= qp
;
1230 cqp_info
->in
.u
.qp_create
.scratch
= (uintptr_t)cqp_request
;
1231 status
= i40iw_handle_cqp_op(iwdev
, cqp_request
);
1233 i40iw_pr_err("CQP-OP QP create fail");
1238 * i40iw_cqp_cq_destroy_cmd - destroy the cqp cq
1239 * @dev: device pointer
1240 * @cq: pointer to cq
1242 void i40iw_cqp_cq_destroy_cmd(struct i40iw_sc_dev
*dev
, struct i40iw_sc_cq
*cq
)
1244 struct i40iw_device
*iwdev
= (struct i40iw_device
*)dev
->back_dev
;
1246 i40iw_cq_wq_destroy(iwdev
, cq
);
1250 * i40iw_cqp_qp_destroy_cmd - destroy the cqp
1251 * @dev: device pointer
1252 * @qp: pointer to qp
1254 void i40iw_cqp_qp_destroy_cmd(struct i40iw_sc_dev
*dev
, struct i40iw_sc_qp
*qp
)
1256 struct i40iw_device
*iwdev
= (struct i40iw_device
*)dev
->back_dev
;
1257 struct i40iw_cqp
*iwcqp
= &iwdev
->cqp
;
1258 struct i40iw_cqp_request
*cqp_request
;
1259 struct cqp_commands_info
*cqp_info
;
1260 enum i40iw_status_code status
;
1262 cqp_request
= i40iw_get_cqp_request(iwcqp
, true);
1266 cqp_info
= &cqp_request
->info
;
1267 memset(cqp_info
, 0, sizeof(*cqp_info
));
1269 cqp_info
->cqp_cmd
= OP_QP_DESTROY
;
1270 cqp_info
->post_sq
= 1;
1271 cqp_info
->in
.u
.qp_destroy
.qp
= qp
;
1272 cqp_info
->in
.u
.qp_destroy
.scratch
= (uintptr_t)cqp_request
;
1273 cqp_info
->in
.u
.qp_destroy
.remove_hash_idx
= true;
1274 status
= i40iw_handle_cqp_op(iwdev
, cqp_request
);
1276 i40iw_pr_err("CQP QP_DESTROY fail");
1281 * i40iw_ieq_mpa_crc_ae - generate AE for crc error
1282 * @dev: hardware control device structure
1283 * @qp: hardware control qp
1285 void i40iw_ieq_mpa_crc_ae(struct i40iw_sc_dev
*dev
, struct i40iw_sc_qp
*qp
)
1287 struct i40iw_qp_flush_info info
;
1288 struct i40iw_device
*iwdev
= (struct i40iw_device
*)dev
->back_dev
;
1290 i40iw_debug(dev
, I40IW_DEBUG_AEQ
, "%s entered\n", __func__
);
1291 memset(&info
, 0, sizeof(info
));
1292 info
.ae_code
= I40IW_AE_LLP_RECEIVED_MPA_CRC_ERROR
;
1293 info
.generate_ae
= true;
1294 info
.ae_source
= 0x3;
1295 (void)i40iw_hw_flush_wqes(iwdev
, qp
, &info
, false);
1299 * i40iw_init_hash_desc - initialize hash for crc calculation
1300 * @desc: cryption type
1302 enum i40iw_status_code
i40iw_init_hash_desc(struct shash_desc
**desc
)
1304 struct crypto_shash
*tfm
;
1305 struct shash_desc
*tdesc
;
1307 tfm
= crypto_alloc_shash("crc32c", 0, 0);
1309 return I40IW_ERR_MPA_CRC
;
1311 tdesc
= kzalloc(sizeof(*tdesc
) + crypto_shash_descsize(tfm
),
1314 crypto_free_shash(tfm
);
1315 return I40IW_ERR_MPA_CRC
;
1324 * i40iw_free_hash_desc - free hash desc
1325 * @desc: to be freed
1327 void i40iw_free_hash_desc(struct shash_desc
*desc
)
1330 crypto_free_shash(desc
->tfm
);
1336 * i40iw_alloc_query_fpm_buf - allocate buffer for fpm
1337 * @dev: hardware control device structure
1338 * @mem: buffer ptr for fpm to be allocated
1339 * @return: memory allocation status
1341 enum i40iw_status_code
i40iw_alloc_query_fpm_buf(struct i40iw_sc_dev
*dev
,
1342 struct i40iw_dma_mem
*mem
)
1344 enum i40iw_status_code status
;
1345 struct i40iw_device
*iwdev
= (struct i40iw_device
*)dev
->back_dev
;
1347 status
= i40iw_obj_aligned_mem(iwdev
, mem
, I40IW_QUERY_FPM_BUF_SIZE
,
1348 I40IW_FPM_QUERY_BUF_ALIGNMENT_MASK
);
1353 * i40iw_ieq_check_mpacrc - check if mpa crc is OK
1354 * @desc: desc for hash
1355 * @addr: address of buffer for crc
1356 * @length: length of buffer
1357 * @value: value to be compared
1359 enum i40iw_status_code
i40iw_ieq_check_mpacrc(struct shash_desc
*desc
,
1366 enum i40iw_status_code ret_code
= 0;
1368 crypto_shash_init(desc
);
1369 ret
= crypto_shash_update(desc
, addr
, length
);
1371 crypto_shash_final(desc
, (u8
*)&crc
);
1373 i40iw_pr_err("mpa crc check fail\n");
1374 ret_code
= I40IW_ERR_MPA_CRC
;
1380 * i40iw_ieq_get_qp - get qp based on quad in puda buffer
1381 * @dev: hardware control device structure
1382 * @buf: receive puda buffer on exception q
1384 struct i40iw_sc_qp
*i40iw_ieq_get_qp(struct i40iw_sc_dev
*dev
,
1385 struct i40iw_puda_buf
*buf
)
1387 struct i40iw_device
*iwdev
= (struct i40iw_device
*)dev
->back_dev
;
1388 struct i40iw_qp
*iwqp
;
1389 struct i40iw_cm_node
*cm_node
;
1390 u32 loc_addr
[4], rem_addr
[4];
1391 u16 loc_port
, rem_port
;
1392 struct ipv6hdr
*ip6h
;
1393 struct iphdr
*iph
= (struct iphdr
*)buf
->iph
;
1394 struct tcphdr
*tcph
= (struct tcphdr
*)buf
->tcph
;
1396 if (iph
->version
== 4) {
1397 memset(loc_addr
, 0, sizeof(loc_addr
));
1398 loc_addr
[0] = ntohl(iph
->daddr
);
1399 memset(rem_addr
, 0, sizeof(rem_addr
));
1400 rem_addr
[0] = ntohl(iph
->saddr
);
1402 ip6h
= (struct ipv6hdr
*)buf
->iph
;
1403 i40iw_copy_ip_ntohl(loc_addr
, ip6h
->daddr
.in6_u
.u6_addr32
);
1404 i40iw_copy_ip_ntohl(rem_addr
, ip6h
->saddr
.in6_u
.u6_addr32
);
1406 loc_port
= ntohs(tcph
->dest
);
1407 rem_port
= ntohs(tcph
->source
);
1409 cm_node
= i40iw_find_node(&iwdev
->cm_core
, rem_port
, rem_addr
, loc_port
,
1413 iwqp
= cm_node
->iwqp
;
1414 return &iwqp
->sc_qp
;
1418 * i40iw_ieq_update_tcpip_info - update tcpip in the buffer
1419 * @buf: puda to update
1420 * @length: length of buffer
1421 * @seqnum: seq number for tcp
1423 void i40iw_ieq_update_tcpip_info(struct i40iw_puda_buf
*buf
, u16 length
, u32 seqnum
)
1425 struct tcphdr
*tcph
;
1429 u8
*addr
= (u8
*)buf
->mem
.va
;
1431 iphlen
= (buf
->ipv4
) ? 20 : 40;
1432 iph
= (struct iphdr
*)(addr
+ buf
->maclen
);
1433 tcph
= (struct tcphdr
*)(addr
+ buf
->maclen
+ iphlen
);
1434 packetsize
= length
+ buf
->tcphlen
+ iphlen
;
1436 iph
->tot_len
= htons(packetsize
);
1437 tcph
->seq
= htonl(seqnum
);
1441 * i40iw_puda_get_tcpip_info - get tcpip info from puda buffer
1442 * @info: to get information
1445 enum i40iw_status_code
i40iw_puda_get_tcpip_info(struct i40iw_puda_completion_info
*info
,
1446 struct i40iw_puda_buf
*buf
)
1449 struct ipv6hdr
*ip6h
;
1450 struct tcphdr
*tcph
;
1453 u8
*mem
= (u8
*)buf
->mem
.va
;
1454 struct ethhdr
*ethh
= (struct ethhdr
*)buf
->mem
.va
;
1456 if (ethh
->h_proto
== htons(0x8100)) {
1457 info
->vlan_valid
= true;
1458 buf
->vlan_id
= ntohs(((struct vlan_ethhdr
*)ethh
)->h_vlan_TCI
) & VLAN_VID_MASK
;
1460 buf
->maclen
= (info
->vlan_valid
) ? 18 : 14;
1461 iphlen
= (info
->l3proto
) ? 40 : 20;
1462 buf
->ipv4
= (info
->l3proto
) ? false : true;
1463 buf
->iph
= mem
+ buf
->maclen
;
1464 iph
= (struct iphdr
*)buf
->iph
;
1466 buf
->tcph
= buf
->iph
+ iphlen
;
1467 tcph
= (struct tcphdr
*)buf
->tcph
;
1470 pkt_len
= ntohs(iph
->tot_len
);
1472 ip6h
= (struct ipv6hdr
*)buf
->iph
;
1473 pkt_len
= ntohs(ip6h
->payload_len
) + iphlen
;
1476 buf
->totallen
= pkt_len
+ buf
->maclen
;
1478 if (info
->payload_len
< buf
->totallen
) {
1479 i40iw_pr_err("payload_len = 0x%x totallen expected0x%x\n",
1480 info
->payload_len
, buf
->totallen
);
1481 return I40IW_ERR_INVALID_SIZE
;
1484 buf
->tcphlen
= (tcph
->doff
) << 2;
1485 buf
->datalen
= pkt_len
- iphlen
- buf
->tcphlen
;
1486 buf
->data
= (buf
->datalen
) ? buf
->tcph
+ buf
->tcphlen
: NULL
;
1487 buf
->hdrlen
= buf
->maclen
+ iphlen
+ buf
->tcphlen
;
1488 buf
->seqnum
= ntohl(tcph
->seq
);
1493 * i40iw_hw_stats_timeout - Stats timer-handler which updates all HW stats
1494 * @vsi: pointer to the vsi structure
1496 static void i40iw_hw_stats_timeout(struct timer_list
*t
)
1498 struct i40iw_vsi_pestat
*pf_devstat
= from_timer(pf_devstat
, t
,
1500 struct i40iw_sc_vsi
*sc_vsi
= pf_devstat
->vsi
;
1501 struct i40iw_sc_dev
*pf_dev
= sc_vsi
->dev
;
1502 struct i40iw_vsi_pestat
*vf_devstat
= NULL
;
1504 unsigned long flags
;
1507 i40iw_hw_stats_read_all(pf_devstat
, &pf_devstat
->hw_stats
);
1509 for (iw_vf_idx
= 0; iw_vf_idx
< I40IW_MAX_PE_ENABLED_VF_COUNT
; iw_vf_idx
++) {
1510 spin_lock_irqsave(&pf_devstat
->lock
, flags
);
1511 if (pf_dev
->vf_dev
[iw_vf_idx
]) {
1512 if (pf_dev
->vf_dev
[iw_vf_idx
]->stats_initialized
) {
1513 vf_devstat
= &pf_dev
->vf_dev
[iw_vf_idx
]->pestat
;
1514 i40iw_hw_stats_read_all(vf_devstat
, &vf_devstat
->hw_stats
);
1517 spin_unlock_irqrestore(&pf_devstat
->lock
, flags
);
1520 mod_timer(&pf_devstat
->stats_timer
,
1521 jiffies
+ msecs_to_jiffies(STATS_TIMER_DELAY
));
1525 * i40iw_hw_stats_start_timer - Start periodic stats timer
1526 * @vsi: pointer to the vsi structure
1528 void i40iw_hw_stats_start_timer(struct i40iw_sc_vsi
*vsi
)
1530 struct i40iw_vsi_pestat
*devstat
= vsi
->pestat
;
1532 timer_setup(&devstat
->stats_timer
, i40iw_hw_stats_timeout
, 0);
1533 mod_timer(&devstat
->stats_timer
,
1534 jiffies
+ msecs_to_jiffies(STATS_TIMER_DELAY
));
1538 * i40iw_hw_stats_stop_timer - Delete periodic stats timer
1539 * @vsi: pointer to the vsi structure
1541 void i40iw_hw_stats_stop_timer(struct i40iw_sc_vsi
*vsi
)
1543 struct i40iw_vsi_pestat
*devstat
= vsi
->pestat
;
1545 del_timer_sync(&devstat
->stats_timer
);