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/atomic.h>
37 #include <linux/tcp.h>
38 #include <linux/init.h>
39 #include <linux/if_arp.h>
40 #include <linux/if_vlan.h>
41 #include <linux/notifier.h>
42 #include <linux/net.h>
43 #include <linux/types.h>
44 #include <linux/timer.h>
45 #include <linux/time.h>
46 #include <linux/delay.h>
47 #include <linux/etherdevice.h>
48 #include <linux/netdevice.h>
49 #include <linux/random.h>
50 #include <linux/list.h>
51 #include <linux/threads.h>
52 #include <linux/highmem.h>
54 #include <net/ndisc.h>
55 #include <net/neighbour.h>
56 #include <net/route.h>
57 #include <net/addrconf.h>
58 #include <net/ip6_route.h>
59 #include <net/ip_fib.h>
60 #include <net/secure_seq.h>
62 #include <asm/checksum.h>
66 static void i40iw_rem_ref_cm_node(struct i40iw_cm_node
*);
67 static void i40iw_cm_post_event(struct i40iw_cm_event
*event
);
68 static void i40iw_disconnect_worker(struct work_struct
*work
);
71 * i40iw_free_sqbuf - put back puda buffer if refcount = 0
72 * @vsi: pointer to vsi structure
73 * @buf: puda buffer to free
75 void i40iw_free_sqbuf(struct i40iw_sc_vsi
*vsi
, void *bufp
)
77 struct i40iw_puda_buf
*buf
= (struct i40iw_puda_buf
*)bufp
;
78 struct i40iw_puda_rsrc
*ilq
= vsi
->ilq
;
80 if (!atomic_dec_return(&buf
->refcount
))
81 i40iw_puda_ret_bufpool(ilq
, buf
);
85 * i40iw_derive_hw_ird_setting - Calculate IRD
87 * @cm_ird: IRD of connection's node
89 * The ird from the connection is rounded to a supported HW
90 * setting (2,8,32,64) and then encoded for ird_size field of
93 static u8
i40iw_derive_hw_ird_setting(u16 cm_ird
)
97 /* ird_size field is encoded in qp_ctx */
98 switch (cm_ird
? roundup_pow_of_two(cm_ird
) : 0) {
99 case I40IW_HW_IRD_SETTING_64
:
100 encoded_ird_size
= 3;
102 case I40IW_HW_IRD_SETTING_32
:
103 case I40IW_HW_IRD_SETTING_16
:
104 encoded_ird_size
= 2;
106 case I40IW_HW_IRD_SETTING_8
:
107 case I40IW_HW_IRD_SETTING_4
:
108 encoded_ird_size
= 1;
110 case I40IW_HW_IRD_SETTING_2
:
112 encoded_ird_size
= 0;
115 return encoded_ird_size
;
119 * i40iw_record_ird_ord - Record IRD/ORD passed in
120 * @cm_node: connection's node
121 * @conn_ird: connection IRD
122 * @conn_ord: connection ORD
124 static void i40iw_record_ird_ord(struct i40iw_cm_node
*cm_node
, u32 conn_ird
,
127 if (conn_ird
> I40IW_MAX_IRD_SIZE
)
128 conn_ird
= I40IW_MAX_IRD_SIZE
;
130 if (conn_ord
> I40IW_MAX_ORD_SIZE
)
131 conn_ord
= I40IW_MAX_ORD_SIZE
;
132 else if (!conn_ord
&& cm_node
->send_rdma0_op
== SEND_RDMA_READ_ZERO
)
135 cm_node
->ird_size
= conn_ird
;
136 cm_node
->ord_size
= conn_ord
;
140 * i40iw_copy_ip_ntohl - change network to host ip
144 void i40iw_copy_ip_ntohl(u32
*dst
, __be32
*src
)
146 *dst
++ = ntohl(*src
++);
147 *dst
++ = ntohl(*src
++);
148 *dst
++ = ntohl(*src
++);
153 * i40iw_copy_ip_htonl - change host addr to network ip
155 * @src: little endian
157 static inline void i40iw_copy_ip_htonl(__be32
*dst
, u32
*src
)
159 *dst
++ = htonl(*src
++);
160 *dst
++ = htonl(*src
++);
161 *dst
++ = htonl(*src
++);
166 * i40iw_fill_sockaddr4 - get addr info for passive connection
167 * @cm_node: connection's node
168 * @event: upper layer's cm event
170 static inline void i40iw_fill_sockaddr4(struct i40iw_cm_node
*cm_node
,
171 struct iw_cm_event
*event
)
173 struct sockaddr_in
*laddr
= (struct sockaddr_in
*)&event
->local_addr
;
174 struct sockaddr_in
*raddr
= (struct sockaddr_in
*)&event
->remote_addr
;
176 laddr
->sin_family
= AF_INET
;
177 raddr
->sin_family
= AF_INET
;
179 laddr
->sin_port
= htons(cm_node
->loc_port
);
180 raddr
->sin_port
= htons(cm_node
->rem_port
);
182 laddr
->sin_addr
.s_addr
= htonl(cm_node
->loc_addr
[0]);
183 raddr
->sin_addr
.s_addr
= htonl(cm_node
->rem_addr
[0]);
187 * i40iw_fill_sockaddr6 - get ipv6 addr info for passive side
188 * @cm_node: connection's node
189 * @event: upper layer's cm event
191 static inline void i40iw_fill_sockaddr6(struct i40iw_cm_node
*cm_node
,
192 struct iw_cm_event
*event
)
194 struct sockaddr_in6
*laddr6
= (struct sockaddr_in6
*)&event
->local_addr
;
195 struct sockaddr_in6
*raddr6
= (struct sockaddr_in6
*)&event
->remote_addr
;
197 laddr6
->sin6_family
= AF_INET6
;
198 raddr6
->sin6_family
= AF_INET6
;
200 laddr6
->sin6_port
= htons(cm_node
->loc_port
);
201 raddr6
->sin6_port
= htons(cm_node
->rem_port
);
203 i40iw_copy_ip_htonl(laddr6
->sin6_addr
.in6_u
.u6_addr32
,
205 i40iw_copy_ip_htonl(raddr6
->sin6_addr
.in6_u
.u6_addr32
,
210 * i40iw_get_addr_info
211 * @cm_node: contains ip/tcp info
212 * @cm_info: to get a copy of the cm_node ip/tcp info
214 static void i40iw_get_addr_info(struct i40iw_cm_node
*cm_node
,
215 struct i40iw_cm_info
*cm_info
)
217 cm_info
->ipv4
= cm_node
->ipv4
;
218 cm_info
->vlan_id
= cm_node
->vlan_id
;
219 memcpy(cm_info
->loc_addr
, cm_node
->loc_addr
, sizeof(cm_info
->loc_addr
));
220 memcpy(cm_info
->rem_addr
, cm_node
->rem_addr
, sizeof(cm_info
->rem_addr
));
221 cm_info
->loc_port
= cm_node
->loc_port
;
222 cm_info
->rem_port
= cm_node
->rem_port
;
223 cm_info
->user_pri
= cm_node
->user_pri
;
227 * i40iw_get_cmevent_info - for cm event upcall
228 * @cm_node: connection's node
229 * @cm_id: upper layers cm struct for the event
230 * @event: upper layer's cm event
232 static inline void i40iw_get_cmevent_info(struct i40iw_cm_node
*cm_node
,
233 struct iw_cm_id
*cm_id
,
234 struct iw_cm_event
*event
)
236 memcpy(&event
->local_addr
, &cm_id
->m_local_addr
,
237 sizeof(event
->local_addr
));
238 memcpy(&event
->remote_addr
, &cm_id
->m_remote_addr
,
239 sizeof(event
->remote_addr
));
241 event
->private_data
= (void *)cm_node
->pdata_buf
;
242 event
->private_data_len
= (u8
)cm_node
->pdata
.size
;
243 event
->ird
= cm_node
->ird_size
;
244 event
->ord
= cm_node
->ord_size
;
249 * i40iw_send_cm_event - upcall cm's event handler
250 * @cm_node: connection's node
251 * @cm_id: upper layer's cm info struct
252 * @type: Event type to indicate
253 * @status: status for the event type
255 static int i40iw_send_cm_event(struct i40iw_cm_node
*cm_node
,
256 struct iw_cm_id
*cm_id
,
257 enum iw_cm_event_type type
,
260 struct iw_cm_event event
;
262 memset(&event
, 0, sizeof(event
));
264 event
.status
= status
;
266 case IW_CM_EVENT_CONNECT_REQUEST
:
268 i40iw_fill_sockaddr4(cm_node
, &event
);
270 i40iw_fill_sockaddr6(cm_node
, &event
);
271 event
.provider_data
= (void *)cm_node
;
272 event
.private_data
= (void *)cm_node
->pdata_buf
;
273 event
.private_data_len
= (u8
)cm_node
->pdata
.size
;
274 event
.ird
= cm_node
->ird_size
;
276 case IW_CM_EVENT_CONNECT_REPLY
:
277 i40iw_get_cmevent_info(cm_node
, cm_id
, &event
);
279 case IW_CM_EVENT_ESTABLISHED
:
280 event
.ird
= cm_node
->ird_size
;
281 event
.ord
= cm_node
->ord_size
;
283 case IW_CM_EVENT_DISCONNECT
:
285 case IW_CM_EVENT_CLOSE
:
288 i40iw_pr_err("event type received type = %d\n", type
);
291 return cm_id
->event_handler(cm_id
, &event
);
295 * i40iw_create_event - create cm event
296 * @cm_node: connection's node
297 * @type: Event type to generate
299 static struct i40iw_cm_event
*i40iw_create_event(struct i40iw_cm_node
*cm_node
,
300 enum i40iw_cm_event_type type
)
302 struct i40iw_cm_event
*event
;
307 event
= kzalloc(sizeof(*event
), GFP_ATOMIC
);
313 event
->cm_node
= cm_node
;
314 memcpy(event
->cm_info
.rem_addr
, cm_node
->rem_addr
, sizeof(event
->cm_info
.rem_addr
));
315 memcpy(event
->cm_info
.loc_addr
, cm_node
->loc_addr
, sizeof(event
->cm_info
.loc_addr
));
316 event
->cm_info
.rem_port
= cm_node
->rem_port
;
317 event
->cm_info
.loc_port
= cm_node
->loc_port
;
318 event
->cm_info
.cm_id
= cm_node
->cm_id
;
320 i40iw_debug(cm_node
->dev
,
322 "node=%p event=%p type=%u dst=%pI4 src=%pI4\n",
326 event
->cm_info
.loc_addr
,
327 event
->cm_info
.rem_addr
);
329 i40iw_cm_post_event(event
);
334 * i40iw_free_retrans_entry - free send entry
335 * @cm_node: connection's node
337 static void i40iw_free_retrans_entry(struct i40iw_cm_node
*cm_node
)
339 struct i40iw_device
*iwdev
= cm_node
->iwdev
;
340 struct i40iw_timer_entry
*send_entry
;
342 send_entry
= cm_node
->send_entry
;
344 cm_node
->send_entry
= NULL
;
345 i40iw_free_sqbuf(&iwdev
->vsi
, (void *)send_entry
->sqbuf
);
347 atomic_dec(&cm_node
->ref_count
);
352 * i40iw_cleanup_retrans_entry - free send entry with lock
353 * @cm_node: connection's node
355 static void i40iw_cleanup_retrans_entry(struct i40iw_cm_node
*cm_node
)
359 spin_lock_irqsave(&cm_node
->retrans_list_lock
, flags
);
360 i40iw_free_retrans_entry(cm_node
);
361 spin_unlock_irqrestore(&cm_node
->retrans_list_lock
, flags
);
365 * i40iw_form_cm_frame - get a free packet and build frame
366 * @cm_node: connection's node ionfo to use in frame
367 * @options: pointer to options info
368 * @hdr: pointer mpa header
369 * @pdata: pointer to private data
370 * @flags: indicates FIN or ACK
372 static struct i40iw_puda_buf
*i40iw_form_cm_frame(struct i40iw_cm_node
*cm_node
,
373 struct i40iw_kmem_info
*options
,
374 struct i40iw_kmem_info
*hdr
,
375 struct i40iw_kmem_info
*pdata
,
378 struct i40iw_puda_buf
*sqbuf
;
379 struct i40iw_sc_vsi
*vsi
= &cm_node
->iwdev
->vsi
;
384 struct ipv6hdr
*ip6h
;
387 u16 eth_hlen
= ETH_HLEN
;
393 sqbuf
= i40iw_puda_get_bufpool(vsi
->ilq
);
399 opts_len
= (u32
)options
->size
;
405 pd_len
= pdata
->size
;
407 if (cm_node
->vlan_id
<= VLAN_VID_MASK
)
411 packetsize
= sizeof(*iph
) + sizeof(*tcph
);
413 packetsize
= sizeof(*ip6h
) + sizeof(*tcph
);
414 packetsize
+= opts_len
+ hdr_len
+ pd_len
;
416 memset(buf
, 0x00, eth_hlen
+ packetsize
);
418 sqbuf
->totallen
= packetsize
+ eth_hlen
;
419 sqbuf
->maclen
= eth_hlen
;
420 sqbuf
->tcphlen
= sizeof(*tcph
) + opts_len
;
421 sqbuf
->scratch
= (void *)cm_node
;
423 ethh
= (struct ethhdr
*)buf
;
429 iph
= (struct iphdr
*)buf
;
431 tcph
= (struct tcphdr
*)buf
;
432 buf
+= sizeof(*tcph
);
434 ether_addr_copy(ethh
->h_dest
, cm_node
->rem_mac
);
435 ether_addr_copy(ethh
->h_source
, cm_node
->loc_mac
);
436 if (cm_node
->vlan_id
<= VLAN_VID_MASK
) {
437 ((struct vlan_ethhdr
*)ethh
)->h_vlan_proto
= htons(ETH_P_8021Q
);
438 vtag
= (cm_node
->user_pri
<< VLAN_PRIO_SHIFT
) | cm_node
->vlan_id
;
439 ((struct vlan_ethhdr
*)ethh
)->h_vlan_TCI
= htons(vtag
);
441 ((struct vlan_ethhdr
*)ethh
)->h_vlan_encapsulated_proto
= htons(ETH_P_IP
);
443 ethh
->h_proto
= htons(ETH_P_IP
);
446 iph
->version
= IPVERSION
;
447 iph
->ihl
= 5; /* 5 * 4Byte words, IP headr len */
448 iph
->tos
= cm_node
->tos
;
449 iph
->tot_len
= htons(packetsize
);
450 iph
->id
= htons(++cm_node
->tcp_cntxt
.loc_id
);
452 iph
->frag_off
= htons(0x4000);
454 iph
->protocol
= IPPROTO_TCP
;
455 iph
->saddr
= htonl(cm_node
->loc_addr
[0]);
456 iph
->daddr
= htonl(cm_node
->rem_addr
[0]);
459 ip6h
= (struct ipv6hdr
*)buf
;
460 buf
+= sizeof(*ip6h
);
461 tcph
= (struct tcphdr
*)buf
;
462 buf
+= sizeof(*tcph
);
464 ether_addr_copy(ethh
->h_dest
, cm_node
->rem_mac
);
465 ether_addr_copy(ethh
->h_source
, cm_node
->loc_mac
);
466 if (cm_node
->vlan_id
<= VLAN_VID_MASK
) {
467 ((struct vlan_ethhdr
*)ethh
)->h_vlan_proto
= htons(ETH_P_8021Q
);
468 vtag
= (cm_node
->user_pri
<< VLAN_PRIO_SHIFT
) | cm_node
->vlan_id
;
469 ((struct vlan_ethhdr
*)ethh
)->h_vlan_TCI
= htons(vtag
);
470 ((struct vlan_ethhdr
*)ethh
)->h_vlan_encapsulated_proto
= htons(ETH_P_IPV6
);
472 ethh
->h_proto
= htons(ETH_P_IPV6
);
475 ip6h
->priority
= cm_node
->tos
>> 4;
476 ip6h
->flow_lbl
[0] = cm_node
->tos
<< 4;
477 ip6h
->flow_lbl
[1] = 0;
478 ip6h
->flow_lbl
[2] = 0;
479 ip6h
->payload_len
= htons(packetsize
- sizeof(*ip6h
));
481 ip6h
->hop_limit
= 128;
482 i40iw_copy_ip_htonl(ip6h
->saddr
.in6_u
.u6_addr32
,
484 i40iw_copy_ip_htonl(ip6h
->daddr
.in6_u
.u6_addr32
,
488 tcph
->source
= htons(cm_node
->loc_port
);
489 tcph
->dest
= htons(cm_node
->rem_port
);
491 tcph
->seq
= htonl(cm_node
->tcp_cntxt
.loc_seq_num
);
493 if (flags
& SET_ACK
) {
494 cm_node
->tcp_cntxt
.loc_ack_num
= cm_node
->tcp_cntxt
.rcv_nxt
;
495 tcph
->ack_seq
= htonl(cm_node
->tcp_cntxt
.loc_ack_num
);
501 if (flags
& SET_SYN
) {
502 cm_node
->tcp_cntxt
.loc_seq_num
++;
505 cm_node
->tcp_cntxt
.loc_seq_num
+= hdr_len
+ pd_len
;
508 if (flags
& SET_FIN
) {
509 cm_node
->tcp_cntxt
.loc_seq_num
++;
516 tcph
->doff
= (u16
)((sizeof(*tcph
) + opts_len
+ 3) >> 2);
517 sqbuf
->tcphlen
= tcph
->doff
<< 2;
518 tcph
->window
= htons(cm_node
->tcp_cntxt
.rcv_wnd
);
522 memcpy(buf
, options
->addr
, opts_len
);
527 memcpy(buf
, hdr
->addr
, hdr_len
);
531 if (pdata
&& pdata
->addr
)
532 memcpy(buf
, pdata
->addr
, pdata
->size
);
534 atomic_set(&sqbuf
->refcount
, 1);
540 * i40iw_send_reset - Send RST packet
541 * @cm_node: connection's node
543 int i40iw_send_reset(struct i40iw_cm_node
*cm_node
)
545 struct i40iw_puda_buf
*sqbuf
;
546 int flags
= SET_RST
| SET_ACK
;
548 sqbuf
= i40iw_form_cm_frame(cm_node
, NULL
, NULL
, NULL
, flags
);
550 i40iw_pr_err("no sqbuf\n");
554 return i40iw_schedule_cm_timer(cm_node
, sqbuf
, I40IW_TIMER_TYPE_SEND
, 0, 1);
558 * i40iw_active_open_err - send event for active side cm error
559 * @cm_node: connection's node
560 * @reset: Flag to send reset or not
562 static void i40iw_active_open_err(struct i40iw_cm_node
*cm_node
, bool reset
)
564 i40iw_cleanup_retrans_entry(cm_node
);
565 cm_node
->cm_core
->stats_connect_errs
++;
567 i40iw_debug(cm_node
->dev
,
569 "%s cm_node=%p state=%d\n",
573 atomic_inc(&cm_node
->ref_count
);
574 i40iw_send_reset(cm_node
);
577 cm_node
->state
= I40IW_CM_STATE_CLOSED
;
578 i40iw_create_event(cm_node
, I40IW_CM_EVENT_ABORTED
);
582 * i40iw_passive_open_err - handle passive side cm error
583 * @cm_node: connection's node
584 * @reset: send reset or just free cm_node
586 static void i40iw_passive_open_err(struct i40iw_cm_node
*cm_node
, bool reset
)
588 i40iw_cleanup_retrans_entry(cm_node
);
589 cm_node
->cm_core
->stats_passive_errs
++;
590 cm_node
->state
= I40IW_CM_STATE_CLOSED
;
591 i40iw_debug(cm_node
->dev
,
593 "%s cm_node=%p state =%d\n",
598 i40iw_send_reset(cm_node
);
600 i40iw_rem_ref_cm_node(cm_node
);
604 * i40iw_event_connect_error - to create connect error event
605 * @event: cm information for connect event
607 static void i40iw_event_connect_error(struct i40iw_cm_event
*event
)
609 struct i40iw_qp
*iwqp
;
610 struct iw_cm_id
*cm_id
;
612 cm_id
= event
->cm_node
->cm_id
;
616 iwqp
= cm_id
->provider_data
;
618 if (!iwqp
|| !iwqp
->iwdev
)
622 cm_id
->provider_data
= NULL
;
623 i40iw_send_cm_event(event
->cm_node
, cm_id
,
624 IW_CM_EVENT_CONNECT_REPLY
,
626 cm_id
->rem_ref(cm_id
);
627 i40iw_rem_ref_cm_node(event
->cm_node
);
631 * i40iw_process_options
632 * @cm_node: connection's node
633 * @optionsloc: point to start of options
634 * @optionsize: size of all options
635 * @syn_packet: flag if syn packet
637 static int i40iw_process_options(struct i40iw_cm_node
*cm_node
,
644 union all_known_options
*all_options
;
645 char got_mss_option
= 0;
647 while (offset
< optionsize
) {
648 all_options
= (union all_known_options
*)(optionsloc
+ offset
);
649 switch (all_options
->as_base
.optionnum
) {
650 case OPTION_NUMBER_END
:
653 case OPTION_NUMBER_NONE
:
656 case OPTION_NUMBER_MSS
:
657 i40iw_debug(cm_node
->dev
,
659 "%s: MSS Length: %d Offset: %d Size: %d\n",
661 all_options
->as_mss
.length
,
665 if (all_options
->as_mss
.length
!= 4)
667 tmp
= ntohs(all_options
->as_mss
.mss
);
668 if (tmp
> 0 && tmp
< cm_node
->tcp_cntxt
.mss
)
669 cm_node
->tcp_cntxt
.mss
= tmp
;
671 case OPTION_NUMBER_WINDOW_SCALE
:
672 cm_node
->tcp_cntxt
.snd_wscale
=
673 all_options
->as_windowscale
.shiftcount
;
676 i40iw_debug(cm_node
->dev
,
678 "TCP Option not understood: %x\n",
679 all_options
->as_base
.optionnum
);
682 offset
+= all_options
->as_base
.length
;
684 if (!got_mss_option
&& syn_packet
)
685 cm_node
->tcp_cntxt
.mss
= I40IW_CM_DEFAULT_MSS
;
690 * i40iw_handle_tcp_options -
691 * @cm_node: connection's node
692 * @tcph: pointer tcp header
693 * @optionsize: size of options rcvd
694 * @passive: active or passive flag
696 static int i40iw_handle_tcp_options(struct i40iw_cm_node
*cm_node
,
701 u8
*optionsloc
= (u8
*)&tcph
[1];
704 if (i40iw_process_options(cm_node
,
708 i40iw_debug(cm_node
->dev
,
710 "%s: Node %p, Sending RESET\n",
714 i40iw_passive_open_err(cm_node
, true);
716 i40iw_active_open_err(cm_node
, true);
721 cm_node
->tcp_cntxt
.snd_wnd
= ntohs(tcph
->window
) <<
722 cm_node
->tcp_cntxt
.snd_wscale
;
724 if (cm_node
->tcp_cntxt
.snd_wnd
> cm_node
->tcp_cntxt
.max_snd_wnd
)
725 cm_node
->tcp_cntxt
.max_snd_wnd
= cm_node
->tcp_cntxt
.snd_wnd
;
730 * i40iw_build_mpa_v1 - build a MPA V1 frame
731 * @cm_node: connection's node
732 * @mpa_key: to do read0 or write0
734 static void i40iw_build_mpa_v1(struct i40iw_cm_node
*cm_node
,
738 struct ietf_mpa_v1
*mpa_frame
= (struct ietf_mpa_v1
*)start_addr
;
741 case MPA_KEY_REQUEST
:
742 memcpy(mpa_frame
->key
, IEFT_MPA_KEY_REQ
, IETF_MPA_KEY_SIZE
);
745 memcpy(mpa_frame
->key
, IEFT_MPA_KEY_REP
, IETF_MPA_KEY_SIZE
);
750 mpa_frame
->flags
= IETF_MPA_FLAGS_CRC
;
751 mpa_frame
->rev
= cm_node
->mpa_frame_rev
;
752 mpa_frame
->priv_data_len
= htons(cm_node
->pdata
.size
);
756 * i40iw_build_mpa_v2 - build a MPA V2 frame
757 * @cm_node: connection's node
758 * @start_addr: buffer start address
759 * @mpa_key: to do read0 or write0
761 static void i40iw_build_mpa_v2(struct i40iw_cm_node
*cm_node
,
765 struct ietf_mpa_v2
*mpa_frame
= (struct ietf_mpa_v2
*)start_addr
;
766 struct ietf_rtr_msg
*rtr_msg
= &mpa_frame
->rtr_msg
;
767 u16 ctrl_ird
, ctrl_ord
;
769 /* initialize the upper 5 bytes of the frame */
770 i40iw_build_mpa_v1(cm_node
, start_addr
, mpa_key
);
771 mpa_frame
->flags
|= IETF_MPA_V2_FLAG
;
772 mpa_frame
->priv_data_len
+= htons(IETF_RTR_MSG_SIZE
);
774 /* initialize RTR msg */
775 if (cm_node
->mpav2_ird_ord
== IETF_NO_IRD_ORD
) {
776 ctrl_ird
= IETF_NO_IRD_ORD
;
777 ctrl_ord
= IETF_NO_IRD_ORD
;
779 ctrl_ird
= (cm_node
->ird_size
> IETF_NO_IRD_ORD
) ?
780 IETF_NO_IRD_ORD
: cm_node
->ird_size
;
781 ctrl_ord
= (cm_node
->ord_size
> IETF_NO_IRD_ORD
) ?
782 IETF_NO_IRD_ORD
: cm_node
->ord_size
;
785 ctrl_ird
|= IETF_PEER_TO_PEER
;
788 case MPA_KEY_REQUEST
:
789 ctrl_ord
|= IETF_RDMA0_WRITE
;
790 ctrl_ord
|= IETF_RDMA0_READ
;
793 switch (cm_node
->send_rdma0_op
) {
794 case SEND_RDMA_WRITE_ZERO
:
795 ctrl_ord
|= IETF_RDMA0_WRITE
;
797 case SEND_RDMA_READ_ZERO
:
798 ctrl_ord
|= IETF_RDMA0_READ
;
805 rtr_msg
->ctrl_ird
= htons(ctrl_ird
);
806 rtr_msg
->ctrl_ord
= htons(ctrl_ord
);
810 * i40iw_cm_build_mpa_frame - build mpa frame for mpa version 1 or version 2
811 * @cm_node: connection's node
812 * @mpa: mpa: data buffer
813 * @mpa_key: to do read0 or write0
815 static int i40iw_cm_build_mpa_frame(struct i40iw_cm_node
*cm_node
,
816 struct i40iw_kmem_info
*mpa
,
821 switch (cm_node
->mpa_frame_rev
) {
823 hdr_len
= sizeof(struct ietf_mpa_v1
);
824 i40iw_build_mpa_v1(cm_node
, mpa
->addr
, mpa_key
);
827 hdr_len
= sizeof(struct ietf_mpa_v2
);
828 i40iw_build_mpa_v2(cm_node
, mpa
->addr
, mpa_key
);
838 * i40iw_send_mpa_request - active node send mpa request to passive node
839 * @cm_node: connection's node
841 static int i40iw_send_mpa_request(struct i40iw_cm_node
*cm_node
)
843 struct i40iw_puda_buf
*sqbuf
;
846 i40iw_pr_err("cm_node == NULL\n");
850 cm_node
->mpa_hdr
.addr
= &cm_node
->mpa_frame
;
851 cm_node
->mpa_hdr
.size
= i40iw_cm_build_mpa_frame(cm_node
,
854 if (!cm_node
->mpa_hdr
.size
) {
855 i40iw_pr_err("mpa size = %d\n", cm_node
->mpa_hdr
.size
);
859 sqbuf
= i40iw_form_cm_frame(cm_node
,
865 i40iw_pr_err("sq_buf == NULL\n");
868 return i40iw_schedule_cm_timer(cm_node
, sqbuf
, I40IW_TIMER_TYPE_SEND
, 1, 0);
872 * i40iw_send_mpa_reject -
873 * @cm_node: connection's node
874 * @pdata: reject data for connection
875 * @plen: length of reject data
877 static int i40iw_send_mpa_reject(struct i40iw_cm_node
*cm_node
,
881 struct i40iw_puda_buf
*sqbuf
;
882 struct i40iw_kmem_info priv_info
;
884 cm_node
->mpa_hdr
.addr
= &cm_node
->mpa_frame
;
885 cm_node
->mpa_hdr
.size
= i40iw_cm_build_mpa_frame(cm_node
,
889 cm_node
->mpa_frame
.flags
|= IETF_MPA_FLAGS_REJECT
;
890 priv_info
.addr
= (void *)pdata
;
891 priv_info
.size
= plen
;
893 sqbuf
= i40iw_form_cm_frame(cm_node
,
899 i40iw_pr_err("no sqbuf\n");
902 cm_node
->state
= I40IW_CM_STATE_FIN_WAIT1
;
903 return i40iw_schedule_cm_timer(cm_node
, sqbuf
, I40IW_TIMER_TYPE_SEND
, 1, 0);
907 * recv_mpa - process an IETF MPA frame
908 * @cm_node: connection's node
909 * @buffer: Data pointer
910 * @type: to return accept or reject
911 * @len: Len of mpa buffer
913 static int i40iw_parse_mpa(struct i40iw_cm_node
*cm_node
, u8
*buffer
, u32
*type
, u32 len
)
915 struct ietf_mpa_v1
*mpa_frame
;
916 struct ietf_mpa_v2
*mpa_v2_frame
;
917 struct ietf_rtr_msg
*rtr_msg
;
921 *type
= I40IW_MPA_REQUEST_ACCEPT
;
923 if (len
< sizeof(struct ietf_mpa_v1
)) {
924 i40iw_pr_err("ietf buffer small (%x)\n", len
);
928 mpa_frame
= (struct ietf_mpa_v1
*)buffer
;
929 mpa_hdr_len
= sizeof(struct ietf_mpa_v1
);
930 priv_data_len
= ntohs(mpa_frame
->priv_data_len
);
932 if (priv_data_len
> IETF_MAX_PRIV_DATA_LEN
) {
933 i40iw_pr_err("large pri_data %d\n", priv_data_len
);
936 if (mpa_frame
->rev
!= IETF_MPA_V1
&& mpa_frame
->rev
!= IETF_MPA_V2
) {
937 i40iw_pr_err("unsupported mpa rev = %d\n", mpa_frame
->rev
);
940 if (mpa_frame
->rev
> cm_node
->mpa_frame_rev
) {
941 i40iw_pr_err("rev %d\n", mpa_frame
->rev
);
944 cm_node
->mpa_frame_rev
= mpa_frame
->rev
;
946 if (cm_node
->state
!= I40IW_CM_STATE_MPAREQ_SENT
) {
947 if (memcmp(mpa_frame
->key
, IEFT_MPA_KEY_REQ
, IETF_MPA_KEY_SIZE
)) {
948 i40iw_pr_err("Unexpected MPA Key received\n");
952 if (memcmp(mpa_frame
->key
, IEFT_MPA_KEY_REP
, IETF_MPA_KEY_SIZE
)) {
953 i40iw_pr_err("Unexpected MPA Key received\n");
958 if (priv_data_len
+ mpa_hdr_len
> len
) {
959 i40iw_pr_err("ietf buffer len(%x + %x != %x)\n",
960 priv_data_len
, mpa_hdr_len
, len
);
963 if (len
> MAX_CM_BUFFER
) {
964 i40iw_pr_err("ietf buffer large len = %d\n", len
);
968 switch (mpa_frame
->rev
) {
975 mpa_v2_frame
= (struct ietf_mpa_v2
*)buffer
;
976 mpa_hdr_len
+= IETF_RTR_MSG_SIZE
;
977 rtr_msg
= &mpa_v2_frame
->rtr_msg
;
979 /* parse rtr message */
980 ctrl_ord
= ntohs(rtr_msg
->ctrl_ord
);
981 ctrl_ird
= ntohs(rtr_msg
->ctrl_ird
);
982 ird_size
= ctrl_ird
& IETF_NO_IRD_ORD
;
983 ord_size
= ctrl_ord
& IETF_NO_IRD_ORD
;
985 if (!(ctrl_ird
& IETF_PEER_TO_PEER
))
988 if (ird_size
== IETF_NO_IRD_ORD
|| ord_size
== IETF_NO_IRD_ORD
) {
989 cm_node
->mpav2_ird_ord
= IETF_NO_IRD_ORD
;
993 if (cm_node
->state
!= I40IW_CM_STATE_MPAREQ_SENT
) {
995 if (!ord_size
&& (ctrl_ord
& IETF_RDMA0_READ
))
996 cm_node
->ird_size
= 1;
997 if (cm_node
->ord_size
> ird_size
)
998 cm_node
->ord_size
= ird_size
;
1001 if (!ird_size
&& (ctrl_ord
& IETF_RDMA0_READ
))
1003 if (cm_node
->ord_size
> ird_size
)
1004 cm_node
->ord_size
= ird_size
;
1006 if (cm_node
->ird_size
< ord_size
)
1007 /* no resources available */
1012 if (ctrl_ord
& IETF_RDMA0_READ
)
1013 cm_node
->send_rdma0_op
= SEND_RDMA_READ_ZERO
;
1014 else if (ctrl_ord
& IETF_RDMA0_WRITE
)
1015 cm_node
->send_rdma0_op
= SEND_RDMA_WRITE_ZERO
;
1016 else /* Not supported RDMA0 operation */
1018 i40iw_debug(cm_node
->dev
, I40IW_DEBUG_CM
,
1019 "MPAV2: Negotiated ORD: %d, IRD: %d\n",
1020 cm_node
->ord_size
, cm_node
->ird_size
);
1029 memcpy(cm_node
->pdata_buf
, buffer
+ mpa_hdr_len
, priv_data_len
);
1030 cm_node
->pdata
.size
= priv_data_len
;
1032 if (mpa_frame
->flags
& IETF_MPA_FLAGS_REJECT
)
1033 *type
= I40IW_MPA_REQUEST_REJECT
;
1035 if (mpa_frame
->flags
& IETF_MPA_FLAGS_MARKERS
)
1036 cm_node
->snd_mark_en
= true;
1042 * i40iw_schedule_cm_timer
1043 * @@cm_node: connection's node
1044 * @sqbuf: buffer to send
1045 * @type: if it is send or close
1046 * @send_retrans: if rexmits to be done
1047 * @close_when_complete: is cm_node to be removed
1049 * note - cm_node needs to be protected before calling this. Encase in:
1050 * i40iw_rem_ref_cm_node(cm_core, cm_node);
1051 * i40iw_schedule_cm_timer(...)
1052 * atomic_inc(&cm_node->ref_count);
1054 int i40iw_schedule_cm_timer(struct i40iw_cm_node
*cm_node
,
1055 struct i40iw_puda_buf
*sqbuf
,
1056 enum i40iw_timer_type type
,
1058 int close_when_complete
)
1060 struct i40iw_sc_vsi
*vsi
= &cm_node
->iwdev
->vsi
;
1061 struct i40iw_cm_core
*cm_core
= cm_node
->cm_core
;
1062 struct i40iw_timer_entry
*new_send
;
1065 unsigned long flags
;
1067 new_send
= kzalloc(sizeof(*new_send
), GFP_ATOMIC
);
1069 if (type
!= I40IW_TIMER_TYPE_CLOSE
)
1070 i40iw_free_sqbuf(vsi
, (void *)sqbuf
);
1073 new_send
->retrycount
= I40IW_DEFAULT_RETRYS
;
1074 new_send
->retranscount
= I40IW_DEFAULT_RETRANS
;
1075 new_send
->sqbuf
= sqbuf
;
1076 new_send
->timetosend
= jiffies
;
1077 new_send
->type
= type
;
1078 new_send
->send_retrans
= send_retrans
;
1079 new_send
->close_when_complete
= close_when_complete
;
1081 if (type
== I40IW_TIMER_TYPE_CLOSE
) {
1082 new_send
->timetosend
+= (HZ
/ 10);
1083 if (cm_node
->close_entry
) {
1085 i40iw_pr_err("already close entry\n");
1088 cm_node
->close_entry
= new_send
;
1091 if (type
== I40IW_TIMER_TYPE_SEND
) {
1092 spin_lock_irqsave(&cm_node
->retrans_list_lock
, flags
);
1093 cm_node
->send_entry
= new_send
;
1094 atomic_inc(&cm_node
->ref_count
);
1095 spin_unlock_irqrestore(&cm_node
->retrans_list_lock
, flags
);
1096 new_send
->timetosend
= jiffies
+ I40IW_RETRY_TIMEOUT
;
1098 atomic_inc(&sqbuf
->refcount
);
1099 i40iw_puda_send_buf(vsi
->ilq
, sqbuf
);
1100 if (!send_retrans
) {
1101 i40iw_cleanup_retrans_entry(cm_node
);
1102 if (close_when_complete
)
1103 i40iw_rem_ref_cm_node(cm_node
);
1108 spin_lock_irqsave(&cm_core
->ht_lock
, flags
);
1109 was_timer_set
= timer_pending(&cm_core
->tcp_timer
);
1111 if (!was_timer_set
) {
1112 cm_core
->tcp_timer
.expires
= new_send
->timetosend
;
1113 add_timer(&cm_core
->tcp_timer
);
1115 spin_unlock_irqrestore(&cm_core
->ht_lock
, flags
);
1121 * i40iw_retrans_expired - Could not rexmit the packet
1122 * @cm_node: connection's node
1124 static void i40iw_retrans_expired(struct i40iw_cm_node
*cm_node
)
1126 struct iw_cm_id
*cm_id
= cm_node
->cm_id
;
1127 enum i40iw_cm_node_state state
= cm_node
->state
;
1129 cm_node
->state
= I40IW_CM_STATE_CLOSED
;
1131 case I40IW_CM_STATE_SYN_RCVD
:
1132 case I40IW_CM_STATE_CLOSING
:
1133 i40iw_rem_ref_cm_node(cm_node
);
1135 case I40IW_CM_STATE_FIN_WAIT1
:
1136 case I40IW_CM_STATE_LAST_ACK
:
1138 cm_id
->rem_ref(cm_id
);
1139 i40iw_send_reset(cm_node
);
1142 atomic_inc(&cm_node
->ref_count
);
1143 i40iw_send_reset(cm_node
);
1144 i40iw_create_event(cm_node
, I40IW_CM_EVENT_ABORTED
);
1150 * i40iw_handle_close_entry - for handling retry/timeouts
1151 * @cm_node: connection's node
1152 * @rem_node: flag for remove cm_node
1154 static void i40iw_handle_close_entry(struct i40iw_cm_node
*cm_node
, u32 rem_node
)
1156 struct i40iw_timer_entry
*close_entry
= cm_node
->close_entry
;
1157 struct iw_cm_id
*cm_id
= cm_node
->cm_id
;
1158 struct i40iw_qp
*iwqp
;
1159 unsigned long flags
;
1163 iwqp
= (struct i40iw_qp
*)close_entry
->sqbuf
;
1165 spin_lock_irqsave(&iwqp
->lock
, flags
);
1167 iwqp
->hw_tcp_state
= I40IW_TCP_STATE_CLOSED
;
1168 iwqp
->hw_iwarp_state
= I40IW_QP_STATE_ERROR
;
1169 iwqp
->last_aeq
= I40IW_AE_RESET_SENT
;
1170 iwqp
->ibqp_state
= IB_QPS_ERR
;
1171 spin_unlock_irqrestore(&iwqp
->lock
, flags
);
1172 i40iw_cm_disconn(iwqp
);
1174 spin_unlock_irqrestore(&iwqp
->lock
, flags
);
1176 } else if (rem_node
) {
1177 /* TIME_WAIT state */
1178 i40iw_rem_ref_cm_node(cm_node
);
1181 cm_id
->rem_ref(cm_id
);
1183 cm_node
->close_entry
= NULL
;
1187 * i40iw_build_timer_list - Add cm_nodes to timer list
1188 * @timer_list: ptr to timer list
1189 * @hte: ptr to accelerated or non-accelerated list
1191 static void i40iw_build_timer_list(struct list_head
*timer_list
,
1192 struct list_head
*hte
)
1194 struct i40iw_cm_node
*cm_node
;
1195 struct list_head
*list_core_temp
, *list_node
;
1197 list_for_each_safe(list_node
, list_core_temp
, hte
) {
1198 cm_node
= container_of(list_node
, struct i40iw_cm_node
, list
);
1199 if (cm_node
->close_entry
|| cm_node
->send_entry
) {
1200 atomic_inc(&cm_node
->ref_count
);
1201 list_add(&cm_node
->timer_entry
, timer_list
);
1207 * i40iw_cm_timer_tick - system's timer expired callback
1208 * @pass: Pointing to cm_core
1210 static void i40iw_cm_timer_tick(struct timer_list
*t
)
1212 unsigned long nexttimeout
= jiffies
+ I40IW_LONG_TIME
;
1213 struct i40iw_cm_node
*cm_node
;
1214 struct i40iw_timer_entry
*send_entry
, *close_entry
;
1215 struct list_head
*list_core_temp
;
1216 struct i40iw_sc_vsi
*vsi
;
1217 struct list_head
*list_node
;
1218 struct i40iw_cm_core
*cm_core
= from_timer(cm_core
, t
, tcp_timer
);
1220 unsigned long timetosend
;
1221 unsigned long flags
;
1223 struct list_head timer_list
;
1225 INIT_LIST_HEAD(&timer_list
);
1227 spin_lock_irqsave(&cm_core
->ht_lock
, flags
);
1228 i40iw_build_timer_list(&timer_list
, &cm_core
->non_accelerated_list
);
1229 i40iw_build_timer_list(&timer_list
, &cm_core
->accelerated_list
);
1230 spin_unlock_irqrestore(&cm_core
->ht_lock
, flags
);
1232 list_for_each_safe(list_node
, list_core_temp
, &timer_list
) {
1233 cm_node
= container_of(list_node
,
1234 struct i40iw_cm_node
,
1236 close_entry
= cm_node
->close_entry
;
1239 if (time_after(close_entry
->timetosend
, jiffies
)) {
1240 if (nexttimeout
> close_entry
->timetosend
||
1242 nexttimeout
= close_entry
->timetosend
;
1246 i40iw_handle_close_entry(cm_node
, 1);
1250 spin_lock_irqsave(&cm_node
->retrans_list_lock
, flags
);
1252 send_entry
= cm_node
->send_entry
;
1255 if (time_after(send_entry
->timetosend
, jiffies
)) {
1256 if (cm_node
->state
!= I40IW_CM_STATE_OFFLOADED
) {
1257 if ((nexttimeout
> send_entry
->timetosend
) ||
1259 nexttimeout
= send_entry
->timetosend
;
1263 i40iw_free_retrans_entry(cm_node
);
1268 if ((cm_node
->state
== I40IW_CM_STATE_OFFLOADED
) ||
1269 (cm_node
->state
== I40IW_CM_STATE_CLOSED
)) {
1270 i40iw_free_retrans_entry(cm_node
);
1274 if (!send_entry
->retranscount
|| !send_entry
->retrycount
) {
1275 i40iw_free_retrans_entry(cm_node
);
1277 spin_unlock_irqrestore(&cm_node
->retrans_list_lock
, flags
);
1278 i40iw_retrans_expired(cm_node
);
1279 cm_node
->state
= I40IW_CM_STATE_CLOSED
;
1280 spin_lock_irqsave(&cm_node
->retrans_list_lock
, flags
);
1283 spin_unlock_irqrestore(&cm_node
->retrans_list_lock
, flags
);
1285 vsi
= &cm_node
->iwdev
->vsi
;
1287 if (!cm_node
->ack_rcvd
) {
1288 atomic_inc(&send_entry
->sqbuf
->refcount
);
1289 i40iw_puda_send_buf(vsi
->ilq
, send_entry
->sqbuf
);
1290 cm_node
->cm_core
->stats_pkt_retrans
++;
1292 spin_lock_irqsave(&cm_node
->retrans_list_lock
, flags
);
1293 if (send_entry
->send_retrans
) {
1294 send_entry
->retranscount
--;
1295 timetosend
= (I40IW_RETRY_TIMEOUT
<<
1296 (I40IW_DEFAULT_RETRANS
-
1297 send_entry
->retranscount
));
1299 send_entry
->timetosend
= jiffies
+
1300 min(timetosend
, I40IW_MAX_TIMEOUT
);
1301 if (nexttimeout
> send_entry
->timetosend
|| !settimer
) {
1302 nexttimeout
= send_entry
->timetosend
;
1306 int close_when_complete
;
1308 close_when_complete
= send_entry
->close_when_complete
;
1309 i40iw_debug(cm_node
->dev
,
1311 "cm_node=%p state=%d\n",
1314 i40iw_free_retrans_entry(cm_node
);
1315 if (close_when_complete
)
1316 i40iw_rem_ref_cm_node(cm_node
);
1319 spin_unlock_irqrestore(&cm_node
->retrans_list_lock
, flags
);
1320 i40iw_rem_ref_cm_node(cm_node
);
1324 spin_lock_irqsave(&cm_core
->ht_lock
, flags
);
1325 if (!timer_pending(&cm_core
->tcp_timer
)) {
1326 cm_core
->tcp_timer
.expires
= nexttimeout
;
1327 add_timer(&cm_core
->tcp_timer
);
1329 spin_unlock_irqrestore(&cm_core
->ht_lock
, flags
);
1334 * i40iw_send_syn - send SYN packet
1335 * @cm_node: connection's node
1336 * @sendack: flag to set ACK bit or not
1338 int i40iw_send_syn(struct i40iw_cm_node
*cm_node
, u32 sendack
)
1340 struct i40iw_puda_buf
*sqbuf
;
1341 int flags
= SET_SYN
;
1342 char optionsbuffer
[sizeof(struct option_mss
) +
1343 sizeof(struct option_windowscale
) +
1344 sizeof(struct option_base
) + TCP_OPTIONS_PADDING
];
1345 struct i40iw_kmem_info opts
;
1347 int optionssize
= 0;
1348 /* Sending MSS option */
1349 union all_known_options
*options
;
1351 opts
.addr
= optionsbuffer
;
1353 i40iw_pr_err("no cm_node\n");
1357 options
= (union all_known_options
*)&optionsbuffer
[optionssize
];
1358 options
->as_mss
.optionnum
= OPTION_NUMBER_MSS
;
1359 options
->as_mss
.length
= sizeof(struct option_mss
);
1360 options
->as_mss
.mss
= htons(cm_node
->tcp_cntxt
.mss
);
1361 optionssize
+= sizeof(struct option_mss
);
1363 options
= (union all_known_options
*)&optionsbuffer
[optionssize
];
1364 options
->as_windowscale
.optionnum
= OPTION_NUMBER_WINDOW_SCALE
;
1365 options
->as_windowscale
.length
= sizeof(struct option_windowscale
);
1366 options
->as_windowscale
.shiftcount
= cm_node
->tcp_cntxt
.rcv_wscale
;
1367 optionssize
+= sizeof(struct option_windowscale
);
1368 options
= (union all_known_options
*)&optionsbuffer
[optionssize
];
1369 options
->as_end
= OPTION_NUMBER_END
;
1375 opts
.size
= optionssize
;
1377 sqbuf
= i40iw_form_cm_frame(cm_node
, &opts
, NULL
, NULL
, flags
);
1379 i40iw_pr_err("no sqbuf\n");
1382 return i40iw_schedule_cm_timer(cm_node
, sqbuf
, I40IW_TIMER_TYPE_SEND
, 1, 0);
1386 * i40iw_send_ack - Send ACK packet
1387 * @cm_node: connection's node
1389 static void i40iw_send_ack(struct i40iw_cm_node
*cm_node
)
1391 struct i40iw_puda_buf
*sqbuf
;
1392 struct i40iw_sc_vsi
*vsi
= &cm_node
->iwdev
->vsi
;
1394 sqbuf
= i40iw_form_cm_frame(cm_node
, NULL
, NULL
, NULL
, SET_ACK
);
1396 i40iw_puda_send_buf(vsi
->ilq
, sqbuf
);
1398 i40iw_pr_err("no sqbuf\n");
1402 * i40iw_send_fin - Send FIN pkt
1403 * @cm_node: connection's node
1405 static int i40iw_send_fin(struct i40iw_cm_node
*cm_node
)
1407 struct i40iw_puda_buf
*sqbuf
;
1409 sqbuf
= i40iw_form_cm_frame(cm_node
, NULL
, NULL
, NULL
, SET_ACK
| SET_FIN
);
1411 i40iw_pr_err("no sqbuf\n");
1414 return i40iw_schedule_cm_timer(cm_node
, sqbuf
, I40IW_TIMER_TYPE_SEND
, 1, 0);
1418 * i40iw_find_node - find a cm node that matches the reference cm node
1419 * @cm_core: cm's core
1420 * @rem_port: remote tcp port num
1421 * @rem_addr: remote ip addr
1422 * @loc_port: local tcp port num
1423 * @loc_addr: loc ip addr
1424 * @add_refcnt: flag to increment refcount of cm_node
1425 * @accelerated_list: flag for accelerated vs non-accelerated list to search
1427 struct i40iw_cm_node
*i40iw_find_node(struct i40iw_cm_core
*cm_core
,
1433 bool accelerated_list
)
1435 struct list_head
*hte
;
1436 struct i40iw_cm_node
*cm_node
;
1437 unsigned long flags
;
1439 hte
= accelerated_list
?
1440 &cm_core
->accelerated_list
: &cm_core
->non_accelerated_list
;
1442 /* walk list and find cm_node associated with this session ID */
1443 spin_lock_irqsave(&cm_core
->ht_lock
, flags
);
1444 list_for_each_entry(cm_node
, hte
, list
) {
1445 if (!memcmp(cm_node
->loc_addr
, loc_addr
, sizeof(cm_node
->loc_addr
)) &&
1446 (cm_node
->loc_port
== loc_port
) &&
1447 !memcmp(cm_node
->rem_addr
, rem_addr
, sizeof(cm_node
->rem_addr
)) &&
1448 (cm_node
->rem_port
== rem_port
)) {
1450 atomic_inc(&cm_node
->ref_count
);
1451 spin_unlock_irqrestore(&cm_core
->ht_lock
, flags
);
1455 spin_unlock_irqrestore(&cm_core
->ht_lock
, flags
);
1462 * i40iw_find_listener - find a cm node listening on this addr-port pair
1463 * @cm_core: cm's core
1464 * @dst_port: listener tcp port num
1465 * @dst_addr: listener ip addr
1466 * @listener_state: state to match with listen node's
1468 static struct i40iw_cm_listener
*i40iw_find_listener(
1469 struct i40iw_cm_core
*cm_core
,
1473 enum i40iw_cm_listener_state
1476 struct i40iw_cm_listener
*listen_node
;
1477 static const u32 ip_zero
[4] = { 0, 0, 0, 0 };
1480 unsigned long flags
;
1482 /* walk list and find cm_node associated with this session ID */
1483 spin_lock_irqsave(&cm_core
->listen_list_lock
, flags
);
1484 list_for_each_entry(listen_node
, &cm_core
->listen_nodes
, list
) {
1485 memcpy(listen_addr
, listen_node
->loc_addr
, sizeof(listen_addr
));
1486 listen_port
= listen_node
->loc_port
;
1487 /* compare node pair, return node handle if a match */
1488 if ((!memcmp(listen_addr
, dst_addr
, sizeof(listen_addr
)) ||
1489 !memcmp(listen_addr
, ip_zero
, sizeof(listen_addr
))) &&
1490 (listen_port
== dst_port
) &&
1491 (listener_state
& listen_node
->listener_state
)) {
1492 atomic_inc(&listen_node
->ref_count
);
1493 spin_unlock_irqrestore(&cm_core
->listen_list_lock
, flags
);
1497 spin_unlock_irqrestore(&cm_core
->listen_list_lock
, flags
);
1502 * i40iw_add_hte_node - add a cm node to the hash table
1503 * @cm_core: cm's core
1504 * @cm_node: connection's node
1506 static void i40iw_add_hte_node(struct i40iw_cm_core
*cm_core
,
1507 struct i40iw_cm_node
*cm_node
)
1509 unsigned long flags
;
1511 if (!cm_node
|| !cm_core
) {
1512 i40iw_pr_err("cm_node or cm_core == NULL\n");
1516 spin_lock_irqsave(&cm_core
->ht_lock
, flags
);
1517 list_add_tail(&cm_node
->list
, &cm_core
->non_accelerated_list
);
1518 spin_unlock_irqrestore(&cm_core
->ht_lock
, flags
);
1522 * i40iw_find_port - find port that matches reference port
1523 * @hte: ptr to accelerated or non-accelerated list
1524 * @accelerated_list: flag for accelerated vs non-accelerated list
1526 static bool i40iw_find_port(struct list_head
*hte
, u16 port
)
1528 struct i40iw_cm_node
*cm_node
;
1530 list_for_each_entry(cm_node
, hte
, list
) {
1531 if (cm_node
->loc_port
== port
)
1538 * i40iw_port_in_use - determine if port is in use
1539 * @cm_core: cm's core
1540 * @port: port number
1542 bool i40iw_port_in_use(struct i40iw_cm_core
*cm_core
, u16 port
)
1544 struct i40iw_cm_listener
*listen_node
;
1545 unsigned long flags
;
1547 spin_lock_irqsave(&cm_core
->ht_lock
, flags
);
1548 if (i40iw_find_port(&cm_core
->accelerated_list
, port
) ||
1549 i40iw_find_port(&cm_core
->non_accelerated_list
, port
)) {
1550 spin_unlock_irqrestore(&cm_core
->ht_lock
, flags
);
1553 spin_unlock_irqrestore(&cm_core
->ht_lock
, flags
);
1555 spin_lock_irqsave(&cm_core
->listen_list_lock
, flags
);
1556 list_for_each_entry(listen_node
, &cm_core
->listen_nodes
, list
) {
1557 if (listen_node
->loc_port
== port
) {
1558 spin_unlock_irqrestore(&cm_core
->listen_list_lock
, flags
);
1562 spin_unlock_irqrestore(&cm_core
->listen_list_lock
, flags
);
1568 * i40iw_del_multiple_qhash - Remove qhash and child listens
1569 * @iwdev: iWarp device
1570 * @cm_info: CM info for parent listen node
1571 * @cm_parent_listen_node: The parent listen node
1573 static enum i40iw_status_code
i40iw_del_multiple_qhash(
1574 struct i40iw_device
*iwdev
,
1575 struct i40iw_cm_info
*cm_info
,
1576 struct i40iw_cm_listener
*cm_parent_listen_node
)
1578 struct i40iw_cm_listener
*child_listen_node
;
1579 enum i40iw_status_code ret
= I40IW_ERR_CONFIG
;
1580 struct list_head
*pos
, *tpos
;
1581 unsigned long flags
;
1583 spin_lock_irqsave(&iwdev
->cm_core
.listen_list_lock
, flags
);
1584 list_for_each_safe(pos
, tpos
, &cm_parent_listen_node
->child_listen_list
) {
1585 child_listen_node
= list_entry(pos
, struct i40iw_cm_listener
, child_listen_list
);
1586 if (child_listen_node
->ipv4
)
1587 i40iw_debug(&iwdev
->sc_dev
,
1589 "removing child listen for IP=%pI4, port=%d, vlan=%d\n",
1590 child_listen_node
->loc_addr
,
1591 child_listen_node
->loc_port
,
1592 child_listen_node
->vlan_id
);
1594 i40iw_debug(&iwdev
->sc_dev
, I40IW_DEBUG_CM
,
1595 "removing child listen for IP=%pI6, port=%d, vlan=%d\n",
1596 child_listen_node
->loc_addr
,
1597 child_listen_node
->loc_port
,
1598 child_listen_node
->vlan_id
);
1600 memcpy(cm_info
->loc_addr
, child_listen_node
->loc_addr
,
1601 sizeof(cm_info
->loc_addr
));
1602 cm_info
->vlan_id
= child_listen_node
->vlan_id
;
1603 if (child_listen_node
->qhash_set
) {
1604 ret
= i40iw_manage_qhash(iwdev
, cm_info
,
1605 I40IW_QHASH_TYPE_TCP_SYN
,
1606 I40IW_QHASH_MANAGE_TYPE_DELETE
,
1608 child_listen_node
->qhash_set
= false;
1610 ret
= I40IW_SUCCESS
;
1612 i40iw_debug(&iwdev
->sc_dev
,
1614 "freed pointer = %p\n",
1616 kfree(child_listen_node
);
1617 cm_parent_listen_node
->cm_core
->stats_listen_nodes_destroyed
++;
1619 spin_unlock_irqrestore(&iwdev
->cm_core
.listen_list_lock
, flags
);
1625 * i40iw_netdev_vlan_ipv6 - Gets the netdev and vlan
1626 * @addr: local IPv6 address
1627 * @vlan_id: vlan id for the given IPv6 address
1629 * Returns the net_device of the IPv6 address and also sets the
1630 * vlan id for that address.
1632 static struct net_device
*i40iw_netdev_vlan_ipv6(u32
*addr
, u16
*vlan_id
)
1634 struct net_device
*ip_dev
= NULL
;
1635 struct in6_addr laddr6
;
1637 if (!IS_ENABLED(CONFIG_IPV6
))
1639 i40iw_copy_ip_htonl(laddr6
.in6_u
.u6_addr32
, addr
);
1641 *vlan_id
= I40IW_NO_VLAN
;
1643 for_each_netdev_rcu(&init_net
, ip_dev
) {
1644 if (ipv6_chk_addr(&init_net
, &laddr6
, ip_dev
, 1)) {
1646 *vlan_id
= rdma_vlan_dev_vlan_id(ip_dev
);
1655 * i40iw_get_vlan_ipv4 - Returns the vlan_id for IPv4 address
1656 * @addr: local IPv4 address
1658 static u16
i40iw_get_vlan_ipv4(u32
*addr
)
1660 struct net_device
*netdev
;
1661 u16 vlan_id
= I40IW_NO_VLAN
;
1663 netdev
= ip_dev_find(&init_net
, htonl(addr
[0]));
1665 vlan_id
= rdma_vlan_dev_vlan_id(netdev
);
1672 * i40iw_add_mqh_6 - Adds multiple qhashes for IPv6
1673 * @iwdev: iWarp device
1674 * @cm_info: CM info for parent listen node
1675 * @cm_parent_listen_node: The parent listen node
1677 * Adds a qhash and a child listen node for every IPv6 address
1678 * on the adapter and adds the associated qhash filter
1680 static enum i40iw_status_code
i40iw_add_mqh_6(struct i40iw_device
*iwdev
,
1681 struct i40iw_cm_info
*cm_info
,
1682 struct i40iw_cm_listener
*cm_parent_listen_node
)
1684 struct net_device
*ip_dev
;
1685 struct inet6_dev
*idev
;
1686 struct inet6_ifaddr
*ifp
, *tmp
;
1687 enum i40iw_status_code ret
= 0;
1688 struct i40iw_cm_listener
*child_listen_node
;
1689 unsigned long flags
;
1692 for_each_netdev(&init_net
, ip_dev
) {
1693 if ((((rdma_vlan_dev_vlan_id(ip_dev
) < I40IW_NO_VLAN
) &&
1694 (rdma_vlan_dev_real_dev(ip_dev
) == iwdev
->netdev
)) ||
1695 (ip_dev
== iwdev
->netdev
)) && (ip_dev
->flags
& IFF_UP
)) {
1696 idev
= __in6_dev_get(ip_dev
);
1698 i40iw_pr_err("idev == NULL\n");
1701 list_for_each_entry_safe(ifp
, tmp
, &idev
->addr_list
, if_list
) {
1702 i40iw_debug(&iwdev
->sc_dev
,
1704 "IP=%pI6, vlan_id=%d, MAC=%pM\n",
1706 rdma_vlan_dev_vlan_id(ip_dev
),
1709 kzalloc(sizeof(*child_listen_node
), GFP_ATOMIC
);
1710 i40iw_debug(&iwdev
->sc_dev
,
1712 "Allocating child listener %p\n",
1714 if (!child_listen_node
) {
1715 ret
= I40IW_ERR_NO_MEMORY
;
1718 cm_info
->vlan_id
= rdma_vlan_dev_vlan_id(ip_dev
);
1719 cm_parent_listen_node
->vlan_id
= cm_info
->vlan_id
;
1721 memcpy(child_listen_node
, cm_parent_listen_node
,
1722 sizeof(*child_listen_node
));
1724 i40iw_copy_ip_ntohl(child_listen_node
->loc_addr
,
1725 ifp
->addr
.in6_u
.u6_addr32
);
1726 memcpy(cm_info
->loc_addr
, child_listen_node
->loc_addr
,
1727 sizeof(cm_info
->loc_addr
));
1729 ret
= i40iw_manage_qhash(iwdev
, cm_info
,
1730 I40IW_QHASH_TYPE_TCP_SYN
,
1731 I40IW_QHASH_MANAGE_TYPE_ADD
,
1734 child_listen_node
->qhash_set
= true;
1735 spin_lock_irqsave(&iwdev
->cm_core
.listen_list_lock
, flags
);
1736 list_add(&child_listen_node
->child_listen_list
,
1737 &cm_parent_listen_node
->child_listen_list
);
1738 spin_unlock_irqrestore(&iwdev
->cm_core
.listen_list_lock
, flags
);
1739 cm_parent_listen_node
->cm_core
->stats_listen_nodes_created
++;
1741 kfree(child_listen_node
);
1752 * i40iw_add_mqh_4 - Adds multiple qhashes for IPv4
1753 * @iwdev: iWarp device
1754 * @cm_info: CM info for parent listen node
1755 * @cm_parent_listen_node: The parent listen node
1757 * Adds a qhash and a child listen node for every IPv4 address
1758 * on the adapter and adds the associated qhash filter
1760 static enum i40iw_status_code
i40iw_add_mqh_4(
1761 struct i40iw_device
*iwdev
,
1762 struct i40iw_cm_info
*cm_info
,
1763 struct i40iw_cm_listener
*cm_parent_listen_node
)
1765 struct net_device
*dev
;
1766 struct in_device
*idev
;
1767 struct i40iw_cm_listener
*child_listen_node
;
1768 enum i40iw_status_code ret
= 0;
1769 unsigned long flags
;
1772 for_each_netdev(&init_net
, dev
) {
1773 if ((((rdma_vlan_dev_vlan_id(dev
) < I40IW_NO_VLAN
) &&
1774 (rdma_vlan_dev_real_dev(dev
) == iwdev
->netdev
)) ||
1775 (dev
== iwdev
->netdev
)) && (dev
->flags
& IFF_UP
)) {
1776 const struct in_ifaddr
*ifa
;
1778 idev
= in_dev_get(dev
);
1780 in_dev_for_each_ifa_rtnl(ifa
, idev
) {
1781 i40iw_debug(&iwdev
->sc_dev
,
1783 "Allocating child CM Listener forIP=%pI4, vlan_id=%d, MAC=%pM\n",
1785 rdma_vlan_dev_vlan_id(dev
),
1787 child_listen_node
= kzalloc(sizeof(*child_listen_node
), GFP_KERNEL
);
1788 cm_parent_listen_node
->cm_core
->stats_listen_nodes_created
++;
1789 i40iw_debug(&iwdev
->sc_dev
,
1791 "Allocating child listener %p\n",
1793 if (!child_listen_node
) {
1795 ret
= I40IW_ERR_NO_MEMORY
;
1798 cm_info
->vlan_id
= rdma_vlan_dev_vlan_id(dev
);
1799 cm_parent_listen_node
->vlan_id
= cm_info
->vlan_id
;
1800 memcpy(child_listen_node
,
1801 cm_parent_listen_node
,
1802 sizeof(*child_listen_node
));
1804 child_listen_node
->loc_addr
[0] = ntohl(ifa
->ifa_address
);
1805 memcpy(cm_info
->loc_addr
, child_listen_node
->loc_addr
,
1806 sizeof(cm_info
->loc_addr
));
1808 ret
= i40iw_manage_qhash(iwdev
,
1810 I40IW_QHASH_TYPE_TCP_SYN
,
1811 I40IW_QHASH_MANAGE_TYPE_ADD
,
1815 child_listen_node
->qhash_set
= true;
1816 spin_lock_irqsave(&iwdev
->cm_core
.listen_list_lock
, flags
);
1817 list_add(&child_listen_node
->child_listen_list
,
1818 &cm_parent_listen_node
->child_listen_list
);
1819 spin_unlock_irqrestore(&iwdev
->cm_core
.listen_list_lock
, flags
);
1821 kfree(child_listen_node
);
1822 cm_parent_listen_node
->cm_core
->stats_listen_nodes_created
--;
1835 * i40iw_dec_refcnt_listen - delete listener and associated cm nodes
1836 * @cm_core: cm's core
1837 * @free_hanging_nodes: to free associated cm_nodes
1838 * @apbvt_del: flag to delete the apbvt
1840 static int i40iw_dec_refcnt_listen(struct i40iw_cm_core
*cm_core
,
1841 struct i40iw_cm_listener
*listener
,
1842 int free_hanging_nodes
, bool apbvt_del
)
1846 struct list_head
*list_pos
;
1847 struct list_head
*list_temp
;
1848 struct i40iw_cm_node
*cm_node
;
1849 struct list_head reset_list
;
1850 struct i40iw_cm_info nfo
;
1851 struct i40iw_cm_node
*loopback
;
1852 enum i40iw_cm_node_state old_state
;
1853 unsigned long flags
;
1855 /* free non-accelerated child nodes for this listener */
1856 INIT_LIST_HEAD(&reset_list
);
1857 if (free_hanging_nodes
) {
1858 spin_lock_irqsave(&cm_core
->ht_lock
, flags
);
1859 list_for_each_safe(list_pos
,
1860 list_temp
, &cm_core
->non_accelerated_list
) {
1861 cm_node
= container_of(list_pos
, struct i40iw_cm_node
, list
);
1862 if ((cm_node
->listener
== listener
) &&
1863 !cm_node
->accelerated
) {
1864 atomic_inc(&cm_node
->ref_count
);
1865 list_add(&cm_node
->reset_entry
, &reset_list
);
1868 spin_unlock_irqrestore(&cm_core
->ht_lock
, flags
);
1871 list_for_each_safe(list_pos
, list_temp
, &reset_list
) {
1872 cm_node
= container_of(list_pos
, struct i40iw_cm_node
, reset_entry
);
1873 loopback
= cm_node
->loopbackpartner
;
1874 if (cm_node
->state
>= I40IW_CM_STATE_FIN_WAIT1
) {
1875 i40iw_rem_ref_cm_node(cm_node
);
1878 i40iw_cleanup_retrans_entry(cm_node
);
1879 err
= i40iw_send_reset(cm_node
);
1881 cm_node
->state
= I40IW_CM_STATE_CLOSED
;
1882 i40iw_pr_err("send reset\n");
1884 old_state
= cm_node
->state
;
1885 cm_node
->state
= I40IW_CM_STATE_LISTENER_DESTROYED
;
1886 if (old_state
!= I40IW_CM_STATE_MPAREQ_RCVD
)
1887 i40iw_rem_ref_cm_node(cm_node
);
1890 struct i40iw_cm_event event
;
1892 event
.cm_node
= loopback
;
1893 memcpy(event
.cm_info
.rem_addr
,
1894 loopback
->rem_addr
, sizeof(event
.cm_info
.rem_addr
));
1895 memcpy(event
.cm_info
.loc_addr
,
1896 loopback
->loc_addr
, sizeof(event
.cm_info
.loc_addr
));
1897 event
.cm_info
.rem_port
= loopback
->rem_port
;
1898 event
.cm_info
.loc_port
= loopback
->loc_port
;
1899 event
.cm_info
.cm_id
= loopback
->cm_id
;
1900 event
.cm_info
.ipv4
= loopback
->ipv4
;
1901 atomic_inc(&loopback
->ref_count
);
1902 loopback
->state
= I40IW_CM_STATE_CLOSED
;
1903 i40iw_event_connect_error(&event
);
1904 cm_node
->state
= I40IW_CM_STATE_LISTENER_DESTROYED
;
1905 i40iw_rem_ref_cm_node(cm_node
);
1910 if (!atomic_dec_return(&listener
->ref_count
)) {
1911 spin_lock_irqsave(&cm_core
->listen_list_lock
, flags
);
1912 list_del(&listener
->list
);
1913 spin_unlock_irqrestore(&cm_core
->listen_list_lock
, flags
);
1915 if (listener
->iwdev
) {
1917 i40iw_manage_apbvt(listener
->iwdev
,
1919 I40IW_MANAGE_APBVT_DEL
);
1921 memcpy(nfo
.loc_addr
, listener
->loc_addr
, sizeof(nfo
.loc_addr
));
1922 nfo
.loc_port
= listener
->loc_port
;
1923 nfo
.ipv4
= listener
->ipv4
;
1924 nfo
.vlan_id
= listener
->vlan_id
;
1925 nfo
.user_pri
= listener
->user_pri
;
1927 if (!list_empty(&listener
->child_listen_list
)) {
1928 i40iw_del_multiple_qhash(listener
->iwdev
, &nfo
, listener
);
1930 if (listener
->qhash_set
)
1931 i40iw_manage_qhash(listener
->iwdev
,
1933 I40IW_QHASH_TYPE_TCP_SYN
,
1934 I40IW_QHASH_MANAGE_TYPE_DELETE
,
1940 cm_core
->stats_listen_destroyed
++;
1942 cm_core
->stats_listen_nodes_destroyed
++;
1948 if (atomic_read(&listener
->pend_accepts_cnt
) > 0)
1949 i40iw_debug(cm_core
->dev
,
1951 "%s: listener (%p) pending accepts=%u\n",
1954 atomic_read(&listener
->pend_accepts_cnt
));
1961 * i40iw_cm_del_listen - delete a linstener
1962 * @cm_core: cm's core
1963 * @listener: passive connection's listener
1964 * @apbvt_del: flag to delete apbvt
1966 static int i40iw_cm_del_listen(struct i40iw_cm_core
*cm_core
,
1967 struct i40iw_cm_listener
*listener
,
1970 listener
->listener_state
= I40IW_CM_LISTENER_PASSIVE_STATE
;
1971 listener
->cm_id
= NULL
; /* going to be destroyed pretty soon */
1972 return i40iw_dec_refcnt_listen(cm_core
, listener
, 1, apbvt_del
);
1976 * i40iw_addr_resolve_neigh - resolve neighbor address
1977 * @iwdev: iwarp device structure
1978 * @src_ip: local ip address
1979 * @dst_ip: remote ip address
1980 * @arpindex: if there is an arp entry
1982 static int i40iw_addr_resolve_neigh(struct i40iw_device
*iwdev
,
1988 struct neighbour
*neigh
;
1990 __be32 dst_ipaddr
= htonl(dst_ip
);
1991 __be32 src_ipaddr
= htonl(src_ip
);
1993 rt
= ip_route_output(&init_net
, dst_ipaddr
, src_ipaddr
, 0, 0);
1995 i40iw_pr_err("ip_route_output\n");
1999 neigh
= dst_neigh_lookup(&rt
->dst
, &dst_ipaddr
);
2003 if (neigh
->nud_state
& NUD_VALID
) {
2004 if (arpindex
>= 0) {
2005 if (ether_addr_equal(iwdev
->arp_table
[arpindex
].mac_addr
,
2007 /* Mac address same as arp table */
2008 goto resolve_neigh_exit
;
2009 i40iw_manage_arp_cache(iwdev
,
2010 iwdev
->arp_table
[arpindex
].mac_addr
,
2016 i40iw_manage_arp_cache(iwdev
, neigh
->ha
, &dst_ip
, true, I40IW_ARP_ADD
);
2017 rc
= i40iw_arp_table(iwdev
, &dst_ip
, true, NULL
, I40IW_ARP_RESOLVE
);
2019 neigh_event_send(neigh
, NULL
);
2026 neigh_release(neigh
);
2033 * i40iw_get_dst_ipv6
2035 static struct dst_entry
*i40iw_get_dst_ipv6(struct sockaddr_in6
*src_addr
,
2036 struct sockaddr_in6
*dst_addr
)
2038 struct dst_entry
*dst
;
2041 memset(&fl6
, 0, sizeof(fl6
));
2042 fl6
.daddr
= dst_addr
->sin6_addr
;
2043 fl6
.saddr
= src_addr
->sin6_addr
;
2044 if (ipv6_addr_type(&fl6
.daddr
) & IPV6_ADDR_LINKLOCAL
)
2045 fl6
.flowi6_oif
= dst_addr
->sin6_scope_id
;
2047 dst
= ip6_route_output(&init_net
, NULL
, &fl6
);
2052 * i40iw_addr_resolve_neigh_ipv6 - resolve neighbor ipv6 address
2053 * @iwdev: iwarp device structure
2054 * @dst_ip: remote ip address
2055 * @arpindex: if there is an arp entry
2057 static int i40iw_addr_resolve_neigh_ipv6(struct i40iw_device
*iwdev
,
2062 struct neighbour
*neigh
;
2064 struct dst_entry
*dst
;
2065 struct sockaddr_in6 dst_addr
;
2066 struct sockaddr_in6 src_addr
;
2068 memset(&dst_addr
, 0, sizeof(dst_addr
));
2069 dst_addr
.sin6_family
= AF_INET6
;
2070 i40iw_copy_ip_htonl(dst_addr
.sin6_addr
.in6_u
.u6_addr32
, dest
);
2071 memset(&src_addr
, 0, sizeof(src_addr
));
2072 src_addr
.sin6_family
= AF_INET6
;
2073 i40iw_copy_ip_htonl(src_addr
.sin6_addr
.in6_u
.u6_addr32
, src
);
2074 dst
= i40iw_get_dst_ipv6(&src_addr
, &dst_addr
);
2075 if (!dst
|| dst
->error
) {
2077 i40iw_pr_err("ip6_route_output returned dst->error = %d\n",
2084 neigh
= dst_neigh_lookup(dst
, dst_addr
.sin6_addr
.in6_u
.u6_addr32
);
2088 i40iw_debug(&iwdev
->sc_dev
, I40IW_DEBUG_CM
, "dst_neigh_lookup MAC=%pM\n", neigh
->ha
);
2089 if (neigh
->nud_state
& NUD_VALID
) {
2090 if (arpindex
>= 0) {
2091 if (ether_addr_equal
2092 (iwdev
->arp_table
[arpindex
].mac_addr
,
2094 /* Mac address same as in arp table */
2095 goto resolve_neigh_exit6
;
2097 i40iw_manage_arp_cache(iwdev
,
2098 iwdev
->arp_table
[arpindex
].mac_addr
,
2103 i40iw_manage_arp_cache(iwdev
,
2108 rc
= i40iw_arp_table(iwdev
,
2114 neigh_event_send(neigh
, NULL
);
2118 resolve_neigh_exit6
:
2121 neigh_release(neigh
);
2127 * i40iw_ipv4_is_loopback - check if loopback
2128 * @loc_addr: local addr to compare
2129 * @rem_addr: remote address
2131 static bool i40iw_ipv4_is_loopback(u32 loc_addr
, u32 rem_addr
)
2133 return ipv4_is_loopback(htonl(rem_addr
)) || (loc_addr
== rem_addr
);
2137 * i40iw_ipv6_is_loopback - check if loopback
2138 * @loc_addr: local addr to compare
2139 * @rem_addr: remote address
2141 static bool i40iw_ipv6_is_loopback(u32
*loc_addr
, u32
*rem_addr
)
2143 struct in6_addr raddr6
;
2145 i40iw_copy_ip_htonl(raddr6
.in6_u
.u6_addr32
, rem_addr
);
2146 return !memcmp(loc_addr
, rem_addr
, 16) || ipv6_addr_loopback(&raddr6
);
2150 * i40iw_make_cm_node - create a new instance of a cm node
2151 * @cm_core: cm's core
2152 * @iwdev: iwarp device structure
2153 * @cm_info: quad info for connection
2154 * @listener: passive connection's listener
2156 static struct i40iw_cm_node
*i40iw_make_cm_node(
2157 struct i40iw_cm_core
*cm_core
,
2158 struct i40iw_device
*iwdev
,
2159 struct i40iw_cm_info
*cm_info
,
2160 struct i40iw_cm_listener
*listener
)
2162 struct i40iw_cm_node
*cm_node
;
2165 struct net_device
*netdev
= iwdev
->netdev
;
2167 /* create an hte and cm_node for this instance */
2168 cm_node
= kzalloc(sizeof(*cm_node
), GFP_ATOMIC
);
2172 /* set our node specific transport info */
2173 cm_node
->ipv4
= cm_info
->ipv4
;
2174 cm_node
->vlan_id
= cm_info
->vlan_id
;
2175 if ((cm_node
->vlan_id
== I40IW_NO_VLAN
) && iwdev
->dcb
)
2176 cm_node
->vlan_id
= 0;
2177 cm_node
->tos
= cm_info
->tos
;
2178 cm_node
->user_pri
= cm_info
->user_pri
;
2180 if (listener
->tos
!= cm_info
->tos
)
2181 i40iw_debug(&iwdev
->sc_dev
, I40IW_DEBUG_DCB
,
2182 "application TOS[%d] and remote client TOS[%d] mismatch\n",
2183 listener
->tos
, cm_info
->tos
);
2184 cm_node
->tos
= max(listener
->tos
, cm_info
->tos
);
2185 cm_node
->user_pri
= rt_tos2priority(cm_node
->tos
);
2186 i40iw_debug(&iwdev
->sc_dev
, I40IW_DEBUG_DCB
, "listener: TOS:[%d] UP:[%d]\n",
2187 cm_node
->tos
, cm_node
->user_pri
);
2189 memcpy(cm_node
->loc_addr
, cm_info
->loc_addr
, sizeof(cm_node
->loc_addr
));
2190 memcpy(cm_node
->rem_addr
, cm_info
->rem_addr
, sizeof(cm_node
->rem_addr
));
2191 cm_node
->loc_port
= cm_info
->loc_port
;
2192 cm_node
->rem_port
= cm_info
->rem_port
;
2194 cm_node
->mpa_frame_rev
= iwdev
->mpa_version
;
2195 cm_node
->send_rdma0_op
= SEND_RDMA_READ_ZERO
;
2196 cm_node
->ird_size
= I40IW_MAX_IRD_SIZE
;
2197 cm_node
->ord_size
= I40IW_MAX_ORD_SIZE
;
2199 cm_node
->listener
= listener
;
2200 cm_node
->cm_id
= cm_info
->cm_id
;
2201 ether_addr_copy(cm_node
->loc_mac
, netdev
->dev_addr
);
2202 spin_lock_init(&cm_node
->retrans_list_lock
);
2203 cm_node
->ack_rcvd
= false;
2205 atomic_set(&cm_node
->ref_count
, 1);
2206 /* associate our parent CM core */
2207 cm_node
->cm_core
= cm_core
;
2208 cm_node
->tcp_cntxt
.loc_id
= I40IW_CM_DEF_LOCAL_ID
;
2209 cm_node
->tcp_cntxt
.rcv_wscale
= I40IW_CM_DEFAULT_RCV_WND_SCALE
;
2210 cm_node
->tcp_cntxt
.rcv_wnd
=
2211 I40IW_CM_DEFAULT_RCV_WND_SCALED
>> I40IW_CM_DEFAULT_RCV_WND_SCALE
;
2212 if (cm_node
->ipv4
) {
2213 cm_node
->tcp_cntxt
.loc_seq_num
= secure_tcp_seq(htonl(cm_node
->loc_addr
[0]),
2214 htonl(cm_node
->rem_addr
[0]),
2215 htons(cm_node
->loc_port
),
2216 htons(cm_node
->rem_port
));
2217 cm_node
->tcp_cntxt
.mss
= iwdev
->vsi
.mtu
- I40IW_MTU_TO_MSS_IPV4
;
2218 } else if (IS_ENABLED(CONFIG_IPV6
)) {
2220 htonl(cm_node
->loc_addr
[0]), htonl(cm_node
->loc_addr
[1]),
2221 htonl(cm_node
->loc_addr
[2]), htonl(cm_node
->loc_addr
[3])
2224 htonl(cm_node
->rem_addr
[0]), htonl(cm_node
->rem_addr
[1]),
2225 htonl(cm_node
->rem_addr
[2]), htonl(cm_node
->rem_addr
[3])
2227 cm_node
->tcp_cntxt
.loc_seq_num
= secure_tcpv6_seq(loc
, rem
,
2228 htons(cm_node
->loc_port
),
2229 htons(cm_node
->rem_port
));
2230 cm_node
->tcp_cntxt
.mss
= iwdev
->vsi
.mtu
- I40IW_MTU_TO_MSS_IPV6
;
2233 cm_node
->iwdev
= iwdev
;
2234 cm_node
->dev
= &iwdev
->sc_dev
;
2236 if ((cm_node
->ipv4
&&
2237 i40iw_ipv4_is_loopback(cm_node
->loc_addr
[0], cm_node
->rem_addr
[0])) ||
2238 (!cm_node
->ipv4
&& i40iw_ipv6_is_loopback(cm_node
->loc_addr
,
2239 cm_node
->rem_addr
))) {
2240 arpindex
= i40iw_arp_table(iwdev
,
2246 oldarpindex
= i40iw_arp_table(iwdev
,
2252 arpindex
= i40iw_addr_resolve_neigh(iwdev
,
2253 cm_info
->loc_addr
[0],
2254 cm_info
->rem_addr
[0],
2256 else if (IS_ENABLED(CONFIG_IPV6
))
2257 arpindex
= i40iw_addr_resolve_neigh_ipv6(iwdev
,
2265 i40iw_pr_err("cm_node arpindex\n");
2269 ether_addr_copy(cm_node
->rem_mac
, iwdev
->arp_table
[arpindex
].mac_addr
);
2270 i40iw_add_hte_node(cm_core
, cm_node
);
2271 cm_core
->stats_nodes_created
++;
2276 * i40iw_rem_ref_cm_node - destroy an instance of a cm node
2277 * @cm_node: connection's node
2279 static void i40iw_rem_ref_cm_node(struct i40iw_cm_node
*cm_node
)
2281 struct i40iw_cm_core
*cm_core
= cm_node
->cm_core
;
2282 struct i40iw_qp
*iwqp
;
2283 struct i40iw_cm_info nfo
;
2284 unsigned long flags
;
2286 spin_lock_irqsave(&cm_node
->cm_core
->ht_lock
, flags
);
2287 if (atomic_dec_return(&cm_node
->ref_count
)) {
2288 spin_unlock_irqrestore(&cm_node
->cm_core
->ht_lock
, flags
);
2291 list_del(&cm_node
->list
);
2292 spin_unlock_irqrestore(&cm_node
->cm_core
->ht_lock
, flags
);
2294 /* if the node is destroyed before connection was accelerated */
2295 if (!cm_node
->accelerated
&& cm_node
->accept_pend
) {
2296 pr_err("node destroyed before established\n");
2297 atomic_dec(&cm_node
->listener
->pend_accepts_cnt
);
2299 if (cm_node
->close_entry
)
2300 i40iw_handle_close_entry(cm_node
, 0);
2301 if (cm_node
->listener
) {
2302 i40iw_dec_refcnt_listen(cm_core
, cm_node
->listener
, 0, true);
2304 if (cm_node
->apbvt_set
) {
2305 i40iw_manage_apbvt(cm_node
->iwdev
,
2307 I40IW_MANAGE_APBVT_DEL
);
2308 cm_node
->apbvt_set
= 0;
2310 i40iw_get_addr_info(cm_node
, &nfo
);
2311 if (cm_node
->qhash_set
) {
2312 i40iw_manage_qhash(cm_node
->iwdev
,
2314 I40IW_QHASH_TYPE_TCP_ESTABLISHED
,
2315 I40IW_QHASH_MANAGE_TYPE_DELETE
,
2318 cm_node
->qhash_set
= 0;
2322 iwqp
= cm_node
->iwqp
;
2324 iwqp
->cm_node
= NULL
;
2325 i40iw_qp_rem_ref(&iwqp
->ibqp
);
2326 cm_node
->iwqp
= NULL
;
2327 } else if (cm_node
->qhash_set
) {
2328 i40iw_get_addr_info(cm_node
, &nfo
);
2329 i40iw_manage_qhash(cm_node
->iwdev
,
2331 I40IW_QHASH_TYPE_TCP_ESTABLISHED
,
2332 I40IW_QHASH_MANAGE_TYPE_DELETE
,
2335 cm_node
->qhash_set
= 0;
2338 cm_node
->cm_core
->stats_nodes_destroyed
++;
2343 * i40iw_handle_fin_pkt - FIN packet received
2344 * @cm_node: connection's node
2346 static void i40iw_handle_fin_pkt(struct i40iw_cm_node
*cm_node
)
2350 switch (cm_node
->state
) {
2351 case I40IW_CM_STATE_SYN_RCVD
:
2352 case I40IW_CM_STATE_SYN_SENT
:
2353 case I40IW_CM_STATE_ESTABLISHED
:
2354 case I40IW_CM_STATE_MPAREJ_RCVD
:
2355 cm_node
->tcp_cntxt
.rcv_nxt
++;
2356 i40iw_cleanup_retrans_entry(cm_node
);
2357 cm_node
->state
= I40IW_CM_STATE_LAST_ACK
;
2358 i40iw_send_fin(cm_node
);
2360 case I40IW_CM_STATE_MPAREQ_SENT
:
2361 i40iw_create_event(cm_node
, I40IW_CM_EVENT_ABORTED
);
2362 cm_node
->tcp_cntxt
.rcv_nxt
++;
2363 i40iw_cleanup_retrans_entry(cm_node
);
2364 cm_node
->state
= I40IW_CM_STATE_CLOSED
;
2365 atomic_inc(&cm_node
->ref_count
);
2366 i40iw_send_reset(cm_node
);
2368 case I40IW_CM_STATE_FIN_WAIT1
:
2369 cm_node
->tcp_cntxt
.rcv_nxt
++;
2370 i40iw_cleanup_retrans_entry(cm_node
);
2371 cm_node
->state
= I40IW_CM_STATE_CLOSING
;
2372 i40iw_send_ack(cm_node
);
2374 * Wait for ACK as this is simultaneous close.
2375 * After we receive ACK, do not send anything.
2379 case I40IW_CM_STATE_FIN_WAIT2
:
2380 cm_node
->tcp_cntxt
.rcv_nxt
++;
2381 i40iw_cleanup_retrans_entry(cm_node
);
2382 cm_node
->state
= I40IW_CM_STATE_TIME_WAIT
;
2383 i40iw_send_ack(cm_node
);
2385 i40iw_schedule_cm_timer(cm_node
, NULL
, I40IW_TIMER_TYPE_CLOSE
, 1, 0);
2387 i40iw_pr_err("node %p state = %d\n", cm_node
, cm_node
->state
);
2389 case I40IW_CM_STATE_TIME_WAIT
:
2390 cm_node
->tcp_cntxt
.rcv_nxt
++;
2391 i40iw_cleanup_retrans_entry(cm_node
);
2392 cm_node
->state
= I40IW_CM_STATE_CLOSED
;
2393 i40iw_rem_ref_cm_node(cm_node
);
2395 case I40IW_CM_STATE_OFFLOADED
:
2397 i40iw_pr_err("bad state node %p state = %d\n", cm_node
, cm_node
->state
);
2403 * i40iw_handle_rst_pkt - process received RST packet
2404 * @cm_node: connection's node
2405 * @rbuf: receive buffer
2407 static void i40iw_handle_rst_pkt(struct i40iw_cm_node
*cm_node
,
2408 struct i40iw_puda_buf
*rbuf
)
2410 i40iw_cleanup_retrans_entry(cm_node
);
2411 switch (cm_node
->state
) {
2412 case I40IW_CM_STATE_SYN_SENT
:
2413 case I40IW_CM_STATE_MPAREQ_SENT
:
2414 switch (cm_node
->mpa_frame_rev
) {
2416 cm_node
->mpa_frame_rev
= IETF_MPA_V1
;
2417 /* send a syn and goto syn sent state */
2418 cm_node
->state
= I40IW_CM_STATE_SYN_SENT
;
2419 if (i40iw_send_syn(cm_node
, 0))
2420 i40iw_active_open_err(cm_node
, false);
2424 i40iw_active_open_err(cm_node
, false);
2428 case I40IW_CM_STATE_MPAREQ_RCVD
:
2429 atomic_inc(&cm_node
->passive_state
);
2431 case I40IW_CM_STATE_ESTABLISHED
:
2432 case I40IW_CM_STATE_SYN_RCVD
:
2433 case I40IW_CM_STATE_LISTENING
:
2434 i40iw_pr_err("Bad state state = %d\n", cm_node
->state
);
2435 i40iw_passive_open_err(cm_node
, false);
2437 case I40IW_CM_STATE_OFFLOADED
:
2438 i40iw_active_open_err(cm_node
, false);
2440 case I40IW_CM_STATE_CLOSED
:
2442 case I40IW_CM_STATE_FIN_WAIT2
:
2443 case I40IW_CM_STATE_FIN_WAIT1
:
2444 case I40IW_CM_STATE_LAST_ACK
:
2445 cm_node
->cm_id
->rem_ref(cm_node
->cm_id
);
2447 case I40IW_CM_STATE_TIME_WAIT
:
2448 cm_node
->state
= I40IW_CM_STATE_CLOSED
;
2449 i40iw_rem_ref_cm_node(cm_node
);
2457 * i40iw_handle_rcv_mpa - Process a recv'd mpa buffer
2458 * @cm_node: connection's node
2459 * @rbuf: receive buffer
2461 static void i40iw_handle_rcv_mpa(struct i40iw_cm_node
*cm_node
,
2462 struct i40iw_puda_buf
*rbuf
)
2465 int datasize
= rbuf
->datalen
;
2466 u8
*dataloc
= rbuf
->data
;
2468 enum i40iw_cm_event_type type
= I40IW_CM_EVENT_UNKNOWN
;
2471 ret
= i40iw_parse_mpa(cm_node
, dataloc
, &res_type
, datasize
);
2473 if (cm_node
->state
== I40IW_CM_STATE_MPAREQ_SENT
)
2474 i40iw_active_open_err(cm_node
, true);
2476 i40iw_passive_open_err(cm_node
, true);
2480 switch (cm_node
->state
) {
2481 case I40IW_CM_STATE_ESTABLISHED
:
2482 if (res_type
== I40IW_MPA_REQUEST_REJECT
)
2483 i40iw_pr_err("state for reject\n");
2484 cm_node
->state
= I40IW_CM_STATE_MPAREQ_RCVD
;
2485 type
= I40IW_CM_EVENT_MPA_REQ
;
2486 i40iw_send_ack(cm_node
); /* ACK received MPA request */
2487 atomic_set(&cm_node
->passive_state
,
2488 I40IW_PASSIVE_STATE_INDICATED
);
2490 case I40IW_CM_STATE_MPAREQ_SENT
:
2491 i40iw_cleanup_retrans_entry(cm_node
);
2492 if (res_type
== I40IW_MPA_REQUEST_REJECT
) {
2493 type
= I40IW_CM_EVENT_MPA_REJECT
;
2494 cm_node
->state
= I40IW_CM_STATE_MPAREJ_RCVD
;
2496 type
= I40IW_CM_EVENT_CONNECTED
;
2497 cm_node
->state
= I40IW_CM_STATE_OFFLOADED
;
2499 i40iw_send_ack(cm_node
);
2502 pr_err("%s wrong cm_node state =%d\n", __func__
, cm_node
->state
);
2505 i40iw_create_event(cm_node
, type
);
2509 * i40iw_indicate_pkt_err - Send up err event to cm
2510 * @cm_node: connection's node
2512 static void i40iw_indicate_pkt_err(struct i40iw_cm_node
*cm_node
)
2514 switch (cm_node
->state
) {
2515 case I40IW_CM_STATE_SYN_SENT
:
2516 case I40IW_CM_STATE_MPAREQ_SENT
:
2517 i40iw_active_open_err(cm_node
, true);
2519 case I40IW_CM_STATE_ESTABLISHED
:
2520 case I40IW_CM_STATE_SYN_RCVD
:
2521 i40iw_passive_open_err(cm_node
, true);
2523 case I40IW_CM_STATE_OFFLOADED
:
2530 * i40iw_check_syn - Check for error on received syn ack
2531 * @cm_node: connection's node
2532 * @tcph: pointer tcp header
2534 static int i40iw_check_syn(struct i40iw_cm_node
*cm_node
, struct tcphdr
*tcph
)
2538 if (ntohl(tcph
->ack_seq
) != cm_node
->tcp_cntxt
.loc_seq_num
) {
2540 i40iw_active_open_err(cm_node
, true);
2546 * i40iw_check_seq - check seq numbers if OK
2547 * @cm_node: connection's node
2548 * @tcph: pointer tcp header
2550 static int i40iw_check_seq(struct i40iw_cm_node
*cm_node
, struct tcphdr
*tcph
)
2555 u32 loc_seq_num
= cm_node
->tcp_cntxt
.loc_seq_num
;
2556 u32 rcv_nxt
= cm_node
->tcp_cntxt
.rcv_nxt
;
2559 seq
= ntohl(tcph
->seq
);
2560 ack_seq
= ntohl(tcph
->ack_seq
);
2561 rcv_wnd
= cm_node
->tcp_cntxt
.rcv_wnd
;
2562 if (ack_seq
!= loc_seq_num
)
2564 else if (!between(seq
, rcv_nxt
, (rcv_nxt
+ rcv_wnd
)))
2567 i40iw_pr_err("seq number\n");
2568 i40iw_indicate_pkt_err(cm_node
);
2574 * i40iw_handle_syn_pkt - is for Passive node
2575 * @cm_node: connection's node
2576 * @rbuf: receive buffer
2578 static void i40iw_handle_syn_pkt(struct i40iw_cm_node
*cm_node
,
2579 struct i40iw_puda_buf
*rbuf
)
2581 struct tcphdr
*tcph
= (struct tcphdr
*)rbuf
->tcph
;
2585 struct i40iw_cm_info nfo
;
2587 optionsize
= (tcph
->doff
<< 2) - sizeof(struct tcphdr
);
2588 inc_sequence
= ntohl(tcph
->seq
);
2590 switch (cm_node
->state
) {
2591 case I40IW_CM_STATE_SYN_SENT
:
2592 case I40IW_CM_STATE_MPAREQ_SENT
:
2593 /* Rcvd syn on active open connection */
2594 i40iw_active_open_err(cm_node
, 1);
2596 case I40IW_CM_STATE_LISTENING
:
2598 if (atomic_read(&cm_node
->listener
->pend_accepts_cnt
) >
2599 cm_node
->listener
->backlog
) {
2600 cm_node
->cm_core
->stats_backlog_drops
++;
2601 i40iw_passive_open_err(cm_node
, false);
2604 ret
= i40iw_handle_tcp_options(cm_node
, tcph
, optionsize
, 1);
2606 i40iw_passive_open_err(cm_node
, false);
2610 cm_node
->tcp_cntxt
.rcv_nxt
= inc_sequence
+ 1;
2611 cm_node
->accept_pend
= 1;
2612 atomic_inc(&cm_node
->listener
->pend_accepts_cnt
);
2614 cm_node
->state
= I40IW_CM_STATE_SYN_RCVD
;
2615 i40iw_get_addr_info(cm_node
, &nfo
);
2616 ret
= i40iw_manage_qhash(cm_node
->iwdev
,
2618 I40IW_QHASH_TYPE_TCP_ESTABLISHED
,
2619 I40IW_QHASH_MANAGE_TYPE_ADD
,
2622 cm_node
->qhash_set
= true;
2624 case I40IW_CM_STATE_CLOSED
:
2625 i40iw_cleanup_retrans_entry(cm_node
);
2626 atomic_inc(&cm_node
->ref_count
);
2627 i40iw_send_reset(cm_node
);
2629 case I40IW_CM_STATE_OFFLOADED
:
2630 case I40IW_CM_STATE_ESTABLISHED
:
2631 case I40IW_CM_STATE_FIN_WAIT1
:
2632 case I40IW_CM_STATE_FIN_WAIT2
:
2633 case I40IW_CM_STATE_MPAREQ_RCVD
:
2634 case I40IW_CM_STATE_LAST_ACK
:
2635 case I40IW_CM_STATE_CLOSING
:
2636 case I40IW_CM_STATE_UNKNOWN
:
2643 * i40iw_handle_synack_pkt - Process SYN+ACK packet (active side)
2644 * @cm_node: connection's node
2645 * @rbuf: receive buffer
2647 static void i40iw_handle_synack_pkt(struct i40iw_cm_node
*cm_node
,
2648 struct i40iw_puda_buf
*rbuf
)
2650 struct tcphdr
*tcph
= (struct tcphdr
*)rbuf
->tcph
;
2655 optionsize
= (tcph
->doff
<< 2) - sizeof(struct tcphdr
);
2656 inc_sequence
= ntohl(tcph
->seq
);
2657 switch (cm_node
->state
) {
2658 case I40IW_CM_STATE_SYN_SENT
:
2659 i40iw_cleanup_retrans_entry(cm_node
);
2661 if (i40iw_check_syn(cm_node
, tcph
)) {
2662 i40iw_pr_err("check syn fail\n");
2665 cm_node
->tcp_cntxt
.rem_ack_num
= ntohl(tcph
->ack_seq
);
2667 ret
= i40iw_handle_tcp_options(cm_node
, tcph
, optionsize
, 0);
2669 i40iw_debug(cm_node
->dev
,
2671 "cm_node=%p tcp_options failed\n",
2675 i40iw_cleanup_retrans_entry(cm_node
);
2676 cm_node
->tcp_cntxt
.rcv_nxt
= inc_sequence
+ 1;
2677 i40iw_send_ack(cm_node
); /* ACK for the syn_ack */
2678 ret
= i40iw_send_mpa_request(cm_node
);
2680 i40iw_debug(cm_node
->dev
,
2682 "cm_node=%p i40iw_send_mpa_request failed\n",
2686 cm_node
->state
= I40IW_CM_STATE_MPAREQ_SENT
;
2688 case I40IW_CM_STATE_MPAREQ_RCVD
:
2689 i40iw_passive_open_err(cm_node
, true);
2691 case I40IW_CM_STATE_LISTENING
:
2692 cm_node
->tcp_cntxt
.loc_seq_num
= ntohl(tcph
->ack_seq
);
2693 i40iw_cleanup_retrans_entry(cm_node
);
2694 cm_node
->state
= I40IW_CM_STATE_CLOSED
;
2695 i40iw_send_reset(cm_node
);
2697 case I40IW_CM_STATE_CLOSED
:
2698 cm_node
->tcp_cntxt
.loc_seq_num
= ntohl(tcph
->ack_seq
);
2699 i40iw_cleanup_retrans_entry(cm_node
);
2700 atomic_inc(&cm_node
->ref_count
);
2701 i40iw_send_reset(cm_node
);
2703 case I40IW_CM_STATE_ESTABLISHED
:
2704 case I40IW_CM_STATE_FIN_WAIT1
:
2705 case I40IW_CM_STATE_FIN_WAIT2
:
2706 case I40IW_CM_STATE_LAST_ACK
:
2707 case I40IW_CM_STATE_OFFLOADED
:
2708 case I40IW_CM_STATE_CLOSING
:
2709 case I40IW_CM_STATE_UNKNOWN
:
2710 case I40IW_CM_STATE_MPAREQ_SENT
:
2717 * i40iw_handle_ack_pkt - process packet with ACK
2718 * @cm_node: connection's node
2719 * @rbuf: receive buffer
2721 static int i40iw_handle_ack_pkt(struct i40iw_cm_node
*cm_node
,
2722 struct i40iw_puda_buf
*rbuf
)
2724 struct tcphdr
*tcph
= (struct tcphdr
*)rbuf
->tcph
;
2728 u32 datasize
= rbuf
->datalen
;
2730 optionsize
= (tcph
->doff
<< 2) - sizeof(struct tcphdr
);
2732 if (i40iw_check_seq(cm_node
, tcph
))
2735 inc_sequence
= ntohl(tcph
->seq
);
2736 switch (cm_node
->state
) {
2737 case I40IW_CM_STATE_SYN_RCVD
:
2738 i40iw_cleanup_retrans_entry(cm_node
);
2739 ret
= i40iw_handle_tcp_options(cm_node
, tcph
, optionsize
, 1);
2742 cm_node
->tcp_cntxt
.rem_ack_num
= ntohl(tcph
->ack_seq
);
2743 cm_node
->state
= I40IW_CM_STATE_ESTABLISHED
;
2745 cm_node
->tcp_cntxt
.rcv_nxt
= inc_sequence
+ datasize
;
2746 i40iw_handle_rcv_mpa(cm_node
, rbuf
);
2749 case I40IW_CM_STATE_ESTABLISHED
:
2750 i40iw_cleanup_retrans_entry(cm_node
);
2752 cm_node
->tcp_cntxt
.rcv_nxt
= inc_sequence
+ datasize
;
2753 i40iw_handle_rcv_mpa(cm_node
, rbuf
);
2756 case I40IW_CM_STATE_MPAREQ_SENT
:
2757 cm_node
->tcp_cntxt
.rem_ack_num
= ntohl(tcph
->ack_seq
);
2759 cm_node
->tcp_cntxt
.rcv_nxt
= inc_sequence
+ datasize
;
2760 cm_node
->ack_rcvd
= false;
2761 i40iw_handle_rcv_mpa(cm_node
, rbuf
);
2763 cm_node
->ack_rcvd
= true;
2766 case I40IW_CM_STATE_LISTENING
:
2767 i40iw_cleanup_retrans_entry(cm_node
);
2768 cm_node
->state
= I40IW_CM_STATE_CLOSED
;
2769 i40iw_send_reset(cm_node
);
2771 case I40IW_CM_STATE_CLOSED
:
2772 i40iw_cleanup_retrans_entry(cm_node
);
2773 atomic_inc(&cm_node
->ref_count
);
2774 i40iw_send_reset(cm_node
);
2776 case I40IW_CM_STATE_LAST_ACK
:
2777 case I40IW_CM_STATE_CLOSING
:
2778 i40iw_cleanup_retrans_entry(cm_node
);
2779 cm_node
->state
= I40IW_CM_STATE_CLOSED
;
2780 if (!cm_node
->accept_pend
)
2781 cm_node
->cm_id
->rem_ref(cm_node
->cm_id
);
2782 i40iw_rem_ref_cm_node(cm_node
);
2784 case I40IW_CM_STATE_FIN_WAIT1
:
2785 i40iw_cleanup_retrans_entry(cm_node
);
2786 cm_node
->state
= I40IW_CM_STATE_FIN_WAIT2
;
2788 case I40IW_CM_STATE_SYN_SENT
:
2789 case I40IW_CM_STATE_FIN_WAIT2
:
2790 case I40IW_CM_STATE_OFFLOADED
:
2791 case I40IW_CM_STATE_MPAREQ_RCVD
:
2792 case I40IW_CM_STATE_UNKNOWN
:
2794 i40iw_cleanup_retrans_entry(cm_node
);
2801 * i40iw_process_packet - process cm packet
2802 * @cm_node: connection's node
2803 * @rbuf: receive buffer
2805 static void i40iw_process_packet(struct i40iw_cm_node
*cm_node
,
2806 struct i40iw_puda_buf
*rbuf
)
2808 enum i40iw_tcpip_pkt_type pkt_type
= I40IW_PKT_TYPE_UNKNOWN
;
2809 struct tcphdr
*tcph
= (struct tcphdr
*)rbuf
->tcph
;
2814 pkt_type
= I40IW_PKT_TYPE_RST
;
2815 } else if (tcph
->syn
) {
2816 pkt_type
= I40IW_PKT_TYPE_SYN
;
2818 pkt_type
= I40IW_PKT_TYPE_SYNACK
;
2819 } else if (tcph
->ack
) {
2820 pkt_type
= I40IW_PKT_TYPE_ACK
;
2826 case I40IW_PKT_TYPE_SYN
:
2827 i40iw_handle_syn_pkt(cm_node
, rbuf
);
2829 case I40IW_PKT_TYPE_SYNACK
:
2830 i40iw_handle_synack_pkt(cm_node
, rbuf
);
2832 case I40IW_PKT_TYPE_ACK
:
2833 ret
= i40iw_handle_ack_pkt(cm_node
, rbuf
);
2834 if (fin_set
&& !ret
)
2835 i40iw_handle_fin_pkt(cm_node
);
2837 case I40IW_PKT_TYPE_RST
:
2838 i40iw_handle_rst_pkt(cm_node
, rbuf
);
2842 (!i40iw_check_seq(cm_node
, (struct tcphdr
*)rbuf
->tcph
)))
2843 i40iw_handle_fin_pkt(cm_node
);
2849 * i40iw_make_listen_node - create a listen node with params
2850 * @cm_core: cm's core
2851 * @iwdev: iwarp device structure
2852 * @cm_info: quad info for connection
2854 static struct i40iw_cm_listener
*i40iw_make_listen_node(
2855 struct i40iw_cm_core
*cm_core
,
2856 struct i40iw_device
*iwdev
,
2857 struct i40iw_cm_info
*cm_info
)
2859 struct i40iw_cm_listener
*listener
;
2860 unsigned long flags
;
2862 /* cannot have multiple matching listeners */
2863 listener
= i40iw_find_listener(cm_core
, cm_info
->loc_addr
,
2866 I40IW_CM_LISTENER_EITHER_STATE
);
2868 (listener
->listener_state
== I40IW_CM_LISTENER_ACTIVE_STATE
)) {
2869 atomic_dec(&listener
->ref_count
);
2870 i40iw_debug(cm_core
->dev
,
2872 "Not creating listener since it already exists\n");
2877 /* create a CM listen node (1/2 node to compare incoming traffic to) */
2878 listener
= kzalloc(sizeof(*listener
), GFP_KERNEL
);
2881 cm_core
->stats_listen_nodes_created
++;
2882 memcpy(listener
->loc_addr
, cm_info
->loc_addr
, sizeof(listener
->loc_addr
));
2883 listener
->loc_port
= cm_info
->loc_port
;
2885 INIT_LIST_HEAD(&listener
->child_listen_list
);
2887 atomic_set(&listener
->ref_count
, 1);
2889 listener
->reused_node
= 1;
2892 listener
->cm_id
= cm_info
->cm_id
;
2893 listener
->ipv4
= cm_info
->ipv4
;
2894 listener
->vlan_id
= cm_info
->vlan_id
;
2895 atomic_set(&listener
->pend_accepts_cnt
, 0);
2896 listener
->cm_core
= cm_core
;
2897 listener
->iwdev
= iwdev
;
2899 listener
->backlog
= cm_info
->backlog
;
2900 listener
->listener_state
= I40IW_CM_LISTENER_ACTIVE_STATE
;
2902 if (!listener
->reused_node
) {
2903 spin_lock_irqsave(&cm_core
->listen_list_lock
, flags
);
2904 list_add(&listener
->list
, &cm_core
->listen_nodes
);
2905 spin_unlock_irqrestore(&cm_core
->listen_list_lock
, flags
);
2912 * i40iw_create_cm_node - make a connection node with params
2913 * @cm_core: cm's core
2914 * @iwdev: iwarp device structure
2915 * @conn_param: upper layer connection parameters
2916 * @cm_info: quad info for connection
2918 static struct i40iw_cm_node
*i40iw_create_cm_node(
2919 struct i40iw_cm_core
*cm_core
,
2920 struct i40iw_device
*iwdev
,
2921 struct iw_cm_conn_param
*conn_param
,
2922 struct i40iw_cm_info
*cm_info
)
2924 struct i40iw_cm_node
*cm_node
;
2925 struct i40iw_cm_listener
*loopback_remotelistener
;
2926 struct i40iw_cm_node
*loopback_remotenode
;
2927 struct i40iw_cm_info loopback_cm_info
;
2929 u16 private_data_len
= conn_param
->private_data_len
;
2930 const void *private_data
= conn_param
->private_data
;
2932 /* create a CM connection node */
2933 cm_node
= i40iw_make_cm_node(cm_core
, iwdev
, cm_info
, NULL
);
2935 return ERR_PTR(-ENOMEM
);
2936 /* set our node side to client (active) side */
2937 cm_node
->tcp_cntxt
.client
= 1;
2938 cm_node
->tcp_cntxt
.rcv_wscale
= I40IW_CM_DEFAULT_RCV_WND_SCALE
;
2940 i40iw_record_ird_ord(cm_node
, conn_param
->ird
, conn_param
->ord
);
2942 if (!memcmp(cm_info
->loc_addr
, cm_info
->rem_addr
, sizeof(cm_info
->loc_addr
))) {
2943 loopback_remotelistener
= i40iw_find_listener(
2948 I40IW_CM_LISTENER_ACTIVE_STATE
);
2949 if (!loopback_remotelistener
) {
2950 i40iw_rem_ref_cm_node(cm_node
);
2951 return ERR_PTR(-ECONNREFUSED
);
2953 loopback_cm_info
= *cm_info
;
2954 loopback_cm_info
.loc_port
= cm_info
->rem_port
;
2955 loopback_cm_info
.rem_port
= cm_info
->loc_port
;
2956 loopback_cm_info
.cm_id
= loopback_remotelistener
->cm_id
;
2957 loopback_cm_info
.ipv4
= cm_info
->ipv4
;
2958 loopback_remotenode
= i40iw_make_cm_node(cm_core
,
2961 loopback_remotelistener
);
2962 if (!loopback_remotenode
) {
2963 i40iw_rem_ref_cm_node(cm_node
);
2964 return ERR_PTR(-ENOMEM
);
2966 cm_core
->stats_loopbacks
++;
2967 loopback_remotenode
->loopbackpartner
= cm_node
;
2968 loopback_remotenode
->tcp_cntxt
.rcv_wscale
=
2969 I40IW_CM_DEFAULT_RCV_WND_SCALE
;
2970 cm_node
->loopbackpartner
= loopback_remotenode
;
2971 memcpy(loopback_remotenode
->pdata_buf
, private_data
,
2973 loopback_remotenode
->pdata
.size
= private_data_len
;
2975 if (loopback_remotenode
->ord_size
> cm_node
->ird_size
)
2976 loopback_remotenode
->ord_size
=
2979 cm_node
->state
= I40IW_CM_STATE_OFFLOADED
;
2980 cm_node
->tcp_cntxt
.rcv_nxt
=
2981 loopback_remotenode
->tcp_cntxt
.loc_seq_num
;
2982 loopback_remotenode
->tcp_cntxt
.rcv_nxt
=
2983 cm_node
->tcp_cntxt
.loc_seq_num
;
2984 cm_node
->tcp_cntxt
.max_snd_wnd
=
2985 loopback_remotenode
->tcp_cntxt
.rcv_wnd
;
2986 loopback_remotenode
->tcp_cntxt
.max_snd_wnd
= cm_node
->tcp_cntxt
.rcv_wnd
;
2987 cm_node
->tcp_cntxt
.snd_wnd
= loopback_remotenode
->tcp_cntxt
.rcv_wnd
;
2988 loopback_remotenode
->tcp_cntxt
.snd_wnd
= cm_node
->tcp_cntxt
.rcv_wnd
;
2989 cm_node
->tcp_cntxt
.snd_wscale
= loopback_remotenode
->tcp_cntxt
.rcv_wscale
;
2990 loopback_remotenode
->tcp_cntxt
.snd_wscale
= cm_node
->tcp_cntxt
.rcv_wscale
;
2995 cm_node
->pdata
.size
= private_data_len
;
2996 cm_node
->pdata
.addr
= cm_node
->pdata_buf
;
2998 memcpy(cm_node
->pdata_buf
, private_data
, private_data_len
);
3000 cm_node
->state
= I40IW_CM_STATE_SYN_SENT
;
3005 * i40iw_cm_reject - reject and teardown a connection
3006 * @cm_node: connection's node
3007 * @pdate: ptr to private data for reject
3008 * @plen: size of private data
3010 static int i40iw_cm_reject(struct i40iw_cm_node
*cm_node
, const void *pdata
, u8 plen
)
3015 struct iw_cm_id
*cm_id
= cm_node
->cm_id
;
3016 struct i40iw_cm_node
*loopback
= cm_node
->loopbackpartner
;
3018 if (cm_node
->tcp_cntxt
.client
)
3020 i40iw_cleanup_retrans_entry(cm_node
);
3023 passive_state
= atomic_inc_return(&cm_node
->passive_state
);
3024 if (passive_state
== I40IW_SEND_RESET_EVENT
) {
3025 cm_node
->state
= I40IW_CM_STATE_CLOSED
;
3026 i40iw_rem_ref_cm_node(cm_node
);
3028 if (cm_node
->state
== I40IW_CM_STATE_LISTENER_DESTROYED
) {
3029 i40iw_rem_ref_cm_node(cm_node
);
3031 ret
= i40iw_send_mpa_reject(cm_node
, pdata
, plen
);
3033 cm_node
->state
= I40IW_CM_STATE_CLOSED
;
3034 err
= i40iw_send_reset(cm_node
);
3036 i40iw_pr_err("send reset failed\n");
3038 cm_id
->add_ref(cm_id
);
3043 cm_node
->cm_id
= NULL
;
3044 if (cm_node
->state
== I40IW_CM_STATE_LISTENER_DESTROYED
) {
3045 i40iw_rem_ref_cm_node(cm_node
);
3046 i40iw_rem_ref_cm_node(loopback
);
3048 ret
= i40iw_send_cm_event(loopback
,
3050 IW_CM_EVENT_CONNECT_REPLY
,
3052 i40iw_rem_ref_cm_node(cm_node
);
3053 loopback
->state
= I40IW_CM_STATE_CLOSING
;
3055 cm_id
= loopback
->cm_id
;
3056 i40iw_rem_ref_cm_node(loopback
);
3057 cm_id
->rem_ref(cm_id
);
3065 * i40iw_cm_close - close of cm connection
3066 * @cm_node: connection's node
3068 static int i40iw_cm_close(struct i40iw_cm_node
*cm_node
)
3075 switch (cm_node
->state
) {
3076 case I40IW_CM_STATE_SYN_RCVD
:
3077 case I40IW_CM_STATE_SYN_SENT
:
3078 case I40IW_CM_STATE_ONE_SIDE_ESTABLISHED
:
3079 case I40IW_CM_STATE_ESTABLISHED
:
3080 case I40IW_CM_STATE_ACCEPTING
:
3081 case I40IW_CM_STATE_MPAREQ_SENT
:
3082 case I40IW_CM_STATE_MPAREQ_RCVD
:
3083 i40iw_cleanup_retrans_entry(cm_node
);
3084 i40iw_send_reset(cm_node
);
3086 case I40IW_CM_STATE_CLOSE_WAIT
:
3087 cm_node
->state
= I40IW_CM_STATE_LAST_ACK
;
3088 i40iw_send_fin(cm_node
);
3090 case I40IW_CM_STATE_FIN_WAIT1
:
3091 case I40IW_CM_STATE_FIN_WAIT2
:
3092 case I40IW_CM_STATE_LAST_ACK
:
3093 case I40IW_CM_STATE_TIME_WAIT
:
3094 case I40IW_CM_STATE_CLOSING
:
3097 case I40IW_CM_STATE_LISTENING
:
3098 i40iw_cleanup_retrans_entry(cm_node
);
3099 i40iw_send_reset(cm_node
);
3101 case I40IW_CM_STATE_MPAREJ_RCVD
:
3102 case I40IW_CM_STATE_UNKNOWN
:
3103 case I40IW_CM_STATE_INITED
:
3104 case I40IW_CM_STATE_CLOSED
:
3105 case I40IW_CM_STATE_LISTENER_DESTROYED
:
3106 i40iw_rem_ref_cm_node(cm_node
);
3108 case I40IW_CM_STATE_OFFLOADED
:
3109 if (cm_node
->send_entry
)
3110 i40iw_pr_err("send_entry\n");
3111 i40iw_rem_ref_cm_node(cm_node
);
3118 * i40iw_receive_ilq - recv an ETHERNET packet, and process it
3120 * @vsi: pointer to the vsi structure
3121 * @rbuf: receive buffer
3123 void i40iw_receive_ilq(struct i40iw_sc_vsi
*vsi
, struct i40iw_puda_buf
*rbuf
)
3125 struct i40iw_cm_node
*cm_node
;
3126 struct i40iw_cm_listener
*listener
;
3128 struct ipv6hdr
*ip6h
;
3129 struct tcphdr
*tcph
;
3130 struct i40iw_cm_info cm_info
;
3131 struct i40iw_sc_dev
*dev
= vsi
->dev
;
3132 struct i40iw_device
*iwdev
= (struct i40iw_device
*)dev
->back_dev
;
3133 struct i40iw_cm_core
*cm_core
= &iwdev
->cm_core
;
3134 struct vlan_ethhdr
*ethh
;
3137 /* if vlan, then maclen = 18 else 14 */
3138 iph
= (struct iphdr
*)rbuf
->iph
;
3139 memset(&cm_info
, 0, sizeof(cm_info
));
3141 i40iw_debug_buf(dev
,
3143 "RECEIVE ILQ BUFFER",
3146 ethh
= (struct vlan_ethhdr
*)rbuf
->mem
.va
;
3148 if (ethh
->h_vlan_proto
== htons(ETH_P_8021Q
)) {
3149 vtag
= ntohs(ethh
->h_vlan_TCI
);
3150 cm_info
.user_pri
= (vtag
& VLAN_PRIO_MASK
) >> VLAN_PRIO_SHIFT
;
3151 cm_info
.vlan_id
= vtag
& VLAN_VID_MASK
;
3152 i40iw_debug(cm_core
->dev
,
3158 cm_info
.vlan_id
= I40IW_NO_VLAN
;
3160 tcph
= (struct tcphdr
*)rbuf
->tcph
;
3163 cm_info
.loc_addr
[0] = ntohl(iph
->daddr
);
3164 cm_info
.rem_addr
[0] = ntohl(iph
->saddr
);
3165 cm_info
.ipv4
= true;
3166 cm_info
.tos
= iph
->tos
;
3168 ip6h
= (struct ipv6hdr
*)rbuf
->iph
;
3169 i40iw_copy_ip_ntohl(cm_info
.loc_addr
,
3170 ip6h
->daddr
.in6_u
.u6_addr32
);
3171 i40iw_copy_ip_ntohl(cm_info
.rem_addr
,
3172 ip6h
->saddr
.in6_u
.u6_addr32
);
3173 cm_info
.ipv4
= false;
3174 cm_info
.tos
= (ip6h
->priority
<< 4) | (ip6h
->flow_lbl
[0] >> 4);
3176 cm_info
.loc_port
= ntohs(tcph
->dest
);
3177 cm_info
.rem_port
= ntohs(tcph
->source
);
3178 cm_node
= i40iw_find_node(cm_core
,
3187 /* Only type of packet accepted are for */
3188 /* the PASSIVE open (syn only) */
3189 if (!tcph
->syn
|| tcph
->ack
)
3192 i40iw_find_listener(cm_core
,
3196 I40IW_CM_LISTENER_ACTIVE_STATE
);
3198 cm_info
.cm_id
= NULL
;
3199 i40iw_debug(cm_core
->dev
,
3201 "%s no listener found\n",
3205 cm_info
.cm_id
= listener
->cm_id
;
3206 cm_node
= i40iw_make_cm_node(cm_core
, iwdev
, &cm_info
, listener
);
3208 i40iw_debug(cm_core
->dev
,
3210 "%s allocate node failed\n",
3212 atomic_dec(&listener
->ref_count
);
3215 if (!tcph
->rst
&& !tcph
->fin
) {
3216 cm_node
->state
= I40IW_CM_STATE_LISTENING
;
3218 i40iw_rem_ref_cm_node(cm_node
);
3221 atomic_inc(&cm_node
->ref_count
);
3222 } else if (cm_node
->state
== I40IW_CM_STATE_OFFLOADED
) {
3223 i40iw_rem_ref_cm_node(cm_node
);
3226 i40iw_process_packet(cm_node
, rbuf
);
3227 i40iw_rem_ref_cm_node(cm_node
);
3231 * i40iw_setup_cm_core - allocate a top level instance of a cm
3233 * @iwdev: iwarp device structure
3235 int i40iw_setup_cm_core(struct i40iw_device
*iwdev
)
3237 struct i40iw_cm_core
*cm_core
= &iwdev
->cm_core
;
3239 cm_core
->iwdev
= iwdev
;
3240 cm_core
->dev
= &iwdev
->sc_dev
;
3242 INIT_LIST_HEAD(&cm_core
->accelerated_list
);
3243 INIT_LIST_HEAD(&cm_core
->non_accelerated_list
);
3244 INIT_LIST_HEAD(&cm_core
->listen_nodes
);
3246 timer_setup(&cm_core
->tcp_timer
, i40iw_cm_timer_tick
, 0);
3248 spin_lock_init(&cm_core
->ht_lock
);
3249 spin_lock_init(&cm_core
->listen_list_lock
);
3250 spin_lock_init(&cm_core
->apbvt_lock
);
3252 cm_core
->event_wq
= alloc_ordered_workqueue("iwewq",
3254 if (!cm_core
->event_wq
)
3257 cm_core
->disconn_wq
= alloc_ordered_workqueue("iwdwq",
3259 if (!cm_core
->disconn_wq
)
3264 i40iw_cleanup_cm_core(&iwdev
->cm_core
);
3270 * i40iw_cleanup_cm_core - deallocate a top level instance of a
3272 * @cm_core: cm's core
3274 void i40iw_cleanup_cm_core(struct i40iw_cm_core
*cm_core
)
3276 unsigned long flags
;
3281 spin_lock_irqsave(&cm_core
->ht_lock
, flags
);
3282 if (timer_pending(&cm_core
->tcp_timer
))
3283 del_timer_sync(&cm_core
->tcp_timer
);
3284 spin_unlock_irqrestore(&cm_core
->ht_lock
, flags
);
3286 if (cm_core
->event_wq
)
3287 destroy_workqueue(cm_core
->event_wq
);
3288 if (cm_core
->disconn_wq
)
3289 destroy_workqueue(cm_core
->disconn_wq
);
3293 * i40iw_init_tcp_ctx - setup qp context
3294 * @cm_node: connection's node
3295 * @tcp_info: offload info for tcp
3296 * @iwqp: associate qp for the connection
3298 static void i40iw_init_tcp_ctx(struct i40iw_cm_node
*cm_node
,
3299 struct i40iw_tcp_offload_info
*tcp_info
,
3300 struct i40iw_qp
*iwqp
)
3302 tcp_info
->ipv4
= cm_node
->ipv4
;
3303 tcp_info
->drop_ooo_seg
= true;
3304 tcp_info
->wscale
= true;
3305 tcp_info
->ignore_tcp_opt
= true;
3306 tcp_info
->ignore_tcp_uns_opt
= true;
3307 tcp_info
->no_nagle
= false;
3309 tcp_info
->ttl
= I40IW_DEFAULT_TTL
;
3310 tcp_info
->rtt_var
= cpu_to_le32(I40IW_DEFAULT_RTT_VAR
);
3311 tcp_info
->ss_thresh
= cpu_to_le32(I40IW_DEFAULT_SS_THRESH
);
3312 tcp_info
->rexmit_thresh
= I40IW_DEFAULT_REXMIT_THRESH
;
3314 tcp_info
->tcp_state
= I40IW_TCP_STATE_ESTABLISHED
;
3315 tcp_info
->snd_wscale
= cm_node
->tcp_cntxt
.snd_wscale
;
3316 tcp_info
->rcv_wscale
= cm_node
->tcp_cntxt
.rcv_wscale
;
3318 tcp_info
->snd_nxt
= cpu_to_le32(cm_node
->tcp_cntxt
.loc_seq_num
);
3319 tcp_info
->snd_wnd
= cpu_to_le32(cm_node
->tcp_cntxt
.snd_wnd
);
3320 tcp_info
->rcv_nxt
= cpu_to_le32(cm_node
->tcp_cntxt
.rcv_nxt
);
3321 tcp_info
->snd_max
= cpu_to_le32(cm_node
->tcp_cntxt
.loc_seq_num
);
3323 tcp_info
->snd_una
= cpu_to_le32(cm_node
->tcp_cntxt
.loc_seq_num
);
3324 tcp_info
->cwnd
= cpu_to_le32(2 * cm_node
->tcp_cntxt
.mss
);
3325 tcp_info
->snd_wl1
= cpu_to_le32(cm_node
->tcp_cntxt
.rcv_nxt
);
3326 tcp_info
->snd_wl2
= cpu_to_le32(cm_node
->tcp_cntxt
.loc_seq_num
);
3327 tcp_info
->max_snd_window
= cpu_to_le32(cm_node
->tcp_cntxt
.max_snd_wnd
);
3328 tcp_info
->rcv_wnd
= cpu_to_le32(cm_node
->tcp_cntxt
.rcv_wnd
<<
3329 cm_node
->tcp_cntxt
.rcv_wscale
);
3331 tcp_info
->flow_label
= 0;
3332 tcp_info
->snd_mss
= cpu_to_le32(((u32
)cm_node
->tcp_cntxt
.mss
));
3333 if (cm_node
->vlan_id
<= VLAN_VID_MASK
) {
3334 tcp_info
->insert_vlan_tag
= true;
3335 tcp_info
->vlan_tag
= cpu_to_le16(((u16
)cm_node
->user_pri
<< I40IW_VLAN_PRIO_SHIFT
) |
3338 if (cm_node
->ipv4
) {
3339 tcp_info
->src_port
= cpu_to_le16(cm_node
->loc_port
);
3340 tcp_info
->dst_port
= cpu_to_le16(cm_node
->rem_port
);
3342 tcp_info
->dest_ip_addr3
= cpu_to_le32(cm_node
->rem_addr
[0]);
3343 tcp_info
->local_ipaddr3
= cpu_to_le32(cm_node
->loc_addr
[0]);
3345 cpu_to_le16((u16
)i40iw_arp_table(
3347 &tcp_info
->dest_ip_addr3
,
3350 I40IW_ARP_RESOLVE
));
3352 tcp_info
->src_port
= cpu_to_le16(cm_node
->loc_port
);
3353 tcp_info
->dst_port
= cpu_to_le16(cm_node
->rem_port
);
3354 tcp_info
->dest_ip_addr0
= cpu_to_le32(cm_node
->rem_addr
[0]);
3355 tcp_info
->dest_ip_addr1
= cpu_to_le32(cm_node
->rem_addr
[1]);
3356 tcp_info
->dest_ip_addr2
= cpu_to_le32(cm_node
->rem_addr
[2]);
3357 tcp_info
->dest_ip_addr3
= cpu_to_le32(cm_node
->rem_addr
[3]);
3358 tcp_info
->local_ipaddr0
= cpu_to_le32(cm_node
->loc_addr
[0]);
3359 tcp_info
->local_ipaddr1
= cpu_to_le32(cm_node
->loc_addr
[1]);
3360 tcp_info
->local_ipaddr2
= cpu_to_le32(cm_node
->loc_addr
[2]);
3361 tcp_info
->local_ipaddr3
= cpu_to_le32(cm_node
->loc_addr
[3]);
3363 cpu_to_le16((u16
)i40iw_arp_table(
3365 &tcp_info
->dest_ip_addr0
,
3368 I40IW_ARP_RESOLVE
));
3373 * i40iw_cm_init_tsa_conn - setup qp for RTS
3374 * @iwqp: associate qp for the connection
3375 * @cm_node: connection's node
3377 static void i40iw_cm_init_tsa_conn(struct i40iw_qp
*iwqp
,
3378 struct i40iw_cm_node
*cm_node
)
3380 struct i40iw_tcp_offload_info tcp_info
;
3381 struct i40iwarp_offload_info
*iwarp_info
;
3382 struct i40iw_qp_host_ctx_info
*ctx_info
;
3383 struct i40iw_device
*iwdev
= iwqp
->iwdev
;
3384 struct i40iw_sc_dev
*dev
= &iwqp
->iwdev
->sc_dev
;
3386 memset(&tcp_info
, 0x00, sizeof(struct i40iw_tcp_offload_info
));
3387 iwarp_info
= &iwqp
->iwarp_info
;
3388 ctx_info
= &iwqp
->ctx_info
;
3390 ctx_info
->tcp_info
= &tcp_info
;
3391 ctx_info
->send_cq_num
= iwqp
->iwscq
->sc_cq
.cq_uk
.cq_id
;
3392 ctx_info
->rcv_cq_num
= iwqp
->iwrcq
->sc_cq
.cq_uk
.cq_id
;
3394 iwarp_info
->ord_size
= cm_node
->ord_size
;
3395 iwarp_info
->ird_size
= i40iw_derive_hw_ird_setting(cm_node
->ird_size
);
3397 if (iwarp_info
->ord_size
== 1)
3398 iwarp_info
->ord_size
= 2;
3400 iwarp_info
->rd_enable
= true;
3401 iwarp_info
->rdmap_ver
= 1;
3402 iwarp_info
->ddp_ver
= 1;
3404 iwarp_info
->pd_id
= iwqp
->iwpd
->sc_pd
.pd_id
;
3406 ctx_info
->tcp_info_valid
= true;
3407 ctx_info
->iwarp_info_valid
= true;
3408 ctx_info
->add_to_qoslist
= true;
3409 ctx_info
->user_pri
= cm_node
->user_pri
;
3411 i40iw_init_tcp_ctx(cm_node
, &tcp_info
, iwqp
);
3412 if (cm_node
->snd_mark_en
) {
3413 iwarp_info
->snd_mark_en
= true;
3414 iwarp_info
->snd_mark_offset
= (tcp_info
.snd_nxt
&
3415 SNDMARKER_SEQNMASK
) + cm_node
->lsmm_size
;
3418 cm_node
->state
= I40IW_CM_STATE_OFFLOADED
;
3419 tcp_info
.tcp_state
= I40IW_TCP_STATE_ESTABLISHED
;
3420 tcp_info
.src_mac_addr_idx
= iwdev
->mac_ip_table_idx
;
3421 tcp_info
.tos
= cm_node
->tos
;
3423 dev
->iw_priv_qp_ops
->qp_setctx(&iwqp
->sc_qp
, (u64
*)(iwqp
->host_ctx
.va
), ctx_info
);
3425 /* once tcp_info is set, no need to do it again */
3426 ctx_info
->tcp_info_valid
= false;
3427 ctx_info
->iwarp_info_valid
= false;
3428 ctx_info
->add_to_qoslist
= false;
3432 * i40iw_cm_disconn - when a connection is being closed
3433 * @iwqp: associate qp for the connection
3435 void i40iw_cm_disconn(struct i40iw_qp
*iwqp
)
3437 struct disconn_work
*work
;
3438 struct i40iw_device
*iwdev
= iwqp
->iwdev
;
3439 struct i40iw_cm_core
*cm_core
= &iwdev
->cm_core
;
3440 unsigned long flags
;
3442 work
= kzalloc(sizeof(*work
), GFP_ATOMIC
);
3444 return; /* Timer will clean up */
3446 spin_lock_irqsave(&iwdev
->qptable_lock
, flags
);
3447 if (!iwdev
->qp_table
[iwqp
->ibqp
.qp_num
]) {
3448 spin_unlock_irqrestore(&iwdev
->qptable_lock
, flags
);
3449 i40iw_debug(&iwdev
->sc_dev
, I40IW_DEBUG_CM
,
3450 "%s qp_id %d is already freed\n",
3451 __func__
, iwqp
->ibqp
.qp_num
);
3455 i40iw_qp_add_ref(&iwqp
->ibqp
);
3456 spin_unlock_irqrestore(&iwdev
->qptable_lock
, flags
);
3459 INIT_WORK(&work
->work
, i40iw_disconnect_worker
);
3460 queue_work(cm_core
->disconn_wq
, &work
->work
);
3465 * i40iw_qp_disconnect - free qp and close cm
3466 * @iwqp: associate qp for the connection
3468 static void i40iw_qp_disconnect(struct i40iw_qp
*iwqp
)
3470 struct i40iw_device
*iwdev
;
3471 struct i40iw_ib_device
*iwibdev
;
3473 iwdev
= to_iwdev(iwqp
->ibqp
.device
);
3475 i40iw_pr_err("iwdev == NULL\n");
3479 iwibdev
= iwdev
->iwibdev
;
3481 if (iwqp
->active_conn
) {
3482 /* indicate this connection is NOT active */
3483 iwqp
->active_conn
= 0;
3485 /* Need to free the Last Streaming Mode Message */
3486 if (iwqp
->ietf_mem
.va
) {
3488 iwibdev
->ibdev
.ops
.dereg_mr(iwqp
->lsmm_mr
,
3490 i40iw_free_dma_mem(iwdev
->sc_dev
.hw
, &iwqp
->ietf_mem
);
3494 /* close the CM node down if it is still active */
3495 if (iwqp
->cm_node
) {
3496 i40iw_debug(&iwdev
->sc_dev
, I40IW_DEBUG_CM
, "%s Call close API\n", __func__
);
3497 i40iw_cm_close(iwqp
->cm_node
);
3502 * i40iw_cm_disconn_true - called by worker thread to disconnect qp
3503 * @iwqp: associate qp for the connection
3505 static void i40iw_cm_disconn_true(struct i40iw_qp
*iwqp
)
3507 struct iw_cm_id
*cm_id
;
3508 struct i40iw_device
*iwdev
;
3509 struct i40iw_sc_qp
*qp
= &iwqp
->sc_qp
;
3511 u8 original_hw_tcp_state
;
3512 u8 original_ibqp_state
;
3513 int disconn_status
= 0;
3514 int issue_disconn
= 0;
3515 int issue_close
= 0;
3516 int issue_flush
= 0;
3517 struct ib_event ibevent
;
3518 unsigned long flags
;
3522 i40iw_pr_err("iwqp == NULL\n");
3526 spin_lock_irqsave(&iwqp
->lock
, flags
);
3527 cm_id
= iwqp
->cm_id
;
3528 /* make sure we havent already closed this connection */
3530 spin_unlock_irqrestore(&iwqp
->lock
, flags
);
3534 iwdev
= to_iwdev(iwqp
->ibqp
.device
);
3536 original_hw_tcp_state
= iwqp
->hw_tcp_state
;
3537 original_ibqp_state
= iwqp
->ibqp_state
;
3538 last_ae
= iwqp
->last_aeq
;
3540 if (qp
->term_flags
) {
3544 /*When term timer expires after cm_timer, don't want
3545 *terminate-handler to issue cm_disconn which can re-free
3546 *a QP even after its refcnt=0.
3548 i40iw_terminate_del_timer(qp
);
3549 if (!iwqp
->flush_issued
) {
3550 iwqp
->flush_issued
= 1;
3553 } else if ((original_hw_tcp_state
== I40IW_TCP_STATE_CLOSE_WAIT
) ||
3554 ((original_ibqp_state
== IB_QPS_RTS
) &&
3555 (last_ae
== I40IW_AE_LLP_CONNECTION_RESET
))) {
3557 if (last_ae
== I40IW_AE_LLP_CONNECTION_RESET
)
3558 disconn_status
= -ECONNRESET
;
3561 if (((original_hw_tcp_state
== I40IW_TCP_STATE_CLOSED
) ||
3562 (original_hw_tcp_state
== I40IW_TCP_STATE_TIME_WAIT
) ||
3563 (last_ae
== I40IW_AE_RDMAP_ROE_BAD_LLP_CLOSE
) ||
3564 (last_ae
== I40IW_AE_LLP_CONNECTION_RESET
) ||
3568 if (!iwqp
->flush_issued
) {
3569 iwqp
->flush_issued
= 1;
3574 spin_unlock_irqrestore(&iwqp
->lock
, flags
);
3575 if (issue_flush
&& !iwqp
->destroyed
) {
3576 /* Flush the queues */
3577 i40iw_flush_wqes(iwdev
, iwqp
);
3579 if (qp
->term_flags
&& iwqp
->ibqp
.event_handler
) {
3580 ibevent
.device
= iwqp
->ibqp
.device
;
3581 ibevent
.event
= (qp
->eventtype
== TERM_EVENT_QP_FATAL
) ?
3582 IB_EVENT_QP_FATAL
: IB_EVENT_QP_ACCESS_ERR
;
3583 ibevent
.element
.qp
= &iwqp
->ibqp
;
3584 iwqp
->ibqp
.event_handler(&ibevent
, iwqp
->ibqp
.qp_context
);
3588 if (cm_id
&& cm_id
->event_handler
) {
3589 if (issue_disconn
) {
3590 ret
= i40iw_send_cm_event(NULL
,
3592 IW_CM_EVENT_DISCONNECT
,
3596 i40iw_debug(&iwdev
->sc_dev
,
3598 "disconnect event failed %s: - cm_id = %p\n",
3602 i40iw_qp_disconnect(iwqp
);
3603 cm_id
->provider_data
= iwqp
;
3604 ret
= i40iw_send_cm_event(NULL
, cm_id
, IW_CM_EVENT_CLOSE
, 0);
3606 i40iw_debug(&iwdev
->sc_dev
,
3608 "close event failed %s: - cm_id = %p\n",
3610 cm_id
->rem_ref(cm_id
);
3616 * i40iw_disconnect_worker - worker for connection close
3617 * @work: points or disconn structure
3619 static void i40iw_disconnect_worker(struct work_struct
*work
)
3621 struct disconn_work
*dwork
= container_of(work
, struct disconn_work
, work
);
3622 struct i40iw_qp
*iwqp
= dwork
->iwqp
;
3625 i40iw_cm_disconn_true(iwqp
);
3626 i40iw_qp_rem_ref(&iwqp
->ibqp
);
3630 * i40iw_accept - registered call for connection to be accepted
3631 * @cm_id: cm information for passive connection
3632 * @conn_param: accpet parameters
3634 int i40iw_accept(struct iw_cm_id
*cm_id
, struct iw_cm_conn_param
*conn_param
)
3637 struct i40iw_qp
*iwqp
;
3638 struct i40iw_device
*iwdev
;
3639 struct i40iw_sc_dev
*dev
;
3640 struct i40iw_cm_core
*cm_core
;
3641 struct i40iw_cm_node
*cm_node
;
3642 struct ib_qp_attr attr
;
3645 struct i40iw_pd
*iwpd
;
3647 struct i40iw_kmem_info accept
;
3648 enum i40iw_status_code status
;
3650 unsigned long flags
;
3652 memset(&attr
, 0, sizeof(attr
));
3653 ibqp
= i40iw_get_qp(cm_id
->device
, conn_param
->qpn
);
3657 iwqp
= to_iwqp(ibqp
);
3658 iwdev
= iwqp
->iwdev
;
3659 dev
= &iwdev
->sc_dev
;
3660 cm_core
= &iwdev
->cm_core
;
3661 cm_node
= (struct i40iw_cm_node
*)cm_id
->provider_data
;
3663 if (((struct sockaddr_in
*)&cm_id
->local_addr
)->sin_family
== AF_INET
) {
3664 cm_node
->ipv4
= true;
3665 cm_node
->vlan_id
= i40iw_get_vlan_ipv4(cm_node
->loc_addr
);
3667 cm_node
->ipv4
= false;
3668 i40iw_netdev_vlan_ipv6(cm_node
->loc_addr
, &cm_node
->vlan_id
);
3670 i40iw_debug(cm_node
->dev
,
3672 "Accept vlan_id=%d\n",
3674 if (cm_node
->state
== I40IW_CM_STATE_LISTENER_DESTROYED
) {
3675 if (cm_node
->loopbackpartner
)
3676 i40iw_rem_ref_cm_node(cm_node
->loopbackpartner
);
3677 i40iw_rem_ref_cm_node(cm_node
);
3681 passive_state
= atomic_inc_return(&cm_node
->passive_state
);
3682 if (passive_state
== I40IW_SEND_RESET_EVENT
) {
3683 i40iw_rem_ref_cm_node(cm_node
);
3687 cm_node
->cm_core
->stats_accepts
++;
3688 iwqp
->cm_node
= (void *)cm_node
;
3689 cm_node
->iwqp
= iwqp
;
3691 buf_len
= conn_param
->private_data_len
+ I40IW_MAX_IETF_SIZE
;
3693 status
= i40iw_allocate_dma_mem(dev
->hw
, &iwqp
->ietf_mem
, buf_len
, 1);
3697 cm_node
->pdata
.size
= conn_param
->private_data_len
;
3698 accept
.addr
= iwqp
->ietf_mem
.va
;
3699 accept
.size
= i40iw_cm_build_mpa_frame(cm_node
, &accept
, MPA_KEY_REPLY
);
3700 memcpy(accept
.addr
+ accept
.size
, conn_param
->private_data
,
3701 conn_param
->private_data_len
);
3703 /* setup our first outgoing iWarp send WQE (the IETF frame response) */
3704 if ((cm_node
->ipv4
&&
3705 !i40iw_ipv4_is_loopback(cm_node
->loc_addr
[0], cm_node
->rem_addr
[0])) ||
3707 !i40iw_ipv6_is_loopback(cm_node
->loc_addr
, cm_node
->rem_addr
))) {
3709 tagged_offset
= (uintptr_t)iwqp
->ietf_mem
.va
;
3710 ibmr
= i40iw_reg_phys_mr(&iwpd
->ibpd
,
3713 IB_ACCESS_LOCAL_WRITE
,
3716 i40iw_free_dma_mem(dev
->hw
, &iwqp
->ietf_mem
);
3720 ibmr
->pd
= &iwpd
->ibpd
;
3721 ibmr
->device
= iwpd
->ibpd
.device
;
3722 iwqp
->lsmm_mr
= ibmr
;
3724 iwqp
->sc_qp
.qp_uk
.sq_base
= kmap(iwqp
->page
);
3725 dev
->iw_priv_qp_ops
->qp_send_lsmm(&iwqp
->sc_qp
,
3727 (accept
.size
+ conn_param
->private_data_len
),
3732 iwqp
->sc_qp
.qp_uk
.sq_base
= kmap(iwqp
->page
);
3733 dev
->iw_priv_qp_ops
->qp_send_lsmm(&iwqp
->sc_qp
, NULL
, 0, 0);
3739 iwqp
->cm_id
= cm_id
;
3740 cm_node
->cm_id
= cm_id
;
3742 cm_id
->provider_data
= (void *)iwqp
;
3743 iwqp
->active_conn
= 0;
3745 cm_node
->lsmm_size
= accept
.size
+ conn_param
->private_data_len
;
3746 i40iw_cm_init_tsa_conn(iwqp
, cm_node
);
3747 cm_id
->add_ref(cm_id
);
3748 i40iw_qp_add_ref(&iwqp
->ibqp
);
3750 attr
.qp_state
= IB_QPS_RTS
;
3751 cm_node
->qhash_set
= false;
3752 i40iw_modify_qp(&iwqp
->ibqp
, &attr
, IB_QP_STATE
, NULL
);
3754 cm_node
->accelerated
= true;
3755 spin_lock_irqsave(&cm_core
->ht_lock
, flags
);
3756 list_move_tail(&cm_node
->list
, &cm_core
->accelerated_list
);
3757 spin_unlock_irqrestore(&cm_core
->ht_lock
, flags
);
3760 i40iw_send_cm_event(cm_node
, cm_id
, IW_CM_EVENT_ESTABLISHED
, 0);
3762 i40iw_debug(dev
, I40IW_DEBUG_CM
, "error sending cm event - ESTABLISHED\n");
3764 if (cm_node
->loopbackpartner
) {
3765 cm_node
->loopbackpartner
->pdata
.size
= conn_param
->private_data_len
;
3767 /* copy entire MPA frame to our cm_node's frame */
3768 memcpy(cm_node
->loopbackpartner
->pdata_buf
,
3769 conn_param
->private_data
,
3770 conn_param
->private_data_len
);
3771 i40iw_create_event(cm_node
->loopbackpartner
, I40IW_CM_EVENT_CONNECTED
);
3774 if (cm_node
->accept_pend
) {
3775 atomic_dec(&cm_node
->listener
->pend_accepts_cnt
);
3776 cm_node
->accept_pend
= 0;
3782 * i40iw_reject - registered call for connection to be rejected
3783 * @cm_id: cm information for passive connection
3784 * @pdata: private data to be sent
3785 * @pdata_len: private data length
3787 int i40iw_reject(struct iw_cm_id
*cm_id
, const void *pdata
, u8 pdata_len
)
3789 struct i40iw_device
*iwdev
;
3790 struct i40iw_cm_node
*cm_node
;
3791 struct i40iw_cm_node
*loopback
;
3793 cm_node
= (struct i40iw_cm_node
*)cm_id
->provider_data
;
3794 loopback
= cm_node
->loopbackpartner
;
3795 cm_node
->cm_id
= cm_id
;
3796 cm_node
->pdata
.size
= pdata_len
;
3798 iwdev
= to_iwdev(cm_id
->device
);
3801 cm_node
->cm_core
->stats_rejects
++;
3803 if (pdata_len
+ sizeof(struct ietf_mpa_v2
) > MAX_CM_BUFFER
)
3807 memcpy(&loopback
->pdata_buf
, pdata
, pdata_len
);
3808 loopback
->pdata
.size
= pdata_len
;
3811 return i40iw_cm_reject(cm_node
, pdata
, pdata_len
);
3815 * i40iw_connect - registered call for connection to be established
3816 * @cm_id: cm information for passive connection
3817 * @conn_param: Information about the connection
3819 int i40iw_connect(struct iw_cm_id
*cm_id
, struct iw_cm_conn_param
*conn_param
)
3822 struct i40iw_qp
*iwqp
;
3823 struct i40iw_device
*iwdev
;
3824 struct i40iw_cm_node
*cm_node
;
3825 struct i40iw_cm_info cm_info
;
3826 struct sockaddr_in
*laddr
;
3827 struct sockaddr_in
*raddr
;
3828 struct sockaddr_in6
*laddr6
;
3829 struct sockaddr_in6
*raddr6
;
3832 ibqp
= i40iw_get_qp(cm_id
->device
, conn_param
->qpn
);
3835 iwqp
= to_iwqp(ibqp
);
3838 iwdev
= to_iwdev(iwqp
->ibqp
.device
);
3842 laddr
= (struct sockaddr_in
*)&cm_id
->m_local_addr
;
3843 raddr
= (struct sockaddr_in
*)&cm_id
->m_remote_addr
;
3844 laddr6
= (struct sockaddr_in6
*)&cm_id
->m_local_addr
;
3845 raddr6
= (struct sockaddr_in6
*)&cm_id
->m_remote_addr
;
3847 if (!(laddr
->sin_port
) || !(raddr
->sin_port
))
3850 iwqp
->active_conn
= 1;
3852 cm_id
->provider_data
= iwqp
;
3854 /* set up the connection params for the node */
3855 if (cm_id
->remote_addr
.ss_family
== AF_INET
) {
3856 cm_info
.ipv4
= true;
3857 memset(cm_info
.loc_addr
, 0, sizeof(cm_info
.loc_addr
));
3858 memset(cm_info
.rem_addr
, 0, sizeof(cm_info
.rem_addr
));
3859 cm_info
.loc_addr
[0] = ntohl(laddr
->sin_addr
.s_addr
);
3860 cm_info
.rem_addr
[0] = ntohl(raddr
->sin_addr
.s_addr
);
3861 cm_info
.loc_port
= ntohs(laddr
->sin_port
);
3862 cm_info
.rem_port
= ntohs(raddr
->sin_port
);
3863 cm_info
.vlan_id
= i40iw_get_vlan_ipv4(cm_info
.loc_addr
);
3865 cm_info
.ipv4
= false;
3866 i40iw_copy_ip_ntohl(cm_info
.loc_addr
,
3867 laddr6
->sin6_addr
.in6_u
.u6_addr32
);
3868 i40iw_copy_ip_ntohl(cm_info
.rem_addr
,
3869 raddr6
->sin6_addr
.in6_u
.u6_addr32
);
3870 cm_info
.loc_port
= ntohs(laddr6
->sin6_port
);
3871 cm_info
.rem_port
= ntohs(raddr6
->sin6_port
);
3872 i40iw_netdev_vlan_ipv6(cm_info
.loc_addr
, &cm_info
.vlan_id
);
3874 cm_info
.cm_id
= cm_id
;
3875 cm_info
.tos
= cm_id
->tos
;
3876 cm_info
.user_pri
= rt_tos2priority(cm_id
->tos
);
3877 i40iw_debug(&iwdev
->sc_dev
, I40IW_DEBUG_DCB
, "%s TOS:[%d] UP:[%d]\n",
3878 __func__
, cm_id
->tos
, cm_info
.user_pri
);
3879 cm_id
->add_ref(cm_id
);
3880 cm_node
= i40iw_create_cm_node(&iwdev
->cm_core
, iwdev
,
3881 conn_param
, &cm_info
);
3883 if (IS_ERR(cm_node
)) {
3884 ret
= PTR_ERR(cm_node
);
3885 cm_id
->rem_ref(cm_id
);
3889 if ((cm_info
.ipv4
&& (laddr
->sin_addr
.s_addr
!= raddr
->sin_addr
.s_addr
)) ||
3890 (!cm_info
.ipv4
&& memcmp(laddr6
->sin6_addr
.in6_u
.u6_addr32
,
3891 raddr6
->sin6_addr
.in6_u
.u6_addr32
,
3892 sizeof(laddr6
->sin6_addr
.in6_u
.u6_addr32
)))) {
3893 if (i40iw_manage_qhash(iwdev
, &cm_info
, I40IW_QHASH_TYPE_TCP_ESTABLISHED
,
3894 I40IW_QHASH_MANAGE_TYPE_ADD
, NULL
, true)) {
3898 cm_node
->qhash_set
= true;
3901 if (i40iw_manage_apbvt(iwdev
, cm_info
.loc_port
,
3902 I40IW_MANAGE_APBVT_ADD
)) {
3907 cm_node
->apbvt_set
= true;
3908 iwqp
->cm_node
= cm_node
;
3909 cm_node
->iwqp
= iwqp
;
3910 iwqp
->cm_id
= cm_id
;
3911 i40iw_qp_add_ref(&iwqp
->ibqp
);
3913 if (cm_node
->state
!= I40IW_CM_STATE_OFFLOADED
) {
3914 cm_node
->state
= I40IW_CM_STATE_SYN_SENT
;
3915 ret
= i40iw_send_syn(cm_node
, 0);
3920 if (cm_node
->loopbackpartner
) {
3921 cm_node
->loopbackpartner
->state
= I40IW_CM_STATE_MPAREQ_RCVD
;
3922 i40iw_create_event(cm_node
->loopbackpartner
,
3923 I40IW_CM_EVENT_MPA_REQ
);
3926 i40iw_debug(cm_node
->dev
,
3928 "Api - connect(): port=0x%04x, cm_node=%p, cm_id = %p.\n",
3937 i40iw_debug(&iwdev
->sc_dev
,
3939 "Api - connect() FAILED: dest addr=%pI4",
3942 i40iw_debug(&iwdev
->sc_dev
,
3944 "Api - connect() FAILED: dest addr=%pI6",
3947 i40iw_rem_ref_cm_node(cm_node
);
3948 cm_id
->rem_ref(cm_id
);
3949 iwdev
->cm_core
.stats_connect_errs
++;
3954 * i40iw_create_listen - registered call creating listener
3955 * @cm_id: cm information for passive connection
3956 * @backlog: to max accept pending count
3958 int i40iw_create_listen(struct iw_cm_id
*cm_id
, int backlog
)
3960 struct i40iw_device
*iwdev
;
3961 struct i40iw_cm_listener
*cm_listen_node
;
3962 struct i40iw_cm_info cm_info
;
3963 enum i40iw_status_code ret
;
3964 struct sockaddr_in
*laddr
;
3965 struct sockaddr_in6
*laddr6
;
3966 bool wildcard
= false;
3968 iwdev
= to_iwdev(cm_id
->device
);
3972 laddr
= (struct sockaddr_in
*)&cm_id
->m_local_addr
;
3973 laddr6
= (struct sockaddr_in6
*)&cm_id
->m_local_addr
;
3974 memset(&cm_info
, 0, sizeof(cm_info
));
3975 if (laddr
->sin_family
== AF_INET
) {
3976 cm_info
.ipv4
= true;
3977 cm_info
.loc_addr
[0] = ntohl(laddr
->sin_addr
.s_addr
);
3978 cm_info
.loc_port
= ntohs(laddr
->sin_port
);
3980 if (laddr
->sin_addr
.s_addr
!= INADDR_ANY
)
3981 cm_info
.vlan_id
= i40iw_get_vlan_ipv4(cm_info
.loc_addr
);
3986 cm_info
.ipv4
= false;
3987 i40iw_copy_ip_ntohl(cm_info
.loc_addr
,
3988 laddr6
->sin6_addr
.in6_u
.u6_addr32
);
3989 cm_info
.loc_port
= ntohs(laddr6
->sin6_port
);
3990 if (ipv6_addr_type(&laddr6
->sin6_addr
) != IPV6_ADDR_ANY
)
3991 i40iw_netdev_vlan_ipv6(cm_info
.loc_addr
,
3996 cm_info
.backlog
= backlog
;
3997 cm_info
.cm_id
= cm_id
;
3999 cm_listen_node
= i40iw_make_listen_node(&iwdev
->cm_core
, iwdev
, &cm_info
);
4000 if (!cm_listen_node
) {
4001 i40iw_pr_err("cm_listen_node == NULL\n");
4005 cm_id
->provider_data
= cm_listen_node
;
4007 cm_listen_node
->tos
= cm_id
->tos
;
4008 cm_listen_node
->user_pri
= rt_tos2priority(cm_id
->tos
);
4009 cm_info
.user_pri
= cm_listen_node
->user_pri
;
4011 if (!cm_listen_node
->reused_node
) {
4014 ret
= i40iw_add_mqh_4(iwdev
,
4018 ret
= i40iw_add_mqh_6(iwdev
,
4024 ret
= i40iw_manage_apbvt(iwdev
,
4026 I40IW_MANAGE_APBVT_ADD
);
4031 ret
= i40iw_manage_qhash(iwdev
,
4033 I40IW_QHASH_TYPE_TCP_SYN
,
4034 I40IW_QHASH_MANAGE_TYPE_ADD
,
4039 cm_listen_node
->qhash_set
= true;
4040 ret
= i40iw_manage_apbvt(iwdev
,
4042 I40IW_MANAGE_APBVT_ADD
);
4047 cm_id
->add_ref(cm_id
);
4048 cm_listen_node
->cm_core
->stats_listen_created
++;
4051 i40iw_cm_del_listen(&iwdev
->cm_core
, (void *)cm_listen_node
, false);
4056 * i40iw_destroy_listen - registered call to destroy listener
4057 * @cm_id: cm information for passive connection
4059 int i40iw_destroy_listen(struct iw_cm_id
*cm_id
)
4061 struct i40iw_device
*iwdev
;
4063 iwdev
= to_iwdev(cm_id
->device
);
4064 if (cm_id
->provider_data
)
4065 i40iw_cm_del_listen(&iwdev
->cm_core
, cm_id
->provider_data
, true);
4067 i40iw_pr_err("cm_id->provider_data was NULL\n");
4069 cm_id
->rem_ref(cm_id
);
4075 * i40iw_cm_event_connected - handle connected active node
4076 * @event: the info for cm_node of connection
4078 static void i40iw_cm_event_connected(struct i40iw_cm_event
*event
)
4080 struct i40iw_qp
*iwqp
;
4081 struct i40iw_device
*iwdev
;
4082 struct i40iw_cm_core
*cm_core
;
4083 struct i40iw_cm_node
*cm_node
;
4084 struct i40iw_sc_dev
*dev
;
4085 struct ib_qp_attr attr
;
4086 struct iw_cm_id
*cm_id
;
4087 unsigned long flags
;
4091 cm_node
= event
->cm_node
;
4092 cm_id
= cm_node
->cm_id
;
4093 iwqp
= (struct i40iw_qp
*)cm_id
->provider_data
;
4094 iwdev
= to_iwdev(iwqp
->ibqp
.device
);
4095 dev
= &iwdev
->sc_dev
;
4096 cm_core
= &iwdev
->cm_core
;
4098 if (iwqp
->destroyed
) {
4099 status
= -ETIMEDOUT
;
4102 i40iw_cm_init_tsa_conn(iwqp
, cm_node
);
4103 read0
= (cm_node
->send_rdma0_op
== SEND_RDMA_READ_ZERO
);
4105 iwqp
->sc_qp
.qp_uk
.sq_base
= kmap(iwqp
->page
);
4106 dev
->iw_priv_qp_ops
->qp_send_rtt(&iwqp
->sc_qp
, read0
);
4110 memset(&attr
, 0, sizeof(attr
));
4111 attr
.qp_state
= IB_QPS_RTS
;
4112 cm_node
->qhash_set
= false;
4113 i40iw_modify_qp(&iwqp
->ibqp
, &attr
, IB_QP_STATE
, NULL
);
4115 cm_node
->accelerated
= true;
4116 spin_lock_irqsave(&cm_core
->ht_lock
, flags
);
4117 list_move_tail(&cm_node
->list
, &cm_core
->accelerated_list
);
4118 spin_unlock_irqrestore(&cm_core
->ht_lock
, flags
);
4119 status
= i40iw_send_cm_event(cm_node
, cm_id
, IW_CM_EVENT_CONNECT_REPLY
,
4122 i40iw_debug(dev
, I40IW_DEBUG_CM
, "error sending cm event - CONNECT_REPLY\n");
4128 cm_id
->provider_data
= NULL
;
4129 i40iw_send_cm_event(event
->cm_node
,
4131 IW_CM_EVENT_CONNECT_REPLY
,
4133 cm_id
->rem_ref(cm_id
);
4134 i40iw_rem_ref_cm_node(event
->cm_node
);
4138 * i40iw_cm_event_reset - handle reset
4139 * @event: the info for cm_node of connection
4141 static void i40iw_cm_event_reset(struct i40iw_cm_event
*event
)
4143 struct i40iw_cm_node
*cm_node
= event
->cm_node
;
4144 struct iw_cm_id
*cm_id
= cm_node
->cm_id
;
4145 struct i40iw_qp
*iwqp
;
4150 iwqp
= cm_id
->provider_data
;
4154 i40iw_debug(cm_node
->dev
,
4156 "reset event %p - cm_id = %p\n",
4157 event
->cm_node
, cm_id
);
4160 i40iw_send_cm_event(cm_node
, cm_node
->cm_id
, IW_CM_EVENT_DISCONNECT
, -ECONNRESET
);
4161 i40iw_send_cm_event(cm_node
, cm_node
->cm_id
, IW_CM_EVENT_CLOSE
, 0);
4165 * i40iw_cm_event_handler - worker thread callback to send event to cm upper layer
4166 * @work: pointer of cm event info.
4168 static void i40iw_cm_event_handler(struct work_struct
*work
)
4170 struct i40iw_cm_event
*event
= container_of(work
,
4171 struct i40iw_cm_event
,
4173 struct i40iw_cm_node
*cm_node
;
4175 if (!event
|| !event
->cm_node
|| !event
->cm_node
->cm_core
)
4178 cm_node
= event
->cm_node
;
4180 switch (event
->type
) {
4181 case I40IW_CM_EVENT_MPA_REQ
:
4182 i40iw_send_cm_event(cm_node
,
4184 IW_CM_EVENT_CONNECT_REQUEST
,
4187 case I40IW_CM_EVENT_RESET
:
4188 i40iw_cm_event_reset(event
);
4190 case I40IW_CM_EVENT_CONNECTED
:
4191 if (!event
->cm_node
->cm_id
||
4192 (event
->cm_node
->state
!= I40IW_CM_STATE_OFFLOADED
))
4194 i40iw_cm_event_connected(event
);
4196 case I40IW_CM_EVENT_MPA_REJECT
:
4197 if (!event
->cm_node
->cm_id
||
4198 (cm_node
->state
== I40IW_CM_STATE_OFFLOADED
))
4200 i40iw_send_cm_event(cm_node
,
4202 IW_CM_EVENT_CONNECT_REPLY
,
4205 case I40IW_CM_EVENT_ABORTED
:
4206 if (!event
->cm_node
->cm_id
||
4207 (event
->cm_node
->state
== I40IW_CM_STATE_OFFLOADED
))
4209 i40iw_event_connect_error(event
);
4212 i40iw_pr_err("event type = %d\n", event
->type
);
4216 event
->cm_info
.cm_id
->rem_ref(event
->cm_info
.cm_id
);
4217 i40iw_rem_ref_cm_node(event
->cm_node
);
4222 * i40iw_cm_post_event - queue event request for worker thread
4223 * @event: cm node's info for up event call
4225 static void i40iw_cm_post_event(struct i40iw_cm_event
*event
)
4227 atomic_inc(&event
->cm_node
->ref_count
);
4228 event
->cm_info
.cm_id
->add_ref(event
->cm_info
.cm_id
);
4229 INIT_WORK(&event
->event_work
, i40iw_cm_event_handler
);
4231 queue_work(event
->cm_node
->cm_core
->event_wq
, &event
->event_work
);
4235 * i40iw_qhash_ctrl - enable/disable qhash for list
4236 * @iwdev: device pointer
4237 * @parent_listen_node: parent listen node
4238 * @nfo: cm info node
4239 * @ipaddr: Pointer to IPv4 or IPv6 address
4240 * @ipv4: flag indicating IPv4 when true
4241 * @ifup: flag indicating interface up when true
4243 * Enables or disables the qhash for the node in the child
4244 * listen list that matches ipaddr. If no matching IP was found
4245 * it will allocate and add a new child listen node to the
4246 * parent listen node. The listen_list_lock is assumed to be
4249 static void i40iw_qhash_ctrl(struct i40iw_device
*iwdev
,
4250 struct i40iw_cm_listener
*parent_listen_node
,
4251 struct i40iw_cm_info
*nfo
,
4252 u32
*ipaddr
, bool ipv4
, bool ifup
)
4254 struct list_head
*child_listen_list
= &parent_listen_node
->child_listen_list
;
4255 struct i40iw_cm_listener
*child_listen_node
;
4256 struct list_head
*pos
, *tpos
;
4257 enum i40iw_status_code ret
;
4258 bool node_allocated
= false;
4259 enum i40iw_quad_hash_manage_type op
=
4260 ifup
? I40IW_QHASH_MANAGE_TYPE_ADD
: I40IW_QHASH_MANAGE_TYPE_DELETE
;
4262 list_for_each_safe(pos
, tpos
, child_listen_list
) {
4265 struct i40iw_cm_listener
,
4267 if (!memcmp(child_listen_node
->loc_addr
, ipaddr
, ipv4
? 4 : 16))
4271 /* if not found then add a child listener if interface is going up */
4274 child_listen_node
= kmemdup(parent_listen_node
,
4275 sizeof(*child_listen_node
), GFP_ATOMIC
);
4276 if (!child_listen_node
)
4278 node_allocated
= true;
4280 memcpy(child_listen_node
->loc_addr
, ipaddr
, ipv4
? 4 : 16);
4283 memcpy(nfo
->loc_addr
,
4284 child_listen_node
->loc_addr
,
4285 sizeof(nfo
->loc_addr
));
4286 nfo
->vlan_id
= child_listen_node
->vlan_id
;
4287 ret
= i40iw_manage_qhash(iwdev
, nfo
,
4288 I40IW_QHASH_TYPE_TCP_SYN
,
4292 child_listen_node
->qhash_set
= ifup
;
4294 list_add(&child_listen_node
->child_listen_list
,
4295 &parent_listen_node
->child_listen_list
);
4296 } else if (node_allocated
) {
4297 kfree(child_listen_node
);
4302 * i40iw_cm_teardown_connections - teardown QPs
4303 * @iwdev: device pointer
4304 * @ipaddr: Pointer to IPv4 or IPv6 address
4305 * @ipv4: flag indicating IPv4 when true
4306 * @disconnect_all: flag indicating disconnect all QPs
4307 * teardown QPs where source or destination addr matches ip addr
4309 void i40iw_cm_teardown_connections(struct i40iw_device
*iwdev
, u32
*ipaddr
,
4310 struct i40iw_cm_info
*nfo
,
4311 bool disconnect_all
)
4313 struct i40iw_cm_core
*cm_core
= &iwdev
->cm_core
;
4314 struct list_head
*list_core_temp
;
4315 struct list_head
*list_node
;
4316 struct i40iw_cm_node
*cm_node
;
4317 unsigned long flags
;
4318 struct list_head teardown_list
;
4319 struct ib_qp_attr attr
;
4321 INIT_LIST_HEAD(&teardown_list
);
4322 spin_lock_irqsave(&cm_core
->ht_lock
, flags
);
4323 list_for_each_safe(list_node
, list_core_temp
,
4324 &cm_core
->accelerated_list
) {
4325 cm_node
= container_of(list_node
, struct i40iw_cm_node
, list
);
4326 if (disconnect_all
||
4327 (nfo
->vlan_id
== cm_node
->vlan_id
&&
4328 (!memcmp(cm_node
->loc_addr
, ipaddr
, nfo
->ipv4
? 4 : 16) ||
4329 !memcmp(cm_node
->rem_addr
, ipaddr
, nfo
->ipv4
? 4 : 16)))) {
4330 atomic_inc(&cm_node
->ref_count
);
4331 list_add(&cm_node
->teardown_entry
, &teardown_list
);
4334 list_for_each_safe(list_node
, list_core_temp
,
4335 &cm_core
->non_accelerated_list
) {
4336 cm_node
= container_of(list_node
, struct i40iw_cm_node
, list
);
4337 if (disconnect_all
||
4338 (nfo
->vlan_id
== cm_node
->vlan_id
&&
4339 (!memcmp(cm_node
->loc_addr
, ipaddr
, nfo
->ipv4
? 4 : 16) ||
4340 !memcmp(cm_node
->rem_addr
, ipaddr
, nfo
->ipv4
? 4 : 16)))) {
4341 atomic_inc(&cm_node
->ref_count
);
4342 list_add(&cm_node
->teardown_entry
, &teardown_list
);
4345 spin_unlock_irqrestore(&cm_core
->ht_lock
, flags
);
4347 list_for_each_safe(list_node
, list_core_temp
, &teardown_list
) {
4348 cm_node
= container_of(list_node
, struct i40iw_cm_node
,
4350 attr
.qp_state
= IB_QPS_ERR
;
4351 i40iw_modify_qp(&cm_node
->iwqp
->ibqp
, &attr
, IB_QP_STATE
, NULL
);
4353 i40iw_cm_disconn(cm_node
->iwqp
);
4354 i40iw_rem_ref_cm_node(cm_node
);
4359 * i40iw_ifdown_notify - process an ifdown on an interface
4360 * @iwdev: device pointer
4361 * @ipaddr: Pointer to IPv4 or IPv6 address
4362 * @ipv4: flag indicating IPv4 when true
4363 * @ifup: flag indicating interface up when true
4365 void i40iw_if_notify(struct i40iw_device
*iwdev
, struct net_device
*netdev
,
4366 u32
*ipaddr
, bool ipv4
, bool ifup
)
4368 struct i40iw_cm_core
*cm_core
= &iwdev
->cm_core
;
4369 unsigned long flags
;
4370 struct i40iw_cm_listener
*listen_node
;
4371 static const u32 ip_zero
[4] = { 0, 0, 0, 0 };
4372 struct i40iw_cm_info nfo
;
4373 u16 vlan_id
= rdma_vlan_dev_vlan_id(netdev
);
4374 enum i40iw_status_code ret
;
4375 enum i40iw_quad_hash_manage_type op
=
4376 ifup
? I40IW_QHASH_MANAGE_TYPE_ADD
: I40IW_QHASH_MANAGE_TYPE_DELETE
;
4378 nfo
.vlan_id
= vlan_id
;
4381 /* Disable or enable qhash for listeners */
4382 spin_lock_irqsave(&cm_core
->listen_list_lock
, flags
);
4383 list_for_each_entry(listen_node
, &cm_core
->listen_nodes
, list
) {
4384 if (vlan_id
== listen_node
->vlan_id
&&
4385 (!memcmp(listen_node
->loc_addr
, ipaddr
, ipv4
? 4 : 16) ||
4386 !memcmp(listen_node
->loc_addr
, ip_zero
, ipv4
? 4 : 16))) {
4387 memcpy(nfo
.loc_addr
, listen_node
->loc_addr
,
4388 sizeof(nfo
.loc_addr
));
4389 nfo
.loc_port
= listen_node
->loc_port
;
4390 nfo
.user_pri
= listen_node
->user_pri
;
4391 if (!list_empty(&listen_node
->child_listen_list
)) {
4392 i40iw_qhash_ctrl(iwdev
,
4395 ipaddr
, ipv4
, ifup
);
4396 } else if (memcmp(listen_node
->loc_addr
, ip_zero
,
4398 ret
= i40iw_manage_qhash(iwdev
,
4400 I40IW_QHASH_TYPE_TCP_SYN
,
4405 listen_node
->qhash_set
= ifup
;
4409 spin_unlock_irqrestore(&cm_core
->listen_list_lock
, flags
);
4411 /* teardown connected qp's on ifdown */
4413 i40iw_cm_teardown_connections(iwdev
, ipaddr
, &nfo
, false);