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
);
179 struct in_ifaddr
*ifa
;
181 ifa
= rcu_dereference(in
->ifa_list
);
183 local_ipaddr
= ntohl(ifa
->ifa_address
);
188 local_ipaddr
= ntohl(ifa
->ifa_address
);
192 action
= I40IW_ARP_DELETE
;
195 case NETDEV_CHANGEADDR
:
197 /* Just skip if no need to handle ARP cache */
201 i40iw_manage_arp_cache(iwdev
,
206 i40iw_if_notify(iwdev
, netdev
, &local_ipaddr
, true,
207 (action
== I40IW_ARP_ADD
) ? true : false);
216 * i40iw_inet6addr_event - system notifier for ipv6 addr events
218 * @event: event for notifier
221 int i40iw_inet6addr_event(struct notifier_block
*notifier
,
225 struct inet6_ifaddr
*ifa
= (struct inet6_ifaddr
*)ptr
;
226 struct net_device
*event_netdev
= ifa
->idev
->dev
;
227 struct net_device
*netdev
;
228 struct i40iw_device
*iwdev
;
229 struct i40iw_handler
*hdl
;
230 u32 local_ipaddr6
[4];
231 u32 action
= I40IW_ARP_ADD
;
233 hdl
= i40iw_find_netdev(event_netdev
);
237 iwdev
= &hdl
->device
;
238 if (iwdev
->init_state
< IP_ADDR_REGISTERED
|| iwdev
->closing
)
241 netdev
= iwdev
->ldev
->netdev
;
242 if (netdev
!= event_netdev
)
245 i40iw_copy_ip_ntohl(local_ipaddr6
, ifa
->addr
.in6_u
.u6_addr32
);
248 action
= I40IW_ARP_DELETE
;
251 case NETDEV_CHANGEADDR
:
252 i40iw_manage_arp_cache(iwdev
,
257 i40iw_if_notify(iwdev
, netdev
, local_ipaddr6
, false,
258 (action
== I40IW_ARP_ADD
) ? true : false);
267 * i40iw_net_event - system notifier for netevents
269 * @event: event for notifier
272 int i40iw_net_event(struct notifier_block
*notifier
, unsigned long event
, void *ptr
)
274 struct neighbour
*neigh
= ptr
;
275 struct i40iw_device
*iwdev
;
276 struct i40iw_handler
*iwhdl
;
281 case NETEVENT_NEIGH_UPDATE
:
282 iwhdl
= i40iw_find_netdev((struct net_device
*)neigh
->dev
);
285 iwdev
= &iwhdl
->device
;
286 if (iwdev
->init_state
< IP_ADDR_REGISTERED
|| iwdev
->closing
)
288 p
= (__be32
*)neigh
->primary_key
;
289 i40iw_copy_ip_ntohl(local_ipaddr
, p
);
290 if (neigh
->nud_state
& NUD_VALID
) {
291 i40iw_manage_arp_cache(iwdev
,
298 i40iw_manage_arp_cache(iwdev
,
312 * i40iw_netdevice_event - system notifier for netdev events
314 * @event: event for notifier
317 int i40iw_netdevice_event(struct notifier_block
*notifier
,
321 struct net_device
*event_netdev
;
322 struct net_device
*netdev
;
323 struct i40iw_device
*iwdev
;
324 struct i40iw_handler
*hdl
;
326 event_netdev
= netdev_notifier_info_to_dev(ptr
);
328 hdl
= i40iw_find_netdev(event_netdev
);
332 iwdev
= &hdl
->device
;
333 if (iwdev
->init_state
< RDMA_DEV_REGISTERED
|| iwdev
->closing
)
336 netdev
= iwdev
->ldev
->netdev
;
337 if (netdev
!= event_netdev
)
340 iwdev
->iw_status
= 1;
344 iwdev
->iw_status
= 0;
347 i40iw_port_ibevent(iwdev
);
356 * i40iw_get_cqp_request - get cqp struct
357 * @cqp: device cqp ptr
358 * @wait: cqp to be used in wait mode
360 struct i40iw_cqp_request
*i40iw_get_cqp_request(struct i40iw_cqp
*cqp
, bool wait
)
362 struct i40iw_cqp_request
*cqp_request
= NULL
;
365 spin_lock_irqsave(&cqp
->req_lock
, flags
);
366 if (!list_empty(&cqp
->cqp_avail_reqs
)) {
367 cqp_request
= list_entry(cqp
->cqp_avail_reqs
.next
,
368 struct i40iw_cqp_request
, list
);
369 list_del_init(&cqp_request
->list
);
371 spin_unlock_irqrestore(&cqp
->req_lock
, flags
);
373 cqp_request
= kzalloc(sizeof(*cqp_request
), GFP_ATOMIC
);
375 cqp_request
->dynamic
= true;
376 INIT_LIST_HEAD(&cqp_request
->list
);
377 init_waitqueue_head(&cqp_request
->waitq
);
381 i40iw_pr_err("CQP Request Fail: No Memory");
386 atomic_set(&cqp_request
->refcount
, 2);
387 cqp_request
->waiting
= true;
389 atomic_set(&cqp_request
->refcount
, 1);
395 * i40iw_free_cqp_request - free cqp request
397 * @cqp_request: to be put back in cqp list
399 void i40iw_free_cqp_request(struct i40iw_cqp
*cqp
, struct i40iw_cqp_request
*cqp_request
)
401 struct i40iw_device
*iwdev
= container_of(cqp
, struct i40iw_device
, cqp
);
404 if (cqp_request
->dynamic
) {
407 cqp_request
->request_done
= false;
408 cqp_request
->callback_fcn
= NULL
;
409 cqp_request
->waiting
= false;
411 spin_lock_irqsave(&cqp
->req_lock
, flags
);
412 list_add_tail(&cqp_request
->list
, &cqp
->cqp_avail_reqs
);
413 spin_unlock_irqrestore(&cqp
->req_lock
, flags
);
415 wake_up(&iwdev
->close_wq
);
419 * i40iw_put_cqp_request - dec ref count and free if 0
421 * @cqp_request: to be put back in cqp list
423 void i40iw_put_cqp_request(struct i40iw_cqp
*cqp
,
424 struct i40iw_cqp_request
*cqp_request
)
426 if (atomic_dec_and_test(&cqp_request
->refcount
))
427 i40iw_free_cqp_request(cqp
, cqp_request
);
431 * i40iw_free_pending_cqp_request -free pending cqp request objs
433 * @cqp_request: to be put back in cqp list
435 static void i40iw_free_pending_cqp_request(struct i40iw_cqp
*cqp
,
436 struct i40iw_cqp_request
*cqp_request
)
438 struct i40iw_device
*iwdev
= container_of(cqp
, struct i40iw_device
, cqp
);
440 if (cqp_request
->waiting
) {
441 cqp_request
->compl_info
.error
= true;
442 cqp_request
->request_done
= true;
443 wake_up(&cqp_request
->waitq
);
445 i40iw_put_cqp_request(cqp
, cqp_request
);
446 wait_event_timeout(iwdev
->close_wq
,
447 !atomic_read(&cqp_request
->refcount
),
452 * i40iw_cleanup_pending_cqp_op - clean-up cqp with no completions
453 * @iwdev: iwarp device
455 void i40iw_cleanup_pending_cqp_op(struct i40iw_device
*iwdev
)
457 struct i40iw_sc_dev
*dev
= &iwdev
->sc_dev
;
458 struct i40iw_cqp
*cqp
= &iwdev
->cqp
;
459 struct i40iw_cqp_request
*cqp_request
= NULL
;
460 struct cqp_commands_info
*pcmdinfo
= NULL
;
461 u32 i
, pending_work
, wqe_idx
;
463 pending_work
= I40IW_RING_WORK_AVAILABLE(cqp
->sc_cqp
.sq_ring
);
464 wqe_idx
= I40IW_RING_GETCURRENT_TAIL(cqp
->sc_cqp
.sq_ring
);
465 for (i
= 0; i
< pending_work
; i
++) {
466 cqp_request
= (struct i40iw_cqp_request
*)(unsigned long)cqp
->scratch_array
[wqe_idx
];
468 i40iw_free_pending_cqp_request(cqp
, cqp_request
);
469 wqe_idx
= (wqe_idx
+ 1) % I40IW_RING_GETSIZE(cqp
->sc_cqp
.sq_ring
);
472 while (!list_empty(&dev
->cqp_cmd_head
)) {
473 pcmdinfo
= (struct cqp_commands_info
*)i40iw_remove_head(&dev
->cqp_cmd_head
);
474 cqp_request
= container_of(pcmdinfo
, struct i40iw_cqp_request
, info
);
476 i40iw_free_pending_cqp_request(cqp
, cqp_request
);
481 * i40iw_wait_event - wait for completion
482 * @iwdev: iwarp device
483 * @cqp_request: cqp request to wait
485 static int i40iw_wait_event(struct i40iw_device
*iwdev
,
486 struct i40iw_cqp_request
*cqp_request
)
488 struct cqp_commands_info
*info
= &cqp_request
->info
;
489 struct i40iw_cqp
*iwcqp
= &iwdev
->cqp
;
490 struct i40iw_cqp_timeout cqp_timeout
;
491 bool cqp_error
= false;
493 memset(&cqp_timeout
, 0, sizeof(cqp_timeout
));
494 cqp_timeout
.compl_cqp_cmds
= iwdev
->sc_dev
.cqp_cmd_stats
[OP_COMPLETED_COMMANDS
];
496 if (wait_event_timeout(cqp_request
->waitq
,
497 cqp_request
->request_done
, CQP_COMPL_WAIT_TIME
))
500 i40iw_check_cqp_progress(&cqp_timeout
, &iwdev
->sc_dev
);
502 if (cqp_timeout
.count
< CQP_TIMEOUT_THRESHOLD
)
505 i40iw_pr_err("error cqp command 0x%x timed out", info
->cqp_cmd
);
509 i40iw_request_reset(iwdev
);
513 cqp_error
= cqp_request
->compl_info
.error
;
515 i40iw_pr_err("error cqp command 0x%x completion maj = 0x%x min=0x%x\n",
516 info
->cqp_cmd
, cqp_request
->compl_info
.maj_err_code
,
517 cqp_request
->compl_info
.min_err_code
);
522 i40iw_put_cqp_request(iwcqp
, cqp_request
);
527 * i40iw_handle_cqp_op - process cqp command
528 * @iwdev: iwarp device
529 * @cqp_request: cqp request to process
531 enum i40iw_status_code
i40iw_handle_cqp_op(struct i40iw_device
*iwdev
,
532 struct i40iw_cqp_request
535 struct i40iw_sc_dev
*dev
= &iwdev
->sc_dev
;
536 enum i40iw_status_code status
;
537 struct cqp_commands_info
*info
= &cqp_request
->info
;
541 i40iw_free_cqp_request(&iwdev
->cqp
, cqp_request
);
542 return I40IW_ERR_CQP_COMPL_ERROR
;
545 status
= i40iw_process_cqp_cmd(dev
, info
);
547 i40iw_pr_err("error cqp command 0x%x failed\n", info
->cqp_cmd
);
548 i40iw_free_cqp_request(&iwdev
->cqp
, cqp_request
);
551 if (cqp_request
->waiting
)
552 err_code
= i40iw_wait_event(iwdev
, cqp_request
);
554 status
= I40IW_ERR_CQP_COMPL_ERROR
;
559 * i40iw_add_devusecount - add dev refcount
560 * @iwdev: dev for refcount
562 void i40iw_add_devusecount(struct i40iw_device
*iwdev
)
564 atomic64_inc(&iwdev
->use_count
);
568 * i40iw_rem_devusecount - decrement refcount for dev
571 void i40iw_rem_devusecount(struct i40iw_device
*iwdev
)
573 if (!atomic64_dec_and_test(&iwdev
->use_count
))
575 wake_up(&iwdev
->close_wq
);
579 * i40iw_add_pdusecount - add pd refcount
580 * @iwpd: pd for refcount
582 void i40iw_add_pdusecount(struct i40iw_pd
*iwpd
)
584 atomic_inc(&iwpd
->usecount
);
588 * i40iw_rem_pdusecount - decrement refcount for pd and free if 0
589 * @iwpd: pd for refcount
590 * @iwdev: iwarp device
592 void i40iw_rem_pdusecount(struct i40iw_pd
*iwpd
, struct i40iw_device
*iwdev
)
594 if (!atomic_dec_and_test(&iwpd
->usecount
))
596 i40iw_free_resource(iwdev
, iwdev
->allocated_pds
, iwpd
->sc_pd
.pd_id
);
600 * i40iw_qp_add_ref - add refcount for qp
603 void i40iw_qp_add_ref(struct ib_qp
*ibqp
)
605 struct i40iw_qp
*iwqp
= (struct i40iw_qp
*)ibqp
;
607 refcount_inc(&iwqp
->refcount
);
611 * i40iw_qp_rem_ref - rem refcount for qp and free if 0
614 void i40iw_qp_rem_ref(struct ib_qp
*ibqp
)
616 struct i40iw_qp
*iwqp
;
617 struct i40iw_device
*iwdev
;
621 iwqp
= to_iwqp(ibqp
);
623 spin_lock_irqsave(&iwdev
->qptable_lock
, flags
);
624 if (!refcount_dec_and_test(&iwqp
->refcount
)) {
625 spin_unlock_irqrestore(&iwdev
->qptable_lock
, flags
);
629 qp_num
= iwqp
->ibqp
.qp_num
;
630 iwdev
->qp_table
[qp_num
] = NULL
;
631 spin_unlock_irqrestore(&iwdev
->qptable_lock
, flags
);
632 complete(&iwqp
->free_qp
);
637 * i40iw_get_qp - get qp address
638 * @device: iwarp device
641 struct ib_qp
*i40iw_get_qp(struct ib_device
*device
, int qpn
)
643 struct i40iw_device
*iwdev
= to_iwdev(device
);
645 if ((qpn
< IW_FIRST_QPN
) || (qpn
>= iwdev
->max_qp
))
648 return &iwdev
->qp_table
[qpn
]->ibqp
;
652 * i40iw_debug_buf - print debug msg and buffer is mask set
653 * @dev: hardware control device structure
654 * @mask: mask to compare if to print debug buffer
655 * @buf: points buffer addr
656 * @size: saize of buffer to print
658 void i40iw_debug_buf(struct i40iw_sc_dev
*dev
,
659 enum i40iw_debug_flag mask
,
666 if (!(dev
->debug_mask
& mask
))
668 i40iw_debug(dev
, mask
, "%s\n", desc
);
669 i40iw_debug(dev
, mask
, "starting address virt=%p phy=%llxh\n", buf
,
670 (unsigned long long)virt_to_phys(buf
));
672 for (i
= 0; i
< size
; i
+= 8)
673 i40iw_debug(dev
, mask
, "index %03d val: %016llx\n", i
, buf
[i
/ 8]);
677 * i40iw_get_hw_addr - return hw addr
678 * @par: points to shared dev
680 u8 __iomem
*i40iw_get_hw_addr(void *par
)
682 struct i40iw_sc_dev
*dev
= (struct i40iw_sc_dev
*)par
;
684 return dev
->hw
->hw_addr
;
688 * i40iw_remove_head - return head entry and remove from list
689 * @list: list for entry
691 void *i40iw_remove_head(struct list_head
*list
)
693 struct list_head
*entry
;
695 if (list_empty(list
))
698 entry
= (void *)list
->next
;
700 return (void *)entry
;
704 * i40iw_allocate_dma_mem - Memory alloc helper fn
705 * @hw: pointer to the HW structure
706 * @mem: ptr to mem struct to fill out
707 * @size: size of memory requested
708 * @alignment: what to align the allocation to
710 enum i40iw_status_code
i40iw_allocate_dma_mem(struct i40iw_hw
*hw
,
711 struct i40iw_dma_mem
*mem
,
715 struct pci_dev
*pcidev
= hw
->pcidev
;
718 return I40IW_ERR_PARAM
;
719 mem
->size
= ALIGN(size
, alignment
);
720 mem
->va
= dma_alloc_coherent(&pcidev
->dev
, mem
->size
,
721 (dma_addr_t
*)&mem
->pa
, GFP_KERNEL
);
723 return I40IW_ERR_NO_MEMORY
;
728 * i40iw_free_dma_mem - Memory free helper fn
729 * @hw: pointer to the HW structure
730 * @mem: ptr to mem struct to free
732 void i40iw_free_dma_mem(struct i40iw_hw
*hw
, struct i40iw_dma_mem
*mem
)
734 struct pci_dev
*pcidev
= hw
->pcidev
;
736 if (!mem
|| !mem
->va
)
739 dma_free_coherent(&pcidev
->dev
, mem
->size
,
740 mem
->va
, (dma_addr_t
)mem
->pa
);
745 * i40iw_allocate_virt_mem - virtual memory alloc helper fn
746 * @hw: pointer to the HW structure
747 * @mem: ptr to mem struct to fill out
748 * @size: size of memory requested
750 enum i40iw_status_code
i40iw_allocate_virt_mem(struct i40iw_hw
*hw
,
751 struct i40iw_virt_mem
*mem
,
755 return I40IW_ERR_PARAM
;
758 mem
->va
= kzalloc(size
, GFP_KERNEL
);
763 return I40IW_ERR_NO_MEMORY
;
767 * i40iw_free_virt_mem - virtual memory free helper fn
768 * @hw: pointer to the HW structure
769 * @mem: ptr to mem struct to free
771 enum i40iw_status_code
i40iw_free_virt_mem(struct i40iw_hw
*hw
,
772 struct i40iw_virt_mem
*mem
)
775 return I40IW_ERR_PARAM
;
777 * mem->va points to the parent of mem, so both mem and mem->va
778 * can not be touched once mem->va is freed
785 * i40iw_cqp_sds_cmd - create cqp command for sd
786 * @dev: hardware control device structure
787 * @sd_info: information for sd cqp
790 enum i40iw_status_code
i40iw_cqp_sds_cmd(struct i40iw_sc_dev
*dev
,
791 struct i40iw_update_sds_info
*sdinfo
)
793 enum i40iw_status_code status
;
794 struct i40iw_cqp_request
*cqp_request
;
795 struct cqp_commands_info
*cqp_info
;
796 struct i40iw_device
*iwdev
= (struct i40iw_device
*)dev
->back_dev
;
798 cqp_request
= i40iw_get_cqp_request(&iwdev
->cqp
, true);
800 return I40IW_ERR_NO_MEMORY
;
801 cqp_info
= &cqp_request
->info
;
802 memcpy(&cqp_info
->in
.u
.update_pe_sds
.info
, sdinfo
,
803 sizeof(cqp_info
->in
.u
.update_pe_sds
.info
));
804 cqp_info
->cqp_cmd
= OP_UPDATE_PE_SDS
;
805 cqp_info
->post_sq
= 1;
806 cqp_info
->in
.u
.update_pe_sds
.dev
= dev
;
807 cqp_info
->in
.u
.update_pe_sds
.scratch
= (uintptr_t)cqp_request
;
808 status
= i40iw_handle_cqp_op(iwdev
, cqp_request
);
810 i40iw_pr_err("CQP-OP Update SD's fail");
815 * i40iw_qp_suspend_resume - cqp command for suspend/resume
816 * @dev: hardware control device structure
817 * @qp: hardware control qp
818 * @suspend: flag if suspend or resume
820 void i40iw_qp_suspend_resume(struct i40iw_sc_dev
*dev
, struct i40iw_sc_qp
*qp
, bool suspend
)
822 struct i40iw_device
*iwdev
= (struct i40iw_device
*)dev
->back_dev
;
823 struct i40iw_cqp_request
*cqp_request
;
824 struct i40iw_sc_cqp
*cqp
= dev
->cqp
;
825 struct cqp_commands_info
*cqp_info
;
826 enum i40iw_status_code status
;
828 cqp_request
= i40iw_get_cqp_request(&iwdev
->cqp
, false);
832 cqp_info
= &cqp_request
->info
;
833 cqp_info
->cqp_cmd
= (suspend
) ? OP_SUSPEND
: OP_RESUME
;
834 cqp_info
->in
.u
.suspend_resume
.cqp
= cqp
;
835 cqp_info
->in
.u
.suspend_resume
.qp
= qp
;
836 cqp_info
->in
.u
.suspend_resume
.scratch
= (uintptr_t)cqp_request
;
837 status
= i40iw_handle_cqp_op(iwdev
, cqp_request
);
839 i40iw_pr_err("CQP-OP QP Suspend/Resume fail");
843 * i40iw_term_modify_qp - modify qp for term message
844 * @qp: hardware control qp
845 * @next_state: qp's next state
846 * @term: terminate code
849 void i40iw_term_modify_qp(struct i40iw_sc_qp
*qp
, u8 next_state
, u8 term
, u8 term_len
)
851 struct i40iw_qp
*iwqp
;
853 iwqp
= (struct i40iw_qp
*)qp
->back_qp
;
854 i40iw_next_iw_state(iwqp
, next_state
, 0, term
, term_len
);
858 * i40iw_terminate_done - after terminate is completed
859 * @qp: hardware control qp
860 * @timeout_occurred: indicates if terminate timer expired
862 void i40iw_terminate_done(struct i40iw_sc_qp
*qp
, int timeout_occurred
)
864 struct i40iw_qp
*iwqp
;
865 u32 next_iwarp_state
= I40IW_QP_STATE_ERROR
;
870 iwqp
= (struct i40iw_qp
*)qp
->back_qp
;
871 spin_lock_irqsave(&iwqp
->lock
, flags
);
872 if (iwqp
->hte_added
) {
876 first_time
= !(qp
->term_flags
& I40IW_TERM_DONE
);
877 qp
->term_flags
|= I40IW_TERM_DONE
;
878 spin_unlock_irqrestore(&iwqp
->lock
, flags
);
880 if (!timeout_occurred
)
881 i40iw_terminate_del_timer(qp
);
883 next_iwarp_state
= I40IW_QP_STATE_CLOSING
;
885 i40iw_next_iw_state(iwqp
, next_iwarp_state
, hte
, 0, 0);
886 i40iw_cm_disconn(iwqp
);
891 * i40iw_terminate_imeout - timeout happened
892 * @context: points to iwarp qp
894 static void i40iw_terminate_timeout(struct timer_list
*t
)
896 struct i40iw_qp
*iwqp
= from_timer(iwqp
, t
, terminate_timer
);
897 struct i40iw_sc_qp
*qp
= (struct i40iw_sc_qp
*)&iwqp
->sc_qp
;
899 i40iw_terminate_done(qp
, 1);
900 i40iw_qp_rem_ref(&iwqp
->ibqp
);
904 * i40iw_terminate_start_timer - start terminate timeout
905 * @qp: hardware control qp
907 void i40iw_terminate_start_timer(struct i40iw_sc_qp
*qp
)
909 struct i40iw_qp
*iwqp
;
911 iwqp
= (struct i40iw_qp
*)qp
->back_qp
;
912 i40iw_qp_add_ref(&iwqp
->ibqp
);
913 timer_setup(&iwqp
->terminate_timer
, i40iw_terminate_timeout
, 0);
914 iwqp
->terminate_timer
.expires
= jiffies
+ HZ
;
915 add_timer(&iwqp
->terminate_timer
);
919 * i40iw_terminate_del_timer - delete terminate timeout
920 * @qp: hardware control qp
922 void i40iw_terminate_del_timer(struct i40iw_sc_qp
*qp
)
924 struct i40iw_qp
*iwqp
;
926 iwqp
= (struct i40iw_qp
*)qp
->back_qp
;
927 if (del_timer(&iwqp
->terminate_timer
))
928 i40iw_qp_rem_ref(&iwqp
->ibqp
);
932 * i40iw_cqp_generic_worker - generic worker for cqp
933 * @work: work pointer
935 static void i40iw_cqp_generic_worker(struct work_struct
*work
)
937 struct i40iw_virtchnl_work_info
*work_info
=
938 &((struct virtchnl_work
*)work
)->work_info
;
940 if (work_info
->worker_vf_dev
)
941 work_info
->callback_fcn(work_info
->worker_vf_dev
);
945 * i40iw_cqp_spawn_worker - spawn worket thread
946 * @iwdev: device struct pointer
947 * @work_info: work request info
948 * @iw_vf_idx: virtual function index
950 void i40iw_cqp_spawn_worker(struct i40iw_sc_dev
*dev
,
951 struct i40iw_virtchnl_work_info
*work_info
,
954 struct virtchnl_work
*work
;
955 struct i40iw_device
*iwdev
= (struct i40iw_device
*)dev
->back_dev
;
957 work
= &iwdev
->virtchnl_w
[iw_vf_idx
];
958 memcpy(&work
->work_info
, work_info
, sizeof(*work_info
));
959 INIT_WORK(&work
->work
, i40iw_cqp_generic_worker
);
960 queue_work(iwdev
->virtchnl_wq
, &work
->work
);
964 * i40iw_cqp_manage_hmc_fcn_worker -
965 * @work: work pointer for hmc info
967 static void i40iw_cqp_manage_hmc_fcn_worker(struct work_struct
*work
)
969 struct i40iw_cqp_request
*cqp_request
=
970 ((struct virtchnl_work
*)work
)->cqp_request
;
971 struct i40iw_ccq_cqe_info ccq_cqe_info
;
972 struct i40iw_hmc_fcn_info
*hmcfcninfo
=
973 &cqp_request
->info
.in
.u
.manage_hmc_pm
.info
;
974 struct i40iw_device
*iwdev
=
975 (struct i40iw_device
*)cqp_request
->info
.in
.u
.manage_hmc_pm
.dev
->back_dev
;
977 ccq_cqe_info
.cqp
= NULL
;
978 ccq_cqe_info
.maj_err_code
= cqp_request
->compl_info
.maj_err_code
;
979 ccq_cqe_info
.min_err_code
= cqp_request
->compl_info
.min_err_code
;
980 ccq_cqe_info
.op_code
= cqp_request
->compl_info
.op_code
;
981 ccq_cqe_info
.op_ret_val
= cqp_request
->compl_info
.op_ret_val
;
982 ccq_cqe_info
.scratch
= 0;
983 ccq_cqe_info
.error
= cqp_request
->compl_info
.error
;
984 hmcfcninfo
->callback_fcn(cqp_request
->info
.in
.u
.manage_hmc_pm
.dev
,
985 hmcfcninfo
->cqp_callback_param
, &ccq_cqe_info
);
986 i40iw_put_cqp_request(&iwdev
->cqp
, cqp_request
);
990 * i40iw_cqp_manage_hmc_fcn_callback - called function after cqp completion
991 * @cqp_request: cqp request info struct for hmc fun
992 * @unused: unused param of callback
994 static void i40iw_cqp_manage_hmc_fcn_callback(struct i40iw_cqp_request
*cqp_request
,
997 struct virtchnl_work
*work
;
998 struct i40iw_hmc_fcn_info
*hmcfcninfo
=
999 &cqp_request
->info
.in
.u
.manage_hmc_pm
.info
;
1000 struct i40iw_device
*iwdev
=
1001 (struct i40iw_device
*)cqp_request
->info
.in
.u
.manage_hmc_pm
.dev
->
1004 if (hmcfcninfo
&& hmcfcninfo
->callback_fcn
) {
1005 i40iw_debug(&iwdev
->sc_dev
, I40IW_DEBUG_HMC
, "%s1\n", __func__
);
1006 atomic_inc(&cqp_request
->refcount
);
1007 work
= &iwdev
->virtchnl_w
[hmcfcninfo
->iw_vf_idx
];
1008 work
->cqp_request
= cqp_request
;
1009 INIT_WORK(&work
->work
, i40iw_cqp_manage_hmc_fcn_worker
);
1010 queue_work(iwdev
->virtchnl_wq
, &work
->work
);
1011 i40iw_debug(&iwdev
->sc_dev
, I40IW_DEBUG_HMC
, "%s2\n", __func__
);
1013 i40iw_debug(&iwdev
->sc_dev
, I40IW_DEBUG_HMC
, "%s: Something wrong\n", __func__
);
1018 * i40iw_cqp_manage_hmc_fcn_cmd - issue cqp command to manage hmc
1019 * @dev: hardware control device structure
1020 * @hmcfcninfo: info for hmc
1022 enum i40iw_status_code
i40iw_cqp_manage_hmc_fcn_cmd(struct i40iw_sc_dev
*dev
,
1023 struct i40iw_hmc_fcn_info
*hmcfcninfo
)
1025 enum i40iw_status_code status
;
1026 struct i40iw_cqp_request
*cqp_request
;
1027 struct cqp_commands_info
*cqp_info
;
1028 struct i40iw_device
*iwdev
= (struct i40iw_device
*)dev
->back_dev
;
1030 i40iw_debug(&iwdev
->sc_dev
, I40IW_DEBUG_HMC
, "%s\n", __func__
);
1031 cqp_request
= i40iw_get_cqp_request(&iwdev
->cqp
, false);
1033 return I40IW_ERR_NO_MEMORY
;
1034 cqp_info
= &cqp_request
->info
;
1035 cqp_request
->callback_fcn
= i40iw_cqp_manage_hmc_fcn_callback
;
1036 cqp_request
->param
= hmcfcninfo
;
1037 memcpy(&cqp_info
->in
.u
.manage_hmc_pm
.info
, hmcfcninfo
,
1038 sizeof(*hmcfcninfo
));
1039 cqp_info
->in
.u
.manage_hmc_pm
.dev
= dev
;
1040 cqp_info
->cqp_cmd
= OP_MANAGE_HMC_PM_FUNC_TABLE
;
1041 cqp_info
->post_sq
= 1;
1042 cqp_info
->in
.u
.manage_hmc_pm
.scratch
= (uintptr_t)cqp_request
;
1043 status
= i40iw_handle_cqp_op(iwdev
, cqp_request
);
1045 i40iw_pr_err("CQP-OP Manage HMC fail");
1050 * i40iw_cqp_query_fpm_values_cmd - send cqp command for fpm
1051 * @iwdev: function device struct
1052 * @values_mem: buffer for fpm
1053 * @hmc_fn_id: function id for fpm
1055 enum i40iw_status_code
i40iw_cqp_query_fpm_values_cmd(struct i40iw_sc_dev
*dev
,
1056 struct i40iw_dma_mem
*values_mem
,
1059 enum i40iw_status_code status
;
1060 struct i40iw_cqp_request
*cqp_request
;
1061 struct cqp_commands_info
*cqp_info
;
1062 struct i40iw_device
*iwdev
= (struct i40iw_device
*)dev
->back_dev
;
1064 cqp_request
= i40iw_get_cqp_request(&iwdev
->cqp
, true);
1066 return I40IW_ERR_NO_MEMORY
;
1067 cqp_info
= &cqp_request
->info
;
1068 cqp_request
->param
= NULL
;
1069 cqp_info
->in
.u
.query_fpm_values
.cqp
= dev
->cqp
;
1070 cqp_info
->in
.u
.query_fpm_values
.fpm_values_pa
= values_mem
->pa
;
1071 cqp_info
->in
.u
.query_fpm_values
.fpm_values_va
= values_mem
->va
;
1072 cqp_info
->in
.u
.query_fpm_values
.hmc_fn_id
= hmc_fn_id
;
1073 cqp_info
->cqp_cmd
= OP_QUERY_FPM_VALUES
;
1074 cqp_info
->post_sq
= 1;
1075 cqp_info
->in
.u
.query_fpm_values
.scratch
= (uintptr_t)cqp_request
;
1076 status
= i40iw_handle_cqp_op(iwdev
, cqp_request
);
1078 i40iw_pr_err("CQP-OP Query FPM fail");
1083 * i40iw_cqp_commit_fpm_values_cmd - commit fpm values in hw
1084 * @dev: hardware control device structure
1085 * @values_mem: buffer with fpm values
1086 * @hmc_fn_id: function id for fpm
1088 enum i40iw_status_code
i40iw_cqp_commit_fpm_values_cmd(struct i40iw_sc_dev
*dev
,
1089 struct i40iw_dma_mem
*values_mem
,
1092 enum i40iw_status_code status
;
1093 struct i40iw_cqp_request
*cqp_request
;
1094 struct cqp_commands_info
*cqp_info
;
1095 struct i40iw_device
*iwdev
= (struct i40iw_device
*)dev
->back_dev
;
1097 cqp_request
= i40iw_get_cqp_request(&iwdev
->cqp
, true);
1099 return I40IW_ERR_NO_MEMORY
;
1100 cqp_info
= &cqp_request
->info
;
1101 cqp_request
->param
= NULL
;
1102 cqp_info
->in
.u
.commit_fpm_values
.cqp
= dev
->cqp
;
1103 cqp_info
->in
.u
.commit_fpm_values
.fpm_values_pa
= values_mem
->pa
;
1104 cqp_info
->in
.u
.commit_fpm_values
.fpm_values_va
= values_mem
->va
;
1105 cqp_info
->in
.u
.commit_fpm_values
.hmc_fn_id
= hmc_fn_id
;
1106 cqp_info
->cqp_cmd
= OP_COMMIT_FPM_VALUES
;
1107 cqp_info
->post_sq
= 1;
1108 cqp_info
->in
.u
.commit_fpm_values
.scratch
= (uintptr_t)cqp_request
;
1109 status
= i40iw_handle_cqp_op(iwdev
, cqp_request
);
1111 i40iw_pr_err("CQP-OP Commit FPM fail");
1116 * i40iw_vf_wait_vchnl_resp - wait for channel msg
1117 * @iwdev: function's device struct
1119 enum i40iw_status_code
i40iw_vf_wait_vchnl_resp(struct i40iw_sc_dev
*dev
)
1121 struct i40iw_device
*iwdev
= dev
->back_dev
;
1124 i40iw_debug(dev
, I40IW_DEBUG_VIRT
, "%s[%u] dev %p, iwdev %p\n",
1125 __func__
, __LINE__
, dev
, iwdev
);
1127 atomic_set(&iwdev
->vchnl_msgs
, 2);
1128 timeout_ret
= wait_event_timeout(iwdev
->vchnl_waitq
,
1129 (atomic_read(&iwdev
->vchnl_msgs
) == 1),
1130 I40IW_VCHNL_EVENT_TIMEOUT
);
1131 atomic_dec(&iwdev
->vchnl_msgs
);
1133 i40iw_pr_err("virt channel completion timeout = 0x%x\n", timeout_ret
);
1134 atomic_set(&iwdev
->vchnl_msgs
, 0);
1135 dev
->vchnl_up
= false;
1136 return I40IW_ERR_TIMEOUT
;
1138 wake_up(&dev
->vf_reqs
);
1143 * i40iw_cqp_cq_create_cmd - create a cq for the cqp
1144 * @dev: device pointer
1145 * @cq: pointer to created cq
1147 enum i40iw_status_code
i40iw_cqp_cq_create_cmd(struct i40iw_sc_dev
*dev
,
1148 struct i40iw_sc_cq
*cq
)
1150 struct i40iw_device
*iwdev
= (struct i40iw_device
*)dev
->back_dev
;
1151 struct i40iw_cqp
*iwcqp
= &iwdev
->cqp
;
1152 struct i40iw_cqp_request
*cqp_request
;
1153 struct cqp_commands_info
*cqp_info
;
1154 enum i40iw_status_code status
;
1156 cqp_request
= i40iw_get_cqp_request(iwcqp
, true);
1158 return I40IW_ERR_NO_MEMORY
;
1160 cqp_info
= &cqp_request
->info
;
1161 cqp_info
->cqp_cmd
= OP_CQ_CREATE
;
1162 cqp_info
->post_sq
= 1;
1163 cqp_info
->in
.u
.cq_create
.cq
= cq
;
1164 cqp_info
->in
.u
.cq_create
.scratch
= (uintptr_t)cqp_request
;
1165 status
= i40iw_handle_cqp_op(iwdev
, cqp_request
);
1167 i40iw_pr_err("CQP-OP Create QP fail");
1173 * i40iw_cqp_qp_create_cmd - create a qp for the cqp
1174 * @dev: device pointer
1175 * @qp: pointer to created qp
1177 enum i40iw_status_code
i40iw_cqp_qp_create_cmd(struct i40iw_sc_dev
*dev
,
1178 struct i40iw_sc_qp
*qp
)
1180 struct i40iw_device
*iwdev
= (struct i40iw_device
*)dev
->back_dev
;
1181 struct i40iw_cqp
*iwcqp
= &iwdev
->cqp
;
1182 struct i40iw_cqp_request
*cqp_request
;
1183 struct cqp_commands_info
*cqp_info
;
1184 struct i40iw_create_qp_info
*qp_info
;
1185 enum i40iw_status_code status
;
1187 cqp_request
= i40iw_get_cqp_request(iwcqp
, true);
1189 return I40IW_ERR_NO_MEMORY
;
1191 cqp_info
= &cqp_request
->info
;
1192 qp_info
= &cqp_request
->info
.in
.u
.qp_create
.info
;
1194 memset(qp_info
, 0, sizeof(*qp_info
));
1196 qp_info
->cq_num_valid
= true;
1197 qp_info
->next_iwarp_state
= I40IW_QP_STATE_RTS
;
1199 cqp_info
->cqp_cmd
= OP_QP_CREATE
;
1200 cqp_info
->post_sq
= 1;
1201 cqp_info
->in
.u
.qp_create
.qp
= qp
;
1202 cqp_info
->in
.u
.qp_create
.scratch
= (uintptr_t)cqp_request
;
1203 status
= i40iw_handle_cqp_op(iwdev
, cqp_request
);
1205 i40iw_pr_err("CQP-OP QP create fail");
1210 * i40iw_cqp_cq_destroy_cmd - destroy the cqp cq
1211 * @dev: device pointer
1212 * @cq: pointer to cq
1214 void i40iw_cqp_cq_destroy_cmd(struct i40iw_sc_dev
*dev
, struct i40iw_sc_cq
*cq
)
1216 struct i40iw_device
*iwdev
= (struct i40iw_device
*)dev
->back_dev
;
1218 i40iw_cq_wq_destroy(iwdev
, cq
);
1222 * i40iw_cqp_qp_destroy_cmd - destroy the cqp
1223 * @dev: device pointer
1224 * @qp: pointer to qp
1226 void i40iw_cqp_qp_destroy_cmd(struct i40iw_sc_dev
*dev
, struct i40iw_sc_qp
*qp
)
1228 struct i40iw_device
*iwdev
= (struct i40iw_device
*)dev
->back_dev
;
1229 struct i40iw_cqp
*iwcqp
= &iwdev
->cqp
;
1230 struct i40iw_cqp_request
*cqp_request
;
1231 struct cqp_commands_info
*cqp_info
;
1232 enum i40iw_status_code status
;
1234 cqp_request
= i40iw_get_cqp_request(iwcqp
, true);
1238 cqp_info
= &cqp_request
->info
;
1239 memset(cqp_info
, 0, sizeof(*cqp_info
));
1241 cqp_info
->cqp_cmd
= OP_QP_DESTROY
;
1242 cqp_info
->post_sq
= 1;
1243 cqp_info
->in
.u
.qp_destroy
.qp
= qp
;
1244 cqp_info
->in
.u
.qp_destroy
.scratch
= (uintptr_t)cqp_request
;
1245 cqp_info
->in
.u
.qp_destroy
.remove_hash_idx
= true;
1246 status
= i40iw_handle_cqp_op(iwdev
, cqp_request
);
1248 i40iw_pr_err("CQP QP_DESTROY fail");
1253 * i40iw_ieq_mpa_crc_ae - generate AE for crc error
1254 * @dev: hardware control device structure
1255 * @qp: hardware control qp
1257 void i40iw_ieq_mpa_crc_ae(struct i40iw_sc_dev
*dev
, struct i40iw_sc_qp
*qp
)
1259 struct i40iw_gen_ae_info info
;
1260 struct i40iw_device
*iwdev
= (struct i40iw_device
*)dev
->back_dev
;
1262 i40iw_debug(dev
, I40IW_DEBUG_AEQ
, "%s entered\n", __func__
);
1263 info
.ae_code
= I40IW_AE_LLP_RECEIVED_MPA_CRC_ERROR
;
1264 info
.ae_source
= I40IW_AE_SOURCE_RQ
;
1265 i40iw_gen_ae(iwdev
, qp
, &info
, false);
1269 * i40iw_init_hash_desc - initialize hash for crc calculation
1270 * @desc: cryption type
1272 enum i40iw_status_code
i40iw_init_hash_desc(struct shash_desc
**desc
)
1274 struct crypto_shash
*tfm
;
1275 struct shash_desc
*tdesc
;
1277 tfm
= crypto_alloc_shash("crc32c", 0, 0);
1279 return I40IW_ERR_MPA_CRC
;
1281 tdesc
= kzalloc(sizeof(*tdesc
) + crypto_shash_descsize(tfm
),
1284 crypto_free_shash(tfm
);
1285 return I40IW_ERR_MPA_CRC
;
1294 * i40iw_free_hash_desc - free hash desc
1295 * @desc: to be freed
1297 void i40iw_free_hash_desc(struct shash_desc
*desc
)
1300 crypto_free_shash(desc
->tfm
);
1306 * i40iw_alloc_query_fpm_buf - allocate buffer for fpm
1307 * @dev: hardware control device structure
1308 * @mem: buffer ptr for fpm to be allocated
1309 * @return: memory allocation status
1311 enum i40iw_status_code
i40iw_alloc_query_fpm_buf(struct i40iw_sc_dev
*dev
,
1312 struct i40iw_dma_mem
*mem
)
1314 enum i40iw_status_code status
;
1315 struct i40iw_device
*iwdev
= (struct i40iw_device
*)dev
->back_dev
;
1317 status
= i40iw_obj_aligned_mem(iwdev
, mem
, I40IW_QUERY_FPM_BUF_SIZE
,
1318 I40IW_FPM_QUERY_BUF_ALIGNMENT_MASK
);
1323 * i40iw_ieq_check_mpacrc - check if mpa crc is OK
1324 * @desc: desc for hash
1325 * @addr: address of buffer for crc
1326 * @length: length of buffer
1327 * @value: value to be compared
1329 enum i40iw_status_code
i40iw_ieq_check_mpacrc(struct shash_desc
*desc
,
1336 enum i40iw_status_code ret_code
= 0;
1338 crypto_shash_init(desc
);
1339 ret
= crypto_shash_update(desc
, addr
, length
);
1341 crypto_shash_final(desc
, (u8
*)&crc
);
1343 i40iw_pr_err("mpa crc check fail\n");
1344 ret_code
= I40IW_ERR_MPA_CRC
;
1350 * i40iw_ieq_get_qp - get qp based on quad in puda buffer
1351 * @dev: hardware control device structure
1352 * @buf: receive puda buffer on exception q
1354 struct i40iw_sc_qp
*i40iw_ieq_get_qp(struct i40iw_sc_dev
*dev
,
1355 struct i40iw_puda_buf
*buf
)
1357 struct i40iw_device
*iwdev
= (struct i40iw_device
*)dev
->back_dev
;
1358 struct i40iw_qp
*iwqp
;
1359 struct i40iw_cm_node
*cm_node
;
1360 u32 loc_addr
[4], rem_addr
[4];
1361 u16 loc_port
, rem_port
;
1362 struct ipv6hdr
*ip6h
;
1363 struct iphdr
*iph
= (struct iphdr
*)buf
->iph
;
1364 struct tcphdr
*tcph
= (struct tcphdr
*)buf
->tcph
;
1366 if (iph
->version
== 4) {
1367 memset(loc_addr
, 0, sizeof(loc_addr
));
1368 loc_addr
[0] = ntohl(iph
->daddr
);
1369 memset(rem_addr
, 0, sizeof(rem_addr
));
1370 rem_addr
[0] = ntohl(iph
->saddr
);
1372 ip6h
= (struct ipv6hdr
*)buf
->iph
;
1373 i40iw_copy_ip_ntohl(loc_addr
, ip6h
->daddr
.in6_u
.u6_addr32
);
1374 i40iw_copy_ip_ntohl(rem_addr
, ip6h
->saddr
.in6_u
.u6_addr32
);
1376 loc_port
= ntohs(tcph
->dest
);
1377 rem_port
= ntohs(tcph
->source
);
1379 cm_node
= i40iw_find_node(&iwdev
->cm_core
, rem_port
, rem_addr
, loc_port
,
1380 loc_addr
, false, true);
1383 iwqp
= cm_node
->iwqp
;
1384 return &iwqp
->sc_qp
;
1388 * i40iw_ieq_update_tcpip_info - update tcpip in the buffer
1389 * @buf: puda to update
1390 * @length: length of buffer
1391 * @seqnum: seq number for tcp
1393 void i40iw_ieq_update_tcpip_info(struct i40iw_puda_buf
*buf
, u16 length
, u32 seqnum
)
1395 struct tcphdr
*tcph
;
1399 u8
*addr
= (u8
*)buf
->mem
.va
;
1401 iphlen
= (buf
->ipv4
) ? 20 : 40;
1402 iph
= (struct iphdr
*)(addr
+ buf
->maclen
);
1403 tcph
= (struct tcphdr
*)(addr
+ buf
->maclen
+ iphlen
);
1404 packetsize
= length
+ buf
->tcphlen
+ iphlen
;
1406 iph
->tot_len
= htons(packetsize
);
1407 tcph
->seq
= htonl(seqnum
);
1411 * i40iw_puda_get_tcpip_info - get tcpip info from puda buffer
1412 * @info: to get information
1415 enum i40iw_status_code
i40iw_puda_get_tcpip_info(struct i40iw_puda_completion_info
*info
,
1416 struct i40iw_puda_buf
*buf
)
1419 struct ipv6hdr
*ip6h
;
1420 struct tcphdr
*tcph
;
1423 u8
*mem
= (u8
*)buf
->mem
.va
;
1424 struct ethhdr
*ethh
= (struct ethhdr
*)buf
->mem
.va
;
1426 if (ethh
->h_proto
== htons(0x8100)) {
1427 info
->vlan_valid
= true;
1428 buf
->vlan_id
= ntohs(((struct vlan_ethhdr
*)ethh
)->h_vlan_TCI
) & VLAN_VID_MASK
;
1430 buf
->maclen
= (info
->vlan_valid
) ? 18 : 14;
1431 iphlen
= (info
->l3proto
) ? 40 : 20;
1432 buf
->ipv4
= (info
->l3proto
) ? false : true;
1433 buf
->iph
= mem
+ buf
->maclen
;
1434 iph
= (struct iphdr
*)buf
->iph
;
1436 buf
->tcph
= buf
->iph
+ iphlen
;
1437 tcph
= (struct tcphdr
*)buf
->tcph
;
1440 pkt_len
= ntohs(iph
->tot_len
);
1442 ip6h
= (struct ipv6hdr
*)buf
->iph
;
1443 pkt_len
= ntohs(ip6h
->payload_len
) + iphlen
;
1446 buf
->totallen
= pkt_len
+ buf
->maclen
;
1448 if (info
->payload_len
< buf
->totallen
) {
1449 i40iw_pr_err("payload_len = 0x%x totallen expected0x%x\n",
1450 info
->payload_len
, buf
->totallen
);
1451 return I40IW_ERR_INVALID_SIZE
;
1454 buf
->tcphlen
= (tcph
->doff
) << 2;
1455 buf
->datalen
= pkt_len
- iphlen
- buf
->tcphlen
;
1456 buf
->data
= (buf
->datalen
) ? buf
->tcph
+ buf
->tcphlen
: NULL
;
1457 buf
->hdrlen
= buf
->maclen
+ iphlen
+ buf
->tcphlen
;
1458 buf
->seqnum
= ntohl(tcph
->seq
);
1463 * i40iw_hw_stats_timeout - Stats timer-handler which updates all HW stats
1464 * @vsi: pointer to the vsi structure
1466 static void i40iw_hw_stats_timeout(struct timer_list
*t
)
1468 struct i40iw_vsi_pestat
*pf_devstat
= from_timer(pf_devstat
, t
,
1470 struct i40iw_sc_vsi
*sc_vsi
= pf_devstat
->vsi
;
1471 struct i40iw_sc_dev
*pf_dev
= sc_vsi
->dev
;
1472 struct i40iw_vsi_pestat
*vf_devstat
= NULL
;
1474 unsigned long flags
;
1477 i40iw_hw_stats_read_all(pf_devstat
, &pf_devstat
->hw_stats
);
1479 for (iw_vf_idx
= 0; iw_vf_idx
< I40IW_MAX_PE_ENABLED_VF_COUNT
; iw_vf_idx
++) {
1480 spin_lock_irqsave(&pf_devstat
->lock
, flags
);
1481 if (pf_dev
->vf_dev
[iw_vf_idx
]) {
1482 if (pf_dev
->vf_dev
[iw_vf_idx
]->stats_initialized
) {
1483 vf_devstat
= &pf_dev
->vf_dev
[iw_vf_idx
]->pestat
;
1484 i40iw_hw_stats_read_all(vf_devstat
, &vf_devstat
->hw_stats
);
1487 spin_unlock_irqrestore(&pf_devstat
->lock
, flags
);
1490 mod_timer(&pf_devstat
->stats_timer
,
1491 jiffies
+ msecs_to_jiffies(STATS_TIMER_DELAY
));
1495 * i40iw_hw_stats_start_timer - Start periodic stats timer
1496 * @vsi: pointer to the vsi structure
1498 void i40iw_hw_stats_start_timer(struct i40iw_sc_vsi
*vsi
)
1500 struct i40iw_vsi_pestat
*devstat
= vsi
->pestat
;
1502 timer_setup(&devstat
->stats_timer
, i40iw_hw_stats_timeout
, 0);
1503 mod_timer(&devstat
->stats_timer
,
1504 jiffies
+ msecs_to_jiffies(STATS_TIMER_DELAY
));
1508 * i40iw_hw_stats_stop_timer - Delete periodic stats timer
1509 * @vsi: pointer to the vsi structure
1511 void i40iw_hw_stats_stop_timer(struct i40iw_sc_vsi
*vsi
)
1513 struct i40iw_vsi_pestat
*devstat
= vsi
->pestat
;
1515 del_timer_sync(&devstat
->stats_timer
);