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>
61 #include <asm/checksum.h>
65 static void i40iw_rem_ref_cm_node(struct i40iw_cm_node
*);
66 static void i40iw_cm_post_event(struct i40iw_cm_event
*event
);
67 static void i40iw_disconnect_worker(struct work_struct
*work
);
70 * i40iw_free_sqbuf - put back puda buffer if refcount = 0
71 * @vsi: pointer to vsi structure
72 * @buf: puda buffer to free
74 void i40iw_free_sqbuf(struct i40iw_sc_vsi
*vsi
, void *bufp
)
76 struct i40iw_puda_buf
*buf
= (struct i40iw_puda_buf
*)bufp
;
77 struct i40iw_puda_rsrc
*ilq
= vsi
->ilq
;
79 if (!atomic_dec_return(&buf
->refcount
))
80 i40iw_puda_ret_bufpool(ilq
, buf
);
84 * i40iw_derive_hw_ird_setting - Calculate IRD
86 * @cm_ird: IRD of connection's node
88 * The ird from the connection is rounded to a supported HW
89 * setting (2,8,32,64) and then encoded for ird_size field of
92 static u8
i40iw_derive_hw_ird_setting(u16 cm_ird
)
97 /* round-off to next powerof2 */
98 while (pof2_cm_ird
< cm_ird
)
101 /* ird_size field is encoded in qp_ctx */
102 switch (pof2_cm_ird
) {
103 case I40IW_HW_IRD_SETTING_64
:
104 encoded_ird_size
= 3;
106 case I40IW_HW_IRD_SETTING_32
:
107 case I40IW_HW_IRD_SETTING_16
:
108 encoded_ird_size
= 2;
110 case I40IW_HW_IRD_SETTING_8
:
111 case I40IW_HW_IRD_SETTING_4
:
112 encoded_ird_size
= 1;
114 case I40IW_HW_IRD_SETTING_2
:
116 encoded_ird_size
= 0;
119 return encoded_ird_size
;
123 * i40iw_record_ird_ord - Record IRD/ORD passed in
124 * @cm_node: connection's node
125 * @conn_ird: connection IRD
126 * @conn_ord: connection ORD
128 static void i40iw_record_ird_ord(struct i40iw_cm_node
*cm_node
, u16 conn_ird
, u16 conn_ord
)
130 if (conn_ird
> I40IW_MAX_IRD_SIZE
)
131 conn_ird
= I40IW_MAX_IRD_SIZE
;
133 if (conn_ord
> I40IW_MAX_ORD_SIZE
)
134 conn_ord
= I40IW_MAX_ORD_SIZE
;
136 cm_node
->ird_size
= conn_ird
;
137 cm_node
->ord_size
= conn_ord
;
141 * i40iw_copy_ip_ntohl - change network to host ip
145 void i40iw_copy_ip_ntohl(u32
*dst
, __be32
*src
)
147 *dst
++ = ntohl(*src
++);
148 *dst
++ = ntohl(*src
++);
149 *dst
++ = ntohl(*src
++);
154 * i40iw_copy_ip_htonl - change host addr to network ip
156 * @src: little endian
158 static inline void i40iw_copy_ip_htonl(__be32
*dst
, u32
*src
)
160 *dst
++ = htonl(*src
++);
161 *dst
++ = htonl(*src
++);
162 *dst
++ = htonl(*src
++);
167 * i40iw_fill_sockaddr4 - get addr info for passive connection
168 * @cm_node: connection's node
169 * @event: upper layer's cm event
171 static inline void i40iw_fill_sockaddr4(struct i40iw_cm_node
*cm_node
,
172 struct iw_cm_event
*event
)
174 struct sockaddr_in
*laddr
= (struct sockaddr_in
*)&event
->local_addr
;
175 struct sockaddr_in
*raddr
= (struct sockaddr_in
*)&event
->remote_addr
;
177 laddr
->sin_family
= AF_INET
;
178 raddr
->sin_family
= AF_INET
;
180 laddr
->sin_port
= htons(cm_node
->loc_port
);
181 raddr
->sin_port
= htons(cm_node
->rem_port
);
183 laddr
->sin_addr
.s_addr
= htonl(cm_node
->loc_addr
[0]);
184 raddr
->sin_addr
.s_addr
= htonl(cm_node
->rem_addr
[0]);
188 * i40iw_fill_sockaddr6 - get ipv6 addr info for passive side
189 * @cm_node: connection's node
190 * @event: upper layer's cm event
192 static inline void i40iw_fill_sockaddr6(struct i40iw_cm_node
*cm_node
,
193 struct iw_cm_event
*event
)
195 struct sockaddr_in6
*laddr6
= (struct sockaddr_in6
*)&event
->local_addr
;
196 struct sockaddr_in6
*raddr6
= (struct sockaddr_in6
*)&event
->remote_addr
;
198 laddr6
->sin6_family
= AF_INET6
;
199 raddr6
->sin6_family
= AF_INET6
;
201 laddr6
->sin6_port
= htons(cm_node
->loc_port
);
202 raddr6
->sin6_port
= htons(cm_node
->rem_port
);
204 i40iw_copy_ip_htonl(laddr6
->sin6_addr
.in6_u
.u6_addr32
,
206 i40iw_copy_ip_htonl(raddr6
->sin6_addr
.in6_u
.u6_addr32
,
211 * i40iw_get_addr_info
212 * @cm_node: contains ip/tcp info
213 * @cm_info: to get a copy of the cm_node ip/tcp info
215 static void i40iw_get_addr_info(struct i40iw_cm_node
*cm_node
,
216 struct i40iw_cm_info
*cm_info
)
218 cm_info
->ipv4
= cm_node
->ipv4
;
219 cm_info
->vlan_id
= cm_node
->vlan_id
;
220 memcpy(cm_info
->loc_addr
, cm_node
->loc_addr
, sizeof(cm_info
->loc_addr
));
221 memcpy(cm_info
->rem_addr
, cm_node
->rem_addr
, sizeof(cm_info
->rem_addr
));
222 cm_info
->loc_port
= cm_node
->loc_port
;
223 cm_info
->rem_port
= cm_node
->rem_port
;
224 cm_info
->user_pri
= cm_node
->user_pri
;
228 * i40iw_get_cmevent_info - for cm event upcall
229 * @cm_node: connection's node
230 * @cm_id: upper layers cm struct for the event
231 * @event: upper layer's cm event
233 static inline void i40iw_get_cmevent_info(struct i40iw_cm_node
*cm_node
,
234 struct iw_cm_id
*cm_id
,
235 struct iw_cm_event
*event
)
237 memcpy(&event
->local_addr
, &cm_id
->m_local_addr
,
238 sizeof(event
->local_addr
));
239 memcpy(&event
->remote_addr
, &cm_id
->m_remote_addr
,
240 sizeof(event
->remote_addr
));
242 event
->private_data
= (void *)cm_node
->pdata_buf
;
243 event
->private_data_len
= (u8
)cm_node
->pdata
.size
;
244 event
->ird
= cm_node
->ird_size
;
245 event
->ord
= cm_node
->ord_size
;
250 * i40iw_send_cm_event - upcall cm's event handler
251 * @cm_node: connection's node
252 * @cm_id: upper layer's cm info struct
253 * @type: Event type to indicate
254 * @status: status for the event type
256 static int i40iw_send_cm_event(struct i40iw_cm_node
*cm_node
,
257 struct iw_cm_id
*cm_id
,
258 enum iw_cm_event_type type
,
261 struct iw_cm_event event
;
263 memset(&event
, 0, sizeof(event
));
265 event
.status
= status
;
267 case IW_CM_EVENT_CONNECT_REQUEST
:
269 i40iw_fill_sockaddr4(cm_node
, &event
);
271 i40iw_fill_sockaddr6(cm_node
, &event
);
272 event
.provider_data
= (void *)cm_node
;
273 event
.private_data
= (void *)cm_node
->pdata_buf
;
274 event
.private_data_len
= (u8
)cm_node
->pdata
.size
;
275 event
.ird
= cm_node
->ird_size
;
277 case IW_CM_EVENT_CONNECT_REPLY
:
278 i40iw_get_cmevent_info(cm_node
, cm_id
, &event
);
280 case IW_CM_EVENT_ESTABLISHED
:
281 event
.ird
= cm_node
->ird_size
;
282 event
.ord
= cm_node
->ord_size
;
284 case IW_CM_EVENT_DISCONNECT
:
286 case IW_CM_EVENT_CLOSE
:
289 i40iw_pr_err("event type received type = %d\n", type
);
292 return cm_id
->event_handler(cm_id
, &event
);
296 * i40iw_create_event - create cm event
297 * @cm_node: connection's node
298 * @type: Event type to generate
300 static struct i40iw_cm_event
*i40iw_create_event(struct i40iw_cm_node
*cm_node
,
301 enum i40iw_cm_event_type type
)
303 struct i40iw_cm_event
*event
;
308 event
= kzalloc(sizeof(*event
), GFP_ATOMIC
);
314 event
->cm_node
= cm_node
;
315 memcpy(event
->cm_info
.rem_addr
, cm_node
->rem_addr
, sizeof(event
->cm_info
.rem_addr
));
316 memcpy(event
->cm_info
.loc_addr
, cm_node
->loc_addr
, sizeof(event
->cm_info
.loc_addr
));
317 event
->cm_info
.rem_port
= cm_node
->rem_port
;
318 event
->cm_info
.loc_port
= cm_node
->loc_port
;
319 event
->cm_info
.cm_id
= cm_node
->cm_id
;
321 i40iw_debug(cm_node
->dev
,
323 "node=%p event=%p type=%u dst=%pI4 src=%pI4\n",
327 event
->cm_info
.loc_addr
,
328 event
->cm_info
.rem_addr
);
330 i40iw_cm_post_event(event
);
335 * i40iw_free_retrans_entry - free send entry
336 * @cm_node: connection's node
338 static void i40iw_free_retrans_entry(struct i40iw_cm_node
*cm_node
)
340 struct i40iw_device
*iwdev
= cm_node
->iwdev
;
341 struct i40iw_timer_entry
*send_entry
;
343 send_entry
= cm_node
->send_entry
;
345 cm_node
->send_entry
= NULL
;
346 i40iw_free_sqbuf(&iwdev
->vsi
, (void *)send_entry
->sqbuf
);
348 atomic_dec(&cm_node
->ref_count
);
353 * i40iw_cleanup_retrans_entry - free send entry with lock
354 * @cm_node: connection's node
356 static void i40iw_cleanup_retrans_entry(struct i40iw_cm_node
*cm_node
)
360 spin_lock_irqsave(&cm_node
->retrans_list_lock
, flags
);
361 i40iw_free_retrans_entry(cm_node
);
362 spin_unlock_irqrestore(&cm_node
->retrans_list_lock
, flags
);
366 * i40iw_form_cm_frame - get a free packet and build frame
367 * @cm_node: connection's node ionfo to use in frame
368 * @options: pointer to options info
369 * @hdr: pointer mpa header
370 * @pdata: pointer to private data
371 * @flags: indicates FIN or ACK
373 static struct i40iw_puda_buf
*i40iw_form_cm_frame(struct i40iw_cm_node
*cm_node
,
374 struct i40iw_kmem_info
*options
,
375 struct i40iw_kmem_info
*hdr
,
376 struct i40iw_kmem_info
*pdata
,
379 struct i40iw_puda_buf
*sqbuf
;
380 struct i40iw_sc_vsi
*vsi
= &cm_node
->iwdev
->vsi
;
385 struct ipv6hdr
*ip6h
;
388 u16 eth_hlen
= ETH_HLEN
;
394 sqbuf
= i40iw_puda_get_bufpool(vsi
->ilq
);
400 opts_len
= (u32
)options
->size
;
406 pd_len
= pdata
->size
;
408 if (cm_node
->vlan_id
< VLAN_TAG_PRESENT
)
412 packetsize
= sizeof(*iph
) + sizeof(*tcph
);
414 packetsize
= sizeof(*ip6h
) + sizeof(*tcph
);
415 packetsize
+= opts_len
+ hdr_len
+ pd_len
;
417 memset(buf
, 0x00, eth_hlen
+ packetsize
);
419 sqbuf
->totallen
= packetsize
+ eth_hlen
;
420 sqbuf
->maclen
= eth_hlen
;
421 sqbuf
->tcphlen
= sizeof(*tcph
) + opts_len
;
422 sqbuf
->scratch
= (void *)cm_node
;
424 ethh
= (struct ethhdr
*)buf
;
430 iph
= (struct iphdr
*)buf
;
432 tcph
= (struct tcphdr
*)buf
;
433 buf
+= sizeof(*tcph
);
435 ether_addr_copy(ethh
->h_dest
, cm_node
->rem_mac
);
436 ether_addr_copy(ethh
->h_source
, cm_node
->loc_mac
);
437 if (cm_node
->vlan_id
< VLAN_TAG_PRESENT
) {
438 ((struct vlan_ethhdr
*)ethh
)->h_vlan_proto
= htons(ETH_P_8021Q
);
439 vtag
= (cm_node
->user_pri
<< VLAN_PRIO_SHIFT
) | cm_node
->vlan_id
;
440 ((struct vlan_ethhdr
*)ethh
)->h_vlan_TCI
= htons(vtag
);
442 ((struct vlan_ethhdr
*)ethh
)->h_vlan_encapsulated_proto
= htons(ETH_P_IP
);
444 ethh
->h_proto
= htons(ETH_P_IP
);
447 iph
->version
= IPVERSION
;
448 iph
->ihl
= 5; /* 5 * 4Byte words, IP headr len */
449 iph
->tos
= cm_node
->tos
;
450 iph
->tot_len
= htons(packetsize
);
451 iph
->id
= htons(++cm_node
->tcp_cntxt
.loc_id
);
453 iph
->frag_off
= htons(0x4000);
455 iph
->protocol
= IPPROTO_TCP
;
456 iph
->saddr
= htonl(cm_node
->loc_addr
[0]);
457 iph
->daddr
= htonl(cm_node
->rem_addr
[0]);
460 ip6h
= (struct ipv6hdr
*)buf
;
461 buf
+= sizeof(*ip6h
);
462 tcph
= (struct tcphdr
*)buf
;
463 buf
+= sizeof(*tcph
);
465 ether_addr_copy(ethh
->h_dest
, cm_node
->rem_mac
);
466 ether_addr_copy(ethh
->h_source
, cm_node
->loc_mac
);
467 if (cm_node
->vlan_id
< VLAN_TAG_PRESENT
) {
468 ((struct vlan_ethhdr
*)ethh
)->h_vlan_proto
= htons(ETH_P_8021Q
);
469 vtag
= (cm_node
->user_pri
<< VLAN_PRIO_SHIFT
) | cm_node
->vlan_id
;
470 ((struct vlan_ethhdr
*)ethh
)->h_vlan_TCI
= htons(vtag
);
471 ((struct vlan_ethhdr
*)ethh
)->h_vlan_encapsulated_proto
= htons(ETH_P_IPV6
);
473 ethh
->h_proto
= htons(ETH_P_IPV6
);
476 ip6h
->priority
= cm_node
->tos
>> 4;
477 ip6h
->flow_lbl
[0] = cm_node
->tos
<< 4;
478 ip6h
->flow_lbl
[1] = 0;
479 ip6h
->flow_lbl
[2] = 0;
480 ip6h
->payload_len
= htons(packetsize
- sizeof(*ip6h
));
482 ip6h
->hop_limit
= 128;
483 i40iw_copy_ip_htonl(ip6h
->saddr
.in6_u
.u6_addr32
,
485 i40iw_copy_ip_htonl(ip6h
->daddr
.in6_u
.u6_addr32
,
489 tcph
->source
= htons(cm_node
->loc_port
);
490 tcph
->dest
= htons(cm_node
->rem_port
);
492 tcph
->seq
= htonl(cm_node
->tcp_cntxt
.loc_seq_num
);
494 if (flags
& SET_ACK
) {
495 cm_node
->tcp_cntxt
.loc_ack_num
= cm_node
->tcp_cntxt
.rcv_nxt
;
496 tcph
->ack_seq
= htonl(cm_node
->tcp_cntxt
.loc_ack_num
);
502 if (flags
& SET_SYN
) {
503 cm_node
->tcp_cntxt
.loc_seq_num
++;
506 cm_node
->tcp_cntxt
.loc_seq_num
+= hdr_len
+ pd_len
;
509 if (flags
& SET_FIN
) {
510 cm_node
->tcp_cntxt
.loc_seq_num
++;
517 tcph
->doff
= (u16
)((sizeof(*tcph
) + opts_len
+ 3) >> 2);
518 sqbuf
->tcphlen
= tcph
->doff
<< 2;
519 tcph
->window
= htons(cm_node
->tcp_cntxt
.rcv_wnd
);
523 memcpy(buf
, options
->addr
, opts_len
);
528 memcpy(buf
, hdr
->addr
, hdr_len
);
532 if (pdata
&& pdata
->addr
)
533 memcpy(buf
, pdata
->addr
, pdata
->size
);
535 atomic_set(&sqbuf
->refcount
, 1);
541 * i40iw_send_reset - Send RST packet
542 * @cm_node: connection's node
544 static int i40iw_send_reset(struct i40iw_cm_node
*cm_node
)
546 struct i40iw_puda_buf
*sqbuf
;
547 int flags
= SET_RST
| SET_ACK
;
549 sqbuf
= i40iw_form_cm_frame(cm_node
, NULL
, NULL
, NULL
, flags
);
551 i40iw_pr_err("no sqbuf\n");
555 return i40iw_schedule_cm_timer(cm_node
, sqbuf
, I40IW_TIMER_TYPE_SEND
, 0, 1);
559 * i40iw_active_open_err - send event for active side cm error
560 * @cm_node: connection's node
561 * @reset: Flag to send reset or not
563 static void i40iw_active_open_err(struct i40iw_cm_node
*cm_node
, bool reset
)
565 i40iw_cleanup_retrans_entry(cm_node
);
566 cm_node
->cm_core
->stats_connect_errs
++;
568 i40iw_debug(cm_node
->dev
,
570 "%s cm_node=%p state=%d\n",
574 atomic_inc(&cm_node
->ref_count
);
575 i40iw_send_reset(cm_node
);
578 cm_node
->state
= I40IW_CM_STATE_CLOSED
;
579 i40iw_create_event(cm_node
, I40IW_CM_EVENT_ABORTED
);
583 * i40iw_passive_open_err - handle passive side cm error
584 * @cm_node: connection's node
585 * @reset: send reset or just free cm_node
587 static void i40iw_passive_open_err(struct i40iw_cm_node
*cm_node
, bool reset
)
589 i40iw_cleanup_retrans_entry(cm_node
);
590 cm_node
->cm_core
->stats_passive_errs
++;
591 cm_node
->state
= I40IW_CM_STATE_CLOSED
;
592 i40iw_debug(cm_node
->dev
,
594 "%s cm_node=%p state =%d\n",
599 i40iw_send_reset(cm_node
);
601 i40iw_rem_ref_cm_node(cm_node
);
605 * i40iw_event_connect_error - to create connect error event
606 * @event: cm information for connect event
608 static void i40iw_event_connect_error(struct i40iw_cm_event
*event
)
610 struct i40iw_qp
*iwqp
;
611 struct iw_cm_id
*cm_id
;
613 cm_id
= event
->cm_node
->cm_id
;
617 iwqp
= cm_id
->provider_data
;
619 if (!iwqp
|| !iwqp
->iwdev
)
623 cm_id
->provider_data
= NULL
;
624 i40iw_send_cm_event(event
->cm_node
, cm_id
,
625 IW_CM_EVENT_CONNECT_REPLY
,
627 cm_id
->rem_ref(cm_id
);
628 i40iw_rem_ref_cm_node(event
->cm_node
);
632 * i40iw_process_options
633 * @cm_node: connection's node
634 * @optionsloc: point to start of options
635 * @optionsize: size of all options
636 * @syn_packet: flag if syn packet
638 static int i40iw_process_options(struct i40iw_cm_node
*cm_node
,
645 union all_known_options
*all_options
;
646 char got_mss_option
= 0;
648 while (offset
< optionsize
) {
649 all_options
= (union all_known_options
*)(optionsloc
+ offset
);
650 switch (all_options
->as_base
.optionnum
) {
651 case OPTION_NUMBER_END
:
654 case OPTION_NUMBER_NONE
:
657 case OPTION_NUMBER_MSS
:
658 i40iw_debug(cm_node
->dev
,
660 "%s: MSS Length: %d Offset: %d Size: %d\n",
662 all_options
->as_mss
.length
,
666 if (all_options
->as_mss
.length
!= 4)
668 tmp
= ntohs(all_options
->as_mss
.mss
);
669 if (tmp
> 0 && tmp
< cm_node
->tcp_cntxt
.mss
)
670 cm_node
->tcp_cntxt
.mss
= tmp
;
672 case OPTION_NUMBER_WINDOW_SCALE
:
673 cm_node
->tcp_cntxt
.snd_wscale
=
674 all_options
->as_windowscale
.shiftcount
;
677 i40iw_debug(cm_node
->dev
,
679 "TCP Option not understood: %x\n",
680 all_options
->as_base
.optionnum
);
683 offset
+= all_options
->as_base
.length
;
685 if (!got_mss_option
&& syn_packet
)
686 cm_node
->tcp_cntxt
.mss
= I40IW_CM_DEFAULT_MSS
;
691 * i40iw_handle_tcp_options -
692 * @cm_node: connection's node
693 * @tcph: pointer tcp header
694 * @optionsize: size of options rcvd
695 * @passive: active or passive flag
697 static int i40iw_handle_tcp_options(struct i40iw_cm_node
*cm_node
,
702 u8
*optionsloc
= (u8
*)&tcph
[1];
705 if (i40iw_process_options(cm_node
,
709 i40iw_debug(cm_node
->dev
,
711 "%s: Node %p, Sending RESET\n",
715 i40iw_passive_open_err(cm_node
, true);
717 i40iw_active_open_err(cm_node
, true);
722 cm_node
->tcp_cntxt
.snd_wnd
= ntohs(tcph
->window
) <<
723 cm_node
->tcp_cntxt
.snd_wscale
;
725 if (cm_node
->tcp_cntxt
.snd_wnd
> cm_node
->tcp_cntxt
.max_snd_wnd
)
726 cm_node
->tcp_cntxt
.max_snd_wnd
= cm_node
->tcp_cntxt
.snd_wnd
;
731 * i40iw_build_mpa_v1 - build a MPA V1 frame
732 * @cm_node: connection's node
733 * @mpa_key: to do read0 or write0
735 static void i40iw_build_mpa_v1(struct i40iw_cm_node
*cm_node
,
739 struct ietf_mpa_v1
*mpa_frame
= (struct ietf_mpa_v1
*)start_addr
;
742 case MPA_KEY_REQUEST
:
743 memcpy(mpa_frame
->key
, IEFT_MPA_KEY_REQ
, IETF_MPA_KEY_SIZE
);
746 memcpy(mpa_frame
->key
, IEFT_MPA_KEY_REP
, IETF_MPA_KEY_SIZE
);
751 mpa_frame
->flags
= IETF_MPA_FLAGS_CRC
;
752 mpa_frame
->rev
= cm_node
->mpa_frame_rev
;
753 mpa_frame
->priv_data_len
= htons(cm_node
->pdata
.size
);
757 * i40iw_build_mpa_v2 - build a MPA V2 frame
758 * @cm_node: connection's node
759 * @start_addr: buffer start address
760 * @mpa_key: to do read0 or write0
762 static void i40iw_build_mpa_v2(struct i40iw_cm_node
*cm_node
,
766 struct ietf_mpa_v2
*mpa_frame
= (struct ietf_mpa_v2
*)start_addr
;
767 struct ietf_rtr_msg
*rtr_msg
= &mpa_frame
->rtr_msg
;
768 u16 ctrl_ird
, ctrl_ord
;
770 /* initialize the upper 5 bytes of the frame */
771 i40iw_build_mpa_v1(cm_node
, start_addr
, mpa_key
);
772 mpa_frame
->flags
|= IETF_MPA_V2_FLAG
;
773 mpa_frame
->priv_data_len
+= htons(IETF_RTR_MSG_SIZE
);
775 /* initialize RTR msg */
776 if (cm_node
->mpav2_ird_ord
== IETF_NO_IRD_ORD
) {
777 ctrl_ird
= IETF_NO_IRD_ORD
;
778 ctrl_ord
= IETF_NO_IRD_ORD
;
780 ctrl_ird
= (cm_node
->ird_size
> IETF_NO_IRD_ORD
) ?
781 IETF_NO_IRD_ORD
: cm_node
->ird_size
;
782 ctrl_ord
= (cm_node
->ord_size
> IETF_NO_IRD_ORD
) ?
783 IETF_NO_IRD_ORD
: cm_node
->ord_size
;
786 ctrl_ird
|= IETF_PEER_TO_PEER
;
789 case MPA_KEY_REQUEST
:
790 ctrl_ord
|= IETF_RDMA0_WRITE
;
791 ctrl_ord
|= IETF_RDMA0_READ
;
794 switch (cm_node
->send_rdma0_op
) {
795 case SEND_RDMA_WRITE_ZERO
:
796 ctrl_ord
|= IETF_RDMA0_WRITE
;
798 case SEND_RDMA_READ_ZERO
:
799 ctrl_ord
|= IETF_RDMA0_READ
;
806 rtr_msg
->ctrl_ird
= htons(ctrl_ird
);
807 rtr_msg
->ctrl_ord
= htons(ctrl_ord
);
811 * i40iw_cm_build_mpa_frame - build mpa frame for mpa version 1 or version 2
812 * @cm_node: connection's node
813 * @mpa: mpa: data buffer
814 * @mpa_key: to do read0 or write0
816 static int i40iw_cm_build_mpa_frame(struct i40iw_cm_node
*cm_node
,
817 struct i40iw_kmem_info
*mpa
,
822 switch (cm_node
->mpa_frame_rev
) {
824 hdr_len
= sizeof(struct ietf_mpa_v1
);
825 i40iw_build_mpa_v1(cm_node
, mpa
->addr
, mpa_key
);
828 hdr_len
= sizeof(struct ietf_mpa_v2
);
829 i40iw_build_mpa_v2(cm_node
, mpa
->addr
, mpa_key
);
839 * i40iw_send_mpa_request - active node send mpa request to passive node
840 * @cm_node: connection's node
842 static int i40iw_send_mpa_request(struct i40iw_cm_node
*cm_node
)
844 struct i40iw_puda_buf
*sqbuf
;
847 i40iw_pr_err("cm_node == NULL\n");
851 cm_node
->mpa_hdr
.addr
= &cm_node
->mpa_frame
;
852 cm_node
->mpa_hdr
.size
= i40iw_cm_build_mpa_frame(cm_node
,
855 if (!cm_node
->mpa_hdr
.size
) {
856 i40iw_pr_err("mpa size = %d\n", cm_node
->mpa_hdr
.size
);
860 sqbuf
= i40iw_form_cm_frame(cm_node
,
866 i40iw_pr_err("sq_buf == NULL\n");
869 return i40iw_schedule_cm_timer(cm_node
, sqbuf
, I40IW_TIMER_TYPE_SEND
, 1, 0);
873 * i40iw_send_mpa_reject -
874 * @cm_node: connection's node
875 * @pdata: reject data for connection
876 * @plen: length of reject data
878 static int i40iw_send_mpa_reject(struct i40iw_cm_node
*cm_node
,
882 struct i40iw_puda_buf
*sqbuf
;
883 struct i40iw_kmem_info priv_info
;
885 cm_node
->mpa_hdr
.addr
= &cm_node
->mpa_frame
;
886 cm_node
->mpa_hdr
.size
= i40iw_cm_build_mpa_frame(cm_node
,
890 cm_node
->mpa_frame
.flags
|= IETF_MPA_FLAGS_REJECT
;
891 priv_info
.addr
= (void *)pdata
;
892 priv_info
.size
= plen
;
894 sqbuf
= i40iw_form_cm_frame(cm_node
,
900 i40iw_pr_err("no sqbuf\n");
903 cm_node
->state
= I40IW_CM_STATE_FIN_WAIT1
;
904 return i40iw_schedule_cm_timer(cm_node
, sqbuf
, I40IW_TIMER_TYPE_SEND
, 1, 0);
908 * recv_mpa - process an IETF MPA frame
909 * @cm_node: connection's node
910 * @buffer: Data pointer
911 * @type: to return accept or reject
912 * @len: Len of mpa buffer
914 static int i40iw_parse_mpa(struct i40iw_cm_node
*cm_node
, u8
*buffer
, u32
*type
, u32 len
)
916 struct ietf_mpa_v1
*mpa_frame
;
917 struct ietf_mpa_v2
*mpa_v2_frame
;
918 struct ietf_rtr_msg
*rtr_msg
;
922 *type
= I40IW_MPA_REQUEST_ACCEPT
;
924 if (len
< sizeof(struct ietf_mpa_v1
)) {
925 i40iw_pr_err("ietf buffer small (%x)\n", len
);
929 mpa_frame
= (struct ietf_mpa_v1
*)buffer
;
930 mpa_hdr_len
= sizeof(struct ietf_mpa_v1
);
931 priv_data_len
= ntohs(mpa_frame
->priv_data_len
);
933 if (priv_data_len
> IETF_MAX_PRIV_DATA_LEN
) {
934 i40iw_pr_err("large pri_data %d\n", priv_data_len
);
937 if (mpa_frame
->rev
!= IETF_MPA_V1
&& mpa_frame
->rev
!= IETF_MPA_V2
) {
938 i40iw_pr_err("unsupported mpa rev = %d\n", mpa_frame
->rev
);
941 if (mpa_frame
->rev
> cm_node
->mpa_frame_rev
) {
942 i40iw_pr_err("rev %d\n", mpa_frame
->rev
);
945 cm_node
->mpa_frame_rev
= mpa_frame
->rev
;
947 if (cm_node
->state
!= I40IW_CM_STATE_MPAREQ_SENT
) {
948 if (memcmp(mpa_frame
->key
, IEFT_MPA_KEY_REQ
, IETF_MPA_KEY_SIZE
)) {
949 i40iw_pr_err("Unexpected MPA Key received\n");
953 if (memcmp(mpa_frame
->key
, IEFT_MPA_KEY_REP
, IETF_MPA_KEY_SIZE
)) {
954 i40iw_pr_err("Unexpected MPA Key received\n");
959 if (priv_data_len
+ mpa_hdr_len
> len
) {
960 i40iw_pr_err("ietf buffer len(%x + %x != %x)\n",
961 priv_data_len
, mpa_hdr_len
, len
);
964 if (len
> MAX_CM_BUFFER
) {
965 i40iw_pr_err("ietf buffer large len = %d\n", len
);
969 switch (mpa_frame
->rev
) {
976 mpa_v2_frame
= (struct ietf_mpa_v2
*)buffer
;
977 mpa_hdr_len
+= IETF_RTR_MSG_SIZE
;
978 rtr_msg
= &mpa_v2_frame
->rtr_msg
;
980 /* parse rtr message */
981 ctrl_ord
= ntohs(rtr_msg
->ctrl_ord
);
982 ctrl_ird
= ntohs(rtr_msg
->ctrl_ird
);
983 ird_size
= ctrl_ird
& IETF_NO_IRD_ORD
;
984 ord_size
= ctrl_ord
& IETF_NO_IRD_ORD
;
986 if (!(ctrl_ird
& IETF_PEER_TO_PEER
))
989 if (ird_size
== IETF_NO_IRD_ORD
|| ord_size
== IETF_NO_IRD_ORD
) {
990 cm_node
->mpav2_ird_ord
= IETF_NO_IRD_ORD
;
994 if (cm_node
->state
!= I40IW_CM_STATE_MPAREQ_SENT
) {
996 if (!ord_size
&& (ctrl_ord
& IETF_RDMA0_READ
))
997 cm_node
->ird_size
= 1;
998 if (cm_node
->ord_size
> ird_size
)
999 cm_node
->ord_size
= ird_size
;
1002 if (!ird_size
&& (ctrl_ord
& IETF_RDMA0_READ
))
1004 if (cm_node
->ord_size
> ird_size
)
1005 cm_node
->ord_size
= ird_size
;
1007 if (cm_node
->ird_size
< ord_size
)
1008 /* no resources available */
1013 if (ctrl_ord
& IETF_RDMA0_READ
)
1014 cm_node
->send_rdma0_op
= SEND_RDMA_READ_ZERO
;
1015 else if (ctrl_ord
& IETF_RDMA0_WRITE
)
1016 cm_node
->send_rdma0_op
= SEND_RDMA_WRITE_ZERO
;
1017 else /* Not supported RDMA0 operation */
1019 i40iw_debug(cm_node
->dev
, I40IW_DEBUG_CM
,
1020 "MPAV2: Negotiated ORD: %d, IRD: %d\n",
1021 cm_node
->ord_size
, cm_node
->ird_size
);
1030 memcpy(cm_node
->pdata_buf
, buffer
+ mpa_hdr_len
, priv_data_len
);
1031 cm_node
->pdata
.size
= priv_data_len
;
1033 if (mpa_frame
->flags
& IETF_MPA_FLAGS_REJECT
)
1034 *type
= I40IW_MPA_REQUEST_REJECT
;
1036 if (mpa_frame
->flags
& IETF_MPA_FLAGS_MARKERS
)
1037 cm_node
->snd_mark_en
= true;
1043 * i40iw_schedule_cm_timer
1044 * @@cm_node: connection's node
1045 * @sqbuf: buffer to send
1046 * @type: if it is send or close
1047 * @send_retrans: if rexmits to be done
1048 * @close_when_complete: is cm_node to be removed
1050 * note - cm_node needs to be protected before calling this. Encase in:
1051 * i40iw_rem_ref_cm_node(cm_core, cm_node);
1052 * i40iw_schedule_cm_timer(...)
1053 * atomic_inc(&cm_node->ref_count);
1055 int i40iw_schedule_cm_timer(struct i40iw_cm_node
*cm_node
,
1056 struct i40iw_puda_buf
*sqbuf
,
1057 enum i40iw_timer_type type
,
1059 int close_when_complete
)
1061 struct i40iw_sc_vsi
*vsi
= &cm_node
->iwdev
->vsi
;
1062 struct i40iw_cm_core
*cm_core
= cm_node
->cm_core
;
1063 struct i40iw_timer_entry
*new_send
;
1066 unsigned long flags
;
1068 new_send
= kzalloc(sizeof(*new_send
), GFP_ATOMIC
);
1070 if (type
!= I40IW_TIMER_TYPE_CLOSE
)
1071 i40iw_free_sqbuf(vsi
, (void *)sqbuf
);
1074 new_send
->retrycount
= I40IW_DEFAULT_RETRYS
;
1075 new_send
->retranscount
= I40IW_DEFAULT_RETRANS
;
1076 new_send
->sqbuf
= sqbuf
;
1077 new_send
->timetosend
= jiffies
;
1078 new_send
->type
= type
;
1079 new_send
->send_retrans
= send_retrans
;
1080 new_send
->close_when_complete
= close_when_complete
;
1082 if (type
== I40IW_TIMER_TYPE_CLOSE
) {
1083 new_send
->timetosend
+= (HZ
/ 10);
1084 if (cm_node
->close_entry
) {
1086 i40iw_pr_err("already close entry\n");
1089 cm_node
->close_entry
= new_send
;
1092 if (type
== I40IW_TIMER_TYPE_SEND
) {
1093 spin_lock_irqsave(&cm_node
->retrans_list_lock
, flags
);
1094 cm_node
->send_entry
= new_send
;
1095 atomic_inc(&cm_node
->ref_count
);
1096 spin_unlock_irqrestore(&cm_node
->retrans_list_lock
, flags
);
1097 new_send
->timetosend
= jiffies
+ I40IW_RETRY_TIMEOUT
;
1099 atomic_inc(&sqbuf
->refcount
);
1100 i40iw_puda_send_buf(vsi
->ilq
, sqbuf
);
1101 if (!send_retrans
) {
1102 i40iw_cleanup_retrans_entry(cm_node
);
1103 if (close_when_complete
)
1104 i40iw_rem_ref_cm_node(cm_node
);
1109 spin_lock_irqsave(&cm_core
->ht_lock
, flags
);
1110 was_timer_set
= timer_pending(&cm_core
->tcp_timer
);
1112 if (!was_timer_set
) {
1113 cm_core
->tcp_timer
.expires
= new_send
->timetosend
;
1114 add_timer(&cm_core
->tcp_timer
);
1116 spin_unlock_irqrestore(&cm_core
->ht_lock
, flags
);
1122 * i40iw_retrans_expired - Could not rexmit the packet
1123 * @cm_node: connection's node
1125 static void i40iw_retrans_expired(struct i40iw_cm_node
*cm_node
)
1127 struct iw_cm_id
*cm_id
= cm_node
->cm_id
;
1128 enum i40iw_cm_node_state state
= cm_node
->state
;
1130 cm_node
->state
= I40IW_CM_STATE_CLOSED
;
1132 case I40IW_CM_STATE_SYN_RCVD
:
1133 case I40IW_CM_STATE_CLOSING
:
1134 i40iw_rem_ref_cm_node(cm_node
);
1136 case I40IW_CM_STATE_FIN_WAIT1
:
1137 case I40IW_CM_STATE_LAST_ACK
:
1139 cm_id
->rem_ref(cm_id
);
1140 i40iw_send_reset(cm_node
);
1143 atomic_inc(&cm_node
->ref_count
);
1144 i40iw_send_reset(cm_node
);
1145 i40iw_create_event(cm_node
, I40IW_CM_EVENT_ABORTED
);
1151 * i40iw_handle_close_entry - for handling retry/timeouts
1152 * @cm_node: connection's node
1153 * @rem_node: flag for remove cm_node
1155 static void i40iw_handle_close_entry(struct i40iw_cm_node
*cm_node
, u32 rem_node
)
1157 struct i40iw_timer_entry
*close_entry
= cm_node
->close_entry
;
1158 struct iw_cm_id
*cm_id
= cm_node
->cm_id
;
1159 struct i40iw_qp
*iwqp
;
1160 unsigned long flags
;
1164 iwqp
= (struct i40iw_qp
*)close_entry
->sqbuf
;
1166 spin_lock_irqsave(&iwqp
->lock
, flags
);
1168 iwqp
->hw_tcp_state
= I40IW_TCP_STATE_CLOSED
;
1169 iwqp
->hw_iwarp_state
= I40IW_QP_STATE_ERROR
;
1170 iwqp
->last_aeq
= I40IW_AE_RESET_SENT
;
1171 iwqp
->ibqp_state
= IB_QPS_ERR
;
1172 spin_unlock_irqrestore(&iwqp
->lock
, flags
);
1173 i40iw_cm_disconn(iwqp
);
1175 spin_unlock_irqrestore(&iwqp
->lock
, flags
);
1177 } else if (rem_node
) {
1178 /* TIME_WAIT state */
1179 i40iw_rem_ref_cm_node(cm_node
);
1182 cm_id
->rem_ref(cm_id
);
1184 cm_node
->close_entry
= NULL
;
1188 * i40iw_cm_timer_tick - system's timer expired callback
1189 * @pass: Pointing to cm_core
1191 static void i40iw_cm_timer_tick(struct timer_list
*t
)
1193 unsigned long nexttimeout
= jiffies
+ I40IW_LONG_TIME
;
1194 struct i40iw_cm_node
*cm_node
;
1195 struct i40iw_timer_entry
*send_entry
, *close_entry
;
1196 struct list_head
*list_core_temp
;
1197 struct i40iw_sc_vsi
*vsi
;
1198 struct list_head
*list_node
;
1199 struct i40iw_cm_core
*cm_core
= from_timer(cm_core
, t
, tcp_timer
);
1201 unsigned long timetosend
;
1202 unsigned long flags
;
1204 struct list_head timer_list
;
1206 INIT_LIST_HEAD(&timer_list
);
1207 spin_lock_irqsave(&cm_core
->ht_lock
, flags
);
1209 list_for_each_safe(list_node
, list_core_temp
, &cm_core
->connected_nodes
) {
1210 cm_node
= container_of(list_node
, struct i40iw_cm_node
, list
);
1211 if (cm_node
->close_entry
|| cm_node
->send_entry
) {
1212 atomic_inc(&cm_node
->ref_count
);
1213 list_add(&cm_node
->timer_entry
, &timer_list
);
1216 spin_unlock_irqrestore(&cm_core
->ht_lock
, flags
);
1218 list_for_each_safe(list_node
, list_core_temp
, &timer_list
) {
1219 cm_node
= container_of(list_node
,
1220 struct i40iw_cm_node
,
1222 close_entry
= cm_node
->close_entry
;
1225 if (time_after(close_entry
->timetosend
, jiffies
)) {
1226 if (nexttimeout
> close_entry
->timetosend
||
1228 nexttimeout
= close_entry
->timetosend
;
1232 i40iw_handle_close_entry(cm_node
, 1);
1236 spin_lock_irqsave(&cm_node
->retrans_list_lock
, flags
);
1238 send_entry
= cm_node
->send_entry
;
1241 if (time_after(send_entry
->timetosend
, jiffies
)) {
1242 if (cm_node
->state
!= I40IW_CM_STATE_OFFLOADED
) {
1243 if ((nexttimeout
> send_entry
->timetosend
) ||
1245 nexttimeout
= send_entry
->timetosend
;
1249 i40iw_free_retrans_entry(cm_node
);
1254 if ((cm_node
->state
== I40IW_CM_STATE_OFFLOADED
) ||
1255 (cm_node
->state
== I40IW_CM_STATE_CLOSED
)) {
1256 i40iw_free_retrans_entry(cm_node
);
1260 if (!send_entry
->retranscount
|| !send_entry
->retrycount
) {
1261 i40iw_free_retrans_entry(cm_node
);
1263 spin_unlock_irqrestore(&cm_node
->retrans_list_lock
, flags
);
1264 i40iw_retrans_expired(cm_node
);
1265 cm_node
->state
= I40IW_CM_STATE_CLOSED
;
1266 spin_lock_irqsave(&cm_node
->retrans_list_lock
, flags
);
1269 spin_unlock_irqrestore(&cm_node
->retrans_list_lock
, flags
);
1271 vsi
= &cm_node
->iwdev
->vsi
;
1273 if (!cm_node
->ack_rcvd
) {
1274 atomic_inc(&send_entry
->sqbuf
->refcount
);
1275 i40iw_puda_send_buf(vsi
->ilq
, send_entry
->sqbuf
);
1276 cm_node
->cm_core
->stats_pkt_retrans
++;
1278 spin_lock_irqsave(&cm_node
->retrans_list_lock
, flags
);
1279 if (send_entry
->send_retrans
) {
1280 send_entry
->retranscount
--;
1281 timetosend
= (I40IW_RETRY_TIMEOUT
<<
1282 (I40IW_DEFAULT_RETRANS
-
1283 send_entry
->retranscount
));
1285 send_entry
->timetosend
= jiffies
+
1286 min(timetosend
, I40IW_MAX_TIMEOUT
);
1287 if (nexttimeout
> send_entry
->timetosend
|| !settimer
) {
1288 nexttimeout
= send_entry
->timetosend
;
1292 int close_when_complete
;
1294 close_when_complete
= send_entry
->close_when_complete
;
1295 i40iw_debug(cm_node
->dev
,
1297 "cm_node=%p state=%d\n",
1300 i40iw_free_retrans_entry(cm_node
);
1301 if (close_when_complete
)
1302 i40iw_rem_ref_cm_node(cm_node
);
1305 spin_unlock_irqrestore(&cm_node
->retrans_list_lock
, flags
);
1306 i40iw_rem_ref_cm_node(cm_node
);
1310 spin_lock_irqsave(&cm_core
->ht_lock
, flags
);
1311 if (!timer_pending(&cm_core
->tcp_timer
)) {
1312 cm_core
->tcp_timer
.expires
= nexttimeout
;
1313 add_timer(&cm_core
->tcp_timer
);
1315 spin_unlock_irqrestore(&cm_core
->ht_lock
, flags
);
1320 * i40iw_send_syn - send SYN packet
1321 * @cm_node: connection's node
1322 * @sendack: flag to set ACK bit or not
1324 int i40iw_send_syn(struct i40iw_cm_node
*cm_node
, u32 sendack
)
1326 struct i40iw_puda_buf
*sqbuf
;
1327 int flags
= SET_SYN
;
1328 char optionsbuffer
[sizeof(struct option_mss
) +
1329 sizeof(struct option_windowscale
) +
1330 sizeof(struct option_base
) + TCP_OPTIONS_PADDING
];
1331 struct i40iw_kmem_info opts
;
1333 int optionssize
= 0;
1334 /* Sending MSS option */
1335 union all_known_options
*options
;
1337 opts
.addr
= optionsbuffer
;
1339 i40iw_pr_err("no cm_node\n");
1343 options
= (union all_known_options
*)&optionsbuffer
[optionssize
];
1344 options
->as_mss
.optionnum
= OPTION_NUMBER_MSS
;
1345 options
->as_mss
.length
= sizeof(struct option_mss
);
1346 options
->as_mss
.mss
= htons(cm_node
->tcp_cntxt
.mss
);
1347 optionssize
+= sizeof(struct option_mss
);
1349 options
= (union all_known_options
*)&optionsbuffer
[optionssize
];
1350 options
->as_windowscale
.optionnum
= OPTION_NUMBER_WINDOW_SCALE
;
1351 options
->as_windowscale
.length
= sizeof(struct option_windowscale
);
1352 options
->as_windowscale
.shiftcount
= cm_node
->tcp_cntxt
.rcv_wscale
;
1353 optionssize
+= sizeof(struct option_windowscale
);
1354 options
= (union all_known_options
*)&optionsbuffer
[optionssize
];
1355 options
->as_end
= OPTION_NUMBER_END
;
1361 opts
.size
= optionssize
;
1363 sqbuf
= i40iw_form_cm_frame(cm_node
, &opts
, NULL
, NULL
, flags
);
1365 i40iw_pr_err("no sqbuf\n");
1368 return i40iw_schedule_cm_timer(cm_node
, sqbuf
, I40IW_TIMER_TYPE_SEND
, 1, 0);
1372 * i40iw_send_ack - Send ACK packet
1373 * @cm_node: connection's node
1375 static void i40iw_send_ack(struct i40iw_cm_node
*cm_node
)
1377 struct i40iw_puda_buf
*sqbuf
;
1378 struct i40iw_sc_vsi
*vsi
= &cm_node
->iwdev
->vsi
;
1380 sqbuf
= i40iw_form_cm_frame(cm_node
, NULL
, NULL
, NULL
, SET_ACK
);
1382 i40iw_puda_send_buf(vsi
->ilq
, sqbuf
);
1384 i40iw_pr_err("no sqbuf\n");
1388 * i40iw_send_fin - Send FIN pkt
1389 * @cm_node: connection's node
1391 static int i40iw_send_fin(struct i40iw_cm_node
*cm_node
)
1393 struct i40iw_puda_buf
*sqbuf
;
1395 sqbuf
= i40iw_form_cm_frame(cm_node
, NULL
, NULL
, NULL
, SET_ACK
| SET_FIN
);
1397 i40iw_pr_err("no sqbuf\n");
1400 return i40iw_schedule_cm_timer(cm_node
, sqbuf
, I40IW_TIMER_TYPE_SEND
, 1, 0);
1404 * i40iw_find_node - find a cm node that matches the reference cm node
1405 * @cm_core: cm's core
1406 * @rem_port: remote tcp port num
1407 * @rem_addr: remote ip addr
1408 * @loc_port: local tcp port num
1409 * @loc_addr: loc ip addr
1410 * @add_refcnt: flag to increment refcount of cm_node
1412 struct i40iw_cm_node
*i40iw_find_node(struct i40iw_cm_core
*cm_core
,
1419 struct list_head
*hte
;
1420 struct i40iw_cm_node
*cm_node
;
1421 unsigned long flags
;
1423 hte
= &cm_core
->connected_nodes
;
1425 /* walk list and find cm_node associated with this session ID */
1426 spin_lock_irqsave(&cm_core
->ht_lock
, flags
);
1427 list_for_each_entry(cm_node
, hte
, list
) {
1428 if (!memcmp(cm_node
->loc_addr
, loc_addr
, sizeof(cm_node
->loc_addr
)) &&
1429 (cm_node
->loc_port
== loc_port
) &&
1430 !memcmp(cm_node
->rem_addr
, rem_addr
, sizeof(cm_node
->rem_addr
)) &&
1431 (cm_node
->rem_port
== rem_port
)) {
1433 atomic_inc(&cm_node
->ref_count
);
1434 spin_unlock_irqrestore(&cm_core
->ht_lock
, flags
);
1438 spin_unlock_irqrestore(&cm_core
->ht_lock
, flags
);
1445 * i40iw_find_listener - find a cm node listening on this addr-port pair
1446 * @cm_core: cm's core
1447 * @dst_port: listener tcp port num
1448 * @dst_addr: listener ip addr
1449 * @listener_state: state to match with listen node's
1451 static struct i40iw_cm_listener
*i40iw_find_listener(
1452 struct i40iw_cm_core
*cm_core
,
1456 enum i40iw_cm_listener_state
1459 struct i40iw_cm_listener
*listen_node
;
1460 static const u32 ip_zero
[4] = { 0, 0, 0, 0 };
1463 unsigned long flags
;
1465 /* walk list and find cm_node associated with this session ID */
1466 spin_lock_irqsave(&cm_core
->listen_list_lock
, flags
);
1467 list_for_each_entry(listen_node
, &cm_core
->listen_nodes
, list
) {
1468 memcpy(listen_addr
, listen_node
->loc_addr
, sizeof(listen_addr
));
1469 listen_port
= listen_node
->loc_port
;
1470 /* compare node pair, return node handle if a match */
1471 if ((!memcmp(listen_addr
, dst_addr
, sizeof(listen_addr
)) ||
1472 !memcmp(listen_addr
, ip_zero
, sizeof(listen_addr
))) &&
1473 (listen_port
== dst_port
) &&
1474 (listener_state
& listen_node
->listener_state
)) {
1475 atomic_inc(&listen_node
->ref_count
);
1476 spin_unlock_irqrestore(&cm_core
->listen_list_lock
, flags
);
1480 spin_unlock_irqrestore(&cm_core
->listen_list_lock
, flags
);
1485 * i40iw_add_hte_node - add a cm node to the hash table
1486 * @cm_core: cm's core
1487 * @cm_node: connection's node
1489 static void i40iw_add_hte_node(struct i40iw_cm_core
*cm_core
,
1490 struct i40iw_cm_node
*cm_node
)
1492 struct list_head
*hte
;
1493 unsigned long flags
;
1495 if (!cm_node
|| !cm_core
) {
1496 i40iw_pr_err("cm_node or cm_core == NULL\n");
1499 spin_lock_irqsave(&cm_core
->ht_lock
, flags
);
1501 /* get a handle on the hash table element (list head for this slot) */
1502 hte
= &cm_core
->connected_nodes
;
1503 list_add_tail(&cm_node
->list
, hte
);
1504 spin_unlock_irqrestore(&cm_core
->ht_lock
, flags
);
1508 * i40iw_port_in_use - determine if port is in use
1509 * @port: port number
1510 * @active_side: flag for listener side vs active side
1512 static bool i40iw_port_in_use(struct i40iw_cm_core
*cm_core
, u16 port
, bool active_side
)
1514 struct i40iw_cm_listener
*listen_node
;
1515 struct i40iw_cm_node
*cm_node
;
1516 unsigned long flags
;
1520 /* search connected node list */
1521 spin_lock_irqsave(&cm_core
->ht_lock
, flags
);
1522 list_for_each_entry(cm_node
, &cm_core
->connected_nodes
, list
) {
1523 if (cm_node
->loc_port
== port
) {
1529 clear_bit(port
, cm_core
->active_side_ports
);
1530 spin_unlock_irqrestore(&cm_core
->ht_lock
, flags
);
1532 spin_lock_irqsave(&cm_core
->listen_list_lock
, flags
);
1533 list_for_each_entry(listen_node
, &cm_core
->listen_nodes
, list
) {
1534 if (listen_node
->loc_port
== port
) {
1539 spin_unlock_irqrestore(&cm_core
->listen_list_lock
, flags
);
1546 * i40iw_del_multiple_qhash - Remove qhash and child listens
1547 * @iwdev: iWarp device
1548 * @cm_info: CM info for parent listen node
1549 * @cm_parent_listen_node: The parent listen node
1551 static enum i40iw_status_code
i40iw_del_multiple_qhash(
1552 struct i40iw_device
*iwdev
,
1553 struct i40iw_cm_info
*cm_info
,
1554 struct i40iw_cm_listener
*cm_parent_listen_node
)
1556 struct i40iw_cm_listener
*child_listen_node
;
1557 enum i40iw_status_code ret
= I40IW_ERR_CONFIG
;
1558 struct list_head
*pos
, *tpos
;
1559 unsigned long flags
;
1561 spin_lock_irqsave(&iwdev
->cm_core
.listen_list_lock
, flags
);
1562 list_for_each_safe(pos
, tpos
, &cm_parent_listen_node
->child_listen_list
) {
1563 child_listen_node
= list_entry(pos
, struct i40iw_cm_listener
, child_listen_list
);
1564 if (child_listen_node
->ipv4
)
1565 i40iw_debug(&iwdev
->sc_dev
,
1567 "removing child listen for IP=%pI4, port=%d, vlan=%d\n",
1568 child_listen_node
->loc_addr
,
1569 child_listen_node
->loc_port
,
1570 child_listen_node
->vlan_id
);
1572 i40iw_debug(&iwdev
->sc_dev
, I40IW_DEBUG_CM
,
1573 "removing child listen for IP=%pI6, port=%d, vlan=%d\n",
1574 child_listen_node
->loc_addr
,
1575 child_listen_node
->loc_port
,
1576 child_listen_node
->vlan_id
);
1578 memcpy(cm_info
->loc_addr
, child_listen_node
->loc_addr
,
1579 sizeof(cm_info
->loc_addr
));
1580 cm_info
->vlan_id
= child_listen_node
->vlan_id
;
1581 if (child_listen_node
->qhash_set
) {
1582 ret
= i40iw_manage_qhash(iwdev
, cm_info
,
1583 I40IW_QHASH_TYPE_TCP_SYN
,
1584 I40IW_QHASH_MANAGE_TYPE_DELETE
,
1586 child_listen_node
->qhash_set
= false;
1588 ret
= I40IW_SUCCESS
;
1590 i40iw_debug(&iwdev
->sc_dev
,
1592 "freed pointer = %p\n",
1594 kfree(child_listen_node
);
1595 cm_parent_listen_node
->cm_core
->stats_listen_nodes_destroyed
++;
1597 spin_unlock_irqrestore(&iwdev
->cm_core
.listen_list_lock
, flags
);
1603 * i40iw_netdev_vlan_ipv6 - Gets the netdev and vlan
1604 * @addr: local IPv6 address
1605 * @vlan_id: vlan id for the given IPv6 address
1607 * Returns the net_device of the IPv6 address and also sets the
1608 * vlan id for that address.
1610 static struct net_device
*i40iw_netdev_vlan_ipv6(u32
*addr
, u16
*vlan_id
)
1612 struct net_device
*ip_dev
= NULL
;
1613 struct in6_addr laddr6
;
1615 if (!IS_ENABLED(CONFIG_IPV6
))
1617 i40iw_copy_ip_htonl(laddr6
.in6_u
.u6_addr32
, addr
);
1619 *vlan_id
= I40IW_NO_VLAN
;
1621 for_each_netdev_rcu(&init_net
, ip_dev
) {
1622 if (ipv6_chk_addr(&init_net
, &laddr6
, ip_dev
, 1)) {
1624 *vlan_id
= rdma_vlan_dev_vlan_id(ip_dev
);
1633 * i40iw_get_vlan_ipv4 - Returns the vlan_id for IPv4 address
1634 * @addr: local IPv4 address
1636 static u16
i40iw_get_vlan_ipv4(u32
*addr
)
1638 struct net_device
*netdev
;
1639 u16 vlan_id
= I40IW_NO_VLAN
;
1641 netdev
= ip_dev_find(&init_net
, htonl(addr
[0]));
1643 vlan_id
= rdma_vlan_dev_vlan_id(netdev
);
1650 * i40iw_add_mqh_6 - Adds multiple qhashes for IPv6
1651 * @iwdev: iWarp device
1652 * @cm_info: CM info for parent listen node
1653 * @cm_parent_listen_node: The parent listen node
1655 * Adds a qhash and a child listen node for every IPv6 address
1656 * on the adapter and adds the associated qhash filter
1658 static enum i40iw_status_code
i40iw_add_mqh_6(struct i40iw_device
*iwdev
,
1659 struct i40iw_cm_info
*cm_info
,
1660 struct i40iw_cm_listener
*cm_parent_listen_node
)
1662 struct net_device
*ip_dev
;
1663 struct inet6_dev
*idev
;
1664 struct inet6_ifaddr
*ifp
, *tmp
;
1665 enum i40iw_status_code ret
= 0;
1666 struct i40iw_cm_listener
*child_listen_node
;
1667 unsigned long flags
;
1670 for_each_netdev_rcu(&init_net
, ip_dev
) {
1671 if ((((rdma_vlan_dev_vlan_id(ip_dev
) < I40IW_NO_VLAN
) &&
1672 (rdma_vlan_dev_real_dev(ip_dev
) == iwdev
->netdev
)) ||
1673 (ip_dev
== iwdev
->netdev
)) && (ip_dev
->flags
& IFF_UP
)) {
1674 idev
= __in6_dev_get(ip_dev
);
1676 i40iw_pr_err("idev == NULL\n");
1679 list_for_each_entry_safe(ifp
, tmp
, &idev
->addr_list
, if_list
) {
1680 i40iw_debug(&iwdev
->sc_dev
,
1682 "IP=%pI6, vlan_id=%d, MAC=%pM\n",
1684 rdma_vlan_dev_vlan_id(ip_dev
),
1687 kzalloc(sizeof(*child_listen_node
), GFP_ATOMIC
);
1688 i40iw_debug(&iwdev
->sc_dev
,
1690 "Allocating child listener %p\n",
1692 if (!child_listen_node
) {
1693 ret
= I40IW_ERR_NO_MEMORY
;
1696 cm_info
->vlan_id
= rdma_vlan_dev_vlan_id(ip_dev
);
1697 cm_parent_listen_node
->vlan_id
= cm_info
->vlan_id
;
1699 memcpy(child_listen_node
, cm_parent_listen_node
,
1700 sizeof(*child_listen_node
));
1702 i40iw_copy_ip_ntohl(child_listen_node
->loc_addr
,
1703 ifp
->addr
.in6_u
.u6_addr32
);
1704 memcpy(cm_info
->loc_addr
, child_listen_node
->loc_addr
,
1705 sizeof(cm_info
->loc_addr
));
1707 ret
= i40iw_manage_qhash(iwdev
, cm_info
,
1708 I40IW_QHASH_TYPE_TCP_SYN
,
1709 I40IW_QHASH_MANAGE_TYPE_ADD
,
1712 child_listen_node
->qhash_set
= true;
1713 spin_lock_irqsave(&iwdev
->cm_core
.listen_list_lock
, flags
);
1714 list_add(&child_listen_node
->child_listen_list
,
1715 &cm_parent_listen_node
->child_listen_list
);
1716 spin_unlock_irqrestore(&iwdev
->cm_core
.listen_list_lock
, flags
);
1717 cm_parent_listen_node
->cm_core
->stats_listen_nodes_created
++;
1719 kfree(child_listen_node
);
1730 * i40iw_add_mqh_4 - Adds multiple qhashes for IPv4
1731 * @iwdev: iWarp device
1732 * @cm_info: CM info for parent listen node
1733 * @cm_parent_listen_node: The parent listen node
1735 * Adds a qhash and a child listen node for every IPv4 address
1736 * on the adapter and adds the associated qhash filter
1738 static enum i40iw_status_code
i40iw_add_mqh_4(
1739 struct i40iw_device
*iwdev
,
1740 struct i40iw_cm_info
*cm_info
,
1741 struct i40iw_cm_listener
*cm_parent_listen_node
)
1743 struct net_device
*dev
;
1744 struct in_device
*idev
;
1745 struct i40iw_cm_listener
*child_listen_node
;
1746 enum i40iw_status_code ret
= 0;
1747 unsigned long flags
;
1750 for_each_netdev(&init_net
, dev
) {
1751 if ((((rdma_vlan_dev_vlan_id(dev
) < I40IW_NO_VLAN
) &&
1752 (rdma_vlan_dev_real_dev(dev
) == iwdev
->netdev
)) ||
1753 (dev
== iwdev
->netdev
)) && (dev
->flags
& IFF_UP
)) {
1754 idev
= in_dev_get(dev
);
1756 i40iw_debug(&iwdev
->sc_dev
,
1758 "Allocating child CM Listener forIP=%pI4, vlan_id=%d, MAC=%pM\n",
1760 rdma_vlan_dev_vlan_id(dev
),
1762 child_listen_node
= kzalloc(sizeof(*child_listen_node
), GFP_ATOMIC
);
1763 cm_parent_listen_node
->cm_core
->stats_listen_nodes_created
++;
1764 i40iw_debug(&iwdev
->sc_dev
,
1766 "Allocating child listener %p\n",
1768 if (!child_listen_node
) {
1770 ret
= I40IW_ERR_NO_MEMORY
;
1773 cm_info
->vlan_id
= rdma_vlan_dev_vlan_id(dev
);
1774 cm_parent_listen_node
->vlan_id
= cm_info
->vlan_id
;
1775 memcpy(child_listen_node
,
1776 cm_parent_listen_node
,
1777 sizeof(*child_listen_node
));
1779 child_listen_node
->loc_addr
[0] = ntohl(ifa
->ifa_address
);
1780 memcpy(cm_info
->loc_addr
, child_listen_node
->loc_addr
,
1781 sizeof(cm_info
->loc_addr
));
1783 ret
= i40iw_manage_qhash(iwdev
,
1785 I40IW_QHASH_TYPE_TCP_SYN
,
1786 I40IW_QHASH_MANAGE_TYPE_ADD
,
1790 child_listen_node
->qhash_set
= true;
1791 spin_lock_irqsave(&iwdev
->cm_core
.listen_list_lock
, flags
);
1792 list_add(&child_listen_node
->child_listen_list
,
1793 &cm_parent_listen_node
->child_listen_list
);
1794 spin_unlock_irqrestore(&iwdev
->cm_core
.listen_list_lock
, flags
);
1796 kfree(child_listen_node
);
1797 cm_parent_listen_node
->cm_core
->stats_listen_nodes_created
--;
1810 * i40iw_dec_refcnt_listen - delete listener and associated cm nodes
1811 * @cm_core: cm's core
1812 * @free_hanging_nodes: to free associated cm_nodes
1813 * @apbvt_del: flag to delete the apbvt
1815 static int i40iw_dec_refcnt_listen(struct i40iw_cm_core
*cm_core
,
1816 struct i40iw_cm_listener
*listener
,
1817 int free_hanging_nodes
, bool apbvt_del
)
1821 struct list_head
*list_pos
;
1822 struct list_head
*list_temp
;
1823 struct i40iw_cm_node
*cm_node
;
1824 struct list_head reset_list
;
1825 struct i40iw_cm_info nfo
;
1826 struct i40iw_cm_node
*loopback
;
1827 enum i40iw_cm_node_state old_state
;
1828 unsigned long flags
;
1830 /* free non-accelerated child nodes for this listener */
1831 INIT_LIST_HEAD(&reset_list
);
1832 if (free_hanging_nodes
) {
1833 spin_lock_irqsave(&cm_core
->ht_lock
, flags
);
1834 list_for_each_safe(list_pos
, list_temp
, &cm_core
->connected_nodes
) {
1835 cm_node
= container_of(list_pos
, struct i40iw_cm_node
, list
);
1836 if ((cm_node
->listener
== listener
) && !cm_node
->accelerated
) {
1837 atomic_inc(&cm_node
->ref_count
);
1838 list_add(&cm_node
->reset_entry
, &reset_list
);
1841 spin_unlock_irqrestore(&cm_core
->ht_lock
, flags
);
1844 list_for_each_safe(list_pos
, list_temp
, &reset_list
) {
1845 cm_node
= container_of(list_pos
, struct i40iw_cm_node
, reset_entry
);
1846 loopback
= cm_node
->loopbackpartner
;
1847 if (cm_node
->state
>= I40IW_CM_STATE_FIN_WAIT1
) {
1848 i40iw_rem_ref_cm_node(cm_node
);
1851 i40iw_cleanup_retrans_entry(cm_node
);
1852 err
= i40iw_send_reset(cm_node
);
1854 cm_node
->state
= I40IW_CM_STATE_CLOSED
;
1855 i40iw_pr_err("send reset\n");
1857 old_state
= cm_node
->state
;
1858 cm_node
->state
= I40IW_CM_STATE_LISTENER_DESTROYED
;
1859 if (old_state
!= I40IW_CM_STATE_MPAREQ_RCVD
)
1860 i40iw_rem_ref_cm_node(cm_node
);
1863 struct i40iw_cm_event event
;
1865 event
.cm_node
= loopback
;
1866 memcpy(event
.cm_info
.rem_addr
,
1867 loopback
->rem_addr
, sizeof(event
.cm_info
.rem_addr
));
1868 memcpy(event
.cm_info
.loc_addr
,
1869 loopback
->loc_addr
, sizeof(event
.cm_info
.loc_addr
));
1870 event
.cm_info
.rem_port
= loopback
->rem_port
;
1871 event
.cm_info
.loc_port
= loopback
->loc_port
;
1872 event
.cm_info
.cm_id
= loopback
->cm_id
;
1873 event
.cm_info
.ipv4
= loopback
->ipv4
;
1874 atomic_inc(&loopback
->ref_count
);
1875 loopback
->state
= I40IW_CM_STATE_CLOSED
;
1876 i40iw_event_connect_error(&event
);
1877 cm_node
->state
= I40IW_CM_STATE_LISTENER_DESTROYED
;
1878 i40iw_rem_ref_cm_node(cm_node
);
1883 if (!atomic_dec_return(&listener
->ref_count
)) {
1884 spin_lock_irqsave(&cm_core
->listen_list_lock
, flags
);
1885 list_del(&listener
->list
);
1886 spin_unlock_irqrestore(&cm_core
->listen_list_lock
, flags
);
1888 if (listener
->iwdev
) {
1889 if (apbvt_del
&& !i40iw_port_in_use(cm_core
, listener
->loc_port
, false))
1890 i40iw_manage_apbvt(listener
->iwdev
,
1892 I40IW_MANAGE_APBVT_DEL
);
1894 memcpy(nfo
.loc_addr
, listener
->loc_addr
, sizeof(nfo
.loc_addr
));
1895 nfo
.loc_port
= listener
->loc_port
;
1896 nfo
.ipv4
= listener
->ipv4
;
1897 nfo
.vlan_id
= listener
->vlan_id
;
1898 nfo
.user_pri
= listener
->user_pri
;
1900 if (!list_empty(&listener
->child_listen_list
)) {
1901 i40iw_del_multiple_qhash(listener
->iwdev
, &nfo
, listener
);
1903 if (listener
->qhash_set
)
1904 i40iw_manage_qhash(listener
->iwdev
,
1906 I40IW_QHASH_TYPE_TCP_SYN
,
1907 I40IW_QHASH_MANAGE_TYPE_DELETE
,
1913 cm_core
->stats_listen_destroyed
++;
1915 cm_core
->stats_listen_nodes_destroyed
++;
1921 if (atomic_read(&listener
->pend_accepts_cnt
) > 0)
1922 i40iw_debug(cm_core
->dev
,
1924 "%s: listener (%p) pending accepts=%u\n",
1927 atomic_read(&listener
->pend_accepts_cnt
));
1934 * i40iw_cm_del_listen - delete a linstener
1935 * @cm_core: cm's core
1936 * @listener: passive connection's listener
1937 * @apbvt_del: flag to delete apbvt
1939 static int i40iw_cm_del_listen(struct i40iw_cm_core
*cm_core
,
1940 struct i40iw_cm_listener
*listener
,
1943 listener
->listener_state
= I40IW_CM_LISTENER_PASSIVE_STATE
;
1944 listener
->cm_id
= NULL
; /* going to be destroyed pretty soon */
1945 return i40iw_dec_refcnt_listen(cm_core
, listener
, 1, apbvt_del
);
1949 * i40iw_addr_resolve_neigh - resolve neighbor address
1950 * @iwdev: iwarp device structure
1951 * @src_ip: local ip address
1952 * @dst_ip: remote ip address
1953 * @arpindex: if there is an arp entry
1955 static int i40iw_addr_resolve_neigh(struct i40iw_device
*iwdev
,
1961 struct neighbour
*neigh
;
1963 struct net_device
*netdev
= iwdev
->netdev
;
1964 __be32 dst_ipaddr
= htonl(dst_ip
);
1965 __be32 src_ipaddr
= htonl(src_ip
);
1967 rt
= ip_route_output(&init_net
, dst_ipaddr
, src_ipaddr
, 0, 0);
1969 i40iw_pr_err("ip_route_output\n");
1973 if (netif_is_bond_slave(netdev
))
1974 netdev
= netdev_master_upper_dev_get(netdev
);
1976 neigh
= dst_neigh_lookup(&rt
->dst
, &dst_ipaddr
);
1980 if (neigh
->nud_state
& NUD_VALID
) {
1981 if (arpindex
>= 0) {
1982 if (ether_addr_equal(iwdev
->arp_table
[arpindex
].mac_addr
,
1984 /* Mac address same as arp table */
1985 goto resolve_neigh_exit
;
1986 i40iw_manage_arp_cache(iwdev
,
1987 iwdev
->arp_table
[arpindex
].mac_addr
,
1993 i40iw_manage_arp_cache(iwdev
, neigh
->ha
, &dst_ip
, true, I40IW_ARP_ADD
);
1994 rc
= i40iw_arp_table(iwdev
, &dst_ip
, true, NULL
, I40IW_ARP_RESOLVE
);
1996 neigh_event_send(neigh
, NULL
);
2003 neigh_release(neigh
);
2010 * i40iw_get_dst_ipv6
2012 static struct dst_entry
*i40iw_get_dst_ipv6(struct sockaddr_in6
*src_addr
,
2013 struct sockaddr_in6
*dst_addr
)
2015 struct dst_entry
*dst
;
2018 memset(&fl6
, 0, sizeof(fl6
));
2019 fl6
.daddr
= dst_addr
->sin6_addr
;
2020 fl6
.saddr
= src_addr
->sin6_addr
;
2021 if (ipv6_addr_type(&fl6
.daddr
) & IPV6_ADDR_LINKLOCAL
)
2022 fl6
.flowi6_oif
= dst_addr
->sin6_scope_id
;
2024 dst
= ip6_route_output(&init_net
, NULL
, &fl6
);
2029 * i40iw_addr_resolve_neigh_ipv6 - resolve neighbor ipv6 address
2030 * @iwdev: iwarp device structure
2031 * @dst_ip: remote ip address
2032 * @arpindex: if there is an arp entry
2034 static int i40iw_addr_resolve_neigh_ipv6(struct i40iw_device
*iwdev
,
2039 struct neighbour
*neigh
;
2041 struct net_device
*netdev
= iwdev
->netdev
;
2042 struct dst_entry
*dst
;
2043 struct sockaddr_in6 dst_addr
;
2044 struct sockaddr_in6 src_addr
;
2046 memset(&dst_addr
, 0, sizeof(dst_addr
));
2047 dst_addr
.sin6_family
= AF_INET6
;
2048 i40iw_copy_ip_htonl(dst_addr
.sin6_addr
.in6_u
.u6_addr32
, dest
);
2049 memset(&src_addr
, 0, sizeof(src_addr
));
2050 src_addr
.sin6_family
= AF_INET6
;
2051 i40iw_copy_ip_htonl(src_addr
.sin6_addr
.in6_u
.u6_addr32
, src
);
2052 dst
= i40iw_get_dst_ipv6(&src_addr
, &dst_addr
);
2053 if (!dst
|| dst
->error
) {
2056 i40iw_pr_err("ip6_route_output returned dst->error = %d\n",
2062 if (netif_is_bond_slave(netdev
))
2063 netdev
= netdev_master_upper_dev_get(netdev
);
2065 neigh
= dst_neigh_lookup(dst
, &dst_addr
);
2069 i40iw_debug(&iwdev
->sc_dev
, I40IW_DEBUG_CM
, "dst_neigh_lookup MAC=%pM\n", neigh
->ha
);
2070 if (neigh
->nud_state
& NUD_VALID
) {
2071 if (arpindex
>= 0) {
2072 if (ether_addr_equal
2073 (iwdev
->arp_table
[arpindex
].mac_addr
,
2075 /* Mac address same as in arp table */
2076 goto resolve_neigh_exit6
;
2078 i40iw_manage_arp_cache(iwdev
,
2079 iwdev
->arp_table
[arpindex
].mac_addr
,
2084 i40iw_manage_arp_cache(iwdev
,
2089 rc
= i40iw_arp_table(iwdev
,
2095 neigh_event_send(neigh
, NULL
);
2099 resolve_neigh_exit6
:
2102 neigh_release(neigh
);
2108 * i40iw_ipv4_is_loopback - check if loopback
2109 * @loc_addr: local addr to compare
2110 * @rem_addr: remote address
2112 static bool i40iw_ipv4_is_loopback(u32 loc_addr
, u32 rem_addr
)
2114 return ipv4_is_loopback(htonl(rem_addr
)) || (loc_addr
== rem_addr
);
2118 * i40iw_ipv6_is_loopback - check if loopback
2119 * @loc_addr: local addr to compare
2120 * @rem_addr: remote address
2122 static bool i40iw_ipv6_is_loopback(u32
*loc_addr
, u32
*rem_addr
)
2124 struct in6_addr raddr6
;
2126 i40iw_copy_ip_htonl(raddr6
.in6_u
.u6_addr32
, rem_addr
);
2127 return !memcmp(loc_addr
, rem_addr
, 16) || ipv6_addr_loopback(&raddr6
);
2131 * i40iw_make_cm_node - create a new instance of a cm node
2132 * @cm_core: cm's core
2133 * @iwdev: iwarp device structure
2134 * @cm_info: quad info for connection
2135 * @listener: passive connection's listener
2137 static struct i40iw_cm_node
*i40iw_make_cm_node(
2138 struct i40iw_cm_core
*cm_core
,
2139 struct i40iw_device
*iwdev
,
2140 struct i40iw_cm_info
*cm_info
,
2141 struct i40iw_cm_listener
*listener
)
2143 struct i40iw_cm_node
*cm_node
;
2147 struct net_device
*netdev
= iwdev
->netdev
;
2149 /* create an hte and cm_node for this instance */
2150 cm_node
= kzalloc(sizeof(*cm_node
), GFP_ATOMIC
);
2154 /* set our node specific transport info */
2155 cm_node
->ipv4
= cm_info
->ipv4
;
2156 cm_node
->vlan_id
= cm_info
->vlan_id
;
2157 if ((cm_node
->vlan_id
== I40IW_NO_VLAN
) && iwdev
->dcb
)
2158 cm_node
->vlan_id
= 0;
2159 cm_node
->tos
= cm_info
->tos
;
2160 cm_node
->user_pri
= cm_info
->user_pri
;
2162 if (listener
->tos
!= cm_info
->tos
)
2163 i40iw_debug(&iwdev
->sc_dev
, I40IW_DEBUG_DCB
,
2164 "application TOS[%d] and remote client TOS[%d] mismatch\n",
2165 listener
->tos
, cm_info
->tos
);
2166 cm_node
->tos
= max(listener
->tos
, cm_info
->tos
);
2167 cm_node
->user_pri
= rt_tos2priority(cm_node
->tos
);
2168 i40iw_debug(&iwdev
->sc_dev
, I40IW_DEBUG_DCB
, "listener: TOS:[%d] UP:[%d]\n",
2169 cm_node
->tos
, cm_node
->user_pri
);
2171 memcpy(cm_node
->loc_addr
, cm_info
->loc_addr
, sizeof(cm_node
->loc_addr
));
2172 memcpy(cm_node
->rem_addr
, cm_info
->rem_addr
, sizeof(cm_node
->rem_addr
));
2173 cm_node
->loc_port
= cm_info
->loc_port
;
2174 cm_node
->rem_port
= cm_info
->rem_port
;
2176 cm_node
->mpa_frame_rev
= iwdev
->mpa_version
;
2177 cm_node
->send_rdma0_op
= SEND_RDMA_READ_ZERO
;
2178 cm_node
->ird_size
= I40IW_MAX_IRD_SIZE
;
2179 cm_node
->ord_size
= I40IW_MAX_ORD_SIZE
;
2181 cm_node
->listener
= listener
;
2182 cm_node
->cm_id
= cm_info
->cm_id
;
2183 ether_addr_copy(cm_node
->loc_mac
, netdev
->dev_addr
);
2184 spin_lock_init(&cm_node
->retrans_list_lock
);
2185 cm_node
->ack_rcvd
= false;
2187 atomic_set(&cm_node
->ref_count
, 1);
2188 /* associate our parent CM core */
2189 cm_node
->cm_core
= cm_core
;
2190 cm_node
->tcp_cntxt
.loc_id
= I40IW_CM_DEF_LOCAL_ID
;
2191 cm_node
->tcp_cntxt
.rcv_wscale
= I40IW_CM_DEFAULT_RCV_WND_SCALE
;
2192 cm_node
->tcp_cntxt
.rcv_wnd
=
2193 I40IW_CM_DEFAULT_RCV_WND_SCALED
>> I40IW_CM_DEFAULT_RCV_WND_SCALE
;
2194 ts
= current_kernel_time();
2195 cm_node
->tcp_cntxt
.loc_seq_num
= ts
.tv_nsec
;
2196 cm_node
->tcp_cntxt
.mss
= (cm_node
->ipv4
) ? (iwdev
->vsi
.mtu
- I40IW_MTU_TO_MSS_IPV4
) :
2197 (iwdev
->vsi
.mtu
- I40IW_MTU_TO_MSS_IPV6
);
2199 cm_node
->iwdev
= iwdev
;
2200 cm_node
->dev
= &iwdev
->sc_dev
;
2202 if ((cm_node
->ipv4
&&
2203 i40iw_ipv4_is_loopback(cm_node
->loc_addr
[0], cm_node
->rem_addr
[0])) ||
2204 (!cm_node
->ipv4
&& i40iw_ipv6_is_loopback(cm_node
->loc_addr
,
2205 cm_node
->rem_addr
))) {
2206 arpindex
= i40iw_arp_table(iwdev
,
2212 oldarpindex
= i40iw_arp_table(iwdev
,
2218 arpindex
= i40iw_addr_resolve_neigh(iwdev
,
2219 cm_info
->loc_addr
[0],
2220 cm_info
->rem_addr
[0],
2222 else if (IS_ENABLED(CONFIG_IPV6
))
2223 arpindex
= i40iw_addr_resolve_neigh_ipv6(iwdev
,
2231 i40iw_pr_err("cm_node arpindex\n");
2235 ether_addr_copy(cm_node
->rem_mac
, iwdev
->arp_table
[arpindex
].mac_addr
);
2236 i40iw_add_hte_node(cm_core
, cm_node
);
2237 cm_core
->stats_nodes_created
++;
2242 * i40iw_rem_ref_cm_node - destroy an instance of a cm node
2243 * @cm_node: connection's node
2245 static void i40iw_rem_ref_cm_node(struct i40iw_cm_node
*cm_node
)
2247 struct i40iw_cm_core
*cm_core
= cm_node
->cm_core
;
2248 struct i40iw_qp
*iwqp
;
2249 struct i40iw_cm_info nfo
;
2250 unsigned long flags
;
2252 spin_lock_irqsave(&cm_node
->cm_core
->ht_lock
, flags
);
2253 if (atomic_dec_return(&cm_node
->ref_count
)) {
2254 spin_unlock_irqrestore(&cm_node
->cm_core
->ht_lock
, flags
);
2257 list_del(&cm_node
->list
);
2258 spin_unlock_irqrestore(&cm_node
->cm_core
->ht_lock
, flags
);
2260 /* if the node is destroyed before connection was accelerated */
2261 if (!cm_node
->accelerated
&& cm_node
->accept_pend
) {
2262 pr_err("node destroyed before established\n");
2263 atomic_dec(&cm_node
->listener
->pend_accepts_cnt
);
2265 if (cm_node
->close_entry
)
2266 i40iw_handle_close_entry(cm_node
, 0);
2267 if (cm_node
->listener
) {
2268 i40iw_dec_refcnt_listen(cm_core
, cm_node
->listener
, 0, true);
2270 if (!i40iw_port_in_use(cm_core
, cm_node
->loc_port
, true) && cm_node
->apbvt_set
) {
2271 i40iw_manage_apbvt(cm_node
->iwdev
,
2273 I40IW_MANAGE_APBVT_DEL
);
2274 cm_node
->apbvt_set
= 0;
2276 i40iw_get_addr_info(cm_node
, &nfo
);
2277 if (cm_node
->qhash_set
) {
2278 i40iw_manage_qhash(cm_node
->iwdev
,
2280 I40IW_QHASH_TYPE_TCP_ESTABLISHED
,
2281 I40IW_QHASH_MANAGE_TYPE_DELETE
,
2284 cm_node
->qhash_set
= 0;
2288 iwqp
= cm_node
->iwqp
;
2290 iwqp
->cm_node
= NULL
;
2291 i40iw_rem_ref(&iwqp
->ibqp
);
2292 cm_node
->iwqp
= NULL
;
2293 } else if (cm_node
->qhash_set
) {
2294 i40iw_get_addr_info(cm_node
, &nfo
);
2295 i40iw_manage_qhash(cm_node
->iwdev
,
2297 I40IW_QHASH_TYPE_TCP_ESTABLISHED
,
2298 I40IW_QHASH_MANAGE_TYPE_DELETE
,
2301 cm_node
->qhash_set
= 0;
2304 cm_node
->cm_core
->stats_nodes_destroyed
++;
2309 * i40iw_handle_fin_pkt - FIN packet received
2310 * @cm_node: connection's node
2312 static void i40iw_handle_fin_pkt(struct i40iw_cm_node
*cm_node
)
2316 switch (cm_node
->state
) {
2317 case I40IW_CM_STATE_SYN_RCVD
:
2318 case I40IW_CM_STATE_SYN_SENT
:
2319 case I40IW_CM_STATE_ESTABLISHED
:
2320 case I40IW_CM_STATE_MPAREJ_RCVD
:
2321 cm_node
->tcp_cntxt
.rcv_nxt
++;
2322 i40iw_cleanup_retrans_entry(cm_node
);
2323 cm_node
->state
= I40IW_CM_STATE_LAST_ACK
;
2324 i40iw_send_fin(cm_node
);
2326 case I40IW_CM_STATE_MPAREQ_SENT
:
2327 i40iw_create_event(cm_node
, I40IW_CM_EVENT_ABORTED
);
2328 cm_node
->tcp_cntxt
.rcv_nxt
++;
2329 i40iw_cleanup_retrans_entry(cm_node
);
2330 cm_node
->state
= I40IW_CM_STATE_CLOSED
;
2331 atomic_inc(&cm_node
->ref_count
);
2332 i40iw_send_reset(cm_node
);
2334 case I40IW_CM_STATE_FIN_WAIT1
:
2335 cm_node
->tcp_cntxt
.rcv_nxt
++;
2336 i40iw_cleanup_retrans_entry(cm_node
);
2337 cm_node
->state
= I40IW_CM_STATE_CLOSING
;
2338 i40iw_send_ack(cm_node
);
2340 * Wait for ACK as this is simultaneous close.
2341 * After we receive ACK, do not send anything.
2345 case I40IW_CM_STATE_FIN_WAIT2
:
2346 cm_node
->tcp_cntxt
.rcv_nxt
++;
2347 i40iw_cleanup_retrans_entry(cm_node
);
2348 cm_node
->state
= I40IW_CM_STATE_TIME_WAIT
;
2349 i40iw_send_ack(cm_node
);
2351 i40iw_schedule_cm_timer(cm_node
, NULL
, I40IW_TIMER_TYPE_CLOSE
, 1, 0);
2353 i40iw_pr_err("node %p state = %d\n", cm_node
, cm_node
->state
);
2355 case I40IW_CM_STATE_TIME_WAIT
:
2356 cm_node
->tcp_cntxt
.rcv_nxt
++;
2357 i40iw_cleanup_retrans_entry(cm_node
);
2358 cm_node
->state
= I40IW_CM_STATE_CLOSED
;
2359 i40iw_rem_ref_cm_node(cm_node
);
2361 case I40IW_CM_STATE_OFFLOADED
:
2363 i40iw_pr_err("bad state node %p state = %d\n", cm_node
, cm_node
->state
);
2369 * i40iw_handle_rst_pkt - process received RST packet
2370 * @cm_node: connection's node
2371 * @rbuf: receive buffer
2373 static void i40iw_handle_rst_pkt(struct i40iw_cm_node
*cm_node
,
2374 struct i40iw_puda_buf
*rbuf
)
2376 i40iw_cleanup_retrans_entry(cm_node
);
2377 switch (cm_node
->state
) {
2378 case I40IW_CM_STATE_SYN_SENT
:
2379 case I40IW_CM_STATE_MPAREQ_SENT
:
2380 switch (cm_node
->mpa_frame_rev
) {
2382 cm_node
->mpa_frame_rev
= IETF_MPA_V1
;
2383 /* send a syn and goto syn sent state */
2384 cm_node
->state
= I40IW_CM_STATE_SYN_SENT
;
2385 if (i40iw_send_syn(cm_node
, 0))
2386 i40iw_active_open_err(cm_node
, false);
2390 i40iw_active_open_err(cm_node
, false);
2394 case I40IW_CM_STATE_MPAREQ_RCVD
:
2395 atomic_add_return(1, &cm_node
->passive_state
);
2397 case I40IW_CM_STATE_ESTABLISHED
:
2398 case I40IW_CM_STATE_SYN_RCVD
:
2399 case I40IW_CM_STATE_LISTENING
:
2400 i40iw_pr_err("Bad state state = %d\n", cm_node
->state
);
2401 i40iw_passive_open_err(cm_node
, false);
2403 case I40IW_CM_STATE_OFFLOADED
:
2404 i40iw_active_open_err(cm_node
, false);
2406 case I40IW_CM_STATE_CLOSED
:
2408 case I40IW_CM_STATE_FIN_WAIT2
:
2409 case I40IW_CM_STATE_FIN_WAIT1
:
2410 case I40IW_CM_STATE_LAST_ACK
:
2411 cm_node
->cm_id
->rem_ref(cm_node
->cm_id
);
2413 case I40IW_CM_STATE_TIME_WAIT
:
2414 cm_node
->state
= I40IW_CM_STATE_CLOSED
;
2415 i40iw_rem_ref_cm_node(cm_node
);
2423 * i40iw_handle_rcv_mpa - Process a recv'd mpa buffer
2424 * @cm_node: connection's node
2425 * @rbuf: receive buffer
2427 static void i40iw_handle_rcv_mpa(struct i40iw_cm_node
*cm_node
,
2428 struct i40iw_puda_buf
*rbuf
)
2431 int datasize
= rbuf
->datalen
;
2432 u8
*dataloc
= rbuf
->data
;
2434 enum i40iw_cm_event_type type
= I40IW_CM_EVENT_UNKNOWN
;
2437 ret
= i40iw_parse_mpa(cm_node
, dataloc
, &res_type
, datasize
);
2439 if (cm_node
->state
== I40IW_CM_STATE_MPAREQ_SENT
)
2440 i40iw_active_open_err(cm_node
, true);
2442 i40iw_passive_open_err(cm_node
, true);
2446 switch (cm_node
->state
) {
2447 case I40IW_CM_STATE_ESTABLISHED
:
2448 if (res_type
== I40IW_MPA_REQUEST_REJECT
)
2449 i40iw_pr_err("state for reject\n");
2450 cm_node
->state
= I40IW_CM_STATE_MPAREQ_RCVD
;
2451 type
= I40IW_CM_EVENT_MPA_REQ
;
2452 i40iw_send_ack(cm_node
); /* ACK received MPA request */
2453 atomic_set(&cm_node
->passive_state
,
2454 I40IW_PASSIVE_STATE_INDICATED
);
2456 case I40IW_CM_STATE_MPAREQ_SENT
:
2457 i40iw_cleanup_retrans_entry(cm_node
);
2458 if (res_type
== I40IW_MPA_REQUEST_REJECT
) {
2459 type
= I40IW_CM_EVENT_MPA_REJECT
;
2460 cm_node
->state
= I40IW_CM_STATE_MPAREJ_RCVD
;
2462 type
= I40IW_CM_EVENT_CONNECTED
;
2463 cm_node
->state
= I40IW_CM_STATE_OFFLOADED
;
2465 i40iw_send_ack(cm_node
);
2468 pr_err("%s wrong cm_node state =%d\n", __func__
, cm_node
->state
);
2471 i40iw_create_event(cm_node
, type
);
2475 * i40iw_indicate_pkt_err - Send up err event to cm
2476 * @cm_node: connection's node
2478 static void i40iw_indicate_pkt_err(struct i40iw_cm_node
*cm_node
)
2480 switch (cm_node
->state
) {
2481 case I40IW_CM_STATE_SYN_SENT
:
2482 case I40IW_CM_STATE_MPAREQ_SENT
:
2483 i40iw_active_open_err(cm_node
, true);
2485 case I40IW_CM_STATE_ESTABLISHED
:
2486 case I40IW_CM_STATE_SYN_RCVD
:
2487 i40iw_passive_open_err(cm_node
, true);
2489 case I40IW_CM_STATE_OFFLOADED
:
2496 * i40iw_check_syn - Check for error on received syn ack
2497 * @cm_node: connection's node
2498 * @tcph: pointer tcp header
2500 static int i40iw_check_syn(struct i40iw_cm_node
*cm_node
, struct tcphdr
*tcph
)
2504 if (ntohl(tcph
->ack_seq
) != cm_node
->tcp_cntxt
.loc_seq_num
) {
2506 i40iw_active_open_err(cm_node
, true);
2512 * i40iw_check_seq - check seq numbers if OK
2513 * @cm_node: connection's node
2514 * @tcph: pointer tcp header
2516 static int i40iw_check_seq(struct i40iw_cm_node
*cm_node
, struct tcphdr
*tcph
)
2521 u32 loc_seq_num
= cm_node
->tcp_cntxt
.loc_seq_num
;
2522 u32 rcv_nxt
= cm_node
->tcp_cntxt
.rcv_nxt
;
2525 seq
= ntohl(tcph
->seq
);
2526 ack_seq
= ntohl(tcph
->ack_seq
);
2527 rcv_wnd
= cm_node
->tcp_cntxt
.rcv_wnd
;
2528 if (ack_seq
!= loc_seq_num
)
2530 else if (!between(seq
, rcv_nxt
, (rcv_nxt
+ rcv_wnd
)))
2533 i40iw_pr_err("seq number\n");
2534 i40iw_indicate_pkt_err(cm_node
);
2540 * i40iw_handle_syn_pkt - is for Passive node
2541 * @cm_node: connection's node
2542 * @rbuf: receive buffer
2544 static void i40iw_handle_syn_pkt(struct i40iw_cm_node
*cm_node
,
2545 struct i40iw_puda_buf
*rbuf
)
2547 struct tcphdr
*tcph
= (struct tcphdr
*)rbuf
->tcph
;
2551 struct i40iw_cm_info nfo
;
2553 optionsize
= (tcph
->doff
<< 2) - sizeof(struct tcphdr
);
2554 inc_sequence
= ntohl(tcph
->seq
);
2556 switch (cm_node
->state
) {
2557 case I40IW_CM_STATE_SYN_SENT
:
2558 case I40IW_CM_STATE_MPAREQ_SENT
:
2559 /* Rcvd syn on active open connection */
2560 i40iw_active_open_err(cm_node
, 1);
2562 case I40IW_CM_STATE_LISTENING
:
2564 if (atomic_read(&cm_node
->listener
->pend_accepts_cnt
) >
2565 cm_node
->listener
->backlog
) {
2566 cm_node
->cm_core
->stats_backlog_drops
++;
2567 i40iw_passive_open_err(cm_node
, false);
2570 ret
= i40iw_handle_tcp_options(cm_node
, tcph
, optionsize
, 1);
2572 i40iw_passive_open_err(cm_node
, false);
2576 cm_node
->tcp_cntxt
.rcv_nxt
= inc_sequence
+ 1;
2577 cm_node
->accept_pend
= 1;
2578 atomic_inc(&cm_node
->listener
->pend_accepts_cnt
);
2580 cm_node
->state
= I40IW_CM_STATE_SYN_RCVD
;
2581 i40iw_get_addr_info(cm_node
, &nfo
);
2582 ret
= i40iw_manage_qhash(cm_node
->iwdev
,
2584 I40IW_QHASH_TYPE_TCP_ESTABLISHED
,
2585 I40IW_QHASH_MANAGE_TYPE_ADD
,
2588 cm_node
->qhash_set
= true;
2590 case I40IW_CM_STATE_CLOSED
:
2591 i40iw_cleanup_retrans_entry(cm_node
);
2592 atomic_inc(&cm_node
->ref_count
);
2593 i40iw_send_reset(cm_node
);
2595 case I40IW_CM_STATE_OFFLOADED
:
2596 case I40IW_CM_STATE_ESTABLISHED
:
2597 case I40IW_CM_STATE_FIN_WAIT1
:
2598 case I40IW_CM_STATE_FIN_WAIT2
:
2599 case I40IW_CM_STATE_MPAREQ_RCVD
:
2600 case I40IW_CM_STATE_LAST_ACK
:
2601 case I40IW_CM_STATE_CLOSING
:
2602 case I40IW_CM_STATE_UNKNOWN
:
2609 * i40iw_handle_synack_pkt - Process SYN+ACK packet (active side)
2610 * @cm_node: connection's node
2611 * @rbuf: receive buffer
2613 static void i40iw_handle_synack_pkt(struct i40iw_cm_node
*cm_node
,
2614 struct i40iw_puda_buf
*rbuf
)
2616 struct tcphdr
*tcph
= (struct tcphdr
*)rbuf
->tcph
;
2621 optionsize
= (tcph
->doff
<< 2) - sizeof(struct tcphdr
);
2622 inc_sequence
= ntohl(tcph
->seq
);
2623 switch (cm_node
->state
) {
2624 case I40IW_CM_STATE_SYN_SENT
:
2625 i40iw_cleanup_retrans_entry(cm_node
);
2627 if (i40iw_check_syn(cm_node
, tcph
)) {
2628 i40iw_pr_err("check syn fail\n");
2631 cm_node
->tcp_cntxt
.rem_ack_num
= ntohl(tcph
->ack_seq
);
2633 ret
= i40iw_handle_tcp_options(cm_node
, tcph
, optionsize
, 0);
2635 i40iw_debug(cm_node
->dev
,
2637 "cm_node=%p tcp_options failed\n",
2641 i40iw_cleanup_retrans_entry(cm_node
);
2642 cm_node
->tcp_cntxt
.rcv_nxt
= inc_sequence
+ 1;
2643 i40iw_send_ack(cm_node
); /* ACK for the syn_ack */
2644 ret
= i40iw_send_mpa_request(cm_node
);
2646 i40iw_debug(cm_node
->dev
,
2648 "cm_node=%p i40iw_send_mpa_request failed\n",
2652 cm_node
->state
= I40IW_CM_STATE_MPAREQ_SENT
;
2654 case I40IW_CM_STATE_MPAREQ_RCVD
:
2655 i40iw_passive_open_err(cm_node
, true);
2657 case I40IW_CM_STATE_LISTENING
:
2658 cm_node
->tcp_cntxt
.loc_seq_num
= ntohl(tcph
->ack_seq
);
2659 i40iw_cleanup_retrans_entry(cm_node
);
2660 cm_node
->state
= I40IW_CM_STATE_CLOSED
;
2661 i40iw_send_reset(cm_node
);
2663 case I40IW_CM_STATE_CLOSED
:
2664 cm_node
->tcp_cntxt
.loc_seq_num
= ntohl(tcph
->ack_seq
);
2665 i40iw_cleanup_retrans_entry(cm_node
);
2666 atomic_inc(&cm_node
->ref_count
);
2667 i40iw_send_reset(cm_node
);
2669 case I40IW_CM_STATE_ESTABLISHED
:
2670 case I40IW_CM_STATE_FIN_WAIT1
:
2671 case I40IW_CM_STATE_FIN_WAIT2
:
2672 case I40IW_CM_STATE_LAST_ACK
:
2673 case I40IW_CM_STATE_OFFLOADED
:
2674 case I40IW_CM_STATE_CLOSING
:
2675 case I40IW_CM_STATE_UNKNOWN
:
2676 case I40IW_CM_STATE_MPAREQ_SENT
:
2683 * i40iw_handle_ack_pkt - process packet with ACK
2684 * @cm_node: connection's node
2685 * @rbuf: receive buffer
2687 static int i40iw_handle_ack_pkt(struct i40iw_cm_node
*cm_node
,
2688 struct i40iw_puda_buf
*rbuf
)
2690 struct tcphdr
*tcph
= (struct tcphdr
*)rbuf
->tcph
;
2694 u32 datasize
= rbuf
->datalen
;
2696 optionsize
= (tcph
->doff
<< 2) - sizeof(struct tcphdr
);
2698 if (i40iw_check_seq(cm_node
, tcph
))
2701 inc_sequence
= ntohl(tcph
->seq
);
2702 switch (cm_node
->state
) {
2703 case I40IW_CM_STATE_SYN_RCVD
:
2704 i40iw_cleanup_retrans_entry(cm_node
);
2705 ret
= i40iw_handle_tcp_options(cm_node
, tcph
, optionsize
, 1);
2708 cm_node
->tcp_cntxt
.rem_ack_num
= ntohl(tcph
->ack_seq
);
2709 cm_node
->state
= I40IW_CM_STATE_ESTABLISHED
;
2711 cm_node
->tcp_cntxt
.rcv_nxt
= inc_sequence
+ datasize
;
2712 i40iw_handle_rcv_mpa(cm_node
, rbuf
);
2715 case I40IW_CM_STATE_ESTABLISHED
:
2716 i40iw_cleanup_retrans_entry(cm_node
);
2718 cm_node
->tcp_cntxt
.rcv_nxt
= inc_sequence
+ datasize
;
2719 i40iw_handle_rcv_mpa(cm_node
, rbuf
);
2722 case I40IW_CM_STATE_MPAREQ_SENT
:
2723 cm_node
->tcp_cntxt
.rem_ack_num
= ntohl(tcph
->ack_seq
);
2725 cm_node
->tcp_cntxt
.rcv_nxt
= inc_sequence
+ datasize
;
2726 cm_node
->ack_rcvd
= false;
2727 i40iw_handle_rcv_mpa(cm_node
, rbuf
);
2729 cm_node
->ack_rcvd
= true;
2732 case I40IW_CM_STATE_LISTENING
:
2733 i40iw_cleanup_retrans_entry(cm_node
);
2734 cm_node
->state
= I40IW_CM_STATE_CLOSED
;
2735 i40iw_send_reset(cm_node
);
2737 case I40IW_CM_STATE_CLOSED
:
2738 i40iw_cleanup_retrans_entry(cm_node
);
2739 atomic_inc(&cm_node
->ref_count
);
2740 i40iw_send_reset(cm_node
);
2742 case I40IW_CM_STATE_LAST_ACK
:
2743 case I40IW_CM_STATE_CLOSING
:
2744 i40iw_cleanup_retrans_entry(cm_node
);
2745 cm_node
->state
= I40IW_CM_STATE_CLOSED
;
2746 if (!cm_node
->accept_pend
)
2747 cm_node
->cm_id
->rem_ref(cm_node
->cm_id
);
2748 i40iw_rem_ref_cm_node(cm_node
);
2750 case I40IW_CM_STATE_FIN_WAIT1
:
2751 i40iw_cleanup_retrans_entry(cm_node
);
2752 cm_node
->state
= I40IW_CM_STATE_FIN_WAIT2
;
2754 case I40IW_CM_STATE_SYN_SENT
:
2755 case I40IW_CM_STATE_FIN_WAIT2
:
2756 case I40IW_CM_STATE_OFFLOADED
:
2757 case I40IW_CM_STATE_MPAREQ_RCVD
:
2758 case I40IW_CM_STATE_UNKNOWN
:
2760 i40iw_cleanup_retrans_entry(cm_node
);
2767 * i40iw_process_packet - process cm packet
2768 * @cm_node: connection's node
2769 * @rbuf: receive buffer
2771 static void i40iw_process_packet(struct i40iw_cm_node
*cm_node
,
2772 struct i40iw_puda_buf
*rbuf
)
2774 enum i40iw_tcpip_pkt_type pkt_type
= I40IW_PKT_TYPE_UNKNOWN
;
2775 struct tcphdr
*tcph
= (struct tcphdr
*)rbuf
->tcph
;
2780 pkt_type
= I40IW_PKT_TYPE_RST
;
2781 } else if (tcph
->syn
) {
2782 pkt_type
= I40IW_PKT_TYPE_SYN
;
2784 pkt_type
= I40IW_PKT_TYPE_SYNACK
;
2785 } else if (tcph
->ack
) {
2786 pkt_type
= I40IW_PKT_TYPE_ACK
;
2792 case I40IW_PKT_TYPE_SYN
:
2793 i40iw_handle_syn_pkt(cm_node
, rbuf
);
2795 case I40IW_PKT_TYPE_SYNACK
:
2796 i40iw_handle_synack_pkt(cm_node
, rbuf
);
2798 case I40IW_PKT_TYPE_ACK
:
2799 ret
= i40iw_handle_ack_pkt(cm_node
, rbuf
);
2800 if (fin_set
&& !ret
)
2801 i40iw_handle_fin_pkt(cm_node
);
2803 case I40IW_PKT_TYPE_RST
:
2804 i40iw_handle_rst_pkt(cm_node
, rbuf
);
2808 (!i40iw_check_seq(cm_node
, (struct tcphdr
*)rbuf
->tcph
)))
2809 i40iw_handle_fin_pkt(cm_node
);
2815 * i40iw_make_listen_node - create a listen node with params
2816 * @cm_core: cm's core
2817 * @iwdev: iwarp device structure
2818 * @cm_info: quad info for connection
2820 static struct i40iw_cm_listener
*i40iw_make_listen_node(
2821 struct i40iw_cm_core
*cm_core
,
2822 struct i40iw_device
*iwdev
,
2823 struct i40iw_cm_info
*cm_info
)
2825 struct i40iw_cm_listener
*listener
;
2826 unsigned long flags
;
2828 /* cannot have multiple matching listeners */
2829 listener
= i40iw_find_listener(cm_core
, cm_info
->loc_addr
,
2832 I40IW_CM_LISTENER_EITHER_STATE
);
2834 (listener
->listener_state
== I40IW_CM_LISTENER_ACTIVE_STATE
)) {
2835 atomic_dec(&listener
->ref_count
);
2836 i40iw_debug(cm_core
->dev
,
2838 "Not creating listener since it already exists\n");
2843 /* create a CM listen node (1/2 node to compare incoming traffic to) */
2844 listener
= kzalloc(sizeof(*listener
), GFP_ATOMIC
);
2847 cm_core
->stats_listen_nodes_created
++;
2848 memcpy(listener
->loc_addr
, cm_info
->loc_addr
, sizeof(listener
->loc_addr
));
2849 listener
->loc_port
= cm_info
->loc_port
;
2851 INIT_LIST_HEAD(&listener
->child_listen_list
);
2853 atomic_set(&listener
->ref_count
, 1);
2855 listener
->reused_node
= 1;
2858 listener
->cm_id
= cm_info
->cm_id
;
2859 listener
->ipv4
= cm_info
->ipv4
;
2860 listener
->vlan_id
= cm_info
->vlan_id
;
2861 atomic_set(&listener
->pend_accepts_cnt
, 0);
2862 listener
->cm_core
= cm_core
;
2863 listener
->iwdev
= iwdev
;
2865 listener
->backlog
= cm_info
->backlog
;
2866 listener
->listener_state
= I40IW_CM_LISTENER_ACTIVE_STATE
;
2868 if (!listener
->reused_node
) {
2869 spin_lock_irqsave(&cm_core
->listen_list_lock
, flags
);
2870 list_add(&listener
->list
, &cm_core
->listen_nodes
);
2871 spin_unlock_irqrestore(&cm_core
->listen_list_lock
, flags
);
2878 * i40iw_create_cm_node - make a connection node with params
2879 * @cm_core: cm's core
2880 * @iwdev: iwarp device structure
2881 * @private_data_len: len to provate data for mpa request
2882 * @private_data: pointer to private data for connection
2883 * @cm_info: quad info for connection
2885 static struct i40iw_cm_node
*i40iw_create_cm_node(
2886 struct i40iw_cm_core
*cm_core
,
2887 struct i40iw_device
*iwdev
,
2888 u16 private_data_len
,
2890 struct i40iw_cm_info
*cm_info
)
2892 struct i40iw_cm_node
*cm_node
;
2893 struct i40iw_cm_listener
*loopback_remotelistener
;
2894 struct i40iw_cm_node
*loopback_remotenode
;
2895 struct i40iw_cm_info loopback_cm_info
;
2897 /* create a CM connection node */
2898 cm_node
= i40iw_make_cm_node(cm_core
, iwdev
, cm_info
, NULL
);
2900 return ERR_PTR(-ENOMEM
);
2901 /* set our node side to client (active) side */
2902 cm_node
->tcp_cntxt
.client
= 1;
2903 cm_node
->tcp_cntxt
.rcv_wscale
= I40IW_CM_DEFAULT_RCV_WND_SCALE
;
2905 if (!memcmp(cm_info
->loc_addr
, cm_info
->rem_addr
, sizeof(cm_info
->loc_addr
))) {
2906 loopback_remotelistener
= i40iw_find_listener(
2911 I40IW_CM_LISTENER_ACTIVE_STATE
);
2912 if (!loopback_remotelistener
) {
2913 i40iw_rem_ref_cm_node(cm_node
);
2914 return ERR_PTR(-ECONNREFUSED
);
2916 loopback_cm_info
= *cm_info
;
2917 loopback_cm_info
.loc_port
= cm_info
->rem_port
;
2918 loopback_cm_info
.rem_port
= cm_info
->loc_port
;
2919 loopback_cm_info
.cm_id
= loopback_remotelistener
->cm_id
;
2920 loopback_cm_info
.ipv4
= cm_info
->ipv4
;
2921 loopback_remotenode
= i40iw_make_cm_node(cm_core
,
2924 loopback_remotelistener
);
2925 if (!loopback_remotenode
) {
2926 i40iw_rem_ref_cm_node(cm_node
);
2927 return ERR_PTR(-ENOMEM
);
2929 cm_core
->stats_loopbacks
++;
2930 loopback_remotenode
->loopbackpartner
= cm_node
;
2931 loopback_remotenode
->tcp_cntxt
.rcv_wscale
=
2932 I40IW_CM_DEFAULT_RCV_WND_SCALE
;
2933 cm_node
->loopbackpartner
= loopback_remotenode
;
2934 memcpy(loopback_remotenode
->pdata_buf
, private_data
,
2936 loopback_remotenode
->pdata
.size
= private_data_len
;
2938 cm_node
->state
= I40IW_CM_STATE_OFFLOADED
;
2939 cm_node
->tcp_cntxt
.rcv_nxt
=
2940 loopback_remotenode
->tcp_cntxt
.loc_seq_num
;
2941 loopback_remotenode
->tcp_cntxt
.rcv_nxt
=
2942 cm_node
->tcp_cntxt
.loc_seq_num
;
2943 cm_node
->tcp_cntxt
.max_snd_wnd
=
2944 loopback_remotenode
->tcp_cntxt
.rcv_wnd
;
2945 loopback_remotenode
->tcp_cntxt
.max_snd_wnd
= cm_node
->tcp_cntxt
.rcv_wnd
;
2946 cm_node
->tcp_cntxt
.snd_wnd
= loopback_remotenode
->tcp_cntxt
.rcv_wnd
;
2947 loopback_remotenode
->tcp_cntxt
.snd_wnd
= cm_node
->tcp_cntxt
.rcv_wnd
;
2948 cm_node
->tcp_cntxt
.snd_wscale
= loopback_remotenode
->tcp_cntxt
.rcv_wscale
;
2949 loopback_remotenode
->tcp_cntxt
.snd_wscale
= cm_node
->tcp_cntxt
.rcv_wscale
;
2954 cm_node
->pdata
.size
= private_data_len
;
2955 cm_node
->pdata
.addr
= cm_node
->pdata_buf
;
2957 memcpy(cm_node
->pdata_buf
, private_data
, private_data_len
);
2959 cm_node
->state
= I40IW_CM_STATE_SYN_SENT
;
2964 * i40iw_cm_reject - reject and teardown a connection
2965 * @cm_node: connection's node
2966 * @pdate: ptr to private data for reject
2967 * @plen: size of private data
2969 static int i40iw_cm_reject(struct i40iw_cm_node
*cm_node
, const void *pdata
, u8 plen
)
2974 struct iw_cm_id
*cm_id
= cm_node
->cm_id
;
2975 struct i40iw_cm_node
*loopback
= cm_node
->loopbackpartner
;
2977 if (cm_node
->tcp_cntxt
.client
)
2979 i40iw_cleanup_retrans_entry(cm_node
);
2982 passive_state
= atomic_add_return(1, &cm_node
->passive_state
);
2983 if (passive_state
== I40IW_SEND_RESET_EVENT
) {
2984 cm_node
->state
= I40IW_CM_STATE_CLOSED
;
2985 i40iw_rem_ref_cm_node(cm_node
);
2987 if (cm_node
->state
== I40IW_CM_STATE_LISTENER_DESTROYED
) {
2988 i40iw_rem_ref_cm_node(cm_node
);
2990 ret
= i40iw_send_mpa_reject(cm_node
, pdata
, plen
);
2992 cm_node
->state
= I40IW_CM_STATE_CLOSED
;
2993 err
= i40iw_send_reset(cm_node
);
2995 i40iw_pr_err("send reset failed\n");
2997 cm_id
->add_ref(cm_id
);
3002 cm_node
->cm_id
= NULL
;
3003 if (cm_node
->state
== I40IW_CM_STATE_LISTENER_DESTROYED
) {
3004 i40iw_rem_ref_cm_node(cm_node
);
3005 i40iw_rem_ref_cm_node(loopback
);
3007 ret
= i40iw_send_cm_event(loopback
,
3009 IW_CM_EVENT_CONNECT_REPLY
,
3011 i40iw_rem_ref_cm_node(cm_node
);
3012 loopback
->state
= I40IW_CM_STATE_CLOSING
;
3014 cm_id
= loopback
->cm_id
;
3015 i40iw_rem_ref_cm_node(loopback
);
3016 cm_id
->rem_ref(cm_id
);
3024 * i40iw_cm_close - close of cm connection
3025 * @cm_node: connection's node
3027 static int i40iw_cm_close(struct i40iw_cm_node
*cm_node
)
3034 switch (cm_node
->state
) {
3035 case I40IW_CM_STATE_SYN_RCVD
:
3036 case I40IW_CM_STATE_SYN_SENT
:
3037 case I40IW_CM_STATE_ONE_SIDE_ESTABLISHED
:
3038 case I40IW_CM_STATE_ESTABLISHED
:
3039 case I40IW_CM_STATE_ACCEPTING
:
3040 case I40IW_CM_STATE_MPAREQ_SENT
:
3041 case I40IW_CM_STATE_MPAREQ_RCVD
:
3042 i40iw_cleanup_retrans_entry(cm_node
);
3043 i40iw_send_reset(cm_node
);
3045 case I40IW_CM_STATE_CLOSE_WAIT
:
3046 cm_node
->state
= I40IW_CM_STATE_LAST_ACK
;
3047 i40iw_send_fin(cm_node
);
3049 case I40IW_CM_STATE_FIN_WAIT1
:
3050 case I40IW_CM_STATE_FIN_WAIT2
:
3051 case I40IW_CM_STATE_LAST_ACK
:
3052 case I40IW_CM_STATE_TIME_WAIT
:
3053 case I40IW_CM_STATE_CLOSING
:
3056 case I40IW_CM_STATE_LISTENING
:
3057 i40iw_cleanup_retrans_entry(cm_node
);
3058 i40iw_send_reset(cm_node
);
3060 case I40IW_CM_STATE_MPAREJ_RCVD
:
3061 case I40IW_CM_STATE_UNKNOWN
:
3062 case I40IW_CM_STATE_INITED
:
3063 case I40IW_CM_STATE_CLOSED
:
3064 case I40IW_CM_STATE_LISTENER_DESTROYED
:
3065 i40iw_rem_ref_cm_node(cm_node
);
3067 case I40IW_CM_STATE_OFFLOADED
:
3068 if (cm_node
->send_entry
)
3069 i40iw_pr_err("send_entry\n");
3070 i40iw_rem_ref_cm_node(cm_node
);
3077 * i40iw_receive_ilq - recv an ETHERNET packet, and process it
3079 * @vsi: pointer to the vsi structure
3080 * @rbuf: receive buffer
3082 void i40iw_receive_ilq(struct i40iw_sc_vsi
*vsi
, struct i40iw_puda_buf
*rbuf
)
3084 struct i40iw_cm_node
*cm_node
;
3085 struct i40iw_cm_listener
*listener
;
3087 struct ipv6hdr
*ip6h
;
3088 struct tcphdr
*tcph
;
3089 struct i40iw_cm_info cm_info
;
3090 struct i40iw_sc_dev
*dev
= vsi
->dev
;
3091 struct i40iw_device
*iwdev
= (struct i40iw_device
*)dev
->back_dev
;
3092 struct i40iw_cm_core
*cm_core
= &iwdev
->cm_core
;
3093 struct vlan_ethhdr
*ethh
;
3096 /* if vlan, then maclen = 18 else 14 */
3097 iph
= (struct iphdr
*)rbuf
->iph
;
3098 memset(&cm_info
, 0, sizeof(cm_info
));
3100 i40iw_debug_buf(dev
,
3102 "RECEIVE ILQ BUFFER",
3105 ethh
= (struct vlan_ethhdr
*)rbuf
->mem
.va
;
3107 if (ethh
->h_vlan_proto
== htons(ETH_P_8021Q
)) {
3108 vtag
= ntohs(ethh
->h_vlan_TCI
);
3109 cm_info
.user_pri
= (vtag
& VLAN_PRIO_MASK
) >> VLAN_PRIO_SHIFT
;
3110 cm_info
.vlan_id
= vtag
& VLAN_VID_MASK
;
3111 i40iw_debug(cm_core
->dev
,
3117 cm_info
.vlan_id
= I40IW_NO_VLAN
;
3119 tcph
= (struct tcphdr
*)rbuf
->tcph
;
3122 cm_info
.loc_addr
[0] = ntohl(iph
->daddr
);
3123 cm_info
.rem_addr
[0] = ntohl(iph
->saddr
);
3124 cm_info
.ipv4
= true;
3125 cm_info
.tos
= iph
->tos
;
3127 ip6h
= (struct ipv6hdr
*)rbuf
->iph
;
3128 i40iw_copy_ip_ntohl(cm_info
.loc_addr
,
3129 ip6h
->daddr
.in6_u
.u6_addr32
);
3130 i40iw_copy_ip_ntohl(cm_info
.rem_addr
,
3131 ip6h
->saddr
.in6_u
.u6_addr32
);
3132 cm_info
.ipv4
= false;
3133 cm_info
.tos
= (ip6h
->priority
<< 4) | (ip6h
->flow_lbl
[0] >> 4);
3135 cm_info
.loc_port
= ntohs(tcph
->dest
);
3136 cm_info
.rem_port
= ntohs(tcph
->source
);
3137 cm_node
= i40iw_find_node(cm_core
,
3145 /* Only type of packet accepted are for */
3146 /* the PASSIVE open (syn only) */
3147 if (!tcph
->syn
|| tcph
->ack
)
3150 i40iw_find_listener(cm_core
,
3154 I40IW_CM_LISTENER_ACTIVE_STATE
);
3156 cm_info
.cm_id
= NULL
;
3157 i40iw_debug(cm_core
->dev
,
3159 "%s no listener found\n",
3163 cm_info
.cm_id
= listener
->cm_id
;
3164 cm_node
= i40iw_make_cm_node(cm_core
, iwdev
, &cm_info
, listener
);
3166 i40iw_debug(cm_core
->dev
,
3168 "%s allocate node failed\n",
3170 atomic_dec(&listener
->ref_count
);
3173 if (!tcph
->rst
&& !tcph
->fin
) {
3174 cm_node
->state
= I40IW_CM_STATE_LISTENING
;
3176 i40iw_rem_ref_cm_node(cm_node
);
3179 atomic_inc(&cm_node
->ref_count
);
3180 } else if (cm_node
->state
== I40IW_CM_STATE_OFFLOADED
) {
3181 i40iw_rem_ref_cm_node(cm_node
);
3184 i40iw_process_packet(cm_node
, rbuf
);
3185 i40iw_rem_ref_cm_node(cm_node
);
3189 * i40iw_setup_cm_core - allocate a top level instance of a cm
3191 * @iwdev: iwarp device structure
3193 void i40iw_setup_cm_core(struct i40iw_device
*iwdev
)
3195 struct i40iw_cm_core
*cm_core
= &iwdev
->cm_core
;
3197 cm_core
->iwdev
= iwdev
;
3198 cm_core
->dev
= &iwdev
->sc_dev
;
3200 INIT_LIST_HEAD(&cm_core
->connected_nodes
);
3201 INIT_LIST_HEAD(&cm_core
->listen_nodes
);
3203 timer_setup(&cm_core
->tcp_timer
, i40iw_cm_timer_tick
, 0);
3205 spin_lock_init(&cm_core
->ht_lock
);
3206 spin_lock_init(&cm_core
->listen_list_lock
);
3208 cm_core
->event_wq
= alloc_ordered_workqueue("iwewq",
3211 cm_core
->disconn_wq
= alloc_ordered_workqueue("iwdwq",
3216 * i40iw_cleanup_cm_core - deallocate a top level instance of a
3218 * @cm_core: cm's core
3220 void i40iw_cleanup_cm_core(struct i40iw_cm_core
*cm_core
)
3222 unsigned long flags
;
3227 spin_lock_irqsave(&cm_core
->ht_lock
, flags
);
3228 if (timer_pending(&cm_core
->tcp_timer
))
3229 del_timer_sync(&cm_core
->tcp_timer
);
3230 spin_unlock_irqrestore(&cm_core
->ht_lock
, flags
);
3232 destroy_workqueue(cm_core
->event_wq
);
3233 destroy_workqueue(cm_core
->disconn_wq
);
3237 * i40iw_init_tcp_ctx - setup qp context
3238 * @cm_node: connection's node
3239 * @tcp_info: offload info for tcp
3240 * @iwqp: associate qp for the connection
3242 static void i40iw_init_tcp_ctx(struct i40iw_cm_node
*cm_node
,
3243 struct i40iw_tcp_offload_info
*tcp_info
,
3244 struct i40iw_qp
*iwqp
)
3246 tcp_info
->ipv4
= cm_node
->ipv4
;
3247 tcp_info
->drop_ooo_seg
= true;
3248 tcp_info
->wscale
= true;
3249 tcp_info
->ignore_tcp_opt
= true;
3250 tcp_info
->ignore_tcp_uns_opt
= true;
3251 tcp_info
->no_nagle
= false;
3253 tcp_info
->ttl
= I40IW_DEFAULT_TTL
;
3254 tcp_info
->rtt_var
= cpu_to_le32(I40IW_DEFAULT_RTT_VAR
);
3255 tcp_info
->ss_thresh
= cpu_to_le32(I40IW_DEFAULT_SS_THRESH
);
3256 tcp_info
->rexmit_thresh
= I40IW_DEFAULT_REXMIT_THRESH
;
3258 tcp_info
->tcp_state
= I40IW_TCP_STATE_ESTABLISHED
;
3259 tcp_info
->snd_wscale
= cm_node
->tcp_cntxt
.snd_wscale
;
3260 tcp_info
->rcv_wscale
= cm_node
->tcp_cntxt
.rcv_wscale
;
3262 tcp_info
->snd_nxt
= cpu_to_le32(cm_node
->tcp_cntxt
.loc_seq_num
);
3263 tcp_info
->snd_wnd
= cpu_to_le32(cm_node
->tcp_cntxt
.snd_wnd
);
3264 tcp_info
->rcv_nxt
= cpu_to_le32(cm_node
->tcp_cntxt
.rcv_nxt
);
3265 tcp_info
->snd_max
= cpu_to_le32(cm_node
->tcp_cntxt
.loc_seq_num
);
3267 tcp_info
->snd_una
= cpu_to_le32(cm_node
->tcp_cntxt
.loc_seq_num
);
3268 tcp_info
->cwnd
= cpu_to_le32(2 * cm_node
->tcp_cntxt
.mss
);
3269 tcp_info
->snd_wl1
= cpu_to_le32(cm_node
->tcp_cntxt
.rcv_nxt
);
3270 tcp_info
->snd_wl2
= cpu_to_le32(cm_node
->tcp_cntxt
.loc_seq_num
);
3271 tcp_info
->max_snd_window
= cpu_to_le32(cm_node
->tcp_cntxt
.max_snd_wnd
);
3272 tcp_info
->rcv_wnd
= cpu_to_le32(cm_node
->tcp_cntxt
.rcv_wnd
<<
3273 cm_node
->tcp_cntxt
.rcv_wscale
);
3275 tcp_info
->flow_label
= 0;
3276 tcp_info
->snd_mss
= cpu_to_le32(((u32
)cm_node
->tcp_cntxt
.mss
));
3277 if (cm_node
->vlan_id
< VLAN_TAG_PRESENT
) {
3278 tcp_info
->insert_vlan_tag
= true;
3279 tcp_info
->vlan_tag
= cpu_to_le16(((u16
)cm_node
->user_pri
<< I40IW_VLAN_PRIO_SHIFT
) |
3282 if (cm_node
->ipv4
) {
3283 tcp_info
->src_port
= cpu_to_le16(cm_node
->loc_port
);
3284 tcp_info
->dst_port
= cpu_to_le16(cm_node
->rem_port
);
3286 tcp_info
->dest_ip_addr3
= cpu_to_le32(cm_node
->rem_addr
[0]);
3287 tcp_info
->local_ipaddr3
= cpu_to_le32(cm_node
->loc_addr
[0]);
3289 cpu_to_le16((u16
)i40iw_arp_table(
3291 &tcp_info
->dest_ip_addr3
,
3294 I40IW_ARP_RESOLVE
));
3296 tcp_info
->src_port
= cpu_to_le16(cm_node
->loc_port
);
3297 tcp_info
->dst_port
= cpu_to_le16(cm_node
->rem_port
);
3298 tcp_info
->dest_ip_addr0
= cpu_to_le32(cm_node
->rem_addr
[0]);
3299 tcp_info
->dest_ip_addr1
= cpu_to_le32(cm_node
->rem_addr
[1]);
3300 tcp_info
->dest_ip_addr2
= cpu_to_le32(cm_node
->rem_addr
[2]);
3301 tcp_info
->dest_ip_addr3
= cpu_to_le32(cm_node
->rem_addr
[3]);
3302 tcp_info
->local_ipaddr0
= cpu_to_le32(cm_node
->loc_addr
[0]);
3303 tcp_info
->local_ipaddr1
= cpu_to_le32(cm_node
->loc_addr
[1]);
3304 tcp_info
->local_ipaddr2
= cpu_to_le32(cm_node
->loc_addr
[2]);
3305 tcp_info
->local_ipaddr3
= cpu_to_le32(cm_node
->loc_addr
[3]);
3307 cpu_to_le16((u16
)i40iw_arp_table(
3309 &tcp_info
->dest_ip_addr0
,
3312 I40IW_ARP_RESOLVE
));
3317 * i40iw_cm_init_tsa_conn - setup qp for RTS
3318 * @iwqp: associate qp for the connection
3319 * @cm_node: connection's node
3321 static void i40iw_cm_init_tsa_conn(struct i40iw_qp
*iwqp
,
3322 struct i40iw_cm_node
*cm_node
)
3324 struct i40iw_tcp_offload_info tcp_info
;
3325 struct i40iwarp_offload_info
*iwarp_info
;
3326 struct i40iw_qp_host_ctx_info
*ctx_info
;
3327 struct i40iw_device
*iwdev
= iwqp
->iwdev
;
3328 struct i40iw_sc_dev
*dev
= &iwqp
->iwdev
->sc_dev
;
3330 memset(&tcp_info
, 0x00, sizeof(struct i40iw_tcp_offload_info
));
3331 iwarp_info
= &iwqp
->iwarp_info
;
3332 ctx_info
= &iwqp
->ctx_info
;
3334 ctx_info
->tcp_info
= &tcp_info
;
3335 ctx_info
->send_cq_num
= iwqp
->iwscq
->sc_cq
.cq_uk
.cq_id
;
3336 ctx_info
->rcv_cq_num
= iwqp
->iwrcq
->sc_cq
.cq_uk
.cq_id
;
3338 iwarp_info
->ord_size
= cm_node
->ord_size
;
3339 iwarp_info
->ird_size
= i40iw_derive_hw_ird_setting(cm_node
->ird_size
);
3341 if (iwarp_info
->ord_size
== 1)
3342 iwarp_info
->ord_size
= 2;
3344 iwarp_info
->rd_enable
= true;
3345 iwarp_info
->rdmap_ver
= 1;
3346 iwarp_info
->ddp_ver
= 1;
3348 iwarp_info
->pd_id
= iwqp
->iwpd
->sc_pd
.pd_id
;
3350 ctx_info
->tcp_info_valid
= true;
3351 ctx_info
->iwarp_info_valid
= true;
3352 ctx_info
->add_to_qoslist
= true;
3353 ctx_info
->user_pri
= cm_node
->user_pri
;
3355 i40iw_init_tcp_ctx(cm_node
, &tcp_info
, iwqp
);
3356 if (cm_node
->snd_mark_en
) {
3357 iwarp_info
->snd_mark_en
= true;
3358 iwarp_info
->snd_mark_offset
= (tcp_info
.snd_nxt
&
3359 SNDMARKER_SEQNMASK
) + cm_node
->lsmm_size
;
3362 cm_node
->state
= I40IW_CM_STATE_OFFLOADED
;
3363 tcp_info
.tcp_state
= I40IW_TCP_STATE_ESTABLISHED
;
3364 tcp_info
.src_mac_addr_idx
= iwdev
->mac_ip_table_idx
;
3365 tcp_info
.tos
= cm_node
->tos
;
3367 dev
->iw_priv_qp_ops
->qp_setctx(&iwqp
->sc_qp
, (u64
*)(iwqp
->host_ctx
.va
), ctx_info
);
3369 /* once tcp_info is set, no need to do it again */
3370 ctx_info
->tcp_info_valid
= false;
3371 ctx_info
->iwarp_info_valid
= false;
3372 ctx_info
->add_to_qoslist
= false;
3376 * i40iw_cm_disconn - when a connection is being closed
3377 * @iwqp: associate qp for the connection
3379 void i40iw_cm_disconn(struct i40iw_qp
*iwqp
)
3381 struct disconn_work
*work
;
3382 struct i40iw_device
*iwdev
= iwqp
->iwdev
;
3383 struct i40iw_cm_core
*cm_core
= &iwdev
->cm_core
;
3384 unsigned long flags
;
3386 work
= kzalloc(sizeof(*work
), GFP_ATOMIC
);
3388 return; /* Timer will clean up */
3390 spin_lock_irqsave(&iwdev
->qptable_lock
, flags
);
3391 if (!iwdev
->qp_table
[iwqp
->ibqp
.qp_num
]) {
3392 spin_unlock_irqrestore(&iwdev
->qptable_lock
, flags
);
3393 i40iw_debug(&iwdev
->sc_dev
, I40IW_DEBUG_CM
,
3394 "%s qp_id %d is already freed\n",
3395 __func__
, iwqp
->ibqp
.qp_num
);
3399 i40iw_add_ref(&iwqp
->ibqp
);
3400 spin_unlock_irqrestore(&iwdev
->qptable_lock
, flags
);
3403 INIT_WORK(&work
->work
, i40iw_disconnect_worker
);
3404 queue_work(cm_core
->disconn_wq
, &work
->work
);
3409 * i40iw_qp_disconnect - free qp and close cm
3410 * @iwqp: associate qp for the connection
3412 static void i40iw_qp_disconnect(struct i40iw_qp
*iwqp
)
3414 struct i40iw_device
*iwdev
;
3415 struct i40iw_ib_device
*iwibdev
;
3417 iwdev
= to_iwdev(iwqp
->ibqp
.device
);
3419 i40iw_pr_err("iwdev == NULL\n");
3423 iwibdev
= iwdev
->iwibdev
;
3425 if (iwqp
->active_conn
) {
3426 /* indicate this connection is NOT active */
3427 iwqp
->active_conn
= 0;
3429 /* Need to free the Last Streaming Mode Message */
3430 if (iwqp
->ietf_mem
.va
) {
3432 iwibdev
->ibdev
.dereg_mr(iwqp
->lsmm_mr
);
3433 i40iw_free_dma_mem(iwdev
->sc_dev
.hw
, &iwqp
->ietf_mem
);
3437 /* close the CM node down if it is still active */
3438 if (iwqp
->cm_node
) {
3439 i40iw_debug(&iwdev
->sc_dev
, I40IW_DEBUG_CM
, "%s Call close API\n", __func__
);
3440 i40iw_cm_close(iwqp
->cm_node
);
3445 * i40iw_cm_disconn_true - called by worker thread to disconnect qp
3446 * @iwqp: associate qp for the connection
3448 static void i40iw_cm_disconn_true(struct i40iw_qp
*iwqp
)
3450 struct iw_cm_id
*cm_id
;
3451 struct i40iw_device
*iwdev
;
3452 struct i40iw_sc_qp
*qp
= &iwqp
->sc_qp
;
3454 u8 original_hw_tcp_state
;
3455 u8 original_ibqp_state
;
3456 int disconn_status
= 0;
3457 int issue_disconn
= 0;
3458 int issue_close
= 0;
3459 int issue_flush
= 0;
3460 struct ib_event ibevent
;
3461 unsigned long flags
;
3465 i40iw_pr_err("iwqp == NULL\n");
3469 spin_lock_irqsave(&iwqp
->lock
, flags
);
3470 cm_id
= iwqp
->cm_id
;
3471 /* make sure we havent already closed this connection */
3473 spin_unlock_irqrestore(&iwqp
->lock
, flags
);
3477 iwdev
= to_iwdev(iwqp
->ibqp
.device
);
3479 original_hw_tcp_state
= iwqp
->hw_tcp_state
;
3480 original_ibqp_state
= iwqp
->ibqp_state
;
3481 last_ae
= iwqp
->last_aeq
;
3483 if (qp
->term_flags
) {
3487 /*When term timer expires after cm_timer, don't want
3488 *terminate-handler to issue cm_disconn which can re-free
3489 *a QP even after its refcnt=0.
3491 i40iw_terminate_del_timer(qp
);
3492 if (!iwqp
->flush_issued
) {
3493 iwqp
->flush_issued
= 1;
3496 } else if ((original_hw_tcp_state
== I40IW_TCP_STATE_CLOSE_WAIT
) ||
3497 ((original_ibqp_state
== IB_QPS_RTS
) &&
3498 (last_ae
== I40IW_AE_LLP_CONNECTION_RESET
))) {
3500 if (last_ae
== I40IW_AE_LLP_CONNECTION_RESET
)
3501 disconn_status
= -ECONNRESET
;
3504 if (((original_hw_tcp_state
== I40IW_TCP_STATE_CLOSED
) ||
3505 (original_hw_tcp_state
== I40IW_TCP_STATE_TIME_WAIT
) ||
3506 (last_ae
== I40IW_AE_RDMAP_ROE_BAD_LLP_CLOSE
) ||
3507 (last_ae
== I40IW_AE_LLP_CONNECTION_RESET
) ||
3511 if (!iwqp
->flush_issued
) {
3512 iwqp
->flush_issued
= 1;
3517 spin_unlock_irqrestore(&iwqp
->lock
, flags
);
3518 if (issue_flush
&& !iwqp
->destroyed
) {
3519 /* Flush the queues */
3520 i40iw_flush_wqes(iwdev
, iwqp
);
3522 if (qp
->term_flags
&& iwqp
->ibqp
.event_handler
) {
3523 ibevent
.device
= iwqp
->ibqp
.device
;
3524 ibevent
.event
= (qp
->eventtype
== TERM_EVENT_QP_FATAL
) ?
3525 IB_EVENT_QP_FATAL
: IB_EVENT_QP_ACCESS_ERR
;
3526 ibevent
.element
.qp
= &iwqp
->ibqp
;
3527 iwqp
->ibqp
.event_handler(&ibevent
, iwqp
->ibqp
.qp_context
);
3531 if (cm_id
&& cm_id
->event_handler
) {
3532 if (issue_disconn
) {
3533 ret
= i40iw_send_cm_event(NULL
,
3535 IW_CM_EVENT_DISCONNECT
,
3539 i40iw_debug(&iwdev
->sc_dev
,
3541 "disconnect event failed %s: - cm_id = %p\n",
3545 i40iw_qp_disconnect(iwqp
);
3546 cm_id
->provider_data
= iwqp
;
3547 ret
= i40iw_send_cm_event(NULL
, cm_id
, IW_CM_EVENT_CLOSE
, 0);
3549 i40iw_debug(&iwdev
->sc_dev
,
3551 "close event failed %s: - cm_id = %p\n",
3553 cm_id
->rem_ref(cm_id
);
3559 * i40iw_disconnect_worker - worker for connection close
3560 * @work: points or disconn structure
3562 static void i40iw_disconnect_worker(struct work_struct
*work
)
3564 struct disconn_work
*dwork
= container_of(work
, struct disconn_work
, work
);
3565 struct i40iw_qp
*iwqp
= dwork
->iwqp
;
3568 i40iw_cm_disconn_true(iwqp
);
3569 i40iw_rem_ref(&iwqp
->ibqp
);
3573 * i40iw_accept - registered call for connection to be accepted
3574 * @cm_id: cm information for passive connection
3575 * @conn_param: accpet parameters
3577 int i40iw_accept(struct iw_cm_id
*cm_id
, struct iw_cm_conn_param
*conn_param
)
3580 struct i40iw_qp
*iwqp
;
3581 struct i40iw_device
*iwdev
;
3582 struct i40iw_sc_dev
*dev
;
3583 struct i40iw_cm_node
*cm_node
;
3584 struct ib_qp_attr attr
;
3587 struct i40iw_pd
*iwpd
;
3589 struct i40iw_kmem_info accept
;
3590 enum i40iw_status_code status
;
3593 memset(&attr
, 0, sizeof(attr
));
3594 ibqp
= i40iw_get_qp(cm_id
->device
, conn_param
->qpn
);
3598 iwqp
= to_iwqp(ibqp
);
3599 iwdev
= iwqp
->iwdev
;
3600 dev
= &iwdev
->sc_dev
;
3601 cm_node
= (struct i40iw_cm_node
*)cm_id
->provider_data
;
3603 if (((struct sockaddr_in
*)&cm_id
->local_addr
)->sin_family
== AF_INET
) {
3604 cm_node
->ipv4
= true;
3605 cm_node
->vlan_id
= i40iw_get_vlan_ipv4(cm_node
->loc_addr
);
3607 cm_node
->ipv4
= false;
3608 i40iw_netdev_vlan_ipv6(cm_node
->loc_addr
, &cm_node
->vlan_id
);
3610 i40iw_debug(cm_node
->dev
,
3612 "Accept vlan_id=%d\n",
3614 if (cm_node
->state
== I40IW_CM_STATE_LISTENER_DESTROYED
) {
3615 if (cm_node
->loopbackpartner
)
3616 i40iw_rem_ref_cm_node(cm_node
->loopbackpartner
);
3617 i40iw_rem_ref_cm_node(cm_node
);
3621 passive_state
= atomic_add_return(1, &cm_node
->passive_state
);
3622 if (passive_state
== I40IW_SEND_RESET_EVENT
) {
3623 i40iw_rem_ref_cm_node(cm_node
);
3627 cm_node
->cm_core
->stats_accepts
++;
3628 iwqp
->cm_node
= (void *)cm_node
;
3629 cm_node
->iwqp
= iwqp
;
3631 buf_len
= conn_param
->private_data_len
+ I40IW_MAX_IETF_SIZE
;
3633 status
= i40iw_allocate_dma_mem(dev
->hw
, &iwqp
->ietf_mem
, buf_len
, 1);
3637 cm_node
->pdata
.size
= conn_param
->private_data_len
;
3638 accept
.addr
= iwqp
->ietf_mem
.va
;
3639 accept
.size
= i40iw_cm_build_mpa_frame(cm_node
, &accept
, MPA_KEY_REPLY
);
3640 memcpy(accept
.addr
+ accept
.size
, conn_param
->private_data
,
3641 conn_param
->private_data_len
);
3643 /* setup our first outgoing iWarp send WQE (the IETF frame response) */
3644 if ((cm_node
->ipv4
&&
3645 !i40iw_ipv4_is_loopback(cm_node
->loc_addr
[0], cm_node
->rem_addr
[0])) ||
3647 !i40iw_ipv6_is_loopback(cm_node
->loc_addr
, cm_node
->rem_addr
))) {
3649 tagged_offset
= (uintptr_t)iwqp
->ietf_mem
.va
;
3650 ibmr
= i40iw_reg_phys_mr(&iwpd
->ibpd
,
3653 IB_ACCESS_LOCAL_WRITE
,
3656 i40iw_free_dma_mem(dev
->hw
, &iwqp
->ietf_mem
);
3660 ibmr
->pd
= &iwpd
->ibpd
;
3661 ibmr
->device
= iwpd
->ibpd
.device
;
3662 iwqp
->lsmm_mr
= ibmr
;
3664 iwqp
->sc_qp
.qp_uk
.sq_base
= kmap(iwqp
->page
);
3665 dev
->iw_priv_qp_ops
->qp_send_lsmm(&iwqp
->sc_qp
,
3667 (accept
.size
+ conn_param
->private_data_len
),
3672 iwqp
->sc_qp
.qp_uk
.sq_base
= kmap(iwqp
->page
);
3673 dev
->iw_priv_qp_ops
->qp_send_lsmm(&iwqp
->sc_qp
, NULL
, 0, 0);
3679 iwqp
->cm_id
= cm_id
;
3680 cm_node
->cm_id
= cm_id
;
3682 cm_id
->provider_data
= (void *)iwqp
;
3683 iwqp
->active_conn
= 0;
3685 cm_node
->lsmm_size
= accept
.size
+ conn_param
->private_data_len
;
3686 i40iw_cm_init_tsa_conn(iwqp
, cm_node
);
3687 cm_id
->add_ref(cm_id
);
3688 i40iw_add_ref(&iwqp
->ibqp
);
3690 attr
.qp_state
= IB_QPS_RTS
;
3691 cm_node
->qhash_set
= false;
3692 i40iw_modify_qp(&iwqp
->ibqp
, &attr
, IB_QP_STATE
, NULL
);
3694 cm_node
->accelerated
= 1;
3696 i40iw_send_cm_event(cm_node
, cm_id
, IW_CM_EVENT_ESTABLISHED
, 0);
3698 i40iw_debug(dev
, I40IW_DEBUG_CM
, "error sending cm event - ESTABLISHED\n");
3700 if (cm_node
->loopbackpartner
) {
3701 cm_node
->loopbackpartner
->pdata
.size
= conn_param
->private_data_len
;
3703 /* copy entire MPA frame to our cm_node's frame */
3704 memcpy(cm_node
->loopbackpartner
->pdata_buf
,
3705 conn_param
->private_data
,
3706 conn_param
->private_data_len
);
3707 i40iw_create_event(cm_node
->loopbackpartner
, I40IW_CM_EVENT_CONNECTED
);
3710 if (cm_node
->accept_pend
) {
3711 atomic_dec(&cm_node
->listener
->pend_accepts_cnt
);
3712 cm_node
->accept_pend
= 0;
3718 * i40iw_reject - registered call for connection to be rejected
3719 * @cm_id: cm information for passive connection
3720 * @pdata: private data to be sent
3721 * @pdata_len: private data length
3723 int i40iw_reject(struct iw_cm_id
*cm_id
, const void *pdata
, u8 pdata_len
)
3725 struct i40iw_device
*iwdev
;
3726 struct i40iw_cm_node
*cm_node
;
3727 struct i40iw_cm_node
*loopback
;
3729 cm_node
= (struct i40iw_cm_node
*)cm_id
->provider_data
;
3730 loopback
= cm_node
->loopbackpartner
;
3731 cm_node
->cm_id
= cm_id
;
3732 cm_node
->pdata
.size
= pdata_len
;
3734 iwdev
= to_iwdev(cm_id
->device
);
3737 cm_node
->cm_core
->stats_rejects
++;
3739 if (pdata_len
+ sizeof(struct ietf_mpa_v2
) > MAX_CM_BUFFER
)
3743 memcpy(&loopback
->pdata_buf
, pdata
, pdata_len
);
3744 loopback
->pdata
.size
= pdata_len
;
3747 return i40iw_cm_reject(cm_node
, pdata
, pdata_len
);
3751 * i40iw_connect - registered call for connection to be established
3752 * @cm_id: cm information for passive connection
3753 * @conn_param: Information about the connection
3755 int i40iw_connect(struct iw_cm_id
*cm_id
, struct iw_cm_conn_param
*conn_param
)
3758 struct i40iw_qp
*iwqp
;
3759 struct i40iw_device
*iwdev
;
3760 struct i40iw_cm_node
*cm_node
;
3761 struct i40iw_cm_info cm_info
;
3762 struct sockaddr_in
*laddr
;
3763 struct sockaddr_in
*raddr
;
3764 struct sockaddr_in6
*laddr6
;
3765 struct sockaddr_in6
*raddr6
;
3767 unsigned long flags
;
3769 ibqp
= i40iw_get_qp(cm_id
->device
, conn_param
->qpn
);
3772 iwqp
= to_iwqp(ibqp
);
3775 iwdev
= to_iwdev(iwqp
->ibqp
.device
);
3779 laddr
= (struct sockaddr_in
*)&cm_id
->m_local_addr
;
3780 raddr
= (struct sockaddr_in
*)&cm_id
->m_remote_addr
;
3781 laddr6
= (struct sockaddr_in6
*)&cm_id
->m_local_addr
;
3782 raddr6
= (struct sockaddr_in6
*)&cm_id
->m_remote_addr
;
3784 if (!(laddr
->sin_port
) || !(raddr
->sin_port
))
3787 iwqp
->active_conn
= 1;
3789 cm_id
->provider_data
= iwqp
;
3791 /* set up the connection params for the node */
3792 if (cm_id
->remote_addr
.ss_family
== AF_INET
) {
3793 cm_info
.ipv4
= true;
3794 memset(cm_info
.loc_addr
, 0, sizeof(cm_info
.loc_addr
));
3795 memset(cm_info
.rem_addr
, 0, sizeof(cm_info
.rem_addr
));
3796 cm_info
.loc_addr
[0] = ntohl(laddr
->sin_addr
.s_addr
);
3797 cm_info
.rem_addr
[0] = ntohl(raddr
->sin_addr
.s_addr
);
3798 cm_info
.loc_port
= ntohs(laddr
->sin_port
);
3799 cm_info
.rem_port
= ntohs(raddr
->sin_port
);
3800 cm_info
.vlan_id
= i40iw_get_vlan_ipv4(cm_info
.loc_addr
);
3802 cm_info
.ipv4
= false;
3803 i40iw_copy_ip_ntohl(cm_info
.loc_addr
,
3804 laddr6
->sin6_addr
.in6_u
.u6_addr32
);
3805 i40iw_copy_ip_ntohl(cm_info
.rem_addr
,
3806 raddr6
->sin6_addr
.in6_u
.u6_addr32
);
3807 cm_info
.loc_port
= ntohs(laddr6
->sin6_port
);
3808 cm_info
.rem_port
= ntohs(raddr6
->sin6_port
);
3809 i40iw_netdev_vlan_ipv6(cm_info
.loc_addr
, &cm_info
.vlan_id
);
3811 cm_info
.cm_id
= cm_id
;
3812 cm_info
.tos
= cm_id
->tos
;
3813 cm_info
.user_pri
= rt_tos2priority(cm_id
->tos
);
3814 i40iw_debug(&iwdev
->sc_dev
, I40IW_DEBUG_DCB
, "%s TOS:[%d] UP:[%d]\n",
3815 __func__
, cm_id
->tos
, cm_info
.user_pri
);
3816 cm_id
->add_ref(cm_id
);
3817 cm_node
= i40iw_create_cm_node(&iwdev
->cm_core
, iwdev
,
3818 conn_param
->private_data_len
,
3819 (void *)conn_param
->private_data
,
3822 if (IS_ERR(cm_node
)) {
3823 ret
= PTR_ERR(cm_node
);
3824 cm_id
->rem_ref(cm_id
);
3828 if ((cm_info
.ipv4
&& (laddr
->sin_addr
.s_addr
!= raddr
->sin_addr
.s_addr
)) ||
3829 (!cm_info
.ipv4
&& memcmp(laddr6
->sin6_addr
.in6_u
.u6_addr32
,
3830 raddr6
->sin6_addr
.in6_u
.u6_addr32
,
3831 sizeof(laddr6
->sin6_addr
.in6_u
.u6_addr32
)))) {
3832 if (i40iw_manage_qhash(iwdev
, &cm_info
, I40IW_QHASH_TYPE_TCP_ESTABLISHED
,
3833 I40IW_QHASH_MANAGE_TYPE_ADD
, NULL
, true)) {
3837 cm_node
->qhash_set
= true;
3840 spin_lock_irqsave(&iwdev
->cm_core
.ht_lock
, flags
);
3841 if (!test_and_set_bit(cm_info
.loc_port
, iwdev
->cm_core
.active_side_ports
)) {
3842 spin_unlock_irqrestore(&iwdev
->cm_core
.ht_lock
, flags
);
3843 if (i40iw_manage_apbvt(iwdev
, cm_info
.loc_port
, I40IW_MANAGE_APBVT_ADD
)) {
3848 spin_unlock_irqrestore(&iwdev
->cm_core
.ht_lock
, flags
);
3851 cm_node
->apbvt_set
= true;
3852 i40iw_record_ird_ord(cm_node
, (u16
)conn_param
->ird
, (u16
)conn_param
->ord
);
3853 if (cm_node
->send_rdma0_op
== SEND_RDMA_READ_ZERO
&&
3855 cm_node
->ord_size
= 1;
3857 iwqp
->cm_node
= cm_node
;
3858 cm_node
->iwqp
= iwqp
;
3859 iwqp
->cm_id
= cm_id
;
3860 i40iw_add_ref(&iwqp
->ibqp
);
3862 if (cm_node
->state
!= I40IW_CM_STATE_OFFLOADED
) {
3863 cm_node
->state
= I40IW_CM_STATE_SYN_SENT
;
3864 ret
= i40iw_send_syn(cm_node
, 0);
3869 if (cm_node
->loopbackpartner
) {
3870 cm_node
->loopbackpartner
->state
= I40IW_CM_STATE_MPAREQ_RCVD
;
3871 i40iw_create_event(cm_node
->loopbackpartner
,
3872 I40IW_CM_EVENT_MPA_REQ
);
3875 i40iw_debug(cm_node
->dev
,
3877 "Api - connect(): port=0x%04x, cm_node=%p, cm_id = %p.\n",
3886 i40iw_debug(&iwdev
->sc_dev
,
3888 "Api - connect() FAILED: dest addr=%pI4",
3891 i40iw_debug(&iwdev
->sc_dev
,
3893 "Api - connect() FAILED: dest addr=%pI6",
3896 i40iw_rem_ref_cm_node(cm_node
);
3897 cm_id
->rem_ref(cm_id
);
3898 iwdev
->cm_core
.stats_connect_errs
++;
3903 * i40iw_create_listen - registered call creating listener
3904 * @cm_id: cm information for passive connection
3905 * @backlog: to max accept pending count
3907 int i40iw_create_listen(struct iw_cm_id
*cm_id
, int backlog
)
3909 struct i40iw_device
*iwdev
;
3910 struct i40iw_cm_listener
*cm_listen_node
;
3911 struct i40iw_cm_info cm_info
;
3912 enum i40iw_status_code ret
;
3913 struct sockaddr_in
*laddr
;
3914 struct sockaddr_in6
*laddr6
;
3915 bool wildcard
= false;
3917 iwdev
= to_iwdev(cm_id
->device
);
3921 laddr
= (struct sockaddr_in
*)&cm_id
->m_local_addr
;
3922 laddr6
= (struct sockaddr_in6
*)&cm_id
->m_local_addr
;
3923 memset(&cm_info
, 0, sizeof(cm_info
));
3924 if (laddr
->sin_family
== AF_INET
) {
3925 cm_info
.ipv4
= true;
3926 cm_info
.loc_addr
[0] = ntohl(laddr
->sin_addr
.s_addr
);
3927 cm_info
.loc_port
= ntohs(laddr
->sin_port
);
3929 if (laddr
->sin_addr
.s_addr
!= INADDR_ANY
)
3930 cm_info
.vlan_id
= i40iw_get_vlan_ipv4(cm_info
.loc_addr
);
3935 cm_info
.ipv4
= false;
3936 i40iw_copy_ip_ntohl(cm_info
.loc_addr
,
3937 laddr6
->sin6_addr
.in6_u
.u6_addr32
);
3938 cm_info
.loc_port
= ntohs(laddr6
->sin6_port
);
3939 if (ipv6_addr_type(&laddr6
->sin6_addr
) != IPV6_ADDR_ANY
)
3940 i40iw_netdev_vlan_ipv6(cm_info
.loc_addr
,
3945 cm_info
.backlog
= backlog
;
3946 cm_info
.cm_id
= cm_id
;
3948 cm_listen_node
= i40iw_make_listen_node(&iwdev
->cm_core
, iwdev
, &cm_info
);
3949 if (!cm_listen_node
) {
3950 i40iw_pr_err("cm_listen_node == NULL\n");
3954 cm_id
->provider_data
= cm_listen_node
;
3956 cm_listen_node
->tos
= cm_id
->tos
;
3957 cm_listen_node
->user_pri
= rt_tos2priority(cm_id
->tos
);
3958 cm_info
.user_pri
= cm_listen_node
->user_pri
;
3960 if (!cm_listen_node
->reused_node
) {
3963 ret
= i40iw_add_mqh_4(iwdev
,
3967 ret
= i40iw_add_mqh_6(iwdev
,
3973 ret
= i40iw_manage_apbvt(iwdev
,
3975 I40IW_MANAGE_APBVT_ADD
);
3980 ret
= i40iw_manage_qhash(iwdev
,
3982 I40IW_QHASH_TYPE_TCP_SYN
,
3983 I40IW_QHASH_MANAGE_TYPE_ADD
,
3988 cm_listen_node
->qhash_set
= true;
3989 ret
= i40iw_manage_apbvt(iwdev
,
3991 I40IW_MANAGE_APBVT_ADD
);
3996 cm_id
->add_ref(cm_id
);
3997 cm_listen_node
->cm_core
->stats_listen_created
++;
4000 i40iw_cm_del_listen(&iwdev
->cm_core
, (void *)cm_listen_node
, false);
4005 * i40iw_destroy_listen - registered call to destroy listener
4006 * @cm_id: cm information for passive connection
4008 int i40iw_destroy_listen(struct iw_cm_id
*cm_id
)
4010 struct i40iw_device
*iwdev
;
4012 iwdev
= to_iwdev(cm_id
->device
);
4013 if (cm_id
->provider_data
)
4014 i40iw_cm_del_listen(&iwdev
->cm_core
, cm_id
->provider_data
, true);
4016 i40iw_pr_err("cm_id->provider_data was NULL\n");
4018 cm_id
->rem_ref(cm_id
);
4024 * i40iw_cm_event_connected - handle connected active node
4025 * @event: the info for cm_node of connection
4027 static void i40iw_cm_event_connected(struct i40iw_cm_event
*event
)
4029 struct i40iw_qp
*iwqp
;
4030 struct i40iw_device
*iwdev
;
4031 struct i40iw_cm_node
*cm_node
;
4032 struct i40iw_sc_dev
*dev
;
4033 struct ib_qp_attr attr
;
4034 struct iw_cm_id
*cm_id
;
4038 cm_node
= event
->cm_node
;
4039 cm_id
= cm_node
->cm_id
;
4040 iwqp
= (struct i40iw_qp
*)cm_id
->provider_data
;
4041 iwdev
= to_iwdev(iwqp
->ibqp
.device
);
4042 dev
= &iwdev
->sc_dev
;
4044 if (iwqp
->destroyed
) {
4045 status
= -ETIMEDOUT
;
4048 i40iw_cm_init_tsa_conn(iwqp
, cm_node
);
4049 read0
= (cm_node
->send_rdma0_op
== SEND_RDMA_READ_ZERO
);
4051 iwqp
->sc_qp
.qp_uk
.sq_base
= kmap(iwqp
->page
);
4052 dev
->iw_priv_qp_ops
->qp_send_rtt(&iwqp
->sc_qp
, read0
);
4056 memset(&attr
, 0, sizeof(attr
));
4057 attr
.qp_state
= IB_QPS_RTS
;
4058 cm_node
->qhash_set
= false;
4059 i40iw_modify_qp(&iwqp
->ibqp
, &attr
, IB_QP_STATE
, NULL
);
4061 cm_node
->accelerated
= 1;
4062 status
= i40iw_send_cm_event(cm_node
, cm_id
, IW_CM_EVENT_CONNECT_REPLY
,
4065 i40iw_debug(dev
, I40IW_DEBUG_CM
, "error sending cm event - CONNECT_REPLY\n");
4071 cm_id
->provider_data
= NULL
;
4072 i40iw_send_cm_event(event
->cm_node
,
4074 IW_CM_EVENT_CONNECT_REPLY
,
4076 cm_id
->rem_ref(cm_id
);
4077 i40iw_rem_ref_cm_node(event
->cm_node
);
4081 * i40iw_cm_event_reset - handle reset
4082 * @event: the info for cm_node of connection
4084 static void i40iw_cm_event_reset(struct i40iw_cm_event
*event
)
4086 struct i40iw_cm_node
*cm_node
= event
->cm_node
;
4087 struct iw_cm_id
*cm_id
= cm_node
->cm_id
;
4088 struct i40iw_qp
*iwqp
;
4093 iwqp
= cm_id
->provider_data
;
4097 i40iw_debug(cm_node
->dev
,
4099 "reset event %p - cm_id = %p\n",
4100 event
->cm_node
, cm_id
);
4103 i40iw_send_cm_event(cm_node
, cm_node
->cm_id
, IW_CM_EVENT_DISCONNECT
, -ECONNRESET
);
4104 i40iw_send_cm_event(cm_node
, cm_node
->cm_id
, IW_CM_EVENT_CLOSE
, 0);
4108 * i40iw_cm_event_handler - worker thread callback to send event to cm upper layer
4109 * @work: pointer of cm event info.
4111 static void i40iw_cm_event_handler(struct work_struct
*work
)
4113 struct i40iw_cm_event
*event
= container_of(work
,
4114 struct i40iw_cm_event
,
4116 struct i40iw_cm_node
*cm_node
;
4118 if (!event
|| !event
->cm_node
|| !event
->cm_node
->cm_core
)
4121 cm_node
= event
->cm_node
;
4123 switch (event
->type
) {
4124 case I40IW_CM_EVENT_MPA_REQ
:
4125 i40iw_send_cm_event(cm_node
,
4127 IW_CM_EVENT_CONNECT_REQUEST
,
4130 case I40IW_CM_EVENT_RESET
:
4131 i40iw_cm_event_reset(event
);
4133 case I40IW_CM_EVENT_CONNECTED
:
4134 if (!event
->cm_node
->cm_id
||
4135 (event
->cm_node
->state
!= I40IW_CM_STATE_OFFLOADED
))
4137 i40iw_cm_event_connected(event
);
4139 case I40IW_CM_EVENT_MPA_REJECT
:
4140 if (!event
->cm_node
->cm_id
||
4141 (cm_node
->state
== I40IW_CM_STATE_OFFLOADED
))
4143 i40iw_send_cm_event(cm_node
,
4145 IW_CM_EVENT_CONNECT_REPLY
,
4148 case I40IW_CM_EVENT_ABORTED
:
4149 if (!event
->cm_node
->cm_id
||
4150 (event
->cm_node
->state
== I40IW_CM_STATE_OFFLOADED
))
4152 i40iw_event_connect_error(event
);
4155 i40iw_pr_err("event type = %d\n", event
->type
);
4159 event
->cm_info
.cm_id
->rem_ref(event
->cm_info
.cm_id
);
4160 i40iw_rem_ref_cm_node(event
->cm_node
);
4165 * i40iw_cm_post_event - queue event request for worker thread
4166 * @event: cm node's info for up event call
4168 static void i40iw_cm_post_event(struct i40iw_cm_event
*event
)
4170 atomic_inc(&event
->cm_node
->ref_count
);
4171 event
->cm_info
.cm_id
->add_ref(event
->cm_info
.cm_id
);
4172 INIT_WORK(&event
->event_work
, i40iw_cm_event_handler
);
4174 queue_work(event
->cm_node
->cm_core
->event_wq
, &event
->event_work
);
4178 * i40iw_qhash_ctrl - enable/disable qhash for list
4179 * @iwdev: device pointer
4180 * @parent_listen_node: parent listen node
4181 * @nfo: cm info node
4182 * @ipaddr: Pointer to IPv4 or IPv6 address
4183 * @ipv4: flag indicating IPv4 when true
4184 * @ifup: flag indicating interface up when true
4186 * Enables or disables the qhash for the node in the child
4187 * listen list that matches ipaddr. If no matching IP was found
4188 * it will allocate and add a new child listen node to the
4189 * parent listen node. The listen_list_lock is assumed to be
4192 static void i40iw_qhash_ctrl(struct i40iw_device
*iwdev
,
4193 struct i40iw_cm_listener
*parent_listen_node
,
4194 struct i40iw_cm_info
*nfo
,
4195 u32
*ipaddr
, bool ipv4
, bool ifup
)
4197 struct list_head
*child_listen_list
= &parent_listen_node
->child_listen_list
;
4198 struct i40iw_cm_listener
*child_listen_node
;
4199 struct list_head
*pos
, *tpos
;
4200 enum i40iw_status_code ret
;
4201 bool node_allocated
= false;
4202 enum i40iw_quad_hash_manage_type op
=
4203 ifup
? I40IW_QHASH_MANAGE_TYPE_ADD
: I40IW_QHASH_MANAGE_TYPE_DELETE
;
4205 list_for_each_safe(pos
, tpos
, child_listen_list
) {
4208 struct i40iw_cm_listener
,
4210 if (!memcmp(child_listen_node
->loc_addr
, ipaddr
, ipv4
? 4 : 16))
4214 /* if not found then add a child listener if interface is going up */
4217 child_listen_node
= kzalloc(sizeof(*child_listen_node
), GFP_ATOMIC
);
4218 if (!child_listen_node
)
4220 node_allocated
= true;
4221 memcpy(child_listen_node
, parent_listen_node
, sizeof(*child_listen_node
));
4223 memcpy(child_listen_node
->loc_addr
, ipaddr
, ipv4
? 4 : 16);
4226 memcpy(nfo
->loc_addr
,
4227 child_listen_node
->loc_addr
,
4228 sizeof(nfo
->loc_addr
));
4229 nfo
->vlan_id
= child_listen_node
->vlan_id
;
4230 ret
= i40iw_manage_qhash(iwdev
, nfo
,
4231 I40IW_QHASH_TYPE_TCP_SYN
,
4235 child_listen_node
->qhash_set
= ifup
;
4237 list_add(&child_listen_node
->child_listen_list
,
4238 &parent_listen_node
->child_listen_list
);
4239 } else if (node_allocated
) {
4240 kfree(child_listen_node
);
4245 * i40iw_cm_disconnect_all - disconnect all connected qp's
4246 * @iwdev: device pointer
4248 void i40iw_cm_disconnect_all(struct i40iw_device
*iwdev
)
4250 struct i40iw_cm_core
*cm_core
= &iwdev
->cm_core
;
4251 struct list_head
*list_core_temp
;
4252 struct list_head
*list_node
;
4253 struct i40iw_cm_node
*cm_node
;
4254 unsigned long flags
;
4255 struct list_head connected_list
;
4256 struct ib_qp_attr attr
;
4258 INIT_LIST_HEAD(&connected_list
);
4259 spin_lock_irqsave(&cm_core
->ht_lock
, flags
);
4260 list_for_each_safe(list_node
, list_core_temp
, &cm_core
->connected_nodes
) {
4261 cm_node
= container_of(list_node
, struct i40iw_cm_node
, list
);
4262 atomic_inc(&cm_node
->ref_count
);
4263 list_add(&cm_node
->connected_entry
, &connected_list
);
4265 spin_unlock_irqrestore(&cm_core
->ht_lock
, flags
);
4267 list_for_each_safe(list_node
, list_core_temp
, &connected_list
) {
4268 cm_node
= container_of(list_node
, struct i40iw_cm_node
, connected_entry
);
4269 attr
.qp_state
= IB_QPS_ERR
;
4270 i40iw_modify_qp(&cm_node
->iwqp
->ibqp
, &attr
, IB_QP_STATE
, NULL
);
4272 i40iw_cm_disconn(cm_node
->iwqp
);
4273 i40iw_rem_ref_cm_node(cm_node
);
4278 * i40iw_ifdown_notify - process an ifdown on an interface
4279 * @iwdev: device pointer
4280 * @ipaddr: Pointer to IPv4 or IPv6 address
4281 * @ipv4: flag indicating IPv4 when true
4282 * @ifup: flag indicating interface up when true
4284 void i40iw_if_notify(struct i40iw_device
*iwdev
, struct net_device
*netdev
,
4285 u32
*ipaddr
, bool ipv4
, bool ifup
)
4287 struct i40iw_cm_core
*cm_core
= &iwdev
->cm_core
;
4288 unsigned long flags
;
4289 struct i40iw_cm_listener
*listen_node
;
4290 static const u32 ip_zero
[4] = { 0, 0, 0, 0 };
4291 struct i40iw_cm_info nfo
;
4292 u16 vlan_id
= rdma_vlan_dev_vlan_id(netdev
);
4293 enum i40iw_status_code ret
;
4294 enum i40iw_quad_hash_manage_type op
=
4295 ifup
? I40IW_QHASH_MANAGE_TYPE_ADD
: I40IW_QHASH_MANAGE_TYPE_DELETE
;
4297 /* Disable or enable qhash for listeners */
4298 spin_lock_irqsave(&cm_core
->listen_list_lock
, flags
);
4299 list_for_each_entry(listen_node
, &cm_core
->listen_nodes
, list
) {
4300 if (vlan_id
== listen_node
->vlan_id
&&
4301 (!memcmp(listen_node
->loc_addr
, ipaddr
, ipv4
? 4 : 16) ||
4302 !memcmp(listen_node
->loc_addr
, ip_zero
, ipv4
? 4 : 16))) {
4303 memcpy(nfo
.loc_addr
, listen_node
->loc_addr
,
4304 sizeof(nfo
.loc_addr
));
4305 nfo
.loc_port
= listen_node
->loc_port
;
4306 nfo
.ipv4
= listen_node
->ipv4
;
4307 nfo
.vlan_id
= listen_node
->vlan_id
;
4308 nfo
.user_pri
= listen_node
->user_pri
;
4309 if (!list_empty(&listen_node
->child_listen_list
)) {
4310 i40iw_qhash_ctrl(iwdev
,
4313 ipaddr
, ipv4
, ifup
);
4314 } else if (memcmp(listen_node
->loc_addr
, ip_zero
,
4316 ret
= i40iw_manage_qhash(iwdev
,
4318 I40IW_QHASH_TYPE_TCP_SYN
,
4323 listen_node
->qhash_set
= ifup
;
4327 spin_unlock_irqrestore(&cm_core
->listen_list_lock
, flags
);
4329 /* disconnect any connected qp's on ifdown */
4331 i40iw_cm_disconnect_all(iwdev
);