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)");
103 module_param(c4iw_debug
, int, 0644);
104 MODULE_PARM_DESC(c4iw_debug
, "Enable debug logging (default=0)");
106 static int peer2peer
= 1;
107 module_param(peer2peer
, int, 0644);
108 MODULE_PARM_DESC(peer2peer
, "Support peer2peer ULPs (default=1)");
110 static int p2p_type
= FW_RI_INIT_P2PTYPE_READ_REQ
;
111 module_param(p2p_type
, int, 0644);
112 MODULE_PARM_DESC(p2p_type
, "RDMAP opcode to use for the RTR message: "
113 "1=RDMA_READ 0=RDMA_WRITE (default 1)");
115 static int ep_timeout_secs
= 60;
116 module_param(ep_timeout_secs
, int, 0644);
117 MODULE_PARM_DESC(ep_timeout_secs
, "CM Endpoint operation timeout "
118 "in seconds (default=60)");
120 static int mpa_rev
= 2;
121 module_param(mpa_rev
, int, 0644);
122 MODULE_PARM_DESC(mpa_rev
, "MPA Revision, 0 supports amso1100, "
123 "1 is RFC5044 spec compliant, 2 is IETF MPA Peer Connect Draft"
124 " compliant (default=2)");
126 static int markers_enabled
;
127 module_param(markers_enabled
, int, 0644);
128 MODULE_PARM_DESC(markers_enabled
, "Enable MPA MARKERS (default(0)=disabled)");
130 static int crc_enabled
= 1;
131 module_param(crc_enabled
, int, 0644);
132 MODULE_PARM_DESC(crc_enabled
, "Enable MPA CRC (default(1)=enabled)");
134 static int rcv_win
= 256 * 1024;
135 module_param(rcv_win
, int, 0644);
136 MODULE_PARM_DESC(rcv_win
, "TCP receive window in bytes (default=256KB)");
138 static int snd_win
= 128 * 1024;
139 module_param(snd_win
, int, 0644);
140 MODULE_PARM_DESC(snd_win
, "TCP send window in bytes (default=128KB)");
142 static struct workqueue_struct
*workq
;
144 static struct sk_buff_head rxq
;
146 static struct sk_buff
*get_skb(struct sk_buff
*skb
, int len
, gfp_t gfp
);
147 static void ep_timeout(unsigned long arg
);
148 static void connect_reply_upcall(struct c4iw_ep
*ep
, int status
);
149 static int sched(struct c4iw_dev
*dev
, struct sk_buff
*skb
);
151 static LIST_HEAD(timeout_list
);
152 static spinlock_t timeout_lock
;
154 static void deref_cm_id(struct c4iw_ep_common
*epc
)
156 epc
->cm_id
->rem_ref(epc
->cm_id
);
158 set_bit(CM_ID_DEREFED
, &epc
->history
);
161 static void ref_cm_id(struct c4iw_ep_common
*epc
)
163 set_bit(CM_ID_REFED
, &epc
->history
);
164 epc
->cm_id
->add_ref(epc
->cm_id
);
167 static void deref_qp(struct c4iw_ep
*ep
)
169 c4iw_qp_rem_ref(&ep
->com
.qp
->ibqp
);
170 clear_bit(QP_REFERENCED
, &ep
->com
.flags
);
171 set_bit(QP_DEREFED
, &ep
->com
.history
);
174 static void ref_qp(struct c4iw_ep
*ep
)
176 set_bit(QP_REFERENCED
, &ep
->com
.flags
);
177 set_bit(QP_REFED
, &ep
->com
.history
);
178 c4iw_qp_add_ref(&ep
->com
.qp
->ibqp
);
181 static void start_ep_timer(struct c4iw_ep
*ep
)
183 PDBG("%s ep %p\n", __func__
, ep
);
184 if (timer_pending(&ep
->timer
)) {
185 pr_err("%s timer already started! ep %p\n",
189 clear_bit(TIMEOUT
, &ep
->com
.flags
);
190 c4iw_get_ep(&ep
->com
);
191 ep
->timer
.expires
= jiffies
+ ep_timeout_secs
* HZ
;
192 ep
->timer
.data
= (unsigned long)ep
;
193 ep
->timer
.function
= ep_timeout
;
194 add_timer(&ep
->timer
);
197 static int stop_ep_timer(struct c4iw_ep
*ep
)
199 PDBG("%s ep %p stopping\n", __func__
, ep
);
200 del_timer_sync(&ep
->timer
);
201 if (!test_and_set_bit(TIMEOUT
, &ep
->com
.flags
)) {
202 c4iw_put_ep(&ep
->com
);
208 static int c4iw_l2t_send(struct c4iw_rdev
*rdev
, struct sk_buff
*skb
,
209 struct l2t_entry
*l2e
)
213 if (c4iw_fatal_error(rdev
)) {
215 PDBG("%s - device in error state - dropping\n", __func__
);
218 error
= cxgb4_l2t_send(rdev
->lldi
.ports
[0], skb
, l2e
);
221 else if (error
== NET_XMIT_DROP
)
223 return error
< 0 ? error
: 0;
226 int c4iw_ofld_send(struct c4iw_rdev
*rdev
, struct sk_buff
*skb
)
230 if (c4iw_fatal_error(rdev
)) {
232 PDBG("%s - device in error state - dropping\n", __func__
);
235 error
= cxgb4_ofld_send(rdev
->lldi
.ports
[0], skb
);
238 return error
< 0 ? error
: 0;
241 static void release_tid(struct c4iw_rdev
*rdev
, u32 hwtid
, struct sk_buff
*skb
)
243 struct cpl_tid_release
*req
;
245 skb
= get_skb(skb
, sizeof *req
, GFP_KERNEL
);
248 req
= (struct cpl_tid_release
*) skb_put(skb
, sizeof(*req
));
249 INIT_TP_WR(req
, hwtid
);
250 OPCODE_TID(req
) = cpu_to_be32(MK_OPCODE_TID(CPL_TID_RELEASE
, hwtid
));
251 set_wr_txq(skb
, CPL_PRIORITY_SETUP
, 0);
252 c4iw_ofld_send(rdev
, skb
);
256 static void set_emss(struct c4iw_ep
*ep
, u16 opt
)
258 ep
->emss
= ep
->com
.dev
->rdev
.lldi
.mtus
[TCPOPT_MSS_G(opt
)] -
259 ((AF_INET
== ep
->com
.remote_addr
.ss_family
) ?
260 sizeof(struct iphdr
) : sizeof(struct ipv6hdr
)) -
261 sizeof(struct tcphdr
);
263 if (TCPOPT_TSTAMP_G(opt
))
264 ep
->emss
-= round_up(TCPOLEN_TIMESTAMP
, 4);
268 PDBG("Warning: misaligned mtu idx %u mss %u emss=%u\n",
269 TCPOPT_MSS_G(opt
), ep
->mss
, ep
->emss
);
270 PDBG("%s mss_idx %u mss %u emss=%u\n", __func__
, TCPOPT_MSS_G(opt
),
274 static enum c4iw_ep_state
state_read(struct c4iw_ep_common
*epc
)
276 enum c4iw_ep_state state
;
278 mutex_lock(&epc
->mutex
);
280 mutex_unlock(&epc
->mutex
);
284 static void __state_set(struct c4iw_ep_common
*epc
, enum c4iw_ep_state
new)
289 static void state_set(struct c4iw_ep_common
*epc
, enum c4iw_ep_state
new)
291 mutex_lock(&epc
->mutex
);
292 PDBG("%s - %s -> %s\n", __func__
, states
[epc
->state
], states
[new]);
293 __state_set(epc
, new);
294 mutex_unlock(&epc
->mutex
);
298 static int alloc_ep_skb_list(struct sk_buff_head
*ep_skb_list
, int size
)
304 len
= roundup(sizeof(union cpl_wr_size
), 16);
305 for (i
= 0; i
< size
; i
++) {
306 skb
= alloc_skb(len
, GFP_KERNEL
);
309 skb_queue_tail(ep_skb_list
, skb
);
313 skb_queue_purge(ep_skb_list
);
317 static void *alloc_ep(int size
, gfp_t gfp
)
319 struct c4iw_ep_common
*epc
;
321 epc
= kzalloc(size
, gfp
);
323 kref_init(&epc
->kref
);
324 mutex_init(&epc
->mutex
);
325 c4iw_init_wr_wait(&epc
->wr_wait
);
327 PDBG("%s alloc ep %p\n", __func__
, epc
);
331 static void remove_ep_tid(struct c4iw_ep
*ep
)
335 spin_lock_irqsave(&ep
->com
.dev
->lock
, flags
);
336 _remove_handle(ep
->com
.dev
, &ep
->com
.dev
->hwtid_idr
, ep
->hwtid
, 0);
337 spin_unlock_irqrestore(&ep
->com
.dev
->lock
, flags
);
340 static void insert_ep_tid(struct c4iw_ep
*ep
)
344 spin_lock_irqsave(&ep
->com
.dev
->lock
, flags
);
345 _insert_handle(ep
->com
.dev
, &ep
->com
.dev
->hwtid_idr
, ep
, ep
->hwtid
, 0);
346 spin_unlock_irqrestore(&ep
->com
.dev
->lock
, flags
);
350 * Atomically lookup the ep ptr given the tid and grab a reference on the ep.
352 static struct c4iw_ep
*get_ep_from_tid(struct c4iw_dev
*dev
, unsigned int tid
)
357 spin_lock_irqsave(&dev
->lock
, flags
);
358 ep
= idr_find(&dev
->hwtid_idr
, tid
);
360 c4iw_get_ep(&ep
->com
);
361 spin_unlock_irqrestore(&dev
->lock
, flags
);
366 * Atomically lookup the ep ptr given the stid and grab a reference on the ep.
368 static struct c4iw_listen_ep
*get_ep_from_stid(struct c4iw_dev
*dev
,
371 struct c4iw_listen_ep
*ep
;
374 spin_lock_irqsave(&dev
->lock
, flags
);
375 ep
= idr_find(&dev
->stid_idr
, stid
);
377 c4iw_get_ep(&ep
->com
);
378 spin_unlock_irqrestore(&dev
->lock
, flags
);
382 void _c4iw_free_ep(struct kref
*kref
)
386 ep
= container_of(kref
, struct c4iw_ep
, com
.kref
);
387 PDBG("%s ep %p state %s\n", __func__
, ep
, states
[ep
->com
.state
]);
388 if (test_bit(QP_REFERENCED
, &ep
->com
.flags
))
390 if (test_bit(RELEASE_RESOURCES
, &ep
->com
.flags
)) {
391 if (ep
->com
.remote_addr
.ss_family
== AF_INET6
) {
392 struct sockaddr_in6
*sin6
=
393 (struct sockaddr_in6
*)
397 ep
->com
.dev
->rdev
.lldi
.ports
[0],
398 (const u32
*)&sin6
->sin6_addr
.s6_addr
,
401 cxgb4_remove_tid(ep
->com
.dev
->rdev
.lldi
.tids
, 0, ep
->hwtid
);
402 dst_release(ep
->dst
);
403 cxgb4_l2t_release(ep
->l2t
);
405 kfree_skb(ep
->mpa_skb
);
407 if (!skb_queue_empty(&ep
->com
.ep_skb_list
))
408 skb_queue_purge(&ep
->com
.ep_skb_list
);
412 static void release_ep_resources(struct c4iw_ep
*ep
)
414 set_bit(RELEASE_RESOURCES
, &ep
->com
.flags
);
417 * If we have a hwtid, then remove it from the idr table
418 * so lookups will no longer find this endpoint. Otherwise
419 * we have a race where one thread finds the ep ptr just
420 * before the other thread is freeing the ep memory.
424 c4iw_put_ep(&ep
->com
);
427 static int status2errno(int status
)
432 case CPL_ERR_CONN_RESET
:
434 case CPL_ERR_ARP_MISS
:
435 return -EHOSTUNREACH
;
436 case CPL_ERR_CONN_TIMEDOUT
:
438 case CPL_ERR_TCAM_FULL
:
440 case CPL_ERR_CONN_EXIST
:
448 * Try and reuse skbs already allocated...
450 static struct sk_buff
*get_skb(struct sk_buff
*skb
, int len
, gfp_t gfp
)
452 if (skb
&& !skb_is_nonlinear(skb
) && !skb_cloned(skb
)) {
455 skb_reset_transport_header(skb
);
457 skb
= alloc_skb(len
, gfp
);
459 t4_set_arp_err_handler(skb
, NULL
, NULL
);
463 static struct net_device
*get_real_dev(struct net_device
*egress_dev
)
465 return rdma_vlan_dev_real_dev(egress_dev
) ? : egress_dev
;
468 static int our_interface(struct c4iw_dev
*dev
, struct net_device
*egress_dev
)
472 egress_dev
= get_real_dev(egress_dev
);
473 for (i
= 0; i
< dev
->rdev
.lldi
.nports
; i
++)
474 if (dev
->rdev
.lldi
.ports
[i
] == egress_dev
)
479 static struct dst_entry
*find_route6(struct c4iw_dev
*dev
, __u8
*local_ip
,
480 __u8
*peer_ip
, __be16 local_port
,
481 __be16 peer_port
, u8 tos
,
484 struct dst_entry
*dst
= NULL
;
486 if (IS_ENABLED(CONFIG_IPV6
)) {
489 memset(&fl6
, 0, sizeof(fl6
));
490 memcpy(&fl6
.daddr
, peer_ip
, 16);
491 memcpy(&fl6
.saddr
, local_ip
, 16);
492 if (ipv6_addr_type(&fl6
.daddr
) & IPV6_ADDR_LINKLOCAL
)
493 fl6
.flowi6_oif
= sin6_scope_id
;
494 dst
= ip6_route_output(&init_net
, NULL
, &fl6
);
497 if (!our_interface(dev
, ip6_dst_idev(dst
)->dev
) &&
498 !(ip6_dst_idev(dst
)->dev
->flags
& IFF_LOOPBACK
)) {
508 static struct dst_entry
*find_route(struct c4iw_dev
*dev
, __be32 local_ip
,
509 __be32 peer_ip
, __be16 local_port
,
510 __be16 peer_port
, u8 tos
)
516 rt
= ip_route_output_ports(&init_net
, &fl4
, NULL
, peer_ip
, local_ip
,
517 peer_port
, local_port
, IPPROTO_TCP
,
521 n
= dst_neigh_lookup(&rt
->dst
, &peer_ip
);
524 if (!our_interface(dev
, n
->dev
) &&
525 !(n
->dev
->flags
& IFF_LOOPBACK
)) {
527 dst_release(&rt
->dst
);
534 static void arp_failure_discard(void *handle
, struct sk_buff
*skb
)
536 pr_err(MOD
"ARP failure\n");
540 static void mpa_start_arp_failure(void *handle
, struct sk_buff
*skb
)
542 pr_err("ARP failure during MPA Negotiation - Closing Connection\n");
547 FAKE_CPL_PUT_EP_SAFE
= NUM_CPL_CMDS
+ 0,
548 FAKE_CPL_PASS_PUT_EP_SAFE
= NUM_CPL_CMDS
+ 1,
551 static int _put_ep_safe(struct c4iw_dev
*dev
, struct sk_buff
*skb
)
555 ep
= *((struct c4iw_ep
**)(skb
->cb
+ 2 * sizeof(void *)));
556 release_ep_resources(ep
);
560 static int _put_pass_ep_safe(struct c4iw_dev
*dev
, struct sk_buff
*skb
)
564 ep
= *((struct c4iw_ep
**)(skb
->cb
+ 2 * sizeof(void *)));
565 c4iw_put_ep(&ep
->parent_ep
->com
);
566 release_ep_resources(ep
);
571 * Fake up a special CPL opcode and call sched() so process_work() will call
572 * _put_ep_safe() in a safe context to free the ep resources. This is needed
573 * because ARP error handlers are called in an ATOMIC context, and
574 * _c4iw_free_ep() needs to block.
576 static void queue_arp_failure_cpl(struct c4iw_ep
*ep
, struct sk_buff
*skb
,
579 struct cpl_act_establish
*rpl
= cplhdr(skb
);
581 /* Set our special ARP_FAILURE opcode */
582 rpl
->ot
.opcode
= cpl
;
585 * Save ep in the skb->cb area, after where sched() will save the dev
588 *((struct c4iw_ep
**)(skb
->cb
+ 2 * sizeof(void *))) = ep
;
589 sched(ep
->com
.dev
, skb
);
592 /* Handle an ARP failure for an accept */
593 static void pass_accept_rpl_arp_failure(void *handle
, struct sk_buff
*skb
)
595 struct c4iw_ep
*ep
= handle
;
597 pr_err(MOD
"ARP failure during accept - tid %u -dropping connection\n",
600 __state_set(&ep
->com
, DEAD
);
601 queue_arp_failure_cpl(ep
, skb
, FAKE_CPL_PASS_PUT_EP_SAFE
);
605 * Handle an ARP failure for an active open.
607 static void act_open_req_arp_failure(void *handle
, struct sk_buff
*skb
)
609 struct c4iw_ep
*ep
= handle
;
611 printk(KERN_ERR MOD
"ARP failure during connect\n");
612 connect_reply_upcall(ep
, -EHOSTUNREACH
);
613 __state_set(&ep
->com
, DEAD
);
614 if (ep
->com
.remote_addr
.ss_family
== AF_INET6
) {
615 struct sockaddr_in6
*sin6
=
616 (struct sockaddr_in6
*)&ep
->com
.local_addr
;
617 cxgb4_clip_release(ep
->com
.dev
->rdev
.lldi
.ports
[0],
618 (const u32
*)&sin6
->sin6_addr
.s6_addr
, 1);
620 remove_handle(ep
->com
.dev
, &ep
->com
.dev
->atid_idr
, ep
->atid
);
621 cxgb4_free_atid(ep
->com
.dev
->rdev
.lldi
.tids
, ep
->atid
);
622 queue_arp_failure_cpl(ep
, skb
, FAKE_CPL_PUT_EP_SAFE
);
626 * Handle an ARP failure for a CPL_ABORT_REQ. Change it into a no RST variant
629 static void abort_arp_failure(void *handle
, struct sk_buff
*skb
)
632 struct c4iw_ep
*ep
= handle
;
633 struct c4iw_rdev
*rdev
= &ep
->com
.dev
->rdev
;
634 struct cpl_abort_req
*req
= cplhdr(skb
);
636 PDBG("%s rdev %p\n", __func__
, rdev
);
637 req
->cmd
= CPL_ABORT_NO_RST
;
638 ret
= c4iw_ofld_send(rdev
, skb
);
640 __state_set(&ep
->com
, DEAD
);
641 queue_arp_failure_cpl(ep
, skb
, FAKE_CPL_PUT_EP_SAFE
);
645 static int send_flowc(struct c4iw_ep
*ep
)
647 struct fw_flowc_wr
*flowc
;
648 struct sk_buff
*skb
= skb_dequeue(&ep
->com
.ep_skb_list
);
650 u16 vlan
= ep
->l2t
->vlan
;
656 if (vlan
== CPL_L2T_VLAN_NONE
)
661 flowc
= (struct fw_flowc_wr
*)__skb_put(skb
, FLOWC_LEN
);
663 flowc
->op_to_nparams
= cpu_to_be32(FW_WR_OP_V(FW_FLOWC_WR
) |
664 FW_FLOWC_WR_NPARAMS_V(nparams
));
665 flowc
->flowid_len16
= cpu_to_be32(FW_WR_LEN16_V(DIV_ROUND_UP(FLOWC_LEN
,
666 16)) | FW_WR_FLOWID_V(ep
->hwtid
));
668 flowc
->mnemval
[0].mnemonic
= FW_FLOWC_MNEM_PFNVFN
;
669 flowc
->mnemval
[0].val
= cpu_to_be32(FW_PFVF_CMD_PFN_V
670 (ep
->com
.dev
->rdev
.lldi
.pf
));
671 flowc
->mnemval
[1].mnemonic
= FW_FLOWC_MNEM_CH
;
672 flowc
->mnemval
[1].val
= cpu_to_be32(ep
->tx_chan
);
673 flowc
->mnemval
[2].mnemonic
= FW_FLOWC_MNEM_PORT
;
674 flowc
->mnemval
[2].val
= cpu_to_be32(ep
->tx_chan
);
675 flowc
->mnemval
[3].mnemonic
= FW_FLOWC_MNEM_IQID
;
676 flowc
->mnemval
[3].val
= cpu_to_be32(ep
->rss_qid
);
677 flowc
->mnemval
[4].mnemonic
= FW_FLOWC_MNEM_SNDNXT
;
678 flowc
->mnemval
[4].val
= cpu_to_be32(ep
->snd_seq
);
679 flowc
->mnemval
[5].mnemonic
= FW_FLOWC_MNEM_RCVNXT
;
680 flowc
->mnemval
[5].val
= cpu_to_be32(ep
->rcv_seq
);
681 flowc
->mnemval
[6].mnemonic
= FW_FLOWC_MNEM_SNDBUF
;
682 flowc
->mnemval
[6].val
= cpu_to_be32(ep
->snd_win
);
683 flowc
->mnemval
[7].mnemonic
= FW_FLOWC_MNEM_MSS
;
684 flowc
->mnemval
[7].val
= cpu_to_be32(ep
->emss
);
688 pri
= (vlan
& VLAN_PRIO_MASK
) >> VLAN_PRIO_SHIFT
;
689 flowc
->mnemval
[8].mnemonic
= FW_FLOWC_MNEM_SCHEDCLASS
;
690 flowc
->mnemval
[8].val
= cpu_to_be32(pri
);
692 /* Pad WR to 16 byte boundary */
693 flowc
->mnemval
[8].mnemonic
= 0;
694 flowc
->mnemval
[8].val
= 0;
696 for (i
= 0; i
< 9; i
++) {
697 flowc
->mnemval
[i
].r4
[0] = 0;
698 flowc
->mnemval
[i
].r4
[1] = 0;
699 flowc
->mnemval
[i
].r4
[2] = 0;
702 set_wr_txq(skb
, CPL_PRIORITY_DATA
, ep
->txq_idx
);
703 return c4iw_ofld_send(&ep
->com
.dev
->rdev
, skb
);
706 static int send_halfclose(struct c4iw_ep
*ep
)
708 struct cpl_close_con_req
*req
;
709 struct sk_buff
*skb
= skb_dequeue(&ep
->com
.ep_skb_list
);
710 int wrlen
= roundup(sizeof *req
, 16);
712 PDBG("%s ep %p tid %u\n", __func__
, ep
, ep
->hwtid
);
716 set_wr_txq(skb
, CPL_PRIORITY_DATA
, ep
->txq_idx
);
717 t4_set_arp_err_handler(skb
, NULL
, arp_failure_discard
);
718 req
= (struct cpl_close_con_req
*) skb_put(skb
, wrlen
);
719 memset(req
, 0, wrlen
);
720 INIT_TP_WR(req
, ep
->hwtid
);
721 OPCODE_TID(req
) = cpu_to_be32(MK_OPCODE_TID(CPL_CLOSE_CON_REQ
,
723 return c4iw_l2t_send(&ep
->com
.dev
->rdev
, skb
, ep
->l2t
);
726 static int send_abort(struct c4iw_ep
*ep
)
728 struct cpl_abort_req
*req
;
729 int wrlen
= roundup(sizeof *req
, 16);
730 struct sk_buff
*req_skb
= skb_dequeue(&ep
->com
.ep_skb_list
);
732 PDBG("%s ep %p tid %u\n", __func__
, ep
, ep
->hwtid
);
733 if (WARN_ON(!req_skb
))
736 set_wr_txq(req_skb
, CPL_PRIORITY_DATA
, ep
->txq_idx
);
737 t4_set_arp_err_handler(req_skb
, ep
, abort_arp_failure
);
738 req
= (struct cpl_abort_req
*)skb_put(req_skb
, wrlen
);
739 memset(req
, 0, wrlen
);
740 INIT_TP_WR(req
, ep
->hwtid
);
741 OPCODE_TID(req
) = cpu_to_be32(MK_OPCODE_TID(CPL_ABORT_REQ
, ep
->hwtid
));
742 req
->cmd
= CPL_ABORT_SEND_RST
;
743 return c4iw_l2t_send(&ep
->com
.dev
->rdev
, req_skb
, ep
->l2t
);
746 static void best_mtu(const unsigned short *mtus
, unsigned short mtu
,
747 unsigned int *idx
, int use_ts
, int ipv6
)
749 unsigned short hdr_size
= (ipv6
?
750 sizeof(struct ipv6hdr
) :
751 sizeof(struct iphdr
)) +
752 sizeof(struct tcphdr
) +
754 round_up(TCPOLEN_TIMESTAMP
, 4) : 0);
755 unsigned short data_size
= mtu
- hdr_size
;
757 cxgb4_best_aligned_mtu(mtus
, hdr_size
, data_size
, 8, idx
);
760 static int send_connect(struct c4iw_ep
*ep
)
762 struct cpl_act_open_req
*req
= NULL
;
763 struct cpl_t5_act_open_req
*t5req
= NULL
;
764 struct cpl_t6_act_open_req
*t6req
= NULL
;
765 struct cpl_act_open_req6
*req6
= NULL
;
766 struct cpl_t5_act_open_req6
*t5req6
= NULL
;
767 struct cpl_t6_act_open_req6
*t6req6
= NULL
;
771 unsigned int mtu_idx
;
773 int win
, sizev4
, sizev6
, wrlen
;
774 struct sockaddr_in
*la
= (struct sockaddr_in
*)
776 struct sockaddr_in
*ra
= (struct sockaddr_in
*)
777 &ep
->com
.remote_addr
;
778 struct sockaddr_in6
*la6
= (struct sockaddr_in6
*)
780 struct sockaddr_in6
*ra6
= (struct sockaddr_in6
*)
781 &ep
->com
.remote_addr
;
783 enum chip_type adapter_type
= ep
->com
.dev
->rdev
.lldi
.adapter_type
;
784 u32 isn
= (prandom_u32() & ~7UL) - 1;
786 switch (CHELSIO_CHIP_VERSION(adapter_type
)) {
788 sizev4
= sizeof(struct cpl_act_open_req
);
789 sizev6
= sizeof(struct cpl_act_open_req6
);
792 sizev4
= sizeof(struct cpl_t5_act_open_req
);
793 sizev6
= sizeof(struct cpl_t5_act_open_req6
);
796 sizev4
= sizeof(struct cpl_t6_act_open_req
);
797 sizev6
= sizeof(struct cpl_t6_act_open_req6
);
800 pr_err("T%d Chip is not supported\n",
801 CHELSIO_CHIP_VERSION(adapter_type
));
805 wrlen
= (ep
->com
.remote_addr
.ss_family
== AF_INET
) ?
806 roundup(sizev4
, 16) :
809 PDBG("%s ep %p atid %u\n", __func__
, ep
, ep
->atid
);
811 skb
= get_skb(NULL
, wrlen
, GFP_KERNEL
);
813 printk(KERN_ERR MOD
"%s - failed to alloc skb.\n",
817 set_wr_txq(skb
, CPL_PRIORITY_SETUP
, ep
->ctrlq_idx
);
819 best_mtu(ep
->com
.dev
->rdev
.lldi
.mtus
, ep
->mtu
, &mtu_idx
,
820 enable_tcp_timestamps
,
821 (AF_INET
== ep
->com
.remote_addr
.ss_family
) ? 0 : 1);
822 wscale
= compute_wscale(rcv_win
);
825 * Specify the largest window that will fit in opt0. The
826 * remainder will be specified in the rx_data_ack.
828 win
= ep
->rcv_win
>> 10;
829 if (win
> RCV_BUFSIZ_M
)
832 opt0
= (nocong
? NO_CONG_F
: 0) |
835 WND_SCALE_V(wscale
) |
837 L2T_IDX_V(ep
->l2t
->idx
) |
838 TX_CHAN_V(ep
->tx_chan
) |
839 SMAC_SEL_V(ep
->smac_idx
) |
840 DSCP_V(ep
->tos
>> 2) |
841 ULP_MODE_V(ULP_MODE_TCPDDP
) |
843 opt2
= RX_CHANNEL_V(0) |
844 CCTRL_ECN_V(enable_ecn
) |
845 RSS_QUEUE_VALID_F
| RSS_QUEUE_V(ep
->rss_qid
);
846 if (enable_tcp_timestamps
)
847 opt2
|= TSTAMPS_EN_F
;
850 if (wscale
&& enable_tcp_window_scaling
)
851 opt2
|= WND_SCALE_EN_F
;
852 if (CHELSIO_CHIP_VERSION(adapter_type
) > CHELSIO_T4
) {
856 opt2
|= T5_OPT_2_VALID_F
;
857 opt2
|= CONG_CNTRL_V(CONG_ALG_TAHOE
);
861 if (ep
->com
.remote_addr
.ss_family
== AF_INET6
)
862 cxgb4_clip_get(ep
->com
.dev
->rdev
.lldi
.ports
[0],
863 (const u32
*)&la6
->sin6_addr
.s6_addr
, 1);
865 t4_set_arp_err_handler(skb
, ep
, act_open_req_arp_failure
);
867 if (ep
->com
.remote_addr
.ss_family
== AF_INET
) {
868 switch (CHELSIO_CHIP_VERSION(adapter_type
)) {
870 req
= (struct cpl_act_open_req
*)skb_put(skb
, wrlen
);
874 t5req
= (struct cpl_t5_act_open_req
*)skb_put(skb
,
876 INIT_TP_WR(t5req
, 0);
877 req
= (struct cpl_act_open_req
*)t5req
;
880 t6req
= (struct cpl_t6_act_open_req
*)skb_put(skb
,
882 INIT_TP_WR(t6req
, 0);
883 req
= (struct cpl_act_open_req
*)t6req
;
884 t5req
= (struct cpl_t5_act_open_req
*)t6req
;
887 pr_err("T%d Chip is not supported\n",
888 CHELSIO_CHIP_VERSION(adapter_type
));
893 OPCODE_TID(req
) = cpu_to_be32(MK_OPCODE_TID(CPL_ACT_OPEN_REQ
,
894 ((ep
->rss_qid
<<14) | ep
->atid
)));
895 req
->local_port
= la
->sin_port
;
896 req
->peer_port
= ra
->sin_port
;
897 req
->local_ip
= la
->sin_addr
.s_addr
;
898 req
->peer_ip
= ra
->sin_addr
.s_addr
;
899 req
->opt0
= cpu_to_be64(opt0
);
901 if (is_t4(ep
->com
.dev
->rdev
.lldi
.adapter_type
)) {
902 req
->params
= cpu_to_be32(cxgb4_select_ntuple(
903 ep
->com
.dev
->rdev
.lldi
.ports
[0],
905 req
->opt2
= cpu_to_be32(opt2
);
907 t5req
->params
= cpu_to_be64(FILTER_TUPLE_V(
909 ep
->com
.dev
->rdev
.lldi
.ports
[0],
911 t5req
->rsvd
= cpu_to_be32(isn
);
912 PDBG("%s snd_isn %u\n", __func__
, t5req
->rsvd
);
913 t5req
->opt2
= cpu_to_be32(opt2
);
916 switch (CHELSIO_CHIP_VERSION(adapter_type
)) {
918 req6
= (struct cpl_act_open_req6
*)skb_put(skb
, wrlen
);
922 t5req6
= (struct cpl_t5_act_open_req6
*)skb_put(skb
,
924 INIT_TP_WR(t5req6
, 0);
925 req6
= (struct cpl_act_open_req6
*)t5req6
;
928 t6req6
= (struct cpl_t6_act_open_req6
*)skb_put(skb
,
930 INIT_TP_WR(t6req6
, 0);
931 req6
= (struct cpl_act_open_req6
*)t6req6
;
932 t5req6
= (struct cpl_t5_act_open_req6
*)t6req6
;
935 pr_err("T%d Chip is not supported\n",
936 CHELSIO_CHIP_VERSION(adapter_type
));
941 OPCODE_TID(req6
) = cpu_to_be32(MK_OPCODE_TID(CPL_ACT_OPEN_REQ6
,
942 ((ep
->rss_qid
<<14)|ep
->atid
)));
943 req6
->local_port
= la6
->sin6_port
;
944 req6
->peer_port
= ra6
->sin6_port
;
945 req6
->local_ip_hi
= *((__be64
*)(la6
->sin6_addr
.s6_addr
));
946 req6
->local_ip_lo
= *((__be64
*)(la6
->sin6_addr
.s6_addr
+ 8));
947 req6
->peer_ip_hi
= *((__be64
*)(ra6
->sin6_addr
.s6_addr
));
948 req6
->peer_ip_lo
= *((__be64
*)(ra6
->sin6_addr
.s6_addr
+ 8));
949 req6
->opt0
= cpu_to_be64(opt0
);
951 if (is_t4(ep
->com
.dev
->rdev
.lldi
.adapter_type
)) {
952 req6
->params
= cpu_to_be32(cxgb4_select_ntuple(
953 ep
->com
.dev
->rdev
.lldi
.ports
[0],
955 req6
->opt2
= cpu_to_be32(opt2
);
957 t5req6
->params
= cpu_to_be64(FILTER_TUPLE_V(
959 ep
->com
.dev
->rdev
.lldi
.ports
[0],
961 t5req6
->rsvd
= cpu_to_be32(isn
);
962 PDBG("%s snd_isn %u\n", __func__
, t5req6
->rsvd
);
963 t5req6
->opt2
= cpu_to_be32(opt2
);
967 set_bit(ACT_OPEN_REQ
, &ep
->com
.history
);
968 ret
= c4iw_l2t_send(&ep
->com
.dev
->rdev
, skb
, ep
->l2t
);
970 if (ret
&& ep
->com
.remote_addr
.ss_family
== AF_INET6
)
971 cxgb4_clip_release(ep
->com
.dev
->rdev
.lldi
.ports
[0],
972 (const u32
*)&la6
->sin6_addr
.s6_addr
, 1);
976 static int send_mpa_req(struct c4iw_ep
*ep
, struct sk_buff
*skb
,
979 int mpalen
, wrlen
, ret
;
980 struct fw_ofld_tx_data_wr
*req
;
981 struct mpa_message
*mpa
;
982 struct mpa_v2_conn_params mpa_v2_params
;
984 PDBG("%s ep %p tid %u pd_len %d\n", __func__
, ep
, ep
->hwtid
, ep
->plen
);
986 BUG_ON(skb_cloned(skb
));
988 mpalen
= sizeof(*mpa
) + ep
->plen
;
989 if (mpa_rev_to_use
== 2)
990 mpalen
+= sizeof(struct mpa_v2_conn_params
);
991 wrlen
= roundup(mpalen
+ sizeof *req
, 16);
992 skb
= get_skb(skb
, wrlen
, GFP_KERNEL
);
994 connect_reply_upcall(ep
, -ENOMEM
);
997 set_wr_txq(skb
, CPL_PRIORITY_DATA
, ep
->txq_idx
);
999 req
= (struct fw_ofld_tx_data_wr
*)skb_put(skb
, wrlen
);
1000 memset(req
, 0, wrlen
);
1001 req
->op_to_immdlen
= cpu_to_be32(
1002 FW_WR_OP_V(FW_OFLD_TX_DATA_WR
) |
1004 FW_WR_IMMDLEN_V(mpalen
));
1005 req
->flowid_len16
= cpu_to_be32(
1006 FW_WR_FLOWID_V(ep
->hwtid
) |
1007 FW_WR_LEN16_V(wrlen
>> 4));
1008 req
->plen
= cpu_to_be32(mpalen
);
1009 req
->tunnel_to_proxy
= cpu_to_be32(
1010 FW_OFLD_TX_DATA_WR_FLUSH_F
|
1011 FW_OFLD_TX_DATA_WR_SHOVE_F
);
1013 mpa
= (struct mpa_message
*)(req
+ 1);
1014 memcpy(mpa
->key
, MPA_KEY_REQ
, sizeof(mpa
->key
));
1018 mpa
->flags
|= MPA_CRC
;
1019 if (markers_enabled
) {
1020 mpa
->flags
|= MPA_MARKERS
;
1021 ep
->mpa_attr
.recv_marker_enabled
= 1;
1023 ep
->mpa_attr
.recv_marker_enabled
= 0;
1025 if (mpa_rev_to_use
== 2)
1026 mpa
->flags
|= MPA_ENHANCED_RDMA_CONN
;
1028 mpa
->private_data_size
= htons(ep
->plen
);
1029 mpa
->revision
= mpa_rev_to_use
;
1030 if (mpa_rev_to_use
== 1) {
1031 ep
->tried_with_mpa_v1
= 1;
1032 ep
->retry_with_mpa_v1
= 0;
1035 if (mpa_rev_to_use
== 2) {
1036 mpa
->private_data_size
= htons(ntohs(mpa
->private_data_size
) +
1037 sizeof (struct mpa_v2_conn_params
));
1038 PDBG("%s initiator ird %u ord %u\n", __func__
, ep
->ird
,
1040 mpa_v2_params
.ird
= htons((u16
)ep
->ird
);
1041 mpa_v2_params
.ord
= htons((u16
)ep
->ord
);
1044 mpa_v2_params
.ird
|= htons(MPA_V2_PEER2PEER_MODEL
);
1045 if (p2p_type
== FW_RI_INIT_P2PTYPE_RDMA_WRITE
)
1046 mpa_v2_params
.ord
|=
1047 htons(MPA_V2_RDMA_WRITE_RTR
);
1048 else if (p2p_type
== FW_RI_INIT_P2PTYPE_READ_REQ
)
1049 mpa_v2_params
.ord
|=
1050 htons(MPA_V2_RDMA_READ_RTR
);
1052 memcpy(mpa
->private_data
, &mpa_v2_params
,
1053 sizeof(struct mpa_v2_conn_params
));
1056 memcpy(mpa
->private_data
+
1057 sizeof(struct mpa_v2_conn_params
),
1058 ep
->mpa_pkt
+ sizeof(*mpa
), ep
->plen
);
1061 memcpy(mpa
->private_data
,
1062 ep
->mpa_pkt
+ sizeof(*mpa
), ep
->plen
);
1065 * Reference the mpa skb. This ensures the data area
1066 * will remain in memory until the hw acks the tx.
1067 * Function fw4_ack() will deref it.
1070 t4_set_arp_err_handler(skb
, NULL
, arp_failure_discard
);
1071 BUG_ON(ep
->mpa_skb
);
1073 ret
= c4iw_l2t_send(&ep
->com
.dev
->rdev
, skb
, ep
->l2t
);
1077 __state_set(&ep
->com
, MPA_REQ_SENT
);
1078 ep
->mpa_attr
.initiator
= 1;
1079 ep
->snd_seq
+= mpalen
;
1083 static int send_mpa_reject(struct c4iw_ep
*ep
, const void *pdata
, u8 plen
)
1086 struct fw_ofld_tx_data_wr
*req
;
1087 struct mpa_message
*mpa
;
1088 struct sk_buff
*skb
;
1089 struct mpa_v2_conn_params mpa_v2_params
;
1091 PDBG("%s ep %p tid %u pd_len %d\n", __func__
, ep
, ep
->hwtid
, ep
->plen
);
1093 mpalen
= sizeof(*mpa
) + plen
;
1094 if (ep
->mpa_attr
.version
== 2 && ep
->mpa_attr
.enhanced_rdma_conn
)
1095 mpalen
+= sizeof(struct mpa_v2_conn_params
);
1096 wrlen
= roundup(mpalen
+ sizeof *req
, 16);
1098 skb
= get_skb(NULL
, wrlen
, GFP_KERNEL
);
1100 printk(KERN_ERR MOD
"%s - cannot alloc skb!\n", __func__
);
1103 set_wr_txq(skb
, CPL_PRIORITY_DATA
, ep
->txq_idx
);
1105 req
= (struct fw_ofld_tx_data_wr
*)skb_put(skb
, wrlen
);
1106 memset(req
, 0, wrlen
);
1107 req
->op_to_immdlen
= cpu_to_be32(
1108 FW_WR_OP_V(FW_OFLD_TX_DATA_WR
) |
1110 FW_WR_IMMDLEN_V(mpalen
));
1111 req
->flowid_len16
= cpu_to_be32(
1112 FW_WR_FLOWID_V(ep
->hwtid
) |
1113 FW_WR_LEN16_V(wrlen
>> 4));
1114 req
->plen
= cpu_to_be32(mpalen
);
1115 req
->tunnel_to_proxy
= cpu_to_be32(
1116 FW_OFLD_TX_DATA_WR_FLUSH_F
|
1117 FW_OFLD_TX_DATA_WR_SHOVE_F
);
1119 mpa
= (struct mpa_message
*)(req
+ 1);
1120 memset(mpa
, 0, sizeof(*mpa
));
1121 memcpy(mpa
->key
, MPA_KEY_REP
, sizeof(mpa
->key
));
1122 mpa
->flags
= MPA_REJECT
;
1123 mpa
->revision
= ep
->mpa_attr
.version
;
1124 mpa
->private_data_size
= htons(plen
);
1126 if (ep
->mpa_attr
.version
== 2 && ep
->mpa_attr
.enhanced_rdma_conn
) {
1127 mpa
->flags
|= MPA_ENHANCED_RDMA_CONN
;
1128 mpa
->private_data_size
= htons(ntohs(mpa
->private_data_size
) +
1129 sizeof (struct mpa_v2_conn_params
));
1130 mpa_v2_params
.ird
= htons(((u16
)ep
->ird
) |
1131 (peer2peer
? MPA_V2_PEER2PEER_MODEL
:
1133 mpa_v2_params
.ord
= htons(((u16
)ep
->ord
) | (peer2peer
?
1135 FW_RI_INIT_P2PTYPE_RDMA_WRITE
?
1136 MPA_V2_RDMA_WRITE_RTR
: p2p_type
==
1137 FW_RI_INIT_P2PTYPE_READ_REQ
?
1138 MPA_V2_RDMA_READ_RTR
: 0) : 0));
1139 memcpy(mpa
->private_data
, &mpa_v2_params
,
1140 sizeof(struct mpa_v2_conn_params
));
1143 memcpy(mpa
->private_data
+
1144 sizeof(struct mpa_v2_conn_params
), pdata
, plen
);
1147 memcpy(mpa
->private_data
, pdata
, plen
);
1150 * Reference the mpa skb again. This ensures the data area
1151 * will remain in memory until the hw acks the tx.
1152 * Function fw4_ack() will deref it.
1155 set_wr_txq(skb
, CPL_PRIORITY_DATA
, ep
->txq_idx
);
1156 t4_set_arp_err_handler(skb
, NULL
, mpa_start_arp_failure
);
1157 BUG_ON(ep
->mpa_skb
);
1159 ep
->snd_seq
+= mpalen
;
1160 return c4iw_l2t_send(&ep
->com
.dev
->rdev
, skb
, ep
->l2t
);
1163 static int send_mpa_reply(struct c4iw_ep
*ep
, const void *pdata
, u8 plen
)
1166 struct fw_ofld_tx_data_wr
*req
;
1167 struct mpa_message
*mpa
;
1168 struct sk_buff
*skb
;
1169 struct mpa_v2_conn_params mpa_v2_params
;
1171 PDBG("%s ep %p tid %u pd_len %d\n", __func__
, ep
, ep
->hwtid
, ep
->plen
);
1173 mpalen
= sizeof(*mpa
) + plen
;
1174 if (ep
->mpa_attr
.version
== 2 && ep
->mpa_attr
.enhanced_rdma_conn
)
1175 mpalen
+= sizeof(struct mpa_v2_conn_params
);
1176 wrlen
= roundup(mpalen
+ sizeof *req
, 16);
1178 skb
= get_skb(NULL
, wrlen
, GFP_KERNEL
);
1180 printk(KERN_ERR MOD
"%s - cannot alloc skb!\n", __func__
);
1183 set_wr_txq(skb
, CPL_PRIORITY_DATA
, ep
->txq_idx
);
1185 req
= (struct fw_ofld_tx_data_wr
*) skb_put(skb
, wrlen
);
1186 memset(req
, 0, wrlen
);
1187 req
->op_to_immdlen
= cpu_to_be32(
1188 FW_WR_OP_V(FW_OFLD_TX_DATA_WR
) |
1190 FW_WR_IMMDLEN_V(mpalen
));
1191 req
->flowid_len16
= cpu_to_be32(
1192 FW_WR_FLOWID_V(ep
->hwtid
) |
1193 FW_WR_LEN16_V(wrlen
>> 4));
1194 req
->plen
= cpu_to_be32(mpalen
);
1195 req
->tunnel_to_proxy
= cpu_to_be32(
1196 FW_OFLD_TX_DATA_WR_FLUSH_F
|
1197 FW_OFLD_TX_DATA_WR_SHOVE_F
);
1199 mpa
= (struct mpa_message
*)(req
+ 1);
1200 memset(mpa
, 0, sizeof(*mpa
));
1201 memcpy(mpa
->key
, MPA_KEY_REP
, sizeof(mpa
->key
));
1203 if (ep
->mpa_attr
.crc_enabled
)
1204 mpa
->flags
|= MPA_CRC
;
1205 if (ep
->mpa_attr
.recv_marker_enabled
)
1206 mpa
->flags
|= MPA_MARKERS
;
1207 mpa
->revision
= ep
->mpa_attr
.version
;
1208 mpa
->private_data_size
= htons(plen
);
1210 if (ep
->mpa_attr
.version
== 2 && ep
->mpa_attr
.enhanced_rdma_conn
) {
1211 mpa
->flags
|= MPA_ENHANCED_RDMA_CONN
;
1212 mpa
->private_data_size
= htons(ntohs(mpa
->private_data_size
) +
1213 sizeof (struct mpa_v2_conn_params
));
1214 mpa_v2_params
.ird
= htons((u16
)ep
->ird
);
1215 mpa_v2_params
.ord
= htons((u16
)ep
->ord
);
1216 if (peer2peer
&& (ep
->mpa_attr
.p2p_type
!=
1217 FW_RI_INIT_P2PTYPE_DISABLED
)) {
1218 mpa_v2_params
.ird
|= htons(MPA_V2_PEER2PEER_MODEL
);
1220 if (p2p_type
== FW_RI_INIT_P2PTYPE_RDMA_WRITE
)
1221 mpa_v2_params
.ord
|=
1222 htons(MPA_V2_RDMA_WRITE_RTR
);
1223 else if (p2p_type
== FW_RI_INIT_P2PTYPE_READ_REQ
)
1224 mpa_v2_params
.ord
|=
1225 htons(MPA_V2_RDMA_READ_RTR
);
1228 memcpy(mpa
->private_data
, &mpa_v2_params
,
1229 sizeof(struct mpa_v2_conn_params
));
1232 memcpy(mpa
->private_data
+
1233 sizeof(struct mpa_v2_conn_params
), pdata
, plen
);
1236 memcpy(mpa
->private_data
, pdata
, plen
);
1239 * Reference the mpa skb. This ensures the data area
1240 * will remain in memory until the hw acks the tx.
1241 * Function fw4_ack() will deref it.
1244 t4_set_arp_err_handler(skb
, NULL
, mpa_start_arp_failure
);
1246 __state_set(&ep
->com
, MPA_REP_SENT
);
1247 ep
->snd_seq
+= mpalen
;
1248 return c4iw_l2t_send(&ep
->com
.dev
->rdev
, skb
, ep
->l2t
);
1251 static int act_establish(struct c4iw_dev
*dev
, struct sk_buff
*skb
)
1254 struct cpl_act_establish
*req
= cplhdr(skb
);
1255 unsigned int tid
= GET_TID(req
);
1256 unsigned int atid
= TID_TID_G(ntohl(req
->tos_atid
));
1257 struct tid_info
*t
= dev
->rdev
.lldi
.tids
;
1260 ep
= lookup_atid(t
, atid
);
1262 PDBG("%s ep %p tid %u snd_isn %u rcv_isn %u\n", __func__
, ep
, tid
,
1263 be32_to_cpu(req
->snd_isn
), be32_to_cpu(req
->rcv_isn
));
1265 mutex_lock(&ep
->com
.mutex
);
1266 dst_confirm(ep
->dst
);
1268 /* setup the hwtid for this connection */
1270 cxgb4_insert_tid(t
, ep
, tid
);
1273 ep
->snd_seq
= be32_to_cpu(req
->snd_isn
);
1274 ep
->rcv_seq
= be32_to_cpu(req
->rcv_isn
);
1276 set_emss(ep
, ntohs(req
->tcp_opt
));
1278 /* dealloc the atid */
1279 remove_handle(ep
->com
.dev
, &ep
->com
.dev
->atid_idr
, atid
);
1280 cxgb4_free_atid(t
, atid
);
1281 set_bit(ACT_ESTAB
, &ep
->com
.history
);
1283 /* start MPA negotiation */
1284 ret
= send_flowc(ep
);
1287 if (ep
->retry_with_mpa_v1
)
1288 ret
= send_mpa_req(ep
, skb
, 1);
1290 ret
= send_mpa_req(ep
, skb
, mpa_rev
);
1293 mutex_unlock(&ep
->com
.mutex
);
1296 mutex_unlock(&ep
->com
.mutex
);
1297 connect_reply_upcall(ep
, -ENOMEM
);
1298 c4iw_ep_disconnect(ep
, 0, GFP_KERNEL
);
1302 static void close_complete_upcall(struct c4iw_ep
*ep
, int status
)
1304 struct iw_cm_event event
;
1306 PDBG("%s ep %p tid %u\n", __func__
, ep
, ep
->hwtid
);
1307 memset(&event
, 0, sizeof(event
));
1308 event
.event
= IW_CM_EVENT_CLOSE
;
1309 event
.status
= status
;
1310 if (ep
->com
.cm_id
) {
1311 PDBG("close complete delivered ep %p cm_id %p tid %u\n",
1312 ep
, ep
->com
.cm_id
, ep
->hwtid
);
1313 ep
->com
.cm_id
->event_handler(ep
->com
.cm_id
, &event
);
1314 deref_cm_id(&ep
->com
);
1315 set_bit(CLOSE_UPCALL
, &ep
->com
.history
);
1319 static void peer_close_upcall(struct c4iw_ep
*ep
)
1321 struct iw_cm_event event
;
1323 PDBG("%s ep %p tid %u\n", __func__
, ep
, ep
->hwtid
);
1324 memset(&event
, 0, sizeof(event
));
1325 event
.event
= IW_CM_EVENT_DISCONNECT
;
1326 if (ep
->com
.cm_id
) {
1327 PDBG("peer close delivered ep %p cm_id %p tid %u\n",
1328 ep
, ep
->com
.cm_id
, ep
->hwtid
);
1329 ep
->com
.cm_id
->event_handler(ep
->com
.cm_id
, &event
);
1330 set_bit(DISCONN_UPCALL
, &ep
->com
.history
);
1334 static void peer_abort_upcall(struct c4iw_ep
*ep
)
1336 struct iw_cm_event event
;
1338 PDBG("%s ep %p tid %u\n", __func__
, ep
, ep
->hwtid
);
1339 memset(&event
, 0, sizeof(event
));
1340 event
.event
= IW_CM_EVENT_CLOSE
;
1341 event
.status
= -ECONNRESET
;
1342 if (ep
->com
.cm_id
) {
1343 PDBG("abort delivered ep %p cm_id %p tid %u\n", ep
,
1344 ep
->com
.cm_id
, ep
->hwtid
);
1345 ep
->com
.cm_id
->event_handler(ep
->com
.cm_id
, &event
);
1346 deref_cm_id(&ep
->com
);
1347 set_bit(ABORT_UPCALL
, &ep
->com
.history
);
1351 static void connect_reply_upcall(struct c4iw_ep
*ep
, int status
)
1353 struct iw_cm_event event
;
1355 PDBG("%s ep %p tid %u status %d\n", __func__
, ep
, ep
->hwtid
, status
);
1356 memset(&event
, 0, sizeof(event
));
1357 event
.event
= IW_CM_EVENT_CONNECT_REPLY
;
1358 event
.status
= status
;
1359 memcpy(&event
.local_addr
, &ep
->com
.local_addr
,
1360 sizeof(ep
->com
.local_addr
));
1361 memcpy(&event
.remote_addr
, &ep
->com
.remote_addr
,
1362 sizeof(ep
->com
.remote_addr
));
1364 if ((status
== 0) || (status
== -ECONNREFUSED
)) {
1365 if (!ep
->tried_with_mpa_v1
) {
1366 /* this means MPA_v2 is used */
1367 event
.ord
= ep
->ird
;
1368 event
.ird
= ep
->ord
;
1369 event
.private_data_len
= ep
->plen
-
1370 sizeof(struct mpa_v2_conn_params
);
1371 event
.private_data
= ep
->mpa_pkt
+
1372 sizeof(struct mpa_message
) +
1373 sizeof(struct mpa_v2_conn_params
);
1375 /* this means MPA_v1 is used */
1376 event
.ord
= cur_max_read_depth(ep
->com
.dev
);
1377 event
.ird
= cur_max_read_depth(ep
->com
.dev
);
1378 event
.private_data_len
= ep
->plen
;
1379 event
.private_data
= ep
->mpa_pkt
+
1380 sizeof(struct mpa_message
);
1384 PDBG("%s ep %p tid %u status %d\n", __func__
, ep
,
1386 set_bit(CONN_RPL_UPCALL
, &ep
->com
.history
);
1387 ep
->com
.cm_id
->event_handler(ep
->com
.cm_id
, &event
);
1390 deref_cm_id(&ep
->com
);
1393 static int connect_request_upcall(struct c4iw_ep
*ep
)
1395 struct iw_cm_event event
;
1398 PDBG("%s ep %p tid %u\n", __func__
, ep
, ep
->hwtid
);
1399 memset(&event
, 0, sizeof(event
));
1400 event
.event
= IW_CM_EVENT_CONNECT_REQUEST
;
1401 memcpy(&event
.local_addr
, &ep
->com
.local_addr
,
1402 sizeof(ep
->com
.local_addr
));
1403 memcpy(&event
.remote_addr
, &ep
->com
.remote_addr
,
1404 sizeof(ep
->com
.remote_addr
));
1405 event
.provider_data
= ep
;
1406 if (!ep
->tried_with_mpa_v1
) {
1407 /* this means MPA_v2 is used */
1408 event
.ord
= ep
->ord
;
1409 event
.ird
= ep
->ird
;
1410 event
.private_data_len
= ep
->plen
-
1411 sizeof(struct mpa_v2_conn_params
);
1412 event
.private_data
= ep
->mpa_pkt
+ sizeof(struct mpa_message
) +
1413 sizeof(struct mpa_v2_conn_params
);
1415 /* this means MPA_v1 is used. Send max supported */
1416 event
.ord
= cur_max_read_depth(ep
->com
.dev
);
1417 event
.ird
= cur_max_read_depth(ep
->com
.dev
);
1418 event
.private_data_len
= ep
->plen
;
1419 event
.private_data
= ep
->mpa_pkt
+ sizeof(struct mpa_message
);
1421 c4iw_get_ep(&ep
->com
);
1422 ret
= ep
->parent_ep
->com
.cm_id
->event_handler(ep
->parent_ep
->com
.cm_id
,
1425 c4iw_put_ep(&ep
->com
);
1426 set_bit(CONNREQ_UPCALL
, &ep
->com
.history
);
1427 c4iw_put_ep(&ep
->parent_ep
->com
);
1431 static void established_upcall(struct c4iw_ep
*ep
)
1433 struct iw_cm_event event
;
1435 PDBG("%s ep %p tid %u\n", __func__
, ep
, ep
->hwtid
);
1436 memset(&event
, 0, sizeof(event
));
1437 event
.event
= IW_CM_EVENT_ESTABLISHED
;
1438 event
.ird
= ep
->ord
;
1439 event
.ord
= ep
->ird
;
1440 if (ep
->com
.cm_id
) {
1441 PDBG("%s ep %p tid %u\n", __func__
, ep
, ep
->hwtid
);
1442 ep
->com
.cm_id
->event_handler(ep
->com
.cm_id
, &event
);
1443 set_bit(ESTAB_UPCALL
, &ep
->com
.history
);
1447 static int update_rx_credits(struct c4iw_ep
*ep
, u32 credits
)
1449 struct cpl_rx_data_ack
*req
;
1450 struct sk_buff
*skb
;
1451 int wrlen
= roundup(sizeof *req
, 16);
1453 PDBG("%s ep %p tid %u credits %u\n", __func__
, ep
, ep
->hwtid
, credits
);
1454 skb
= get_skb(NULL
, wrlen
, GFP_KERNEL
);
1456 printk(KERN_ERR MOD
"update_rx_credits - cannot alloc skb!\n");
1461 * If we couldn't specify the entire rcv window at connection setup
1462 * due to the limit in the number of bits in the RCV_BUFSIZ field,
1463 * then add the overage in to the credits returned.
1465 if (ep
->rcv_win
> RCV_BUFSIZ_M
* 1024)
1466 credits
+= ep
->rcv_win
- RCV_BUFSIZ_M
* 1024;
1468 req
= (struct cpl_rx_data_ack
*) skb_put(skb
, wrlen
);
1469 memset(req
, 0, wrlen
);
1470 INIT_TP_WR(req
, ep
->hwtid
);
1471 OPCODE_TID(req
) = cpu_to_be32(MK_OPCODE_TID(CPL_RX_DATA_ACK
,
1473 req
->credit_dack
= cpu_to_be32(credits
| RX_FORCE_ACK_F
|
1475 RX_DACK_MODE_V(dack_mode
));
1476 set_wr_txq(skb
, CPL_PRIORITY_ACK
, ep
->ctrlq_idx
);
1477 c4iw_ofld_send(&ep
->com
.dev
->rdev
, skb
);
1481 #define RELAXED_IRD_NEGOTIATION 1
1484 * process_mpa_reply - process streaming mode MPA reply
1488 * 0 upon success indicating a connect request was delivered to the ULP
1489 * or the mpa request is incomplete but valid so far.
1491 * 1 if a failure requires the caller to close the connection.
1493 * 2 if a failure requires the caller to abort the connection.
1495 static int process_mpa_reply(struct c4iw_ep
*ep
, struct sk_buff
*skb
)
1497 struct mpa_message
*mpa
;
1498 struct mpa_v2_conn_params
*mpa_v2_params
;
1500 u16 resp_ird
, resp_ord
;
1501 u8 rtr_mismatch
= 0, insuff_ird
= 0;
1502 struct c4iw_qp_attributes attrs
;
1503 enum c4iw_qp_attr_mask mask
;
1507 PDBG("%s ep %p tid %u\n", __func__
, ep
, ep
->hwtid
);
1510 * If we get more than the supported amount of private data
1511 * then we must fail this connection.
1513 if (ep
->mpa_pkt_len
+ skb
->len
> sizeof(ep
->mpa_pkt
)) {
1515 goto err_stop_timer
;
1519 * copy the new data into our accumulation buffer.
1521 skb_copy_from_linear_data(skb
, &(ep
->mpa_pkt
[ep
->mpa_pkt_len
]),
1523 ep
->mpa_pkt_len
+= skb
->len
;
1526 * if we don't even have the mpa message, then bail.
1528 if (ep
->mpa_pkt_len
< sizeof(*mpa
))
1530 mpa
= (struct mpa_message
*) ep
->mpa_pkt
;
1532 /* Validate MPA header. */
1533 if (mpa
->revision
> mpa_rev
) {
1534 printk(KERN_ERR MOD
"%s MPA version mismatch. Local = %d,"
1535 " Received = %d\n", __func__
, mpa_rev
, mpa
->revision
);
1537 goto err_stop_timer
;
1539 if (memcmp(mpa
->key
, MPA_KEY_REP
, sizeof(mpa
->key
))) {
1541 goto err_stop_timer
;
1544 plen
= ntohs(mpa
->private_data_size
);
1547 * Fail if there's too much private data.
1549 if (plen
> MPA_MAX_PRIVATE_DATA
) {
1551 goto err_stop_timer
;
1555 * If plen does not account for pkt size
1557 if (ep
->mpa_pkt_len
> (sizeof(*mpa
) + plen
)) {
1559 goto err_stop_timer
;
1562 ep
->plen
= (u8
) plen
;
1565 * If we don't have all the pdata yet, then bail.
1566 * We'll continue process when more data arrives.
1568 if (ep
->mpa_pkt_len
< (sizeof(*mpa
) + plen
))
1571 if (mpa
->flags
& MPA_REJECT
) {
1572 err
= -ECONNREFUSED
;
1573 goto err_stop_timer
;
1577 * Stop mpa timer. If it expired, then
1578 * we ignore the MPA reply. process_timeout()
1579 * will abort the connection.
1581 if (stop_ep_timer(ep
))
1585 * If we get here we have accumulated the entire mpa
1586 * start reply message including private data. And
1587 * the MPA header is valid.
1589 __state_set(&ep
->com
, FPDU_MODE
);
1590 ep
->mpa_attr
.crc_enabled
= (mpa
->flags
& MPA_CRC
) | crc_enabled
? 1 : 0;
1591 ep
->mpa_attr
.xmit_marker_enabled
= mpa
->flags
& MPA_MARKERS
? 1 : 0;
1592 ep
->mpa_attr
.version
= mpa
->revision
;
1593 ep
->mpa_attr
.p2p_type
= FW_RI_INIT_P2PTYPE_DISABLED
;
1595 if (mpa
->revision
== 2) {
1596 ep
->mpa_attr
.enhanced_rdma_conn
=
1597 mpa
->flags
& MPA_ENHANCED_RDMA_CONN
? 1 : 0;
1598 if (ep
->mpa_attr
.enhanced_rdma_conn
) {
1599 mpa_v2_params
= (struct mpa_v2_conn_params
*)
1600 (ep
->mpa_pkt
+ sizeof(*mpa
));
1601 resp_ird
= ntohs(mpa_v2_params
->ird
) &
1602 MPA_V2_IRD_ORD_MASK
;
1603 resp_ord
= ntohs(mpa_v2_params
->ord
) &
1604 MPA_V2_IRD_ORD_MASK
;
1605 PDBG("%s responder ird %u ord %u ep ird %u ord %u\n",
1606 __func__
, resp_ird
, resp_ord
, ep
->ird
, ep
->ord
);
1609 * This is a double-check. Ideally, below checks are
1610 * not required since ird/ord stuff has been taken
1611 * care of in c4iw_accept_cr
1613 if (ep
->ird
< resp_ord
) {
1614 if (RELAXED_IRD_NEGOTIATION
&& resp_ord
<=
1615 ep
->com
.dev
->rdev
.lldi
.max_ordird_qp
)
1619 } else if (ep
->ird
> resp_ord
) {
1622 if (ep
->ord
> resp_ird
) {
1623 if (RELAXED_IRD_NEGOTIATION
)
1634 if (ntohs(mpa_v2_params
->ird
) &
1635 MPA_V2_PEER2PEER_MODEL
) {
1636 if (ntohs(mpa_v2_params
->ord
) &
1637 MPA_V2_RDMA_WRITE_RTR
)
1638 ep
->mpa_attr
.p2p_type
=
1639 FW_RI_INIT_P2PTYPE_RDMA_WRITE
;
1640 else if (ntohs(mpa_v2_params
->ord
) &
1641 MPA_V2_RDMA_READ_RTR
)
1642 ep
->mpa_attr
.p2p_type
=
1643 FW_RI_INIT_P2PTYPE_READ_REQ
;
1646 } else if (mpa
->revision
== 1)
1648 ep
->mpa_attr
.p2p_type
= p2p_type
;
1650 PDBG("%s - crc_enabled=%d, recv_marker_enabled=%d, "
1651 "xmit_marker_enabled=%d, version=%d p2p_type=%d local-p2p_type = "
1652 "%d\n", __func__
, ep
->mpa_attr
.crc_enabled
,
1653 ep
->mpa_attr
.recv_marker_enabled
,
1654 ep
->mpa_attr
.xmit_marker_enabled
, ep
->mpa_attr
.version
,
1655 ep
->mpa_attr
.p2p_type
, p2p_type
);
1658 * If responder's RTR does not match with that of initiator, assign
1659 * FW_RI_INIT_P2PTYPE_DISABLED in mpa attributes so that RTR is not
1660 * generated when moving QP to RTS state.
1661 * A TERM message will be sent after QP has moved to RTS state
1663 if ((ep
->mpa_attr
.version
== 2) && peer2peer
&&
1664 (ep
->mpa_attr
.p2p_type
!= p2p_type
)) {
1665 ep
->mpa_attr
.p2p_type
= FW_RI_INIT_P2PTYPE_DISABLED
;
1669 attrs
.mpa_attr
= ep
->mpa_attr
;
1670 attrs
.max_ird
= ep
->ird
;
1671 attrs
.max_ord
= ep
->ord
;
1672 attrs
.llp_stream_handle
= ep
;
1673 attrs
.next_state
= C4IW_QP_STATE_RTS
;
1675 mask
= C4IW_QP_ATTR_NEXT_STATE
|
1676 C4IW_QP_ATTR_LLP_STREAM_HANDLE
| C4IW_QP_ATTR_MPA_ATTR
|
1677 C4IW_QP_ATTR_MAX_IRD
| C4IW_QP_ATTR_MAX_ORD
;
1679 /* bind QP and TID with INIT_WR */
1680 err
= c4iw_modify_qp(ep
->com
.qp
->rhp
,
1681 ep
->com
.qp
, mask
, &attrs
, 1);
1686 * If responder's RTR requirement did not match with what initiator
1687 * supports, generate TERM message
1690 printk(KERN_ERR
"%s: RTR mismatch, sending TERM\n", __func__
);
1691 attrs
.layer_etype
= LAYER_MPA
| DDP_LLP
;
1692 attrs
.ecode
= MPA_NOMATCH_RTR
;
1693 attrs
.next_state
= C4IW_QP_STATE_TERMINATE
;
1694 attrs
.send_term
= 1;
1695 err
= c4iw_modify_qp(ep
->com
.qp
->rhp
, ep
->com
.qp
,
1696 C4IW_QP_ATTR_NEXT_STATE
, &attrs
, 1);
1703 * Generate TERM if initiator IRD is not sufficient for responder
1704 * provided ORD. Currently, we do the same behaviour even when
1705 * responder provided IRD is also not sufficient as regards to
1709 printk(KERN_ERR
"%s: Insufficient IRD, sending TERM\n",
1711 attrs
.layer_etype
= LAYER_MPA
| DDP_LLP
;
1712 attrs
.ecode
= MPA_INSUFF_IRD
;
1713 attrs
.next_state
= C4IW_QP_STATE_TERMINATE
;
1714 attrs
.send_term
= 1;
1715 err
= c4iw_modify_qp(ep
->com
.qp
->rhp
, ep
->com
.qp
,
1716 C4IW_QP_ATTR_NEXT_STATE
, &attrs
, 1);
1727 connect_reply_upcall(ep
, err
);
1732 * process_mpa_request - process streaming mode MPA request
1736 * 0 upon success indicating a connect request was delivered to the ULP
1737 * or the mpa request is incomplete but valid so far.
1739 * 1 if a failure requires the caller to close the connection.
1741 * 2 if a failure requires the caller to abort the connection.
1743 static int process_mpa_request(struct c4iw_ep
*ep
, struct sk_buff
*skb
)
1745 struct mpa_message
*mpa
;
1746 struct mpa_v2_conn_params
*mpa_v2_params
;
1749 PDBG("%s ep %p tid %u\n", __func__
, ep
, ep
->hwtid
);
1752 * If we get more than the supported amount of private data
1753 * then we must fail this connection.
1755 if (ep
->mpa_pkt_len
+ skb
->len
> sizeof(ep
->mpa_pkt
))
1756 goto err_stop_timer
;
1758 PDBG("%s enter (%s line %u)\n", __func__
, __FILE__
, __LINE__
);
1761 * Copy the new data into our accumulation buffer.
1763 skb_copy_from_linear_data(skb
, &(ep
->mpa_pkt
[ep
->mpa_pkt_len
]),
1765 ep
->mpa_pkt_len
+= skb
->len
;
1768 * If we don't even have the mpa message, then bail.
1769 * We'll continue process when more data arrives.
1771 if (ep
->mpa_pkt_len
< sizeof(*mpa
))
1774 PDBG("%s enter (%s line %u)\n", __func__
, __FILE__
, __LINE__
);
1775 mpa
= (struct mpa_message
*) ep
->mpa_pkt
;
1778 * Validate MPA Header.
1780 if (mpa
->revision
> mpa_rev
) {
1781 printk(KERN_ERR MOD
"%s MPA version mismatch. Local = %d,"
1782 " Received = %d\n", __func__
, mpa_rev
, mpa
->revision
);
1783 goto err_stop_timer
;
1786 if (memcmp(mpa
->key
, MPA_KEY_REQ
, sizeof(mpa
->key
)))
1787 goto err_stop_timer
;
1789 plen
= ntohs(mpa
->private_data_size
);
1792 * Fail if there's too much private data.
1794 if (plen
> MPA_MAX_PRIVATE_DATA
)
1795 goto err_stop_timer
;
1798 * If plen does not account for pkt size
1800 if (ep
->mpa_pkt_len
> (sizeof(*mpa
) + plen
))
1801 goto err_stop_timer
;
1802 ep
->plen
= (u8
) plen
;
1805 * If we don't have all the pdata yet, then bail.
1807 if (ep
->mpa_pkt_len
< (sizeof(*mpa
) + plen
))
1811 * If we get here we have accumulated the entire mpa
1812 * start reply message including private data.
1814 ep
->mpa_attr
.initiator
= 0;
1815 ep
->mpa_attr
.crc_enabled
= (mpa
->flags
& MPA_CRC
) | crc_enabled
? 1 : 0;
1816 ep
->mpa_attr
.recv_marker_enabled
= markers_enabled
;
1817 ep
->mpa_attr
.xmit_marker_enabled
= mpa
->flags
& MPA_MARKERS
? 1 : 0;
1818 ep
->mpa_attr
.version
= mpa
->revision
;
1819 if (mpa
->revision
== 1)
1820 ep
->tried_with_mpa_v1
= 1;
1821 ep
->mpa_attr
.p2p_type
= FW_RI_INIT_P2PTYPE_DISABLED
;
1823 if (mpa
->revision
== 2) {
1824 ep
->mpa_attr
.enhanced_rdma_conn
=
1825 mpa
->flags
& MPA_ENHANCED_RDMA_CONN
? 1 : 0;
1826 if (ep
->mpa_attr
.enhanced_rdma_conn
) {
1827 mpa_v2_params
= (struct mpa_v2_conn_params
*)
1828 (ep
->mpa_pkt
+ sizeof(*mpa
));
1829 ep
->ird
= ntohs(mpa_v2_params
->ird
) &
1830 MPA_V2_IRD_ORD_MASK
;
1831 ep
->ird
= min_t(u32
, ep
->ird
,
1832 cur_max_read_depth(ep
->com
.dev
));
1833 ep
->ord
= ntohs(mpa_v2_params
->ord
) &
1834 MPA_V2_IRD_ORD_MASK
;
1835 ep
->ord
= min_t(u32
, ep
->ord
,
1836 cur_max_read_depth(ep
->com
.dev
));
1837 PDBG("%s initiator ird %u ord %u\n", __func__
, ep
->ird
,
1839 if (ntohs(mpa_v2_params
->ird
) & MPA_V2_PEER2PEER_MODEL
)
1841 if (ntohs(mpa_v2_params
->ord
) &
1842 MPA_V2_RDMA_WRITE_RTR
)
1843 ep
->mpa_attr
.p2p_type
=
1844 FW_RI_INIT_P2PTYPE_RDMA_WRITE
;
1845 else if (ntohs(mpa_v2_params
->ord
) &
1846 MPA_V2_RDMA_READ_RTR
)
1847 ep
->mpa_attr
.p2p_type
=
1848 FW_RI_INIT_P2PTYPE_READ_REQ
;
1851 } else if (mpa
->revision
== 1)
1853 ep
->mpa_attr
.p2p_type
= p2p_type
;
1855 PDBG("%s - crc_enabled=%d, recv_marker_enabled=%d, "
1856 "xmit_marker_enabled=%d, version=%d p2p_type=%d\n", __func__
,
1857 ep
->mpa_attr
.crc_enabled
, ep
->mpa_attr
.recv_marker_enabled
,
1858 ep
->mpa_attr
.xmit_marker_enabled
, ep
->mpa_attr
.version
,
1859 ep
->mpa_attr
.p2p_type
);
1861 __state_set(&ep
->com
, MPA_REQ_RCVD
);
1864 mutex_lock_nested(&ep
->parent_ep
->com
.mutex
, SINGLE_DEPTH_NESTING
);
1865 if (ep
->parent_ep
->com
.state
!= DEAD
) {
1866 if (connect_request_upcall(ep
))
1867 goto err_unlock_parent
;
1869 goto err_unlock_parent
;
1871 mutex_unlock(&ep
->parent_ep
->com
.mutex
);
1875 mutex_unlock(&ep
->parent_ep
->com
.mutex
);
1878 (void)stop_ep_timer(ep
);
1883 static int rx_data(struct c4iw_dev
*dev
, struct sk_buff
*skb
)
1886 struct cpl_rx_data
*hdr
= cplhdr(skb
);
1887 unsigned int dlen
= ntohs(hdr
->len
);
1888 unsigned int tid
= GET_TID(hdr
);
1889 __u8 status
= hdr
->status
;
1892 ep
= get_ep_from_tid(dev
, tid
);
1895 PDBG("%s ep %p tid %u dlen %u\n", __func__
, ep
, ep
->hwtid
, dlen
);
1896 skb_pull(skb
, sizeof(*hdr
));
1897 skb_trim(skb
, dlen
);
1898 mutex_lock(&ep
->com
.mutex
);
1900 /* update RX credits */
1901 update_rx_credits(ep
, dlen
);
1903 switch (ep
->com
.state
) {
1905 ep
->rcv_seq
+= dlen
;
1906 disconnect
= process_mpa_reply(ep
, skb
);
1909 ep
->rcv_seq
+= dlen
;
1910 disconnect
= process_mpa_request(ep
, skb
);
1913 struct c4iw_qp_attributes attrs
;
1914 BUG_ON(!ep
->com
.qp
);
1916 pr_err("%s Unexpected streaming data." \
1917 " qpid %u ep %p state %d tid %u status %d\n",
1918 __func__
, ep
->com
.qp
->wq
.sq
.qid
, ep
,
1919 ep
->com
.state
, ep
->hwtid
, status
);
1920 attrs
.next_state
= C4IW_QP_STATE_TERMINATE
;
1921 c4iw_modify_qp(ep
->com
.qp
->rhp
, ep
->com
.qp
,
1922 C4IW_QP_ATTR_NEXT_STATE
, &attrs
, 1);
1929 mutex_unlock(&ep
->com
.mutex
);
1931 c4iw_ep_disconnect(ep
, disconnect
== 2, GFP_KERNEL
);
1932 c4iw_put_ep(&ep
->com
);
1936 static int abort_rpl(struct c4iw_dev
*dev
, struct sk_buff
*skb
)
1939 struct cpl_abort_rpl_rss
*rpl
= cplhdr(skb
);
1941 unsigned int tid
= GET_TID(rpl
);
1943 ep
= get_ep_from_tid(dev
, tid
);
1945 printk(KERN_WARNING MOD
"Abort rpl to freed endpoint\n");
1948 PDBG("%s ep %p tid %u\n", __func__
, ep
, ep
->hwtid
);
1949 mutex_lock(&ep
->com
.mutex
);
1950 switch (ep
->com
.state
) {
1952 c4iw_wake_up(&ep
->com
.wr_wait
, -ECONNRESET
);
1953 __state_set(&ep
->com
, DEAD
);
1957 printk(KERN_ERR
"%s ep %p state %d\n",
1958 __func__
, ep
, ep
->com
.state
);
1961 mutex_unlock(&ep
->com
.mutex
);
1964 release_ep_resources(ep
);
1965 c4iw_put_ep(&ep
->com
);
1969 static int send_fw_act_open_req(struct c4iw_ep
*ep
, unsigned int atid
)
1971 struct sk_buff
*skb
;
1972 struct fw_ofld_connection_wr
*req
;
1973 unsigned int mtu_idx
;
1975 struct sockaddr_in
*sin
;
1978 skb
= get_skb(NULL
, sizeof(*req
), GFP_KERNEL
);
1979 req
= (struct fw_ofld_connection_wr
*)__skb_put(skb
, sizeof(*req
));
1980 memset(req
, 0, sizeof(*req
));
1981 req
->op_compl
= htonl(WR_OP_V(FW_OFLD_CONNECTION_WR
));
1982 req
->len16_pkd
= htonl(FW_WR_LEN16_V(DIV_ROUND_UP(sizeof(*req
), 16)));
1983 req
->le
.filter
= cpu_to_be32(cxgb4_select_ntuple(
1984 ep
->com
.dev
->rdev
.lldi
.ports
[0],
1986 sin
= (struct sockaddr_in
*)&ep
->com
.local_addr
;
1987 req
->le
.lport
= sin
->sin_port
;
1988 req
->le
.u
.ipv4
.lip
= sin
->sin_addr
.s_addr
;
1989 sin
= (struct sockaddr_in
*)&ep
->com
.remote_addr
;
1990 req
->le
.pport
= sin
->sin_port
;
1991 req
->le
.u
.ipv4
.pip
= sin
->sin_addr
.s_addr
;
1992 req
->tcb
.t_state_to_astid
=
1993 htonl(FW_OFLD_CONNECTION_WR_T_STATE_V(TCP_SYN_SENT
) |
1994 FW_OFLD_CONNECTION_WR_ASTID_V(atid
));
1995 req
->tcb
.cplrxdataack_cplpassacceptrpl
=
1996 htons(FW_OFLD_CONNECTION_WR_CPLRXDATAACK_F
);
1997 req
->tcb
.tx_max
= (__force __be32
) jiffies
;
1998 req
->tcb
.rcv_adv
= htons(1);
1999 best_mtu(ep
->com
.dev
->rdev
.lldi
.mtus
, ep
->mtu
, &mtu_idx
,
2000 enable_tcp_timestamps
,
2001 (AF_INET
== ep
->com
.remote_addr
.ss_family
) ? 0 : 1);
2002 wscale
= compute_wscale(rcv_win
);
2005 * Specify the largest window that will fit in opt0. The
2006 * remainder will be specified in the rx_data_ack.
2008 win
= ep
->rcv_win
>> 10;
2009 if (win
> RCV_BUFSIZ_M
)
2012 req
->tcb
.opt0
= (__force __be64
) (TCAM_BYPASS_F
|
2013 (nocong
? NO_CONG_F
: 0) |
2016 WND_SCALE_V(wscale
) |
2017 MSS_IDX_V(mtu_idx
) |
2018 L2T_IDX_V(ep
->l2t
->idx
) |
2019 TX_CHAN_V(ep
->tx_chan
) |
2020 SMAC_SEL_V(ep
->smac_idx
) |
2021 DSCP_V(ep
->tos
>> 2) |
2022 ULP_MODE_V(ULP_MODE_TCPDDP
) |
2024 req
->tcb
.opt2
= (__force __be32
) (PACE_V(1) |
2025 TX_QUEUE_V(ep
->com
.dev
->rdev
.lldi
.tx_modq
[ep
->tx_chan
]) |
2027 CCTRL_ECN_V(enable_ecn
) |
2028 RSS_QUEUE_VALID_F
| RSS_QUEUE_V(ep
->rss_qid
));
2029 if (enable_tcp_timestamps
)
2030 req
->tcb
.opt2
|= (__force __be32
)TSTAMPS_EN_F
;
2031 if (enable_tcp_sack
)
2032 req
->tcb
.opt2
|= (__force __be32
)SACK_EN_F
;
2033 if (wscale
&& enable_tcp_window_scaling
)
2034 req
->tcb
.opt2
|= (__force __be32
)WND_SCALE_EN_F
;
2035 req
->tcb
.opt0
= cpu_to_be64((__force u64
)req
->tcb
.opt0
);
2036 req
->tcb
.opt2
= cpu_to_be32((__force u32
)req
->tcb
.opt2
);
2037 set_wr_txq(skb
, CPL_PRIORITY_CONTROL
, ep
->ctrlq_idx
);
2038 set_bit(ACT_OFLD_CONN
, &ep
->com
.history
);
2039 return c4iw_l2t_send(&ep
->com
.dev
->rdev
, skb
, ep
->l2t
);
2043 * Some of the error codes above implicitly indicate that there is no TID
2044 * allocated with the result of an ACT_OPEN. We use this predicate to make
2047 static inline int act_open_has_tid(int status
)
2049 return (status
!= CPL_ERR_TCAM_PARITY
&&
2050 status
!= CPL_ERR_TCAM_MISS
&&
2051 status
!= CPL_ERR_TCAM_FULL
&&
2052 status
!= CPL_ERR_CONN_EXIST_SYNRECV
&&
2053 status
!= CPL_ERR_CONN_EXIST
);
2056 /* Returns whether a CPL status conveys negative advice.
2058 static int is_neg_adv(unsigned int status
)
2060 return status
== CPL_ERR_RTX_NEG_ADVICE
||
2061 status
== CPL_ERR_PERSIST_NEG_ADVICE
||
2062 status
== CPL_ERR_KEEPALV_NEG_ADVICE
;
2065 static char *neg_adv_str(unsigned int status
)
2068 case CPL_ERR_RTX_NEG_ADVICE
:
2069 return "Retransmit timeout";
2070 case CPL_ERR_PERSIST_NEG_ADVICE
:
2071 return "Persist timeout";
2072 case CPL_ERR_KEEPALV_NEG_ADVICE
:
2073 return "Keepalive timeout";
2079 static void set_tcp_window(struct c4iw_ep
*ep
, struct port_info
*pi
)
2081 ep
->snd_win
= snd_win
;
2082 ep
->rcv_win
= rcv_win
;
2083 PDBG("%s snd_win %d rcv_win %d\n", __func__
, ep
->snd_win
, ep
->rcv_win
);
2086 #define ACT_OPEN_RETRY_COUNT 2
2088 static int import_ep(struct c4iw_ep
*ep
, int iptype
, __u8
*peer_ip
,
2089 struct dst_entry
*dst
, struct c4iw_dev
*cdev
,
2090 bool clear_mpa_v1
, enum chip_type adapter_type
, u8 tos
)
2092 struct neighbour
*n
;
2094 struct net_device
*pdev
;
2096 n
= dst_neigh_lookup(dst
, peer_ip
);
2102 if (n
->dev
->flags
& IFF_LOOPBACK
) {
2104 pdev
= ip_dev_find(&init_net
, *(__be32
*)peer_ip
);
2105 else if (IS_ENABLED(CONFIG_IPV6
))
2106 for_each_netdev(&init_net
, pdev
) {
2107 if (ipv6_chk_addr(&init_net
,
2108 (struct in6_addr
*)peer_ip
,
2119 ep
->l2t
= cxgb4_l2t_get(cdev
->rdev
.lldi
.l2t
,
2120 n
, pdev
, rt_tos2priority(tos
));
2123 ep
->mtu
= pdev
->mtu
;
2124 ep
->tx_chan
= cxgb4_port_chan(pdev
);
2125 ep
->smac_idx
= cxgb4_tp_smt_idx(adapter_type
,
2126 cxgb4_port_viid(pdev
));
2127 step
= cdev
->rdev
.lldi
.ntxq
/
2128 cdev
->rdev
.lldi
.nchan
;
2129 ep
->txq_idx
= cxgb4_port_idx(pdev
) * step
;
2130 step
= cdev
->rdev
.lldi
.nrxq
/
2131 cdev
->rdev
.lldi
.nchan
;
2132 ep
->ctrlq_idx
= cxgb4_port_idx(pdev
);
2133 ep
->rss_qid
= cdev
->rdev
.lldi
.rxq_ids
[
2134 cxgb4_port_idx(pdev
) * step
];
2135 set_tcp_window(ep
, (struct port_info
*)netdev_priv(pdev
));
2138 pdev
= get_real_dev(n
->dev
);
2139 ep
->l2t
= cxgb4_l2t_get(cdev
->rdev
.lldi
.l2t
,
2143 ep
->mtu
= dst_mtu(dst
);
2144 ep
->tx_chan
= cxgb4_port_chan(pdev
);
2145 ep
->smac_idx
= cxgb4_tp_smt_idx(adapter_type
,
2146 cxgb4_port_viid(pdev
));
2147 step
= cdev
->rdev
.lldi
.ntxq
/
2148 cdev
->rdev
.lldi
.nchan
;
2149 ep
->txq_idx
= cxgb4_port_idx(pdev
) * step
;
2150 ep
->ctrlq_idx
= cxgb4_port_idx(pdev
);
2151 step
= cdev
->rdev
.lldi
.nrxq
/
2152 cdev
->rdev
.lldi
.nchan
;
2153 ep
->rss_qid
= cdev
->rdev
.lldi
.rxq_ids
[
2154 cxgb4_port_idx(pdev
) * step
];
2155 set_tcp_window(ep
, (struct port_info
*)netdev_priv(pdev
));
2158 ep
->retry_with_mpa_v1
= 0;
2159 ep
->tried_with_mpa_v1
= 0;
2171 static int c4iw_reconnect(struct c4iw_ep
*ep
)
2175 struct sockaddr_in
*laddr
= (struct sockaddr_in
*)
2176 &ep
->com
.cm_id
->m_local_addr
;
2177 struct sockaddr_in
*raddr
= (struct sockaddr_in
*)
2178 &ep
->com
.cm_id
->m_remote_addr
;
2179 struct sockaddr_in6
*laddr6
= (struct sockaddr_in6
*)
2180 &ep
->com
.cm_id
->m_local_addr
;
2181 struct sockaddr_in6
*raddr6
= (struct sockaddr_in6
*)
2182 &ep
->com
.cm_id
->m_remote_addr
;
2186 PDBG("%s qp %p cm_id %p\n", __func__
, ep
->com
.qp
, ep
->com
.cm_id
);
2187 init_timer(&ep
->timer
);
2188 c4iw_init_wr_wait(&ep
->com
.wr_wait
);
2190 /* When MPA revision is different on nodes, the node with MPA_rev=2
2191 * tries to reconnect with MPA_rev 1 for the same EP through
2192 * c4iw_reconnect(), where the same EP is assigned with new tid for
2193 * further connection establishment. As we are using the same EP pointer
2194 * for reconnect, few skbs are used during the previous c4iw_connect(),
2195 * which leaves the EP with inadequate skbs for further
2196 * c4iw_reconnect(), Further causing an assert BUG_ON() due to empty
2197 * skb_list() during peer_abort(). Allocate skbs which is already used.
2199 size
= (CN_MAX_CON_BUF
- skb_queue_len(&ep
->com
.ep_skb_list
));
2200 if (alloc_ep_skb_list(&ep
->com
.ep_skb_list
, size
)) {
2206 * Allocate an active TID to initiate a TCP connection.
2208 ep
->atid
= cxgb4_alloc_atid(ep
->com
.dev
->rdev
.lldi
.tids
, ep
);
2209 if (ep
->atid
== -1) {
2210 pr_err("%s - cannot alloc atid.\n", __func__
);
2214 insert_handle(ep
->com
.dev
, &ep
->com
.dev
->atid_idr
, ep
, ep
->atid
);
2217 if (ep
->com
.cm_id
->m_local_addr
.ss_family
== AF_INET
) {
2218 ep
->dst
= find_route(ep
->com
.dev
, laddr
->sin_addr
.s_addr
,
2219 raddr
->sin_addr
.s_addr
, laddr
->sin_port
,
2220 raddr
->sin_port
, ep
->com
.cm_id
->tos
);
2222 ra
= (__u8
*)&raddr
->sin_addr
;
2224 ep
->dst
= find_route6(ep
->com
.dev
, laddr6
->sin6_addr
.s6_addr
,
2225 raddr6
->sin6_addr
.s6_addr
,
2226 laddr6
->sin6_port
, raddr6
->sin6_port
, 0,
2227 raddr6
->sin6_scope_id
);
2229 ra
= (__u8
*)&raddr6
->sin6_addr
;
2232 pr_err("%s - cannot find route.\n", __func__
);
2233 err
= -EHOSTUNREACH
;
2236 err
= import_ep(ep
, iptype
, ra
, ep
->dst
, ep
->com
.dev
, false,
2237 ep
->com
.dev
->rdev
.lldi
.adapter_type
,
2238 ep
->com
.cm_id
->tos
);
2240 pr_err("%s - cannot alloc l2e.\n", __func__
);
2244 PDBG("%s txq_idx %u tx_chan %u smac_idx %u rss_qid %u l2t_idx %u\n",
2245 __func__
, ep
->txq_idx
, ep
->tx_chan
, ep
->smac_idx
, ep
->rss_qid
,
2248 state_set(&ep
->com
, CONNECTING
);
2249 ep
->tos
= ep
->com
.cm_id
->tos
;
2251 /* send connect request to rnic */
2252 err
= send_connect(ep
);
2256 cxgb4_l2t_release(ep
->l2t
);
2258 dst_release(ep
->dst
);
2260 remove_handle(ep
->com
.dev
, &ep
->com
.dev
->atid_idr
, ep
->atid
);
2261 cxgb4_free_atid(ep
->com
.dev
->rdev
.lldi
.tids
, ep
->atid
);
2264 * remember to send notification to upper layer.
2265 * We are in here so the upper layer is not aware that this is
2266 * re-connect attempt and so, upper layer is still waiting for
2267 * response of 1st connect request.
2269 connect_reply_upcall(ep
, -ECONNRESET
);
2271 c4iw_put_ep(&ep
->com
);
2276 static int act_open_rpl(struct c4iw_dev
*dev
, struct sk_buff
*skb
)
2279 struct cpl_act_open_rpl
*rpl
= cplhdr(skb
);
2280 unsigned int atid
= TID_TID_G(AOPEN_ATID_G(
2281 ntohl(rpl
->atid_status
)));
2282 struct tid_info
*t
= dev
->rdev
.lldi
.tids
;
2283 int status
= AOPEN_STATUS_G(ntohl(rpl
->atid_status
));
2284 struct sockaddr_in
*la
;
2285 struct sockaddr_in
*ra
;
2286 struct sockaddr_in6
*la6
;
2287 struct sockaddr_in6
*ra6
;
2290 ep
= lookup_atid(t
, atid
);
2291 la
= (struct sockaddr_in
*)&ep
->com
.local_addr
;
2292 ra
= (struct sockaddr_in
*)&ep
->com
.remote_addr
;
2293 la6
= (struct sockaddr_in6
*)&ep
->com
.local_addr
;
2294 ra6
= (struct sockaddr_in6
*)&ep
->com
.remote_addr
;
2296 PDBG("%s ep %p atid %u status %u errno %d\n", __func__
, ep
, atid
,
2297 status
, status2errno(status
));
2299 if (is_neg_adv(status
)) {
2300 PDBG("%s Connection problems for atid %u status %u (%s)\n",
2301 __func__
, atid
, status
, neg_adv_str(status
));
2302 ep
->stats
.connect_neg_adv
++;
2303 mutex_lock(&dev
->rdev
.stats
.lock
);
2304 dev
->rdev
.stats
.neg_adv
++;
2305 mutex_unlock(&dev
->rdev
.stats
.lock
);
2309 set_bit(ACT_OPEN_RPL
, &ep
->com
.history
);
2312 * Log interesting failures.
2315 case CPL_ERR_CONN_RESET
:
2316 case CPL_ERR_CONN_TIMEDOUT
:
2318 case CPL_ERR_TCAM_FULL
:
2319 mutex_lock(&dev
->rdev
.stats
.lock
);
2320 dev
->rdev
.stats
.tcam_full
++;
2321 mutex_unlock(&dev
->rdev
.stats
.lock
);
2322 if (ep
->com
.local_addr
.ss_family
== AF_INET
&&
2323 dev
->rdev
.lldi
.enable_fw_ofld_conn
) {
2324 ret
= send_fw_act_open_req(ep
, TID_TID_G(AOPEN_ATID_G(
2325 ntohl(rpl
->atid_status
))));
2331 case CPL_ERR_CONN_EXIST
:
2332 if (ep
->retry_count
++ < ACT_OPEN_RETRY_COUNT
) {
2333 set_bit(ACT_RETRY_INUSE
, &ep
->com
.history
);
2334 if (ep
->com
.remote_addr
.ss_family
== AF_INET6
) {
2335 struct sockaddr_in6
*sin6
=
2336 (struct sockaddr_in6
*)
2337 &ep
->com
.local_addr
;
2339 ep
->com
.dev
->rdev
.lldi
.ports
[0],
2341 &sin6
->sin6_addr
.s6_addr
, 1);
2343 remove_handle(ep
->com
.dev
, &ep
->com
.dev
->atid_idr
,
2345 cxgb4_free_atid(t
, atid
);
2346 dst_release(ep
->dst
);
2347 cxgb4_l2t_release(ep
->l2t
);
2353 if (ep
->com
.local_addr
.ss_family
== AF_INET
) {
2354 pr_info("Active open failure - atid %u status %u errno %d %pI4:%u->%pI4:%u\n",
2355 atid
, status
, status2errno(status
),
2356 &la
->sin_addr
.s_addr
, ntohs(la
->sin_port
),
2357 &ra
->sin_addr
.s_addr
, ntohs(ra
->sin_port
));
2359 pr_info("Active open failure - atid %u status %u errno %d %pI6:%u->%pI6:%u\n",
2360 atid
, status
, status2errno(status
),
2361 la6
->sin6_addr
.s6_addr
, ntohs(la6
->sin6_port
),
2362 ra6
->sin6_addr
.s6_addr
, ntohs(ra6
->sin6_port
));
2368 connect_reply_upcall(ep
, status2errno(status
));
2369 state_set(&ep
->com
, DEAD
);
2371 if (ep
->com
.remote_addr
.ss_family
== AF_INET6
) {
2372 struct sockaddr_in6
*sin6
=
2373 (struct sockaddr_in6
*)&ep
->com
.local_addr
;
2374 cxgb4_clip_release(ep
->com
.dev
->rdev
.lldi
.ports
[0],
2375 (const u32
*)&sin6
->sin6_addr
.s6_addr
, 1);
2377 if (status
&& act_open_has_tid(status
))
2378 cxgb4_remove_tid(ep
->com
.dev
->rdev
.lldi
.tids
, 0, GET_TID(rpl
));
2380 remove_handle(ep
->com
.dev
, &ep
->com
.dev
->atid_idr
, atid
);
2381 cxgb4_free_atid(t
, atid
);
2382 dst_release(ep
->dst
);
2383 cxgb4_l2t_release(ep
->l2t
);
2384 c4iw_put_ep(&ep
->com
);
2389 static int pass_open_rpl(struct c4iw_dev
*dev
, struct sk_buff
*skb
)
2391 struct cpl_pass_open_rpl
*rpl
= cplhdr(skb
);
2392 unsigned int stid
= GET_TID(rpl
);
2393 struct c4iw_listen_ep
*ep
= get_ep_from_stid(dev
, stid
);
2396 PDBG("%s stid %d lookup failure!\n", __func__
, stid
);
2399 PDBG("%s ep %p status %d error %d\n", __func__
, ep
,
2400 rpl
->status
, status2errno(rpl
->status
));
2401 c4iw_wake_up(&ep
->com
.wr_wait
, status2errno(rpl
->status
));
2402 c4iw_put_ep(&ep
->com
);
2407 static int close_listsrv_rpl(struct c4iw_dev
*dev
, struct sk_buff
*skb
)
2409 struct cpl_close_listsvr_rpl
*rpl
= cplhdr(skb
);
2410 unsigned int stid
= GET_TID(rpl
);
2411 struct c4iw_listen_ep
*ep
= get_ep_from_stid(dev
, stid
);
2413 PDBG("%s ep %p\n", __func__
, ep
);
2414 c4iw_wake_up(&ep
->com
.wr_wait
, status2errno(rpl
->status
));
2415 c4iw_put_ep(&ep
->com
);
2419 static int accept_cr(struct c4iw_ep
*ep
, struct sk_buff
*skb
,
2420 struct cpl_pass_accept_req
*req
)
2422 struct cpl_pass_accept_rpl
*rpl
;
2423 unsigned int mtu_idx
;
2427 struct cpl_t5_pass_accept_rpl
*rpl5
= NULL
;
2429 enum chip_type adapter_type
= ep
->com
.dev
->rdev
.lldi
.adapter_type
;
2431 PDBG("%s ep %p tid %u\n", __func__
, ep
, ep
->hwtid
);
2432 BUG_ON(skb_cloned(skb
));
2436 if (!is_t4(adapter_type
)) {
2437 skb_trim(skb
, roundup(sizeof(*rpl5
), 16));
2439 INIT_TP_WR(rpl5
, ep
->hwtid
);
2441 skb_trim(skb
, sizeof(*rpl
));
2442 INIT_TP_WR(rpl
, ep
->hwtid
);
2444 OPCODE_TID(rpl
) = cpu_to_be32(MK_OPCODE_TID(CPL_PASS_ACCEPT_RPL
,
2447 best_mtu(ep
->com
.dev
->rdev
.lldi
.mtus
, ep
->mtu
, &mtu_idx
,
2448 enable_tcp_timestamps
&& req
->tcpopt
.tstamp
,
2449 (AF_INET
== ep
->com
.remote_addr
.ss_family
) ? 0 : 1);
2450 wscale
= compute_wscale(rcv_win
);
2453 * Specify the largest window that will fit in opt0. The
2454 * remainder will be specified in the rx_data_ack.
2456 win
= ep
->rcv_win
>> 10;
2457 if (win
> RCV_BUFSIZ_M
)
2459 opt0
= (nocong
? NO_CONG_F
: 0) |
2462 WND_SCALE_V(wscale
) |
2463 MSS_IDX_V(mtu_idx
) |
2464 L2T_IDX_V(ep
->l2t
->idx
) |
2465 TX_CHAN_V(ep
->tx_chan
) |
2466 SMAC_SEL_V(ep
->smac_idx
) |
2467 DSCP_V(ep
->tos
>> 2) |
2468 ULP_MODE_V(ULP_MODE_TCPDDP
) |
2470 opt2
= RX_CHANNEL_V(0) |
2471 RSS_QUEUE_VALID_F
| RSS_QUEUE_V(ep
->rss_qid
);
2473 if (enable_tcp_timestamps
&& req
->tcpopt
.tstamp
)
2474 opt2
|= TSTAMPS_EN_F
;
2475 if (enable_tcp_sack
&& req
->tcpopt
.sack
)
2477 if (wscale
&& enable_tcp_window_scaling
)
2478 opt2
|= WND_SCALE_EN_F
;
2480 const struct tcphdr
*tcph
;
2481 u32 hlen
= ntohl(req
->hdr_len
);
2483 if (CHELSIO_CHIP_VERSION(adapter_type
) <= CHELSIO_T5
)
2484 tcph
= (const void *)(req
+ 1) + ETH_HDR_LEN_G(hlen
) +
2487 tcph
= (const void *)(req
+ 1) +
2488 T6_ETH_HDR_LEN_G(hlen
) + T6_IP_HDR_LEN_G(hlen
);
2489 if (tcph
->ece
&& tcph
->cwr
)
2490 opt2
|= CCTRL_ECN_V(1);
2492 if (CHELSIO_CHIP_VERSION(adapter_type
) > CHELSIO_T4
) {
2493 u32 isn
= (prandom_u32() & ~7UL) - 1;
2494 opt2
|= T5_OPT_2_VALID_F
;
2495 opt2
|= CONG_CNTRL_V(CONG_ALG_TAHOE
);
2498 memset(&rpl5
->iss
, 0, roundup(sizeof(*rpl5
)-sizeof(*rpl
), 16));
2501 rpl5
->iss
= cpu_to_be32(isn
);
2502 PDBG("%s iss %u\n", __func__
, be32_to_cpu(rpl5
->iss
));
2505 rpl
->opt0
= cpu_to_be64(opt0
);
2506 rpl
->opt2
= cpu_to_be32(opt2
);
2507 set_wr_txq(skb
, CPL_PRIORITY_SETUP
, ep
->ctrlq_idx
);
2508 t4_set_arp_err_handler(skb
, ep
, pass_accept_rpl_arp_failure
);
2510 return c4iw_l2t_send(&ep
->com
.dev
->rdev
, skb
, ep
->l2t
);
2513 static void reject_cr(struct c4iw_dev
*dev
, u32 hwtid
, struct sk_buff
*skb
)
2515 PDBG("%s c4iw_dev %p tid %u\n", __func__
, dev
, hwtid
);
2516 BUG_ON(skb_cloned(skb
));
2517 skb_trim(skb
, sizeof(struct cpl_tid_release
));
2518 release_tid(&dev
->rdev
, hwtid
, skb
);
2522 static int pass_accept_req(struct c4iw_dev
*dev
, struct sk_buff
*skb
)
2524 struct c4iw_ep
*child_ep
= NULL
, *parent_ep
;
2525 struct cpl_pass_accept_req
*req
= cplhdr(skb
);
2526 unsigned int stid
= PASS_OPEN_TID_G(ntohl(req
->tos_stid
));
2527 struct tid_info
*t
= dev
->rdev
.lldi
.tids
;
2528 unsigned int hwtid
= GET_TID(req
);
2529 struct dst_entry
*dst
;
2530 __u8 local_ip
[16], peer_ip
[16];
2531 __be16 local_port
, peer_port
;
2532 struct sockaddr_in6
*sin6
;
2534 u16 peer_mss
= ntohs(req
->tcpopt
.mss
);
2536 unsigned short hdrs
;
2537 u8 tos
= PASS_OPEN_TOS_G(ntohl(req
->tos_stid
));
2539 parent_ep
= (struct c4iw_ep
*)get_ep_from_stid(dev
, stid
);
2541 PDBG("%s connect request on invalid stid %d\n", __func__
, stid
);
2545 if (state_read(&parent_ep
->com
) != LISTEN
) {
2546 PDBG("%s - listening ep not in LISTEN\n", __func__
);
2550 cxgb_get_4tuple(req
, parent_ep
->com
.dev
->rdev
.lldi
.adapter_type
,
2551 &iptype
, local_ip
, peer_ip
, &local_port
, &peer_port
);
2553 /* Find output route */
2555 PDBG("%s parent ep %p hwtid %u laddr %pI4 raddr %pI4 lport %d rport %d peer_mss %d\n"
2556 , __func__
, parent_ep
, hwtid
,
2557 local_ip
, peer_ip
, ntohs(local_port
),
2558 ntohs(peer_port
), peer_mss
);
2559 dst
= find_route(dev
, *(__be32
*)local_ip
, *(__be32
*)peer_ip
,
2560 local_port
, peer_port
,
2563 PDBG("%s parent ep %p hwtid %u laddr %pI6 raddr %pI6 lport %d rport %d peer_mss %d\n"
2564 , __func__
, parent_ep
, hwtid
,
2565 local_ip
, peer_ip
, ntohs(local_port
),
2566 ntohs(peer_port
), peer_mss
);
2567 dst
= find_route6(dev
, local_ip
, peer_ip
, local_port
, peer_port
,
2568 PASS_OPEN_TOS_G(ntohl(req
->tos_stid
)),
2569 ((struct sockaddr_in6
*)
2570 &parent_ep
->com
.local_addr
)->sin6_scope_id
);
2573 printk(KERN_ERR MOD
"%s - failed to find dst entry!\n",
2578 child_ep
= alloc_ep(sizeof(*child_ep
), GFP_KERNEL
);
2580 printk(KERN_ERR MOD
"%s - failed to allocate ep entry!\n",
2586 err
= import_ep(child_ep
, iptype
, peer_ip
, dst
, dev
, false,
2587 parent_ep
->com
.dev
->rdev
.lldi
.adapter_type
, tos
);
2589 printk(KERN_ERR MOD
"%s - failed to allocate l2t entry!\n",
2596 hdrs
= sizeof(struct iphdr
) + sizeof(struct tcphdr
) +
2597 ((enable_tcp_timestamps
&& req
->tcpopt
.tstamp
) ? 12 : 0);
2598 if (peer_mss
&& child_ep
->mtu
> (peer_mss
+ hdrs
))
2599 child_ep
->mtu
= peer_mss
+ hdrs
;
2601 skb_queue_head_init(&child_ep
->com
.ep_skb_list
);
2602 if (alloc_ep_skb_list(&child_ep
->com
.ep_skb_list
, CN_MAX_CON_BUF
))
2605 state_set(&child_ep
->com
, CONNECTING
);
2606 child_ep
->com
.dev
= dev
;
2607 child_ep
->com
.cm_id
= NULL
;
2610 struct sockaddr_in
*sin
= (struct sockaddr_in
*)
2611 &child_ep
->com
.local_addr
;
2613 sin
->sin_family
= PF_INET
;
2614 sin
->sin_port
= local_port
;
2615 sin
->sin_addr
.s_addr
= *(__be32
*)local_ip
;
2617 sin
= (struct sockaddr_in
*)&child_ep
->com
.local_addr
;
2618 sin
->sin_family
= PF_INET
;
2619 sin
->sin_port
= ((struct sockaddr_in
*)
2620 &parent_ep
->com
.local_addr
)->sin_port
;
2621 sin
->sin_addr
.s_addr
= *(__be32
*)local_ip
;
2623 sin
= (struct sockaddr_in
*)&child_ep
->com
.remote_addr
;
2624 sin
->sin_family
= PF_INET
;
2625 sin
->sin_port
= peer_port
;
2626 sin
->sin_addr
.s_addr
= *(__be32
*)peer_ip
;
2628 sin6
= (struct sockaddr_in6
*)&child_ep
->com
.local_addr
;
2629 sin6
->sin6_family
= PF_INET6
;
2630 sin6
->sin6_port
= local_port
;
2631 memcpy(sin6
->sin6_addr
.s6_addr
, local_ip
, 16);
2633 sin6
= (struct sockaddr_in6
*)&child_ep
->com
.local_addr
;
2634 sin6
->sin6_family
= PF_INET6
;
2635 sin6
->sin6_port
= ((struct sockaddr_in6
*)
2636 &parent_ep
->com
.local_addr
)->sin6_port
;
2637 memcpy(sin6
->sin6_addr
.s6_addr
, local_ip
, 16);
2639 sin6
= (struct sockaddr_in6
*)&child_ep
->com
.remote_addr
;
2640 sin6
->sin6_family
= PF_INET6
;
2641 sin6
->sin6_port
= peer_port
;
2642 memcpy(sin6
->sin6_addr
.s6_addr
, peer_ip
, 16);
2645 c4iw_get_ep(&parent_ep
->com
);
2646 child_ep
->parent_ep
= parent_ep
;
2647 child_ep
->tos
= tos
;
2648 child_ep
->dst
= dst
;
2649 child_ep
->hwtid
= hwtid
;
2651 PDBG("%s tx_chan %u smac_idx %u rss_qid %u\n", __func__
,
2652 child_ep
->tx_chan
, child_ep
->smac_idx
, child_ep
->rss_qid
);
2654 init_timer(&child_ep
->timer
);
2655 cxgb4_insert_tid(t
, child_ep
, hwtid
);
2656 insert_ep_tid(child_ep
);
2657 if (accept_cr(child_ep
, skb
, req
)) {
2658 c4iw_put_ep(&parent_ep
->com
);
2659 release_ep_resources(child_ep
);
2661 set_bit(PASS_ACCEPT_REQ
, &child_ep
->com
.history
);
2664 sin6
= (struct sockaddr_in6
*)&child_ep
->com
.local_addr
;
2665 cxgb4_clip_get(child_ep
->com
.dev
->rdev
.lldi
.ports
[0],
2666 (const u32
*)&sin6
->sin6_addr
.s6_addr
, 1);
2670 c4iw_put_ep(&child_ep
->com
);
2672 reject_cr(dev
, hwtid
, skb
);
2674 c4iw_put_ep(&parent_ep
->com
);
2679 static int pass_establish(struct c4iw_dev
*dev
, struct sk_buff
*skb
)
2682 struct cpl_pass_establish
*req
= cplhdr(skb
);
2683 unsigned int tid
= GET_TID(req
);
2686 ep
= get_ep_from_tid(dev
, tid
);
2687 PDBG("%s ep %p tid %u\n", __func__
, ep
, ep
->hwtid
);
2688 ep
->snd_seq
= be32_to_cpu(req
->snd_isn
);
2689 ep
->rcv_seq
= be32_to_cpu(req
->rcv_isn
);
2691 PDBG("%s ep %p hwtid %u tcp_opt 0x%02x\n", __func__
, ep
, tid
,
2692 ntohs(req
->tcp_opt
));
2694 set_emss(ep
, ntohs(req
->tcp_opt
));
2696 dst_confirm(ep
->dst
);
2697 mutex_lock(&ep
->com
.mutex
);
2698 ep
->com
.state
= MPA_REQ_WAIT
;
2700 set_bit(PASS_ESTAB
, &ep
->com
.history
);
2701 ret
= send_flowc(ep
);
2702 mutex_unlock(&ep
->com
.mutex
);
2704 c4iw_ep_disconnect(ep
, 1, GFP_KERNEL
);
2705 c4iw_put_ep(&ep
->com
);
2710 static int peer_close(struct c4iw_dev
*dev
, struct sk_buff
*skb
)
2712 struct cpl_peer_close
*hdr
= cplhdr(skb
);
2714 struct c4iw_qp_attributes attrs
;
2717 unsigned int tid
= GET_TID(hdr
);
2720 ep
= get_ep_from_tid(dev
, tid
);
2724 PDBG("%s ep %p tid %u\n", __func__
, ep
, ep
->hwtid
);
2725 dst_confirm(ep
->dst
);
2727 set_bit(PEER_CLOSE
, &ep
->com
.history
);
2728 mutex_lock(&ep
->com
.mutex
);
2729 switch (ep
->com
.state
) {
2731 __state_set(&ep
->com
, CLOSING
);
2734 __state_set(&ep
->com
, CLOSING
);
2735 connect_reply_upcall(ep
, -ECONNRESET
);
2740 * We're gonna mark this puppy DEAD, but keep
2741 * the reference on it until the ULP accepts or
2742 * rejects the CR. Also wake up anyone waiting
2743 * in rdma connection migration (see c4iw_accept_cr()).
2745 __state_set(&ep
->com
, CLOSING
);
2746 PDBG("waking up ep %p tid %u\n", ep
, ep
->hwtid
);
2747 c4iw_wake_up(&ep
->com
.wr_wait
, -ECONNRESET
);
2750 __state_set(&ep
->com
, CLOSING
);
2751 PDBG("waking up ep %p tid %u\n", ep
, ep
->hwtid
);
2752 c4iw_wake_up(&ep
->com
.wr_wait
, -ECONNRESET
);
2756 __state_set(&ep
->com
, CLOSING
);
2757 attrs
.next_state
= C4IW_QP_STATE_CLOSING
;
2758 ret
= c4iw_modify_qp(ep
->com
.qp
->rhp
, ep
->com
.qp
,
2759 C4IW_QP_ATTR_NEXT_STATE
, &attrs
, 1);
2760 if (ret
!= -ECONNRESET
) {
2761 peer_close_upcall(ep
);
2769 __state_set(&ep
->com
, MORIBUND
);
2773 (void)stop_ep_timer(ep
);
2774 if (ep
->com
.cm_id
&& ep
->com
.qp
) {
2775 attrs
.next_state
= C4IW_QP_STATE_IDLE
;
2776 c4iw_modify_qp(ep
->com
.qp
->rhp
, ep
->com
.qp
,
2777 C4IW_QP_ATTR_NEXT_STATE
, &attrs
, 1);
2779 close_complete_upcall(ep
, 0);
2780 __state_set(&ep
->com
, DEAD
);
2790 mutex_unlock(&ep
->com
.mutex
);
2792 c4iw_ep_disconnect(ep
, 0, GFP_KERNEL
);
2794 release_ep_resources(ep
);
2795 c4iw_put_ep(&ep
->com
);
2799 static int peer_abort(struct c4iw_dev
*dev
, struct sk_buff
*skb
)
2801 struct cpl_abort_req_rss
*req
= cplhdr(skb
);
2803 struct cpl_abort_rpl
*rpl
;
2804 struct sk_buff
*rpl_skb
;
2805 struct c4iw_qp_attributes attrs
;
2808 unsigned int tid
= GET_TID(req
);
2810 ep
= get_ep_from_tid(dev
, tid
);
2814 if (is_neg_adv(req
->status
)) {
2815 PDBG("%s Negative advice on abort- tid %u status %d (%s)\n",
2816 __func__
, ep
->hwtid
, req
->status
,
2817 neg_adv_str(req
->status
));
2818 ep
->stats
.abort_neg_adv
++;
2819 mutex_lock(&dev
->rdev
.stats
.lock
);
2820 dev
->rdev
.stats
.neg_adv
++;
2821 mutex_unlock(&dev
->rdev
.stats
.lock
);
2824 PDBG("%s ep %p tid %u state %u\n", __func__
, ep
, ep
->hwtid
,
2826 set_bit(PEER_ABORT
, &ep
->com
.history
);
2829 * Wake up any threads in rdma_init() or rdma_fini().
2830 * However, this is not needed if com state is just
2833 if (ep
->com
.state
!= MPA_REQ_SENT
)
2834 c4iw_wake_up(&ep
->com
.wr_wait
, -ECONNRESET
);
2836 mutex_lock(&ep
->com
.mutex
);
2837 switch (ep
->com
.state
) {
2839 c4iw_put_ep(&ep
->parent_ep
->com
);
2842 (void)stop_ep_timer(ep
);
2845 (void)stop_ep_timer(ep
);
2846 if (mpa_rev
== 1 || (mpa_rev
== 2 && ep
->tried_with_mpa_v1
))
2847 connect_reply_upcall(ep
, -ECONNRESET
);
2850 * we just don't send notification upwards because we
2851 * want to retry with mpa_v1 without upper layers even
2854 * do some housekeeping so as to re-initiate the
2857 PDBG("%s: mpa_rev=%d. Retrying with mpav1\n", __func__
,
2859 ep
->retry_with_mpa_v1
= 1;
2871 if (ep
->com
.cm_id
&& ep
->com
.qp
) {
2872 attrs
.next_state
= C4IW_QP_STATE_ERROR
;
2873 ret
= c4iw_modify_qp(ep
->com
.qp
->rhp
,
2874 ep
->com
.qp
, C4IW_QP_ATTR_NEXT_STATE
,
2878 "%s - qp <- error failed!\n",
2881 peer_abort_upcall(ep
);
2886 PDBG("%s PEER_ABORT IN DEAD STATE!!!!\n", __func__
);
2887 mutex_unlock(&ep
->com
.mutex
);
2893 dst_confirm(ep
->dst
);
2894 if (ep
->com
.state
!= ABORTING
) {
2895 __state_set(&ep
->com
, DEAD
);
2896 /* we don't release if we want to retry with mpa_v1 */
2897 if (!ep
->retry_with_mpa_v1
)
2900 mutex_unlock(&ep
->com
.mutex
);
2902 rpl_skb
= skb_dequeue(&ep
->com
.ep_skb_list
);
2903 if (WARN_ON(!rpl_skb
)) {
2907 set_wr_txq(skb
, CPL_PRIORITY_DATA
, ep
->txq_idx
);
2908 rpl
= (struct cpl_abort_rpl
*) skb_put(rpl_skb
, sizeof(*rpl
));
2909 INIT_TP_WR(rpl
, ep
->hwtid
);
2910 OPCODE_TID(rpl
) = cpu_to_be32(MK_OPCODE_TID(CPL_ABORT_RPL
, ep
->hwtid
));
2911 rpl
->cmd
= CPL_ABORT_NO_RST
;
2912 c4iw_ofld_send(&ep
->com
.dev
->rdev
, rpl_skb
);
2915 release_ep_resources(ep
);
2916 else if (ep
->retry_with_mpa_v1
) {
2917 if (ep
->com
.remote_addr
.ss_family
== AF_INET6
) {
2918 struct sockaddr_in6
*sin6
=
2919 (struct sockaddr_in6
*)
2920 &ep
->com
.local_addr
;
2922 ep
->com
.dev
->rdev
.lldi
.ports
[0],
2923 (const u32
*)&sin6
->sin6_addr
.s6_addr
,
2926 remove_handle(ep
->com
.dev
, &ep
->com
.dev
->hwtid_idr
, ep
->hwtid
);
2927 cxgb4_remove_tid(ep
->com
.dev
->rdev
.lldi
.tids
, 0, ep
->hwtid
);
2928 dst_release(ep
->dst
);
2929 cxgb4_l2t_release(ep
->l2t
);
2934 c4iw_put_ep(&ep
->com
);
2935 /* Dereferencing ep, referenced in peer_abort_intr() */
2936 c4iw_put_ep(&ep
->com
);
2940 static int close_con_rpl(struct c4iw_dev
*dev
, struct sk_buff
*skb
)
2943 struct c4iw_qp_attributes attrs
;
2944 struct cpl_close_con_rpl
*rpl
= cplhdr(skb
);
2946 unsigned int tid
= GET_TID(rpl
);
2948 ep
= get_ep_from_tid(dev
, tid
);
2952 PDBG("%s ep %p tid %u\n", __func__
, ep
, ep
->hwtid
);
2955 /* The cm_id may be null if we failed to connect */
2956 mutex_lock(&ep
->com
.mutex
);
2957 set_bit(CLOSE_CON_RPL
, &ep
->com
.history
);
2958 switch (ep
->com
.state
) {
2960 __state_set(&ep
->com
, MORIBUND
);
2963 (void)stop_ep_timer(ep
);
2964 if ((ep
->com
.cm_id
) && (ep
->com
.qp
)) {
2965 attrs
.next_state
= C4IW_QP_STATE_IDLE
;
2966 c4iw_modify_qp(ep
->com
.qp
->rhp
,
2968 C4IW_QP_ATTR_NEXT_STATE
,
2971 close_complete_upcall(ep
, 0);
2972 __state_set(&ep
->com
, DEAD
);
2982 mutex_unlock(&ep
->com
.mutex
);
2984 release_ep_resources(ep
);
2985 c4iw_put_ep(&ep
->com
);
2989 static int terminate(struct c4iw_dev
*dev
, struct sk_buff
*skb
)
2991 struct cpl_rdma_terminate
*rpl
= cplhdr(skb
);
2992 unsigned int tid
= GET_TID(rpl
);
2994 struct c4iw_qp_attributes attrs
;
2996 ep
= get_ep_from_tid(dev
, tid
);
2999 if (ep
&& ep
->com
.qp
) {
3000 printk(KERN_WARNING MOD
"TERM received tid %u qpid %u\n", tid
,
3001 ep
->com
.qp
->wq
.sq
.qid
);
3002 attrs
.next_state
= C4IW_QP_STATE_TERMINATE
;
3003 c4iw_modify_qp(ep
->com
.qp
->rhp
, ep
->com
.qp
,
3004 C4IW_QP_ATTR_NEXT_STATE
, &attrs
, 1);
3006 printk(KERN_WARNING MOD
"TERM received tid %u no ep/qp\n", tid
);
3007 c4iw_put_ep(&ep
->com
);
3013 * Upcall from the adapter indicating data has been transmitted.
3014 * For us its just the single MPA request or reply. We can now free
3015 * the skb holding the mpa message.
3017 static int fw4_ack(struct c4iw_dev
*dev
, struct sk_buff
*skb
)
3020 struct cpl_fw4_ack
*hdr
= cplhdr(skb
);
3021 u8 credits
= hdr
->credits
;
3022 unsigned int tid
= GET_TID(hdr
);
3025 ep
= get_ep_from_tid(dev
, tid
);
3028 PDBG("%s ep %p tid %u credits %u\n", __func__
, ep
, ep
->hwtid
, credits
);
3030 PDBG("%s 0 credit ack ep %p tid %u state %u\n",
3031 __func__
, ep
, ep
->hwtid
, state_read(&ep
->com
));
3035 dst_confirm(ep
->dst
);
3037 PDBG("%s last streaming msg ack ep %p tid %u state %u "
3038 "initiator %u freeing skb\n", __func__
, ep
, ep
->hwtid
,
3039 state_read(&ep
->com
), ep
->mpa_attr
.initiator
? 1 : 0);
3040 mutex_lock(&ep
->com
.mutex
);
3041 kfree_skb(ep
->mpa_skb
);
3043 if (test_bit(STOP_MPA_TIMER
, &ep
->com
.flags
))
3045 mutex_unlock(&ep
->com
.mutex
);
3048 c4iw_put_ep(&ep
->com
);
3052 int c4iw_reject_cr(struct iw_cm_id
*cm_id
, const void *pdata
, u8 pdata_len
)
3055 struct c4iw_ep
*ep
= to_ep(cm_id
);
3057 PDBG("%s ep %p tid %u\n", __func__
, ep
, ep
->hwtid
);
3059 mutex_lock(&ep
->com
.mutex
);
3060 if (ep
->com
.state
!= MPA_REQ_RCVD
) {
3061 mutex_unlock(&ep
->com
.mutex
);
3062 c4iw_put_ep(&ep
->com
);
3065 set_bit(ULP_REJECT
, &ep
->com
.history
);
3069 abort
= send_mpa_reject(ep
, pdata
, pdata_len
);
3070 mutex_unlock(&ep
->com
.mutex
);
3073 c4iw_ep_disconnect(ep
, abort
!= 0, GFP_KERNEL
);
3074 c4iw_put_ep(&ep
->com
);
3078 int c4iw_accept_cr(struct iw_cm_id
*cm_id
, struct iw_cm_conn_param
*conn_param
)
3081 struct c4iw_qp_attributes attrs
;
3082 enum c4iw_qp_attr_mask mask
;
3083 struct c4iw_ep
*ep
= to_ep(cm_id
);
3084 struct c4iw_dev
*h
= to_c4iw_dev(cm_id
->device
);
3085 struct c4iw_qp
*qp
= get_qhp(h
, conn_param
->qpn
);
3088 PDBG("%s ep %p tid %u\n", __func__
, ep
, ep
->hwtid
);
3090 mutex_lock(&ep
->com
.mutex
);
3091 if (ep
->com
.state
!= MPA_REQ_RCVD
) {
3098 set_bit(ULP_ACCEPT
, &ep
->com
.history
);
3099 if ((conn_param
->ord
> cur_max_read_depth(ep
->com
.dev
)) ||
3100 (conn_param
->ird
> cur_max_read_depth(ep
->com
.dev
))) {
3105 if (ep
->mpa_attr
.version
== 2 && ep
->mpa_attr
.enhanced_rdma_conn
) {
3106 if (conn_param
->ord
> ep
->ird
) {
3107 if (RELAXED_IRD_NEGOTIATION
) {
3108 conn_param
->ord
= ep
->ird
;
3110 ep
->ird
= conn_param
->ird
;
3111 ep
->ord
= conn_param
->ord
;
3112 send_mpa_reject(ep
, conn_param
->private_data
,
3113 conn_param
->private_data_len
);
3118 if (conn_param
->ird
< ep
->ord
) {
3119 if (RELAXED_IRD_NEGOTIATION
&&
3120 ep
->ord
<= h
->rdev
.lldi
.max_ordird_qp
) {
3121 conn_param
->ird
= ep
->ord
;
3128 ep
->ird
= conn_param
->ird
;
3129 ep
->ord
= conn_param
->ord
;
3131 if (ep
->mpa_attr
.version
== 1) {
3132 if (peer2peer
&& ep
->ird
== 0)
3136 (ep
->mpa_attr
.p2p_type
!= FW_RI_INIT_P2PTYPE_DISABLED
) &&
3137 (p2p_type
== FW_RI_INIT_P2PTYPE_READ_REQ
) && ep
->ird
== 0)
3141 PDBG("%s %d ird %d ord %d\n", __func__
, __LINE__
, ep
->ird
, ep
->ord
);
3143 ep
->com
.cm_id
= cm_id
;
3144 ref_cm_id(&ep
->com
);
3148 /* bind QP to EP and move to RTS */
3149 attrs
.mpa_attr
= ep
->mpa_attr
;
3150 attrs
.max_ird
= ep
->ird
;
3151 attrs
.max_ord
= ep
->ord
;
3152 attrs
.llp_stream_handle
= ep
;
3153 attrs
.next_state
= C4IW_QP_STATE_RTS
;
3155 /* bind QP and TID with INIT_WR */
3156 mask
= C4IW_QP_ATTR_NEXT_STATE
|
3157 C4IW_QP_ATTR_LLP_STREAM_HANDLE
|
3158 C4IW_QP_ATTR_MPA_ATTR
|
3159 C4IW_QP_ATTR_MAX_IRD
|
3160 C4IW_QP_ATTR_MAX_ORD
;
3162 err
= c4iw_modify_qp(ep
->com
.qp
->rhp
,
3163 ep
->com
.qp
, mask
, &attrs
, 1);
3165 goto err_deref_cm_id
;
3167 set_bit(STOP_MPA_TIMER
, &ep
->com
.flags
);
3168 err
= send_mpa_reply(ep
, conn_param
->private_data
,
3169 conn_param
->private_data_len
);
3171 goto err_deref_cm_id
;
3173 __state_set(&ep
->com
, FPDU_MODE
);
3174 established_upcall(ep
);
3175 mutex_unlock(&ep
->com
.mutex
);
3176 c4iw_put_ep(&ep
->com
);
3179 deref_cm_id(&ep
->com
);
3183 mutex_unlock(&ep
->com
.mutex
);
3185 c4iw_ep_disconnect(ep
, 1, GFP_KERNEL
);
3186 c4iw_put_ep(&ep
->com
);
3190 static int pick_local_ipaddrs(struct c4iw_dev
*dev
, struct iw_cm_id
*cm_id
)
3192 struct in_device
*ind
;
3194 struct sockaddr_in
*laddr
= (struct sockaddr_in
*)&cm_id
->m_local_addr
;
3195 struct sockaddr_in
*raddr
= (struct sockaddr_in
*)&cm_id
->m_remote_addr
;
3197 ind
= in_dev_get(dev
->rdev
.lldi
.ports
[0]);
3199 return -EADDRNOTAVAIL
;
3200 for_primary_ifa(ind
) {
3201 laddr
->sin_addr
.s_addr
= ifa
->ifa_address
;
3202 raddr
->sin_addr
.s_addr
= ifa
->ifa_address
;
3208 return found
? 0 : -EADDRNOTAVAIL
;
3211 static int get_lladdr(struct net_device
*dev
, struct in6_addr
*addr
,
3212 unsigned char banned_flags
)
3214 struct inet6_dev
*idev
;
3215 int err
= -EADDRNOTAVAIL
;
3218 idev
= __in6_dev_get(dev
);
3220 struct inet6_ifaddr
*ifp
;
3222 read_lock_bh(&idev
->lock
);
3223 list_for_each_entry(ifp
, &idev
->addr_list
, if_list
) {
3224 if (ifp
->scope
== IFA_LINK
&&
3225 !(ifp
->flags
& banned_flags
)) {
3226 memcpy(addr
, &ifp
->addr
, 16);
3231 read_unlock_bh(&idev
->lock
);
3237 static int pick_local_ip6addrs(struct c4iw_dev
*dev
, struct iw_cm_id
*cm_id
)
3239 struct in6_addr
uninitialized_var(addr
);
3240 struct sockaddr_in6
*la6
= (struct sockaddr_in6
*)&cm_id
->m_local_addr
;
3241 struct sockaddr_in6
*ra6
= (struct sockaddr_in6
*)&cm_id
->m_remote_addr
;
3243 if (!get_lladdr(dev
->rdev
.lldi
.ports
[0], &addr
, IFA_F_TENTATIVE
)) {
3244 memcpy(la6
->sin6_addr
.s6_addr
, &addr
, 16);
3245 memcpy(ra6
->sin6_addr
.s6_addr
, &addr
, 16);
3248 return -EADDRNOTAVAIL
;
3251 int c4iw_connect(struct iw_cm_id
*cm_id
, struct iw_cm_conn_param
*conn_param
)
3253 struct c4iw_dev
*dev
= to_c4iw_dev(cm_id
->device
);
3256 struct sockaddr_in
*laddr
;
3257 struct sockaddr_in
*raddr
;
3258 struct sockaddr_in6
*laddr6
;
3259 struct sockaddr_in6
*raddr6
;
3263 if ((conn_param
->ord
> cur_max_read_depth(dev
)) ||
3264 (conn_param
->ird
> cur_max_read_depth(dev
))) {
3268 ep
= alloc_ep(sizeof(*ep
), GFP_KERNEL
);
3270 printk(KERN_ERR MOD
"%s - cannot alloc ep.\n", __func__
);
3275 skb_queue_head_init(&ep
->com
.ep_skb_list
);
3276 if (alloc_ep_skb_list(&ep
->com
.ep_skb_list
, CN_MAX_CON_BUF
)) {
3281 init_timer(&ep
->timer
);
3282 ep
->plen
= conn_param
->private_data_len
;
3284 memcpy(ep
->mpa_pkt
+ sizeof(struct mpa_message
),
3285 conn_param
->private_data
, ep
->plen
);
3286 ep
->ird
= conn_param
->ird
;
3287 ep
->ord
= conn_param
->ord
;
3289 if (peer2peer
&& ep
->ord
== 0)
3292 ep
->com
.cm_id
= cm_id
;
3293 ref_cm_id(&ep
->com
);
3295 ep
->com
.qp
= get_qhp(dev
, conn_param
->qpn
);
3297 PDBG("%s qpn 0x%x not found!\n", __func__
, conn_param
->qpn
);
3302 PDBG("%s qpn 0x%x qp %p cm_id %p\n", __func__
, conn_param
->qpn
,
3306 * Allocate an active TID to initiate a TCP connection.
3308 ep
->atid
= cxgb4_alloc_atid(dev
->rdev
.lldi
.tids
, ep
);
3309 if (ep
->atid
== -1) {
3310 printk(KERN_ERR MOD
"%s - cannot alloc atid.\n", __func__
);
3314 insert_handle(dev
, &dev
->atid_idr
, ep
, ep
->atid
);
3316 memcpy(&ep
->com
.local_addr
, &cm_id
->m_local_addr
,
3317 sizeof(ep
->com
.local_addr
));
3318 memcpy(&ep
->com
.remote_addr
, &cm_id
->m_remote_addr
,
3319 sizeof(ep
->com
.remote_addr
));
3321 laddr
= (struct sockaddr_in
*)&ep
->com
.local_addr
;
3322 raddr
= (struct sockaddr_in
*)&ep
->com
.remote_addr
;
3323 laddr6
= (struct sockaddr_in6
*)&ep
->com
.local_addr
;
3324 raddr6
= (struct sockaddr_in6
*) &ep
->com
.remote_addr
;
3326 if (cm_id
->m_remote_addr
.ss_family
== AF_INET
) {
3328 ra
= (__u8
*)&raddr
->sin_addr
;
3331 * Handle loopback requests to INADDR_ANY.
3333 if (raddr
->sin_addr
.s_addr
== htonl(INADDR_ANY
)) {
3334 err
= pick_local_ipaddrs(dev
, cm_id
);
3340 PDBG("%s saddr %pI4 sport 0x%x raddr %pI4 rport 0x%x\n",
3341 __func__
, &laddr
->sin_addr
, ntohs(laddr
->sin_port
),
3342 ra
, ntohs(raddr
->sin_port
));
3343 ep
->dst
= find_route(dev
, laddr
->sin_addr
.s_addr
,
3344 raddr
->sin_addr
.s_addr
, laddr
->sin_port
,
3345 raddr
->sin_port
, cm_id
->tos
);
3348 ra
= (__u8
*)&raddr6
->sin6_addr
;
3351 * Handle loopback requests to INADDR_ANY.
3353 if (ipv6_addr_type(&raddr6
->sin6_addr
) == IPV6_ADDR_ANY
) {
3354 err
= pick_local_ip6addrs(dev
, cm_id
);
3360 PDBG("%s saddr %pI6 sport 0x%x raddr %pI6 rport 0x%x\n",
3361 __func__
, laddr6
->sin6_addr
.s6_addr
,
3362 ntohs(laddr6
->sin6_port
),
3363 raddr6
->sin6_addr
.s6_addr
, ntohs(raddr6
->sin6_port
));
3364 ep
->dst
= find_route6(dev
, laddr6
->sin6_addr
.s6_addr
,
3365 raddr6
->sin6_addr
.s6_addr
,
3366 laddr6
->sin6_port
, raddr6
->sin6_port
, 0,
3367 raddr6
->sin6_scope_id
);
3370 printk(KERN_ERR MOD
"%s - cannot find route.\n", __func__
);
3371 err
= -EHOSTUNREACH
;
3375 err
= import_ep(ep
, iptype
, ra
, ep
->dst
, ep
->com
.dev
, true,
3376 ep
->com
.dev
->rdev
.lldi
.adapter_type
, cm_id
->tos
);
3378 printk(KERN_ERR MOD
"%s - cannot alloc l2e.\n", __func__
);
3382 PDBG("%s txq_idx %u tx_chan %u smac_idx %u rss_qid %u l2t_idx %u\n",
3383 __func__
, ep
->txq_idx
, ep
->tx_chan
, ep
->smac_idx
, ep
->rss_qid
,
3386 state_set(&ep
->com
, CONNECTING
);
3387 ep
->tos
= cm_id
->tos
;
3389 /* send connect request to rnic */
3390 err
= send_connect(ep
);
3394 cxgb4_l2t_release(ep
->l2t
);
3396 dst_release(ep
->dst
);
3398 remove_handle(ep
->com
.dev
, &ep
->com
.dev
->atid_idr
, ep
->atid
);
3399 cxgb4_free_atid(ep
->com
.dev
->rdev
.lldi
.tids
, ep
->atid
);
3401 skb_queue_purge(&ep
->com
.ep_skb_list
);
3402 deref_cm_id(&ep
->com
);
3404 c4iw_put_ep(&ep
->com
);
3409 static int create_server6(struct c4iw_dev
*dev
, struct c4iw_listen_ep
*ep
)
3412 struct sockaddr_in6
*sin6
= (struct sockaddr_in6
*)
3413 &ep
->com
.local_addr
;
3415 if (ipv6_addr_type(&sin6
->sin6_addr
) != IPV6_ADDR_ANY
) {
3416 err
= cxgb4_clip_get(ep
->com
.dev
->rdev
.lldi
.ports
[0],
3417 (const u32
*)&sin6
->sin6_addr
.s6_addr
, 1);
3421 c4iw_init_wr_wait(&ep
->com
.wr_wait
);
3422 err
= cxgb4_create_server6(ep
->com
.dev
->rdev
.lldi
.ports
[0],
3423 ep
->stid
, &sin6
->sin6_addr
,
3425 ep
->com
.dev
->rdev
.lldi
.rxq_ids
[0]);
3427 err
= c4iw_wait_for_reply(&ep
->com
.dev
->rdev
,
3431 err
= net_xmit_errno(err
);
3433 cxgb4_clip_release(ep
->com
.dev
->rdev
.lldi
.ports
[0],
3434 (const u32
*)&sin6
->sin6_addr
.s6_addr
, 1);
3435 pr_err("cxgb4_create_server6/filter failed err %d stid %d laddr %pI6 lport %d\n",
3437 sin6
->sin6_addr
.s6_addr
, ntohs(sin6
->sin6_port
));
3442 static int create_server4(struct c4iw_dev
*dev
, struct c4iw_listen_ep
*ep
)
3445 struct sockaddr_in
*sin
= (struct sockaddr_in
*)
3446 &ep
->com
.local_addr
;
3448 if (dev
->rdev
.lldi
.enable_fw_ofld_conn
) {
3450 err
= cxgb4_create_server_filter(
3451 ep
->com
.dev
->rdev
.lldi
.ports
[0], ep
->stid
,
3452 sin
->sin_addr
.s_addr
, sin
->sin_port
, 0,
3453 ep
->com
.dev
->rdev
.lldi
.rxq_ids
[0], 0, 0);
3454 if (err
== -EBUSY
) {
3455 if (c4iw_fatal_error(&ep
->com
.dev
->rdev
)) {
3459 set_current_state(TASK_UNINTERRUPTIBLE
);
3460 schedule_timeout(usecs_to_jiffies(100));
3462 } while (err
== -EBUSY
);
3464 c4iw_init_wr_wait(&ep
->com
.wr_wait
);
3465 err
= cxgb4_create_server(ep
->com
.dev
->rdev
.lldi
.ports
[0],
3466 ep
->stid
, sin
->sin_addr
.s_addr
, sin
->sin_port
,
3467 0, ep
->com
.dev
->rdev
.lldi
.rxq_ids
[0]);
3469 err
= c4iw_wait_for_reply(&ep
->com
.dev
->rdev
,
3473 err
= net_xmit_errno(err
);
3476 pr_err("cxgb4_create_server/filter failed err %d stid %d laddr %pI4 lport %d\n"
3478 &sin
->sin_addr
, ntohs(sin
->sin_port
));
3482 int c4iw_create_listen(struct iw_cm_id
*cm_id
, int backlog
)
3485 struct c4iw_dev
*dev
= to_c4iw_dev(cm_id
->device
);
3486 struct c4iw_listen_ep
*ep
;
3490 ep
= alloc_ep(sizeof(*ep
), GFP_KERNEL
);
3492 printk(KERN_ERR MOD
"%s - cannot alloc ep.\n", __func__
);
3496 skb_queue_head_init(&ep
->com
.ep_skb_list
);
3497 PDBG("%s ep %p\n", __func__
, ep
);
3498 ep
->com
.cm_id
= cm_id
;
3499 ref_cm_id(&ep
->com
);
3501 ep
->backlog
= backlog
;
3502 memcpy(&ep
->com
.local_addr
, &cm_id
->m_local_addr
,
3503 sizeof(ep
->com
.local_addr
));
3506 * Allocate a server TID.
3508 if (dev
->rdev
.lldi
.enable_fw_ofld_conn
&&
3509 ep
->com
.local_addr
.ss_family
== AF_INET
)
3510 ep
->stid
= cxgb4_alloc_sftid(dev
->rdev
.lldi
.tids
,
3511 cm_id
->m_local_addr
.ss_family
, ep
);
3513 ep
->stid
= cxgb4_alloc_stid(dev
->rdev
.lldi
.tids
,
3514 cm_id
->m_local_addr
.ss_family
, ep
);
3516 if (ep
->stid
== -1) {
3517 printk(KERN_ERR MOD
"%s - cannot alloc stid.\n", __func__
);
3521 insert_handle(dev
, &dev
->stid_idr
, ep
, ep
->stid
);
3523 memcpy(&ep
->com
.local_addr
, &cm_id
->m_local_addr
,
3524 sizeof(ep
->com
.local_addr
));
3526 state_set(&ep
->com
, LISTEN
);
3527 if (ep
->com
.local_addr
.ss_family
== AF_INET
)
3528 err
= create_server4(dev
, ep
);
3530 err
= create_server6(dev
, ep
);
3532 cm_id
->provider_data
= ep
;
3536 cxgb4_free_stid(ep
->com
.dev
->rdev
.lldi
.tids
, ep
->stid
,
3537 ep
->com
.local_addr
.ss_family
);
3539 deref_cm_id(&ep
->com
);
3540 c4iw_put_ep(&ep
->com
);
3546 int c4iw_destroy_listen(struct iw_cm_id
*cm_id
)
3549 struct c4iw_listen_ep
*ep
= to_listen_ep(cm_id
);
3551 PDBG("%s ep %p\n", __func__
, ep
);
3554 state_set(&ep
->com
, DEAD
);
3555 if (ep
->com
.dev
->rdev
.lldi
.enable_fw_ofld_conn
&&
3556 ep
->com
.local_addr
.ss_family
== AF_INET
) {
3557 err
= cxgb4_remove_server_filter(
3558 ep
->com
.dev
->rdev
.lldi
.ports
[0], ep
->stid
,
3559 ep
->com
.dev
->rdev
.lldi
.rxq_ids
[0], 0);
3561 struct sockaddr_in6
*sin6
;
3562 c4iw_init_wr_wait(&ep
->com
.wr_wait
);
3563 err
= cxgb4_remove_server(
3564 ep
->com
.dev
->rdev
.lldi
.ports
[0], ep
->stid
,
3565 ep
->com
.dev
->rdev
.lldi
.rxq_ids
[0], 0);
3568 err
= c4iw_wait_for_reply(&ep
->com
.dev
->rdev
, &ep
->com
.wr_wait
,
3570 sin6
= (struct sockaddr_in6
*)&ep
->com
.local_addr
;
3571 cxgb4_clip_release(ep
->com
.dev
->rdev
.lldi
.ports
[0],
3572 (const u32
*)&sin6
->sin6_addr
.s6_addr
, 1);
3574 remove_handle(ep
->com
.dev
, &ep
->com
.dev
->stid_idr
, ep
->stid
);
3575 cxgb4_free_stid(ep
->com
.dev
->rdev
.lldi
.tids
, ep
->stid
,
3576 ep
->com
.local_addr
.ss_family
);
3578 deref_cm_id(&ep
->com
);
3579 c4iw_put_ep(&ep
->com
);
3583 int c4iw_ep_disconnect(struct c4iw_ep
*ep
, int abrupt
, gfp_t gfp
)
3588 struct c4iw_rdev
*rdev
;
3590 mutex_lock(&ep
->com
.mutex
);
3592 PDBG("%s ep %p state %s, abrupt %d\n", __func__
, ep
,
3593 states
[ep
->com
.state
], abrupt
);
3596 * Ref the ep here in case we have fatal errors causing the
3597 * ep to be released and freed.
3599 c4iw_get_ep(&ep
->com
);
3601 rdev
= &ep
->com
.dev
->rdev
;
3602 if (c4iw_fatal_error(rdev
)) {
3604 close_complete_upcall(ep
, -EIO
);
3605 ep
->com
.state
= DEAD
;
3607 switch (ep
->com
.state
) {
3616 ep
->com
.state
= ABORTING
;
3618 ep
->com
.state
= CLOSING
;
3621 * if we close before we see the fw4_ack() then we fix
3622 * up the timer state since we're reusing it.
3625 test_bit(STOP_MPA_TIMER
, &ep
->com
.flags
)) {
3626 clear_bit(STOP_MPA_TIMER
, &ep
->com
.flags
);
3631 set_bit(CLOSE_SENT
, &ep
->com
.flags
);
3634 if (!test_and_set_bit(CLOSE_SENT
, &ep
->com
.flags
)) {
3637 (void)stop_ep_timer(ep
);
3638 ep
->com
.state
= ABORTING
;
3640 ep
->com
.state
= MORIBUND
;
3646 PDBG("%s ignoring disconnect ep %p state %u\n",
3647 __func__
, ep
, ep
->com
.state
);
3656 set_bit(EP_DISC_ABORT
, &ep
->com
.history
);
3657 close_complete_upcall(ep
, -ECONNRESET
);
3658 ret
= send_abort(ep
);
3660 set_bit(EP_DISC_CLOSE
, &ep
->com
.history
);
3661 ret
= send_halfclose(ep
);
3664 set_bit(EP_DISC_FAIL
, &ep
->com
.history
);
3667 close_complete_upcall(ep
, -EIO
);
3670 struct c4iw_qp_attributes attrs
;
3672 attrs
.next_state
= C4IW_QP_STATE_ERROR
;
3673 ret
= c4iw_modify_qp(ep
->com
.qp
->rhp
,
3675 C4IW_QP_ATTR_NEXT_STATE
,
3679 "%s - qp <- error failed!\n",
3685 mutex_unlock(&ep
->com
.mutex
);
3686 c4iw_put_ep(&ep
->com
);
3688 release_ep_resources(ep
);
3692 static void active_ofld_conn_reply(struct c4iw_dev
*dev
, struct sk_buff
*skb
,
3693 struct cpl_fw6_msg_ofld_connection_wr_rpl
*req
)
3696 int atid
= be32_to_cpu(req
->tid
);
3698 ep
= (struct c4iw_ep
*)lookup_atid(dev
->rdev
.lldi
.tids
,
3699 (__force u32
) req
->tid
);
3703 switch (req
->retval
) {
3705 set_bit(ACT_RETRY_NOMEM
, &ep
->com
.history
);
3706 if (ep
->retry_count
++ < ACT_OPEN_RETRY_COUNT
) {
3707 send_fw_act_open_req(ep
, atid
);
3711 set_bit(ACT_RETRY_INUSE
, &ep
->com
.history
);
3712 if (ep
->retry_count
++ < ACT_OPEN_RETRY_COUNT
) {
3713 send_fw_act_open_req(ep
, atid
);
3718 pr_info("%s unexpected ofld conn wr retval %d\n",
3719 __func__
, req
->retval
);
3722 pr_err("active ofld_connect_wr failure %d atid %d\n",
3724 mutex_lock(&dev
->rdev
.stats
.lock
);
3725 dev
->rdev
.stats
.act_ofld_conn_fails
++;
3726 mutex_unlock(&dev
->rdev
.stats
.lock
);
3727 connect_reply_upcall(ep
, status2errno(req
->retval
));
3728 state_set(&ep
->com
, DEAD
);
3729 if (ep
->com
.remote_addr
.ss_family
== AF_INET6
) {
3730 struct sockaddr_in6
*sin6
=
3731 (struct sockaddr_in6
*)&ep
->com
.local_addr
;
3732 cxgb4_clip_release(ep
->com
.dev
->rdev
.lldi
.ports
[0],
3733 (const u32
*)&sin6
->sin6_addr
.s6_addr
, 1);
3735 remove_handle(dev
, &dev
->atid_idr
, atid
);
3736 cxgb4_free_atid(dev
->rdev
.lldi
.tids
, atid
);
3737 dst_release(ep
->dst
);
3738 cxgb4_l2t_release(ep
->l2t
);
3739 c4iw_put_ep(&ep
->com
);
3742 static void passive_ofld_conn_reply(struct c4iw_dev
*dev
, struct sk_buff
*skb
,
3743 struct cpl_fw6_msg_ofld_connection_wr_rpl
*req
)
3745 struct sk_buff
*rpl_skb
;
3746 struct cpl_pass_accept_req
*cpl
;
3749 rpl_skb
= (struct sk_buff
*)(unsigned long)req
->cookie
;
3752 PDBG("%s passive open failure %d\n", __func__
, req
->retval
);
3753 mutex_lock(&dev
->rdev
.stats
.lock
);
3754 dev
->rdev
.stats
.pas_ofld_conn_fails
++;
3755 mutex_unlock(&dev
->rdev
.stats
.lock
);
3758 cpl
= (struct cpl_pass_accept_req
*)cplhdr(rpl_skb
);
3759 OPCODE_TID(cpl
) = htonl(MK_OPCODE_TID(CPL_PASS_ACCEPT_REQ
,
3760 (__force u32
) htonl(
3761 (__force u32
) req
->tid
)));
3762 ret
= pass_accept_req(dev
, rpl_skb
);
3769 static int deferred_fw6_msg(struct c4iw_dev
*dev
, struct sk_buff
*skb
)
3771 struct cpl_fw6_msg
*rpl
= cplhdr(skb
);
3772 struct cpl_fw6_msg_ofld_connection_wr_rpl
*req
;
3774 switch (rpl
->type
) {
3776 c4iw_ev_dispatch(dev
, (struct t4_cqe
*)&rpl
->data
[0]);
3778 case FW6_TYPE_OFLD_CONNECTION_WR_RPL
:
3779 req
= (struct cpl_fw6_msg_ofld_connection_wr_rpl
*)rpl
->data
;
3780 switch (req
->t_state
) {
3782 active_ofld_conn_reply(dev
, skb
, req
);
3785 passive_ofld_conn_reply(dev
, skb
, req
);
3788 pr_err("%s unexpected ofld conn wr state %d\n",
3789 __func__
, req
->t_state
);
3797 static void build_cpl_pass_accept_req(struct sk_buff
*skb
, int stid
, u8 tos
)
3800 __be16 hdr_len
, vlantag
, len
;
3802 int tcp_hdr_len
, ip_hdr_len
;
3804 struct cpl_rx_pkt
*cpl
= cplhdr(skb
);
3805 struct cpl_pass_accept_req
*req
;
3806 struct tcp_options_received tmp_opt
;
3807 struct c4iw_dev
*dev
;
3808 enum chip_type type
;
3810 dev
= *((struct c4iw_dev
**) (skb
->cb
+ sizeof(void *)));
3811 /* Store values from cpl_rx_pkt in temporary location. */
3812 vlantag
= cpl
->vlan
;
3814 l2info
= cpl
->l2info
;
3815 hdr_len
= cpl
->hdr_len
;
3818 __skb_pull(skb
, sizeof(*req
) + sizeof(struct rss_header
));
3821 * We need to parse the TCP options from SYN packet.
3822 * to generate cpl_pass_accept_req.
3824 memset(&tmp_opt
, 0, sizeof(tmp_opt
));
3825 tcp_clear_options(&tmp_opt
);
3826 tcp_parse_options(skb
, &tmp_opt
, 0, NULL
);
3828 req
= (struct cpl_pass_accept_req
*)__skb_push(skb
, sizeof(*req
));
3829 memset(req
, 0, sizeof(*req
));
3830 req
->l2info
= cpu_to_be16(SYN_INTF_V(intf
) |
3831 SYN_MAC_IDX_V(RX_MACIDX_G(
3832 be32_to_cpu(l2info
))) |
3834 type
= dev
->rdev
.lldi
.adapter_type
;
3835 tcp_hdr_len
= RX_TCPHDR_LEN_G(be16_to_cpu(hdr_len
));
3836 ip_hdr_len
= RX_IPHDR_LEN_G(be16_to_cpu(hdr_len
));
3838 cpu_to_be32(SYN_RX_CHAN_V(RX_CHAN_G(be32_to_cpu(l2info
))));
3839 if (CHELSIO_CHIP_VERSION(type
) <= CHELSIO_T5
) {
3840 eth_hdr_len
= is_t4(type
) ?
3841 RX_ETHHDR_LEN_G(be32_to_cpu(l2info
)) :
3842 RX_T5_ETHHDR_LEN_G(be32_to_cpu(l2info
));
3843 req
->hdr_len
|= cpu_to_be32(TCP_HDR_LEN_V(tcp_hdr_len
) |
3844 IP_HDR_LEN_V(ip_hdr_len
) |
3845 ETH_HDR_LEN_V(eth_hdr_len
));
3846 } else { /* T6 and later */
3847 eth_hdr_len
= RX_T6_ETHHDR_LEN_G(be32_to_cpu(l2info
));
3848 req
->hdr_len
|= cpu_to_be32(T6_TCP_HDR_LEN_V(tcp_hdr_len
) |
3849 T6_IP_HDR_LEN_V(ip_hdr_len
) |
3850 T6_ETH_HDR_LEN_V(eth_hdr_len
));
3852 req
->vlan
= vlantag
;
3854 req
->tos_stid
= cpu_to_be32(PASS_OPEN_TID_V(stid
) |
3855 PASS_OPEN_TOS_V(tos
));
3856 req
->tcpopt
.mss
= htons(tmp_opt
.mss_clamp
);
3857 if (tmp_opt
.wscale_ok
)
3858 req
->tcpopt
.wsf
= tmp_opt
.snd_wscale
;
3859 req
->tcpopt
.tstamp
= tmp_opt
.saw_tstamp
;
3860 if (tmp_opt
.sack_ok
)
3861 req
->tcpopt
.sack
= 1;
3862 OPCODE_TID(req
) = htonl(MK_OPCODE_TID(CPL_PASS_ACCEPT_REQ
, 0));
3866 static void send_fw_pass_open_req(struct c4iw_dev
*dev
, struct sk_buff
*skb
,
3867 __be32 laddr
, __be16 lport
,
3868 __be32 raddr
, __be16 rport
,
3869 u32 rcv_isn
, u32 filter
, u16 window
,
3870 u32 rss_qid
, u8 port_id
)
3872 struct sk_buff
*req_skb
;
3873 struct fw_ofld_connection_wr
*req
;
3874 struct cpl_pass_accept_req
*cpl
= cplhdr(skb
);
3877 req_skb
= alloc_skb(sizeof(struct fw_ofld_connection_wr
), GFP_KERNEL
);
3878 req
= (struct fw_ofld_connection_wr
*)__skb_put(req_skb
, sizeof(*req
));
3879 memset(req
, 0, sizeof(*req
));
3880 req
->op_compl
= htonl(WR_OP_V(FW_OFLD_CONNECTION_WR
) | FW_WR_COMPL_F
);
3881 req
->len16_pkd
= htonl(FW_WR_LEN16_V(DIV_ROUND_UP(sizeof(*req
), 16)));
3882 req
->le
.version_cpl
= htonl(FW_OFLD_CONNECTION_WR_CPL_F
);
3883 req
->le
.filter
= (__force __be32
) filter
;
3884 req
->le
.lport
= lport
;
3885 req
->le
.pport
= rport
;
3886 req
->le
.u
.ipv4
.lip
= laddr
;
3887 req
->le
.u
.ipv4
.pip
= raddr
;
3888 req
->tcb
.rcv_nxt
= htonl(rcv_isn
+ 1);
3889 req
->tcb
.rcv_adv
= htons(window
);
3890 req
->tcb
.t_state_to_astid
=
3891 htonl(FW_OFLD_CONNECTION_WR_T_STATE_V(TCP_SYN_RECV
) |
3892 FW_OFLD_CONNECTION_WR_RCV_SCALE_V(cpl
->tcpopt
.wsf
) |
3893 FW_OFLD_CONNECTION_WR_ASTID_V(
3894 PASS_OPEN_TID_G(ntohl(cpl
->tos_stid
))));
3897 * We store the qid in opt2 which will be used by the firmware
3898 * to send us the wr response.
3900 req
->tcb
.opt2
= htonl(RSS_QUEUE_V(rss_qid
));
3903 * We initialize the MSS index in TCB to 0xF.
3904 * So that when driver sends cpl_pass_accept_rpl
3905 * TCB picks up the correct value. If this was 0
3906 * TP will ignore any value > 0 for MSS index.
3908 req
->tcb
.opt0
= cpu_to_be64(MSS_IDX_V(0xF));
3909 req
->cookie
= (uintptr_t)skb
;
3911 set_wr_txq(req_skb
, CPL_PRIORITY_CONTROL
, port_id
);
3912 ret
= cxgb4_ofld_send(dev
->rdev
.lldi
.ports
[0], req_skb
);
3914 pr_err("%s - cxgb4_ofld_send error %d - dropping\n", __func__
,
3922 * Handler for CPL_RX_PKT message. Need to handle cpl_rx_pkt
3923 * messages when a filter is being used instead of server to
3924 * redirect a syn packet. When packets hit filter they are redirected
3925 * to the offload queue and driver tries to establish the connection
3926 * using firmware work request.
3928 static int rx_pkt(struct c4iw_dev
*dev
, struct sk_buff
*skb
)
3931 unsigned int filter
;
3932 struct ethhdr
*eh
= NULL
;
3933 struct vlan_ethhdr
*vlan_eh
= NULL
;
3935 struct tcphdr
*tcph
;
3936 struct rss_header
*rss
= (void *)skb
->data
;
3937 struct cpl_rx_pkt
*cpl
= (void *)skb
->data
;
3938 struct cpl_pass_accept_req
*req
= (void *)(rss
+ 1);
3939 struct l2t_entry
*e
;
3940 struct dst_entry
*dst
;
3941 struct c4iw_ep
*lep
= NULL
;
3943 struct port_info
*pi
;
3944 struct net_device
*pdev
;
3945 u16 rss_qid
, eth_hdr_len
;
3948 struct neighbour
*neigh
;
3950 /* Drop all non-SYN packets */
3951 if (!(cpl
->l2info
& cpu_to_be32(RXF_SYN_F
)))
3955 * Drop all packets which did not hit the filter.
3956 * Unlikely to happen.
3958 if (!(rss
->filter_hit
&& rss
->filter_tid
))
3962 * Calculate the server tid from filter hit index from cpl_rx_pkt.
3964 stid
= (__force
int) cpu_to_be32((__force u32
) rss
->hash_val
);
3966 lep
= (struct c4iw_ep
*)get_ep_from_stid(dev
, stid
);
3968 PDBG("%s connect request on invalid stid %d\n", __func__
, stid
);
3972 switch (CHELSIO_CHIP_VERSION(dev
->rdev
.lldi
.adapter_type
)) {
3974 eth_hdr_len
= RX_ETHHDR_LEN_G(be32_to_cpu(cpl
->l2info
));
3977 eth_hdr_len
= RX_T5_ETHHDR_LEN_G(be32_to_cpu(cpl
->l2info
));
3980 eth_hdr_len
= RX_T6_ETHHDR_LEN_G(be32_to_cpu(cpl
->l2info
));
3983 pr_err("T%d Chip is not supported\n",
3984 CHELSIO_CHIP_VERSION(dev
->rdev
.lldi
.adapter_type
));
3988 if (eth_hdr_len
== ETH_HLEN
) {
3989 eh
= (struct ethhdr
*)(req
+ 1);
3990 iph
= (struct iphdr
*)(eh
+ 1);
3992 vlan_eh
= (struct vlan_ethhdr
*)(req
+ 1);
3993 iph
= (struct iphdr
*)(vlan_eh
+ 1);
3994 skb
->vlan_tci
= ntohs(cpl
->vlan
);
3997 if (iph
->version
!= 0x4)
4000 tcph
= (struct tcphdr
*)(iph
+ 1);
4001 skb_set_network_header(skb
, (void *)iph
- (void *)rss
);
4002 skb_set_transport_header(skb
, (void *)tcph
- (void *)rss
);
4005 PDBG("%s lip 0x%x lport %u pip 0x%x pport %u tos %d\n", __func__
,
4006 ntohl(iph
->daddr
), ntohs(tcph
->dest
), ntohl(iph
->saddr
),
4007 ntohs(tcph
->source
), iph
->tos
);
4009 dst
= find_route(dev
, iph
->daddr
, iph
->saddr
, tcph
->dest
, tcph
->source
,
4012 pr_err("%s - failed to find dst entry!\n",
4016 neigh
= dst_neigh_lookup_skb(dst
, skb
);
4019 pr_err("%s - failed to allocate neigh!\n",
4024 if (neigh
->dev
->flags
& IFF_LOOPBACK
) {
4025 pdev
= ip_dev_find(&init_net
, iph
->daddr
);
4026 e
= cxgb4_l2t_get(dev
->rdev
.lldi
.l2t
, neigh
,
4028 pi
= (struct port_info
*)netdev_priv(pdev
);
4029 tx_chan
= cxgb4_port_chan(pdev
);
4032 pdev
= get_real_dev(neigh
->dev
);
4033 e
= cxgb4_l2t_get(dev
->rdev
.lldi
.l2t
, neigh
,
4035 pi
= (struct port_info
*)netdev_priv(pdev
);
4036 tx_chan
= cxgb4_port_chan(pdev
);
4038 neigh_release(neigh
);
4040 pr_err("%s - failed to allocate l2t entry!\n",
4045 step
= dev
->rdev
.lldi
.nrxq
/ dev
->rdev
.lldi
.nchan
;
4046 rss_qid
= dev
->rdev
.lldi
.rxq_ids
[pi
->port_id
* step
];
4047 window
= (__force u16
) htons((__force u16
)tcph
->window
);
4049 /* Calcuate filter portion for LE region. */
4050 filter
= (__force
unsigned int) cpu_to_be32(cxgb4_select_ntuple(
4051 dev
->rdev
.lldi
.ports
[0],
4055 * Synthesize the cpl_pass_accept_req. We have everything except the
4056 * TID. Once firmware sends a reply with TID we update the TID field
4057 * in cpl and pass it through the regular cpl_pass_accept_req path.
4059 build_cpl_pass_accept_req(skb
, stid
, iph
->tos
);
4060 send_fw_pass_open_req(dev
, skb
, iph
->daddr
, tcph
->dest
, iph
->saddr
,
4061 tcph
->source
, ntohl(tcph
->seq
), filter
, window
,
4062 rss_qid
, pi
->port_id
);
4063 cxgb4_l2t_release(e
);
4068 c4iw_put_ep(&lep
->com
);
4073 * These are the real handlers that are called from a
4076 static c4iw_handler_func work_handlers
[NUM_CPL_CMDS
+ NUM_FAKE_CPLS
] = {
4077 [CPL_ACT_ESTABLISH
] = act_establish
,
4078 [CPL_ACT_OPEN_RPL
] = act_open_rpl
,
4079 [CPL_RX_DATA
] = rx_data
,
4080 [CPL_ABORT_RPL_RSS
] = abort_rpl
,
4081 [CPL_ABORT_RPL
] = abort_rpl
,
4082 [CPL_PASS_OPEN_RPL
] = pass_open_rpl
,
4083 [CPL_CLOSE_LISTSRV_RPL
] = close_listsrv_rpl
,
4084 [CPL_PASS_ACCEPT_REQ
] = pass_accept_req
,
4085 [CPL_PASS_ESTABLISH
] = pass_establish
,
4086 [CPL_PEER_CLOSE
] = peer_close
,
4087 [CPL_ABORT_REQ_RSS
] = peer_abort
,
4088 [CPL_CLOSE_CON_RPL
] = close_con_rpl
,
4089 [CPL_RDMA_TERMINATE
] = terminate
,
4090 [CPL_FW4_ACK
] = fw4_ack
,
4091 [CPL_FW6_MSG
] = deferred_fw6_msg
,
4092 [CPL_RX_PKT
] = rx_pkt
,
4093 [FAKE_CPL_PUT_EP_SAFE
] = _put_ep_safe
,
4094 [FAKE_CPL_PASS_PUT_EP_SAFE
] = _put_pass_ep_safe
4097 static void process_timeout(struct c4iw_ep
*ep
)
4099 struct c4iw_qp_attributes attrs
;
4102 mutex_lock(&ep
->com
.mutex
);
4103 PDBG("%s ep %p tid %u state %d\n", __func__
, ep
, ep
->hwtid
,
4105 set_bit(TIMEDOUT
, &ep
->com
.history
);
4106 switch (ep
->com
.state
) {
4108 connect_reply_upcall(ep
, -ETIMEDOUT
);
4117 if (ep
->com
.cm_id
&& ep
->com
.qp
) {
4118 attrs
.next_state
= C4IW_QP_STATE_ERROR
;
4119 c4iw_modify_qp(ep
->com
.qp
->rhp
,
4120 ep
->com
.qp
, C4IW_QP_ATTR_NEXT_STATE
,
4123 close_complete_upcall(ep
, -ETIMEDOUT
);
4129 * These states are expected if the ep timed out at the same
4130 * time as another thread was calling stop_ep_timer().
4131 * So we silently do nothing for these states.
4136 WARN(1, "%s unexpected state ep %p tid %u state %u\n",
4137 __func__
, ep
, ep
->hwtid
, ep
->com
.state
);
4140 mutex_unlock(&ep
->com
.mutex
);
4142 c4iw_ep_disconnect(ep
, 1, GFP_KERNEL
);
4143 c4iw_put_ep(&ep
->com
);
4146 static void process_timedout_eps(void)
4150 spin_lock_irq(&timeout_lock
);
4151 while (!list_empty(&timeout_list
)) {
4152 struct list_head
*tmp
;
4154 tmp
= timeout_list
.next
;
4158 spin_unlock_irq(&timeout_lock
);
4159 ep
= list_entry(tmp
, struct c4iw_ep
, entry
);
4160 process_timeout(ep
);
4161 spin_lock_irq(&timeout_lock
);
4163 spin_unlock_irq(&timeout_lock
);
4166 static void process_work(struct work_struct
*work
)
4168 struct sk_buff
*skb
= NULL
;
4169 struct c4iw_dev
*dev
;
4170 struct cpl_act_establish
*rpl
;
4171 unsigned int opcode
;
4174 process_timedout_eps();
4175 while ((skb
= skb_dequeue(&rxq
))) {
4177 dev
= *((struct c4iw_dev
**) (skb
->cb
+ sizeof(void *)));
4178 opcode
= rpl
->ot
.opcode
;
4180 BUG_ON(!work_handlers
[opcode
]);
4181 ret
= work_handlers
[opcode
](dev
, skb
);
4184 process_timedout_eps();
4188 static DECLARE_WORK(skb_work
, process_work
);
4190 static void ep_timeout(unsigned long arg
)
4192 struct c4iw_ep
*ep
= (struct c4iw_ep
*)arg
;
4195 spin_lock(&timeout_lock
);
4196 if (!test_and_set_bit(TIMEOUT
, &ep
->com
.flags
)) {
4198 * Only insert if it is not already on the list.
4200 if (!ep
->entry
.next
) {
4201 list_add_tail(&ep
->entry
, &timeout_list
);
4205 spin_unlock(&timeout_lock
);
4207 queue_work(workq
, &skb_work
);
4211 * All the CM events are handled on a work queue to have a safe context.
4213 static int sched(struct c4iw_dev
*dev
, struct sk_buff
*skb
)
4217 * Save dev in the skb->cb area.
4219 *((struct c4iw_dev
**) (skb
->cb
+ sizeof(void *))) = dev
;
4222 * Queue the skb and schedule the worker thread.
4224 skb_queue_tail(&rxq
, skb
);
4225 queue_work(workq
, &skb_work
);
4229 static int set_tcb_rpl(struct c4iw_dev
*dev
, struct sk_buff
*skb
)
4231 struct cpl_set_tcb_rpl
*rpl
= cplhdr(skb
);
4233 if (rpl
->status
!= CPL_ERR_NONE
) {
4234 printk(KERN_ERR MOD
"Unexpected SET_TCB_RPL status %u "
4235 "for tid %u\n", rpl
->status
, GET_TID(rpl
));
4241 static int fw6_msg(struct c4iw_dev
*dev
, struct sk_buff
*skb
)
4243 struct cpl_fw6_msg
*rpl
= cplhdr(skb
);
4244 struct c4iw_wr_wait
*wr_waitp
;
4247 PDBG("%s type %u\n", __func__
, rpl
->type
);
4249 switch (rpl
->type
) {
4250 case FW6_TYPE_WR_RPL
:
4251 ret
= (int)((be64_to_cpu(rpl
->data
[0]) >> 8) & 0xff);
4252 wr_waitp
= (struct c4iw_wr_wait
*)(__force
unsigned long) rpl
->data
[1];
4253 PDBG("%s wr_waitp %p ret %u\n", __func__
, wr_waitp
, ret
);
4255 c4iw_wake_up(wr_waitp
, ret
? -ret
: 0);
4259 case FW6_TYPE_OFLD_CONNECTION_WR_RPL
:
4263 printk(KERN_ERR MOD
"%s unexpected fw6 msg type %u\n", __func__
,
4271 static int peer_abort_intr(struct c4iw_dev
*dev
, struct sk_buff
*skb
)
4273 struct cpl_abort_req_rss
*req
= cplhdr(skb
);
4275 unsigned int tid
= GET_TID(req
);
4277 ep
= get_ep_from_tid(dev
, tid
);
4278 /* This EP will be dereferenced in peer_abort() */
4280 printk(KERN_WARNING MOD
4281 "Abort on non-existent endpoint, tid %d\n", tid
);
4285 if (is_neg_adv(req
->status
)) {
4286 PDBG("%s Negative advice on abort- tid %u status %d (%s)\n",
4287 __func__
, ep
->hwtid
, req
->status
,
4288 neg_adv_str(req
->status
));
4291 PDBG("%s ep %p tid %u state %u\n", __func__
, ep
, ep
->hwtid
,
4294 c4iw_wake_up(&ep
->com
.wr_wait
, -ECONNRESET
);
4301 * Most upcalls from the T4 Core go to sched() to
4302 * schedule the processing on a work queue.
4304 c4iw_handler_func c4iw_handlers
[NUM_CPL_CMDS
] = {
4305 [CPL_ACT_ESTABLISH
] = sched
,
4306 [CPL_ACT_OPEN_RPL
] = sched
,
4307 [CPL_RX_DATA
] = sched
,
4308 [CPL_ABORT_RPL_RSS
] = sched
,
4309 [CPL_ABORT_RPL
] = sched
,
4310 [CPL_PASS_OPEN_RPL
] = sched
,
4311 [CPL_CLOSE_LISTSRV_RPL
] = sched
,
4312 [CPL_PASS_ACCEPT_REQ
] = sched
,
4313 [CPL_PASS_ESTABLISH
] = sched
,
4314 [CPL_PEER_CLOSE
] = sched
,
4315 [CPL_CLOSE_CON_RPL
] = sched
,
4316 [CPL_ABORT_REQ_RSS
] = peer_abort_intr
,
4317 [CPL_RDMA_TERMINATE
] = sched
,
4318 [CPL_FW4_ACK
] = sched
,
4319 [CPL_SET_TCB_RPL
] = set_tcb_rpl
,
4320 [CPL_FW6_MSG
] = fw6_msg
,
4321 [CPL_RX_PKT
] = sched
4324 int __init
c4iw_cm_init(void)
4326 spin_lock_init(&timeout_lock
);
4327 skb_queue_head_init(&rxq
);
4329 workq
= create_singlethread_workqueue("iw_cxgb4");
4336 void c4iw_cm_term(void)
4338 WARN_ON(!list_empty(&timeout_list
));
4339 flush_workqueue(workq
);
4340 destroy_workqueue(workq
);