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
72 * @buf: puda buffer to free
74 void i40iw_free_sqbuf(struct i40iw_sc_dev
*dev
, void *bufp
)
76 struct i40iw_puda_buf
*buf
= (struct i40iw_puda_buf
*)bufp
;
77 struct i40iw_puda_rsrc
*ilq
= dev
->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
;
227 * i40iw_get_cmevent_info - for cm event upcall
228 * @cm_node: connection's node
229 * @cm_id: upper layers cm struct for the event
230 * @event: upper layer's cm event
232 static inline void i40iw_get_cmevent_info(struct i40iw_cm_node
*cm_node
,
233 struct iw_cm_id
*cm_id
,
234 struct iw_cm_event
*event
)
236 memcpy(&event
->local_addr
, &cm_id
->m_local_addr
,
237 sizeof(event
->local_addr
));
238 memcpy(&event
->remote_addr
, &cm_id
->m_remote_addr
,
239 sizeof(event
->remote_addr
));
241 event
->private_data
= (void *)cm_node
->pdata_buf
;
242 event
->private_data_len
= (u8
)cm_node
->pdata
.size
;
243 event
->ird
= cm_node
->ird_size
;
244 event
->ord
= cm_node
->ord_size
;
249 * i40iw_send_cm_event - upcall cm's event handler
250 * @cm_node: connection's node
251 * @cm_id: upper layer's cm info struct
252 * @type: Event type to indicate
253 * @status: status for the event type
255 static int i40iw_send_cm_event(struct i40iw_cm_node
*cm_node
,
256 struct iw_cm_id
*cm_id
,
257 enum iw_cm_event_type type
,
260 struct iw_cm_event event
;
262 memset(&event
, 0, sizeof(event
));
264 event
.status
= status
;
266 case IW_CM_EVENT_CONNECT_REQUEST
:
268 i40iw_fill_sockaddr4(cm_node
, &event
);
270 i40iw_fill_sockaddr6(cm_node
, &event
);
271 event
.provider_data
= (void *)cm_node
;
272 event
.private_data
= (void *)cm_node
->pdata_buf
;
273 event
.private_data_len
= (u8
)cm_node
->pdata
.size
;
275 case IW_CM_EVENT_CONNECT_REPLY
:
276 i40iw_get_cmevent_info(cm_node
, cm_id
, &event
);
278 case IW_CM_EVENT_ESTABLISHED
:
279 event
.ird
= cm_node
->ird_size
;
280 event
.ord
= cm_node
->ord_size
;
282 case IW_CM_EVENT_DISCONNECT
:
284 case IW_CM_EVENT_CLOSE
:
287 i40iw_pr_err("event type received type = %d\n", type
);
290 return cm_id
->event_handler(cm_id
, &event
);
294 * i40iw_create_event - create cm event
295 * @cm_node: connection's node
296 * @type: Event type to generate
298 static struct i40iw_cm_event
*i40iw_create_event(struct i40iw_cm_node
*cm_node
,
299 enum i40iw_cm_event_type type
)
301 struct i40iw_cm_event
*event
;
306 event
= kzalloc(sizeof(*event
), GFP_ATOMIC
);
312 event
->cm_node
= cm_node
;
313 memcpy(event
->cm_info
.rem_addr
, cm_node
->rem_addr
, sizeof(event
->cm_info
.rem_addr
));
314 memcpy(event
->cm_info
.loc_addr
, cm_node
->loc_addr
, sizeof(event
->cm_info
.loc_addr
));
315 event
->cm_info
.rem_port
= cm_node
->rem_port
;
316 event
->cm_info
.loc_port
= cm_node
->loc_port
;
317 event
->cm_info
.cm_id
= cm_node
->cm_id
;
319 i40iw_debug(cm_node
->dev
,
321 "node=%p event=%p type=%u dst=%pI4 src=%pI4\n",
325 event
->cm_info
.loc_addr
,
326 event
->cm_info
.rem_addr
);
328 i40iw_cm_post_event(event
);
333 * i40iw_free_retrans_entry - free send entry
334 * @cm_node: connection's node
336 static void i40iw_free_retrans_entry(struct i40iw_cm_node
*cm_node
)
338 struct i40iw_sc_dev
*dev
= cm_node
->dev
;
339 struct i40iw_timer_entry
*send_entry
;
341 send_entry
= cm_node
->send_entry
;
343 cm_node
->send_entry
= NULL
;
344 i40iw_free_sqbuf(dev
, (void *)send_entry
->sqbuf
);
346 atomic_dec(&cm_node
->ref_count
);
351 * i40iw_cleanup_retrans_entry - free send entry with lock
352 * @cm_node: connection's node
354 static void i40iw_cleanup_retrans_entry(struct i40iw_cm_node
*cm_node
)
358 spin_lock_irqsave(&cm_node
->retrans_list_lock
, flags
);
359 i40iw_free_retrans_entry(cm_node
);
360 spin_unlock_irqrestore(&cm_node
->retrans_list_lock
, flags
);
363 static bool is_remote_ne020_or_chelsio(struct i40iw_cm_node
*cm_node
)
365 if ((cm_node
->rem_mac
[0] == 0x0) &&
366 (((cm_node
->rem_mac
[1] == 0x12) && (cm_node
->rem_mac
[2] == 0x55)) ||
367 ((cm_node
->rem_mac
[1] == 0x07 && (cm_node
->rem_mac
[2] == 0x43)))))
373 * i40iw_form_cm_frame - get a free packet and build frame
374 * @cm_node: connection's node ionfo to use in frame
375 * @options: pointer to options info
376 * @hdr: pointer mpa header
377 * @pdata: pointer to private data
378 * @flags: indicates FIN or ACK
380 static struct i40iw_puda_buf
*i40iw_form_cm_frame(struct i40iw_cm_node
*cm_node
,
381 struct i40iw_kmem_info
*options
,
382 struct i40iw_kmem_info
*hdr
,
383 struct i40iw_kmem_info
*pdata
,
386 struct i40iw_puda_buf
*sqbuf
;
387 struct i40iw_sc_dev
*dev
= cm_node
->dev
;
392 struct ipv6hdr
*ip6h
;
395 u16 eth_hlen
= ETH_HLEN
;
400 sqbuf
= i40iw_puda_get_bufpool(dev
->ilq
);
406 opts_len
= (u32
)options
->size
;
412 pd_len
= pdata
->size
;
413 if (!is_remote_ne020_or_chelsio(cm_node
))
414 pd_len
+= MPA_ZERO_PAD_LEN
;
417 if (cm_node
->vlan_id
< VLAN_TAG_PRESENT
)
421 packetsize
= sizeof(*iph
) + sizeof(*tcph
);
423 packetsize
= sizeof(*ip6h
) + sizeof(*tcph
);
424 packetsize
+= opts_len
+ hdr_len
+ pd_len
;
426 memset(buf
, 0x00, eth_hlen
+ packetsize
);
428 sqbuf
->totallen
= packetsize
+ eth_hlen
;
429 sqbuf
->maclen
= eth_hlen
;
430 sqbuf
->tcphlen
= sizeof(*tcph
) + opts_len
;
431 sqbuf
->scratch
= (void *)cm_node
;
433 ethh
= (struct ethhdr
*)buf
;
439 iph
= (struct iphdr
*)buf
;
441 tcph
= (struct tcphdr
*)buf
;
442 buf
+= sizeof(*tcph
);
444 ether_addr_copy(ethh
->h_dest
, cm_node
->rem_mac
);
445 ether_addr_copy(ethh
->h_source
, cm_node
->loc_mac
);
446 if (cm_node
->vlan_id
< VLAN_TAG_PRESENT
) {
447 ((struct vlan_ethhdr
*)ethh
)->h_vlan_proto
= htons(ETH_P_8021Q
);
448 ((struct vlan_ethhdr
*)ethh
)->h_vlan_TCI
= htons(cm_node
->vlan_id
);
450 ((struct vlan_ethhdr
*)ethh
)->h_vlan_encapsulated_proto
= htons(ETH_P_IP
);
452 ethh
->h_proto
= htons(ETH_P_IP
);
455 iph
->version
= IPVERSION
;
456 iph
->ihl
= 5; /* 5 * 4Byte words, IP headr len */
458 iph
->tot_len
= htons(packetsize
);
459 iph
->id
= htons(++cm_node
->tcp_cntxt
.loc_id
);
461 iph
->frag_off
= htons(0x4000);
463 iph
->protocol
= IPPROTO_TCP
;
464 iph
->saddr
= htonl(cm_node
->loc_addr
[0]);
465 iph
->daddr
= htonl(cm_node
->rem_addr
[0]);
468 ip6h
= (struct ipv6hdr
*)buf
;
469 buf
+= sizeof(*ip6h
);
470 tcph
= (struct tcphdr
*)buf
;
471 buf
+= sizeof(*tcph
);
473 ether_addr_copy(ethh
->h_dest
, cm_node
->rem_mac
);
474 ether_addr_copy(ethh
->h_source
, cm_node
->loc_mac
);
475 if (cm_node
->vlan_id
< VLAN_TAG_PRESENT
) {
476 ((struct vlan_ethhdr
*)ethh
)->h_vlan_proto
= htons(ETH_P_8021Q
);
477 ((struct vlan_ethhdr
*)ethh
)->h_vlan_TCI
= htons(cm_node
->vlan_id
);
478 ((struct vlan_ethhdr
*)ethh
)->h_vlan_encapsulated_proto
= htons(ETH_P_IPV6
);
480 ethh
->h_proto
= htons(ETH_P_IPV6
);
483 ip6h
->flow_lbl
[0] = 0;
484 ip6h
->flow_lbl
[1] = 0;
485 ip6h
->flow_lbl
[2] = 0;
486 ip6h
->payload_len
= htons(packetsize
- sizeof(*ip6h
));
488 ip6h
->hop_limit
= 128;
489 i40iw_copy_ip_htonl(ip6h
->saddr
.in6_u
.u6_addr32
,
491 i40iw_copy_ip_htonl(ip6h
->daddr
.in6_u
.u6_addr32
,
495 tcph
->source
= htons(cm_node
->loc_port
);
496 tcph
->dest
= htons(cm_node
->rem_port
);
498 tcph
->seq
= htonl(cm_node
->tcp_cntxt
.loc_seq_num
);
500 if (flags
& SET_ACK
) {
501 cm_node
->tcp_cntxt
.loc_ack_num
= cm_node
->tcp_cntxt
.rcv_nxt
;
502 tcph
->ack_seq
= htonl(cm_node
->tcp_cntxt
.loc_ack_num
);
508 if (flags
& SET_SYN
) {
509 cm_node
->tcp_cntxt
.loc_seq_num
++;
512 cm_node
->tcp_cntxt
.loc_seq_num
+= hdr_len
+ pd_len
;
515 if (flags
& SET_FIN
) {
516 cm_node
->tcp_cntxt
.loc_seq_num
++;
523 tcph
->doff
= (u16
)((sizeof(*tcph
) + opts_len
+ 3) >> 2);
524 sqbuf
->tcphlen
= tcph
->doff
<< 2;
525 tcph
->window
= htons(cm_node
->tcp_cntxt
.rcv_wnd
);
529 memcpy(buf
, options
->addr
, opts_len
);
534 memcpy(buf
, hdr
->addr
, hdr_len
);
539 memcpy(buf
, pdata
->addr
, pd_len
);
541 atomic_set(&sqbuf
->refcount
, 1);
547 * i40iw_send_reset - Send RST packet
548 * @cm_node: connection's node
550 static int i40iw_send_reset(struct i40iw_cm_node
*cm_node
)
552 struct i40iw_puda_buf
*sqbuf
;
553 int flags
= SET_RST
| SET_ACK
;
555 sqbuf
= i40iw_form_cm_frame(cm_node
, NULL
, NULL
, NULL
, flags
);
557 i40iw_pr_err("no sqbuf\n");
561 return i40iw_schedule_cm_timer(cm_node
, sqbuf
, I40IW_TIMER_TYPE_SEND
, 0, 1);
565 * i40iw_active_open_err - send event for active side cm error
566 * @cm_node: connection's node
567 * @reset: Flag to send reset or not
569 static void i40iw_active_open_err(struct i40iw_cm_node
*cm_node
, bool reset
)
571 i40iw_cleanup_retrans_entry(cm_node
);
572 cm_node
->cm_core
->stats_connect_errs
++;
574 i40iw_debug(cm_node
->dev
,
576 "%s cm_node=%p state=%d\n",
580 atomic_inc(&cm_node
->ref_count
);
581 i40iw_send_reset(cm_node
);
584 cm_node
->state
= I40IW_CM_STATE_CLOSED
;
585 i40iw_create_event(cm_node
, I40IW_CM_EVENT_ABORTED
);
589 * i40iw_passive_open_err - handle passive side cm error
590 * @cm_node: connection's node
591 * @reset: send reset or just free cm_node
593 static void i40iw_passive_open_err(struct i40iw_cm_node
*cm_node
, bool reset
)
595 i40iw_cleanup_retrans_entry(cm_node
);
596 cm_node
->cm_core
->stats_passive_errs
++;
597 cm_node
->state
= I40IW_CM_STATE_CLOSED
;
598 i40iw_debug(cm_node
->dev
,
600 "%s cm_node=%p state =%d\n",
605 i40iw_send_reset(cm_node
);
607 i40iw_rem_ref_cm_node(cm_node
);
611 * i40iw_event_connect_error - to create connect error event
612 * @event: cm information for connect event
614 static void i40iw_event_connect_error(struct i40iw_cm_event
*event
)
616 struct i40iw_qp
*iwqp
;
617 struct iw_cm_id
*cm_id
;
619 cm_id
= event
->cm_node
->cm_id
;
623 iwqp
= cm_id
->provider_data
;
625 if (!iwqp
|| !iwqp
->iwdev
)
629 cm_id
->provider_data
= NULL
;
630 i40iw_send_cm_event(event
->cm_node
, cm_id
,
631 IW_CM_EVENT_CONNECT_REPLY
,
633 cm_id
->rem_ref(cm_id
);
634 i40iw_rem_ref_cm_node(event
->cm_node
);
638 * i40iw_process_options
639 * @cm_node: connection's node
640 * @optionsloc: point to start of options
641 * @optionsize: size of all options
642 * @syn_packet: flag if syn packet
644 static int i40iw_process_options(struct i40iw_cm_node
*cm_node
,
651 union all_known_options
*all_options
;
652 char got_mss_option
= 0;
654 while (offset
< optionsize
) {
655 all_options
= (union all_known_options
*)(optionsloc
+ offset
);
656 switch (all_options
->as_base
.optionnum
) {
657 case OPTION_NUMBER_END
:
660 case OPTION_NUMBER_NONE
:
663 case OPTION_NUMBER_MSS
:
664 i40iw_debug(cm_node
->dev
,
666 "%s: MSS Length: %d Offset: %d Size: %d\n",
668 all_options
->as_mss
.length
,
672 if (all_options
->as_mss
.length
!= 4)
674 tmp
= ntohs(all_options
->as_mss
.mss
);
675 if (tmp
> 0 && tmp
< cm_node
->tcp_cntxt
.mss
)
676 cm_node
->tcp_cntxt
.mss
= tmp
;
678 case OPTION_NUMBER_WINDOW_SCALE
:
679 cm_node
->tcp_cntxt
.snd_wscale
=
680 all_options
->as_windowscale
.shiftcount
;
683 i40iw_debug(cm_node
->dev
,
685 "TCP Option not understood: %x\n",
686 all_options
->as_base
.optionnum
);
689 offset
+= all_options
->as_base
.length
;
691 if (!got_mss_option
&& syn_packet
)
692 cm_node
->tcp_cntxt
.mss
= I40IW_CM_DEFAULT_MSS
;
697 * i40iw_handle_tcp_options -
698 * @cm_node: connection's node
699 * @tcph: pointer tcp header
700 * @optionsize: size of options rcvd
701 * @passive: active or passive flag
703 static int i40iw_handle_tcp_options(struct i40iw_cm_node
*cm_node
,
708 u8
*optionsloc
= (u8
*)&tcph
[1];
711 if (i40iw_process_options(cm_node
,
715 i40iw_debug(cm_node
->dev
,
717 "%s: Node %p, Sending RESET\n",
721 i40iw_passive_open_err(cm_node
, true);
723 i40iw_active_open_err(cm_node
, true);
728 cm_node
->tcp_cntxt
.snd_wnd
= ntohs(tcph
->window
) <<
729 cm_node
->tcp_cntxt
.snd_wscale
;
731 if (cm_node
->tcp_cntxt
.snd_wnd
> cm_node
->tcp_cntxt
.max_snd_wnd
)
732 cm_node
->tcp_cntxt
.max_snd_wnd
= cm_node
->tcp_cntxt
.snd_wnd
;
737 * i40iw_build_mpa_v1 - build a MPA V1 frame
738 * @cm_node: connection's node
739 * @mpa_key: to do read0 or write0
741 static void i40iw_build_mpa_v1(struct i40iw_cm_node
*cm_node
,
745 struct ietf_mpa_v1
*mpa_frame
= (struct ietf_mpa_v1
*)start_addr
;
748 case MPA_KEY_REQUEST
:
749 memcpy(mpa_frame
->key
, IEFT_MPA_KEY_REQ
, IETF_MPA_KEY_SIZE
);
752 memcpy(mpa_frame
->key
, IEFT_MPA_KEY_REP
, IETF_MPA_KEY_SIZE
);
757 mpa_frame
->flags
= IETF_MPA_FLAGS_CRC
;
758 mpa_frame
->rev
= cm_node
->mpa_frame_rev
;
759 mpa_frame
->priv_data_len
= htons(cm_node
->pdata
.size
);
763 * i40iw_build_mpa_v2 - build a MPA V2 frame
764 * @cm_node: connection's node
765 * @start_addr: buffer start address
766 * @mpa_key: to do read0 or write0
768 static void i40iw_build_mpa_v2(struct i40iw_cm_node
*cm_node
,
772 struct ietf_mpa_v2
*mpa_frame
= (struct ietf_mpa_v2
*)start_addr
;
773 struct ietf_rtr_msg
*rtr_msg
= &mpa_frame
->rtr_msg
;
775 /* initialize the upper 5 bytes of the frame */
776 i40iw_build_mpa_v1(cm_node
, start_addr
, mpa_key
);
777 mpa_frame
->flags
|= IETF_MPA_V2_FLAG
;
778 mpa_frame
->priv_data_len
+= htons(IETF_RTR_MSG_SIZE
);
780 /* initialize RTR msg */
781 if (cm_node
->mpav2_ird_ord
== IETF_NO_IRD_ORD
) {
782 rtr_msg
->ctrl_ird
= IETF_NO_IRD_ORD
;
783 rtr_msg
->ctrl_ord
= IETF_NO_IRD_ORD
;
785 rtr_msg
->ctrl_ird
= (cm_node
->ird_size
> IETF_NO_IRD_ORD
) ?
786 IETF_NO_IRD_ORD
: cm_node
->ird_size
;
787 rtr_msg
->ctrl_ord
= (cm_node
->ord_size
> IETF_NO_IRD_ORD
) ?
788 IETF_NO_IRD_ORD
: cm_node
->ord_size
;
791 rtr_msg
->ctrl_ird
|= IETF_PEER_TO_PEER
;
792 rtr_msg
->ctrl_ird
|= IETF_FLPDU_ZERO_LEN
;
795 case MPA_KEY_REQUEST
:
796 rtr_msg
->ctrl_ord
|= IETF_RDMA0_WRITE
;
797 rtr_msg
->ctrl_ord
|= IETF_RDMA0_READ
;
800 switch (cm_node
->send_rdma0_op
) {
801 case SEND_RDMA_WRITE_ZERO
:
802 rtr_msg
->ctrl_ord
|= IETF_RDMA0_WRITE
;
804 case SEND_RDMA_READ_ZERO
:
805 rtr_msg
->ctrl_ord
|= IETF_RDMA0_READ
;
812 rtr_msg
->ctrl_ird
= htons(rtr_msg
->ctrl_ird
);
813 rtr_msg
->ctrl_ord
= htons(rtr_msg
->ctrl_ord
);
817 * i40iw_cm_build_mpa_frame - build mpa frame for mpa version 1 or version 2
818 * @cm_node: connection's node
819 * @mpa: mpa: data buffer
820 * @mpa_key: to do read0 or write0
822 static int i40iw_cm_build_mpa_frame(struct i40iw_cm_node
*cm_node
,
823 struct i40iw_kmem_info
*mpa
,
828 switch (cm_node
->mpa_frame_rev
) {
830 hdr_len
= sizeof(struct ietf_mpa_v1
);
831 i40iw_build_mpa_v1(cm_node
, mpa
->addr
, mpa_key
);
834 hdr_len
= sizeof(struct ietf_mpa_v2
);
835 i40iw_build_mpa_v2(cm_node
, mpa
->addr
, mpa_key
);
845 * i40iw_send_mpa_request - active node send mpa request to passive node
846 * @cm_node: connection's node
848 static int i40iw_send_mpa_request(struct i40iw_cm_node
*cm_node
)
850 struct i40iw_puda_buf
*sqbuf
;
853 i40iw_pr_err("cm_node == NULL\n");
857 cm_node
->mpa_hdr
.addr
= &cm_node
->mpa_frame
;
858 cm_node
->mpa_hdr
.size
= i40iw_cm_build_mpa_frame(cm_node
,
861 if (!cm_node
->mpa_hdr
.size
) {
862 i40iw_pr_err("mpa size = %d\n", cm_node
->mpa_hdr
.size
);
866 sqbuf
= i40iw_form_cm_frame(cm_node
,
872 i40iw_pr_err("sq_buf == NULL\n");
875 return i40iw_schedule_cm_timer(cm_node
, sqbuf
, I40IW_TIMER_TYPE_SEND
, 1, 0);
879 * i40iw_send_mpa_reject -
880 * @cm_node: connection's node
881 * @pdata: reject data for connection
882 * @plen: length of reject data
884 static int i40iw_send_mpa_reject(struct i40iw_cm_node
*cm_node
,
888 struct i40iw_puda_buf
*sqbuf
;
889 struct i40iw_kmem_info priv_info
;
891 cm_node
->mpa_hdr
.addr
= &cm_node
->mpa_frame
;
892 cm_node
->mpa_hdr
.size
= i40iw_cm_build_mpa_frame(cm_node
,
896 cm_node
->mpa_frame
.flags
|= IETF_MPA_FLAGS_REJECT
;
897 priv_info
.addr
= (void *)pdata
;
898 priv_info
.size
= plen
;
900 sqbuf
= i40iw_form_cm_frame(cm_node
,
906 i40iw_pr_err("no sqbuf\n");
909 cm_node
->state
= I40IW_CM_STATE_FIN_WAIT1
;
910 return i40iw_schedule_cm_timer(cm_node
, sqbuf
, I40IW_TIMER_TYPE_SEND
, 1, 0);
914 * recv_mpa - process an IETF MPA frame
915 * @cm_node: connection's node
916 * @buffer: Data pointer
917 * @type: to return accept or reject
918 * @len: Len of mpa buffer
920 static int i40iw_parse_mpa(struct i40iw_cm_node
*cm_node
, u8
*buffer
, u32
*type
, u32 len
)
922 struct ietf_mpa_v1
*mpa_frame
;
923 struct ietf_mpa_v2
*mpa_v2_frame
;
924 struct ietf_rtr_msg
*rtr_msg
;
928 *type
= I40IW_MPA_REQUEST_ACCEPT
;
930 if (len
< sizeof(struct ietf_mpa_v1
)) {
931 i40iw_pr_err("ietf buffer small (%x)\n", len
);
935 mpa_frame
= (struct ietf_mpa_v1
*)buffer
;
936 mpa_hdr_len
= sizeof(struct ietf_mpa_v1
);
937 priv_data_len
= ntohs(mpa_frame
->priv_data_len
);
939 if (priv_data_len
> IETF_MAX_PRIV_DATA_LEN
) {
940 i40iw_pr_err("large pri_data %d\n", priv_data_len
);
943 if (mpa_frame
->rev
!= IETF_MPA_V1
&& mpa_frame
->rev
!= IETF_MPA_V2
) {
944 i40iw_pr_err("unsupported mpa rev = %d\n", mpa_frame
->rev
);
947 if (mpa_frame
->rev
> cm_node
->mpa_frame_rev
) {
948 i40iw_pr_err("rev %d\n", mpa_frame
->rev
);
951 cm_node
->mpa_frame_rev
= mpa_frame
->rev
;
953 if (cm_node
->state
!= I40IW_CM_STATE_MPAREQ_SENT
) {
954 if (memcmp(mpa_frame
->key
, IEFT_MPA_KEY_REQ
, IETF_MPA_KEY_SIZE
)) {
955 i40iw_pr_err("Unexpected MPA Key received\n");
959 if (memcmp(mpa_frame
->key
, IEFT_MPA_KEY_REP
, IETF_MPA_KEY_SIZE
)) {
960 i40iw_pr_err("Unexpected MPA Key received\n");
965 if (priv_data_len
+ mpa_hdr_len
> len
) {
966 i40iw_pr_err("ietf buffer len(%x + %x != %x)\n",
967 priv_data_len
, mpa_hdr_len
, len
);
970 if (len
> MAX_CM_BUFFER
) {
971 i40iw_pr_err("ietf buffer large len = %d\n", len
);
975 switch (mpa_frame
->rev
) {
982 mpa_v2_frame
= (struct ietf_mpa_v2
*)buffer
;
983 mpa_hdr_len
+= IETF_RTR_MSG_SIZE
;
984 rtr_msg
= &mpa_v2_frame
->rtr_msg
;
986 /* parse rtr message */
987 ctrl_ord
= ntohs(rtr_msg
->ctrl_ord
);
988 ctrl_ird
= ntohs(rtr_msg
->ctrl_ird
);
989 ird_size
= ctrl_ird
& IETF_NO_IRD_ORD
;
990 ord_size
= ctrl_ord
& IETF_NO_IRD_ORD
;
992 if (!(ctrl_ird
& IETF_PEER_TO_PEER
))
995 if (ird_size
== IETF_NO_IRD_ORD
|| ord_size
== IETF_NO_IRD_ORD
) {
996 cm_node
->mpav2_ird_ord
= IETF_NO_IRD_ORD
;
1000 if (cm_node
->state
!= I40IW_CM_STATE_MPAREQ_SENT
) {
1002 if (!ord_size
&& (ctrl_ord
& IETF_RDMA0_READ
))
1003 cm_node
->ird_size
= 1;
1004 if (cm_node
->ord_size
> ird_size
)
1005 cm_node
->ord_size
= ird_size
;
1008 if (!ird_size
&& (ctrl_ord
& IETF_RDMA0_READ
))
1010 if (cm_node
->ord_size
> ird_size
)
1011 cm_node
->ord_size
= ird_size
;
1013 if (cm_node
->ird_size
< ord_size
)
1014 /* no resources available */
1019 if (ctrl_ord
& IETF_RDMA0_READ
)
1020 cm_node
->send_rdma0_op
= SEND_RDMA_READ_ZERO
;
1021 else if (ctrl_ord
& IETF_RDMA0_WRITE
)
1022 cm_node
->send_rdma0_op
= SEND_RDMA_WRITE_ZERO
;
1023 else /* Not supported RDMA0 operation */
1025 i40iw_debug(cm_node
->dev
, I40IW_DEBUG_CM
,
1026 "MPAV2: Negotiated ORD: %d, IRD: %d\n",
1027 cm_node
->ord_size
, cm_node
->ird_size
);
1036 memcpy(cm_node
->pdata_buf
, buffer
+ mpa_hdr_len
, priv_data_len
);
1037 cm_node
->pdata
.size
= priv_data_len
;
1039 if (mpa_frame
->flags
& IETF_MPA_FLAGS_REJECT
)
1040 *type
= I40IW_MPA_REQUEST_REJECT
;
1042 if (mpa_frame
->flags
& IETF_MPA_FLAGS_MARKERS
)
1043 cm_node
->snd_mark_en
= true;
1049 * i40iw_schedule_cm_timer
1050 * @@cm_node: connection's node
1051 * @sqbuf: buffer to send
1052 * @type: if it es send ot close
1053 * @send_retrans: if rexmits to be done
1054 * @close_when_complete: is cm_node to be removed
1056 * note - cm_node needs to be protected before calling this. Encase in:
1057 * i40iw_rem_ref_cm_node(cm_core, cm_node);
1058 * i40iw_schedule_cm_timer(...)
1059 * atomic_inc(&cm_node->ref_count);
1061 int i40iw_schedule_cm_timer(struct i40iw_cm_node
*cm_node
,
1062 struct i40iw_puda_buf
*sqbuf
,
1063 enum i40iw_timer_type type
,
1065 int close_when_complete
)
1067 struct i40iw_sc_dev
*dev
= cm_node
->dev
;
1068 struct i40iw_cm_core
*cm_core
= cm_node
->cm_core
;
1069 struct i40iw_timer_entry
*new_send
;
1072 unsigned long flags
;
1074 new_send
= kzalloc(sizeof(*new_send
), GFP_ATOMIC
);
1076 i40iw_free_sqbuf(cm_node
->dev
, (void *)sqbuf
);
1079 new_send
->retrycount
= I40IW_DEFAULT_RETRYS
;
1080 new_send
->retranscount
= I40IW_DEFAULT_RETRANS
;
1081 new_send
->sqbuf
= sqbuf
;
1082 new_send
->timetosend
= jiffies
;
1083 new_send
->type
= type
;
1084 new_send
->send_retrans
= send_retrans
;
1085 new_send
->close_when_complete
= close_when_complete
;
1087 if (type
== I40IW_TIMER_TYPE_CLOSE
) {
1088 new_send
->timetosend
+= (HZ
/ 10);
1089 if (cm_node
->close_entry
) {
1091 i40iw_free_sqbuf(cm_node
->dev
, (void *)sqbuf
);
1092 i40iw_pr_err("already close entry\n");
1095 cm_node
->close_entry
= new_send
;
1098 if (type
== I40IW_TIMER_TYPE_SEND
) {
1099 spin_lock_irqsave(&cm_node
->retrans_list_lock
, flags
);
1100 cm_node
->send_entry
= new_send
;
1101 atomic_inc(&cm_node
->ref_count
);
1102 spin_unlock_irqrestore(&cm_node
->retrans_list_lock
, flags
);
1103 new_send
->timetosend
= jiffies
+ I40IW_RETRY_TIMEOUT
;
1105 atomic_inc(&sqbuf
->refcount
);
1106 i40iw_puda_send_buf(dev
->ilq
, sqbuf
);
1107 if (!send_retrans
) {
1108 i40iw_cleanup_retrans_entry(cm_node
);
1109 if (close_when_complete
)
1110 i40iw_rem_ref_cm_node(cm_node
);
1115 spin_lock_irqsave(&cm_core
->ht_lock
, flags
);
1116 was_timer_set
= timer_pending(&cm_core
->tcp_timer
);
1118 if (!was_timer_set
) {
1119 cm_core
->tcp_timer
.expires
= new_send
->timetosend
;
1120 add_timer(&cm_core
->tcp_timer
);
1122 spin_unlock_irqrestore(&cm_core
->ht_lock
, flags
);
1128 * i40iw_retrans_expired - Could not rexmit the packet
1129 * @cm_node: connection's node
1131 static void i40iw_retrans_expired(struct i40iw_cm_node
*cm_node
)
1133 struct iw_cm_id
*cm_id
= cm_node
->cm_id
;
1134 enum i40iw_cm_node_state state
= cm_node
->state
;
1136 cm_node
->state
= I40IW_CM_STATE_CLOSED
;
1138 case I40IW_CM_STATE_SYN_RCVD
:
1139 case I40IW_CM_STATE_CLOSING
:
1140 i40iw_rem_ref_cm_node(cm_node
);
1142 case I40IW_CM_STATE_FIN_WAIT1
:
1143 case I40IW_CM_STATE_LAST_ACK
:
1145 cm_id
->rem_ref(cm_id
);
1146 i40iw_send_reset(cm_node
);
1149 atomic_inc(&cm_node
->ref_count
);
1150 i40iw_send_reset(cm_node
);
1151 i40iw_create_event(cm_node
, I40IW_CM_EVENT_ABORTED
);
1157 * i40iw_handle_close_entry - for handling retry/timeouts
1158 * @cm_node: connection's node
1159 * @rem_node: flag for remove cm_node
1161 static void i40iw_handle_close_entry(struct i40iw_cm_node
*cm_node
, u32 rem_node
)
1163 struct i40iw_timer_entry
*close_entry
= cm_node
->close_entry
;
1164 struct iw_cm_id
*cm_id
= cm_node
->cm_id
;
1165 struct i40iw_qp
*iwqp
;
1166 unsigned long flags
;
1170 iwqp
= (struct i40iw_qp
*)close_entry
->sqbuf
;
1172 spin_lock_irqsave(&iwqp
->lock
, flags
);
1174 iwqp
->hw_tcp_state
= I40IW_TCP_STATE_CLOSED
;
1175 iwqp
->hw_iwarp_state
= I40IW_QP_STATE_ERROR
;
1176 iwqp
->last_aeq
= I40IW_AE_RESET_SENT
;
1177 iwqp
->ibqp_state
= IB_QPS_ERR
;
1178 spin_unlock_irqrestore(&iwqp
->lock
, flags
);
1179 i40iw_cm_disconn(iwqp
);
1181 spin_unlock_irqrestore(&iwqp
->lock
, flags
);
1183 } else if (rem_node
) {
1184 /* TIME_WAIT state */
1185 i40iw_rem_ref_cm_node(cm_node
);
1188 cm_id
->rem_ref(cm_id
);
1190 cm_node
->close_entry
= NULL
;
1194 * i40iw_cm_timer_tick - system's timer expired callback
1195 * @pass: Pointing to cm_core
1197 static void i40iw_cm_timer_tick(unsigned long pass
)
1199 unsigned long nexttimeout
= jiffies
+ I40IW_LONG_TIME
;
1200 struct i40iw_cm_node
*cm_node
;
1201 struct i40iw_timer_entry
*send_entry
, *close_entry
;
1202 struct list_head
*list_core_temp
;
1203 struct list_head
*list_node
;
1204 struct i40iw_cm_core
*cm_core
= (struct i40iw_cm_core
*)pass
;
1206 unsigned long timetosend
;
1207 struct i40iw_sc_dev
*dev
;
1208 unsigned long flags
;
1210 struct list_head timer_list
;
1212 INIT_LIST_HEAD(&timer_list
);
1213 spin_lock_irqsave(&cm_core
->ht_lock
, flags
);
1215 list_for_each_safe(list_node
, list_core_temp
, &cm_core
->connected_nodes
) {
1216 cm_node
= container_of(list_node
, struct i40iw_cm_node
, list
);
1217 if (cm_node
->close_entry
|| cm_node
->send_entry
) {
1218 atomic_inc(&cm_node
->ref_count
);
1219 list_add(&cm_node
->timer_entry
, &timer_list
);
1222 spin_unlock_irqrestore(&cm_core
->ht_lock
, flags
);
1224 list_for_each_safe(list_node
, list_core_temp
, &timer_list
) {
1225 cm_node
= container_of(list_node
,
1226 struct i40iw_cm_node
,
1228 close_entry
= cm_node
->close_entry
;
1231 if (time_after(close_entry
->timetosend
, jiffies
)) {
1232 if (nexttimeout
> close_entry
->timetosend
||
1234 nexttimeout
= close_entry
->timetosend
;
1238 i40iw_handle_close_entry(cm_node
, 1);
1242 spin_lock_irqsave(&cm_node
->retrans_list_lock
, flags
);
1244 send_entry
= cm_node
->send_entry
;
1247 if (time_after(send_entry
->timetosend
, jiffies
)) {
1248 if (cm_node
->state
!= I40IW_CM_STATE_OFFLOADED
) {
1249 if ((nexttimeout
> send_entry
->timetosend
) ||
1251 nexttimeout
= send_entry
->timetosend
;
1255 i40iw_free_retrans_entry(cm_node
);
1260 if ((cm_node
->state
== I40IW_CM_STATE_OFFLOADED
) ||
1261 (cm_node
->state
== I40IW_CM_STATE_CLOSED
)) {
1262 i40iw_free_retrans_entry(cm_node
);
1266 if (!send_entry
->retranscount
|| !send_entry
->retrycount
) {
1267 i40iw_free_retrans_entry(cm_node
);
1269 spin_unlock_irqrestore(&cm_node
->retrans_list_lock
, flags
);
1270 i40iw_retrans_expired(cm_node
);
1271 cm_node
->state
= I40IW_CM_STATE_CLOSED
;
1272 spin_lock_irqsave(&cm_node
->retrans_list_lock
, flags
);
1275 cm_node
->cm_core
->stats_pkt_retrans
++;
1276 spin_unlock_irqrestore(&cm_node
->retrans_list_lock
, flags
);
1279 atomic_inc(&send_entry
->sqbuf
->refcount
);
1280 i40iw_puda_send_buf(dev
->ilq
, send_entry
->sqbuf
);
1281 spin_lock_irqsave(&cm_node
->retrans_list_lock
, flags
);
1282 if (send_entry
->send_retrans
) {
1283 send_entry
->retranscount
--;
1284 timetosend
= (I40IW_RETRY_TIMEOUT
<<
1285 (I40IW_DEFAULT_RETRANS
-
1286 send_entry
->retranscount
));
1288 send_entry
->timetosend
= jiffies
+
1289 min(timetosend
, I40IW_MAX_TIMEOUT
);
1290 if (nexttimeout
> send_entry
->timetosend
|| !settimer
) {
1291 nexttimeout
= send_entry
->timetosend
;
1295 int close_when_complete
;
1297 close_when_complete
= send_entry
->close_when_complete
;
1298 i40iw_debug(cm_node
->dev
,
1300 "cm_node=%p state=%d\n",
1303 i40iw_free_retrans_entry(cm_node
);
1304 if (close_when_complete
)
1305 i40iw_rem_ref_cm_node(cm_node
);
1308 spin_unlock_irqrestore(&cm_node
->retrans_list_lock
, flags
);
1309 i40iw_rem_ref_cm_node(cm_node
);
1313 spin_lock_irqsave(&cm_core
->ht_lock
, flags
);
1314 if (!timer_pending(&cm_core
->tcp_timer
)) {
1315 cm_core
->tcp_timer
.expires
= nexttimeout
;
1316 add_timer(&cm_core
->tcp_timer
);
1318 spin_unlock_irqrestore(&cm_core
->ht_lock
, flags
);
1323 * i40iw_send_syn - send SYN packet
1324 * @cm_node: connection's node
1325 * @sendack: flag to set ACK bit or not
1327 int i40iw_send_syn(struct i40iw_cm_node
*cm_node
, u32 sendack
)
1329 struct i40iw_puda_buf
*sqbuf
;
1330 int flags
= SET_SYN
;
1331 char optionsbuffer
[sizeof(struct option_mss
) +
1332 sizeof(struct option_windowscale
) +
1333 sizeof(struct option_base
) + TCP_OPTIONS_PADDING
];
1334 struct i40iw_kmem_info opts
;
1336 int optionssize
= 0;
1337 /* Sending MSS option */
1338 union all_known_options
*options
;
1340 opts
.addr
= optionsbuffer
;
1342 i40iw_pr_err("no cm_node\n");
1346 options
= (union all_known_options
*)&optionsbuffer
[optionssize
];
1347 options
->as_mss
.optionnum
= OPTION_NUMBER_MSS
;
1348 options
->as_mss
.length
= sizeof(struct option_mss
);
1349 options
->as_mss
.mss
= htons(cm_node
->tcp_cntxt
.mss
);
1350 optionssize
+= sizeof(struct option_mss
);
1352 options
= (union all_known_options
*)&optionsbuffer
[optionssize
];
1353 options
->as_windowscale
.optionnum
= OPTION_NUMBER_WINDOW_SCALE
;
1354 options
->as_windowscale
.length
= sizeof(struct option_windowscale
);
1355 options
->as_windowscale
.shiftcount
= cm_node
->tcp_cntxt
.rcv_wscale
;
1356 optionssize
+= sizeof(struct option_windowscale
);
1357 options
= (union all_known_options
*)&optionsbuffer
[optionssize
];
1358 options
->as_end
= OPTION_NUMBER_END
;
1364 opts
.size
= optionssize
;
1366 sqbuf
= i40iw_form_cm_frame(cm_node
, &opts
, NULL
, NULL
, flags
);
1368 i40iw_pr_err("no sqbuf\n");
1371 return i40iw_schedule_cm_timer(cm_node
, sqbuf
, I40IW_TIMER_TYPE_SEND
, 1, 0);
1375 * i40iw_send_ack - Send ACK packet
1376 * @cm_node: connection's node
1378 static void i40iw_send_ack(struct i40iw_cm_node
*cm_node
)
1380 struct i40iw_puda_buf
*sqbuf
;
1382 sqbuf
= i40iw_form_cm_frame(cm_node
, NULL
, NULL
, NULL
, SET_ACK
);
1384 i40iw_puda_send_buf(cm_node
->dev
->ilq
, sqbuf
);
1386 i40iw_pr_err("no sqbuf\n");
1390 * i40iw_send_fin - Send FIN pkt
1391 * @cm_node: connection's node
1393 static int i40iw_send_fin(struct i40iw_cm_node
*cm_node
)
1395 struct i40iw_puda_buf
*sqbuf
;
1397 sqbuf
= i40iw_form_cm_frame(cm_node
, NULL
, NULL
, NULL
, SET_ACK
| SET_FIN
);
1399 i40iw_pr_err("no sqbuf\n");
1402 return i40iw_schedule_cm_timer(cm_node
, sqbuf
, I40IW_TIMER_TYPE_SEND
, 1, 0);
1406 * i40iw_find_node - find a cm node that matches the reference cm node
1407 * @cm_core: cm's core
1408 * @rem_port: remote tcp port num
1409 * @rem_addr: remote ip addr
1410 * @loc_port: local tcp port num
1411 * @loc_addr: loc ip addr
1412 * @add_refcnt: flag to increment refcount of cm_node
1414 struct i40iw_cm_node
*i40iw_find_node(struct i40iw_cm_core
*cm_core
,
1421 struct list_head
*hte
;
1422 struct i40iw_cm_node
*cm_node
;
1423 unsigned long flags
;
1425 hte
= &cm_core
->connected_nodes
;
1427 /* walk list and find cm_node associated with this session ID */
1428 spin_lock_irqsave(&cm_core
->ht_lock
, flags
);
1429 list_for_each_entry(cm_node
, hte
, list
) {
1430 if (!memcmp(cm_node
->loc_addr
, loc_addr
, sizeof(cm_node
->loc_addr
)) &&
1431 (cm_node
->loc_port
== loc_port
) &&
1432 !memcmp(cm_node
->rem_addr
, rem_addr
, sizeof(cm_node
->rem_addr
)) &&
1433 (cm_node
->rem_port
== rem_port
)) {
1435 atomic_inc(&cm_node
->ref_count
);
1436 spin_unlock_irqrestore(&cm_core
->ht_lock
, flags
);
1440 spin_unlock_irqrestore(&cm_core
->ht_lock
, flags
);
1447 * i40iw_find_listener - find a cm node listening on this addr-port pair
1448 * @cm_core: cm's core
1449 * @dst_port: listener tcp port num
1450 * @dst_addr: listener ip addr
1451 * @listener_state: state to match with listen node's
1453 static struct i40iw_cm_listener
*i40iw_find_listener(
1454 struct i40iw_cm_core
*cm_core
,
1458 enum i40iw_cm_listener_state
1461 struct i40iw_cm_listener
*listen_node
;
1462 static const u32 ip_zero
[4] = { 0, 0, 0, 0 };
1465 unsigned long flags
;
1467 /* walk list and find cm_node associated with this session ID */
1468 spin_lock_irqsave(&cm_core
->listen_list_lock
, flags
);
1469 list_for_each_entry(listen_node
, &cm_core
->listen_nodes
, list
) {
1470 memcpy(listen_addr
, listen_node
->loc_addr
, sizeof(listen_addr
));
1471 listen_port
= listen_node
->loc_port
;
1472 /* compare node pair, return node handle if a match */
1473 if ((!memcmp(listen_addr
, dst_addr
, sizeof(listen_addr
)) ||
1474 !memcmp(listen_addr
, ip_zero
, sizeof(listen_addr
))) &&
1475 (listen_port
== dst_port
) &&
1476 (listener_state
& listen_node
->listener_state
)) {
1477 atomic_inc(&listen_node
->ref_count
);
1478 spin_unlock_irqrestore(&cm_core
->listen_list_lock
, flags
);
1482 spin_unlock_irqrestore(&cm_core
->listen_list_lock
, flags
);
1487 * i40iw_add_hte_node - add a cm node to the hash table
1488 * @cm_core: cm's core
1489 * @cm_node: connection's node
1491 static void i40iw_add_hte_node(struct i40iw_cm_core
*cm_core
,
1492 struct i40iw_cm_node
*cm_node
)
1494 struct list_head
*hte
;
1495 unsigned long flags
;
1497 if (!cm_node
|| !cm_core
) {
1498 i40iw_pr_err("cm_node or cm_core == NULL\n");
1501 spin_lock_irqsave(&cm_core
->ht_lock
, flags
);
1503 /* get a handle on the hash table element (list head for this slot) */
1504 hte
= &cm_core
->connected_nodes
;
1505 list_add_tail(&cm_node
->list
, hte
);
1506 spin_unlock_irqrestore(&cm_core
->ht_lock
, flags
);
1510 * listen_port_in_use - determine if port is in use
1511 * @port: Listen port number
1513 static bool i40iw_listen_port_in_use(struct i40iw_cm_core
*cm_core
, u16 port
)
1515 struct i40iw_cm_listener
*listen_node
;
1516 unsigned long flags
;
1519 spin_lock_irqsave(&cm_core
->listen_list_lock
, flags
);
1520 list_for_each_entry(listen_node
, &cm_core
->listen_nodes
, list
) {
1521 if (listen_node
->loc_port
== port
) {
1526 spin_unlock_irqrestore(&cm_core
->listen_list_lock
, flags
);
1531 * i40iw_del_multiple_qhash - Remove qhash and child listens
1532 * @iwdev: iWarp device
1533 * @cm_info: CM info for parent listen node
1534 * @cm_parent_listen_node: The parent listen node
1536 static enum i40iw_status_code
i40iw_del_multiple_qhash(
1537 struct i40iw_device
*iwdev
,
1538 struct i40iw_cm_info
*cm_info
,
1539 struct i40iw_cm_listener
*cm_parent_listen_node
)
1541 struct i40iw_cm_listener
*child_listen_node
;
1542 enum i40iw_status_code ret
= I40IW_ERR_CONFIG
;
1543 struct list_head
*pos
, *tpos
;
1544 unsigned long flags
;
1546 spin_lock_irqsave(&iwdev
->cm_core
.listen_list_lock
, flags
);
1547 list_for_each_safe(pos
, tpos
, &cm_parent_listen_node
->child_listen_list
) {
1548 child_listen_node
= list_entry(pos
, struct i40iw_cm_listener
, child_listen_list
);
1549 if (child_listen_node
->ipv4
)
1550 i40iw_debug(&iwdev
->sc_dev
,
1552 "removing child listen for IP=%pI4, port=%d, vlan=%d\n",
1553 child_listen_node
->loc_addr
,
1554 child_listen_node
->loc_port
,
1555 child_listen_node
->vlan_id
);
1557 i40iw_debug(&iwdev
->sc_dev
, I40IW_DEBUG_CM
,
1558 "removing child listen for IP=%pI6, port=%d, vlan=%d\n",
1559 child_listen_node
->loc_addr
,
1560 child_listen_node
->loc_port
,
1561 child_listen_node
->vlan_id
);
1563 memcpy(cm_info
->loc_addr
, child_listen_node
->loc_addr
,
1564 sizeof(cm_info
->loc_addr
));
1565 cm_info
->vlan_id
= child_listen_node
->vlan_id
;
1566 ret
= i40iw_manage_qhash(iwdev
, cm_info
,
1567 I40IW_QHASH_TYPE_TCP_SYN
,
1568 I40IW_QHASH_MANAGE_TYPE_DELETE
, NULL
, false);
1569 kfree(child_listen_node
);
1570 cm_parent_listen_node
->cm_core
->stats_listen_nodes_destroyed
++;
1571 i40iw_debug(&iwdev
->sc_dev
,
1573 "freed pointer = %p\n",
1576 spin_unlock_irqrestore(&iwdev
->cm_core
.listen_list_lock
, flags
);
1582 * i40iw_netdev_vlan_ipv6 - Gets the netdev and mac
1583 * @addr: local IPv6 address
1584 * @vlan_id: vlan id for the given IPv6 address
1585 * @mac: mac address for the given IPv6 address
1587 * Returns the net_device of the IPv6 address and also sets the
1588 * vlan id and mac for that address.
1590 static struct net_device
*i40iw_netdev_vlan_ipv6(u32
*addr
, u16
*vlan_id
, u8
*mac
)
1592 struct net_device
*ip_dev
= NULL
;
1593 #if IS_ENABLED(CONFIG_IPV6)
1594 struct in6_addr laddr6
;
1596 i40iw_copy_ip_htonl(laddr6
.in6_u
.u6_addr32
, addr
);
1598 *vlan_id
= I40IW_NO_VLAN
;
1602 for_each_netdev_rcu(&init_net
, ip_dev
) {
1603 if (ipv6_chk_addr(&init_net
, &laddr6
, ip_dev
, 1)) {
1605 *vlan_id
= rdma_vlan_dev_vlan_id(ip_dev
);
1606 if (ip_dev
->dev_addr
&& mac
)
1607 ether_addr_copy(mac
, ip_dev
->dev_addr
);
1617 * i40iw_get_vlan_ipv4 - Returns the vlan_id for IPv4 address
1618 * @addr: local IPv4 address
1620 static u16
i40iw_get_vlan_ipv4(u32
*addr
)
1622 struct net_device
*netdev
;
1623 u16 vlan_id
= I40IW_NO_VLAN
;
1625 netdev
= ip_dev_find(&init_net
, htonl(addr
[0]));
1627 vlan_id
= rdma_vlan_dev_vlan_id(netdev
);
1634 * i40iw_add_mqh_6 - Adds multiple qhashes for IPv6
1635 * @iwdev: iWarp device
1636 * @cm_info: CM info for parent listen node
1637 * @cm_parent_listen_node: The parent listen node
1639 * Adds a qhash and a child listen node for every IPv6 address
1640 * on the adapter and adds the associated qhash filter
1642 static enum i40iw_status_code
i40iw_add_mqh_6(struct i40iw_device
*iwdev
,
1643 struct i40iw_cm_info
*cm_info
,
1644 struct i40iw_cm_listener
*cm_parent_listen_node
)
1646 struct net_device
*ip_dev
;
1647 struct inet6_dev
*idev
;
1648 struct inet6_ifaddr
*ifp
;
1649 enum i40iw_status_code ret
= 0;
1650 struct i40iw_cm_listener
*child_listen_node
;
1651 unsigned long flags
;
1654 for_each_netdev_rcu(&init_net
, ip_dev
) {
1655 if ((((rdma_vlan_dev_vlan_id(ip_dev
) < I40IW_NO_VLAN
) &&
1656 (rdma_vlan_dev_real_dev(ip_dev
) == iwdev
->netdev
)) ||
1657 (ip_dev
== iwdev
->netdev
)) && (ip_dev
->flags
& IFF_UP
)) {
1658 idev
= __in6_dev_get(ip_dev
);
1660 i40iw_pr_err("idev == NULL\n");
1663 list_for_each_entry(ifp
, &idev
->addr_list
, if_list
) {
1664 i40iw_debug(&iwdev
->sc_dev
,
1666 "IP=%pI6, vlan_id=%d, MAC=%pM\n",
1668 rdma_vlan_dev_vlan_id(ip_dev
),
1671 kzalloc(sizeof(*child_listen_node
), GFP_ATOMIC
);
1672 i40iw_debug(&iwdev
->sc_dev
,
1674 "Allocating child listener %p\n",
1676 if (!child_listen_node
) {
1677 i40iw_pr_err("listener memory allocation\n");
1678 ret
= I40IW_ERR_NO_MEMORY
;
1681 cm_info
->vlan_id
= rdma_vlan_dev_vlan_id(ip_dev
);
1682 cm_parent_listen_node
->vlan_id
= cm_info
->vlan_id
;
1684 memcpy(child_listen_node
, cm_parent_listen_node
,
1685 sizeof(*child_listen_node
));
1687 i40iw_copy_ip_ntohl(child_listen_node
->loc_addr
,
1688 ifp
->addr
.in6_u
.u6_addr32
);
1689 memcpy(cm_info
->loc_addr
, child_listen_node
->loc_addr
,
1690 sizeof(cm_info
->loc_addr
));
1692 ret
= i40iw_manage_qhash(iwdev
, cm_info
,
1693 I40IW_QHASH_TYPE_TCP_SYN
,
1694 I40IW_QHASH_MANAGE_TYPE_ADD
,
1697 spin_lock_irqsave(&iwdev
->cm_core
.listen_list_lock
, flags
);
1698 list_add(&child_listen_node
->child_listen_list
,
1699 &cm_parent_listen_node
->child_listen_list
);
1700 spin_unlock_irqrestore(&iwdev
->cm_core
.listen_list_lock
, flags
);
1701 cm_parent_listen_node
->cm_core
->stats_listen_nodes_created
++;
1703 kfree(child_listen_node
);
1714 * i40iw_add_mqh_4 - Adds multiple qhashes for IPv4
1715 * @iwdev: iWarp device
1716 * @cm_info: CM info for parent listen node
1717 * @cm_parent_listen_node: The parent listen node
1719 * Adds a qhash and a child listen node for every IPv4 address
1720 * on the adapter and adds the associated qhash filter
1722 static enum i40iw_status_code
i40iw_add_mqh_4(
1723 struct i40iw_device
*iwdev
,
1724 struct i40iw_cm_info
*cm_info
,
1725 struct i40iw_cm_listener
*cm_parent_listen_node
)
1727 struct net_device
*dev
;
1728 struct in_device
*idev
;
1729 struct i40iw_cm_listener
*child_listen_node
;
1730 enum i40iw_status_code ret
= 0;
1731 unsigned long flags
;
1734 for_each_netdev(&init_net
, dev
) {
1735 if ((((rdma_vlan_dev_vlan_id(dev
) < I40IW_NO_VLAN
) &&
1736 (rdma_vlan_dev_real_dev(dev
) == iwdev
->netdev
)) ||
1737 (dev
== iwdev
->netdev
)) && (dev
->flags
& IFF_UP
)) {
1738 idev
= in_dev_get(dev
);
1740 i40iw_debug(&iwdev
->sc_dev
,
1742 "Allocating child CM Listener forIP=%pI4, vlan_id=%d, MAC=%pM\n",
1744 rdma_vlan_dev_vlan_id(dev
),
1746 child_listen_node
= kzalloc(sizeof(*child_listen_node
), GFP_ATOMIC
);
1747 cm_parent_listen_node
->cm_core
->stats_listen_nodes_created
++;
1748 i40iw_debug(&iwdev
->sc_dev
,
1750 "Allocating child listener %p\n",
1752 if (!child_listen_node
) {
1753 i40iw_pr_err("listener memory allocation\n");
1755 ret
= I40IW_ERR_NO_MEMORY
;
1758 cm_info
->vlan_id
= rdma_vlan_dev_vlan_id(dev
);
1759 cm_parent_listen_node
->vlan_id
= cm_info
->vlan_id
;
1760 memcpy(child_listen_node
,
1761 cm_parent_listen_node
,
1762 sizeof(*child_listen_node
));
1764 child_listen_node
->loc_addr
[0] = ntohl(ifa
->ifa_address
);
1765 memcpy(cm_info
->loc_addr
, child_listen_node
->loc_addr
,
1766 sizeof(cm_info
->loc_addr
));
1768 ret
= i40iw_manage_qhash(iwdev
,
1770 I40IW_QHASH_TYPE_TCP_SYN
,
1771 I40IW_QHASH_MANAGE_TYPE_ADD
,
1775 spin_lock_irqsave(&iwdev
->cm_core
.listen_list_lock
, flags
);
1776 list_add(&child_listen_node
->child_listen_list
,
1777 &cm_parent_listen_node
->child_listen_list
);
1778 spin_unlock_irqrestore(&iwdev
->cm_core
.listen_list_lock
, flags
);
1780 kfree(child_listen_node
);
1781 cm_parent_listen_node
->cm_core
->stats_listen_nodes_created
--;
1794 * i40iw_dec_refcnt_listen - delete listener and associated cm nodes
1795 * @cm_core: cm's core
1796 * @free_hanging_nodes: to free associated cm_nodes
1797 * @apbvt_del: flag to delete the apbvt
1799 static int i40iw_dec_refcnt_listen(struct i40iw_cm_core
*cm_core
,
1800 struct i40iw_cm_listener
*listener
,
1801 int free_hanging_nodes
, bool apbvt_del
)
1805 struct list_head
*list_pos
;
1806 struct list_head
*list_temp
;
1807 struct i40iw_cm_node
*cm_node
;
1808 struct list_head reset_list
;
1809 struct i40iw_cm_info nfo
;
1810 struct i40iw_cm_node
*loopback
;
1811 enum i40iw_cm_node_state old_state
;
1812 unsigned long flags
;
1814 /* free non-accelerated child nodes for this listener */
1815 INIT_LIST_HEAD(&reset_list
);
1816 if (free_hanging_nodes
) {
1817 spin_lock_irqsave(&cm_core
->ht_lock
, flags
);
1818 list_for_each_safe(list_pos
, list_temp
, &cm_core
->connected_nodes
) {
1819 cm_node
= container_of(list_pos
, struct i40iw_cm_node
, list
);
1820 if ((cm_node
->listener
== listener
) && !cm_node
->accelerated
) {
1821 atomic_inc(&cm_node
->ref_count
);
1822 list_add(&cm_node
->reset_entry
, &reset_list
);
1825 spin_unlock_irqrestore(&cm_core
->ht_lock
, flags
);
1828 list_for_each_safe(list_pos
, list_temp
, &reset_list
) {
1829 cm_node
= container_of(list_pos
, struct i40iw_cm_node
, reset_entry
);
1830 loopback
= cm_node
->loopbackpartner
;
1831 if (cm_node
->state
>= I40IW_CM_STATE_FIN_WAIT1
) {
1832 i40iw_rem_ref_cm_node(cm_node
);
1835 i40iw_cleanup_retrans_entry(cm_node
);
1836 err
= i40iw_send_reset(cm_node
);
1838 cm_node
->state
= I40IW_CM_STATE_CLOSED
;
1839 i40iw_pr_err("send reset\n");
1841 old_state
= cm_node
->state
;
1842 cm_node
->state
= I40IW_CM_STATE_LISTENER_DESTROYED
;
1843 if (old_state
!= I40IW_CM_STATE_MPAREQ_RCVD
)
1844 i40iw_rem_ref_cm_node(cm_node
);
1847 struct i40iw_cm_event event
;
1849 event
.cm_node
= loopback
;
1850 memcpy(event
.cm_info
.rem_addr
,
1851 loopback
->rem_addr
, sizeof(event
.cm_info
.rem_addr
));
1852 memcpy(event
.cm_info
.loc_addr
,
1853 loopback
->loc_addr
, sizeof(event
.cm_info
.loc_addr
));
1854 event
.cm_info
.rem_port
= loopback
->rem_port
;
1855 event
.cm_info
.loc_port
= loopback
->loc_port
;
1856 event
.cm_info
.cm_id
= loopback
->cm_id
;
1857 event
.cm_info
.ipv4
= loopback
->ipv4
;
1858 atomic_inc(&loopback
->ref_count
);
1859 loopback
->state
= I40IW_CM_STATE_CLOSED
;
1860 i40iw_event_connect_error(&event
);
1861 cm_node
->state
= I40IW_CM_STATE_LISTENER_DESTROYED
;
1862 i40iw_rem_ref_cm_node(cm_node
);
1867 if (!atomic_dec_return(&listener
->ref_count
)) {
1868 spin_lock_irqsave(&cm_core
->listen_list_lock
, flags
);
1869 list_del(&listener
->list
);
1870 spin_unlock_irqrestore(&cm_core
->listen_list_lock
, flags
);
1872 if (listener
->iwdev
) {
1873 if (apbvt_del
&& !i40iw_listen_port_in_use(cm_core
, listener
->loc_port
))
1874 i40iw_manage_apbvt(listener
->iwdev
,
1876 I40IW_MANAGE_APBVT_DEL
);
1878 memcpy(nfo
.loc_addr
, listener
->loc_addr
, sizeof(nfo
.loc_addr
));
1879 nfo
.loc_port
= listener
->loc_port
;
1880 nfo
.ipv4
= listener
->ipv4
;
1881 nfo
.vlan_id
= listener
->vlan_id
;
1883 if (!list_empty(&listener
->child_listen_list
)) {
1884 i40iw_del_multiple_qhash(listener
->iwdev
, &nfo
, listener
);
1886 if (listener
->qhash_set
)
1887 i40iw_manage_qhash(listener
->iwdev
,
1889 I40IW_QHASH_TYPE_TCP_SYN
,
1890 I40IW_QHASH_MANAGE_TYPE_DELETE
,
1896 cm_core
->stats_listen_destroyed
++;
1898 cm_core
->stats_listen_nodes_destroyed
++;
1904 if (atomic_read(&listener
->pend_accepts_cnt
) > 0)
1905 i40iw_debug(cm_core
->dev
,
1907 "%s: listener (%p) pending accepts=%u\n",
1910 atomic_read(&listener
->pend_accepts_cnt
));
1917 * i40iw_cm_del_listen - delete a linstener
1918 * @cm_core: cm's core
1919 * @listener: passive connection's listener
1920 * @apbvt_del: flag to delete apbvt
1922 static int i40iw_cm_del_listen(struct i40iw_cm_core
*cm_core
,
1923 struct i40iw_cm_listener
*listener
,
1926 listener
->listener_state
= I40IW_CM_LISTENER_PASSIVE_STATE
;
1927 listener
->cm_id
= NULL
; /* going to be destroyed pretty soon */
1928 return i40iw_dec_refcnt_listen(cm_core
, listener
, 1, apbvt_del
);
1932 * i40iw_addr_resolve_neigh - resolve neighbor address
1933 * @iwdev: iwarp device structure
1934 * @src_ip: local ip address
1935 * @dst_ip: remote ip address
1936 * @arpindex: if there is an arp entry
1938 static int i40iw_addr_resolve_neigh(struct i40iw_device
*iwdev
,
1944 struct neighbour
*neigh
;
1946 struct net_device
*netdev
= iwdev
->netdev
;
1947 __be32 dst_ipaddr
= htonl(dst_ip
);
1948 __be32 src_ipaddr
= htonl(src_ip
);
1950 rt
= ip_route_output(&init_net
, dst_ipaddr
, src_ipaddr
, 0, 0);
1952 i40iw_pr_err("ip_route_output\n");
1956 if (netif_is_bond_slave(netdev
))
1957 netdev
= netdev_master_upper_dev_get(netdev
);
1959 neigh
= dst_neigh_lookup(&rt
->dst
, &dst_ipaddr
);
1963 if (neigh
->nud_state
& NUD_VALID
) {
1964 if (arpindex
>= 0) {
1965 if (ether_addr_equal(iwdev
->arp_table
[arpindex
].mac_addr
,
1967 /* Mac address same as arp table */
1968 goto resolve_neigh_exit
;
1969 i40iw_manage_arp_cache(iwdev
,
1970 iwdev
->arp_table
[arpindex
].mac_addr
,
1976 i40iw_manage_arp_cache(iwdev
, neigh
->ha
, &dst_ip
, true, I40IW_ARP_ADD
);
1977 rc
= i40iw_arp_table(iwdev
, &dst_ip
, true, NULL
, I40IW_ARP_RESOLVE
);
1979 neigh_event_send(neigh
, NULL
);
1986 neigh_release(neigh
);
1993 * i40iw_get_dst_ipv6
1995 static struct dst_entry
*i40iw_get_dst_ipv6(struct sockaddr_in6
*src_addr
,
1996 struct sockaddr_in6
*dst_addr
)
1998 struct dst_entry
*dst
;
2001 memset(&fl6
, 0, sizeof(fl6
));
2002 fl6
.daddr
= dst_addr
->sin6_addr
;
2003 fl6
.saddr
= src_addr
->sin6_addr
;
2004 if (ipv6_addr_type(&fl6
.daddr
) & IPV6_ADDR_LINKLOCAL
)
2005 fl6
.flowi6_oif
= dst_addr
->sin6_scope_id
;
2007 dst
= ip6_route_output(&init_net
, NULL
, &fl6
);
2012 * i40iw_addr_resolve_neigh_ipv6 - resolve neighbor ipv6 address
2013 * @iwdev: iwarp device structure
2014 * @dst_ip: remote ip address
2015 * @arpindex: if there is an arp entry
2017 static int i40iw_addr_resolve_neigh_ipv6(struct i40iw_device
*iwdev
,
2022 struct neighbour
*neigh
;
2024 struct net_device
*netdev
= iwdev
->netdev
;
2025 struct dst_entry
*dst
;
2026 struct sockaddr_in6 dst_addr
;
2027 struct sockaddr_in6 src_addr
;
2029 memset(&dst_addr
, 0, sizeof(dst_addr
));
2030 dst_addr
.sin6_family
= AF_INET6
;
2031 i40iw_copy_ip_htonl(dst_addr
.sin6_addr
.in6_u
.u6_addr32
, dest
);
2032 memset(&src_addr
, 0, sizeof(src_addr
));
2033 src_addr
.sin6_family
= AF_INET6
;
2034 i40iw_copy_ip_htonl(src_addr
.sin6_addr
.in6_u
.u6_addr32
, src
);
2035 dst
= i40iw_get_dst_ipv6(&src_addr
, &dst_addr
);
2036 if (!dst
|| dst
->error
) {
2039 i40iw_pr_err("ip6_route_output returned dst->error = %d\n",
2045 if (netif_is_bond_slave(netdev
))
2046 netdev
= netdev_master_upper_dev_get(netdev
);
2048 neigh
= dst_neigh_lookup(dst
, &dst_addr
);
2052 i40iw_debug(&iwdev
->sc_dev
, I40IW_DEBUG_CM
, "dst_neigh_lookup MAC=%pM\n", neigh
->ha
);
2053 if (neigh
->nud_state
& NUD_VALID
) {
2054 if (arpindex
>= 0) {
2055 if (ether_addr_equal
2056 (iwdev
->arp_table
[arpindex
].mac_addr
,
2058 /* Mac address same as in arp table */
2059 goto resolve_neigh_exit6
;
2061 i40iw_manage_arp_cache(iwdev
,
2062 iwdev
->arp_table
[arpindex
].mac_addr
,
2067 i40iw_manage_arp_cache(iwdev
,
2072 rc
= i40iw_arp_table(iwdev
,
2078 neigh_event_send(neigh
, NULL
);
2082 resolve_neigh_exit6
:
2085 neigh_release(neigh
);
2091 * i40iw_ipv4_is_loopback - check if loopback
2092 * @loc_addr: local addr to compare
2093 * @rem_addr: remote address
2095 static bool i40iw_ipv4_is_loopback(u32 loc_addr
, u32 rem_addr
)
2097 return ipv4_is_loopback(htonl(rem_addr
)) || (loc_addr
== rem_addr
);
2101 * i40iw_ipv6_is_loopback - check if loopback
2102 * @loc_addr: local addr to compare
2103 * @rem_addr: remote address
2105 static bool i40iw_ipv6_is_loopback(u32
*loc_addr
, u32
*rem_addr
)
2107 struct in6_addr raddr6
;
2109 i40iw_copy_ip_htonl(raddr6
.in6_u
.u6_addr32
, rem_addr
);
2110 return (!memcmp(loc_addr
, rem_addr
, 16) || ipv6_addr_loopback(&raddr6
));
2114 * i40iw_make_cm_node - create a new instance of a cm node
2115 * @cm_core: cm's core
2116 * @iwdev: iwarp device structure
2117 * @cm_info: quad info for connection
2118 * @listener: passive connection's listener
2120 static struct i40iw_cm_node
*i40iw_make_cm_node(
2121 struct i40iw_cm_core
*cm_core
,
2122 struct i40iw_device
*iwdev
,
2123 struct i40iw_cm_info
*cm_info
,
2124 struct i40iw_cm_listener
*listener
)
2126 struct i40iw_cm_node
*cm_node
;
2130 struct net_device
*netdev
= iwdev
->netdev
;
2132 /* create an hte and cm_node for this instance */
2133 cm_node
= kzalloc(sizeof(*cm_node
), GFP_ATOMIC
);
2137 /* set our node specific transport info */
2138 cm_node
->ipv4
= cm_info
->ipv4
;
2139 cm_node
->vlan_id
= cm_info
->vlan_id
;
2140 memcpy(cm_node
->loc_addr
, cm_info
->loc_addr
, sizeof(cm_node
->loc_addr
));
2141 memcpy(cm_node
->rem_addr
, cm_info
->rem_addr
, sizeof(cm_node
->rem_addr
));
2142 cm_node
->loc_port
= cm_info
->loc_port
;
2143 cm_node
->rem_port
= cm_info
->rem_port
;
2145 cm_node
->mpa_frame_rev
= iwdev
->mpa_version
;
2146 cm_node
->send_rdma0_op
= SEND_RDMA_READ_ZERO
;
2147 cm_node
->ird_size
= I40IW_MAX_IRD_SIZE
;
2148 cm_node
->ord_size
= I40IW_MAX_ORD_SIZE
;
2150 cm_node
->listener
= listener
;
2151 cm_node
->cm_id
= cm_info
->cm_id
;
2152 ether_addr_copy(cm_node
->loc_mac
, netdev
->dev_addr
);
2153 spin_lock_init(&cm_node
->retrans_list_lock
);
2155 atomic_set(&cm_node
->ref_count
, 1);
2156 /* associate our parent CM core */
2157 cm_node
->cm_core
= cm_core
;
2158 cm_node
->tcp_cntxt
.loc_id
= I40IW_CM_DEF_LOCAL_ID
;
2159 cm_node
->tcp_cntxt
.rcv_wscale
= I40IW_CM_DEFAULT_RCV_WND_SCALE
;
2160 cm_node
->tcp_cntxt
.rcv_wnd
=
2161 I40IW_CM_DEFAULT_RCV_WND_SCALED
>> I40IW_CM_DEFAULT_RCV_WND_SCALE
;
2162 ts
= current_kernel_time();
2163 cm_node
->tcp_cntxt
.loc_seq_num
= htonl(ts
.tv_nsec
);
2164 cm_node
->tcp_cntxt
.mss
= iwdev
->mss
;
2166 cm_node
->iwdev
= iwdev
;
2167 cm_node
->dev
= &iwdev
->sc_dev
;
2169 if ((cm_node
->ipv4
&&
2170 i40iw_ipv4_is_loopback(cm_node
->loc_addr
[0], cm_node
->rem_addr
[0])) ||
2171 (!cm_node
->ipv4
&& i40iw_ipv6_is_loopback(cm_node
->loc_addr
,
2172 cm_node
->rem_addr
))) {
2173 arpindex
= i40iw_arp_table(iwdev
,
2179 oldarpindex
= i40iw_arp_table(iwdev
,
2185 arpindex
= i40iw_addr_resolve_neigh(iwdev
,
2186 cm_info
->loc_addr
[0],
2187 cm_info
->rem_addr
[0],
2189 else if (IS_ENABLED(CONFIG_IPV6
))
2190 arpindex
= i40iw_addr_resolve_neigh_ipv6(iwdev
,
2198 i40iw_pr_err("cm_node arpindex\n");
2202 ether_addr_copy(cm_node
->rem_mac
, iwdev
->arp_table
[arpindex
].mac_addr
);
2203 i40iw_add_hte_node(cm_core
, cm_node
);
2204 cm_core
->stats_nodes_created
++;
2209 * i40iw_rem_ref_cm_node - destroy an instance of a cm node
2210 * @cm_node: connection's node
2212 static void i40iw_rem_ref_cm_node(struct i40iw_cm_node
*cm_node
)
2214 struct i40iw_cm_core
*cm_core
= cm_node
->cm_core
;
2215 struct i40iw_qp
*iwqp
;
2216 struct i40iw_cm_info nfo
;
2217 unsigned long flags
;
2219 spin_lock_irqsave(&cm_node
->cm_core
->ht_lock
, flags
);
2220 if (atomic_dec_return(&cm_node
->ref_count
)) {
2221 spin_unlock_irqrestore(&cm_node
->cm_core
->ht_lock
, flags
);
2224 list_del(&cm_node
->list
);
2225 spin_unlock_irqrestore(&cm_node
->cm_core
->ht_lock
, flags
);
2227 /* if the node is destroyed before connection was accelerated */
2228 if (!cm_node
->accelerated
&& cm_node
->accept_pend
) {
2229 pr_err("node destroyed before established\n");
2230 atomic_dec(&cm_node
->listener
->pend_accepts_cnt
);
2232 if (cm_node
->close_entry
)
2233 i40iw_handle_close_entry(cm_node
, 0);
2234 if (cm_node
->listener
) {
2235 i40iw_dec_refcnt_listen(cm_core
, cm_node
->listener
, 0, true);
2237 if (!i40iw_listen_port_in_use(cm_core
, htons(cm_node
->loc_port
)) &&
2238 cm_node
->apbvt_set
&& cm_node
->iwdev
) {
2239 i40iw_manage_apbvt(cm_node
->iwdev
,
2241 I40IW_MANAGE_APBVT_DEL
);
2242 i40iw_get_addr_info(cm_node
, &nfo
);
2243 if (cm_node
->qhash_set
) {
2244 i40iw_manage_qhash(cm_node
->iwdev
,
2246 I40IW_QHASH_TYPE_TCP_ESTABLISHED
,
2247 I40IW_QHASH_MANAGE_TYPE_DELETE
,
2250 cm_node
->qhash_set
= 0;
2255 iwqp
= cm_node
->iwqp
;
2257 iwqp
->cm_node
= NULL
;
2258 i40iw_rem_ref(&iwqp
->ibqp
);
2259 cm_node
->iwqp
= NULL
;
2260 } else if (cm_node
->qhash_set
) {
2261 i40iw_get_addr_info(cm_node
, &nfo
);
2262 i40iw_manage_qhash(cm_node
->iwdev
,
2264 I40IW_QHASH_TYPE_TCP_ESTABLISHED
,
2265 I40IW_QHASH_MANAGE_TYPE_DELETE
,
2268 cm_node
->qhash_set
= 0;
2271 cm_node
->cm_core
->stats_nodes_destroyed
++;
2276 * i40iw_handle_fin_pkt - FIN packet received
2277 * @cm_node: connection's node
2279 static void i40iw_handle_fin_pkt(struct i40iw_cm_node
*cm_node
)
2283 switch (cm_node
->state
) {
2284 case I40IW_CM_STATE_SYN_RCVD
:
2285 case I40IW_CM_STATE_SYN_SENT
:
2286 case I40IW_CM_STATE_ESTABLISHED
:
2287 case I40IW_CM_STATE_MPAREJ_RCVD
:
2288 cm_node
->tcp_cntxt
.rcv_nxt
++;
2289 i40iw_cleanup_retrans_entry(cm_node
);
2290 cm_node
->state
= I40IW_CM_STATE_LAST_ACK
;
2291 i40iw_send_fin(cm_node
);
2293 case I40IW_CM_STATE_MPAREQ_SENT
:
2294 i40iw_create_event(cm_node
, I40IW_CM_EVENT_ABORTED
);
2295 cm_node
->tcp_cntxt
.rcv_nxt
++;
2296 i40iw_cleanup_retrans_entry(cm_node
);
2297 cm_node
->state
= I40IW_CM_STATE_CLOSED
;
2298 atomic_inc(&cm_node
->ref_count
);
2299 i40iw_send_reset(cm_node
);
2301 case I40IW_CM_STATE_FIN_WAIT1
:
2302 cm_node
->tcp_cntxt
.rcv_nxt
++;
2303 i40iw_cleanup_retrans_entry(cm_node
);
2304 cm_node
->state
= I40IW_CM_STATE_CLOSING
;
2305 i40iw_send_ack(cm_node
);
2307 * Wait for ACK as this is simultaneous close.
2308 * After we receive ACK, do not send anything.
2312 case I40IW_CM_STATE_FIN_WAIT2
:
2313 cm_node
->tcp_cntxt
.rcv_nxt
++;
2314 i40iw_cleanup_retrans_entry(cm_node
);
2315 cm_node
->state
= I40IW_CM_STATE_TIME_WAIT
;
2316 i40iw_send_ack(cm_node
);
2318 i40iw_schedule_cm_timer(cm_node
, NULL
, I40IW_TIMER_TYPE_CLOSE
, 1, 0);
2320 i40iw_pr_err("node %p state = %d\n", cm_node
, cm_node
->state
);
2322 case I40IW_CM_STATE_TIME_WAIT
:
2323 cm_node
->tcp_cntxt
.rcv_nxt
++;
2324 i40iw_cleanup_retrans_entry(cm_node
);
2325 cm_node
->state
= I40IW_CM_STATE_CLOSED
;
2326 i40iw_rem_ref_cm_node(cm_node
);
2328 case I40IW_CM_STATE_OFFLOADED
:
2330 i40iw_pr_err("bad state node %p state = %d\n", cm_node
, cm_node
->state
);
2336 * i40iw_handle_rst_pkt - process received RST packet
2337 * @cm_node: connection's node
2338 * @rbuf: receive buffer
2340 static void i40iw_handle_rst_pkt(struct i40iw_cm_node
*cm_node
,
2341 struct i40iw_puda_buf
*rbuf
)
2343 i40iw_cleanup_retrans_entry(cm_node
);
2344 switch (cm_node
->state
) {
2345 case I40IW_CM_STATE_SYN_SENT
:
2346 case I40IW_CM_STATE_MPAREQ_SENT
:
2347 switch (cm_node
->mpa_frame_rev
) {
2349 cm_node
->mpa_frame_rev
= IETF_MPA_V1
;
2350 /* send a syn and goto syn sent state */
2351 cm_node
->state
= I40IW_CM_STATE_SYN_SENT
;
2352 if (i40iw_send_syn(cm_node
, 0))
2353 i40iw_active_open_err(cm_node
, false);
2357 i40iw_active_open_err(cm_node
, false);
2361 case I40IW_CM_STATE_MPAREQ_RCVD
:
2362 atomic_add_return(1, &cm_node
->passive_state
);
2364 case I40IW_CM_STATE_ESTABLISHED
:
2365 case I40IW_CM_STATE_SYN_RCVD
:
2366 case I40IW_CM_STATE_LISTENING
:
2367 i40iw_pr_err("Bad state state = %d\n", cm_node
->state
);
2368 i40iw_passive_open_err(cm_node
, false);
2370 case I40IW_CM_STATE_OFFLOADED
:
2371 i40iw_active_open_err(cm_node
, false);
2373 case I40IW_CM_STATE_CLOSED
:
2375 case I40IW_CM_STATE_FIN_WAIT2
:
2376 case I40IW_CM_STATE_FIN_WAIT1
:
2377 case I40IW_CM_STATE_LAST_ACK
:
2378 cm_node
->cm_id
->rem_ref(cm_node
->cm_id
);
2379 case I40IW_CM_STATE_TIME_WAIT
:
2380 cm_node
->state
= I40IW_CM_STATE_CLOSED
;
2381 i40iw_rem_ref_cm_node(cm_node
);
2389 * i40iw_handle_rcv_mpa - Process a recv'd mpa buffer
2390 * @cm_node: connection's node
2391 * @rbuf: receive buffer
2393 static void i40iw_handle_rcv_mpa(struct i40iw_cm_node
*cm_node
,
2394 struct i40iw_puda_buf
*rbuf
)
2397 int datasize
= rbuf
->datalen
;
2398 u8
*dataloc
= rbuf
->data
;
2400 enum i40iw_cm_event_type type
= I40IW_CM_EVENT_UNKNOWN
;
2403 ret
= i40iw_parse_mpa(cm_node
, dataloc
, &res_type
, datasize
);
2405 if (cm_node
->state
== I40IW_CM_STATE_MPAREQ_SENT
)
2406 i40iw_active_open_err(cm_node
, true);
2408 i40iw_passive_open_err(cm_node
, true);
2412 switch (cm_node
->state
) {
2413 case I40IW_CM_STATE_ESTABLISHED
:
2414 if (res_type
== I40IW_MPA_REQUEST_REJECT
)
2415 i40iw_pr_err("state for reject\n");
2416 cm_node
->state
= I40IW_CM_STATE_MPAREQ_RCVD
;
2417 type
= I40IW_CM_EVENT_MPA_REQ
;
2418 i40iw_send_ack(cm_node
); /* ACK received MPA request */
2419 atomic_set(&cm_node
->passive_state
,
2420 I40IW_PASSIVE_STATE_INDICATED
);
2422 case I40IW_CM_STATE_MPAREQ_SENT
:
2423 i40iw_cleanup_retrans_entry(cm_node
);
2424 if (res_type
== I40IW_MPA_REQUEST_REJECT
) {
2425 type
= I40IW_CM_EVENT_MPA_REJECT
;
2426 cm_node
->state
= I40IW_CM_STATE_MPAREJ_RCVD
;
2428 type
= I40IW_CM_EVENT_CONNECTED
;
2429 cm_node
->state
= I40IW_CM_STATE_OFFLOADED
;
2430 i40iw_send_ack(cm_node
);
2434 pr_err("%s wrong cm_node state =%d\n", __func__
, cm_node
->state
);
2437 i40iw_create_event(cm_node
, type
);
2441 * i40iw_indicate_pkt_err - Send up err event to cm
2442 * @cm_node: connection's node
2444 static void i40iw_indicate_pkt_err(struct i40iw_cm_node
*cm_node
)
2446 switch (cm_node
->state
) {
2447 case I40IW_CM_STATE_SYN_SENT
:
2448 case I40IW_CM_STATE_MPAREQ_SENT
:
2449 i40iw_active_open_err(cm_node
, true);
2451 case I40IW_CM_STATE_ESTABLISHED
:
2452 case I40IW_CM_STATE_SYN_RCVD
:
2453 i40iw_passive_open_err(cm_node
, true);
2455 case I40IW_CM_STATE_OFFLOADED
:
2462 * i40iw_check_syn - Check for error on received syn ack
2463 * @cm_node: connection's node
2464 * @tcph: pointer tcp header
2466 static int i40iw_check_syn(struct i40iw_cm_node
*cm_node
, struct tcphdr
*tcph
)
2470 if (ntohl(tcph
->ack_seq
) != cm_node
->tcp_cntxt
.loc_seq_num
) {
2472 i40iw_active_open_err(cm_node
, true);
2478 * i40iw_check_seq - check seq numbers if OK
2479 * @cm_node: connection's node
2480 * @tcph: pointer tcp header
2482 static int i40iw_check_seq(struct i40iw_cm_node
*cm_node
, struct tcphdr
*tcph
)
2487 u32 loc_seq_num
= cm_node
->tcp_cntxt
.loc_seq_num
;
2488 u32 rcv_nxt
= cm_node
->tcp_cntxt
.rcv_nxt
;
2491 seq
= ntohl(tcph
->seq
);
2492 ack_seq
= ntohl(tcph
->ack_seq
);
2493 rcv_wnd
= cm_node
->tcp_cntxt
.rcv_wnd
;
2494 if (ack_seq
!= loc_seq_num
)
2496 else if (!between(seq
, rcv_nxt
, (rcv_nxt
+ rcv_wnd
)))
2499 i40iw_pr_err("seq number\n");
2500 i40iw_indicate_pkt_err(cm_node
);
2506 * i40iw_handle_syn_pkt - is for Passive node
2507 * @cm_node: connection's node
2508 * @rbuf: receive buffer
2510 static void i40iw_handle_syn_pkt(struct i40iw_cm_node
*cm_node
,
2511 struct i40iw_puda_buf
*rbuf
)
2513 struct tcphdr
*tcph
= (struct tcphdr
*)rbuf
->tcph
;
2517 struct i40iw_cm_info nfo
;
2519 optionsize
= (tcph
->doff
<< 2) - sizeof(struct tcphdr
);
2520 inc_sequence
= ntohl(tcph
->seq
);
2522 switch (cm_node
->state
) {
2523 case I40IW_CM_STATE_SYN_SENT
:
2524 case I40IW_CM_STATE_MPAREQ_SENT
:
2525 /* Rcvd syn on active open connection */
2526 i40iw_active_open_err(cm_node
, 1);
2528 case I40IW_CM_STATE_LISTENING
:
2530 if (atomic_read(&cm_node
->listener
->pend_accepts_cnt
) >
2531 cm_node
->listener
->backlog
) {
2532 cm_node
->cm_core
->stats_backlog_drops
++;
2533 i40iw_passive_open_err(cm_node
, false);
2536 ret
= i40iw_handle_tcp_options(cm_node
, tcph
, optionsize
, 1);
2538 i40iw_passive_open_err(cm_node
, false);
2542 cm_node
->tcp_cntxt
.rcv_nxt
= inc_sequence
+ 1;
2543 cm_node
->accept_pend
= 1;
2544 atomic_inc(&cm_node
->listener
->pend_accepts_cnt
);
2546 cm_node
->state
= I40IW_CM_STATE_SYN_RCVD
;
2547 i40iw_get_addr_info(cm_node
, &nfo
);
2548 ret
= i40iw_manage_qhash(cm_node
->iwdev
,
2550 I40IW_QHASH_TYPE_TCP_ESTABLISHED
,
2551 I40IW_QHASH_MANAGE_TYPE_ADD
,
2554 cm_node
->qhash_set
= true;
2556 case I40IW_CM_STATE_CLOSED
:
2557 i40iw_cleanup_retrans_entry(cm_node
);
2558 atomic_inc(&cm_node
->ref_count
);
2559 i40iw_send_reset(cm_node
);
2561 case I40IW_CM_STATE_OFFLOADED
:
2562 case I40IW_CM_STATE_ESTABLISHED
:
2563 case I40IW_CM_STATE_FIN_WAIT1
:
2564 case I40IW_CM_STATE_FIN_WAIT2
:
2565 case I40IW_CM_STATE_MPAREQ_RCVD
:
2566 case I40IW_CM_STATE_LAST_ACK
:
2567 case I40IW_CM_STATE_CLOSING
:
2568 case I40IW_CM_STATE_UNKNOWN
:
2575 * i40iw_handle_synack_pkt - Process SYN+ACK packet (active side)
2576 * @cm_node: connection's node
2577 * @rbuf: receive buffer
2579 static void i40iw_handle_synack_pkt(struct i40iw_cm_node
*cm_node
,
2580 struct i40iw_puda_buf
*rbuf
)
2582 struct tcphdr
*tcph
= (struct tcphdr
*)rbuf
->tcph
;
2587 optionsize
= (tcph
->doff
<< 2) - sizeof(struct tcphdr
);
2588 inc_sequence
= ntohl(tcph
->seq
);
2589 switch (cm_node
->state
) {
2590 case I40IW_CM_STATE_SYN_SENT
:
2591 i40iw_cleanup_retrans_entry(cm_node
);
2593 if (i40iw_check_syn(cm_node
, tcph
)) {
2594 i40iw_pr_err("check syn fail\n");
2597 cm_node
->tcp_cntxt
.rem_ack_num
= ntohl(tcph
->ack_seq
);
2599 ret
= i40iw_handle_tcp_options(cm_node
, tcph
, optionsize
, 0);
2601 i40iw_debug(cm_node
->dev
,
2603 "cm_node=%p tcp_options failed\n",
2607 i40iw_cleanup_retrans_entry(cm_node
);
2608 cm_node
->tcp_cntxt
.rcv_nxt
= inc_sequence
+ 1;
2609 i40iw_send_ack(cm_node
); /* ACK for the syn_ack */
2610 ret
= i40iw_send_mpa_request(cm_node
);
2612 i40iw_debug(cm_node
->dev
,
2614 "cm_node=%p i40iw_send_mpa_request failed\n",
2618 cm_node
->state
= I40IW_CM_STATE_MPAREQ_SENT
;
2620 case I40IW_CM_STATE_MPAREQ_RCVD
:
2621 i40iw_passive_open_err(cm_node
, true);
2623 case I40IW_CM_STATE_LISTENING
:
2624 cm_node
->tcp_cntxt
.loc_seq_num
= ntohl(tcph
->ack_seq
);
2625 i40iw_cleanup_retrans_entry(cm_node
);
2626 cm_node
->state
= I40IW_CM_STATE_CLOSED
;
2627 i40iw_send_reset(cm_node
);
2629 case I40IW_CM_STATE_CLOSED
:
2630 cm_node
->tcp_cntxt
.loc_seq_num
= ntohl(tcph
->ack_seq
);
2631 i40iw_cleanup_retrans_entry(cm_node
);
2632 atomic_inc(&cm_node
->ref_count
);
2633 i40iw_send_reset(cm_node
);
2635 case I40IW_CM_STATE_ESTABLISHED
:
2636 case I40IW_CM_STATE_FIN_WAIT1
:
2637 case I40IW_CM_STATE_FIN_WAIT2
:
2638 case I40IW_CM_STATE_LAST_ACK
:
2639 case I40IW_CM_STATE_OFFLOADED
:
2640 case I40IW_CM_STATE_CLOSING
:
2641 case I40IW_CM_STATE_UNKNOWN
:
2642 case I40IW_CM_STATE_MPAREQ_SENT
:
2649 * i40iw_handle_ack_pkt - process packet with ACK
2650 * @cm_node: connection's node
2651 * @rbuf: receive buffer
2653 static int i40iw_handle_ack_pkt(struct i40iw_cm_node
*cm_node
,
2654 struct i40iw_puda_buf
*rbuf
)
2656 struct tcphdr
*tcph
= (struct tcphdr
*)rbuf
->tcph
;
2660 u32 datasize
= rbuf
->datalen
;
2662 optionsize
= (tcph
->doff
<< 2) - sizeof(struct tcphdr
);
2664 if (i40iw_check_seq(cm_node
, tcph
))
2667 inc_sequence
= ntohl(tcph
->seq
);
2668 switch (cm_node
->state
) {
2669 case I40IW_CM_STATE_SYN_RCVD
:
2670 i40iw_cleanup_retrans_entry(cm_node
);
2671 ret
= i40iw_handle_tcp_options(cm_node
, tcph
, optionsize
, 1);
2674 cm_node
->tcp_cntxt
.rem_ack_num
= ntohl(tcph
->ack_seq
);
2675 cm_node
->state
= I40IW_CM_STATE_ESTABLISHED
;
2677 cm_node
->tcp_cntxt
.rcv_nxt
= inc_sequence
+ datasize
;
2678 i40iw_handle_rcv_mpa(cm_node
, rbuf
);
2681 case I40IW_CM_STATE_ESTABLISHED
:
2682 i40iw_cleanup_retrans_entry(cm_node
);
2684 cm_node
->tcp_cntxt
.rcv_nxt
= inc_sequence
+ datasize
;
2685 i40iw_handle_rcv_mpa(cm_node
, rbuf
);
2688 case I40IW_CM_STATE_MPAREQ_SENT
:
2689 cm_node
->tcp_cntxt
.rem_ack_num
= ntohl(tcph
->ack_seq
);
2691 cm_node
->tcp_cntxt
.rcv_nxt
= inc_sequence
+ datasize
;
2692 i40iw_handle_rcv_mpa(cm_node
, rbuf
);
2695 case I40IW_CM_STATE_LISTENING
:
2696 i40iw_cleanup_retrans_entry(cm_node
);
2697 cm_node
->state
= I40IW_CM_STATE_CLOSED
;
2698 i40iw_send_reset(cm_node
);
2700 case I40IW_CM_STATE_CLOSED
:
2701 i40iw_cleanup_retrans_entry(cm_node
);
2702 atomic_inc(&cm_node
->ref_count
);
2703 i40iw_send_reset(cm_node
);
2705 case I40IW_CM_STATE_LAST_ACK
:
2706 case I40IW_CM_STATE_CLOSING
:
2707 i40iw_cleanup_retrans_entry(cm_node
);
2708 cm_node
->state
= I40IW_CM_STATE_CLOSED
;
2709 if (!cm_node
->accept_pend
)
2710 cm_node
->cm_id
->rem_ref(cm_node
->cm_id
);
2711 i40iw_rem_ref_cm_node(cm_node
);
2713 case I40IW_CM_STATE_FIN_WAIT1
:
2714 i40iw_cleanup_retrans_entry(cm_node
);
2715 cm_node
->state
= I40IW_CM_STATE_FIN_WAIT2
;
2717 case I40IW_CM_STATE_SYN_SENT
:
2718 case I40IW_CM_STATE_FIN_WAIT2
:
2719 case I40IW_CM_STATE_OFFLOADED
:
2720 case I40IW_CM_STATE_MPAREQ_RCVD
:
2721 case I40IW_CM_STATE_UNKNOWN
:
2723 i40iw_cleanup_retrans_entry(cm_node
);
2730 * i40iw_process_packet - process cm packet
2731 * @cm_node: connection's node
2732 * @rbuf: receive buffer
2734 static void i40iw_process_packet(struct i40iw_cm_node
*cm_node
,
2735 struct i40iw_puda_buf
*rbuf
)
2737 enum i40iw_tcpip_pkt_type pkt_type
= I40IW_PKT_TYPE_UNKNOWN
;
2738 struct tcphdr
*tcph
= (struct tcphdr
*)rbuf
->tcph
;
2743 pkt_type
= I40IW_PKT_TYPE_RST
;
2744 } else if (tcph
->syn
) {
2745 pkt_type
= I40IW_PKT_TYPE_SYN
;
2747 pkt_type
= I40IW_PKT_TYPE_SYNACK
;
2748 } else if (tcph
->ack
) {
2749 pkt_type
= I40IW_PKT_TYPE_ACK
;
2755 case I40IW_PKT_TYPE_SYN
:
2756 i40iw_handle_syn_pkt(cm_node
, rbuf
);
2758 case I40IW_PKT_TYPE_SYNACK
:
2759 i40iw_handle_synack_pkt(cm_node
, rbuf
);
2761 case I40IW_PKT_TYPE_ACK
:
2762 ret
= i40iw_handle_ack_pkt(cm_node
, rbuf
);
2763 if (fin_set
&& !ret
)
2764 i40iw_handle_fin_pkt(cm_node
);
2766 case I40IW_PKT_TYPE_RST
:
2767 i40iw_handle_rst_pkt(cm_node
, rbuf
);
2771 (!i40iw_check_seq(cm_node
, (struct tcphdr
*)rbuf
->tcph
)))
2772 i40iw_handle_fin_pkt(cm_node
);
2778 * i40iw_make_listen_node - create a listen node with params
2779 * @cm_core: cm's core
2780 * @iwdev: iwarp device structure
2781 * @cm_info: quad info for connection
2783 static struct i40iw_cm_listener
*i40iw_make_listen_node(
2784 struct i40iw_cm_core
*cm_core
,
2785 struct i40iw_device
*iwdev
,
2786 struct i40iw_cm_info
*cm_info
)
2788 struct i40iw_cm_listener
*listener
;
2789 unsigned long flags
;
2791 /* cannot have multiple matching listeners */
2792 listener
= i40iw_find_listener(cm_core
, cm_info
->loc_addr
,
2795 I40IW_CM_LISTENER_EITHER_STATE
);
2797 (listener
->listener_state
== I40IW_CM_LISTENER_ACTIVE_STATE
)) {
2798 atomic_dec(&listener
->ref_count
);
2799 i40iw_debug(cm_core
->dev
,
2801 "Not creating listener since it already exists\n");
2806 /* create a CM listen node (1/2 node to compare incoming traffic to) */
2807 listener
= kzalloc(sizeof(*listener
), GFP_ATOMIC
);
2810 cm_core
->stats_listen_nodes_created
++;
2811 memcpy(listener
->loc_addr
, cm_info
->loc_addr
, sizeof(listener
->loc_addr
));
2812 listener
->loc_port
= cm_info
->loc_port
;
2814 INIT_LIST_HEAD(&listener
->child_listen_list
);
2816 atomic_set(&listener
->ref_count
, 1);
2818 listener
->reused_node
= 1;
2821 listener
->cm_id
= cm_info
->cm_id
;
2822 listener
->ipv4
= cm_info
->ipv4
;
2823 listener
->vlan_id
= cm_info
->vlan_id
;
2824 atomic_set(&listener
->pend_accepts_cnt
, 0);
2825 listener
->cm_core
= cm_core
;
2826 listener
->iwdev
= iwdev
;
2828 listener
->backlog
= cm_info
->backlog
;
2829 listener
->listener_state
= I40IW_CM_LISTENER_ACTIVE_STATE
;
2831 if (!listener
->reused_node
) {
2832 spin_lock_irqsave(&cm_core
->listen_list_lock
, flags
);
2833 list_add(&listener
->list
, &cm_core
->listen_nodes
);
2834 spin_unlock_irqrestore(&cm_core
->listen_list_lock
, flags
);
2841 * i40iw_create_cm_node - make a connection node with params
2842 * @cm_core: cm's core
2843 * @iwdev: iwarp device structure
2844 * @private_data_len: len to provate data for mpa request
2845 * @private_data: pointer to private data for connection
2846 * @cm_info: quad info for connection
2848 static struct i40iw_cm_node
*i40iw_create_cm_node(
2849 struct i40iw_cm_core
*cm_core
,
2850 struct i40iw_device
*iwdev
,
2851 u16 private_data_len
,
2853 struct i40iw_cm_info
*cm_info
)
2856 struct i40iw_cm_node
*cm_node
;
2857 struct i40iw_cm_listener
*loopback_remotelistener
;
2858 struct i40iw_cm_node
*loopback_remotenode
;
2859 struct i40iw_cm_info loopback_cm_info
;
2861 /* create a CM connection node */
2862 cm_node
= i40iw_make_cm_node(cm_core
, iwdev
, cm_info
, NULL
);
2865 /* set our node side to client (active) side */
2866 cm_node
->tcp_cntxt
.client
= 1;
2867 cm_node
->tcp_cntxt
.rcv_wscale
= I40IW_CM_DEFAULT_RCV_WND_SCALE
;
2869 if (!memcmp(cm_info
->loc_addr
, cm_info
->rem_addr
, sizeof(cm_info
->loc_addr
))) {
2870 loopback_remotelistener
= i40iw_find_listener(
2875 I40IW_CM_LISTENER_ACTIVE_STATE
);
2876 if (!loopback_remotelistener
) {
2877 i40iw_create_event(cm_node
, I40IW_CM_EVENT_ABORTED
);
2879 loopback_cm_info
= *cm_info
;
2880 loopback_cm_info
.loc_port
= cm_info
->rem_port
;
2881 loopback_cm_info
.rem_port
= cm_info
->loc_port
;
2882 loopback_cm_info
.cm_id
= loopback_remotelistener
->cm_id
;
2883 loopback_cm_info
.ipv4
= cm_info
->ipv4
;
2884 loopback_remotenode
= i40iw_make_cm_node(cm_core
,
2887 loopback_remotelistener
);
2888 if (!loopback_remotenode
) {
2889 i40iw_rem_ref_cm_node(cm_node
);
2892 cm_core
->stats_loopbacks
++;
2893 loopback_remotenode
->loopbackpartner
= cm_node
;
2894 loopback_remotenode
->tcp_cntxt
.rcv_wscale
=
2895 I40IW_CM_DEFAULT_RCV_WND_SCALE
;
2896 cm_node
->loopbackpartner
= loopback_remotenode
;
2897 memcpy(loopback_remotenode
->pdata_buf
, private_data
,
2899 loopback_remotenode
->pdata
.size
= private_data_len
;
2901 cm_node
->state
= I40IW_CM_STATE_OFFLOADED
;
2902 cm_node
->tcp_cntxt
.rcv_nxt
=
2903 loopback_remotenode
->tcp_cntxt
.loc_seq_num
;
2904 loopback_remotenode
->tcp_cntxt
.rcv_nxt
=
2905 cm_node
->tcp_cntxt
.loc_seq_num
;
2906 cm_node
->tcp_cntxt
.max_snd_wnd
=
2907 loopback_remotenode
->tcp_cntxt
.rcv_wnd
;
2908 loopback_remotenode
->tcp_cntxt
.max_snd_wnd
= cm_node
->tcp_cntxt
.rcv_wnd
;
2909 cm_node
->tcp_cntxt
.snd_wnd
= loopback_remotenode
->tcp_cntxt
.rcv_wnd
;
2910 loopback_remotenode
->tcp_cntxt
.snd_wnd
= cm_node
->tcp_cntxt
.rcv_wnd
;
2911 cm_node
->tcp_cntxt
.snd_wscale
= loopback_remotenode
->tcp_cntxt
.rcv_wscale
;
2912 loopback_remotenode
->tcp_cntxt
.snd_wscale
= cm_node
->tcp_cntxt
.rcv_wscale
;
2913 loopback_remotenode
->state
= I40IW_CM_STATE_MPAREQ_RCVD
;
2914 i40iw_create_event(loopback_remotenode
, I40IW_CM_EVENT_MPA_REQ
);
2919 cm_node
->pdata
.size
= private_data_len
;
2920 cm_node
->pdata
.addr
= cm_node
->pdata_buf
;
2922 memcpy(cm_node
->pdata_buf
, private_data
, private_data_len
);
2924 cm_node
->state
= I40IW_CM_STATE_SYN_SENT
;
2925 ret
= i40iw_send_syn(cm_node
, 0);
2929 i40iw_debug(cm_node
->dev
,
2931 "Api - connect() FAILED: dest addr=%pI4",
2934 i40iw_debug(cm_node
->dev
, I40IW_DEBUG_CM
,
2935 "Api - connect() FAILED: dest addr=%pI6",
2937 i40iw_rem_ref_cm_node(cm_node
);
2942 i40iw_debug(cm_node
->dev
,
2944 "Api - connect(): port=0x%04x, cm_node=%p, cm_id = %p.\n",
2953 * i40iw_cm_reject - reject and teardown a connection
2954 * @cm_node: connection's node
2955 * @pdate: ptr to private data for reject
2956 * @plen: size of private data
2958 static int i40iw_cm_reject(struct i40iw_cm_node
*cm_node
, const void *pdata
, u8 plen
)
2963 struct iw_cm_id
*cm_id
= cm_node
->cm_id
;
2964 struct i40iw_cm_node
*loopback
= cm_node
->loopbackpartner
;
2966 if (cm_node
->tcp_cntxt
.client
)
2968 i40iw_cleanup_retrans_entry(cm_node
);
2971 passive_state
= atomic_add_return(1, &cm_node
->passive_state
);
2972 if (passive_state
== I40IW_SEND_RESET_EVENT
) {
2973 cm_node
->state
= I40IW_CM_STATE_CLOSED
;
2974 i40iw_rem_ref_cm_node(cm_node
);
2976 if (cm_node
->state
== I40IW_CM_STATE_LISTENER_DESTROYED
) {
2977 i40iw_rem_ref_cm_node(cm_node
);
2979 ret
= i40iw_send_mpa_reject(cm_node
, pdata
, plen
);
2981 cm_node
->state
= I40IW_CM_STATE_CLOSED
;
2982 err
= i40iw_send_reset(cm_node
);
2984 i40iw_pr_err("send reset failed\n");
2986 cm_id
->add_ref(cm_id
);
2991 cm_node
->cm_id
= NULL
;
2992 if (cm_node
->state
== I40IW_CM_STATE_LISTENER_DESTROYED
) {
2993 i40iw_rem_ref_cm_node(cm_node
);
2994 i40iw_rem_ref_cm_node(loopback
);
2996 ret
= i40iw_send_cm_event(loopback
,
2998 IW_CM_EVENT_CONNECT_REPLY
,
3000 i40iw_rem_ref_cm_node(cm_node
);
3001 loopback
->state
= I40IW_CM_STATE_CLOSING
;
3003 cm_id
= loopback
->cm_id
;
3004 i40iw_rem_ref_cm_node(loopback
);
3005 cm_id
->rem_ref(cm_id
);
3013 * i40iw_cm_close - close of cm connection
3014 * @cm_node: connection's node
3016 static int i40iw_cm_close(struct i40iw_cm_node
*cm_node
)
3023 switch (cm_node
->state
) {
3024 case I40IW_CM_STATE_SYN_RCVD
:
3025 case I40IW_CM_STATE_SYN_SENT
:
3026 case I40IW_CM_STATE_ONE_SIDE_ESTABLISHED
:
3027 case I40IW_CM_STATE_ESTABLISHED
:
3028 case I40IW_CM_STATE_ACCEPTING
:
3029 case I40IW_CM_STATE_MPAREQ_SENT
:
3030 case I40IW_CM_STATE_MPAREQ_RCVD
:
3031 i40iw_cleanup_retrans_entry(cm_node
);
3032 i40iw_send_reset(cm_node
);
3034 case I40IW_CM_STATE_CLOSE_WAIT
:
3035 cm_node
->state
= I40IW_CM_STATE_LAST_ACK
;
3036 i40iw_send_fin(cm_node
);
3038 case I40IW_CM_STATE_FIN_WAIT1
:
3039 case I40IW_CM_STATE_FIN_WAIT2
:
3040 case I40IW_CM_STATE_LAST_ACK
:
3041 case I40IW_CM_STATE_TIME_WAIT
:
3042 case I40IW_CM_STATE_CLOSING
:
3045 case I40IW_CM_STATE_LISTENING
:
3046 i40iw_cleanup_retrans_entry(cm_node
);
3047 i40iw_send_reset(cm_node
);
3049 case I40IW_CM_STATE_MPAREJ_RCVD
:
3050 case I40IW_CM_STATE_UNKNOWN
:
3051 case I40IW_CM_STATE_INITED
:
3052 case I40IW_CM_STATE_CLOSED
:
3053 case I40IW_CM_STATE_LISTENER_DESTROYED
:
3054 i40iw_rem_ref_cm_node(cm_node
);
3056 case I40IW_CM_STATE_OFFLOADED
:
3057 if (cm_node
->send_entry
)
3058 i40iw_pr_err("send_entry\n");
3059 i40iw_rem_ref_cm_node(cm_node
);
3066 * i40iw_receive_ilq - recv an ETHERNET packet, and process it
3068 * @dev: FPK dev struct
3069 * @rbuf: receive buffer
3071 void i40iw_receive_ilq(struct i40iw_sc_dev
*dev
, struct i40iw_puda_buf
*rbuf
)
3073 struct i40iw_cm_node
*cm_node
;
3074 struct i40iw_cm_listener
*listener
;
3076 struct ipv6hdr
*ip6h
;
3077 struct tcphdr
*tcph
;
3078 struct i40iw_cm_info cm_info
;
3079 struct i40iw_device
*iwdev
= (struct i40iw_device
*)dev
->back_dev
;
3080 struct i40iw_cm_core
*cm_core
= &iwdev
->cm_core
;
3081 struct vlan_ethhdr
*ethh
;
3083 /* if vlan, then maclen = 18 else 14 */
3084 iph
= (struct iphdr
*)rbuf
->iph
;
3085 memset(&cm_info
, 0, sizeof(cm_info
));
3087 i40iw_debug_buf(dev
,
3089 "RECEIVE ILQ BUFFER",
3092 ethh
= (struct vlan_ethhdr
*)rbuf
->mem
.va
;
3094 if (ethh
->h_vlan_proto
== htons(ETH_P_8021Q
)) {
3095 cm_info
.vlan_id
= ntohs(ethh
->h_vlan_TCI
) & VLAN_VID_MASK
;
3096 i40iw_debug(cm_core
->dev
,
3102 cm_info
.vlan_id
= I40IW_NO_VLAN
;
3104 tcph
= (struct tcphdr
*)rbuf
->tcph
;
3107 cm_info
.loc_addr
[0] = ntohl(iph
->daddr
);
3108 cm_info
.rem_addr
[0] = ntohl(iph
->saddr
);
3109 cm_info
.ipv4
= true;
3111 ip6h
= (struct ipv6hdr
*)rbuf
->iph
;
3112 i40iw_copy_ip_ntohl(cm_info
.loc_addr
,
3113 ip6h
->daddr
.in6_u
.u6_addr32
);
3114 i40iw_copy_ip_ntohl(cm_info
.rem_addr
,
3115 ip6h
->saddr
.in6_u
.u6_addr32
);
3116 cm_info
.ipv4
= false;
3118 cm_info
.loc_port
= ntohs(tcph
->dest
);
3119 cm_info
.rem_port
= ntohs(tcph
->source
);
3120 cm_node
= i40iw_find_node(cm_core
,
3128 /* Only type of packet accepted are for */
3129 /* the PASSIVE open (syn only) */
3130 if (!tcph
->syn
|| tcph
->ack
)
3133 i40iw_find_listener(cm_core
,
3137 I40IW_CM_LISTENER_ACTIVE_STATE
);
3139 cm_info
.cm_id
= NULL
;
3140 i40iw_debug(cm_core
->dev
,
3142 "%s no listener found\n",
3146 cm_info
.cm_id
= listener
->cm_id
;
3147 cm_node
= i40iw_make_cm_node(cm_core
, iwdev
, &cm_info
, listener
);
3149 i40iw_debug(cm_core
->dev
,
3151 "%s allocate node failed\n",
3153 atomic_dec(&listener
->ref_count
);
3156 if (!tcph
->rst
&& !tcph
->fin
) {
3157 cm_node
->state
= I40IW_CM_STATE_LISTENING
;
3159 i40iw_rem_ref_cm_node(cm_node
);
3162 atomic_inc(&cm_node
->ref_count
);
3163 } else if (cm_node
->state
== I40IW_CM_STATE_OFFLOADED
) {
3164 i40iw_rem_ref_cm_node(cm_node
);
3167 i40iw_process_packet(cm_node
, rbuf
);
3168 i40iw_rem_ref_cm_node(cm_node
);
3172 * i40iw_setup_cm_core - allocate a top level instance of a cm
3174 * @iwdev: iwarp device structure
3176 void i40iw_setup_cm_core(struct i40iw_device
*iwdev
)
3178 struct i40iw_cm_core
*cm_core
= &iwdev
->cm_core
;
3180 cm_core
->iwdev
= iwdev
;
3181 cm_core
->dev
= &iwdev
->sc_dev
;
3183 INIT_LIST_HEAD(&cm_core
->connected_nodes
);
3184 INIT_LIST_HEAD(&cm_core
->listen_nodes
);
3186 init_timer(&cm_core
->tcp_timer
);
3187 cm_core
->tcp_timer
.function
= i40iw_cm_timer_tick
;
3188 cm_core
->tcp_timer
.data
= (unsigned long)cm_core
;
3190 spin_lock_init(&cm_core
->ht_lock
);
3191 spin_lock_init(&cm_core
->listen_list_lock
);
3193 cm_core
->event_wq
= create_singlethread_workqueue("iwewq");
3194 cm_core
->disconn_wq
= create_singlethread_workqueue("iwdwq");
3198 * i40iw_cleanup_cm_core - deallocate a top level instance of a
3200 * @cm_core: cm's core
3202 void i40iw_cleanup_cm_core(struct i40iw_cm_core
*cm_core
)
3204 unsigned long flags
;
3209 spin_lock_irqsave(&cm_core
->ht_lock
, flags
);
3210 if (timer_pending(&cm_core
->tcp_timer
))
3211 del_timer_sync(&cm_core
->tcp_timer
);
3212 spin_unlock_irqrestore(&cm_core
->ht_lock
, flags
);
3214 destroy_workqueue(cm_core
->event_wq
);
3215 destroy_workqueue(cm_core
->disconn_wq
);
3219 * i40iw_init_tcp_ctx - setup qp context
3220 * @cm_node: connection's node
3221 * @tcp_info: offload info for tcp
3222 * @iwqp: associate qp for the connection
3224 static void i40iw_init_tcp_ctx(struct i40iw_cm_node
*cm_node
,
3225 struct i40iw_tcp_offload_info
*tcp_info
,
3226 struct i40iw_qp
*iwqp
)
3228 tcp_info
->ipv4
= cm_node
->ipv4
;
3229 tcp_info
->drop_ooo_seg
= true;
3230 tcp_info
->wscale
= true;
3231 tcp_info
->ignore_tcp_opt
= true;
3232 tcp_info
->ignore_tcp_uns_opt
= true;
3233 tcp_info
->no_nagle
= false;
3235 tcp_info
->ttl
= I40IW_DEFAULT_TTL
;
3236 tcp_info
->rtt_var
= cpu_to_le32(I40IW_DEFAULT_RTT_VAR
);
3237 tcp_info
->ss_thresh
= cpu_to_le32(I40IW_DEFAULT_SS_THRESH
);
3238 tcp_info
->rexmit_thresh
= I40IW_DEFAULT_REXMIT_THRESH
;
3240 tcp_info
->tcp_state
= I40IW_TCP_STATE_ESTABLISHED
;
3241 tcp_info
->snd_wscale
= cm_node
->tcp_cntxt
.snd_wscale
;
3242 tcp_info
->rcv_wscale
= cm_node
->tcp_cntxt
.rcv_wscale
;
3244 tcp_info
->snd_nxt
= cpu_to_le32(cm_node
->tcp_cntxt
.loc_seq_num
);
3245 tcp_info
->snd_wnd
= cpu_to_le32(cm_node
->tcp_cntxt
.snd_wnd
);
3246 tcp_info
->rcv_nxt
= cpu_to_le32(cm_node
->tcp_cntxt
.rcv_nxt
);
3247 tcp_info
->snd_max
= cpu_to_le32(cm_node
->tcp_cntxt
.loc_seq_num
);
3249 tcp_info
->snd_una
= cpu_to_le32(cm_node
->tcp_cntxt
.loc_seq_num
);
3250 tcp_info
->cwnd
= cpu_to_le32(2 * cm_node
->tcp_cntxt
.mss
);
3251 tcp_info
->snd_wl1
= cpu_to_le32(cm_node
->tcp_cntxt
.rcv_nxt
);
3252 tcp_info
->snd_wl2
= cpu_to_le32(cm_node
->tcp_cntxt
.loc_seq_num
);
3253 tcp_info
->max_snd_window
= cpu_to_le32(cm_node
->tcp_cntxt
.max_snd_wnd
);
3254 tcp_info
->rcv_wnd
= cpu_to_le32(cm_node
->tcp_cntxt
.rcv_wnd
<<
3255 cm_node
->tcp_cntxt
.rcv_wscale
);
3257 tcp_info
->flow_label
= 0;
3258 tcp_info
->snd_mss
= cpu_to_le32(((u32
)cm_node
->tcp_cntxt
.mss
));
3259 if (cm_node
->vlan_id
< VLAN_TAG_PRESENT
) {
3260 tcp_info
->insert_vlan_tag
= true;
3261 tcp_info
->vlan_tag
= cpu_to_le16(cm_node
->vlan_id
);
3263 if (cm_node
->ipv4
) {
3264 tcp_info
->src_port
= cpu_to_le16(cm_node
->loc_port
);
3265 tcp_info
->dst_port
= cpu_to_le16(cm_node
->rem_port
);
3267 tcp_info
->dest_ip_addr3
= cpu_to_le32(cm_node
->rem_addr
[0]);
3268 tcp_info
->local_ipaddr3
= cpu_to_le32(cm_node
->loc_addr
[0]);
3269 tcp_info
->arp_idx
= cpu_to_le32(i40iw_arp_table(iwqp
->iwdev
,
3270 &tcp_info
->dest_ip_addr3
,
3273 I40IW_ARP_RESOLVE
));
3275 tcp_info
->src_port
= cpu_to_le16(cm_node
->loc_port
);
3276 tcp_info
->dst_port
= cpu_to_le16(cm_node
->rem_port
);
3277 tcp_info
->dest_ip_addr0
= cpu_to_le32(cm_node
->rem_addr
[0]);
3278 tcp_info
->dest_ip_addr1
= cpu_to_le32(cm_node
->rem_addr
[1]);
3279 tcp_info
->dest_ip_addr2
= cpu_to_le32(cm_node
->rem_addr
[2]);
3280 tcp_info
->dest_ip_addr3
= cpu_to_le32(cm_node
->rem_addr
[3]);
3281 tcp_info
->local_ipaddr0
= cpu_to_le32(cm_node
->loc_addr
[0]);
3282 tcp_info
->local_ipaddr1
= cpu_to_le32(cm_node
->loc_addr
[1]);
3283 tcp_info
->local_ipaddr2
= cpu_to_le32(cm_node
->loc_addr
[2]);
3284 tcp_info
->local_ipaddr3
= cpu_to_le32(cm_node
->loc_addr
[3]);
3285 tcp_info
->arp_idx
= cpu_to_le32(i40iw_arp_table(
3287 &tcp_info
->dest_ip_addr0
,
3290 I40IW_ARP_RESOLVE
));
3295 * i40iw_cm_init_tsa_conn - setup qp for RTS
3296 * @iwqp: associate qp for the connection
3297 * @cm_node: connection's node
3299 static void i40iw_cm_init_tsa_conn(struct i40iw_qp
*iwqp
,
3300 struct i40iw_cm_node
*cm_node
)
3302 struct i40iw_tcp_offload_info tcp_info
;
3303 struct i40iwarp_offload_info
*iwarp_info
;
3304 struct i40iw_qp_host_ctx_info
*ctx_info
;
3305 struct i40iw_device
*iwdev
= iwqp
->iwdev
;
3306 struct i40iw_sc_dev
*dev
= &iwqp
->iwdev
->sc_dev
;
3308 memset(&tcp_info
, 0x00, sizeof(struct i40iw_tcp_offload_info
));
3309 iwarp_info
= &iwqp
->iwarp_info
;
3310 ctx_info
= &iwqp
->ctx_info
;
3312 ctx_info
->tcp_info
= &tcp_info
;
3313 ctx_info
->send_cq_num
= iwqp
->iwscq
->sc_cq
.cq_uk
.cq_id
;
3314 ctx_info
->rcv_cq_num
= iwqp
->iwrcq
->sc_cq
.cq_uk
.cq_id
;
3316 iwarp_info
->ord_size
= cm_node
->ord_size
;
3317 iwarp_info
->ird_size
= i40iw_derive_hw_ird_setting(cm_node
->ird_size
);
3319 if (iwarp_info
->ord_size
== 1)
3320 iwarp_info
->ord_size
= 2;
3322 iwarp_info
->rd_enable
= true;
3323 iwarp_info
->rdmap_ver
= 1;
3324 iwarp_info
->ddp_ver
= 1;
3326 iwarp_info
->pd_id
= iwqp
->iwpd
->sc_pd
.pd_id
;
3328 ctx_info
->tcp_info_valid
= true;
3329 ctx_info
->iwarp_info_valid
= true;
3331 i40iw_init_tcp_ctx(cm_node
, &tcp_info
, iwqp
);
3332 if (cm_node
->snd_mark_en
) {
3333 iwarp_info
->snd_mark_en
= true;
3334 iwarp_info
->snd_mark_offset
= (tcp_info
.snd_nxt
&
3335 SNDMARKER_SEQNMASK
) + cm_node
->lsmm_size
;
3338 cm_node
->state
= I40IW_CM_STATE_OFFLOADED
;
3339 tcp_info
.tcp_state
= I40IW_TCP_STATE_ESTABLISHED
;
3340 tcp_info
.src_mac_addr_idx
= iwdev
->mac_ip_table_idx
;
3342 dev
->iw_priv_qp_ops
->qp_setctx(&iwqp
->sc_qp
, (u64
*)(iwqp
->host_ctx
.va
), ctx_info
);
3344 /* once tcp_info is set, no need to do it again */
3345 ctx_info
->tcp_info_valid
= false;
3346 ctx_info
->iwarp_info_valid
= false;
3350 * i40iw_cm_disconn - when a connection is being closed
3351 * @iwqp: associate qp for the connection
3353 int i40iw_cm_disconn(struct i40iw_qp
*iwqp
)
3355 struct disconn_work
*work
;
3356 struct i40iw_device
*iwdev
= iwqp
->iwdev
;
3357 struct i40iw_cm_core
*cm_core
= &iwdev
->cm_core
;
3359 work
= kzalloc(sizeof(*work
), GFP_ATOMIC
);
3361 return -ENOMEM
; /* Timer will clean up */
3363 i40iw_add_ref(&iwqp
->ibqp
);
3365 INIT_WORK(&work
->work
, i40iw_disconnect_worker
);
3366 queue_work(cm_core
->disconn_wq
, &work
->work
);
3371 * i40iw_loopback_nop - Send a nop
3372 * @qp: associated hw qp
3374 static void i40iw_loopback_nop(struct i40iw_sc_qp
*qp
)
3379 wqe
= qp
->qp_uk
.sq_base
->elem
;
3380 set_64bit_val(wqe
, 0, 0);
3381 set_64bit_val(wqe
, 8, 0);
3382 set_64bit_val(wqe
, 16, 0);
3384 header
= LS_64(I40IWQP_OP_NOP
, I40IWQPSQ_OPCODE
) |
3385 LS_64(0, I40IWQPSQ_SIGCOMPL
) |
3386 LS_64(qp
->qp_uk
.swqe_polarity
, I40IWQPSQ_VALID
);
3387 set_64bit_val(wqe
, 24, header
);
3391 * i40iw_qp_disconnect - free qp and close cm
3392 * @iwqp: associate qp for the connection
3394 static void i40iw_qp_disconnect(struct i40iw_qp
*iwqp
)
3396 struct i40iw_device
*iwdev
;
3397 struct i40iw_ib_device
*iwibdev
;
3399 iwdev
= to_iwdev(iwqp
->ibqp
.device
);
3401 i40iw_pr_err("iwdev == NULL\n");
3405 iwibdev
= iwdev
->iwibdev
;
3407 if (iwqp
->active_conn
) {
3408 /* indicate this connection is NOT active */
3409 iwqp
->active_conn
= 0;
3411 /* Need to free the Last Streaming Mode Message */
3412 if (iwqp
->ietf_mem
.va
) {
3414 iwibdev
->ibdev
.dereg_mr(iwqp
->lsmm_mr
);
3415 i40iw_free_dma_mem(iwdev
->sc_dev
.hw
, &iwqp
->ietf_mem
);
3419 /* close the CM node down if it is still active */
3420 if (iwqp
->cm_node
) {
3421 i40iw_debug(&iwdev
->sc_dev
, I40IW_DEBUG_CM
, "%s Call close API\n", __func__
);
3422 i40iw_cm_close(iwqp
->cm_node
);
3427 * i40iw_cm_disconn_true - called by worker thread to disconnect qp
3428 * @iwqp: associate qp for the connection
3430 static void i40iw_cm_disconn_true(struct i40iw_qp
*iwqp
)
3432 struct iw_cm_id
*cm_id
;
3433 struct i40iw_device
*iwdev
;
3434 struct i40iw_sc_qp
*qp
= &iwqp
->sc_qp
;
3436 u8 original_hw_tcp_state
;
3437 u8 original_ibqp_state
;
3438 int disconn_status
= 0;
3439 int issue_disconn
= 0;
3440 int issue_close
= 0;
3441 int issue_flush
= 0;
3442 struct ib_event ibevent
;
3443 unsigned long flags
;
3447 i40iw_pr_err("iwqp == NULL\n");
3451 spin_lock_irqsave(&iwqp
->lock
, flags
);
3452 cm_id
= iwqp
->cm_id
;
3453 /* make sure we havent already closed this connection */
3455 spin_unlock_irqrestore(&iwqp
->lock
, flags
);
3459 iwdev
= to_iwdev(iwqp
->ibqp
.device
);
3461 original_hw_tcp_state
= iwqp
->hw_tcp_state
;
3462 original_ibqp_state
= iwqp
->ibqp_state
;
3463 last_ae
= iwqp
->last_aeq
;
3465 if (qp
->term_flags
) {
3469 /*When term timer expires after cm_timer, don't want
3470 *terminate-handler to issue cm_disconn which can re-free
3471 *a QP even after its refcnt=0.
3473 del_timer(&iwqp
->terminate_timer
);
3474 if (!iwqp
->flush_issued
) {
3475 iwqp
->flush_issued
= 1;
3478 } else if ((original_hw_tcp_state
== I40IW_TCP_STATE_CLOSE_WAIT
) ||
3479 ((original_ibqp_state
== IB_QPS_RTS
) &&
3480 (last_ae
== I40IW_AE_LLP_CONNECTION_RESET
))) {
3482 if (last_ae
== I40IW_AE_LLP_CONNECTION_RESET
)
3483 disconn_status
= -ECONNRESET
;
3486 if (((original_hw_tcp_state
== I40IW_TCP_STATE_CLOSED
) ||
3487 (original_hw_tcp_state
== I40IW_TCP_STATE_TIME_WAIT
) ||
3488 (last_ae
== I40IW_AE_RDMAP_ROE_BAD_LLP_CLOSE
) ||
3489 (last_ae
== I40IW_AE_LLP_CONNECTION_RESET
))) {
3492 if (!iwqp
->flush_issued
) {
3493 iwqp
->flush_issued
= 1;
3498 spin_unlock_irqrestore(&iwqp
->lock
, flags
);
3499 if (issue_flush
&& !iwqp
->destroyed
) {
3500 /* Flush the queues */
3501 i40iw_flush_wqes(iwdev
, iwqp
);
3503 if (qp
->term_flags
) {
3504 ibevent
.device
= iwqp
->ibqp
.device
;
3505 ibevent
.event
= (qp
->eventtype
== TERM_EVENT_QP_FATAL
) ?
3506 IB_EVENT_QP_FATAL
: IB_EVENT_QP_ACCESS_ERR
;
3507 ibevent
.element
.qp
= &iwqp
->ibqp
;
3508 iwqp
->ibqp
.event_handler(&ibevent
, iwqp
->ibqp
.qp_context
);
3512 if (cm_id
&& cm_id
->event_handler
) {
3513 if (issue_disconn
) {
3514 ret
= i40iw_send_cm_event(NULL
,
3516 IW_CM_EVENT_DISCONNECT
,
3520 i40iw_debug(&iwdev
->sc_dev
,
3522 "disconnect event failed %s: - cm_id = %p\n",
3526 i40iw_qp_disconnect(iwqp
);
3527 cm_id
->provider_data
= iwqp
;
3528 ret
= i40iw_send_cm_event(NULL
, cm_id
, IW_CM_EVENT_CLOSE
, 0);
3530 i40iw_debug(&iwdev
->sc_dev
,
3532 "close event failed %s: - cm_id = %p\n",
3534 cm_id
->rem_ref(cm_id
);
3540 * i40iw_disconnect_worker - worker for connection close
3541 * @work: points or disconn structure
3543 static void i40iw_disconnect_worker(struct work_struct
*work
)
3545 struct disconn_work
*dwork
= container_of(work
, struct disconn_work
, work
);
3546 struct i40iw_qp
*iwqp
= dwork
->iwqp
;
3549 i40iw_cm_disconn_true(iwqp
);
3550 i40iw_rem_ref(&iwqp
->ibqp
);
3554 * i40iw_accept - registered call for connection to be accepted
3555 * @cm_id: cm information for passive connection
3556 * @conn_param: accpet parameters
3558 int i40iw_accept(struct iw_cm_id
*cm_id
, struct iw_cm_conn_param
*conn_param
)
3561 struct i40iw_qp
*iwqp
;
3562 struct i40iw_device
*iwdev
;
3563 struct i40iw_sc_dev
*dev
;
3564 struct i40iw_cm_node
*cm_node
;
3565 struct ib_qp_attr attr
;
3567 struct i40iw_ib_device
*iwibdev
;
3569 struct i40iw_pd
*iwpd
;
3571 struct i40iw_kmem_info accept
;
3572 enum i40iw_status_code status
;
3575 memset(&attr
, 0, sizeof(attr
));
3576 ibqp
= i40iw_get_qp(cm_id
->device
, conn_param
->qpn
);
3580 iwqp
= to_iwqp(ibqp
);
3581 iwdev
= iwqp
->iwdev
;
3582 dev
= &iwdev
->sc_dev
;
3583 cm_node
= (struct i40iw_cm_node
*)cm_id
->provider_data
;
3585 if (((struct sockaddr_in
*)&cm_id
->local_addr
)->sin_family
== AF_INET
) {
3586 cm_node
->ipv4
= true;
3587 cm_node
->vlan_id
= i40iw_get_vlan_ipv4(cm_node
->loc_addr
);
3589 cm_node
->ipv4
= false;
3590 i40iw_netdev_vlan_ipv6(cm_node
->loc_addr
, &cm_node
->vlan_id
, NULL
);
3592 i40iw_debug(cm_node
->dev
,
3594 "Accept vlan_id=%d\n",
3596 if (cm_node
->state
== I40IW_CM_STATE_LISTENER_DESTROYED
) {
3597 if (cm_node
->loopbackpartner
)
3598 i40iw_rem_ref_cm_node(cm_node
->loopbackpartner
);
3599 i40iw_rem_ref_cm_node(cm_node
);
3603 passive_state
= atomic_add_return(1, &cm_node
->passive_state
);
3604 if (passive_state
== I40IW_SEND_RESET_EVENT
) {
3605 i40iw_rem_ref_cm_node(cm_node
);
3609 cm_node
->cm_core
->stats_accepts
++;
3610 iwqp
->cm_node
= (void *)cm_node
;
3611 cm_node
->iwqp
= iwqp
;
3613 buf_len
= conn_param
->private_data_len
+ I40IW_MAX_IETF_SIZE
+ MPA_ZERO_PAD_LEN
;
3615 status
= i40iw_allocate_dma_mem(dev
->hw
, &iwqp
->ietf_mem
, buf_len
, 1);
3619 cm_node
->pdata
.size
= conn_param
->private_data_len
;
3620 accept
.addr
= iwqp
->ietf_mem
.va
;
3621 accept
.size
= i40iw_cm_build_mpa_frame(cm_node
, &accept
, MPA_KEY_REPLY
);
3622 memcpy(accept
.addr
+ accept
.size
, conn_param
->private_data
,
3623 conn_param
->private_data_len
);
3625 /* setup our first outgoing iWarp send WQE (the IETF frame response) */
3626 if ((cm_node
->ipv4
&&
3627 !i40iw_ipv4_is_loopback(cm_node
->loc_addr
[0], cm_node
->rem_addr
[0])) ||
3629 !i40iw_ipv6_is_loopback(cm_node
->loc_addr
, cm_node
->rem_addr
))) {
3630 iwibdev
= iwdev
->iwibdev
;
3632 tagged_offset
= (uintptr_t)iwqp
->ietf_mem
.va
;
3633 ibmr
= i40iw_reg_phys_mr(&iwpd
->ibpd
,
3636 IB_ACCESS_LOCAL_WRITE
,
3639 i40iw_free_dma_mem(dev
->hw
, &iwqp
->ietf_mem
);
3643 ibmr
->pd
= &iwpd
->ibpd
;
3644 ibmr
->device
= iwpd
->ibpd
.device
;
3645 iwqp
->lsmm_mr
= ibmr
;
3647 iwqp
->sc_qp
.qp_uk
.sq_base
= kmap(iwqp
->page
);
3648 if (is_remote_ne020_or_chelsio(cm_node
))
3649 dev
->iw_priv_qp_ops
->qp_send_lsmm(
3652 (accept
.size
+ conn_param
->private_data_len
),
3655 dev
->iw_priv_qp_ops
->qp_send_lsmm(
3658 (accept
.size
+ conn_param
->private_data_len
+ MPA_ZERO_PAD_LEN
),
3663 iwqp
->sc_qp
.qp_uk
.sq_base
= kmap(iwqp
->page
);
3664 i40iw_loopback_nop(&iwqp
->sc_qp
);
3670 iwqp
->cm_id
= cm_id
;
3671 cm_node
->cm_id
= cm_id
;
3673 cm_id
->provider_data
= (void *)iwqp
;
3674 iwqp
->active_conn
= 0;
3676 cm_node
->lsmm_size
= accept
.size
+ conn_param
->private_data_len
;
3677 i40iw_cm_init_tsa_conn(iwqp
, cm_node
);
3678 cm_id
->add_ref(cm_id
);
3679 i40iw_add_ref(&iwqp
->ibqp
);
3681 i40iw_send_cm_event(cm_node
, cm_id
, IW_CM_EVENT_ESTABLISHED
, 0);
3683 attr
.qp_state
= IB_QPS_RTS
;
3684 cm_node
->qhash_set
= false;
3685 i40iw_modify_qp(&iwqp
->ibqp
, &attr
, IB_QP_STATE
, NULL
);
3686 if (cm_node
->loopbackpartner
) {
3687 cm_node
->loopbackpartner
->pdata
.size
= conn_param
->private_data_len
;
3689 /* copy entire MPA frame to our cm_node's frame */
3690 memcpy(cm_node
->loopbackpartner
->pdata_buf
,
3691 conn_param
->private_data
,
3692 conn_param
->private_data_len
);
3693 i40iw_create_event(cm_node
->loopbackpartner
, I40IW_CM_EVENT_CONNECTED
);
3696 cm_node
->accelerated
= 1;
3697 if (cm_node
->accept_pend
) {
3698 if (!cm_node
->listener
)
3699 i40iw_pr_err("cm_node->listener NULL for passive node\n");
3700 atomic_dec(&cm_node
->listener
->pend_accepts_cnt
);
3701 cm_node
->accept_pend
= 0;
3707 * i40iw_reject - registered call for connection to be rejected
3708 * @cm_id: cm information for passive connection
3709 * @pdata: private data to be sent
3710 * @pdata_len: private data length
3712 int i40iw_reject(struct iw_cm_id
*cm_id
, const void *pdata
, u8 pdata_len
)
3714 struct i40iw_device
*iwdev
;
3715 struct i40iw_cm_node
*cm_node
;
3716 struct i40iw_cm_node
*loopback
;
3718 cm_node
= (struct i40iw_cm_node
*)cm_id
->provider_data
;
3719 loopback
= cm_node
->loopbackpartner
;
3720 cm_node
->cm_id
= cm_id
;
3721 cm_node
->pdata
.size
= pdata_len
;
3723 iwdev
= to_iwdev(cm_id
->device
);
3726 cm_node
->cm_core
->stats_rejects
++;
3728 if (pdata_len
+ sizeof(struct ietf_mpa_v2
) > MAX_CM_BUFFER
)
3732 memcpy(&loopback
->pdata_buf
, pdata
, pdata_len
);
3733 loopback
->pdata
.size
= pdata_len
;
3736 return i40iw_cm_reject(cm_node
, pdata
, pdata_len
);
3740 * i40iw_connect - registered call for connection to be established
3741 * @cm_id: cm information for passive connection
3742 * @conn_param: Information about the connection
3744 int i40iw_connect(struct iw_cm_id
*cm_id
, struct iw_cm_conn_param
*conn_param
)
3747 struct i40iw_qp
*iwqp
;
3748 struct i40iw_device
*iwdev
;
3749 struct i40iw_cm_node
*cm_node
;
3750 struct i40iw_cm_info cm_info
;
3751 struct sockaddr_in
*laddr
;
3752 struct sockaddr_in
*raddr
;
3753 struct sockaddr_in6
*laddr6
;
3754 struct sockaddr_in6
*raddr6
;
3756 enum i40iw_status_code status
;
3758 ibqp
= i40iw_get_qp(cm_id
->device
, conn_param
->qpn
);
3761 iwqp
= to_iwqp(ibqp
);
3764 iwdev
= to_iwdev(iwqp
->ibqp
.device
);
3768 laddr
= (struct sockaddr_in
*)&cm_id
->m_local_addr
;
3769 raddr
= (struct sockaddr_in
*)&cm_id
->m_remote_addr
;
3770 laddr6
= (struct sockaddr_in6
*)&cm_id
->m_local_addr
;
3771 raddr6
= (struct sockaddr_in6
*)&cm_id
->m_remote_addr
;
3773 if (!(laddr
->sin_port
) || !(raddr
->sin_port
))
3776 iwqp
->active_conn
= 1;
3778 cm_id
->provider_data
= iwqp
;
3780 /* set up the connection params for the node */
3781 if (cm_id
->remote_addr
.ss_family
== AF_INET
) {
3782 cm_info
.ipv4
= true;
3783 memset(cm_info
.loc_addr
, 0, sizeof(cm_info
.loc_addr
));
3784 memset(cm_info
.rem_addr
, 0, sizeof(cm_info
.rem_addr
));
3785 cm_info
.loc_addr
[0] = ntohl(laddr
->sin_addr
.s_addr
);
3786 cm_info
.rem_addr
[0] = ntohl(raddr
->sin_addr
.s_addr
);
3787 cm_info
.loc_port
= ntohs(laddr
->sin_port
);
3788 cm_info
.rem_port
= ntohs(raddr
->sin_port
);
3789 cm_info
.vlan_id
= i40iw_get_vlan_ipv4(cm_info
.loc_addr
);
3791 cm_info
.ipv4
= false;
3792 i40iw_copy_ip_ntohl(cm_info
.loc_addr
,
3793 laddr6
->sin6_addr
.in6_u
.u6_addr32
);
3794 i40iw_copy_ip_ntohl(cm_info
.rem_addr
,
3795 raddr6
->sin6_addr
.in6_u
.u6_addr32
);
3796 cm_info
.loc_port
= ntohs(laddr6
->sin6_port
);
3797 cm_info
.rem_port
= ntohs(raddr6
->sin6_port
);
3798 i40iw_netdev_vlan_ipv6(cm_info
.loc_addr
, &cm_info
.vlan_id
, NULL
);
3800 cm_info
.cm_id
= cm_id
;
3801 if ((cm_info
.ipv4
&& (laddr
->sin_addr
.s_addr
!= raddr
->sin_addr
.s_addr
)) ||
3802 (!cm_info
.ipv4
&& memcmp(laddr6
->sin6_addr
.in6_u
.u6_addr32
,
3803 raddr6
->sin6_addr
.in6_u
.u6_addr32
,
3804 sizeof(laddr6
->sin6_addr
.in6_u
.u6_addr32
)))) {
3805 status
= i40iw_manage_qhash(iwdev
,
3807 I40IW_QHASH_TYPE_TCP_ESTABLISHED
,
3808 I40IW_QHASH_MANAGE_TYPE_ADD
,
3814 status
= i40iw_manage_apbvt(iwdev
, cm_info
.loc_port
, I40IW_MANAGE_APBVT_ADD
);
3816 i40iw_manage_qhash(iwdev
,
3818 I40IW_QHASH_TYPE_TCP_ESTABLISHED
,
3819 I40IW_QHASH_MANAGE_TYPE_DELETE
,
3826 cm_id
->add_ref(cm_id
);
3827 cm_node
= i40iw_create_cm_node(&iwdev
->cm_core
, iwdev
,
3828 conn_param
->private_data_len
,
3829 (void *)conn_param
->private_data
,
3832 i40iw_manage_qhash(iwdev
,
3834 I40IW_QHASH_TYPE_TCP_ESTABLISHED
,
3835 I40IW_QHASH_MANAGE_TYPE_DELETE
,
3839 if (apbvt_set
&& !i40iw_listen_port_in_use(&iwdev
->cm_core
,
3841 i40iw_manage_apbvt(iwdev
,
3843 I40IW_MANAGE_APBVT_DEL
);
3844 cm_id
->rem_ref(cm_id
);
3845 iwdev
->cm_core
.stats_connect_errs
++;
3849 i40iw_record_ird_ord(cm_node
, (u16
)conn_param
->ird
, (u16
)conn_param
->ord
);
3850 if (cm_node
->send_rdma0_op
== SEND_RDMA_READ_ZERO
&&
3852 cm_node
->ord_size
= 1;
3854 cm_node
->apbvt_set
= apbvt_set
;
3855 cm_node
->qhash_set
= true;
3856 iwqp
->cm_node
= cm_node
;
3857 cm_node
->iwqp
= iwqp
;
3858 iwqp
->cm_id
= cm_id
;
3859 i40iw_add_ref(&iwqp
->ibqp
);
3864 * i40iw_create_listen - registered call creating listener
3865 * @cm_id: cm information for passive connection
3866 * @backlog: to max accept pending count
3868 int i40iw_create_listen(struct iw_cm_id
*cm_id
, int backlog
)
3870 struct i40iw_device
*iwdev
;
3871 struct i40iw_cm_listener
*cm_listen_node
;
3872 struct i40iw_cm_info cm_info
;
3873 enum i40iw_status_code ret
;
3874 struct sockaddr_in
*laddr
;
3875 struct sockaddr_in6
*laddr6
;
3876 bool wildcard
= false;
3878 iwdev
= to_iwdev(cm_id
->device
);
3882 laddr
= (struct sockaddr_in
*)&cm_id
->m_local_addr
;
3883 laddr6
= (struct sockaddr_in6
*)&cm_id
->m_local_addr
;
3884 memset(&cm_info
, 0, sizeof(cm_info
));
3885 if (laddr
->sin_family
== AF_INET
) {
3886 cm_info
.ipv4
= true;
3887 cm_info
.loc_addr
[0] = ntohl(laddr
->sin_addr
.s_addr
);
3888 cm_info
.loc_port
= ntohs(laddr
->sin_port
);
3890 if (laddr
->sin_addr
.s_addr
!= INADDR_ANY
)
3891 cm_info
.vlan_id
= i40iw_get_vlan_ipv4(cm_info
.loc_addr
);
3896 cm_info
.ipv4
= false;
3897 i40iw_copy_ip_ntohl(cm_info
.loc_addr
,
3898 laddr6
->sin6_addr
.in6_u
.u6_addr32
);
3899 cm_info
.loc_port
= ntohs(laddr6
->sin6_port
);
3900 if (ipv6_addr_type(&laddr6
->sin6_addr
) != IPV6_ADDR_ANY
)
3901 i40iw_netdev_vlan_ipv6(cm_info
.loc_addr
,
3907 cm_info
.backlog
= backlog
;
3908 cm_info
.cm_id
= cm_id
;
3910 cm_listen_node
= i40iw_make_listen_node(&iwdev
->cm_core
, iwdev
, &cm_info
);
3911 if (!cm_listen_node
) {
3912 i40iw_pr_err("cm_listen_node == NULL\n");
3916 cm_id
->provider_data
= cm_listen_node
;
3918 if (!cm_listen_node
->reused_node
) {
3921 ret
= i40iw_add_mqh_4(iwdev
,
3925 ret
= i40iw_add_mqh_6(iwdev
,
3931 ret
= i40iw_manage_apbvt(iwdev
,
3933 I40IW_MANAGE_APBVT_ADD
);
3938 ret
= i40iw_manage_qhash(iwdev
,
3940 I40IW_QHASH_TYPE_TCP_SYN
,
3941 I40IW_QHASH_MANAGE_TYPE_ADD
,
3946 cm_listen_node
->qhash_set
= true;
3947 ret
= i40iw_manage_apbvt(iwdev
,
3949 I40IW_MANAGE_APBVT_ADD
);
3954 cm_id
->add_ref(cm_id
);
3955 cm_listen_node
->cm_core
->stats_listen_created
++;
3958 i40iw_cm_del_listen(&iwdev
->cm_core
, (void *)cm_listen_node
, false);
3963 * i40iw_destroy_listen - registered call to destroy listener
3964 * @cm_id: cm information for passive connection
3966 int i40iw_destroy_listen(struct iw_cm_id
*cm_id
)
3968 struct i40iw_device
*iwdev
;
3970 iwdev
= to_iwdev(cm_id
->device
);
3971 if (cm_id
->provider_data
)
3972 i40iw_cm_del_listen(&iwdev
->cm_core
, cm_id
->provider_data
, true);
3974 i40iw_pr_err("cm_id->provider_data was NULL\n");
3976 cm_id
->rem_ref(cm_id
);
3982 * i40iw_cm_event_connected - handle connected active node
3983 * @event: the info for cm_node of connection
3985 static void i40iw_cm_event_connected(struct i40iw_cm_event
*event
)
3987 struct i40iw_qp
*iwqp
;
3988 struct i40iw_device
*iwdev
;
3989 struct i40iw_cm_node
*cm_node
;
3990 struct i40iw_sc_dev
*dev
;
3991 struct ib_qp_attr attr
;
3992 struct iw_cm_id
*cm_id
;
3996 cm_node
= event
->cm_node
;
3997 cm_id
= cm_node
->cm_id
;
3998 iwqp
= (struct i40iw_qp
*)cm_id
->provider_data
;
3999 iwdev
= to_iwdev(iwqp
->ibqp
.device
);
4000 dev
= &iwdev
->sc_dev
;
4002 if (iwqp
->destroyed
) {
4003 status
= -ETIMEDOUT
;
4006 i40iw_cm_init_tsa_conn(iwqp
, cm_node
);
4007 read0
= (cm_node
->send_rdma0_op
== SEND_RDMA_READ_ZERO
);
4009 iwqp
->sc_qp
.qp_uk
.sq_base
= kmap(iwqp
->page
);
4010 dev
->iw_priv_qp_ops
->qp_send_rtt(&iwqp
->sc_qp
, read0
);
4013 status
= i40iw_send_cm_event(cm_node
, cm_id
, IW_CM_EVENT_CONNECT_REPLY
, 0);
4015 i40iw_pr_err("send cm event\n");
4017 memset(&attr
, 0, sizeof(attr
));
4018 attr
.qp_state
= IB_QPS_RTS
;
4019 cm_node
->qhash_set
= false;
4020 i40iw_modify_qp(&iwqp
->ibqp
, &attr
, IB_QP_STATE
, NULL
);
4022 cm_node
->accelerated
= 1;
4023 if (cm_node
->accept_pend
) {
4024 if (!cm_node
->listener
)
4025 i40iw_pr_err("listener is null for passive node\n");
4026 atomic_dec(&cm_node
->listener
->pend_accepts_cnt
);
4027 cm_node
->accept_pend
= 0;
4033 cm_id
->provider_data
= NULL
;
4034 i40iw_send_cm_event(event
->cm_node
,
4036 IW_CM_EVENT_CONNECT_REPLY
,
4038 cm_id
->rem_ref(cm_id
);
4039 i40iw_rem_ref_cm_node(event
->cm_node
);
4043 * i40iw_cm_event_reset - handle reset
4044 * @event: the info for cm_node of connection
4046 static void i40iw_cm_event_reset(struct i40iw_cm_event
*event
)
4048 struct i40iw_cm_node
*cm_node
= event
->cm_node
;
4049 struct iw_cm_id
*cm_id
= cm_node
->cm_id
;
4050 struct i40iw_qp
*iwqp
;
4055 iwqp
= cm_id
->provider_data
;
4059 i40iw_debug(cm_node
->dev
,
4061 "reset event %p - cm_id = %p\n",
4062 event
->cm_node
, cm_id
);
4065 i40iw_send_cm_event(cm_node
, cm_node
->cm_id
, IW_CM_EVENT_DISCONNECT
, -ECONNRESET
);
4066 i40iw_send_cm_event(cm_node
, cm_node
->cm_id
, IW_CM_EVENT_CLOSE
, 0);
4070 * i40iw_cm_event_handler - worker thread callback to send event to cm upper layer
4071 * @work: pointer of cm event info.
4073 static void i40iw_cm_event_handler(struct work_struct
*work
)
4075 struct i40iw_cm_event
*event
= container_of(work
,
4076 struct i40iw_cm_event
,
4078 struct i40iw_cm_node
*cm_node
;
4080 if (!event
|| !event
->cm_node
|| !event
->cm_node
->cm_core
)
4083 cm_node
= event
->cm_node
;
4085 switch (event
->type
) {
4086 case I40IW_CM_EVENT_MPA_REQ
:
4087 i40iw_send_cm_event(cm_node
,
4089 IW_CM_EVENT_CONNECT_REQUEST
,
4092 case I40IW_CM_EVENT_RESET
:
4093 i40iw_cm_event_reset(event
);
4095 case I40IW_CM_EVENT_CONNECTED
:
4096 if (!event
->cm_node
->cm_id
||
4097 (event
->cm_node
->state
!= I40IW_CM_STATE_OFFLOADED
))
4099 i40iw_cm_event_connected(event
);
4101 case I40IW_CM_EVENT_MPA_REJECT
:
4102 if (!event
->cm_node
->cm_id
||
4103 (cm_node
->state
== I40IW_CM_STATE_OFFLOADED
))
4105 i40iw_send_cm_event(cm_node
,
4107 IW_CM_EVENT_CONNECT_REPLY
,
4110 case I40IW_CM_EVENT_ABORTED
:
4111 if (!event
->cm_node
->cm_id
||
4112 (event
->cm_node
->state
== I40IW_CM_STATE_OFFLOADED
))
4114 i40iw_event_connect_error(event
);
4117 i40iw_pr_err("event type = %d\n", event
->type
);
4121 event
->cm_info
.cm_id
->rem_ref(event
->cm_info
.cm_id
);
4122 i40iw_rem_ref_cm_node(event
->cm_node
);
4127 * i40iw_cm_post_event - queue event request for worker thread
4128 * @event: cm node's info for up event call
4130 static void i40iw_cm_post_event(struct i40iw_cm_event
*event
)
4132 atomic_inc(&event
->cm_node
->ref_count
);
4133 event
->cm_info
.cm_id
->add_ref(event
->cm_info
.cm_id
);
4134 INIT_WORK(&event
->event_work
, i40iw_cm_event_handler
);
4136 queue_work(event
->cm_node
->cm_core
->event_wq
, &event
->event_work
);