2 * Copyright (c) 2009-2014 Chelsio, Inc. All rights reserved.
4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU
6 * General Public License (GPL) Version 2, available from the file
7 * COPYING in the main directory of this source tree, or the
8 * OpenIB.org BSD license below:
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
18 * - Redistributions in binary form must reproduce the above
19 * copyright notice, this list of conditions and the following
20 * disclaimer in the documentation and/or other materials
21 * provided with the distribution.
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
32 #include <linux/module.h>
33 #include <linux/list.h>
34 #include <linux/workqueue.h>
35 #include <linux/skbuff.h>
36 #include <linux/timer.h>
37 #include <linux/notifier.h>
38 #include <linux/inetdevice.h>
40 #include <linux/tcp.h>
41 #include <linux/if_vlan.h>
43 #include <net/neighbour.h>
44 #include <net/netevent.h>
45 #include <net/route.h>
47 #include <net/ip6_route.h>
48 #include <net/addrconf.h>
50 #include <rdma/ib_addr.h>
52 #include <libcxgb_cm.h>
56 static char *states
[] = {
73 module_param(nocong
, int, 0644);
74 MODULE_PARM_DESC(nocong
, "Turn of congestion control (default=0)");
76 static int enable_ecn
;
77 module_param(enable_ecn
, int, 0644);
78 MODULE_PARM_DESC(enable_ecn
, "Enable ECN (default=0/disabled)");
80 static int dack_mode
= 1;
81 module_param(dack_mode
, int, 0644);
82 MODULE_PARM_DESC(dack_mode
, "Delayed ack mode (default=1)");
84 uint c4iw_max_read_depth
= 32;
85 module_param(c4iw_max_read_depth
, int, 0644);
86 MODULE_PARM_DESC(c4iw_max_read_depth
,
87 "Per-connection max ORD/IRD (default=32)");
89 static int enable_tcp_timestamps
;
90 module_param(enable_tcp_timestamps
, int, 0644);
91 MODULE_PARM_DESC(enable_tcp_timestamps
, "Enable tcp timestamps (default=0)");
93 static int enable_tcp_sack
;
94 module_param(enable_tcp_sack
, int, 0644);
95 MODULE_PARM_DESC(enable_tcp_sack
, "Enable tcp SACK (default=0)");
97 static int enable_tcp_window_scaling
= 1;
98 module_param(enable_tcp_window_scaling
, int, 0644);
99 MODULE_PARM_DESC(enable_tcp_window_scaling
,
100 "Enable tcp window scaling (default=1)");
102 static int peer2peer
= 1;
103 module_param(peer2peer
, int, 0644);
104 MODULE_PARM_DESC(peer2peer
, "Support peer2peer ULPs (default=1)");
106 static int p2p_type
= FW_RI_INIT_P2PTYPE_READ_REQ
;
107 module_param(p2p_type
, int, 0644);
108 MODULE_PARM_DESC(p2p_type
, "RDMAP opcode to use for the RTR message: "
109 "1=RDMA_READ 0=RDMA_WRITE (default 1)");
111 static int ep_timeout_secs
= 60;
112 module_param(ep_timeout_secs
, int, 0644);
113 MODULE_PARM_DESC(ep_timeout_secs
, "CM Endpoint operation timeout "
114 "in seconds (default=60)");
116 static int mpa_rev
= 2;
117 module_param(mpa_rev
, int, 0644);
118 MODULE_PARM_DESC(mpa_rev
, "MPA Revision, 0 supports amso1100, "
119 "1 is RFC5044 spec compliant, 2 is IETF MPA Peer Connect Draft"
120 " compliant (default=2)");
122 static int markers_enabled
;
123 module_param(markers_enabled
, int, 0644);
124 MODULE_PARM_DESC(markers_enabled
, "Enable MPA MARKERS (default(0)=disabled)");
126 static int crc_enabled
= 1;
127 module_param(crc_enabled
, int, 0644);
128 MODULE_PARM_DESC(crc_enabled
, "Enable MPA CRC (default(1)=enabled)");
130 static int rcv_win
= 256 * 1024;
131 module_param(rcv_win
, int, 0644);
132 MODULE_PARM_DESC(rcv_win
, "TCP receive window in bytes (default=256KB)");
134 static int snd_win
= 128 * 1024;
135 module_param(snd_win
, int, 0644);
136 MODULE_PARM_DESC(snd_win
, "TCP send window in bytes (default=128KB)");
138 static struct workqueue_struct
*workq
;
140 static struct sk_buff_head rxq
;
142 static struct sk_buff
*get_skb(struct sk_buff
*skb
, int len
, gfp_t gfp
);
143 static void ep_timeout(struct timer_list
*t
);
144 static void connect_reply_upcall(struct c4iw_ep
*ep
, int status
);
145 static int sched(struct c4iw_dev
*dev
, struct sk_buff
*skb
);
147 static LIST_HEAD(timeout_list
);
148 static spinlock_t timeout_lock
;
150 static void deref_cm_id(struct c4iw_ep_common
*epc
)
152 epc
->cm_id
->rem_ref(epc
->cm_id
);
154 set_bit(CM_ID_DEREFED
, &epc
->history
);
157 static void ref_cm_id(struct c4iw_ep_common
*epc
)
159 set_bit(CM_ID_REFED
, &epc
->history
);
160 epc
->cm_id
->add_ref(epc
->cm_id
);
163 static void deref_qp(struct c4iw_ep
*ep
)
165 c4iw_qp_rem_ref(&ep
->com
.qp
->ibqp
);
166 clear_bit(QP_REFERENCED
, &ep
->com
.flags
);
167 set_bit(QP_DEREFED
, &ep
->com
.history
);
170 static void ref_qp(struct c4iw_ep
*ep
)
172 set_bit(QP_REFERENCED
, &ep
->com
.flags
);
173 set_bit(QP_REFED
, &ep
->com
.history
);
174 c4iw_qp_add_ref(&ep
->com
.qp
->ibqp
);
177 static void start_ep_timer(struct c4iw_ep
*ep
)
179 pr_debug("ep %p\n", ep
);
180 if (timer_pending(&ep
->timer
)) {
181 pr_err("%s timer already started! ep %p\n",
185 clear_bit(TIMEOUT
, &ep
->com
.flags
);
186 c4iw_get_ep(&ep
->com
);
187 ep
->timer
.expires
= jiffies
+ ep_timeout_secs
* HZ
;
188 add_timer(&ep
->timer
);
191 static int stop_ep_timer(struct c4iw_ep
*ep
)
193 pr_debug("ep %p stopping\n", ep
);
194 del_timer_sync(&ep
->timer
);
195 if (!test_and_set_bit(TIMEOUT
, &ep
->com
.flags
)) {
196 c4iw_put_ep(&ep
->com
);
202 static int c4iw_l2t_send(struct c4iw_rdev
*rdev
, struct sk_buff
*skb
,
203 struct l2t_entry
*l2e
)
207 if (c4iw_fatal_error(rdev
)) {
209 pr_err("%s - device in error state - dropping\n", __func__
);
212 error
= cxgb4_l2t_send(rdev
->lldi
.ports
[0], skb
, l2e
);
215 else if (error
== NET_XMIT_DROP
)
217 return error
< 0 ? error
: 0;
220 int c4iw_ofld_send(struct c4iw_rdev
*rdev
, struct sk_buff
*skb
)
224 if (c4iw_fatal_error(rdev
)) {
226 pr_err("%s - device in error state - dropping\n", __func__
);
229 error
= cxgb4_ofld_send(rdev
->lldi
.ports
[0], skb
);
232 return error
< 0 ? error
: 0;
235 static void release_tid(struct c4iw_rdev
*rdev
, u32 hwtid
, struct sk_buff
*skb
)
237 u32 len
= roundup(sizeof(struct cpl_tid_release
), 16);
239 skb
= get_skb(skb
, len
, GFP_KERNEL
);
243 cxgb_mk_tid_release(skb
, len
, hwtid
, 0);
244 c4iw_ofld_send(rdev
, skb
);
248 static void set_emss(struct c4iw_ep
*ep
, u16 opt
)
250 ep
->emss
= ep
->com
.dev
->rdev
.lldi
.mtus
[TCPOPT_MSS_G(opt
)] -
251 ((AF_INET
== ep
->com
.remote_addr
.ss_family
) ?
252 sizeof(struct iphdr
) : sizeof(struct ipv6hdr
)) -
253 sizeof(struct tcphdr
);
255 if (TCPOPT_TSTAMP_G(opt
))
256 ep
->emss
-= round_up(TCPOLEN_TIMESTAMP
, 4);
260 pr_debug("Warning: misaligned mtu idx %u mss %u emss=%u\n",
261 TCPOPT_MSS_G(opt
), ep
->mss
, ep
->emss
);
262 pr_debug("mss_idx %u mss %u emss=%u\n", TCPOPT_MSS_G(opt
), ep
->mss
,
266 static enum c4iw_ep_state
state_read(struct c4iw_ep_common
*epc
)
268 enum c4iw_ep_state state
;
270 mutex_lock(&epc
->mutex
);
272 mutex_unlock(&epc
->mutex
);
276 static void __state_set(struct c4iw_ep_common
*epc
, enum c4iw_ep_state
new)
281 static void state_set(struct c4iw_ep_common
*epc
, enum c4iw_ep_state
new)
283 mutex_lock(&epc
->mutex
);
284 pr_debug("%s -> %s\n", states
[epc
->state
], states
[new]);
285 __state_set(epc
, new);
286 mutex_unlock(&epc
->mutex
);
290 static int alloc_ep_skb_list(struct sk_buff_head
*ep_skb_list
, int size
)
296 len
= roundup(sizeof(union cpl_wr_size
), 16);
297 for (i
= 0; i
< size
; i
++) {
298 skb
= alloc_skb(len
, GFP_KERNEL
);
301 skb_queue_tail(ep_skb_list
, skb
);
305 skb_queue_purge(ep_skb_list
);
309 static void *alloc_ep(int size
, gfp_t gfp
)
311 struct c4iw_ep_common
*epc
;
313 epc
= kzalloc(size
, gfp
);
315 epc
->wr_waitp
= c4iw_alloc_wr_wait(gfp
);
316 if (!epc
->wr_waitp
) {
321 kref_init(&epc
->kref
);
322 mutex_init(&epc
->mutex
);
323 c4iw_init_wr_wait(epc
->wr_waitp
);
325 pr_debug("alloc ep %p\n", epc
);
330 static void remove_ep_tid(struct c4iw_ep
*ep
)
334 spin_lock_irqsave(&ep
->com
.dev
->lock
, flags
);
335 _remove_handle(ep
->com
.dev
, &ep
->com
.dev
->hwtid_idr
, ep
->hwtid
, 0);
336 if (idr_is_empty(&ep
->com
.dev
->hwtid_idr
))
337 wake_up(&ep
->com
.dev
->wait
);
338 spin_unlock_irqrestore(&ep
->com
.dev
->lock
, flags
);
341 static void insert_ep_tid(struct c4iw_ep
*ep
)
345 spin_lock_irqsave(&ep
->com
.dev
->lock
, flags
);
346 _insert_handle(ep
->com
.dev
, &ep
->com
.dev
->hwtid_idr
, ep
, ep
->hwtid
, 0);
347 spin_unlock_irqrestore(&ep
->com
.dev
->lock
, flags
);
351 * Atomically lookup the ep ptr given the tid and grab a reference on the ep.
353 static struct c4iw_ep
*get_ep_from_tid(struct c4iw_dev
*dev
, unsigned int tid
)
358 spin_lock_irqsave(&dev
->lock
, flags
);
359 ep
= idr_find(&dev
->hwtid_idr
, tid
);
361 c4iw_get_ep(&ep
->com
);
362 spin_unlock_irqrestore(&dev
->lock
, flags
);
367 * Atomically lookup the ep ptr given the stid and grab a reference on the ep.
369 static struct c4iw_listen_ep
*get_ep_from_stid(struct c4iw_dev
*dev
,
372 struct c4iw_listen_ep
*ep
;
375 spin_lock_irqsave(&dev
->lock
, flags
);
376 ep
= idr_find(&dev
->stid_idr
, stid
);
378 c4iw_get_ep(&ep
->com
);
379 spin_unlock_irqrestore(&dev
->lock
, flags
);
383 void _c4iw_free_ep(struct kref
*kref
)
387 ep
= container_of(kref
, struct c4iw_ep
, com
.kref
);
388 pr_debug("ep %p state %s\n", ep
, states
[ep
->com
.state
]);
389 if (test_bit(QP_REFERENCED
, &ep
->com
.flags
))
391 if (test_bit(RELEASE_RESOURCES
, &ep
->com
.flags
)) {
392 if (ep
->com
.remote_addr
.ss_family
== AF_INET6
) {
393 struct sockaddr_in6
*sin6
=
394 (struct sockaddr_in6
*)
398 ep
->com
.dev
->rdev
.lldi
.ports
[0],
399 (const u32
*)&sin6
->sin6_addr
.s6_addr
,
402 cxgb4_remove_tid(ep
->com
.dev
->rdev
.lldi
.tids
, 0, ep
->hwtid
,
403 ep
->com
.local_addr
.ss_family
);
404 dst_release(ep
->dst
);
405 cxgb4_l2t_release(ep
->l2t
);
407 kfree_skb(ep
->mpa_skb
);
409 if (!skb_queue_empty(&ep
->com
.ep_skb_list
))
410 skb_queue_purge(&ep
->com
.ep_skb_list
);
411 c4iw_put_wr_wait(ep
->com
.wr_waitp
);
415 static void release_ep_resources(struct c4iw_ep
*ep
)
417 set_bit(RELEASE_RESOURCES
, &ep
->com
.flags
);
420 * If we have a hwtid, then remove it from the idr table
421 * so lookups will no longer find this endpoint. Otherwise
422 * we have a race where one thread finds the ep ptr just
423 * before the other thread is freeing the ep memory.
427 c4iw_put_ep(&ep
->com
);
430 static int status2errno(int status
)
435 case CPL_ERR_CONN_RESET
:
437 case CPL_ERR_ARP_MISS
:
438 return -EHOSTUNREACH
;
439 case CPL_ERR_CONN_TIMEDOUT
:
441 case CPL_ERR_TCAM_FULL
:
443 case CPL_ERR_CONN_EXIST
:
451 * Try and reuse skbs already allocated...
453 static struct sk_buff
*get_skb(struct sk_buff
*skb
, int len
, gfp_t gfp
)
455 if (skb
&& !skb_is_nonlinear(skb
) && !skb_cloned(skb
)) {
458 skb_reset_transport_header(skb
);
460 skb
= alloc_skb(len
, gfp
);
462 t4_set_arp_err_handler(skb
, NULL
, NULL
);
466 static struct net_device
*get_real_dev(struct net_device
*egress_dev
)
468 return rdma_vlan_dev_real_dev(egress_dev
) ? : egress_dev
;
471 static void arp_failure_discard(void *handle
, struct sk_buff
*skb
)
473 pr_err("ARP failure\n");
477 static void mpa_start_arp_failure(void *handle
, struct sk_buff
*skb
)
479 pr_err("ARP failure during MPA Negotiation - Closing Connection\n");
484 FAKE_CPL_PUT_EP_SAFE
= NUM_CPL_CMDS
+ 0,
485 FAKE_CPL_PASS_PUT_EP_SAFE
= NUM_CPL_CMDS
+ 1,
488 static int _put_ep_safe(struct c4iw_dev
*dev
, struct sk_buff
*skb
)
492 ep
= *((struct c4iw_ep
**)(skb
->cb
+ 2 * sizeof(void *)));
493 release_ep_resources(ep
);
498 static int _put_pass_ep_safe(struct c4iw_dev
*dev
, struct sk_buff
*skb
)
502 ep
= *((struct c4iw_ep
**)(skb
->cb
+ 2 * sizeof(void *)));
503 c4iw_put_ep(&ep
->parent_ep
->com
);
504 release_ep_resources(ep
);
510 * Fake up a special CPL opcode and call sched() so process_work() will call
511 * _put_ep_safe() in a safe context to free the ep resources. This is needed
512 * because ARP error handlers are called in an ATOMIC context, and
513 * _c4iw_free_ep() needs to block.
515 static void queue_arp_failure_cpl(struct c4iw_ep
*ep
, struct sk_buff
*skb
,
518 struct cpl_act_establish
*rpl
= cplhdr(skb
);
520 /* Set our special ARP_FAILURE opcode */
521 rpl
->ot
.opcode
= cpl
;
524 * Save ep in the skb->cb area, after where sched() will save the dev
527 *((struct c4iw_ep
**)(skb
->cb
+ 2 * sizeof(void *))) = ep
;
528 sched(ep
->com
.dev
, skb
);
531 /* Handle an ARP failure for an accept */
532 static void pass_accept_rpl_arp_failure(void *handle
, struct sk_buff
*skb
)
534 struct c4iw_ep
*ep
= handle
;
536 pr_err("ARP failure during accept - tid %u - dropping connection\n",
539 __state_set(&ep
->com
, DEAD
);
540 queue_arp_failure_cpl(ep
, skb
, FAKE_CPL_PASS_PUT_EP_SAFE
);
544 * Handle an ARP failure for an active open.
546 static void act_open_req_arp_failure(void *handle
, struct sk_buff
*skb
)
548 struct c4iw_ep
*ep
= handle
;
550 pr_err("ARP failure during connect\n");
551 connect_reply_upcall(ep
, -EHOSTUNREACH
);
552 __state_set(&ep
->com
, DEAD
);
553 if (ep
->com
.remote_addr
.ss_family
== AF_INET6
) {
554 struct sockaddr_in6
*sin6
=
555 (struct sockaddr_in6
*)&ep
->com
.local_addr
;
556 cxgb4_clip_release(ep
->com
.dev
->rdev
.lldi
.ports
[0],
557 (const u32
*)&sin6
->sin6_addr
.s6_addr
, 1);
559 remove_handle(ep
->com
.dev
, &ep
->com
.dev
->atid_idr
, ep
->atid
);
560 cxgb4_free_atid(ep
->com
.dev
->rdev
.lldi
.tids
, ep
->atid
);
561 queue_arp_failure_cpl(ep
, skb
, FAKE_CPL_PUT_EP_SAFE
);
565 * Handle an ARP failure for a CPL_ABORT_REQ. Change it into a no RST variant
568 static void abort_arp_failure(void *handle
, struct sk_buff
*skb
)
571 struct c4iw_ep
*ep
= handle
;
572 struct c4iw_rdev
*rdev
= &ep
->com
.dev
->rdev
;
573 struct cpl_abort_req
*req
= cplhdr(skb
);
575 pr_debug("rdev %p\n", rdev
);
576 req
->cmd
= CPL_ABORT_NO_RST
;
578 ret
= c4iw_ofld_send(rdev
, skb
);
580 __state_set(&ep
->com
, DEAD
);
581 queue_arp_failure_cpl(ep
, skb
, FAKE_CPL_PUT_EP_SAFE
);
586 static int send_flowc(struct c4iw_ep
*ep
)
588 struct fw_flowc_wr
*flowc
;
589 struct sk_buff
*skb
= skb_dequeue(&ep
->com
.ep_skb_list
);
591 u16 vlan
= ep
->l2t
->vlan
;
597 if (vlan
== CPL_L2T_VLAN_NONE
)
602 flowc
= __skb_put(skb
, FLOWC_LEN
);
604 flowc
->op_to_nparams
= cpu_to_be32(FW_WR_OP_V(FW_FLOWC_WR
) |
605 FW_FLOWC_WR_NPARAMS_V(nparams
));
606 flowc
->flowid_len16
= cpu_to_be32(FW_WR_LEN16_V(DIV_ROUND_UP(FLOWC_LEN
,
607 16)) | FW_WR_FLOWID_V(ep
->hwtid
));
609 flowc
->mnemval
[0].mnemonic
= FW_FLOWC_MNEM_PFNVFN
;
610 flowc
->mnemval
[0].val
= cpu_to_be32(FW_PFVF_CMD_PFN_V
611 (ep
->com
.dev
->rdev
.lldi
.pf
));
612 flowc
->mnemval
[1].mnemonic
= FW_FLOWC_MNEM_CH
;
613 flowc
->mnemval
[1].val
= cpu_to_be32(ep
->tx_chan
);
614 flowc
->mnemval
[2].mnemonic
= FW_FLOWC_MNEM_PORT
;
615 flowc
->mnemval
[2].val
= cpu_to_be32(ep
->tx_chan
);
616 flowc
->mnemval
[3].mnemonic
= FW_FLOWC_MNEM_IQID
;
617 flowc
->mnemval
[3].val
= cpu_to_be32(ep
->rss_qid
);
618 flowc
->mnemval
[4].mnemonic
= FW_FLOWC_MNEM_SNDNXT
;
619 flowc
->mnemval
[4].val
= cpu_to_be32(ep
->snd_seq
);
620 flowc
->mnemval
[5].mnemonic
= FW_FLOWC_MNEM_RCVNXT
;
621 flowc
->mnemval
[5].val
= cpu_to_be32(ep
->rcv_seq
);
622 flowc
->mnemval
[6].mnemonic
= FW_FLOWC_MNEM_SNDBUF
;
623 flowc
->mnemval
[6].val
= cpu_to_be32(ep
->snd_win
);
624 flowc
->mnemval
[7].mnemonic
= FW_FLOWC_MNEM_MSS
;
625 flowc
->mnemval
[7].val
= cpu_to_be32(ep
->emss
);
629 pri
= (vlan
& VLAN_PRIO_MASK
) >> VLAN_PRIO_SHIFT
;
630 flowc
->mnemval
[8].mnemonic
= FW_FLOWC_MNEM_SCHEDCLASS
;
631 flowc
->mnemval
[8].val
= cpu_to_be32(pri
);
633 /* Pad WR to 16 byte boundary */
634 flowc
->mnemval
[8].mnemonic
= 0;
635 flowc
->mnemval
[8].val
= 0;
637 for (i
= 0; i
< 9; i
++) {
638 flowc
->mnemval
[i
].r4
[0] = 0;
639 flowc
->mnemval
[i
].r4
[1] = 0;
640 flowc
->mnemval
[i
].r4
[2] = 0;
643 set_wr_txq(skb
, CPL_PRIORITY_DATA
, ep
->txq_idx
);
644 return c4iw_ofld_send(&ep
->com
.dev
->rdev
, skb
);
647 static int send_halfclose(struct c4iw_ep
*ep
)
649 struct sk_buff
*skb
= skb_dequeue(&ep
->com
.ep_skb_list
);
650 u32 wrlen
= roundup(sizeof(struct cpl_close_con_req
), 16);
652 pr_debug("ep %p tid %u\n", ep
, ep
->hwtid
);
656 cxgb_mk_close_con_req(skb
, wrlen
, ep
->hwtid
, ep
->txq_idx
,
657 NULL
, arp_failure_discard
);
659 return c4iw_l2t_send(&ep
->com
.dev
->rdev
, skb
, ep
->l2t
);
662 static int send_abort(struct c4iw_ep
*ep
)
664 u32 wrlen
= roundup(sizeof(struct cpl_abort_req
), 16);
665 struct sk_buff
*req_skb
= skb_dequeue(&ep
->com
.ep_skb_list
);
667 pr_debug("ep %p tid %u\n", ep
, ep
->hwtid
);
668 if (WARN_ON(!req_skb
))
671 cxgb_mk_abort_req(req_skb
, wrlen
, ep
->hwtid
, ep
->txq_idx
,
672 ep
, abort_arp_failure
);
674 return c4iw_l2t_send(&ep
->com
.dev
->rdev
, req_skb
, ep
->l2t
);
677 static int send_connect(struct c4iw_ep
*ep
)
679 struct cpl_act_open_req
*req
= NULL
;
680 struct cpl_t5_act_open_req
*t5req
= NULL
;
681 struct cpl_t6_act_open_req
*t6req
= NULL
;
682 struct cpl_act_open_req6
*req6
= NULL
;
683 struct cpl_t5_act_open_req6
*t5req6
= NULL
;
684 struct cpl_t6_act_open_req6
*t6req6
= NULL
;
688 unsigned int mtu_idx
;
690 int win
, sizev4
, sizev6
, wrlen
;
691 struct sockaddr_in
*la
= (struct sockaddr_in
*)
693 struct sockaddr_in
*ra
= (struct sockaddr_in
*)
694 &ep
->com
.remote_addr
;
695 struct sockaddr_in6
*la6
= (struct sockaddr_in6
*)
697 struct sockaddr_in6
*ra6
= (struct sockaddr_in6
*)
698 &ep
->com
.remote_addr
;
700 enum chip_type adapter_type
= ep
->com
.dev
->rdev
.lldi
.adapter_type
;
701 u32 isn
= (prandom_u32() & ~7UL) - 1;
702 struct net_device
*netdev
;
705 netdev
= ep
->com
.dev
->rdev
.lldi
.ports
[0];
707 switch (CHELSIO_CHIP_VERSION(adapter_type
)) {
709 sizev4
= sizeof(struct cpl_act_open_req
);
710 sizev6
= sizeof(struct cpl_act_open_req6
);
713 sizev4
= sizeof(struct cpl_t5_act_open_req
);
714 sizev6
= sizeof(struct cpl_t5_act_open_req6
);
717 sizev4
= sizeof(struct cpl_t6_act_open_req
);
718 sizev6
= sizeof(struct cpl_t6_act_open_req6
);
721 pr_err("T%d Chip is not supported\n",
722 CHELSIO_CHIP_VERSION(adapter_type
));
726 wrlen
= (ep
->com
.remote_addr
.ss_family
== AF_INET
) ?
727 roundup(sizev4
, 16) :
730 pr_debug("ep %p atid %u\n", ep
, ep
->atid
);
732 skb
= get_skb(NULL
, wrlen
, GFP_KERNEL
);
734 pr_err("%s - failed to alloc skb\n", __func__
);
737 set_wr_txq(skb
, CPL_PRIORITY_SETUP
, ep
->ctrlq_idx
);
739 cxgb_best_mtu(ep
->com
.dev
->rdev
.lldi
.mtus
, ep
->mtu
, &mtu_idx
,
740 enable_tcp_timestamps
,
741 (ep
->com
.remote_addr
.ss_family
== AF_INET
) ? 0 : 1);
742 wscale
= cxgb_compute_wscale(rcv_win
);
745 * Specify the largest window that will fit in opt0. The
746 * remainder will be specified in the rx_data_ack.
748 win
= ep
->rcv_win
>> 10;
749 if (win
> RCV_BUFSIZ_M
)
752 opt0
= (nocong
? NO_CONG_F
: 0) |
755 WND_SCALE_V(wscale
) |
757 L2T_IDX_V(ep
->l2t
->idx
) |
758 TX_CHAN_V(ep
->tx_chan
) |
759 SMAC_SEL_V(ep
->smac_idx
) |
760 DSCP_V(ep
->tos
>> 2) |
761 ULP_MODE_V(ULP_MODE_TCPDDP
) |
763 opt2
= RX_CHANNEL_V(0) |
764 CCTRL_ECN_V(enable_ecn
) |
765 RSS_QUEUE_VALID_F
| RSS_QUEUE_V(ep
->rss_qid
);
766 if (enable_tcp_timestamps
)
767 opt2
|= TSTAMPS_EN_F
;
770 if (wscale
&& enable_tcp_window_scaling
)
771 opt2
|= WND_SCALE_EN_F
;
772 if (CHELSIO_CHIP_VERSION(adapter_type
) > CHELSIO_T4
) {
776 opt2
|= T5_OPT_2_VALID_F
;
777 opt2
|= CONG_CNTRL_V(CONG_ALG_TAHOE
);
781 params
= cxgb4_select_ntuple(netdev
, ep
->l2t
);
783 if (ep
->com
.remote_addr
.ss_family
== AF_INET6
)
784 cxgb4_clip_get(ep
->com
.dev
->rdev
.lldi
.ports
[0],
785 (const u32
*)&la6
->sin6_addr
.s6_addr
, 1);
787 t4_set_arp_err_handler(skb
, ep
, act_open_req_arp_failure
);
789 if (ep
->com
.remote_addr
.ss_family
== AF_INET
) {
790 switch (CHELSIO_CHIP_VERSION(adapter_type
)) {
792 req
= skb_put(skb
, wrlen
);
796 t5req
= skb_put(skb
, wrlen
);
797 INIT_TP_WR(t5req
, 0);
798 req
= (struct cpl_act_open_req
*)t5req
;
801 t6req
= skb_put(skb
, wrlen
);
802 INIT_TP_WR(t6req
, 0);
803 req
= (struct cpl_act_open_req
*)t6req
;
804 t5req
= (struct cpl_t5_act_open_req
*)t6req
;
807 pr_err("T%d Chip is not supported\n",
808 CHELSIO_CHIP_VERSION(adapter_type
));
813 OPCODE_TID(req
) = cpu_to_be32(MK_OPCODE_TID(CPL_ACT_OPEN_REQ
,
814 ((ep
->rss_qid
<<14) | ep
->atid
)));
815 req
->local_port
= la
->sin_port
;
816 req
->peer_port
= ra
->sin_port
;
817 req
->local_ip
= la
->sin_addr
.s_addr
;
818 req
->peer_ip
= ra
->sin_addr
.s_addr
;
819 req
->opt0
= cpu_to_be64(opt0
);
821 if (is_t4(ep
->com
.dev
->rdev
.lldi
.adapter_type
)) {
822 req
->params
= cpu_to_be32(params
);
823 req
->opt2
= cpu_to_be32(opt2
);
825 if (is_t5(ep
->com
.dev
->rdev
.lldi
.adapter_type
)) {
827 cpu_to_be64(FILTER_TUPLE_V(params
));
828 t5req
->rsvd
= cpu_to_be32(isn
);
829 pr_debug("snd_isn %u\n", t5req
->rsvd
);
830 t5req
->opt2
= cpu_to_be32(opt2
);
833 cpu_to_be64(FILTER_TUPLE_V(params
));
834 t6req
->rsvd
= cpu_to_be32(isn
);
835 pr_debug("snd_isn %u\n", t6req
->rsvd
);
836 t6req
->opt2
= cpu_to_be32(opt2
);
840 switch (CHELSIO_CHIP_VERSION(adapter_type
)) {
842 req6
= skb_put(skb
, wrlen
);
846 t5req6
= skb_put(skb
, wrlen
);
847 INIT_TP_WR(t5req6
, 0);
848 req6
= (struct cpl_act_open_req6
*)t5req6
;
851 t6req6
= skb_put(skb
, wrlen
);
852 INIT_TP_WR(t6req6
, 0);
853 req6
= (struct cpl_act_open_req6
*)t6req6
;
854 t5req6
= (struct cpl_t5_act_open_req6
*)t6req6
;
857 pr_err("T%d Chip is not supported\n",
858 CHELSIO_CHIP_VERSION(adapter_type
));
863 OPCODE_TID(req6
) = cpu_to_be32(MK_OPCODE_TID(CPL_ACT_OPEN_REQ6
,
864 ((ep
->rss_qid
<<14)|ep
->atid
)));
865 req6
->local_port
= la6
->sin6_port
;
866 req6
->peer_port
= ra6
->sin6_port
;
867 req6
->local_ip_hi
= *((__be64
*)(la6
->sin6_addr
.s6_addr
));
868 req6
->local_ip_lo
= *((__be64
*)(la6
->sin6_addr
.s6_addr
+ 8));
869 req6
->peer_ip_hi
= *((__be64
*)(ra6
->sin6_addr
.s6_addr
));
870 req6
->peer_ip_lo
= *((__be64
*)(ra6
->sin6_addr
.s6_addr
+ 8));
871 req6
->opt0
= cpu_to_be64(opt0
);
873 if (is_t4(ep
->com
.dev
->rdev
.lldi
.adapter_type
)) {
874 req6
->params
= cpu_to_be32(cxgb4_select_ntuple(netdev
,
876 req6
->opt2
= cpu_to_be32(opt2
);
878 if (is_t5(ep
->com
.dev
->rdev
.lldi
.adapter_type
)) {
880 cpu_to_be64(FILTER_TUPLE_V(params
));
881 t5req6
->rsvd
= cpu_to_be32(isn
);
882 pr_debug("snd_isn %u\n", t5req6
->rsvd
);
883 t5req6
->opt2
= cpu_to_be32(opt2
);
886 cpu_to_be64(FILTER_TUPLE_V(params
));
887 t6req6
->rsvd
= cpu_to_be32(isn
);
888 pr_debug("snd_isn %u\n", t6req6
->rsvd
);
889 t6req6
->opt2
= cpu_to_be32(opt2
);
895 set_bit(ACT_OPEN_REQ
, &ep
->com
.history
);
896 ret
= c4iw_l2t_send(&ep
->com
.dev
->rdev
, skb
, ep
->l2t
);
898 if (ret
&& ep
->com
.remote_addr
.ss_family
== AF_INET6
)
899 cxgb4_clip_release(ep
->com
.dev
->rdev
.lldi
.ports
[0],
900 (const u32
*)&la6
->sin6_addr
.s6_addr
, 1);
904 static int send_mpa_req(struct c4iw_ep
*ep
, struct sk_buff
*skb
,
907 int mpalen
, wrlen
, ret
;
908 struct fw_ofld_tx_data_wr
*req
;
909 struct mpa_message
*mpa
;
910 struct mpa_v2_conn_params mpa_v2_params
;
912 pr_debug("ep %p tid %u pd_len %d\n",
913 ep
, ep
->hwtid
, ep
->plen
);
915 mpalen
= sizeof(*mpa
) + ep
->plen
;
916 if (mpa_rev_to_use
== 2)
917 mpalen
+= sizeof(struct mpa_v2_conn_params
);
918 wrlen
= roundup(mpalen
+ sizeof *req
, 16);
919 skb
= get_skb(skb
, wrlen
, GFP_KERNEL
);
921 connect_reply_upcall(ep
, -ENOMEM
);
924 set_wr_txq(skb
, CPL_PRIORITY_DATA
, ep
->txq_idx
);
926 req
= skb_put_zero(skb
, wrlen
);
927 req
->op_to_immdlen
= cpu_to_be32(
928 FW_WR_OP_V(FW_OFLD_TX_DATA_WR
) |
930 FW_WR_IMMDLEN_V(mpalen
));
931 req
->flowid_len16
= cpu_to_be32(
932 FW_WR_FLOWID_V(ep
->hwtid
) |
933 FW_WR_LEN16_V(wrlen
>> 4));
934 req
->plen
= cpu_to_be32(mpalen
);
935 req
->tunnel_to_proxy
= cpu_to_be32(
936 FW_OFLD_TX_DATA_WR_FLUSH_F
|
937 FW_OFLD_TX_DATA_WR_SHOVE_F
);
939 mpa
= (struct mpa_message
*)(req
+ 1);
940 memcpy(mpa
->key
, MPA_KEY_REQ
, sizeof(mpa
->key
));
944 mpa
->flags
|= MPA_CRC
;
945 if (markers_enabled
) {
946 mpa
->flags
|= MPA_MARKERS
;
947 ep
->mpa_attr
.recv_marker_enabled
= 1;
949 ep
->mpa_attr
.recv_marker_enabled
= 0;
951 if (mpa_rev_to_use
== 2)
952 mpa
->flags
|= MPA_ENHANCED_RDMA_CONN
;
954 mpa
->private_data_size
= htons(ep
->plen
);
955 mpa
->revision
= mpa_rev_to_use
;
956 if (mpa_rev_to_use
== 1) {
957 ep
->tried_with_mpa_v1
= 1;
958 ep
->retry_with_mpa_v1
= 0;
961 if (mpa_rev_to_use
== 2) {
962 mpa
->private_data_size
= htons(ntohs(mpa
->private_data_size
) +
963 sizeof (struct mpa_v2_conn_params
));
964 pr_debug("initiator ird %u ord %u\n", ep
->ird
,
966 mpa_v2_params
.ird
= htons((u16
)ep
->ird
);
967 mpa_v2_params
.ord
= htons((u16
)ep
->ord
);
970 mpa_v2_params
.ird
|= htons(MPA_V2_PEER2PEER_MODEL
);
971 if (p2p_type
== FW_RI_INIT_P2PTYPE_RDMA_WRITE
)
973 htons(MPA_V2_RDMA_WRITE_RTR
);
974 else if (p2p_type
== FW_RI_INIT_P2PTYPE_READ_REQ
)
976 htons(MPA_V2_RDMA_READ_RTR
);
978 memcpy(mpa
->private_data
, &mpa_v2_params
,
979 sizeof(struct mpa_v2_conn_params
));
982 memcpy(mpa
->private_data
+
983 sizeof(struct mpa_v2_conn_params
),
984 ep
->mpa_pkt
+ sizeof(*mpa
), ep
->plen
);
987 memcpy(mpa
->private_data
,
988 ep
->mpa_pkt
+ sizeof(*mpa
), ep
->plen
);
991 * Reference the mpa skb. This ensures the data area
992 * will remain in memory until the hw acks the tx.
993 * Function fw4_ack() will deref it.
996 t4_set_arp_err_handler(skb
, NULL
, arp_failure_discard
);
998 ret
= c4iw_l2t_send(&ep
->com
.dev
->rdev
, skb
, ep
->l2t
);
1002 __state_set(&ep
->com
, MPA_REQ_SENT
);
1003 ep
->mpa_attr
.initiator
= 1;
1004 ep
->snd_seq
+= mpalen
;
1008 static int send_mpa_reject(struct c4iw_ep
*ep
, const void *pdata
, u8 plen
)
1011 struct fw_ofld_tx_data_wr
*req
;
1012 struct mpa_message
*mpa
;
1013 struct sk_buff
*skb
;
1014 struct mpa_v2_conn_params mpa_v2_params
;
1016 pr_debug("ep %p tid %u pd_len %d\n",
1017 ep
, ep
->hwtid
, ep
->plen
);
1019 mpalen
= sizeof(*mpa
) + plen
;
1020 if (ep
->mpa_attr
.version
== 2 && ep
->mpa_attr
.enhanced_rdma_conn
)
1021 mpalen
+= sizeof(struct mpa_v2_conn_params
);
1022 wrlen
= roundup(mpalen
+ sizeof *req
, 16);
1024 skb
= get_skb(NULL
, wrlen
, GFP_KERNEL
);
1026 pr_err("%s - cannot alloc skb!\n", __func__
);
1029 set_wr_txq(skb
, CPL_PRIORITY_DATA
, ep
->txq_idx
);
1031 req
= skb_put_zero(skb
, wrlen
);
1032 req
->op_to_immdlen
= cpu_to_be32(
1033 FW_WR_OP_V(FW_OFLD_TX_DATA_WR
) |
1035 FW_WR_IMMDLEN_V(mpalen
));
1036 req
->flowid_len16
= cpu_to_be32(
1037 FW_WR_FLOWID_V(ep
->hwtid
) |
1038 FW_WR_LEN16_V(wrlen
>> 4));
1039 req
->plen
= cpu_to_be32(mpalen
);
1040 req
->tunnel_to_proxy
= cpu_to_be32(
1041 FW_OFLD_TX_DATA_WR_FLUSH_F
|
1042 FW_OFLD_TX_DATA_WR_SHOVE_F
);
1044 mpa
= (struct mpa_message
*)(req
+ 1);
1045 memset(mpa
, 0, sizeof(*mpa
));
1046 memcpy(mpa
->key
, MPA_KEY_REP
, sizeof(mpa
->key
));
1047 mpa
->flags
= MPA_REJECT
;
1048 mpa
->revision
= ep
->mpa_attr
.version
;
1049 mpa
->private_data_size
= htons(plen
);
1051 if (ep
->mpa_attr
.version
== 2 && ep
->mpa_attr
.enhanced_rdma_conn
) {
1052 mpa
->flags
|= MPA_ENHANCED_RDMA_CONN
;
1053 mpa
->private_data_size
= htons(ntohs(mpa
->private_data_size
) +
1054 sizeof (struct mpa_v2_conn_params
));
1055 mpa_v2_params
.ird
= htons(((u16
)ep
->ird
) |
1056 (peer2peer
? MPA_V2_PEER2PEER_MODEL
:
1058 mpa_v2_params
.ord
= htons(((u16
)ep
->ord
) | (peer2peer
?
1060 FW_RI_INIT_P2PTYPE_RDMA_WRITE
?
1061 MPA_V2_RDMA_WRITE_RTR
: p2p_type
==
1062 FW_RI_INIT_P2PTYPE_READ_REQ
?
1063 MPA_V2_RDMA_READ_RTR
: 0) : 0));
1064 memcpy(mpa
->private_data
, &mpa_v2_params
,
1065 sizeof(struct mpa_v2_conn_params
));
1068 memcpy(mpa
->private_data
+
1069 sizeof(struct mpa_v2_conn_params
), pdata
, plen
);
1072 memcpy(mpa
->private_data
, pdata
, plen
);
1075 * Reference the mpa skb again. This ensures the data area
1076 * will remain in memory until the hw acks the tx.
1077 * Function fw4_ack() will deref it.
1080 set_wr_txq(skb
, CPL_PRIORITY_DATA
, ep
->txq_idx
);
1081 t4_set_arp_err_handler(skb
, NULL
, mpa_start_arp_failure
);
1083 ep
->snd_seq
+= mpalen
;
1084 return c4iw_l2t_send(&ep
->com
.dev
->rdev
, skb
, ep
->l2t
);
1087 static int send_mpa_reply(struct c4iw_ep
*ep
, const void *pdata
, u8 plen
)
1090 struct fw_ofld_tx_data_wr
*req
;
1091 struct mpa_message
*mpa
;
1092 struct sk_buff
*skb
;
1093 struct mpa_v2_conn_params mpa_v2_params
;
1095 pr_debug("ep %p tid %u pd_len %d\n",
1096 ep
, ep
->hwtid
, ep
->plen
);
1098 mpalen
= sizeof(*mpa
) + plen
;
1099 if (ep
->mpa_attr
.version
== 2 && ep
->mpa_attr
.enhanced_rdma_conn
)
1100 mpalen
+= sizeof(struct mpa_v2_conn_params
);
1101 wrlen
= roundup(mpalen
+ sizeof *req
, 16);
1103 skb
= get_skb(NULL
, wrlen
, GFP_KERNEL
);
1105 pr_err("%s - cannot alloc skb!\n", __func__
);
1108 set_wr_txq(skb
, CPL_PRIORITY_DATA
, ep
->txq_idx
);
1110 req
= skb_put_zero(skb
, wrlen
);
1111 req
->op_to_immdlen
= cpu_to_be32(
1112 FW_WR_OP_V(FW_OFLD_TX_DATA_WR
) |
1114 FW_WR_IMMDLEN_V(mpalen
));
1115 req
->flowid_len16
= cpu_to_be32(
1116 FW_WR_FLOWID_V(ep
->hwtid
) |
1117 FW_WR_LEN16_V(wrlen
>> 4));
1118 req
->plen
= cpu_to_be32(mpalen
);
1119 req
->tunnel_to_proxy
= cpu_to_be32(
1120 FW_OFLD_TX_DATA_WR_FLUSH_F
|
1121 FW_OFLD_TX_DATA_WR_SHOVE_F
);
1123 mpa
= (struct mpa_message
*)(req
+ 1);
1124 memset(mpa
, 0, sizeof(*mpa
));
1125 memcpy(mpa
->key
, MPA_KEY_REP
, sizeof(mpa
->key
));
1127 if (ep
->mpa_attr
.crc_enabled
)
1128 mpa
->flags
|= MPA_CRC
;
1129 if (ep
->mpa_attr
.recv_marker_enabled
)
1130 mpa
->flags
|= MPA_MARKERS
;
1131 mpa
->revision
= ep
->mpa_attr
.version
;
1132 mpa
->private_data_size
= htons(plen
);
1134 if (ep
->mpa_attr
.version
== 2 && ep
->mpa_attr
.enhanced_rdma_conn
) {
1135 mpa
->flags
|= MPA_ENHANCED_RDMA_CONN
;
1136 mpa
->private_data_size
= htons(ntohs(mpa
->private_data_size
) +
1137 sizeof (struct mpa_v2_conn_params
));
1138 mpa_v2_params
.ird
= htons((u16
)ep
->ird
);
1139 mpa_v2_params
.ord
= htons((u16
)ep
->ord
);
1140 if (peer2peer
&& (ep
->mpa_attr
.p2p_type
!=
1141 FW_RI_INIT_P2PTYPE_DISABLED
)) {
1142 mpa_v2_params
.ird
|= htons(MPA_V2_PEER2PEER_MODEL
);
1144 if (p2p_type
== FW_RI_INIT_P2PTYPE_RDMA_WRITE
)
1145 mpa_v2_params
.ord
|=
1146 htons(MPA_V2_RDMA_WRITE_RTR
);
1147 else if (p2p_type
== FW_RI_INIT_P2PTYPE_READ_REQ
)
1148 mpa_v2_params
.ord
|=
1149 htons(MPA_V2_RDMA_READ_RTR
);
1152 memcpy(mpa
->private_data
, &mpa_v2_params
,
1153 sizeof(struct mpa_v2_conn_params
));
1156 memcpy(mpa
->private_data
+
1157 sizeof(struct mpa_v2_conn_params
), pdata
, plen
);
1160 memcpy(mpa
->private_data
, pdata
, plen
);
1163 * Reference the mpa skb. This ensures the data area
1164 * will remain in memory until the hw acks the tx.
1165 * Function fw4_ack() will deref it.
1168 t4_set_arp_err_handler(skb
, NULL
, mpa_start_arp_failure
);
1170 __state_set(&ep
->com
, MPA_REP_SENT
);
1171 ep
->snd_seq
+= mpalen
;
1172 return c4iw_l2t_send(&ep
->com
.dev
->rdev
, skb
, ep
->l2t
);
1175 static int act_establish(struct c4iw_dev
*dev
, struct sk_buff
*skb
)
1178 struct cpl_act_establish
*req
= cplhdr(skb
);
1179 unsigned int tid
= GET_TID(req
);
1180 unsigned int atid
= TID_TID_G(ntohl(req
->tos_atid
));
1181 struct tid_info
*t
= dev
->rdev
.lldi
.tids
;
1184 ep
= lookup_atid(t
, atid
);
1186 pr_debug("ep %p tid %u snd_isn %u rcv_isn %u\n", ep
, tid
,
1187 be32_to_cpu(req
->snd_isn
), be32_to_cpu(req
->rcv_isn
));
1189 mutex_lock(&ep
->com
.mutex
);
1190 dst_confirm(ep
->dst
);
1192 /* setup the hwtid for this connection */
1194 cxgb4_insert_tid(t
, ep
, tid
, ep
->com
.local_addr
.ss_family
);
1197 ep
->snd_seq
= be32_to_cpu(req
->snd_isn
);
1198 ep
->rcv_seq
= be32_to_cpu(req
->rcv_isn
);
1200 set_emss(ep
, ntohs(req
->tcp_opt
));
1202 /* dealloc the atid */
1203 remove_handle(ep
->com
.dev
, &ep
->com
.dev
->atid_idr
, atid
);
1204 cxgb4_free_atid(t
, atid
);
1205 set_bit(ACT_ESTAB
, &ep
->com
.history
);
1207 /* start MPA negotiation */
1208 ret
= send_flowc(ep
);
1211 if (ep
->retry_with_mpa_v1
)
1212 ret
= send_mpa_req(ep
, skb
, 1);
1214 ret
= send_mpa_req(ep
, skb
, mpa_rev
);
1217 mutex_unlock(&ep
->com
.mutex
);
1220 mutex_unlock(&ep
->com
.mutex
);
1221 connect_reply_upcall(ep
, -ENOMEM
);
1222 c4iw_ep_disconnect(ep
, 0, GFP_KERNEL
);
1226 static void close_complete_upcall(struct c4iw_ep
*ep
, int status
)
1228 struct iw_cm_event event
;
1230 pr_debug("ep %p tid %u\n", ep
, ep
->hwtid
);
1231 memset(&event
, 0, sizeof(event
));
1232 event
.event
= IW_CM_EVENT_CLOSE
;
1233 event
.status
= status
;
1234 if (ep
->com
.cm_id
) {
1235 pr_debug("close complete delivered ep %p cm_id %p tid %u\n",
1236 ep
, ep
->com
.cm_id
, ep
->hwtid
);
1237 ep
->com
.cm_id
->event_handler(ep
->com
.cm_id
, &event
);
1238 deref_cm_id(&ep
->com
);
1239 set_bit(CLOSE_UPCALL
, &ep
->com
.history
);
1243 static void peer_close_upcall(struct c4iw_ep
*ep
)
1245 struct iw_cm_event event
;
1247 pr_debug("ep %p tid %u\n", ep
, ep
->hwtid
);
1248 memset(&event
, 0, sizeof(event
));
1249 event
.event
= IW_CM_EVENT_DISCONNECT
;
1250 if (ep
->com
.cm_id
) {
1251 pr_debug("peer close delivered ep %p cm_id %p tid %u\n",
1252 ep
, ep
->com
.cm_id
, ep
->hwtid
);
1253 ep
->com
.cm_id
->event_handler(ep
->com
.cm_id
, &event
);
1254 set_bit(DISCONN_UPCALL
, &ep
->com
.history
);
1258 static void peer_abort_upcall(struct c4iw_ep
*ep
)
1260 struct iw_cm_event event
;
1262 pr_debug("ep %p tid %u\n", ep
, ep
->hwtid
);
1263 memset(&event
, 0, sizeof(event
));
1264 event
.event
= IW_CM_EVENT_CLOSE
;
1265 event
.status
= -ECONNRESET
;
1266 if (ep
->com
.cm_id
) {
1267 pr_debug("abort delivered ep %p cm_id %p tid %u\n", ep
,
1268 ep
->com
.cm_id
, ep
->hwtid
);
1269 ep
->com
.cm_id
->event_handler(ep
->com
.cm_id
, &event
);
1270 deref_cm_id(&ep
->com
);
1271 set_bit(ABORT_UPCALL
, &ep
->com
.history
);
1275 static void connect_reply_upcall(struct c4iw_ep
*ep
, int status
)
1277 struct iw_cm_event event
;
1279 pr_debug("ep %p tid %u status %d\n",
1280 ep
, ep
->hwtid
, status
);
1281 memset(&event
, 0, sizeof(event
));
1282 event
.event
= IW_CM_EVENT_CONNECT_REPLY
;
1283 event
.status
= status
;
1284 memcpy(&event
.local_addr
, &ep
->com
.local_addr
,
1285 sizeof(ep
->com
.local_addr
));
1286 memcpy(&event
.remote_addr
, &ep
->com
.remote_addr
,
1287 sizeof(ep
->com
.remote_addr
));
1289 if ((status
== 0) || (status
== -ECONNREFUSED
)) {
1290 if (!ep
->tried_with_mpa_v1
) {
1291 /* this means MPA_v2 is used */
1292 event
.ord
= ep
->ird
;
1293 event
.ird
= ep
->ord
;
1294 event
.private_data_len
= ep
->plen
-
1295 sizeof(struct mpa_v2_conn_params
);
1296 event
.private_data
= ep
->mpa_pkt
+
1297 sizeof(struct mpa_message
) +
1298 sizeof(struct mpa_v2_conn_params
);
1300 /* this means MPA_v1 is used */
1301 event
.ord
= cur_max_read_depth(ep
->com
.dev
);
1302 event
.ird
= cur_max_read_depth(ep
->com
.dev
);
1303 event
.private_data_len
= ep
->plen
;
1304 event
.private_data
= ep
->mpa_pkt
+
1305 sizeof(struct mpa_message
);
1309 pr_debug("ep %p tid %u status %d\n", ep
,
1311 set_bit(CONN_RPL_UPCALL
, &ep
->com
.history
);
1312 ep
->com
.cm_id
->event_handler(ep
->com
.cm_id
, &event
);
1315 deref_cm_id(&ep
->com
);
1318 static int connect_request_upcall(struct c4iw_ep
*ep
)
1320 struct iw_cm_event event
;
1323 pr_debug("ep %p tid %u\n", ep
, ep
->hwtid
);
1324 memset(&event
, 0, sizeof(event
));
1325 event
.event
= IW_CM_EVENT_CONNECT_REQUEST
;
1326 memcpy(&event
.local_addr
, &ep
->com
.local_addr
,
1327 sizeof(ep
->com
.local_addr
));
1328 memcpy(&event
.remote_addr
, &ep
->com
.remote_addr
,
1329 sizeof(ep
->com
.remote_addr
));
1330 event
.provider_data
= ep
;
1331 if (!ep
->tried_with_mpa_v1
) {
1332 /* this means MPA_v2 is used */
1333 event
.ord
= ep
->ord
;
1334 event
.ird
= ep
->ird
;
1335 event
.private_data_len
= ep
->plen
-
1336 sizeof(struct mpa_v2_conn_params
);
1337 event
.private_data
= ep
->mpa_pkt
+ sizeof(struct mpa_message
) +
1338 sizeof(struct mpa_v2_conn_params
);
1340 /* this means MPA_v1 is used. Send max supported */
1341 event
.ord
= cur_max_read_depth(ep
->com
.dev
);
1342 event
.ird
= cur_max_read_depth(ep
->com
.dev
);
1343 event
.private_data_len
= ep
->plen
;
1344 event
.private_data
= ep
->mpa_pkt
+ sizeof(struct mpa_message
);
1346 c4iw_get_ep(&ep
->com
);
1347 ret
= ep
->parent_ep
->com
.cm_id
->event_handler(ep
->parent_ep
->com
.cm_id
,
1350 c4iw_put_ep(&ep
->com
);
1351 set_bit(CONNREQ_UPCALL
, &ep
->com
.history
);
1352 c4iw_put_ep(&ep
->parent_ep
->com
);
1356 static void established_upcall(struct c4iw_ep
*ep
)
1358 struct iw_cm_event event
;
1360 pr_debug("ep %p tid %u\n", ep
, ep
->hwtid
);
1361 memset(&event
, 0, sizeof(event
));
1362 event
.event
= IW_CM_EVENT_ESTABLISHED
;
1363 event
.ird
= ep
->ord
;
1364 event
.ord
= ep
->ird
;
1365 if (ep
->com
.cm_id
) {
1366 pr_debug("ep %p tid %u\n", ep
, ep
->hwtid
);
1367 ep
->com
.cm_id
->event_handler(ep
->com
.cm_id
, &event
);
1368 set_bit(ESTAB_UPCALL
, &ep
->com
.history
);
1372 static int update_rx_credits(struct c4iw_ep
*ep
, u32 credits
)
1374 struct sk_buff
*skb
;
1375 u32 wrlen
= roundup(sizeof(struct cpl_rx_data_ack
), 16);
1378 pr_debug("ep %p tid %u credits %u\n",
1379 ep
, ep
->hwtid
, credits
);
1380 skb
= get_skb(NULL
, wrlen
, GFP_KERNEL
);
1382 pr_err("update_rx_credits - cannot alloc skb!\n");
1387 * If we couldn't specify the entire rcv window at connection setup
1388 * due to the limit in the number of bits in the RCV_BUFSIZ field,
1389 * then add the overage in to the credits returned.
1391 if (ep
->rcv_win
> RCV_BUFSIZ_M
* 1024)
1392 credits
+= ep
->rcv_win
- RCV_BUFSIZ_M
* 1024;
1394 credit_dack
= credits
| RX_FORCE_ACK_F
| RX_DACK_CHANGE_F
|
1395 RX_DACK_MODE_V(dack_mode
);
1397 cxgb_mk_rx_data_ack(skb
, wrlen
, ep
->hwtid
, ep
->ctrlq_idx
,
1400 c4iw_ofld_send(&ep
->com
.dev
->rdev
, skb
);
1404 #define RELAXED_IRD_NEGOTIATION 1
1407 * process_mpa_reply - process streaming mode MPA reply
1411 * 0 upon success indicating a connect request was delivered to the ULP
1412 * or the mpa request is incomplete but valid so far.
1414 * 1 if a failure requires the caller to close the connection.
1416 * 2 if a failure requires the caller to abort the connection.
1418 static int process_mpa_reply(struct c4iw_ep
*ep
, struct sk_buff
*skb
)
1420 struct mpa_message
*mpa
;
1421 struct mpa_v2_conn_params
*mpa_v2_params
;
1423 u16 resp_ird
, resp_ord
;
1424 u8 rtr_mismatch
= 0, insuff_ird
= 0;
1425 struct c4iw_qp_attributes attrs
;
1426 enum c4iw_qp_attr_mask mask
;
1430 pr_debug("ep %p tid %u\n", ep
, ep
->hwtid
);
1433 * If we get more than the supported amount of private data
1434 * then we must fail this connection.
1436 if (ep
->mpa_pkt_len
+ skb
->len
> sizeof(ep
->mpa_pkt
)) {
1438 goto err_stop_timer
;
1442 * copy the new data into our accumulation buffer.
1444 skb_copy_from_linear_data(skb
, &(ep
->mpa_pkt
[ep
->mpa_pkt_len
]),
1446 ep
->mpa_pkt_len
+= skb
->len
;
1449 * if we don't even have the mpa message, then bail.
1451 if (ep
->mpa_pkt_len
< sizeof(*mpa
))
1453 mpa
= (struct mpa_message
*) ep
->mpa_pkt
;
1455 /* Validate MPA header. */
1456 if (mpa
->revision
> mpa_rev
) {
1457 pr_err("%s MPA version mismatch. Local = %d, Received = %d\n",
1458 __func__
, mpa_rev
, mpa
->revision
);
1460 goto err_stop_timer
;
1462 if (memcmp(mpa
->key
, MPA_KEY_REP
, sizeof(mpa
->key
))) {
1464 goto err_stop_timer
;
1467 plen
= ntohs(mpa
->private_data_size
);
1470 * Fail if there's too much private data.
1472 if (plen
> MPA_MAX_PRIVATE_DATA
) {
1474 goto err_stop_timer
;
1478 * If plen does not account for pkt size
1480 if (ep
->mpa_pkt_len
> (sizeof(*mpa
) + plen
)) {
1482 goto err_stop_timer
;
1485 ep
->plen
= (u8
) plen
;
1488 * If we don't have all the pdata yet, then bail.
1489 * We'll continue process when more data arrives.
1491 if (ep
->mpa_pkt_len
< (sizeof(*mpa
) + plen
))
1494 if (mpa
->flags
& MPA_REJECT
) {
1495 err
= -ECONNREFUSED
;
1496 goto err_stop_timer
;
1500 * Stop mpa timer. If it expired, then
1501 * we ignore the MPA reply. process_timeout()
1502 * will abort the connection.
1504 if (stop_ep_timer(ep
))
1508 * If we get here we have accumulated the entire mpa
1509 * start reply message including private data. And
1510 * the MPA header is valid.
1512 __state_set(&ep
->com
, FPDU_MODE
);
1513 ep
->mpa_attr
.crc_enabled
= (mpa
->flags
& MPA_CRC
) | crc_enabled
? 1 : 0;
1514 ep
->mpa_attr
.xmit_marker_enabled
= mpa
->flags
& MPA_MARKERS
? 1 : 0;
1515 ep
->mpa_attr
.version
= mpa
->revision
;
1516 ep
->mpa_attr
.p2p_type
= FW_RI_INIT_P2PTYPE_DISABLED
;
1518 if (mpa
->revision
== 2) {
1519 ep
->mpa_attr
.enhanced_rdma_conn
=
1520 mpa
->flags
& MPA_ENHANCED_RDMA_CONN
? 1 : 0;
1521 if (ep
->mpa_attr
.enhanced_rdma_conn
) {
1522 mpa_v2_params
= (struct mpa_v2_conn_params
*)
1523 (ep
->mpa_pkt
+ sizeof(*mpa
));
1524 resp_ird
= ntohs(mpa_v2_params
->ird
) &
1525 MPA_V2_IRD_ORD_MASK
;
1526 resp_ord
= ntohs(mpa_v2_params
->ord
) &
1527 MPA_V2_IRD_ORD_MASK
;
1528 pr_debug("responder ird %u ord %u ep ird %u ord %u\n",
1529 resp_ird
, resp_ord
, ep
->ird
, ep
->ord
);
1532 * This is a double-check. Ideally, below checks are
1533 * not required since ird/ord stuff has been taken
1534 * care of in c4iw_accept_cr
1536 if (ep
->ird
< resp_ord
) {
1537 if (RELAXED_IRD_NEGOTIATION
&& resp_ord
<=
1538 ep
->com
.dev
->rdev
.lldi
.max_ordird_qp
)
1542 } else if (ep
->ird
> resp_ord
) {
1545 if (ep
->ord
> resp_ird
) {
1546 if (RELAXED_IRD_NEGOTIATION
)
1557 if (ntohs(mpa_v2_params
->ird
) &
1558 MPA_V2_PEER2PEER_MODEL
) {
1559 if (ntohs(mpa_v2_params
->ord
) &
1560 MPA_V2_RDMA_WRITE_RTR
)
1561 ep
->mpa_attr
.p2p_type
=
1562 FW_RI_INIT_P2PTYPE_RDMA_WRITE
;
1563 else if (ntohs(mpa_v2_params
->ord
) &
1564 MPA_V2_RDMA_READ_RTR
)
1565 ep
->mpa_attr
.p2p_type
=
1566 FW_RI_INIT_P2PTYPE_READ_REQ
;
1569 } else if (mpa
->revision
== 1)
1571 ep
->mpa_attr
.p2p_type
= p2p_type
;
1573 pr_debug("crc_enabled=%d, recv_marker_enabled=%d, xmit_marker_enabled=%d, version=%d p2p_type=%d local-p2p_type = %d\n",
1574 ep
->mpa_attr
.crc_enabled
,
1575 ep
->mpa_attr
.recv_marker_enabled
,
1576 ep
->mpa_attr
.xmit_marker_enabled
, ep
->mpa_attr
.version
,
1577 ep
->mpa_attr
.p2p_type
, p2p_type
);
1580 * If responder's RTR does not match with that of initiator, assign
1581 * FW_RI_INIT_P2PTYPE_DISABLED in mpa attributes so that RTR is not
1582 * generated when moving QP to RTS state.
1583 * A TERM message will be sent after QP has moved to RTS state
1585 if ((ep
->mpa_attr
.version
== 2) && peer2peer
&&
1586 (ep
->mpa_attr
.p2p_type
!= p2p_type
)) {
1587 ep
->mpa_attr
.p2p_type
= FW_RI_INIT_P2PTYPE_DISABLED
;
1591 attrs
.mpa_attr
= ep
->mpa_attr
;
1592 attrs
.max_ird
= ep
->ird
;
1593 attrs
.max_ord
= ep
->ord
;
1594 attrs
.llp_stream_handle
= ep
;
1595 attrs
.next_state
= C4IW_QP_STATE_RTS
;
1597 mask
= C4IW_QP_ATTR_NEXT_STATE
|
1598 C4IW_QP_ATTR_LLP_STREAM_HANDLE
| C4IW_QP_ATTR_MPA_ATTR
|
1599 C4IW_QP_ATTR_MAX_IRD
| C4IW_QP_ATTR_MAX_ORD
;
1601 /* bind QP and TID with INIT_WR */
1602 err
= c4iw_modify_qp(ep
->com
.qp
->rhp
,
1603 ep
->com
.qp
, mask
, &attrs
, 1);
1608 * If responder's RTR requirement did not match with what initiator
1609 * supports, generate TERM message
1612 pr_err("%s: RTR mismatch, sending TERM\n", __func__
);
1613 attrs
.layer_etype
= LAYER_MPA
| DDP_LLP
;
1614 attrs
.ecode
= MPA_NOMATCH_RTR
;
1615 attrs
.next_state
= C4IW_QP_STATE_TERMINATE
;
1616 attrs
.send_term
= 1;
1617 err
= c4iw_modify_qp(ep
->com
.qp
->rhp
, ep
->com
.qp
,
1618 C4IW_QP_ATTR_NEXT_STATE
, &attrs
, 1);
1625 * Generate TERM if initiator IRD is not sufficient for responder
1626 * provided ORD. Currently, we do the same behaviour even when
1627 * responder provided IRD is also not sufficient as regards to
1631 pr_err("%s: Insufficient IRD, sending TERM\n", __func__
);
1632 attrs
.layer_etype
= LAYER_MPA
| DDP_LLP
;
1633 attrs
.ecode
= MPA_INSUFF_IRD
;
1634 attrs
.next_state
= C4IW_QP_STATE_TERMINATE
;
1635 attrs
.send_term
= 1;
1636 err
= c4iw_modify_qp(ep
->com
.qp
->rhp
, ep
->com
.qp
,
1637 C4IW_QP_ATTR_NEXT_STATE
, &attrs
, 1);
1648 connect_reply_upcall(ep
, err
);
1653 * process_mpa_request - process streaming mode MPA request
1657 * 0 upon success indicating a connect request was delivered to the ULP
1658 * or the mpa request is incomplete but valid so far.
1660 * 1 if a failure requires the caller to close the connection.
1662 * 2 if a failure requires the caller to abort the connection.
1664 static int process_mpa_request(struct c4iw_ep
*ep
, struct sk_buff
*skb
)
1666 struct mpa_message
*mpa
;
1667 struct mpa_v2_conn_params
*mpa_v2_params
;
1670 pr_debug("ep %p tid %u\n", ep
, ep
->hwtid
);
1673 * If we get more than the supported amount of private data
1674 * then we must fail this connection.
1676 if (ep
->mpa_pkt_len
+ skb
->len
> sizeof(ep
->mpa_pkt
))
1677 goto err_stop_timer
;
1679 pr_debug("enter (%s line %u)\n", __FILE__
, __LINE__
);
1682 * Copy the new data into our accumulation buffer.
1684 skb_copy_from_linear_data(skb
, &(ep
->mpa_pkt
[ep
->mpa_pkt_len
]),
1686 ep
->mpa_pkt_len
+= skb
->len
;
1689 * If we don't even have the mpa message, then bail.
1690 * We'll continue process when more data arrives.
1692 if (ep
->mpa_pkt_len
< sizeof(*mpa
))
1695 pr_debug("enter (%s line %u)\n", __FILE__
, __LINE__
);
1696 mpa
= (struct mpa_message
*) ep
->mpa_pkt
;
1699 * Validate MPA Header.
1701 if (mpa
->revision
> mpa_rev
) {
1702 pr_err("%s MPA version mismatch. Local = %d, Received = %d\n",
1703 __func__
, mpa_rev
, mpa
->revision
);
1704 goto err_stop_timer
;
1707 if (memcmp(mpa
->key
, MPA_KEY_REQ
, sizeof(mpa
->key
)))
1708 goto err_stop_timer
;
1710 plen
= ntohs(mpa
->private_data_size
);
1713 * Fail if there's too much private data.
1715 if (plen
> MPA_MAX_PRIVATE_DATA
)
1716 goto err_stop_timer
;
1719 * If plen does not account for pkt size
1721 if (ep
->mpa_pkt_len
> (sizeof(*mpa
) + plen
))
1722 goto err_stop_timer
;
1723 ep
->plen
= (u8
) plen
;
1726 * If we don't have all the pdata yet, then bail.
1728 if (ep
->mpa_pkt_len
< (sizeof(*mpa
) + plen
))
1732 * If we get here we have accumulated the entire mpa
1733 * start reply message including private data.
1735 ep
->mpa_attr
.initiator
= 0;
1736 ep
->mpa_attr
.crc_enabled
= (mpa
->flags
& MPA_CRC
) | crc_enabled
? 1 : 0;
1737 ep
->mpa_attr
.recv_marker_enabled
= markers_enabled
;
1738 ep
->mpa_attr
.xmit_marker_enabled
= mpa
->flags
& MPA_MARKERS
? 1 : 0;
1739 ep
->mpa_attr
.version
= mpa
->revision
;
1740 if (mpa
->revision
== 1)
1741 ep
->tried_with_mpa_v1
= 1;
1742 ep
->mpa_attr
.p2p_type
= FW_RI_INIT_P2PTYPE_DISABLED
;
1744 if (mpa
->revision
== 2) {
1745 ep
->mpa_attr
.enhanced_rdma_conn
=
1746 mpa
->flags
& MPA_ENHANCED_RDMA_CONN
? 1 : 0;
1747 if (ep
->mpa_attr
.enhanced_rdma_conn
) {
1748 mpa_v2_params
= (struct mpa_v2_conn_params
*)
1749 (ep
->mpa_pkt
+ sizeof(*mpa
));
1750 ep
->ird
= ntohs(mpa_v2_params
->ird
) &
1751 MPA_V2_IRD_ORD_MASK
;
1752 ep
->ird
= min_t(u32
, ep
->ird
,
1753 cur_max_read_depth(ep
->com
.dev
));
1754 ep
->ord
= ntohs(mpa_v2_params
->ord
) &
1755 MPA_V2_IRD_ORD_MASK
;
1756 ep
->ord
= min_t(u32
, ep
->ord
,
1757 cur_max_read_depth(ep
->com
.dev
));
1758 pr_debug("initiator ird %u ord %u\n",
1760 if (ntohs(mpa_v2_params
->ird
) & MPA_V2_PEER2PEER_MODEL
)
1762 if (ntohs(mpa_v2_params
->ord
) &
1763 MPA_V2_RDMA_WRITE_RTR
)
1764 ep
->mpa_attr
.p2p_type
=
1765 FW_RI_INIT_P2PTYPE_RDMA_WRITE
;
1766 else if (ntohs(mpa_v2_params
->ord
) &
1767 MPA_V2_RDMA_READ_RTR
)
1768 ep
->mpa_attr
.p2p_type
=
1769 FW_RI_INIT_P2PTYPE_READ_REQ
;
1772 } else if (mpa
->revision
== 1)
1774 ep
->mpa_attr
.p2p_type
= p2p_type
;
1776 pr_debug("crc_enabled=%d, recv_marker_enabled=%d, xmit_marker_enabled=%d, version=%d p2p_type=%d\n",
1777 ep
->mpa_attr
.crc_enabled
, ep
->mpa_attr
.recv_marker_enabled
,
1778 ep
->mpa_attr
.xmit_marker_enabled
, ep
->mpa_attr
.version
,
1779 ep
->mpa_attr
.p2p_type
);
1781 __state_set(&ep
->com
, MPA_REQ_RCVD
);
1784 mutex_lock_nested(&ep
->parent_ep
->com
.mutex
, SINGLE_DEPTH_NESTING
);
1785 if (ep
->parent_ep
->com
.state
!= DEAD
) {
1786 if (connect_request_upcall(ep
))
1787 goto err_unlock_parent
;
1789 goto err_unlock_parent
;
1791 mutex_unlock(&ep
->parent_ep
->com
.mutex
);
1795 mutex_unlock(&ep
->parent_ep
->com
.mutex
);
1798 (void)stop_ep_timer(ep
);
1803 static int rx_data(struct c4iw_dev
*dev
, struct sk_buff
*skb
)
1806 struct cpl_rx_data
*hdr
= cplhdr(skb
);
1807 unsigned int dlen
= ntohs(hdr
->len
);
1808 unsigned int tid
= GET_TID(hdr
);
1809 __u8 status
= hdr
->status
;
1812 ep
= get_ep_from_tid(dev
, tid
);
1815 pr_debug("ep %p tid %u dlen %u\n", ep
, ep
->hwtid
, dlen
);
1816 skb_pull(skb
, sizeof(*hdr
));
1817 skb_trim(skb
, dlen
);
1818 mutex_lock(&ep
->com
.mutex
);
1820 switch (ep
->com
.state
) {
1822 update_rx_credits(ep
, dlen
);
1823 ep
->rcv_seq
+= dlen
;
1824 disconnect
= process_mpa_reply(ep
, skb
);
1827 update_rx_credits(ep
, dlen
);
1828 ep
->rcv_seq
+= dlen
;
1829 disconnect
= process_mpa_request(ep
, skb
);
1832 struct c4iw_qp_attributes attrs
;
1834 update_rx_credits(ep
, dlen
);
1836 pr_err("%s Unexpected streaming data." \
1837 " qpid %u ep %p state %d tid %u status %d\n",
1838 __func__
, ep
->com
.qp
->wq
.sq
.qid
, ep
,
1839 ep
->com
.state
, ep
->hwtid
, status
);
1840 attrs
.next_state
= C4IW_QP_STATE_TERMINATE
;
1841 c4iw_modify_qp(ep
->com
.qp
->rhp
, ep
->com
.qp
,
1842 C4IW_QP_ATTR_NEXT_STATE
, &attrs
, 1);
1849 mutex_unlock(&ep
->com
.mutex
);
1851 c4iw_ep_disconnect(ep
, disconnect
== 2, GFP_KERNEL
);
1852 c4iw_put_ep(&ep
->com
);
1856 static int abort_rpl(struct c4iw_dev
*dev
, struct sk_buff
*skb
)
1859 struct cpl_abort_rpl_rss
*rpl
= cplhdr(skb
);
1861 unsigned int tid
= GET_TID(rpl
);
1863 ep
= get_ep_from_tid(dev
, tid
);
1865 pr_warn("Abort rpl to freed endpoint\n");
1868 pr_debug("ep %p tid %u\n", ep
, ep
->hwtid
);
1869 mutex_lock(&ep
->com
.mutex
);
1870 switch (ep
->com
.state
) {
1872 c4iw_wake_up_noref(ep
->com
.wr_waitp
, -ECONNRESET
);
1873 __state_set(&ep
->com
, DEAD
);
1877 pr_err("%s ep %p state %d\n", __func__
, ep
, ep
->com
.state
);
1880 mutex_unlock(&ep
->com
.mutex
);
1883 release_ep_resources(ep
);
1884 c4iw_put_ep(&ep
->com
);
1888 static int send_fw_act_open_req(struct c4iw_ep
*ep
, unsigned int atid
)
1890 struct sk_buff
*skb
;
1891 struct fw_ofld_connection_wr
*req
;
1892 unsigned int mtu_idx
;
1894 struct sockaddr_in
*sin
;
1897 skb
= get_skb(NULL
, sizeof(*req
), GFP_KERNEL
);
1898 req
= __skb_put_zero(skb
, sizeof(*req
));
1899 req
->op_compl
= htonl(WR_OP_V(FW_OFLD_CONNECTION_WR
));
1900 req
->len16_pkd
= htonl(FW_WR_LEN16_V(DIV_ROUND_UP(sizeof(*req
), 16)));
1901 req
->le
.filter
= cpu_to_be32(cxgb4_select_ntuple(
1902 ep
->com
.dev
->rdev
.lldi
.ports
[0],
1904 sin
= (struct sockaddr_in
*)&ep
->com
.local_addr
;
1905 req
->le
.lport
= sin
->sin_port
;
1906 req
->le
.u
.ipv4
.lip
= sin
->sin_addr
.s_addr
;
1907 sin
= (struct sockaddr_in
*)&ep
->com
.remote_addr
;
1908 req
->le
.pport
= sin
->sin_port
;
1909 req
->le
.u
.ipv4
.pip
= sin
->sin_addr
.s_addr
;
1910 req
->tcb
.t_state_to_astid
=
1911 htonl(FW_OFLD_CONNECTION_WR_T_STATE_V(TCP_SYN_SENT
) |
1912 FW_OFLD_CONNECTION_WR_ASTID_V(atid
));
1913 req
->tcb
.cplrxdataack_cplpassacceptrpl
=
1914 htons(FW_OFLD_CONNECTION_WR_CPLRXDATAACK_F
);
1915 req
->tcb
.tx_max
= (__force __be32
) jiffies
;
1916 req
->tcb
.rcv_adv
= htons(1);
1917 cxgb_best_mtu(ep
->com
.dev
->rdev
.lldi
.mtus
, ep
->mtu
, &mtu_idx
,
1918 enable_tcp_timestamps
,
1919 (ep
->com
.remote_addr
.ss_family
== AF_INET
) ? 0 : 1);
1920 wscale
= cxgb_compute_wscale(rcv_win
);
1923 * Specify the largest window that will fit in opt0. The
1924 * remainder will be specified in the rx_data_ack.
1926 win
= ep
->rcv_win
>> 10;
1927 if (win
> RCV_BUFSIZ_M
)
1930 req
->tcb
.opt0
= (__force __be64
) (TCAM_BYPASS_F
|
1931 (nocong
? NO_CONG_F
: 0) |
1934 WND_SCALE_V(wscale
) |
1935 MSS_IDX_V(mtu_idx
) |
1936 L2T_IDX_V(ep
->l2t
->idx
) |
1937 TX_CHAN_V(ep
->tx_chan
) |
1938 SMAC_SEL_V(ep
->smac_idx
) |
1939 DSCP_V(ep
->tos
>> 2) |
1940 ULP_MODE_V(ULP_MODE_TCPDDP
) |
1942 req
->tcb
.opt2
= (__force __be32
) (PACE_V(1) |
1943 TX_QUEUE_V(ep
->com
.dev
->rdev
.lldi
.tx_modq
[ep
->tx_chan
]) |
1945 CCTRL_ECN_V(enable_ecn
) |
1946 RSS_QUEUE_VALID_F
| RSS_QUEUE_V(ep
->rss_qid
));
1947 if (enable_tcp_timestamps
)
1948 req
->tcb
.opt2
|= (__force __be32
)TSTAMPS_EN_F
;
1949 if (enable_tcp_sack
)
1950 req
->tcb
.opt2
|= (__force __be32
)SACK_EN_F
;
1951 if (wscale
&& enable_tcp_window_scaling
)
1952 req
->tcb
.opt2
|= (__force __be32
)WND_SCALE_EN_F
;
1953 req
->tcb
.opt0
= cpu_to_be64((__force u64
)req
->tcb
.opt0
);
1954 req
->tcb
.opt2
= cpu_to_be32((__force u32
)req
->tcb
.opt2
);
1955 set_wr_txq(skb
, CPL_PRIORITY_CONTROL
, ep
->ctrlq_idx
);
1956 set_bit(ACT_OFLD_CONN
, &ep
->com
.history
);
1957 return c4iw_l2t_send(&ep
->com
.dev
->rdev
, skb
, ep
->l2t
);
1961 * Some of the error codes above implicitly indicate that there is no TID
1962 * allocated with the result of an ACT_OPEN. We use this predicate to make
1965 static inline int act_open_has_tid(int status
)
1967 return (status
!= CPL_ERR_TCAM_PARITY
&&
1968 status
!= CPL_ERR_TCAM_MISS
&&
1969 status
!= CPL_ERR_TCAM_FULL
&&
1970 status
!= CPL_ERR_CONN_EXIST_SYNRECV
&&
1971 status
!= CPL_ERR_CONN_EXIST
);
1974 static char *neg_adv_str(unsigned int status
)
1977 case CPL_ERR_RTX_NEG_ADVICE
:
1978 return "Retransmit timeout";
1979 case CPL_ERR_PERSIST_NEG_ADVICE
:
1980 return "Persist timeout";
1981 case CPL_ERR_KEEPALV_NEG_ADVICE
:
1982 return "Keepalive timeout";
1988 static void set_tcp_window(struct c4iw_ep
*ep
, struct port_info
*pi
)
1990 ep
->snd_win
= snd_win
;
1991 ep
->rcv_win
= rcv_win
;
1992 pr_debug("snd_win %d rcv_win %d\n",
1993 ep
->snd_win
, ep
->rcv_win
);
1996 #define ACT_OPEN_RETRY_COUNT 2
1998 static int import_ep(struct c4iw_ep
*ep
, int iptype
, __u8
*peer_ip
,
1999 struct dst_entry
*dst
, struct c4iw_dev
*cdev
,
2000 bool clear_mpa_v1
, enum chip_type adapter_type
, u8 tos
)
2002 struct neighbour
*n
;
2004 struct net_device
*pdev
;
2006 n
= dst_neigh_lookup(dst
, peer_ip
);
2012 if (n
->dev
->flags
& IFF_LOOPBACK
) {
2014 pdev
= ip_dev_find(&init_net
, *(__be32
*)peer_ip
);
2015 else if (IS_ENABLED(CONFIG_IPV6
))
2016 for_each_netdev(&init_net
, pdev
) {
2017 if (ipv6_chk_addr(&init_net
,
2018 (struct in6_addr
*)peer_ip
,
2029 ep
->l2t
= cxgb4_l2t_get(cdev
->rdev
.lldi
.l2t
,
2030 n
, pdev
, rt_tos2priority(tos
));
2035 ep
->mtu
= pdev
->mtu
;
2036 ep
->tx_chan
= cxgb4_port_chan(pdev
);
2037 ep
->smac_idx
= cxgb4_tp_smt_idx(adapter_type
,
2038 cxgb4_port_viid(pdev
));
2039 step
= cdev
->rdev
.lldi
.ntxq
/
2040 cdev
->rdev
.lldi
.nchan
;
2041 ep
->txq_idx
= cxgb4_port_idx(pdev
) * step
;
2042 step
= cdev
->rdev
.lldi
.nrxq
/
2043 cdev
->rdev
.lldi
.nchan
;
2044 ep
->ctrlq_idx
= cxgb4_port_idx(pdev
);
2045 ep
->rss_qid
= cdev
->rdev
.lldi
.rxq_ids
[
2046 cxgb4_port_idx(pdev
) * step
];
2047 set_tcp_window(ep
, (struct port_info
*)netdev_priv(pdev
));
2050 pdev
= get_real_dev(n
->dev
);
2051 ep
->l2t
= cxgb4_l2t_get(cdev
->rdev
.lldi
.l2t
,
2055 ep
->mtu
= dst_mtu(dst
);
2056 ep
->tx_chan
= cxgb4_port_chan(pdev
);
2057 ep
->smac_idx
= cxgb4_tp_smt_idx(adapter_type
,
2058 cxgb4_port_viid(pdev
));
2059 step
= cdev
->rdev
.lldi
.ntxq
/
2060 cdev
->rdev
.lldi
.nchan
;
2061 ep
->txq_idx
= cxgb4_port_idx(pdev
) * step
;
2062 ep
->ctrlq_idx
= cxgb4_port_idx(pdev
);
2063 step
= cdev
->rdev
.lldi
.nrxq
/
2064 cdev
->rdev
.lldi
.nchan
;
2065 ep
->rss_qid
= cdev
->rdev
.lldi
.rxq_ids
[
2066 cxgb4_port_idx(pdev
) * step
];
2067 set_tcp_window(ep
, (struct port_info
*)netdev_priv(pdev
));
2070 ep
->retry_with_mpa_v1
= 0;
2071 ep
->tried_with_mpa_v1
= 0;
2083 static int c4iw_reconnect(struct c4iw_ep
*ep
)
2087 struct sockaddr_in
*laddr
= (struct sockaddr_in
*)
2088 &ep
->com
.cm_id
->m_local_addr
;
2089 struct sockaddr_in
*raddr
= (struct sockaddr_in
*)
2090 &ep
->com
.cm_id
->m_remote_addr
;
2091 struct sockaddr_in6
*laddr6
= (struct sockaddr_in6
*)
2092 &ep
->com
.cm_id
->m_local_addr
;
2093 struct sockaddr_in6
*raddr6
= (struct sockaddr_in6
*)
2094 &ep
->com
.cm_id
->m_remote_addr
;
2098 pr_debug("qp %p cm_id %p\n", ep
->com
.qp
, ep
->com
.cm_id
);
2099 c4iw_init_wr_wait(ep
->com
.wr_waitp
);
2101 /* When MPA revision is different on nodes, the node with MPA_rev=2
2102 * tries to reconnect with MPA_rev 1 for the same EP through
2103 * c4iw_reconnect(), where the same EP is assigned with new tid for
2104 * further connection establishment. As we are using the same EP pointer
2105 * for reconnect, few skbs are used during the previous c4iw_connect(),
2106 * which leaves the EP with inadequate skbs for further
2107 * c4iw_reconnect(), Further causing a crash due to an empty
2108 * skb_list() during peer_abort(). Allocate skbs which is already used.
2110 size
= (CN_MAX_CON_BUF
- skb_queue_len(&ep
->com
.ep_skb_list
));
2111 if (alloc_ep_skb_list(&ep
->com
.ep_skb_list
, size
)) {
2117 * Allocate an active TID to initiate a TCP connection.
2119 ep
->atid
= cxgb4_alloc_atid(ep
->com
.dev
->rdev
.lldi
.tids
, ep
);
2120 if (ep
->atid
== -1) {
2121 pr_err("%s - cannot alloc atid\n", __func__
);
2125 insert_handle(ep
->com
.dev
, &ep
->com
.dev
->atid_idr
, ep
, ep
->atid
);
2128 if (ep
->com
.cm_id
->m_local_addr
.ss_family
== AF_INET
) {
2129 ep
->dst
= cxgb_find_route(&ep
->com
.dev
->rdev
.lldi
, get_real_dev
,
2130 laddr
->sin_addr
.s_addr
,
2131 raddr
->sin_addr
.s_addr
,
2133 raddr
->sin_port
, ep
->com
.cm_id
->tos
);
2135 ra
= (__u8
*)&raddr
->sin_addr
;
2137 ep
->dst
= cxgb_find_route6(&ep
->com
.dev
->rdev
.lldi
,
2139 laddr6
->sin6_addr
.s6_addr
,
2140 raddr6
->sin6_addr
.s6_addr
,
2142 raddr6
->sin6_port
, 0,
2143 raddr6
->sin6_scope_id
);
2145 ra
= (__u8
*)&raddr6
->sin6_addr
;
2148 pr_err("%s - cannot find route\n", __func__
);
2149 err
= -EHOSTUNREACH
;
2152 err
= import_ep(ep
, iptype
, ra
, ep
->dst
, ep
->com
.dev
, false,
2153 ep
->com
.dev
->rdev
.lldi
.adapter_type
,
2154 ep
->com
.cm_id
->tos
);
2156 pr_err("%s - cannot alloc l2e\n", __func__
);
2160 pr_debug("txq_idx %u tx_chan %u smac_idx %u rss_qid %u l2t_idx %u\n",
2161 ep
->txq_idx
, ep
->tx_chan
, ep
->smac_idx
, ep
->rss_qid
,
2164 state_set(&ep
->com
, CONNECTING
);
2165 ep
->tos
= ep
->com
.cm_id
->tos
;
2167 /* send connect request to rnic */
2168 err
= send_connect(ep
);
2172 cxgb4_l2t_release(ep
->l2t
);
2174 dst_release(ep
->dst
);
2176 remove_handle(ep
->com
.dev
, &ep
->com
.dev
->atid_idr
, ep
->atid
);
2177 cxgb4_free_atid(ep
->com
.dev
->rdev
.lldi
.tids
, ep
->atid
);
2180 * remember to send notification to upper layer.
2181 * We are in here so the upper layer is not aware that this is
2182 * re-connect attempt and so, upper layer is still waiting for
2183 * response of 1st connect request.
2185 connect_reply_upcall(ep
, -ECONNRESET
);
2187 c4iw_put_ep(&ep
->com
);
2192 static int act_open_rpl(struct c4iw_dev
*dev
, struct sk_buff
*skb
)
2195 struct cpl_act_open_rpl
*rpl
= cplhdr(skb
);
2196 unsigned int atid
= TID_TID_G(AOPEN_ATID_G(
2197 ntohl(rpl
->atid_status
)));
2198 struct tid_info
*t
= dev
->rdev
.lldi
.tids
;
2199 int status
= AOPEN_STATUS_G(ntohl(rpl
->atid_status
));
2200 struct sockaddr_in
*la
;
2201 struct sockaddr_in
*ra
;
2202 struct sockaddr_in6
*la6
;
2203 struct sockaddr_in6
*ra6
;
2206 ep
= lookup_atid(t
, atid
);
2207 la
= (struct sockaddr_in
*)&ep
->com
.local_addr
;
2208 ra
= (struct sockaddr_in
*)&ep
->com
.remote_addr
;
2209 la6
= (struct sockaddr_in6
*)&ep
->com
.local_addr
;
2210 ra6
= (struct sockaddr_in6
*)&ep
->com
.remote_addr
;
2212 pr_debug("ep %p atid %u status %u errno %d\n", ep
, atid
,
2213 status
, status2errno(status
));
2215 if (cxgb_is_neg_adv(status
)) {
2216 pr_debug("Connection problems for atid %u status %u (%s)\n",
2217 atid
, status
, neg_adv_str(status
));
2218 ep
->stats
.connect_neg_adv
++;
2219 mutex_lock(&dev
->rdev
.stats
.lock
);
2220 dev
->rdev
.stats
.neg_adv
++;
2221 mutex_unlock(&dev
->rdev
.stats
.lock
);
2225 set_bit(ACT_OPEN_RPL
, &ep
->com
.history
);
2228 * Log interesting failures.
2231 case CPL_ERR_CONN_RESET
:
2232 case CPL_ERR_CONN_TIMEDOUT
:
2234 case CPL_ERR_TCAM_FULL
:
2235 mutex_lock(&dev
->rdev
.stats
.lock
);
2236 dev
->rdev
.stats
.tcam_full
++;
2237 mutex_unlock(&dev
->rdev
.stats
.lock
);
2238 if (ep
->com
.local_addr
.ss_family
== AF_INET
&&
2239 dev
->rdev
.lldi
.enable_fw_ofld_conn
) {
2240 ret
= send_fw_act_open_req(ep
, TID_TID_G(AOPEN_ATID_G(
2241 ntohl(rpl
->atid_status
))));
2247 case CPL_ERR_CONN_EXIST
:
2248 if (ep
->retry_count
++ < ACT_OPEN_RETRY_COUNT
) {
2249 set_bit(ACT_RETRY_INUSE
, &ep
->com
.history
);
2250 if (ep
->com
.remote_addr
.ss_family
== AF_INET6
) {
2251 struct sockaddr_in6
*sin6
=
2252 (struct sockaddr_in6
*)
2253 &ep
->com
.local_addr
;
2255 ep
->com
.dev
->rdev
.lldi
.ports
[0],
2257 &sin6
->sin6_addr
.s6_addr
, 1);
2259 remove_handle(ep
->com
.dev
, &ep
->com
.dev
->atid_idr
,
2261 cxgb4_free_atid(t
, atid
);
2262 dst_release(ep
->dst
);
2263 cxgb4_l2t_release(ep
->l2t
);
2269 if (ep
->com
.local_addr
.ss_family
== AF_INET
) {
2270 pr_info("Active open failure - atid %u status %u errno %d %pI4:%u->%pI4:%u\n",
2271 atid
, status
, status2errno(status
),
2272 &la
->sin_addr
.s_addr
, ntohs(la
->sin_port
),
2273 &ra
->sin_addr
.s_addr
, ntohs(ra
->sin_port
));
2275 pr_info("Active open failure - atid %u status %u errno %d %pI6:%u->%pI6:%u\n",
2276 atid
, status
, status2errno(status
),
2277 la6
->sin6_addr
.s6_addr
, ntohs(la6
->sin6_port
),
2278 ra6
->sin6_addr
.s6_addr
, ntohs(ra6
->sin6_port
));
2284 connect_reply_upcall(ep
, status2errno(status
));
2285 state_set(&ep
->com
, DEAD
);
2287 if (ep
->com
.remote_addr
.ss_family
== AF_INET6
) {
2288 struct sockaddr_in6
*sin6
=
2289 (struct sockaddr_in6
*)&ep
->com
.local_addr
;
2290 cxgb4_clip_release(ep
->com
.dev
->rdev
.lldi
.ports
[0],
2291 (const u32
*)&sin6
->sin6_addr
.s6_addr
, 1);
2293 if (status
&& act_open_has_tid(status
))
2294 cxgb4_remove_tid(ep
->com
.dev
->rdev
.lldi
.tids
, 0, GET_TID(rpl
),
2295 ep
->com
.local_addr
.ss_family
);
2297 remove_handle(ep
->com
.dev
, &ep
->com
.dev
->atid_idr
, atid
);
2298 cxgb4_free_atid(t
, atid
);
2299 dst_release(ep
->dst
);
2300 cxgb4_l2t_release(ep
->l2t
);
2301 c4iw_put_ep(&ep
->com
);
2306 static int pass_open_rpl(struct c4iw_dev
*dev
, struct sk_buff
*skb
)
2308 struct cpl_pass_open_rpl
*rpl
= cplhdr(skb
);
2309 unsigned int stid
= GET_TID(rpl
);
2310 struct c4iw_listen_ep
*ep
= get_ep_from_stid(dev
, stid
);
2313 pr_warn("%s stid %d lookup failure!\n", __func__
, stid
);
2316 pr_debug("ep %p status %d error %d\n", ep
,
2317 rpl
->status
, status2errno(rpl
->status
));
2318 c4iw_wake_up_noref(ep
->com
.wr_waitp
, status2errno(rpl
->status
));
2319 c4iw_put_ep(&ep
->com
);
2324 static int close_listsrv_rpl(struct c4iw_dev
*dev
, struct sk_buff
*skb
)
2326 struct cpl_close_listsvr_rpl
*rpl
= cplhdr(skb
);
2327 unsigned int stid
= GET_TID(rpl
);
2328 struct c4iw_listen_ep
*ep
= get_ep_from_stid(dev
, stid
);
2331 pr_warn("%s stid %d lookup failure!\n", __func__
, stid
);
2334 pr_debug("ep %p\n", ep
);
2335 c4iw_wake_up_noref(ep
->com
.wr_waitp
, status2errno(rpl
->status
));
2336 c4iw_put_ep(&ep
->com
);
2341 static int accept_cr(struct c4iw_ep
*ep
, struct sk_buff
*skb
,
2342 struct cpl_pass_accept_req
*req
)
2344 struct cpl_pass_accept_rpl
*rpl
;
2345 unsigned int mtu_idx
;
2349 struct cpl_t5_pass_accept_rpl
*rpl5
= NULL
;
2351 enum chip_type adapter_type
= ep
->com
.dev
->rdev
.lldi
.adapter_type
;
2353 pr_debug("ep %p tid %u\n", ep
, ep
->hwtid
);
2357 if (!is_t4(adapter_type
)) {
2358 skb_trim(skb
, roundup(sizeof(*rpl5
), 16));
2360 INIT_TP_WR(rpl5
, ep
->hwtid
);
2362 skb_trim(skb
, sizeof(*rpl
));
2363 INIT_TP_WR(rpl
, ep
->hwtid
);
2365 OPCODE_TID(rpl
) = cpu_to_be32(MK_OPCODE_TID(CPL_PASS_ACCEPT_RPL
,
2368 cxgb_best_mtu(ep
->com
.dev
->rdev
.lldi
.mtus
, ep
->mtu
, &mtu_idx
,
2369 enable_tcp_timestamps
&& req
->tcpopt
.tstamp
,
2370 (ep
->com
.remote_addr
.ss_family
== AF_INET
) ? 0 : 1);
2371 wscale
= cxgb_compute_wscale(rcv_win
);
2374 * Specify the largest window that will fit in opt0. The
2375 * remainder will be specified in the rx_data_ack.
2377 win
= ep
->rcv_win
>> 10;
2378 if (win
> RCV_BUFSIZ_M
)
2380 opt0
= (nocong
? NO_CONG_F
: 0) |
2383 WND_SCALE_V(wscale
) |
2384 MSS_IDX_V(mtu_idx
) |
2385 L2T_IDX_V(ep
->l2t
->idx
) |
2386 TX_CHAN_V(ep
->tx_chan
) |
2387 SMAC_SEL_V(ep
->smac_idx
) |
2388 DSCP_V(ep
->tos
>> 2) |
2389 ULP_MODE_V(ULP_MODE_TCPDDP
) |
2391 opt2
= RX_CHANNEL_V(0) |
2392 RSS_QUEUE_VALID_F
| RSS_QUEUE_V(ep
->rss_qid
);
2394 if (enable_tcp_timestamps
&& req
->tcpopt
.tstamp
)
2395 opt2
|= TSTAMPS_EN_F
;
2396 if (enable_tcp_sack
&& req
->tcpopt
.sack
)
2398 if (wscale
&& enable_tcp_window_scaling
)
2399 opt2
|= WND_SCALE_EN_F
;
2401 const struct tcphdr
*tcph
;
2402 u32 hlen
= ntohl(req
->hdr_len
);
2404 if (CHELSIO_CHIP_VERSION(adapter_type
) <= CHELSIO_T5
)
2405 tcph
= (const void *)(req
+ 1) + ETH_HDR_LEN_G(hlen
) +
2408 tcph
= (const void *)(req
+ 1) +
2409 T6_ETH_HDR_LEN_G(hlen
) + T6_IP_HDR_LEN_G(hlen
);
2410 if (tcph
->ece
&& tcph
->cwr
)
2411 opt2
|= CCTRL_ECN_V(1);
2413 if (CHELSIO_CHIP_VERSION(adapter_type
) > CHELSIO_T4
) {
2414 u32 isn
= (prandom_u32() & ~7UL) - 1;
2415 opt2
|= T5_OPT_2_VALID_F
;
2416 opt2
|= CONG_CNTRL_V(CONG_ALG_TAHOE
);
2419 memset(&rpl5
->iss
, 0, roundup(sizeof(*rpl5
)-sizeof(*rpl
), 16));
2422 rpl5
->iss
= cpu_to_be32(isn
);
2423 pr_debug("iss %u\n", be32_to_cpu(rpl5
->iss
));
2426 rpl
->opt0
= cpu_to_be64(opt0
);
2427 rpl
->opt2
= cpu_to_be32(opt2
);
2428 set_wr_txq(skb
, CPL_PRIORITY_SETUP
, ep
->ctrlq_idx
);
2429 t4_set_arp_err_handler(skb
, ep
, pass_accept_rpl_arp_failure
);
2431 return c4iw_l2t_send(&ep
->com
.dev
->rdev
, skb
, ep
->l2t
);
2434 static void reject_cr(struct c4iw_dev
*dev
, u32 hwtid
, struct sk_buff
*skb
)
2436 pr_debug("c4iw_dev %p tid %u\n", dev
, hwtid
);
2437 skb_trim(skb
, sizeof(struct cpl_tid_release
));
2438 release_tid(&dev
->rdev
, hwtid
, skb
);
2442 static int pass_accept_req(struct c4iw_dev
*dev
, struct sk_buff
*skb
)
2444 struct c4iw_ep
*child_ep
= NULL
, *parent_ep
;
2445 struct cpl_pass_accept_req
*req
= cplhdr(skb
);
2446 unsigned int stid
= PASS_OPEN_TID_G(ntohl(req
->tos_stid
));
2447 struct tid_info
*t
= dev
->rdev
.lldi
.tids
;
2448 unsigned int hwtid
= GET_TID(req
);
2449 struct dst_entry
*dst
;
2450 __u8 local_ip
[16], peer_ip
[16];
2451 __be16 local_port
, peer_port
;
2452 struct sockaddr_in6
*sin6
;
2454 u16 peer_mss
= ntohs(req
->tcpopt
.mss
);
2456 unsigned short hdrs
;
2457 u8 tos
= PASS_OPEN_TOS_G(ntohl(req
->tos_stid
));
2459 parent_ep
= (struct c4iw_ep
*)get_ep_from_stid(dev
, stid
);
2461 pr_err("%s connect request on invalid stid %d\n",
2466 if (state_read(&parent_ep
->com
) != LISTEN
) {
2467 pr_err("%s - listening ep not in LISTEN\n", __func__
);
2471 cxgb_get_4tuple(req
, parent_ep
->com
.dev
->rdev
.lldi
.adapter_type
,
2472 &iptype
, local_ip
, peer_ip
, &local_port
, &peer_port
);
2474 /* Find output route */
2476 pr_debug("parent ep %p hwtid %u laddr %pI4 raddr %pI4 lport %d rport %d peer_mss %d\n"
2478 local_ip
, peer_ip
, ntohs(local_port
),
2479 ntohs(peer_port
), peer_mss
);
2480 dst
= cxgb_find_route(&dev
->rdev
.lldi
, get_real_dev
,
2481 *(__be32
*)local_ip
, *(__be32
*)peer_ip
,
2482 local_port
, peer_port
, tos
);
2484 pr_debug("parent ep %p hwtid %u laddr %pI6 raddr %pI6 lport %d rport %d peer_mss %d\n"
2486 local_ip
, peer_ip
, ntohs(local_port
),
2487 ntohs(peer_port
), peer_mss
);
2488 dst
= cxgb_find_route6(&dev
->rdev
.lldi
, get_real_dev
,
2489 local_ip
, peer_ip
, local_port
, peer_port
,
2490 PASS_OPEN_TOS_G(ntohl(req
->tos_stid
)),
2491 ((struct sockaddr_in6
*)
2492 &parent_ep
->com
.local_addr
)->sin6_scope_id
);
2495 pr_err("%s - failed to find dst entry!\n", __func__
);
2499 child_ep
= alloc_ep(sizeof(*child_ep
), GFP_KERNEL
);
2501 pr_err("%s - failed to allocate ep entry!\n", __func__
);
2506 err
= import_ep(child_ep
, iptype
, peer_ip
, dst
, dev
, false,
2507 parent_ep
->com
.dev
->rdev
.lldi
.adapter_type
, tos
);
2509 pr_err("%s - failed to allocate l2t entry!\n", __func__
);
2515 hdrs
= ((iptype
== 4) ? sizeof(struct iphdr
) : sizeof(struct ipv6hdr
)) +
2516 sizeof(struct tcphdr
) +
2517 ((enable_tcp_timestamps
&& req
->tcpopt
.tstamp
) ? 12 : 0);
2518 if (peer_mss
&& child_ep
->mtu
> (peer_mss
+ hdrs
))
2519 child_ep
->mtu
= peer_mss
+ hdrs
;
2521 skb_queue_head_init(&child_ep
->com
.ep_skb_list
);
2522 if (alloc_ep_skb_list(&child_ep
->com
.ep_skb_list
, CN_MAX_CON_BUF
))
2525 state_set(&child_ep
->com
, CONNECTING
);
2526 child_ep
->com
.dev
= dev
;
2527 child_ep
->com
.cm_id
= NULL
;
2530 struct sockaddr_in
*sin
= (struct sockaddr_in
*)
2531 &child_ep
->com
.local_addr
;
2533 sin
->sin_family
= AF_INET
;
2534 sin
->sin_port
= local_port
;
2535 sin
->sin_addr
.s_addr
= *(__be32
*)local_ip
;
2537 sin
= (struct sockaddr_in
*)&child_ep
->com
.local_addr
;
2538 sin
->sin_family
= AF_INET
;
2539 sin
->sin_port
= ((struct sockaddr_in
*)
2540 &parent_ep
->com
.local_addr
)->sin_port
;
2541 sin
->sin_addr
.s_addr
= *(__be32
*)local_ip
;
2543 sin
= (struct sockaddr_in
*)&child_ep
->com
.remote_addr
;
2544 sin
->sin_family
= AF_INET
;
2545 sin
->sin_port
= peer_port
;
2546 sin
->sin_addr
.s_addr
= *(__be32
*)peer_ip
;
2548 sin6
= (struct sockaddr_in6
*)&child_ep
->com
.local_addr
;
2549 sin6
->sin6_family
= PF_INET6
;
2550 sin6
->sin6_port
= local_port
;
2551 memcpy(sin6
->sin6_addr
.s6_addr
, local_ip
, 16);
2553 sin6
= (struct sockaddr_in6
*)&child_ep
->com
.local_addr
;
2554 sin6
->sin6_family
= PF_INET6
;
2555 sin6
->sin6_port
= ((struct sockaddr_in6
*)
2556 &parent_ep
->com
.local_addr
)->sin6_port
;
2557 memcpy(sin6
->sin6_addr
.s6_addr
, local_ip
, 16);
2559 sin6
= (struct sockaddr_in6
*)&child_ep
->com
.remote_addr
;
2560 sin6
->sin6_family
= PF_INET6
;
2561 sin6
->sin6_port
= peer_port
;
2562 memcpy(sin6
->sin6_addr
.s6_addr
, peer_ip
, 16);
2565 c4iw_get_ep(&parent_ep
->com
);
2566 child_ep
->parent_ep
= parent_ep
;
2567 child_ep
->tos
= tos
;
2568 child_ep
->dst
= dst
;
2569 child_ep
->hwtid
= hwtid
;
2571 pr_debug("tx_chan %u smac_idx %u rss_qid %u\n",
2572 child_ep
->tx_chan
, child_ep
->smac_idx
, child_ep
->rss_qid
);
2574 timer_setup(&child_ep
->timer
, ep_timeout
, 0);
2575 cxgb4_insert_tid(t
, child_ep
, hwtid
,
2576 child_ep
->com
.local_addr
.ss_family
);
2577 insert_ep_tid(child_ep
);
2578 if (accept_cr(child_ep
, skb
, req
)) {
2579 c4iw_put_ep(&parent_ep
->com
);
2580 release_ep_resources(child_ep
);
2582 set_bit(PASS_ACCEPT_REQ
, &child_ep
->com
.history
);
2585 sin6
= (struct sockaddr_in6
*)&child_ep
->com
.local_addr
;
2586 cxgb4_clip_get(child_ep
->com
.dev
->rdev
.lldi
.ports
[0],
2587 (const u32
*)&sin6
->sin6_addr
.s6_addr
, 1);
2591 c4iw_put_ep(&child_ep
->com
);
2593 reject_cr(dev
, hwtid
, skb
);
2596 c4iw_put_ep(&parent_ep
->com
);
2600 static int pass_establish(struct c4iw_dev
*dev
, struct sk_buff
*skb
)
2603 struct cpl_pass_establish
*req
= cplhdr(skb
);
2604 unsigned int tid
= GET_TID(req
);
2607 ep
= get_ep_from_tid(dev
, tid
);
2608 pr_debug("ep %p tid %u\n", ep
, ep
->hwtid
);
2609 ep
->snd_seq
= be32_to_cpu(req
->snd_isn
);
2610 ep
->rcv_seq
= be32_to_cpu(req
->rcv_isn
);
2612 pr_debug("ep %p hwtid %u tcp_opt 0x%02x\n", ep
, tid
,
2613 ntohs(req
->tcp_opt
));
2615 set_emss(ep
, ntohs(req
->tcp_opt
));
2617 dst_confirm(ep
->dst
);
2618 mutex_lock(&ep
->com
.mutex
);
2619 ep
->com
.state
= MPA_REQ_WAIT
;
2621 set_bit(PASS_ESTAB
, &ep
->com
.history
);
2622 ret
= send_flowc(ep
);
2623 mutex_unlock(&ep
->com
.mutex
);
2625 c4iw_ep_disconnect(ep
, 1, GFP_KERNEL
);
2626 c4iw_put_ep(&ep
->com
);
2631 static int peer_close(struct c4iw_dev
*dev
, struct sk_buff
*skb
)
2633 struct cpl_peer_close
*hdr
= cplhdr(skb
);
2635 struct c4iw_qp_attributes attrs
;
2638 unsigned int tid
= GET_TID(hdr
);
2641 ep
= get_ep_from_tid(dev
, tid
);
2645 pr_debug("ep %p tid %u\n", ep
, ep
->hwtid
);
2646 dst_confirm(ep
->dst
);
2648 set_bit(PEER_CLOSE
, &ep
->com
.history
);
2649 mutex_lock(&ep
->com
.mutex
);
2650 switch (ep
->com
.state
) {
2652 __state_set(&ep
->com
, CLOSING
);
2655 __state_set(&ep
->com
, CLOSING
);
2656 connect_reply_upcall(ep
, -ECONNRESET
);
2661 * We're gonna mark this puppy DEAD, but keep
2662 * the reference on it until the ULP accepts or
2663 * rejects the CR. Also wake up anyone waiting
2664 * in rdma connection migration (see c4iw_accept_cr()).
2666 __state_set(&ep
->com
, CLOSING
);
2667 pr_debug("waking up ep %p tid %u\n", ep
, ep
->hwtid
);
2668 c4iw_wake_up_noref(ep
->com
.wr_waitp
, -ECONNRESET
);
2671 __state_set(&ep
->com
, CLOSING
);
2672 pr_debug("waking up ep %p tid %u\n", ep
, ep
->hwtid
);
2673 c4iw_wake_up_noref(ep
->com
.wr_waitp
, -ECONNRESET
);
2677 __state_set(&ep
->com
, CLOSING
);
2678 attrs
.next_state
= C4IW_QP_STATE_CLOSING
;
2679 ret
= c4iw_modify_qp(ep
->com
.qp
->rhp
, ep
->com
.qp
,
2680 C4IW_QP_ATTR_NEXT_STATE
, &attrs
, 1);
2681 if (ret
!= -ECONNRESET
) {
2682 peer_close_upcall(ep
);
2690 __state_set(&ep
->com
, MORIBUND
);
2694 (void)stop_ep_timer(ep
);
2695 if (ep
->com
.cm_id
&& ep
->com
.qp
) {
2696 attrs
.next_state
= C4IW_QP_STATE_IDLE
;
2697 c4iw_modify_qp(ep
->com
.qp
->rhp
, ep
->com
.qp
,
2698 C4IW_QP_ATTR_NEXT_STATE
, &attrs
, 1);
2700 close_complete_upcall(ep
, 0);
2701 __state_set(&ep
->com
, DEAD
);
2709 WARN_ONCE(1, "Bad endpoint state %u\n", ep
->com
.state
);
2711 mutex_unlock(&ep
->com
.mutex
);
2713 c4iw_ep_disconnect(ep
, 0, GFP_KERNEL
);
2715 release_ep_resources(ep
);
2716 c4iw_put_ep(&ep
->com
);
2720 static int peer_abort(struct c4iw_dev
*dev
, struct sk_buff
*skb
)
2722 struct cpl_abort_req_rss
*req
= cplhdr(skb
);
2724 struct sk_buff
*rpl_skb
;
2725 struct c4iw_qp_attributes attrs
;
2728 unsigned int tid
= GET_TID(req
);
2729 u32 len
= roundup(sizeof(struct cpl_abort_rpl
), 16);
2731 ep
= get_ep_from_tid(dev
, tid
);
2735 if (cxgb_is_neg_adv(req
->status
)) {
2736 pr_debug("Negative advice on abort- tid %u status %d (%s)\n",
2737 ep
->hwtid
, req
->status
, neg_adv_str(req
->status
));
2738 ep
->stats
.abort_neg_adv
++;
2739 mutex_lock(&dev
->rdev
.stats
.lock
);
2740 dev
->rdev
.stats
.neg_adv
++;
2741 mutex_unlock(&dev
->rdev
.stats
.lock
);
2744 pr_debug("ep %p tid %u state %u\n", ep
, ep
->hwtid
,
2746 set_bit(PEER_ABORT
, &ep
->com
.history
);
2749 * Wake up any threads in rdma_init() or rdma_fini().
2750 * However, this is not needed if com state is just
2753 if (ep
->com
.state
!= MPA_REQ_SENT
)
2754 c4iw_wake_up_noref(ep
->com
.wr_waitp
, -ECONNRESET
);
2756 mutex_lock(&ep
->com
.mutex
);
2757 switch (ep
->com
.state
) {
2759 c4iw_put_ep(&ep
->parent_ep
->com
);
2762 (void)stop_ep_timer(ep
);
2765 (void)stop_ep_timer(ep
);
2766 if (mpa_rev
== 1 || (mpa_rev
== 2 && ep
->tried_with_mpa_v1
))
2767 connect_reply_upcall(ep
, -ECONNRESET
);
2770 * we just don't send notification upwards because we
2771 * want to retry with mpa_v1 without upper layers even
2774 * do some housekeeping so as to re-initiate the
2777 pr_info("%s: mpa_rev=%d. Retrying with mpav1\n",
2779 ep
->retry_with_mpa_v1
= 1;
2791 if (ep
->com
.cm_id
&& ep
->com
.qp
) {
2792 attrs
.next_state
= C4IW_QP_STATE_ERROR
;
2793 ret
= c4iw_modify_qp(ep
->com
.qp
->rhp
,
2794 ep
->com
.qp
, C4IW_QP_ATTR_NEXT_STATE
,
2797 pr_err("%s - qp <- error failed!\n", __func__
);
2799 peer_abort_upcall(ep
);
2804 pr_warn("%s PEER_ABORT IN DEAD STATE!!!!\n", __func__
);
2805 mutex_unlock(&ep
->com
.mutex
);
2808 WARN_ONCE(1, "Bad endpoint state %u\n", ep
->com
.state
);
2811 dst_confirm(ep
->dst
);
2812 if (ep
->com
.state
!= ABORTING
) {
2813 __state_set(&ep
->com
, DEAD
);
2814 /* we don't release if we want to retry with mpa_v1 */
2815 if (!ep
->retry_with_mpa_v1
)
2818 mutex_unlock(&ep
->com
.mutex
);
2820 rpl_skb
= skb_dequeue(&ep
->com
.ep_skb_list
);
2821 if (WARN_ON(!rpl_skb
)) {
2826 cxgb_mk_abort_rpl(rpl_skb
, len
, ep
->hwtid
, ep
->txq_idx
);
2828 c4iw_ofld_send(&ep
->com
.dev
->rdev
, rpl_skb
);
2831 release_ep_resources(ep
);
2832 else if (ep
->retry_with_mpa_v1
) {
2833 if (ep
->com
.remote_addr
.ss_family
== AF_INET6
) {
2834 struct sockaddr_in6
*sin6
=
2835 (struct sockaddr_in6
*)
2836 &ep
->com
.local_addr
;
2838 ep
->com
.dev
->rdev
.lldi
.ports
[0],
2839 (const u32
*)&sin6
->sin6_addr
.s6_addr
,
2842 remove_handle(ep
->com
.dev
, &ep
->com
.dev
->hwtid_idr
, ep
->hwtid
);
2843 cxgb4_remove_tid(ep
->com
.dev
->rdev
.lldi
.tids
, 0, ep
->hwtid
,
2844 ep
->com
.local_addr
.ss_family
);
2845 dst_release(ep
->dst
);
2846 cxgb4_l2t_release(ep
->l2t
);
2851 c4iw_put_ep(&ep
->com
);
2852 /* Dereferencing ep, referenced in peer_abort_intr() */
2853 c4iw_put_ep(&ep
->com
);
2857 static int close_con_rpl(struct c4iw_dev
*dev
, struct sk_buff
*skb
)
2860 struct c4iw_qp_attributes attrs
;
2861 struct cpl_close_con_rpl
*rpl
= cplhdr(skb
);
2863 unsigned int tid
= GET_TID(rpl
);
2865 ep
= get_ep_from_tid(dev
, tid
);
2869 pr_debug("ep %p tid %u\n", ep
, ep
->hwtid
);
2871 /* The cm_id may be null if we failed to connect */
2872 mutex_lock(&ep
->com
.mutex
);
2873 set_bit(CLOSE_CON_RPL
, &ep
->com
.history
);
2874 switch (ep
->com
.state
) {
2876 __state_set(&ep
->com
, MORIBUND
);
2879 (void)stop_ep_timer(ep
);
2880 if ((ep
->com
.cm_id
) && (ep
->com
.qp
)) {
2881 attrs
.next_state
= C4IW_QP_STATE_IDLE
;
2882 c4iw_modify_qp(ep
->com
.qp
->rhp
,
2884 C4IW_QP_ATTR_NEXT_STATE
,
2887 close_complete_upcall(ep
, 0);
2888 __state_set(&ep
->com
, DEAD
);
2895 WARN_ONCE(1, "Bad endpoint state %u\n", ep
->com
.state
);
2898 mutex_unlock(&ep
->com
.mutex
);
2900 release_ep_resources(ep
);
2901 c4iw_put_ep(&ep
->com
);
2905 static int terminate(struct c4iw_dev
*dev
, struct sk_buff
*skb
)
2907 struct cpl_rdma_terminate
*rpl
= cplhdr(skb
);
2908 unsigned int tid
= GET_TID(rpl
);
2910 struct c4iw_qp_attributes attrs
;
2912 ep
= get_ep_from_tid(dev
, tid
);
2914 if (ep
&& ep
->com
.qp
) {
2915 pr_warn("TERM received tid %u qpid %u\n",
2916 tid
, ep
->com
.qp
->wq
.sq
.qid
);
2917 attrs
.next_state
= C4IW_QP_STATE_TERMINATE
;
2918 c4iw_modify_qp(ep
->com
.qp
->rhp
, ep
->com
.qp
,
2919 C4IW_QP_ATTR_NEXT_STATE
, &attrs
, 1);
2921 pr_warn("TERM received tid %u no ep/qp\n", tid
);
2922 c4iw_put_ep(&ep
->com
);
2928 * Upcall from the adapter indicating data has been transmitted.
2929 * For us its just the single MPA request or reply. We can now free
2930 * the skb holding the mpa message.
2932 static int fw4_ack(struct c4iw_dev
*dev
, struct sk_buff
*skb
)
2935 struct cpl_fw4_ack
*hdr
= cplhdr(skb
);
2936 u8 credits
= hdr
->credits
;
2937 unsigned int tid
= GET_TID(hdr
);
2940 ep
= get_ep_from_tid(dev
, tid
);
2943 pr_debug("ep %p tid %u credits %u\n",
2944 ep
, ep
->hwtid
, credits
);
2946 pr_debug("0 credit ack ep %p tid %u state %u\n",
2947 ep
, ep
->hwtid
, state_read(&ep
->com
));
2951 dst_confirm(ep
->dst
);
2953 pr_debug("last streaming msg ack ep %p tid %u state %u initiator %u freeing skb\n",
2954 ep
, ep
->hwtid
, state_read(&ep
->com
),
2955 ep
->mpa_attr
.initiator
? 1 : 0);
2956 mutex_lock(&ep
->com
.mutex
);
2957 kfree_skb(ep
->mpa_skb
);
2959 if (test_bit(STOP_MPA_TIMER
, &ep
->com
.flags
))
2961 mutex_unlock(&ep
->com
.mutex
);
2964 c4iw_put_ep(&ep
->com
);
2968 int c4iw_reject_cr(struct iw_cm_id
*cm_id
, const void *pdata
, u8 pdata_len
)
2971 struct c4iw_ep
*ep
= to_ep(cm_id
);
2973 pr_debug("ep %p tid %u\n", ep
, ep
->hwtid
);
2975 mutex_lock(&ep
->com
.mutex
);
2976 if (ep
->com
.state
!= MPA_REQ_RCVD
) {
2977 mutex_unlock(&ep
->com
.mutex
);
2978 c4iw_put_ep(&ep
->com
);
2981 set_bit(ULP_REJECT
, &ep
->com
.history
);
2985 abort
= send_mpa_reject(ep
, pdata
, pdata_len
);
2986 mutex_unlock(&ep
->com
.mutex
);
2989 c4iw_ep_disconnect(ep
, abort
!= 0, GFP_KERNEL
);
2990 c4iw_put_ep(&ep
->com
);
2994 int c4iw_accept_cr(struct iw_cm_id
*cm_id
, struct iw_cm_conn_param
*conn_param
)
2997 struct c4iw_qp_attributes attrs
;
2998 enum c4iw_qp_attr_mask mask
;
2999 struct c4iw_ep
*ep
= to_ep(cm_id
);
3000 struct c4iw_dev
*h
= to_c4iw_dev(cm_id
->device
);
3001 struct c4iw_qp
*qp
= get_qhp(h
, conn_param
->qpn
);
3004 pr_debug("ep %p tid %u\n", ep
, ep
->hwtid
);
3006 mutex_lock(&ep
->com
.mutex
);
3007 if (ep
->com
.state
!= MPA_REQ_RCVD
) {
3017 set_bit(ULP_ACCEPT
, &ep
->com
.history
);
3018 if ((conn_param
->ord
> cur_max_read_depth(ep
->com
.dev
)) ||
3019 (conn_param
->ird
> cur_max_read_depth(ep
->com
.dev
))) {
3024 if (ep
->mpa_attr
.version
== 2 && ep
->mpa_attr
.enhanced_rdma_conn
) {
3025 if (conn_param
->ord
> ep
->ird
) {
3026 if (RELAXED_IRD_NEGOTIATION
) {
3027 conn_param
->ord
= ep
->ird
;
3029 ep
->ird
= conn_param
->ird
;
3030 ep
->ord
= conn_param
->ord
;
3031 send_mpa_reject(ep
, conn_param
->private_data
,
3032 conn_param
->private_data_len
);
3037 if (conn_param
->ird
< ep
->ord
) {
3038 if (RELAXED_IRD_NEGOTIATION
&&
3039 ep
->ord
<= h
->rdev
.lldi
.max_ordird_qp
) {
3040 conn_param
->ird
= ep
->ord
;
3047 ep
->ird
= conn_param
->ird
;
3048 ep
->ord
= conn_param
->ord
;
3050 if (ep
->mpa_attr
.version
== 1) {
3051 if (peer2peer
&& ep
->ird
== 0)
3055 (ep
->mpa_attr
.p2p_type
!= FW_RI_INIT_P2PTYPE_DISABLED
) &&
3056 (p2p_type
== FW_RI_INIT_P2PTYPE_READ_REQ
) && ep
->ird
== 0)
3060 pr_debug("ird %d ord %d\n", ep
->ird
, ep
->ord
);
3062 ep
->com
.cm_id
= cm_id
;
3063 ref_cm_id(&ep
->com
);
3067 /* bind QP to EP and move to RTS */
3068 attrs
.mpa_attr
= ep
->mpa_attr
;
3069 attrs
.max_ird
= ep
->ird
;
3070 attrs
.max_ord
= ep
->ord
;
3071 attrs
.llp_stream_handle
= ep
;
3072 attrs
.next_state
= C4IW_QP_STATE_RTS
;
3074 /* bind QP and TID with INIT_WR */
3075 mask
= C4IW_QP_ATTR_NEXT_STATE
|
3076 C4IW_QP_ATTR_LLP_STREAM_HANDLE
|
3077 C4IW_QP_ATTR_MPA_ATTR
|
3078 C4IW_QP_ATTR_MAX_IRD
|
3079 C4IW_QP_ATTR_MAX_ORD
;
3081 err
= c4iw_modify_qp(ep
->com
.qp
->rhp
,
3082 ep
->com
.qp
, mask
, &attrs
, 1);
3084 goto err_deref_cm_id
;
3086 set_bit(STOP_MPA_TIMER
, &ep
->com
.flags
);
3087 err
= send_mpa_reply(ep
, conn_param
->private_data
,
3088 conn_param
->private_data_len
);
3090 goto err_deref_cm_id
;
3092 __state_set(&ep
->com
, FPDU_MODE
);
3093 established_upcall(ep
);
3094 mutex_unlock(&ep
->com
.mutex
);
3095 c4iw_put_ep(&ep
->com
);
3098 deref_cm_id(&ep
->com
);
3102 mutex_unlock(&ep
->com
.mutex
);
3104 c4iw_ep_disconnect(ep
, 1, GFP_KERNEL
);
3105 c4iw_put_ep(&ep
->com
);
3109 static int pick_local_ipaddrs(struct c4iw_dev
*dev
, struct iw_cm_id
*cm_id
)
3111 struct in_device
*ind
;
3113 struct sockaddr_in
*laddr
= (struct sockaddr_in
*)&cm_id
->m_local_addr
;
3114 struct sockaddr_in
*raddr
= (struct sockaddr_in
*)&cm_id
->m_remote_addr
;
3116 ind
= in_dev_get(dev
->rdev
.lldi
.ports
[0]);
3118 return -EADDRNOTAVAIL
;
3119 for_primary_ifa(ind
) {
3120 laddr
->sin_addr
.s_addr
= ifa
->ifa_address
;
3121 raddr
->sin_addr
.s_addr
= ifa
->ifa_address
;
3127 return found
? 0 : -EADDRNOTAVAIL
;
3130 static int get_lladdr(struct net_device
*dev
, struct in6_addr
*addr
,
3131 unsigned char banned_flags
)
3133 struct inet6_dev
*idev
;
3134 int err
= -EADDRNOTAVAIL
;
3137 idev
= __in6_dev_get(dev
);
3139 struct inet6_ifaddr
*ifp
;
3141 read_lock_bh(&idev
->lock
);
3142 list_for_each_entry(ifp
, &idev
->addr_list
, if_list
) {
3143 if (ifp
->scope
== IFA_LINK
&&
3144 !(ifp
->flags
& banned_flags
)) {
3145 memcpy(addr
, &ifp
->addr
, 16);
3150 read_unlock_bh(&idev
->lock
);
3156 static int pick_local_ip6addrs(struct c4iw_dev
*dev
, struct iw_cm_id
*cm_id
)
3158 struct in6_addr
uninitialized_var(addr
);
3159 struct sockaddr_in6
*la6
= (struct sockaddr_in6
*)&cm_id
->m_local_addr
;
3160 struct sockaddr_in6
*ra6
= (struct sockaddr_in6
*)&cm_id
->m_remote_addr
;
3162 if (!get_lladdr(dev
->rdev
.lldi
.ports
[0], &addr
, IFA_F_TENTATIVE
)) {
3163 memcpy(la6
->sin6_addr
.s6_addr
, &addr
, 16);
3164 memcpy(ra6
->sin6_addr
.s6_addr
, &addr
, 16);
3167 return -EADDRNOTAVAIL
;
3170 int c4iw_connect(struct iw_cm_id
*cm_id
, struct iw_cm_conn_param
*conn_param
)
3172 struct c4iw_dev
*dev
= to_c4iw_dev(cm_id
->device
);
3175 struct sockaddr_in
*laddr
;
3176 struct sockaddr_in
*raddr
;
3177 struct sockaddr_in6
*laddr6
;
3178 struct sockaddr_in6
*raddr6
;
3182 if ((conn_param
->ord
> cur_max_read_depth(dev
)) ||
3183 (conn_param
->ird
> cur_max_read_depth(dev
))) {
3187 ep
= alloc_ep(sizeof(*ep
), GFP_KERNEL
);
3189 pr_err("%s - cannot alloc ep\n", __func__
);
3194 skb_queue_head_init(&ep
->com
.ep_skb_list
);
3195 if (alloc_ep_skb_list(&ep
->com
.ep_skb_list
, CN_MAX_CON_BUF
)) {
3200 timer_setup(&ep
->timer
, ep_timeout
, 0);
3201 ep
->plen
= conn_param
->private_data_len
;
3203 memcpy(ep
->mpa_pkt
+ sizeof(struct mpa_message
),
3204 conn_param
->private_data
, ep
->plen
);
3205 ep
->ird
= conn_param
->ird
;
3206 ep
->ord
= conn_param
->ord
;
3208 if (peer2peer
&& ep
->ord
== 0)
3211 ep
->com
.cm_id
= cm_id
;
3212 ref_cm_id(&ep
->com
);
3214 ep
->com
.qp
= get_qhp(dev
, conn_param
->qpn
);
3216 pr_warn("%s qpn 0x%x not found!\n", __func__
, conn_param
->qpn
);
3221 pr_debug("qpn 0x%x qp %p cm_id %p\n", conn_param
->qpn
,
3225 * Allocate an active TID to initiate a TCP connection.
3227 ep
->atid
= cxgb4_alloc_atid(dev
->rdev
.lldi
.tids
, ep
);
3228 if (ep
->atid
== -1) {
3229 pr_err("%s - cannot alloc atid\n", __func__
);
3233 insert_handle(dev
, &dev
->atid_idr
, ep
, ep
->atid
);
3235 memcpy(&ep
->com
.local_addr
, &cm_id
->m_local_addr
,
3236 sizeof(ep
->com
.local_addr
));
3237 memcpy(&ep
->com
.remote_addr
, &cm_id
->m_remote_addr
,
3238 sizeof(ep
->com
.remote_addr
));
3240 laddr
= (struct sockaddr_in
*)&ep
->com
.local_addr
;
3241 raddr
= (struct sockaddr_in
*)&ep
->com
.remote_addr
;
3242 laddr6
= (struct sockaddr_in6
*)&ep
->com
.local_addr
;
3243 raddr6
= (struct sockaddr_in6
*) &ep
->com
.remote_addr
;
3245 if (cm_id
->m_remote_addr
.ss_family
== AF_INET
) {
3247 ra
= (__u8
*)&raddr
->sin_addr
;
3250 * Handle loopback requests to INADDR_ANY.
3252 if (raddr
->sin_addr
.s_addr
== htonl(INADDR_ANY
)) {
3253 err
= pick_local_ipaddrs(dev
, cm_id
);
3259 pr_debug("saddr %pI4 sport 0x%x raddr %pI4 rport 0x%x\n",
3260 &laddr
->sin_addr
, ntohs(laddr
->sin_port
),
3261 ra
, ntohs(raddr
->sin_port
));
3262 ep
->dst
= cxgb_find_route(&dev
->rdev
.lldi
, get_real_dev
,
3263 laddr
->sin_addr
.s_addr
,
3264 raddr
->sin_addr
.s_addr
,
3266 raddr
->sin_port
, cm_id
->tos
);
3269 ra
= (__u8
*)&raddr6
->sin6_addr
;
3272 * Handle loopback requests to INADDR_ANY.
3274 if (ipv6_addr_type(&raddr6
->sin6_addr
) == IPV6_ADDR_ANY
) {
3275 err
= pick_local_ip6addrs(dev
, cm_id
);
3281 pr_debug("saddr %pI6 sport 0x%x raddr %pI6 rport 0x%x\n",
3282 laddr6
->sin6_addr
.s6_addr
,
3283 ntohs(laddr6
->sin6_port
),
3284 raddr6
->sin6_addr
.s6_addr
, ntohs(raddr6
->sin6_port
));
3285 ep
->dst
= cxgb_find_route6(&dev
->rdev
.lldi
, get_real_dev
,
3286 laddr6
->sin6_addr
.s6_addr
,
3287 raddr6
->sin6_addr
.s6_addr
,
3289 raddr6
->sin6_port
, 0,
3290 raddr6
->sin6_scope_id
);
3293 pr_err("%s - cannot find route\n", __func__
);
3294 err
= -EHOSTUNREACH
;
3298 err
= import_ep(ep
, iptype
, ra
, ep
->dst
, ep
->com
.dev
, true,
3299 ep
->com
.dev
->rdev
.lldi
.adapter_type
, cm_id
->tos
);
3301 pr_err("%s - cannot alloc l2e\n", __func__
);
3305 pr_debug("txq_idx %u tx_chan %u smac_idx %u rss_qid %u l2t_idx %u\n",
3306 ep
->txq_idx
, ep
->tx_chan
, ep
->smac_idx
, ep
->rss_qid
,
3309 state_set(&ep
->com
, CONNECTING
);
3310 ep
->tos
= cm_id
->tos
;
3312 /* send connect request to rnic */
3313 err
= send_connect(ep
);
3317 cxgb4_l2t_release(ep
->l2t
);
3319 dst_release(ep
->dst
);
3321 remove_handle(ep
->com
.dev
, &ep
->com
.dev
->atid_idr
, ep
->atid
);
3322 cxgb4_free_atid(ep
->com
.dev
->rdev
.lldi
.tids
, ep
->atid
);
3324 skb_queue_purge(&ep
->com
.ep_skb_list
);
3325 deref_cm_id(&ep
->com
);
3327 c4iw_put_ep(&ep
->com
);
3332 static int create_server6(struct c4iw_dev
*dev
, struct c4iw_listen_ep
*ep
)
3335 struct sockaddr_in6
*sin6
= (struct sockaddr_in6
*)
3336 &ep
->com
.local_addr
;
3338 if (ipv6_addr_type(&sin6
->sin6_addr
) != IPV6_ADDR_ANY
) {
3339 err
= cxgb4_clip_get(ep
->com
.dev
->rdev
.lldi
.ports
[0],
3340 (const u32
*)&sin6
->sin6_addr
.s6_addr
, 1);
3344 c4iw_init_wr_wait(ep
->com
.wr_waitp
);
3345 err
= cxgb4_create_server6(ep
->com
.dev
->rdev
.lldi
.ports
[0],
3346 ep
->stid
, &sin6
->sin6_addr
,
3348 ep
->com
.dev
->rdev
.lldi
.rxq_ids
[0]);
3350 err
= c4iw_wait_for_reply(&ep
->com
.dev
->rdev
,
3354 err
= net_xmit_errno(err
);
3356 cxgb4_clip_release(ep
->com
.dev
->rdev
.lldi
.ports
[0],
3357 (const u32
*)&sin6
->sin6_addr
.s6_addr
, 1);
3358 pr_err("cxgb4_create_server6/filter failed err %d stid %d laddr %pI6 lport %d\n",
3360 sin6
->sin6_addr
.s6_addr
, ntohs(sin6
->sin6_port
));
3365 static int create_server4(struct c4iw_dev
*dev
, struct c4iw_listen_ep
*ep
)
3368 struct sockaddr_in
*sin
= (struct sockaddr_in
*)
3369 &ep
->com
.local_addr
;
3371 if (dev
->rdev
.lldi
.enable_fw_ofld_conn
) {
3373 err
= cxgb4_create_server_filter(
3374 ep
->com
.dev
->rdev
.lldi
.ports
[0], ep
->stid
,
3375 sin
->sin_addr
.s_addr
, sin
->sin_port
, 0,
3376 ep
->com
.dev
->rdev
.lldi
.rxq_ids
[0], 0, 0);
3377 if (err
== -EBUSY
) {
3378 if (c4iw_fatal_error(&ep
->com
.dev
->rdev
)) {
3382 set_current_state(TASK_UNINTERRUPTIBLE
);
3383 schedule_timeout(usecs_to_jiffies(100));
3385 } while (err
== -EBUSY
);
3387 c4iw_init_wr_wait(ep
->com
.wr_waitp
);
3388 err
= cxgb4_create_server(ep
->com
.dev
->rdev
.lldi
.ports
[0],
3389 ep
->stid
, sin
->sin_addr
.s_addr
, sin
->sin_port
,
3390 0, ep
->com
.dev
->rdev
.lldi
.rxq_ids
[0]);
3392 err
= c4iw_wait_for_reply(&ep
->com
.dev
->rdev
,
3396 err
= net_xmit_errno(err
);
3399 pr_err("cxgb4_create_server/filter failed err %d stid %d laddr %pI4 lport %d\n"
3401 &sin
->sin_addr
, ntohs(sin
->sin_port
));
3405 int c4iw_create_listen(struct iw_cm_id
*cm_id
, int backlog
)
3408 struct c4iw_dev
*dev
= to_c4iw_dev(cm_id
->device
);
3409 struct c4iw_listen_ep
*ep
;
3413 ep
= alloc_ep(sizeof(*ep
), GFP_KERNEL
);
3415 pr_err("%s - cannot alloc ep\n", __func__
);
3419 skb_queue_head_init(&ep
->com
.ep_skb_list
);
3420 pr_debug("ep %p\n", ep
);
3421 ep
->com
.cm_id
= cm_id
;
3422 ref_cm_id(&ep
->com
);
3424 ep
->backlog
= backlog
;
3425 memcpy(&ep
->com
.local_addr
, &cm_id
->m_local_addr
,
3426 sizeof(ep
->com
.local_addr
));
3429 * Allocate a server TID.
3431 if (dev
->rdev
.lldi
.enable_fw_ofld_conn
&&
3432 ep
->com
.local_addr
.ss_family
== AF_INET
)
3433 ep
->stid
= cxgb4_alloc_sftid(dev
->rdev
.lldi
.tids
,
3434 cm_id
->m_local_addr
.ss_family
, ep
);
3436 ep
->stid
= cxgb4_alloc_stid(dev
->rdev
.lldi
.tids
,
3437 cm_id
->m_local_addr
.ss_family
, ep
);
3439 if (ep
->stid
== -1) {
3440 pr_err("%s - cannot alloc stid\n", __func__
);
3444 insert_handle(dev
, &dev
->stid_idr
, ep
, ep
->stid
);
3446 memcpy(&ep
->com
.local_addr
, &cm_id
->m_local_addr
,
3447 sizeof(ep
->com
.local_addr
));
3449 state_set(&ep
->com
, LISTEN
);
3450 if (ep
->com
.local_addr
.ss_family
== AF_INET
)
3451 err
= create_server4(dev
, ep
);
3453 err
= create_server6(dev
, ep
);
3455 cm_id
->provider_data
= ep
;
3458 remove_handle(ep
->com
.dev
, &ep
->com
.dev
->stid_idr
, ep
->stid
);
3459 cxgb4_free_stid(ep
->com
.dev
->rdev
.lldi
.tids
, ep
->stid
,
3460 ep
->com
.local_addr
.ss_family
);
3462 deref_cm_id(&ep
->com
);
3463 c4iw_put_ep(&ep
->com
);
3469 int c4iw_destroy_listen(struct iw_cm_id
*cm_id
)
3472 struct c4iw_listen_ep
*ep
= to_listen_ep(cm_id
);
3474 pr_debug("ep %p\n", ep
);
3477 state_set(&ep
->com
, DEAD
);
3478 if (ep
->com
.dev
->rdev
.lldi
.enable_fw_ofld_conn
&&
3479 ep
->com
.local_addr
.ss_family
== AF_INET
) {
3480 err
= cxgb4_remove_server_filter(
3481 ep
->com
.dev
->rdev
.lldi
.ports
[0], ep
->stid
,
3482 ep
->com
.dev
->rdev
.lldi
.rxq_ids
[0], 0);
3484 struct sockaddr_in6
*sin6
;
3485 c4iw_init_wr_wait(ep
->com
.wr_waitp
);
3486 err
= cxgb4_remove_server(
3487 ep
->com
.dev
->rdev
.lldi
.ports
[0], ep
->stid
,
3488 ep
->com
.dev
->rdev
.lldi
.rxq_ids
[0], 0);
3491 err
= c4iw_wait_for_reply(&ep
->com
.dev
->rdev
, ep
->com
.wr_waitp
,
3493 sin6
= (struct sockaddr_in6
*)&ep
->com
.local_addr
;
3494 cxgb4_clip_release(ep
->com
.dev
->rdev
.lldi
.ports
[0],
3495 (const u32
*)&sin6
->sin6_addr
.s6_addr
, 1);
3497 remove_handle(ep
->com
.dev
, &ep
->com
.dev
->stid_idr
, ep
->stid
);
3498 cxgb4_free_stid(ep
->com
.dev
->rdev
.lldi
.tids
, ep
->stid
,
3499 ep
->com
.local_addr
.ss_family
);
3501 deref_cm_id(&ep
->com
);
3502 c4iw_put_ep(&ep
->com
);
3506 int c4iw_ep_disconnect(struct c4iw_ep
*ep
, int abrupt
, gfp_t gfp
)
3511 struct c4iw_rdev
*rdev
;
3513 mutex_lock(&ep
->com
.mutex
);
3515 pr_debug("ep %p state %s, abrupt %d\n", ep
,
3516 states
[ep
->com
.state
], abrupt
);
3519 * Ref the ep here in case we have fatal errors causing the
3520 * ep to be released and freed.
3522 c4iw_get_ep(&ep
->com
);
3524 rdev
= &ep
->com
.dev
->rdev
;
3525 if (c4iw_fatal_error(rdev
)) {
3527 close_complete_upcall(ep
, -EIO
);
3528 ep
->com
.state
= DEAD
;
3530 switch (ep
->com
.state
) {
3539 ep
->com
.state
= ABORTING
;
3541 ep
->com
.state
= CLOSING
;
3544 * if we close before we see the fw4_ack() then we fix
3545 * up the timer state since we're reusing it.
3548 test_bit(STOP_MPA_TIMER
, &ep
->com
.flags
)) {
3549 clear_bit(STOP_MPA_TIMER
, &ep
->com
.flags
);
3554 set_bit(CLOSE_SENT
, &ep
->com
.flags
);
3557 if (!test_and_set_bit(CLOSE_SENT
, &ep
->com
.flags
)) {
3560 (void)stop_ep_timer(ep
);
3561 ep
->com
.state
= ABORTING
;
3563 ep
->com
.state
= MORIBUND
;
3569 pr_debug("ignoring disconnect ep %p state %u\n",
3573 WARN_ONCE(1, "Bad endpoint state %u\n", ep
->com
.state
);
3579 set_bit(EP_DISC_ABORT
, &ep
->com
.history
);
3580 close_complete_upcall(ep
, -ECONNRESET
);
3581 ret
= send_abort(ep
);
3583 set_bit(EP_DISC_CLOSE
, &ep
->com
.history
);
3584 ret
= send_halfclose(ep
);
3587 set_bit(EP_DISC_FAIL
, &ep
->com
.history
);
3590 close_complete_upcall(ep
, -EIO
);
3593 struct c4iw_qp_attributes attrs
;
3595 attrs
.next_state
= C4IW_QP_STATE_ERROR
;
3596 ret
= c4iw_modify_qp(ep
->com
.qp
->rhp
,
3598 C4IW_QP_ATTR_NEXT_STATE
,
3601 pr_err("%s - qp <- error failed!\n",
3607 mutex_unlock(&ep
->com
.mutex
);
3608 c4iw_put_ep(&ep
->com
);
3610 release_ep_resources(ep
);
3614 static void active_ofld_conn_reply(struct c4iw_dev
*dev
, struct sk_buff
*skb
,
3615 struct cpl_fw6_msg_ofld_connection_wr_rpl
*req
)
3618 int atid
= be32_to_cpu(req
->tid
);
3620 ep
= (struct c4iw_ep
*)lookup_atid(dev
->rdev
.lldi
.tids
,
3621 (__force u32
) req
->tid
);
3625 switch (req
->retval
) {
3627 set_bit(ACT_RETRY_NOMEM
, &ep
->com
.history
);
3628 if (ep
->retry_count
++ < ACT_OPEN_RETRY_COUNT
) {
3629 send_fw_act_open_req(ep
, atid
);
3634 set_bit(ACT_RETRY_INUSE
, &ep
->com
.history
);
3635 if (ep
->retry_count
++ < ACT_OPEN_RETRY_COUNT
) {
3636 send_fw_act_open_req(ep
, atid
);
3641 pr_info("%s unexpected ofld conn wr retval %d\n",
3642 __func__
, req
->retval
);
3645 pr_err("active ofld_connect_wr failure %d atid %d\n",
3647 mutex_lock(&dev
->rdev
.stats
.lock
);
3648 dev
->rdev
.stats
.act_ofld_conn_fails
++;
3649 mutex_unlock(&dev
->rdev
.stats
.lock
);
3650 connect_reply_upcall(ep
, status2errno(req
->retval
));
3651 state_set(&ep
->com
, DEAD
);
3652 if (ep
->com
.remote_addr
.ss_family
== AF_INET6
) {
3653 struct sockaddr_in6
*sin6
=
3654 (struct sockaddr_in6
*)&ep
->com
.local_addr
;
3655 cxgb4_clip_release(ep
->com
.dev
->rdev
.lldi
.ports
[0],
3656 (const u32
*)&sin6
->sin6_addr
.s6_addr
, 1);
3658 remove_handle(dev
, &dev
->atid_idr
, atid
);
3659 cxgb4_free_atid(dev
->rdev
.lldi
.tids
, atid
);
3660 dst_release(ep
->dst
);
3661 cxgb4_l2t_release(ep
->l2t
);
3662 c4iw_put_ep(&ep
->com
);
3665 static void passive_ofld_conn_reply(struct c4iw_dev
*dev
, struct sk_buff
*skb
,
3666 struct cpl_fw6_msg_ofld_connection_wr_rpl
*req
)
3668 struct sk_buff
*rpl_skb
;
3669 struct cpl_pass_accept_req
*cpl
;
3672 rpl_skb
= (struct sk_buff
*)(unsigned long)req
->cookie
;
3674 pr_err("%s passive open failure %d\n", __func__
, req
->retval
);
3675 mutex_lock(&dev
->rdev
.stats
.lock
);
3676 dev
->rdev
.stats
.pas_ofld_conn_fails
++;
3677 mutex_unlock(&dev
->rdev
.stats
.lock
);
3680 cpl
= (struct cpl_pass_accept_req
*)cplhdr(rpl_skb
);
3681 OPCODE_TID(cpl
) = htonl(MK_OPCODE_TID(CPL_PASS_ACCEPT_REQ
,
3682 (__force u32
) htonl(
3683 (__force u32
) req
->tid
)));
3684 ret
= pass_accept_req(dev
, rpl_skb
);
3691 static int deferred_fw6_msg(struct c4iw_dev
*dev
, struct sk_buff
*skb
)
3693 struct cpl_fw6_msg
*rpl
= cplhdr(skb
);
3694 struct cpl_fw6_msg_ofld_connection_wr_rpl
*req
;
3696 switch (rpl
->type
) {
3698 c4iw_ev_dispatch(dev
, (struct t4_cqe
*)&rpl
->data
[0]);
3700 case FW6_TYPE_OFLD_CONNECTION_WR_RPL
:
3701 req
= (struct cpl_fw6_msg_ofld_connection_wr_rpl
*)rpl
->data
;
3702 switch (req
->t_state
) {
3704 active_ofld_conn_reply(dev
, skb
, req
);
3707 passive_ofld_conn_reply(dev
, skb
, req
);
3710 pr_err("%s unexpected ofld conn wr state %d\n",
3711 __func__
, req
->t_state
);
3719 static void build_cpl_pass_accept_req(struct sk_buff
*skb
, int stid
, u8 tos
)
3722 __be16 hdr_len
, vlantag
, len
;
3724 int tcp_hdr_len
, ip_hdr_len
;
3726 struct cpl_rx_pkt
*cpl
= cplhdr(skb
);
3727 struct cpl_pass_accept_req
*req
;
3728 struct tcp_options_received tmp_opt
;
3729 struct c4iw_dev
*dev
;
3730 enum chip_type type
;
3732 dev
= *((struct c4iw_dev
**) (skb
->cb
+ sizeof(void *)));
3733 /* Store values from cpl_rx_pkt in temporary location. */
3734 vlantag
= cpl
->vlan
;
3736 l2info
= cpl
->l2info
;
3737 hdr_len
= cpl
->hdr_len
;
3740 __skb_pull(skb
, sizeof(*req
) + sizeof(struct rss_header
));
3743 * We need to parse the TCP options from SYN packet.
3744 * to generate cpl_pass_accept_req.
3746 memset(&tmp_opt
, 0, sizeof(tmp_opt
));
3747 tcp_clear_options(&tmp_opt
);
3748 tcp_parse_options(&init_net
, skb
, &tmp_opt
, 0, NULL
);
3750 req
= __skb_push(skb
, sizeof(*req
));
3751 memset(req
, 0, sizeof(*req
));
3752 req
->l2info
= cpu_to_be16(SYN_INTF_V(intf
) |
3753 SYN_MAC_IDX_V(RX_MACIDX_G(
3754 be32_to_cpu(l2info
))) |
3756 type
= dev
->rdev
.lldi
.adapter_type
;
3757 tcp_hdr_len
= RX_TCPHDR_LEN_G(be16_to_cpu(hdr_len
));
3758 ip_hdr_len
= RX_IPHDR_LEN_G(be16_to_cpu(hdr_len
));
3760 cpu_to_be32(SYN_RX_CHAN_V(RX_CHAN_G(be32_to_cpu(l2info
))));
3761 if (CHELSIO_CHIP_VERSION(type
) <= CHELSIO_T5
) {
3762 eth_hdr_len
= is_t4(type
) ?
3763 RX_ETHHDR_LEN_G(be32_to_cpu(l2info
)) :
3764 RX_T5_ETHHDR_LEN_G(be32_to_cpu(l2info
));
3765 req
->hdr_len
|= cpu_to_be32(TCP_HDR_LEN_V(tcp_hdr_len
) |
3766 IP_HDR_LEN_V(ip_hdr_len
) |
3767 ETH_HDR_LEN_V(eth_hdr_len
));
3768 } else { /* T6 and later */
3769 eth_hdr_len
= RX_T6_ETHHDR_LEN_G(be32_to_cpu(l2info
));
3770 req
->hdr_len
|= cpu_to_be32(T6_TCP_HDR_LEN_V(tcp_hdr_len
) |
3771 T6_IP_HDR_LEN_V(ip_hdr_len
) |
3772 T6_ETH_HDR_LEN_V(eth_hdr_len
));
3774 req
->vlan
= vlantag
;
3776 req
->tos_stid
= cpu_to_be32(PASS_OPEN_TID_V(stid
) |
3777 PASS_OPEN_TOS_V(tos
));
3778 req
->tcpopt
.mss
= htons(tmp_opt
.mss_clamp
);
3779 if (tmp_opt
.wscale_ok
)
3780 req
->tcpopt
.wsf
= tmp_opt
.snd_wscale
;
3781 req
->tcpopt
.tstamp
= tmp_opt
.saw_tstamp
;
3782 if (tmp_opt
.sack_ok
)
3783 req
->tcpopt
.sack
= 1;
3784 OPCODE_TID(req
) = htonl(MK_OPCODE_TID(CPL_PASS_ACCEPT_REQ
, 0));
3788 static void send_fw_pass_open_req(struct c4iw_dev
*dev
, struct sk_buff
*skb
,
3789 __be32 laddr
, __be16 lport
,
3790 __be32 raddr
, __be16 rport
,
3791 u32 rcv_isn
, u32 filter
, u16 window
,
3792 u32 rss_qid
, u8 port_id
)
3794 struct sk_buff
*req_skb
;
3795 struct fw_ofld_connection_wr
*req
;
3796 struct cpl_pass_accept_req
*cpl
= cplhdr(skb
);
3799 req_skb
= alloc_skb(sizeof(struct fw_ofld_connection_wr
), GFP_KERNEL
);
3802 req
= __skb_put_zero(req_skb
, sizeof(*req
));
3803 req
->op_compl
= htonl(WR_OP_V(FW_OFLD_CONNECTION_WR
) | FW_WR_COMPL_F
);
3804 req
->len16_pkd
= htonl(FW_WR_LEN16_V(DIV_ROUND_UP(sizeof(*req
), 16)));
3805 req
->le
.version_cpl
= htonl(FW_OFLD_CONNECTION_WR_CPL_F
);
3806 req
->le
.filter
= (__force __be32
) filter
;
3807 req
->le
.lport
= lport
;
3808 req
->le
.pport
= rport
;
3809 req
->le
.u
.ipv4
.lip
= laddr
;
3810 req
->le
.u
.ipv4
.pip
= raddr
;
3811 req
->tcb
.rcv_nxt
= htonl(rcv_isn
+ 1);
3812 req
->tcb
.rcv_adv
= htons(window
);
3813 req
->tcb
.t_state_to_astid
=
3814 htonl(FW_OFLD_CONNECTION_WR_T_STATE_V(TCP_SYN_RECV
) |
3815 FW_OFLD_CONNECTION_WR_RCV_SCALE_V(cpl
->tcpopt
.wsf
) |
3816 FW_OFLD_CONNECTION_WR_ASTID_V(
3817 PASS_OPEN_TID_G(ntohl(cpl
->tos_stid
))));
3820 * We store the qid in opt2 which will be used by the firmware
3821 * to send us the wr response.
3823 req
->tcb
.opt2
= htonl(RSS_QUEUE_V(rss_qid
));
3826 * We initialize the MSS index in TCB to 0xF.
3827 * So that when driver sends cpl_pass_accept_rpl
3828 * TCB picks up the correct value. If this was 0
3829 * TP will ignore any value > 0 for MSS index.
3831 req
->tcb
.opt0
= cpu_to_be64(MSS_IDX_V(0xF));
3832 req
->cookie
= (uintptr_t)skb
;
3834 set_wr_txq(req_skb
, CPL_PRIORITY_CONTROL
, port_id
);
3835 ret
= cxgb4_ofld_send(dev
->rdev
.lldi
.ports
[0], req_skb
);
3837 pr_err("%s - cxgb4_ofld_send error %d - dropping\n", __func__
,
3845 * Handler for CPL_RX_PKT message. Need to handle cpl_rx_pkt
3846 * messages when a filter is being used instead of server to
3847 * redirect a syn packet. When packets hit filter they are redirected
3848 * to the offload queue and driver tries to establish the connection
3849 * using firmware work request.
3851 static int rx_pkt(struct c4iw_dev
*dev
, struct sk_buff
*skb
)
3854 unsigned int filter
;
3855 struct ethhdr
*eh
= NULL
;
3856 struct vlan_ethhdr
*vlan_eh
= NULL
;
3858 struct tcphdr
*tcph
;
3859 struct rss_header
*rss
= (void *)skb
->data
;
3860 struct cpl_rx_pkt
*cpl
= (void *)skb
->data
;
3861 struct cpl_pass_accept_req
*req
= (void *)(rss
+ 1);
3862 struct l2t_entry
*e
;
3863 struct dst_entry
*dst
;
3864 struct c4iw_ep
*lep
= NULL
;
3866 struct port_info
*pi
;
3867 struct net_device
*pdev
;
3868 u16 rss_qid
, eth_hdr_len
;
3870 struct neighbour
*neigh
;
3872 /* Drop all non-SYN packets */
3873 if (!(cpl
->l2info
& cpu_to_be32(RXF_SYN_F
)))
3877 * Drop all packets which did not hit the filter.
3878 * Unlikely to happen.
3880 if (!(rss
->filter_hit
&& rss
->filter_tid
))
3884 * Calculate the server tid from filter hit index from cpl_rx_pkt.
3886 stid
= (__force
int) cpu_to_be32((__force u32
) rss
->hash_val
);
3888 lep
= (struct c4iw_ep
*)get_ep_from_stid(dev
, stid
);
3890 pr_warn("%s connect request on invalid stid %d\n",
3895 switch (CHELSIO_CHIP_VERSION(dev
->rdev
.lldi
.adapter_type
)) {
3897 eth_hdr_len
= RX_ETHHDR_LEN_G(be32_to_cpu(cpl
->l2info
));
3900 eth_hdr_len
= RX_T5_ETHHDR_LEN_G(be32_to_cpu(cpl
->l2info
));
3903 eth_hdr_len
= RX_T6_ETHHDR_LEN_G(be32_to_cpu(cpl
->l2info
));
3906 pr_err("T%d Chip is not supported\n",
3907 CHELSIO_CHIP_VERSION(dev
->rdev
.lldi
.adapter_type
));
3911 if (eth_hdr_len
== ETH_HLEN
) {
3912 eh
= (struct ethhdr
*)(req
+ 1);
3913 iph
= (struct iphdr
*)(eh
+ 1);
3915 vlan_eh
= (struct vlan_ethhdr
*)(req
+ 1);
3916 iph
= (struct iphdr
*)(vlan_eh
+ 1);
3917 skb
->vlan_tci
= ntohs(cpl
->vlan
);
3920 if (iph
->version
!= 0x4)
3923 tcph
= (struct tcphdr
*)(iph
+ 1);
3924 skb_set_network_header(skb
, (void *)iph
- (void *)rss
);
3925 skb_set_transport_header(skb
, (void *)tcph
- (void *)rss
);
3928 pr_debug("lip 0x%x lport %u pip 0x%x pport %u tos %d\n",
3929 ntohl(iph
->daddr
), ntohs(tcph
->dest
), ntohl(iph
->saddr
),
3930 ntohs(tcph
->source
), iph
->tos
);
3932 dst
= cxgb_find_route(&dev
->rdev
.lldi
, get_real_dev
,
3933 iph
->daddr
, iph
->saddr
, tcph
->dest
,
3934 tcph
->source
, iph
->tos
);
3936 pr_err("%s - failed to find dst entry!\n", __func__
);
3939 neigh
= dst_neigh_lookup_skb(dst
, skb
);
3942 pr_err("%s - failed to allocate neigh!\n", __func__
);
3946 if (neigh
->dev
->flags
& IFF_LOOPBACK
) {
3947 pdev
= ip_dev_find(&init_net
, iph
->daddr
);
3948 e
= cxgb4_l2t_get(dev
->rdev
.lldi
.l2t
, neigh
,
3950 pi
= (struct port_info
*)netdev_priv(pdev
);
3953 pdev
= get_real_dev(neigh
->dev
);
3954 e
= cxgb4_l2t_get(dev
->rdev
.lldi
.l2t
, neigh
,
3956 pi
= (struct port_info
*)netdev_priv(pdev
);
3958 neigh_release(neigh
);
3960 pr_err("%s - failed to allocate l2t entry!\n",
3965 step
= dev
->rdev
.lldi
.nrxq
/ dev
->rdev
.lldi
.nchan
;
3966 rss_qid
= dev
->rdev
.lldi
.rxq_ids
[pi
->port_id
* step
];
3967 window
= (__force u16
) htons((__force u16
)tcph
->window
);
3969 /* Calcuate filter portion for LE region. */
3970 filter
= (__force
unsigned int) cpu_to_be32(cxgb4_select_ntuple(
3971 dev
->rdev
.lldi
.ports
[0],
3975 * Synthesize the cpl_pass_accept_req. We have everything except the
3976 * TID. Once firmware sends a reply with TID we update the TID field
3977 * in cpl and pass it through the regular cpl_pass_accept_req path.
3979 build_cpl_pass_accept_req(skb
, stid
, iph
->tos
);
3980 send_fw_pass_open_req(dev
, skb
, iph
->daddr
, tcph
->dest
, iph
->saddr
,
3981 tcph
->source
, ntohl(tcph
->seq
), filter
, window
,
3982 rss_qid
, pi
->port_id
);
3983 cxgb4_l2t_release(e
);
3988 c4iw_put_ep(&lep
->com
);
3993 * These are the real handlers that are called from a
3996 static c4iw_handler_func work_handlers
[NUM_CPL_CMDS
+ NUM_FAKE_CPLS
] = {
3997 [CPL_ACT_ESTABLISH
] = act_establish
,
3998 [CPL_ACT_OPEN_RPL
] = act_open_rpl
,
3999 [CPL_RX_DATA
] = rx_data
,
4000 [CPL_ABORT_RPL_RSS
] = abort_rpl
,
4001 [CPL_ABORT_RPL
] = abort_rpl
,
4002 [CPL_PASS_OPEN_RPL
] = pass_open_rpl
,
4003 [CPL_CLOSE_LISTSRV_RPL
] = close_listsrv_rpl
,
4004 [CPL_PASS_ACCEPT_REQ
] = pass_accept_req
,
4005 [CPL_PASS_ESTABLISH
] = pass_establish
,
4006 [CPL_PEER_CLOSE
] = peer_close
,
4007 [CPL_ABORT_REQ_RSS
] = peer_abort
,
4008 [CPL_CLOSE_CON_RPL
] = close_con_rpl
,
4009 [CPL_RDMA_TERMINATE
] = terminate
,
4010 [CPL_FW4_ACK
] = fw4_ack
,
4011 [CPL_FW6_MSG
] = deferred_fw6_msg
,
4012 [CPL_RX_PKT
] = rx_pkt
,
4013 [FAKE_CPL_PUT_EP_SAFE
] = _put_ep_safe
,
4014 [FAKE_CPL_PASS_PUT_EP_SAFE
] = _put_pass_ep_safe
4017 static void process_timeout(struct c4iw_ep
*ep
)
4019 struct c4iw_qp_attributes attrs
;
4022 mutex_lock(&ep
->com
.mutex
);
4023 pr_debug("ep %p tid %u state %d\n", ep
, ep
->hwtid
, ep
->com
.state
);
4024 set_bit(TIMEDOUT
, &ep
->com
.history
);
4025 switch (ep
->com
.state
) {
4027 connect_reply_upcall(ep
, -ETIMEDOUT
);
4036 if (ep
->com
.cm_id
&& ep
->com
.qp
) {
4037 attrs
.next_state
= C4IW_QP_STATE_ERROR
;
4038 c4iw_modify_qp(ep
->com
.qp
->rhp
,
4039 ep
->com
.qp
, C4IW_QP_ATTR_NEXT_STATE
,
4042 close_complete_upcall(ep
, -ETIMEDOUT
);
4048 * These states are expected if the ep timed out at the same
4049 * time as another thread was calling stop_ep_timer().
4050 * So we silently do nothing for these states.
4055 WARN(1, "%s unexpected state ep %p tid %u state %u\n",
4056 __func__
, ep
, ep
->hwtid
, ep
->com
.state
);
4059 mutex_unlock(&ep
->com
.mutex
);
4061 c4iw_ep_disconnect(ep
, 1, GFP_KERNEL
);
4062 c4iw_put_ep(&ep
->com
);
4065 static void process_timedout_eps(void)
4069 spin_lock_irq(&timeout_lock
);
4070 while (!list_empty(&timeout_list
)) {
4071 struct list_head
*tmp
;
4073 tmp
= timeout_list
.next
;
4077 spin_unlock_irq(&timeout_lock
);
4078 ep
= list_entry(tmp
, struct c4iw_ep
, entry
);
4079 process_timeout(ep
);
4080 spin_lock_irq(&timeout_lock
);
4082 spin_unlock_irq(&timeout_lock
);
4085 static void process_work(struct work_struct
*work
)
4087 struct sk_buff
*skb
= NULL
;
4088 struct c4iw_dev
*dev
;
4089 struct cpl_act_establish
*rpl
;
4090 unsigned int opcode
;
4093 process_timedout_eps();
4094 while ((skb
= skb_dequeue(&rxq
))) {
4096 dev
= *((struct c4iw_dev
**) (skb
->cb
+ sizeof(void *)));
4097 opcode
= rpl
->ot
.opcode
;
4099 if (opcode
>= ARRAY_SIZE(work_handlers
) ||
4100 !work_handlers
[opcode
]) {
4101 pr_err("No handler for opcode 0x%x.\n", opcode
);
4104 ret
= work_handlers
[opcode
](dev
, skb
);
4108 process_timedout_eps();
4112 static DECLARE_WORK(skb_work
, process_work
);
4114 static void ep_timeout(struct timer_list
*t
)
4116 struct c4iw_ep
*ep
= from_timer(ep
, t
, timer
);
4119 spin_lock(&timeout_lock
);
4120 if (!test_and_set_bit(TIMEOUT
, &ep
->com
.flags
)) {
4122 * Only insert if it is not already on the list.
4124 if (!ep
->entry
.next
) {
4125 list_add_tail(&ep
->entry
, &timeout_list
);
4129 spin_unlock(&timeout_lock
);
4131 queue_work(workq
, &skb_work
);
4135 * All the CM events are handled on a work queue to have a safe context.
4137 static int sched(struct c4iw_dev
*dev
, struct sk_buff
*skb
)
4141 * Save dev in the skb->cb area.
4143 *((struct c4iw_dev
**) (skb
->cb
+ sizeof(void *))) = dev
;
4146 * Queue the skb and schedule the worker thread.
4148 skb_queue_tail(&rxq
, skb
);
4149 queue_work(workq
, &skb_work
);
4153 static int set_tcb_rpl(struct c4iw_dev
*dev
, struct sk_buff
*skb
)
4155 struct cpl_set_tcb_rpl
*rpl
= cplhdr(skb
);
4157 if (rpl
->status
!= CPL_ERR_NONE
) {
4158 pr_err("Unexpected SET_TCB_RPL status %u for tid %u\n",
4159 rpl
->status
, GET_TID(rpl
));
4165 static int fw6_msg(struct c4iw_dev
*dev
, struct sk_buff
*skb
)
4167 struct cpl_fw6_msg
*rpl
= cplhdr(skb
);
4168 struct c4iw_wr_wait
*wr_waitp
;
4171 pr_debug("type %u\n", rpl
->type
);
4173 switch (rpl
->type
) {
4174 case FW6_TYPE_WR_RPL
:
4175 ret
= (int)((be64_to_cpu(rpl
->data
[0]) >> 8) & 0xff);
4176 wr_waitp
= (struct c4iw_wr_wait
*)(__force
unsigned long) rpl
->data
[1];
4177 pr_debug("wr_waitp %p ret %u\n", wr_waitp
, ret
);
4179 c4iw_wake_up_deref(wr_waitp
, ret
? -ret
: 0);
4183 case FW6_TYPE_OFLD_CONNECTION_WR_RPL
:
4187 pr_err("%s unexpected fw6 msg type %u\n",
4188 __func__
, rpl
->type
);
4195 static int peer_abort_intr(struct c4iw_dev
*dev
, struct sk_buff
*skb
)
4197 struct cpl_abort_req_rss
*req
= cplhdr(skb
);
4199 unsigned int tid
= GET_TID(req
);
4201 ep
= get_ep_from_tid(dev
, tid
);
4202 /* This EP will be dereferenced in peer_abort() */
4204 pr_warn("Abort on non-existent endpoint, tid %d\n", tid
);
4208 if (cxgb_is_neg_adv(req
->status
)) {
4209 pr_debug("Negative advice on abort- tid %u status %d (%s)\n",
4210 ep
->hwtid
, req
->status
,
4211 neg_adv_str(req
->status
));
4214 pr_debug("ep %p tid %u state %u\n", ep
, ep
->hwtid
, ep
->com
.state
);
4216 c4iw_wake_up_noref(ep
->com
.wr_waitp
, -ECONNRESET
);
4223 * Most upcalls from the T4 Core go to sched() to
4224 * schedule the processing on a work queue.
4226 c4iw_handler_func c4iw_handlers
[NUM_CPL_CMDS
] = {
4227 [CPL_ACT_ESTABLISH
] = sched
,
4228 [CPL_ACT_OPEN_RPL
] = sched
,
4229 [CPL_RX_DATA
] = sched
,
4230 [CPL_ABORT_RPL_RSS
] = sched
,
4231 [CPL_ABORT_RPL
] = sched
,
4232 [CPL_PASS_OPEN_RPL
] = sched
,
4233 [CPL_CLOSE_LISTSRV_RPL
] = sched
,
4234 [CPL_PASS_ACCEPT_REQ
] = sched
,
4235 [CPL_PASS_ESTABLISH
] = sched
,
4236 [CPL_PEER_CLOSE
] = sched
,
4237 [CPL_CLOSE_CON_RPL
] = sched
,
4238 [CPL_ABORT_REQ_RSS
] = peer_abort_intr
,
4239 [CPL_RDMA_TERMINATE
] = sched
,
4240 [CPL_FW4_ACK
] = sched
,
4241 [CPL_SET_TCB_RPL
] = set_tcb_rpl
,
4242 [CPL_FW6_MSG
] = fw6_msg
,
4243 [CPL_RX_PKT
] = sched
4246 int __init
c4iw_cm_init(void)
4248 spin_lock_init(&timeout_lock
);
4249 skb_queue_head_init(&rxq
);
4251 workq
= alloc_ordered_workqueue("iw_cxgb4", WQ_MEM_RECLAIM
);
4258 void c4iw_cm_term(void)
4260 WARN_ON(!list_empty(&timeout_list
));
4261 flush_workqueue(workq
);
4262 destroy_workqueue(workq
);