2 * Copyright (c) 2006 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/slab.h>
35 #include <linux/workqueue.h>
36 #include <linux/skbuff.h>
37 #include <linux/timer.h>
38 #include <linux/notifier.h>
39 #include <linux/inetdevice.h>
41 #include <net/neighbour.h>
42 #include <net/netevent.h>
43 #include <net/route.h>
46 #include "cxgb3_offload.h"
48 #include "iwch_provider.h"
51 static char *states
[] = {
68 module_param(peer2peer
, int, 0644);
69 MODULE_PARM_DESC(peer2peer
, "Support peer2peer ULPs (default=0)");
71 static int ep_timeout_secs
= 60;
72 module_param(ep_timeout_secs
, int, 0644);
73 MODULE_PARM_DESC(ep_timeout_secs
, "CM Endpoint operation timeout "
74 "in seconds (default=60)");
76 static int mpa_rev
= 1;
77 module_param(mpa_rev
, int, 0644);
78 MODULE_PARM_DESC(mpa_rev
, "MPA Revision, 0 supports amso1100, "
79 "1 is spec compliant. (default=1)");
81 static int markers_enabled
= 0;
82 module_param(markers_enabled
, int, 0644);
83 MODULE_PARM_DESC(markers_enabled
, "Enable MPA MARKERS (default(0)=disabled)");
85 static int crc_enabled
= 1;
86 module_param(crc_enabled
, int, 0644);
87 MODULE_PARM_DESC(crc_enabled
, "Enable MPA CRC (default(1)=enabled)");
89 static int rcv_win
= 256 * 1024;
90 module_param(rcv_win
, int, 0644);
91 MODULE_PARM_DESC(rcv_win
, "TCP receive window in bytes (default=256)");
93 static int snd_win
= 32 * 1024;
94 module_param(snd_win
, int, 0644);
95 MODULE_PARM_DESC(snd_win
, "TCP send window in bytes (default=32KB)");
97 static unsigned int nocong
= 0;
98 module_param(nocong
, uint
, 0644);
99 MODULE_PARM_DESC(nocong
, "Turn off congestion control (default=0)");
101 static unsigned int cong_flavor
= 1;
102 module_param(cong_flavor
, uint
, 0644);
103 MODULE_PARM_DESC(cong_flavor
, "TCP Congestion control flavor (default=1)");
105 static struct workqueue_struct
*workq
;
107 static struct sk_buff_head rxq
;
109 static struct sk_buff
*get_skb(struct sk_buff
*skb
, int len
, gfp_t gfp
);
110 static void ep_timeout(unsigned long arg
);
111 static void connect_reply_upcall(struct iwch_ep
*ep
, int status
);
113 static void start_ep_timer(struct iwch_ep
*ep
)
115 PDBG("%s ep %p\n", __func__
, ep
);
116 if (timer_pending(&ep
->timer
)) {
117 PDBG("%s stopped / restarted timer ep %p\n", __func__
, ep
);
118 del_timer_sync(&ep
->timer
);
121 ep
->timer
.expires
= jiffies
+ ep_timeout_secs
* HZ
;
122 ep
->timer
.data
= (unsigned long)ep
;
123 ep
->timer
.function
= ep_timeout
;
124 add_timer(&ep
->timer
);
127 static void stop_ep_timer(struct iwch_ep
*ep
)
129 PDBG("%s ep %p\n", __func__
, ep
);
130 if (!timer_pending(&ep
->timer
)) {
131 printk(KERN_ERR
"%s timer stopped when its not running! ep %p state %u\n",
132 __func__
, ep
, ep
->com
.state
);
136 del_timer_sync(&ep
->timer
);
140 int iwch_l2t_send(struct t3cdev
*tdev
, struct sk_buff
*skb
, struct l2t_entry
*l2e
)
143 struct cxio_rdev
*rdev
;
145 rdev
= (struct cxio_rdev
*)tdev
->ulp
;
146 if (cxio_fatal_error(rdev
)) {
150 error
= l2t_send(tdev
, skb
, l2e
);
156 int iwch_cxgb3_ofld_send(struct t3cdev
*tdev
, struct sk_buff
*skb
)
159 struct cxio_rdev
*rdev
;
161 rdev
= (struct cxio_rdev
*)tdev
->ulp
;
162 if (cxio_fatal_error(rdev
)) {
166 error
= cxgb3_ofld_send(tdev
, skb
);
172 static void release_tid(struct t3cdev
*tdev
, u32 hwtid
, struct sk_buff
*skb
)
174 struct cpl_tid_release
*req
;
176 skb
= get_skb(skb
, sizeof *req
, GFP_KERNEL
);
179 req
= (struct cpl_tid_release
*) skb_put(skb
, sizeof(*req
));
180 req
->wr
.wr_hi
= htonl(V_WR_OP(FW_WROPCODE_FORWARD
));
181 OPCODE_TID(req
) = htonl(MK_OPCODE_TID(CPL_TID_RELEASE
, hwtid
));
182 skb
->priority
= CPL_PRIORITY_SETUP
;
183 iwch_cxgb3_ofld_send(tdev
, skb
);
187 int iwch_quiesce_tid(struct iwch_ep
*ep
)
189 struct cpl_set_tcb_field
*req
;
190 struct sk_buff
*skb
= get_skb(NULL
, sizeof(*req
), GFP_KERNEL
);
194 req
= (struct cpl_set_tcb_field
*) skb_put(skb
, sizeof(*req
));
195 req
->wr
.wr_hi
= htonl(V_WR_OP(FW_WROPCODE_FORWARD
));
196 req
->wr
.wr_lo
= htonl(V_WR_TID(ep
->hwtid
));
197 OPCODE_TID(req
) = htonl(MK_OPCODE_TID(CPL_SET_TCB_FIELD
, ep
->hwtid
));
200 req
->word
= htons(W_TCB_RX_QUIESCE
);
201 req
->mask
= cpu_to_be64(1ULL << S_TCB_RX_QUIESCE
);
202 req
->val
= cpu_to_be64(1 << S_TCB_RX_QUIESCE
);
204 skb
->priority
= CPL_PRIORITY_DATA
;
205 return iwch_cxgb3_ofld_send(ep
->com
.tdev
, skb
);
208 int iwch_resume_tid(struct iwch_ep
*ep
)
210 struct cpl_set_tcb_field
*req
;
211 struct sk_buff
*skb
= get_skb(NULL
, sizeof(*req
), GFP_KERNEL
);
215 req
= (struct cpl_set_tcb_field
*) skb_put(skb
, sizeof(*req
));
216 req
->wr
.wr_hi
= htonl(V_WR_OP(FW_WROPCODE_FORWARD
));
217 req
->wr
.wr_lo
= htonl(V_WR_TID(ep
->hwtid
));
218 OPCODE_TID(req
) = htonl(MK_OPCODE_TID(CPL_SET_TCB_FIELD
, ep
->hwtid
));
221 req
->word
= htons(W_TCB_RX_QUIESCE
);
222 req
->mask
= cpu_to_be64(1ULL << S_TCB_RX_QUIESCE
);
225 skb
->priority
= CPL_PRIORITY_DATA
;
226 return iwch_cxgb3_ofld_send(ep
->com
.tdev
, skb
);
229 static void set_emss(struct iwch_ep
*ep
, u16 opt
)
231 PDBG("%s ep %p opt %u\n", __func__
, ep
, opt
);
232 ep
->emss
= T3C_DATA(ep
->com
.tdev
)->mtus
[G_TCPOPT_MSS(opt
)] - 40;
233 if (G_TCPOPT_TSTAMP(opt
))
237 PDBG("emss=%d\n", ep
->emss
);
240 static enum iwch_ep_state
state_read(struct iwch_ep_common
*epc
)
243 enum iwch_ep_state state
;
245 spin_lock_irqsave(&epc
->lock
, flags
);
247 spin_unlock_irqrestore(&epc
->lock
, flags
);
251 static void __state_set(struct iwch_ep_common
*epc
, enum iwch_ep_state
new)
256 static void state_set(struct iwch_ep_common
*epc
, enum iwch_ep_state
new)
260 spin_lock_irqsave(&epc
->lock
, flags
);
261 PDBG("%s - %s -> %s\n", __func__
, states
[epc
->state
], states
[new]);
262 __state_set(epc
, new);
263 spin_unlock_irqrestore(&epc
->lock
, flags
);
267 static void *alloc_ep(int size
, gfp_t gfp
)
269 struct iwch_ep_common
*epc
;
271 epc
= kzalloc(size
, gfp
);
273 kref_init(&epc
->kref
);
274 spin_lock_init(&epc
->lock
);
275 init_waitqueue_head(&epc
->waitq
);
277 PDBG("%s alloc ep %p\n", __func__
, epc
);
281 void __free_ep(struct kref
*kref
)
284 ep
= container_of(container_of(kref
, struct iwch_ep_common
, kref
),
285 struct iwch_ep
, com
);
286 PDBG("%s ep %p state %s\n", __func__
, ep
, states
[state_read(&ep
->com
)]);
287 if (test_bit(RELEASE_RESOURCES
, &ep
->com
.flags
)) {
288 cxgb3_remove_tid(ep
->com
.tdev
, (void *)ep
, ep
->hwtid
);
289 dst_release(ep
->dst
);
290 l2t_release(L2DATA(ep
->com
.tdev
), ep
->l2t
);
295 static void release_ep_resources(struct iwch_ep
*ep
)
297 PDBG("%s ep %p tid %d\n", __func__
, ep
, ep
->hwtid
);
298 set_bit(RELEASE_RESOURCES
, &ep
->com
.flags
);
302 static int status2errno(int status
)
307 case CPL_ERR_CONN_RESET
:
309 case CPL_ERR_ARP_MISS
:
310 return -EHOSTUNREACH
;
311 case CPL_ERR_CONN_TIMEDOUT
:
313 case CPL_ERR_TCAM_FULL
:
315 case CPL_ERR_CONN_EXIST
:
323 * Try and reuse skbs already allocated...
325 static struct sk_buff
*get_skb(struct sk_buff
*skb
, int len
, gfp_t gfp
)
327 if (skb
&& !skb_is_nonlinear(skb
) && !skb_cloned(skb
)) {
331 skb
= alloc_skb(len
, gfp
);
336 static struct rtable
*find_route(struct t3cdev
*dev
, __be32 local_ip
,
337 __be32 peer_ip
, __be16 local_port
,
338 __be16 peer_port
, u8 tos
)
349 .proto
= IPPROTO_TCP
,
357 if (ip_route_output_flow(&init_net
, &rt
, &fl
, NULL
, 0))
362 static unsigned int find_best_mtu(const struct t3c_data
*d
, unsigned short mtu
)
366 while (i
< d
->nmtus
- 1 && d
->mtus
[i
+ 1] <= mtu
)
371 static void arp_failure_discard(struct t3cdev
*dev
, struct sk_buff
*skb
)
373 PDBG("%s t3cdev %p\n", __func__
, dev
);
378 * Handle an ARP failure for an active open.
380 static void act_open_req_arp_failure(struct t3cdev
*dev
, struct sk_buff
*skb
)
382 printk(KERN_ERR MOD
"ARP failure duing connect\n");
387 * Handle an ARP failure for a CPL_ABORT_REQ. Change it into a no RST variant
390 static void abort_arp_failure(struct t3cdev
*dev
, struct sk_buff
*skb
)
392 struct cpl_abort_req
*req
= cplhdr(skb
);
394 PDBG("%s t3cdev %p\n", __func__
, dev
);
395 req
->cmd
= CPL_ABORT_NO_RST
;
396 iwch_cxgb3_ofld_send(dev
, skb
);
399 static int send_halfclose(struct iwch_ep
*ep
, gfp_t gfp
)
401 struct cpl_close_con_req
*req
;
404 PDBG("%s ep %p\n", __func__
, ep
);
405 skb
= get_skb(NULL
, sizeof(*req
), gfp
);
407 printk(KERN_ERR MOD
"%s - failed to alloc skb\n", __func__
);
410 skb
->priority
= CPL_PRIORITY_DATA
;
411 set_arp_failure_handler(skb
, arp_failure_discard
);
412 req
= (struct cpl_close_con_req
*) skb_put(skb
, sizeof(*req
));
413 req
->wr
.wr_hi
= htonl(V_WR_OP(FW_WROPCODE_OFLD_CLOSE_CON
));
414 req
->wr
.wr_lo
= htonl(V_WR_TID(ep
->hwtid
));
415 OPCODE_TID(req
) = htonl(MK_OPCODE_TID(CPL_CLOSE_CON_REQ
, ep
->hwtid
));
416 return iwch_l2t_send(ep
->com
.tdev
, skb
, ep
->l2t
);
419 static int send_abort(struct iwch_ep
*ep
, struct sk_buff
*skb
, gfp_t gfp
)
421 struct cpl_abort_req
*req
;
423 PDBG("%s ep %p\n", __func__
, ep
);
424 skb
= get_skb(skb
, sizeof(*req
), gfp
);
426 printk(KERN_ERR MOD
"%s - failed to alloc skb.\n",
430 skb
->priority
= CPL_PRIORITY_DATA
;
431 set_arp_failure_handler(skb
, abort_arp_failure
);
432 req
= (struct cpl_abort_req
*) skb_put(skb
, sizeof(*req
));
433 req
->wr
.wr_hi
= htonl(V_WR_OP(FW_WROPCODE_OFLD_HOST_ABORT_CON_REQ
));
434 req
->wr
.wr_lo
= htonl(V_WR_TID(ep
->hwtid
));
435 OPCODE_TID(req
) = htonl(MK_OPCODE_TID(CPL_ABORT_REQ
, ep
->hwtid
));
436 req
->cmd
= CPL_ABORT_SEND_RST
;
437 return iwch_l2t_send(ep
->com
.tdev
, skb
, ep
->l2t
);
440 static int send_connect(struct iwch_ep
*ep
)
442 struct cpl_act_open_req
*req
;
444 u32 opt0h
, opt0l
, opt2
;
445 unsigned int mtu_idx
;
448 PDBG("%s ep %p\n", __func__
, ep
);
450 skb
= get_skb(NULL
, sizeof(*req
), GFP_KERNEL
);
452 printk(KERN_ERR MOD
"%s - failed to alloc skb.\n",
456 mtu_idx
= find_best_mtu(T3C_DATA(ep
->com
.tdev
), dst_mtu(ep
->dst
));
457 wscale
= compute_wscale(rcv_win
);
462 V_WND_SCALE(wscale
) |
464 V_L2T_IDX(ep
->l2t
->idx
) | V_TX_CHANNEL(ep
->l2t
->smt_idx
);
465 opt0l
= V_TOS((ep
->tos
>> 2) & M_TOS
) | V_RCV_BUFSIZ(rcv_win
>>10);
466 opt2
= V_FLAVORS_VALID(1) | V_CONG_CONTROL_FLAVOR(cong_flavor
);
467 skb
->priority
= CPL_PRIORITY_SETUP
;
468 set_arp_failure_handler(skb
, act_open_req_arp_failure
);
470 req
= (struct cpl_act_open_req
*) skb_put(skb
, sizeof(*req
));
471 req
->wr
.wr_hi
= htonl(V_WR_OP(FW_WROPCODE_FORWARD
));
472 OPCODE_TID(req
) = htonl(MK_OPCODE_TID(CPL_ACT_OPEN_REQ
, ep
->atid
));
473 req
->local_port
= ep
->com
.local_addr
.sin_port
;
474 req
->peer_port
= ep
->com
.remote_addr
.sin_port
;
475 req
->local_ip
= ep
->com
.local_addr
.sin_addr
.s_addr
;
476 req
->peer_ip
= ep
->com
.remote_addr
.sin_addr
.s_addr
;
477 req
->opt0h
= htonl(opt0h
);
478 req
->opt0l
= htonl(opt0l
);
480 req
->opt2
= htonl(opt2
);
481 return iwch_l2t_send(ep
->com
.tdev
, skb
, ep
->l2t
);
484 static void send_mpa_req(struct iwch_ep
*ep
, struct sk_buff
*skb
)
487 struct tx_data_wr
*req
;
488 struct mpa_message
*mpa
;
491 PDBG("%s ep %p pd_len %d\n", __func__
, ep
, ep
->plen
);
493 BUG_ON(skb_cloned(skb
));
495 mpalen
= sizeof(*mpa
) + ep
->plen
;
496 if (skb
->data
+ mpalen
+ sizeof(*req
) > skb_end_pointer(skb
)) {
498 skb
=alloc_skb(mpalen
+ sizeof(*req
), GFP_KERNEL
);
500 connect_reply_upcall(ep
, -ENOMEM
);
505 skb_reserve(skb
, sizeof(*req
));
506 skb_put(skb
, mpalen
);
507 skb
->priority
= CPL_PRIORITY_DATA
;
508 mpa
= (struct mpa_message
*) skb
->data
;
509 memset(mpa
, 0, sizeof(*mpa
));
510 memcpy(mpa
->key
, MPA_KEY_REQ
, sizeof(mpa
->key
));
511 mpa
->flags
= (crc_enabled
? MPA_CRC
: 0) |
512 (markers_enabled
? MPA_MARKERS
: 0);
513 mpa
->private_data_size
= htons(ep
->plen
);
514 mpa
->revision
= mpa_rev
;
517 memcpy(mpa
->private_data
, ep
->mpa_pkt
+ sizeof(*mpa
), ep
->plen
);
520 * Reference the mpa skb. This ensures the data area
521 * will remain in memory until the hw acks the tx.
522 * Function tx_ack() will deref it.
525 set_arp_failure_handler(skb
, arp_failure_discard
);
526 skb_reset_transport_header(skb
);
528 req
= (struct tx_data_wr
*) skb_push(skb
, sizeof(*req
));
529 req
->wr_hi
= htonl(V_WR_OP(FW_WROPCODE_OFLD_TX_DATA
)|F_WR_COMPL
);
530 req
->wr_lo
= htonl(V_WR_TID(ep
->hwtid
));
531 req
->len
= htonl(len
);
532 req
->param
= htonl(V_TX_PORT(ep
->l2t
->smt_idx
) |
533 V_TX_SNDBUF(snd_win
>>15));
534 req
->flags
= htonl(F_TX_INIT
);
535 req
->sndseq
= htonl(ep
->snd_seq
);
538 iwch_l2t_send(ep
->com
.tdev
, skb
, ep
->l2t
);
540 state_set(&ep
->com
, MPA_REQ_SENT
);
544 static int send_mpa_reject(struct iwch_ep
*ep
, const void *pdata
, u8 plen
)
547 struct tx_data_wr
*req
;
548 struct mpa_message
*mpa
;
551 PDBG("%s ep %p plen %d\n", __func__
, ep
, plen
);
553 mpalen
= sizeof(*mpa
) + plen
;
555 skb
= get_skb(NULL
, mpalen
+ sizeof(*req
), GFP_KERNEL
);
557 printk(KERN_ERR MOD
"%s - cannot alloc skb!\n", __func__
);
560 skb_reserve(skb
, sizeof(*req
));
561 mpa
= (struct mpa_message
*) skb_put(skb
, mpalen
);
562 memset(mpa
, 0, sizeof(*mpa
));
563 memcpy(mpa
->key
, MPA_KEY_REP
, sizeof(mpa
->key
));
564 mpa
->flags
= MPA_REJECT
;
565 mpa
->revision
= mpa_rev
;
566 mpa
->private_data_size
= htons(plen
);
568 memcpy(mpa
->private_data
, pdata
, plen
);
571 * Reference the mpa skb again. This ensures the data area
572 * will remain in memory until the hw acks the tx.
573 * Function tx_ack() will deref it.
576 skb
->priority
= CPL_PRIORITY_DATA
;
577 set_arp_failure_handler(skb
, arp_failure_discard
);
578 skb_reset_transport_header(skb
);
579 req
= (struct tx_data_wr
*) skb_push(skb
, sizeof(*req
));
580 req
->wr_hi
= htonl(V_WR_OP(FW_WROPCODE_OFLD_TX_DATA
)|F_WR_COMPL
);
581 req
->wr_lo
= htonl(V_WR_TID(ep
->hwtid
));
582 req
->len
= htonl(mpalen
);
583 req
->param
= htonl(V_TX_PORT(ep
->l2t
->smt_idx
) |
584 V_TX_SNDBUF(snd_win
>>15));
585 req
->flags
= htonl(F_TX_INIT
);
586 req
->sndseq
= htonl(ep
->snd_seq
);
589 return iwch_l2t_send(ep
->com
.tdev
, skb
, ep
->l2t
);
592 static int send_mpa_reply(struct iwch_ep
*ep
, const void *pdata
, u8 plen
)
595 struct tx_data_wr
*req
;
596 struct mpa_message
*mpa
;
600 PDBG("%s ep %p plen %d\n", __func__
, ep
, plen
);
602 mpalen
= sizeof(*mpa
) + plen
;
604 skb
= get_skb(NULL
, mpalen
+ sizeof(*req
), GFP_KERNEL
);
606 printk(KERN_ERR MOD
"%s - cannot alloc skb!\n", __func__
);
609 skb
->priority
= CPL_PRIORITY_DATA
;
610 skb_reserve(skb
, sizeof(*req
));
611 mpa
= (struct mpa_message
*) skb_put(skb
, mpalen
);
612 memset(mpa
, 0, sizeof(*mpa
));
613 memcpy(mpa
->key
, MPA_KEY_REP
, sizeof(mpa
->key
));
614 mpa
->flags
= (ep
->mpa_attr
.crc_enabled
? MPA_CRC
: 0) |
615 (markers_enabled
? MPA_MARKERS
: 0);
616 mpa
->revision
= mpa_rev
;
617 mpa
->private_data_size
= htons(plen
);
619 memcpy(mpa
->private_data
, pdata
, plen
);
622 * Reference the mpa skb. This ensures the data area
623 * will remain in memory until the hw acks the tx.
624 * Function tx_ack() will deref it.
627 set_arp_failure_handler(skb
, arp_failure_discard
);
628 skb_reset_transport_header(skb
);
630 req
= (struct tx_data_wr
*) skb_push(skb
, sizeof(*req
));
631 req
->wr_hi
= htonl(V_WR_OP(FW_WROPCODE_OFLD_TX_DATA
)|F_WR_COMPL
);
632 req
->wr_lo
= htonl(V_WR_TID(ep
->hwtid
));
633 req
->len
= htonl(len
);
634 req
->param
= htonl(V_TX_PORT(ep
->l2t
->smt_idx
) |
635 V_TX_SNDBUF(snd_win
>>15));
636 req
->flags
= htonl(F_TX_INIT
);
637 req
->sndseq
= htonl(ep
->snd_seq
);
639 state_set(&ep
->com
, MPA_REP_SENT
);
640 return iwch_l2t_send(ep
->com
.tdev
, skb
, ep
->l2t
);
643 static int act_establish(struct t3cdev
*tdev
, struct sk_buff
*skb
, void *ctx
)
645 struct iwch_ep
*ep
= ctx
;
646 struct cpl_act_establish
*req
= cplhdr(skb
);
647 unsigned int tid
= GET_TID(req
);
649 PDBG("%s ep %p tid %d\n", __func__
, ep
, tid
);
651 dst_confirm(ep
->dst
);
653 /* setup the hwtid for this connection */
655 cxgb3_insert_tid(ep
->com
.tdev
, &t3c_client
, ep
, tid
);
657 ep
->snd_seq
= ntohl(req
->snd_isn
);
658 ep
->rcv_seq
= ntohl(req
->rcv_isn
);
660 set_emss(ep
, ntohs(req
->tcp_opt
));
662 /* dealloc the atid */
663 cxgb3_free_atid(ep
->com
.tdev
, ep
->atid
);
665 /* start MPA negotiation */
666 send_mpa_req(ep
, skb
);
671 static void abort_connection(struct iwch_ep
*ep
, struct sk_buff
*skb
, gfp_t gfp
)
673 PDBG("%s ep %p\n", __FILE__
, ep
);
674 state_set(&ep
->com
, ABORTING
);
675 send_abort(ep
, skb
, gfp
);
678 static void close_complete_upcall(struct iwch_ep
*ep
)
680 struct iw_cm_event event
;
682 PDBG("%s ep %p\n", __func__
, ep
);
683 memset(&event
, 0, sizeof(event
));
684 event
.event
= IW_CM_EVENT_CLOSE
;
686 PDBG("close complete delivered ep %p cm_id %p tid %d\n",
687 ep
, ep
->com
.cm_id
, ep
->hwtid
);
688 ep
->com
.cm_id
->event_handler(ep
->com
.cm_id
, &event
);
689 ep
->com
.cm_id
->rem_ref(ep
->com
.cm_id
);
690 ep
->com
.cm_id
= NULL
;
695 static void peer_close_upcall(struct iwch_ep
*ep
)
697 struct iw_cm_event event
;
699 PDBG("%s ep %p\n", __func__
, ep
);
700 memset(&event
, 0, sizeof(event
));
701 event
.event
= IW_CM_EVENT_DISCONNECT
;
703 PDBG("peer close delivered ep %p cm_id %p tid %d\n",
704 ep
, ep
->com
.cm_id
, ep
->hwtid
);
705 ep
->com
.cm_id
->event_handler(ep
->com
.cm_id
, &event
);
709 static void peer_abort_upcall(struct iwch_ep
*ep
)
711 struct iw_cm_event event
;
713 PDBG("%s ep %p\n", __func__
, ep
);
714 memset(&event
, 0, sizeof(event
));
715 event
.event
= IW_CM_EVENT_CLOSE
;
716 event
.status
= -ECONNRESET
;
718 PDBG("abort delivered ep %p cm_id %p tid %d\n", ep
,
719 ep
->com
.cm_id
, ep
->hwtid
);
720 ep
->com
.cm_id
->event_handler(ep
->com
.cm_id
, &event
);
721 ep
->com
.cm_id
->rem_ref(ep
->com
.cm_id
);
722 ep
->com
.cm_id
= NULL
;
727 static void connect_reply_upcall(struct iwch_ep
*ep
, int status
)
729 struct iw_cm_event event
;
731 PDBG("%s ep %p status %d\n", __func__
, ep
, status
);
732 memset(&event
, 0, sizeof(event
));
733 event
.event
= IW_CM_EVENT_CONNECT_REPLY
;
734 event
.status
= status
;
735 event
.local_addr
= ep
->com
.local_addr
;
736 event
.remote_addr
= ep
->com
.remote_addr
;
738 if ((status
== 0) || (status
== -ECONNREFUSED
)) {
739 event
.private_data_len
= ep
->plen
;
740 event
.private_data
= ep
->mpa_pkt
+ sizeof(struct mpa_message
);
743 PDBG("%s ep %p tid %d status %d\n", __func__
, ep
,
745 ep
->com
.cm_id
->event_handler(ep
->com
.cm_id
, &event
);
748 ep
->com
.cm_id
->rem_ref(ep
->com
.cm_id
);
749 ep
->com
.cm_id
= NULL
;
754 static void connect_request_upcall(struct iwch_ep
*ep
)
756 struct iw_cm_event event
;
758 PDBG("%s ep %p tid %d\n", __func__
, ep
, ep
->hwtid
);
759 memset(&event
, 0, sizeof(event
));
760 event
.event
= IW_CM_EVENT_CONNECT_REQUEST
;
761 event
.local_addr
= ep
->com
.local_addr
;
762 event
.remote_addr
= ep
->com
.remote_addr
;
763 event
.private_data_len
= ep
->plen
;
764 event
.private_data
= ep
->mpa_pkt
+ sizeof(struct mpa_message
);
765 event
.provider_data
= ep
;
766 if (state_read(&ep
->parent_ep
->com
) != DEAD
) {
768 ep
->parent_ep
->com
.cm_id
->event_handler(
769 ep
->parent_ep
->com
.cm_id
,
772 put_ep(&ep
->parent_ep
->com
);
773 ep
->parent_ep
= NULL
;
776 static void established_upcall(struct iwch_ep
*ep
)
778 struct iw_cm_event event
;
780 PDBG("%s ep %p\n", __func__
, ep
);
781 memset(&event
, 0, sizeof(event
));
782 event
.event
= IW_CM_EVENT_ESTABLISHED
;
784 PDBG("%s ep %p tid %d\n", __func__
, ep
, ep
->hwtid
);
785 ep
->com
.cm_id
->event_handler(ep
->com
.cm_id
, &event
);
789 static int update_rx_credits(struct iwch_ep
*ep
, u32 credits
)
791 struct cpl_rx_data_ack
*req
;
794 PDBG("%s ep %p credits %u\n", __func__
, ep
, credits
);
795 skb
= get_skb(NULL
, sizeof(*req
), GFP_KERNEL
);
797 printk(KERN_ERR MOD
"update_rx_credits - cannot alloc skb!\n");
801 req
= (struct cpl_rx_data_ack
*) skb_put(skb
, sizeof(*req
));
802 req
->wr
.wr_hi
= htonl(V_WR_OP(FW_WROPCODE_FORWARD
));
803 OPCODE_TID(req
) = htonl(MK_OPCODE_TID(CPL_RX_DATA_ACK
, ep
->hwtid
));
804 req
->credit_dack
= htonl(V_RX_CREDITS(credits
) | V_RX_FORCE_ACK(1));
805 skb
->priority
= CPL_PRIORITY_ACK
;
806 iwch_cxgb3_ofld_send(ep
->com
.tdev
, skb
);
810 static void process_mpa_reply(struct iwch_ep
*ep
, struct sk_buff
*skb
)
812 struct mpa_message
*mpa
;
814 struct iwch_qp_attributes attrs
;
815 enum iwch_qp_attr_mask mask
;
818 PDBG("%s ep %p\n", __func__
, ep
);
821 * Stop mpa timer. If it expired, then the state has
822 * changed and we bail since ep_timeout already aborted
826 if (state_read(&ep
->com
) != MPA_REQ_SENT
)
830 * If we get more than the supported amount of private data
831 * then we must fail this connection.
833 if (ep
->mpa_pkt_len
+ skb
->len
> sizeof(ep
->mpa_pkt
)) {
839 * copy the new data into our accumulation buffer.
841 skb_copy_from_linear_data(skb
, &(ep
->mpa_pkt
[ep
->mpa_pkt_len
]),
843 ep
->mpa_pkt_len
+= skb
->len
;
846 * if we don't even have the mpa message, then bail.
848 if (ep
->mpa_pkt_len
< sizeof(*mpa
))
850 mpa
= (struct mpa_message
*) ep
->mpa_pkt
;
852 /* Validate MPA header. */
853 if (mpa
->revision
!= mpa_rev
) {
857 if (memcmp(mpa
->key
, MPA_KEY_REP
, sizeof(mpa
->key
))) {
862 plen
= ntohs(mpa
->private_data_size
);
865 * Fail if there's too much private data.
867 if (plen
> MPA_MAX_PRIVATE_DATA
) {
873 * If plen does not account for pkt size
875 if (ep
->mpa_pkt_len
> (sizeof(*mpa
) + plen
)) {
880 ep
->plen
= (u8
) plen
;
883 * If we don't have all the pdata yet, then bail.
884 * We'll continue process when more data arrives.
886 if (ep
->mpa_pkt_len
< (sizeof(*mpa
) + plen
))
889 if (mpa
->flags
& MPA_REJECT
) {
895 * If we get here we have accumulated the entire mpa
896 * start reply message including private data. And
897 * the MPA header is valid.
899 state_set(&ep
->com
, FPDU_MODE
);
900 ep
->mpa_attr
.initiator
= 1;
901 ep
->mpa_attr
.crc_enabled
= (mpa
->flags
& MPA_CRC
) | crc_enabled
? 1 : 0;
902 ep
->mpa_attr
.recv_marker_enabled
= markers_enabled
;
903 ep
->mpa_attr
.xmit_marker_enabled
= mpa
->flags
& MPA_MARKERS
? 1 : 0;
904 ep
->mpa_attr
.version
= mpa_rev
;
905 PDBG("%s - crc_enabled=%d, recv_marker_enabled=%d, "
906 "xmit_marker_enabled=%d, version=%d\n", __func__
,
907 ep
->mpa_attr
.crc_enabled
, ep
->mpa_attr
.recv_marker_enabled
,
908 ep
->mpa_attr
.xmit_marker_enabled
, ep
->mpa_attr
.version
);
910 attrs
.mpa_attr
= ep
->mpa_attr
;
911 attrs
.max_ird
= ep
->ird
;
912 attrs
.max_ord
= ep
->ord
;
913 attrs
.llp_stream_handle
= ep
;
914 attrs
.next_state
= IWCH_QP_STATE_RTS
;
916 mask
= IWCH_QP_ATTR_NEXT_STATE
|
917 IWCH_QP_ATTR_LLP_STREAM_HANDLE
| IWCH_QP_ATTR_MPA_ATTR
|
918 IWCH_QP_ATTR_MAX_IRD
| IWCH_QP_ATTR_MAX_ORD
;
920 /* bind QP and TID with INIT_WR */
921 err
= iwch_modify_qp(ep
->com
.qp
->rhp
,
922 ep
->com
.qp
, mask
, &attrs
, 1);
926 if (peer2peer
&& iwch_rqes_posted(ep
->com
.qp
) == 0) {
927 iwch_post_zb_read(ep
->com
.qp
);
932 abort_connection(ep
, skb
, GFP_KERNEL
);
934 connect_reply_upcall(ep
, err
);
938 static void process_mpa_request(struct iwch_ep
*ep
, struct sk_buff
*skb
)
940 struct mpa_message
*mpa
;
943 PDBG("%s ep %p\n", __func__
, ep
);
946 * Stop mpa timer. If it expired, then the state has
947 * changed and we bail since ep_timeout already aborted
951 if (state_read(&ep
->com
) != MPA_REQ_WAIT
)
955 * If we get more than the supported amount of private data
956 * then we must fail this connection.
958 if (ep
->mpa_pkt_len
+ skb
->len
> sizeof(ep
->mpa_pkt
)) {
959 abort_connection(ep
, skb
, GFP_KERNEL
);
963 PDBG("%s enter (%s line %u)\n", __func__
, __FILE__
, __LINE__
);
966 * Copy the new data into our accumulation buffer.
968 skb_copy_from_linear_data(skb
, &(ep
->mpa_pkt
[ep
->mpa_pkt_len
]),
970 ep
->mpa_pkt_len
+= skb
->len
;
973 * If we don't even have the mpa message, then bail.
974 * We'll continue process when more data arrives.
976 if (ep
->mpa_pkt_len
< sizeof(*mpa
))
978 PDBG("%s enter (%s line %u)\n", __func__
, __FILE__
, __LINE__
);
979 mpa
= (struct mpa_message
*) ep
->mpa_pkt
;
982 * Validate MPA Header.
984 if (mpa
->revision
!= mpa_rev
) {
985 abort_connection(ep
, skb
, GFP_KERNEL
);
989 if (memcmp(mpa
->key
, MPA_KEY_REQ
, sizeof(mpa
->key
))) {
990 abort_connection(ep
, skb
, GFP_KERNEL
);
994 plen
= ntohs(mpa
->private_data_size
);
997 * Fail if there's too much private data.
999 if (plen
> MPA_MAX_PRIVATE_DATA
) {
1000 abort_connection(ep
, skb
, GFP_KERNEL
);
1005 * If plen does not account for pkt size
1007 if (ep
->mpa_pkt_len
> (sizeof(*mpa
) + plen
)) {
1008 abort_connection(ep
, skb
, GFP_KERNEL
);
1011 ep
->plen
= (u8
) plen
;
1014 * If we don't have all the pdata yet, then bail.
1016 if (ep
->mpa_pkt_len
< (sizeof(*mpa
) + plen
))
1020 * If we get here we have accumulated the entire mpa
1021 * start reply message including private data.
1023 ep
->mpa_attr
.initiator
= 0;
1024 ep
->mpa_attr
.crc_enabled
= (mpa
->flags
& MPA_CRC
) | crc_enabled
? 1 : 0;
1025 ep
->mpa_attr
.recv_marker_enabled
= markers_enabled
;
1026 ep
->mpa_attr
.xmit_marker_enabled
= mpa
->flags
& MPA_MARKERS
? 1 : 0;
1027 ep
->mpa_attr
.version
= mpa_rev
;
1028 PDBG("%s - crc_enabled=%d, recv_marker_enabled=%d, "
1029 "xmit_marker_enabled=%d, version=%d\n", __func__
,
1030 ep
->mpa_attr
.crc_enabled
, ep
->mpa_attr
.recv_marker_enabled
,
1031 ep
->mpa_attr
.xmit_marker_enabled
, ep
->mpa_attr
.version
);
1033 state_set(&ep
->com
, MPA_REQ_RCVD
);
1036 connect_request_upcall(ep
);
1040 static int rx_data(struct t3cdev
*tdev
, struct sk_buff
*skb
, void *ctx
)
1042 struct iwch_ep
*ep
= ctx
;
1043 struct cpl_rx_data
*hdr
= cplhdr(skb
);
1044 unsigned int dlen
= ntohs(hdr
->len
);
1046 PDBG("%s ep %p dlen %u\n", __func__
, ep
, dlen
);
1048 skb_pull(skb
, sizeof(*hdr
));
1049 skb_trim(skb
, dlen
);
1051 ep
->rcv_seq
+= dlen
;
1052 BUG_ON(ep
->rcv_seq
!= (ntohl(hdr
->seq
) + dlen
));
1054 switch (state_read(&ep
->com
)) {
1056 process_mpa_reply(ep
, skb
);
1059 process_mpa_request(ep
, skb
);
1064 printk(KERN_ERR MOD
"%s Unexpected streaming data."
1065 " ep %p state %d tid %d\n",
1066 __func__
, ep
, state_read(&ep
->com
), ep
->hwtid
);
1069 * The ep will timeout and inform the ULP of the failure.
1075 /* update RX credits */
1076 update_rx_credits(ep
, dlen
);
1078 return CPL_RET_BUF_DONE
;
1082 * Upcall from the adapter indicating data has been transmitted.
1083 * For us its just the single MPA request or reply. We can now free
1084 * the skb holding the mpa message.
1086 static int tx_ack(struct t3cdev
*tdev
, struct sk_buff
*skb
, void *ctx
)
1088 struct iwch_ep
*ep
= ctx
;
1089 struct cpl_wr_ack
*hdr
= cplhdr(skb
);
1090 unsigned int credits
= ntohs(hdr
->credits
);
1092 PDBG("%s ep %p credits %u\n", __func__
, ep
, credits
);
1095 PDBG(KERN_ERR
"%s 0 credit ack ep %p state %u\n",
1096 __func__
, ep
, state_read(&ep
->com
));
1097 return CPL_RET_BUF_DONE
;
1100 BUG_ON(credits
!= 1);
1101 dst_confirm(ep
->dst
);
1103 PDBG("%s rdma_init wr_ack ep %p state %u\n",
1104 __func__
, ep
, state_read(&ep
->com
));
1105 if (ep
->mpa_attr
.initiator
) {
1106 PDBG("%s initiator ep %p state %u\n",
1107 __func__
, ep
, state_read(&ep
->com
));
1109 iwch_post_zb_read(ep
->com
.qp
);
1111 PDBG("%s responder ep %p state %u\n",
1112 __func__
, ep
, state_read(&ep
->com
));
1113 ep
->com
.rpl_done
= 1;
1114 wake_up(&ep
->com
.waitq
);
1117 PDBG("%s lsm ack ep %p state %u freeing skb\n",
1118 __func__
, ep
, state_read(&ep
->com
));
1119 kfree_skb(ep
->mpa_skb
);
1122 return CPL_RET_BUF_DONE
;
1125 static int abort_rpl(struct t3cdev
*tdev
, struct sk_buff
*skb
, void *ctx
)
1127 struct iwch_ep
*ep
= ctx
;
1128 unsigned long flags
;
1131 PDBG("%s ep %p\n", __func__
, ep
);
1135 * We get 2 abort replies from the HW. The first one must
1136 * be ignored except for scribbling that we need one more.
1138 if (!test_and_set_bit(ABORT_REQ_IN_PROGRESS
, &ep
->com
.flags
)) {
1139 return CPL_RET_BUF_DONE
;
1142 spin_lock_irqsave(&ep
->com
.lock
, flags
);
1143 switch (ep
->com
.state
) {
1145 close_complete_upcall(ep
);
1146 __state_set(&ep
->com
, DEAD
);
1150 printk(KERN_ERR
"%s ep %p state %d\n",
1151 __func__
, ep
, ep
->com
.state
);
1154 spin_unlock_irqrestore(&ep
->com
.lock
, flags
);
1157 release_ep_resources(ep
);
1158 return CPL_RET_BUF_DONE
;
1162 * Return whether a failed active open has allocated a TID
1164 static inline int act_open_has_tid(int status
)
1166 return status
!= CPL_ERR_TCAM_FULL
&& status
!= CPL_ERR_CONN_EXIST
&&
1167 status
!= CPL_ERR_ARP_MISS
;
1170 static int act_open_rpl(struct t3cdev
*tdev
, struct sk_buff
*skb
, void *ctx
)
1172 struct iwch_ep
*ep
= ctx
;
1173 struct cpl_act_open_rpl
*rpl
= cplhdr(skb
);
1175 PDBG("%s ep %p status %u errno %d\n", __func__
, ep
, rpl
->status
,
1176 status2errno(rpl
->status
));
1177 connect_reply_upcall(ep
, status2errno(rpl
->status
));
1178 state_set(&ep
->com
, DEAD
);
1179 if (ep
->com
.tdev
->type
!= T3A
&& act_open_has_tid(rpl
->status
))
1180 release_tid(ep
->com
.tdev
, GET_TID(rpl
), NULL
);
1181 cxgb3_free_atid(ep
->com
.tdev
, ep
->atid
);
1182 dst_release(ep
->dst
);
1183 l2t_release(L2DATA(ep
->com
.tdev
), ep
->l2t
);
1185 return CPL_RET_BUF_DONE
;
1188 static int listen_start(struct iwch_listen_ep
*ep
)
1190 struct sk_buff
*skb
;
1191 struct cpl_pass_open_req
*req
;
1193 PDBG("%s ep %p\n", __func__
, ep
);
1194 skb
= get_skb(NULL
, sizeof(*req
), GFP_KERNEL
);
1196 printk(KERN_ERR MOD
"t3c_listen_start failed to alloc skb!\n");
1200 req
= (struct cpl_pass_open_req
*) skb_put(skb
, sizeof(*req
));
1201 req
->wr
.wr_hi
= htonl(V_WR_OP(FW_WROPCODE_FORWARD
));
1202 OPCODE_TID(req
) = htonl(MK_OPCODE_TID(CPL_PASS_OPEN_REQ
, ep
->stid
));
1203 req
->local_port
= ep
->com
.local_addr
.sin_port
;
1204 req
->local_ip
= ep
->com
.local_addr
.sin_addr
.s_addr
;
1207 req
->peer_netmask
= 0;
1208 req
->opt0h
= htonl(F_DELACK
| F_TCAM_BYPASS
);
1209 req
->opt0l
= htonl(V_RCV_BUFSIZ(rcv_win
>>10));
1210 req
->opt1
= htonl(V_CONN_POLICY(CPL_CONN_POLICY_ASK
));
1213 return iwch_cxgb3_ofld_send(ep
->com
.tdev
, skb
);
1216 static int pass_open_rpl(struct t3cdev
*tdev
, struct sk_buff
*skb
, void *ctx
)
1218 struct iwch_listen_ep
*ep
= ctx
;
1219 struct cpl_pass_open_rpl
*rpl
= cplhdr(skb
);
1221 PDBG("%s ep %p status %d error %d\n", __func__
, ep
,
1222 rpl
->status
, status2errno(rpl
->status
));
1223 ep
->com
.rpl_err
= status2errno(rpl
->status
);
1224 ep
->com
.rpl_done
= 1;
1225 wake_up(&ep
->com
.waitq
);
1227 return CPL_RET_BUF_DONE
;
1230 static int listen_stop(struct iwch_listen_ep
*ep
)
1232 struct sk_buff
*skb
;
1233 struct cpl_close_listserv_req
*req
;
1235 PDBG("%s ep %p\n", __func__
, ep
);
1236 skb
= get_skb(NULL
, sizeof(*req
), GFP_KERNEL
);
1238 printk(KERN_ERR MOD
"%s - failed to alloc skb\n", __func__
);
1241 req
= (struct cpl_close_listserv_req
*) skb_put(skb
, sizeof(*req
));
1242 req
->wr
.wr_hi
= htonl(V_WR_OP(FW_WROPCODE_FORWARD
));
1244 OPCODE_TID(req
) = htonl(MK_OPCODE_TID(CPL_CLOSE_LISTSRV_REQ
, ep
->stid
));
1246 return iwch_cxgb3_ofld_send(ep
->com
.tdev
, skb
);
1249 static int close_listsrv_rpl(struct t3cdev
*tdev
, struct sk_buff
*skb
,
1252 struct iwch_listen_ep
*ep
= ctx
;
1253 struct cpl_close_listserv_rpl
*rpl
= cplhdr(skb
);
1255 PDBG("%s ep %p\n", __func__
, ep
);
1256 ep
->com
.rpl_err
= status2errno(rpl
->status
);
1257 ep
->com
.rpl_done
= 1;
1258 wake_up(&ep
->com
.waitq
);
1259 return CPL_RET_BUF_DONE
;
1262 static void accept_cr(struct iwch_ep
*ep
, __be32 peer_ip
, struct sk_buff
*skb
)
1264 struct cpl_pass_accept_rpl
*rpl
;
1265 unsigned int mtu_idx
;
1266 u32 opt0h
, opt0l
, opt2
;
1269 PDBG("%s ep %p\n", __func__
, ep
);
1270 BUG_ON(skb_cloned(skb
));
1271 skb_trim(skb
, sizeof(*rpl
));
1273 mtu_idx
= find_best_mtu(T3C_DATA(ep
->com
.tdev
), dst_mtu(ep
->dst
));
1274 wscale
= compute_wscale(rcv_win
);
1275 opt0h
= V_NAGLE(0) |
1279 V_WND_SCALE(wscale
) |
1280 V_MSS_IDX(mtu_idx
) |
1281 V_L2T_IDX(ep
->l2t
->idx
) | V_TX_CHANNEL(ep
->l2t
->smt_idx
);
1282 opt0l
= V_TOS((ep
->tos
>> 2) & M_TOS
) | V_RCV_BUFSIZ(rcv_win
>>10);
1283 opt2
= V_FLAVORS_VALID(1) | V_CONG_CONTROL_FLAVOR(cong_flavor
);
1286 rpl
->wr
.wr_hi
= htonl(V_WR_OP(FW_WROPCODE_FORWARD
));
1287 OPCODE_TID(rpl
) = htonl(MK_OPCODE_TID(CPL_PASS_ACCEPT_RPL
, ep
->hwtid
));
1288 rpl
->peer_ip
= peer_ip
;
1289 rpl
->opt0h
= htonl(opt0h
);
1290 rpl
->opt0l_status
= htonl(opt0l
| CPL_PASS_OPEN_ACCEPT
);
1291 rpl
->opt2
= htonl(opt2
);
1292 rpl
->rsvd
= rpl
->opt2
; /* workaround for HW bug */
1293 skb
->priority
= CPL_PRIORITY_SETUP
;
1294 iwch_l2t_send(ep
->com
.tdev
, skb
, ep
->l2t
);
1299 static void reject_cr(struct t3cdev
*tdev
, u32 hwtid
, __be32 peer_ip
,
1300 struct sk_buff
*skb
)
1302 PDBG("%s t3cdev %p tid %u peer_ip %x\n", __func__
, tdev
, hwtid
,
1304 BUG_ON(skb_cloned(skb
));
1305 skb_trim(skb
, sizeof(struct cpl_tid_release
));
1308 if (tdev
->type
!= T3A
)
1309 release_tid(tdev
, hwtid
, skb
);
1311 struct cpl_pass_accept_rpl
*rpl
;
1314 skb
->priority
= CPL_PRIORITY_SETUP
;
1315 rpl
->wr
.wr_hi
= htonl(V_WR_OP(FW_WROPCODE_FORWARD
));
1316 OPCODE_TID(rpl
) = htonl(MK_OPCODE_TID(CPL_PASS_ACCEPT_RPL
,
1318 rpl
->peer_ip
= peer_ip
;
1319 rpl
->opt0h
= htonl(F_TCAM_BYPASS
);
1320 rpl
->opt0l_status
= htonl(CPL_PASS_OPEN_REJECT
);
1322 rpl
->rsvd
= rpl
->opt2
;
1323 iwch_cxgb3_ofld_send(tdev
, skb
);
1327 static int pass_accept_req(struct t3cdev
*tdev
, struct sk_buff
*skb
, void *ctx
)
1329 struct iwch_ep
*child_ep
, *parent_ep
= ctx
;
1330 struct cpl_pass_accept_req
*req
= cplhdr(skb
);
1331 unsigned int hwtid
= GET_TID(req
);
1332 struct dst_entry
*dst
;
1333 struct l2t_entry
*l2t
;
1337 PDBG("%s parent ep %p tid %u\n", __func__
, parent_ep
, hwtid
);
1339 if (state_read(&parent_ep
->com
) != LISTEN
) {
1340 printk(KERN_ERR
"%s - listening ep not in LISTEN\n",
1346 * Find the netdev for this connection request.
1348 tim
.mac_addr
= req
->dst_mac
;
1349 tim
.vlan_tag
= ntohs(req
->vlan_tag
);
1350 if (tdev
->ctl(tdev
, GET_IFF_FROM_MAC
, &tim
) < 0 || !tim
.dev
) {
1351 printk(KERN_ERR
"%s bad dst mac %pM\n",
1352 __func__
, req
->dst_mac
);
1356 /* Find output route */
1357 rt
= find_route(tdev
,
1361 req
->peer_port
, G_PASS_OPEN_TOS(ntohl(req
->tos_tid
)));
1363 printk(KERN_ERR MOD
"%s - failed to find dst entry!\n",
1368 l2t
= t3_l2t_get(tdev
, dst
->neighbour
, dst
->neighbour
->dev
);
1370 printk(KERN_ERR MOD
"%s - failed to allocate l2t entry!\n",
1375 child_ep
= alloc_ep(sizeof(*child_ep
), GFP_KERNEL
);
1377 printk(KERN_ERR MOD
"%s - failed to allocate ep entry!\n",
1379 l2t_release(L2DATA(tdev
), l2t
);
1383 state_set(&child_ep
->com
, CONNECTING
);
1384 child_ep
->com
.tdev
= tdev
;
1385 child_ep
->com
.cm_id
= NULL
;
1386 child_ep
->com
.local_addr
.sin_family
= PF_INET
;
1387 child_ep
->com
.local_addr
.sin_port
= req
->local_port
;
1388 child_ep
->com
.local_addr
.sin_addr
.s_addr
= req
->local_ip
;
1389 child_ep
->com
.remote_addr
.sin_family
= PF_INET
;
1390 child_ep
->com
.remote_addr
.sin_port
= req
->peer_port
;
1391 child_ep
->com
.remote_addr
.sin_addr
.s_addr
= req
->peer_ip
;
1392 get_ep(&parent_ep
->com
);
1393 child_ep
->parent_ep
= parent_ep
;
1394 child_ep
->tos
= G_PASS_OPEN_TOS(ntohl(req
->tos_tid
));
1395 child_ep
->l2t
= l2t
;
1396 child_ep
->dst
= dst
;
1397 child_ep
->hwtid
= hwtid
;
1398 init_timer(&child_ep
->timer
);
1399 cxgb3_insert_tid(tdev
, &t3c_client
, child_ep
, hwtid
);
1400 accept_cr(child_ep
, req
->peer_ip
, skb
);
1403 reject_cr(tdev
, hwtid
, req
->peer_ip
, skb
);
1405 return CPL_RET_BUF_DONE
;
1408 static int pass_establish(struct t3cdev
*tdev
, struct sk_buff
*skb
, void *ctx
)
1410 struct iwch_ep
*ep
= ctx
;
1411 struct cpl_pass_establish
*req
= cplhdr(skb
);
1413 PDBG("%s ep %p\n", __func__
, ep
);
1414 ep
->snd_seq
= ntohl(req
->snd_isn
);
1415 ep
->rcv_seq
= ntohl(req
->rcv_isn
);
1417 set_emss(ep
, ntohs(req
->tcp_opt
));
1419 dst_confirm(ep
->dst
);
1420 state_set(&ep
->com
, MPA_REQ_WAIT
);
1423 return CPL_RET_BUF_DONE
;
1426 static int peer_close(struct t3cdev
*tdev
, struct sk_buff
*skb
, void *ctx
)
1428 struct iwch_ep
*ep
= ctx
;
1429 struct iwch_qp_attributes attrs
;
1430 unsigned long flags
;
1434 PDBG("%s ep %p\n", __func__
, ep
);
1435 dst_confirm(ep
->dst
);
1437 spin_lock_irqsave(&ep
->com
.lock
, flags
);
1438 switch (ep
->com
.state
) {
1440 __state_set(&ep
->com
, CLOSING
);
1443 __state_set(&ep
->com
, CLOSING
);
1444 connect_reply_upcall(ep
, -ECONNRESET
);
1449 * We're gonna mark this puppy DEAD, but keep
1450 * the reference on it until the ULP accepts or
1451 * rejects the CR. Also wake up anyone waiting
1452 * in rdma connection migration (see iwch_accept_cr()).
1454 __state_set(&ep
->com
, CLOSING
);
1455 ep
->com
.rpl_done
= 1;
1456 ep
->com
.rpl_err
= -ECONNRESET
;
1457 PDBG("waking up ep %p\n", ep
);
1458 wake_up(&ep
->com
.waitq
);
1461 __state_set(&ep
->com
, CLOSING
);
1462 ep
->com
.rpl_done
= 1;
1463 ep
->com
.rpl_err
= -ECONNRESET
;
1464 PDBG("waking up ep %p\n", ep
);
1465 wake_up(&ep
->com
.waitq
);
1469 __state_set(&ep
->com
, CLOSING
);
1470 attrs
.next_state
= IWCH_QP_STATE_CLOSING
;
1471 iwch_modify_qp(ep
->com
.qp
->rhp
, ep
->com
.qp
,
1472 IWCH_QP_ATTR_NEXT_STATE
, &attrs
, 1);
1473 peer_close_upcall(ep
);
1479 __state_set(&ep
->com
, MORIBUND
);
1484 if (ep
->com
.cm_id
&& ep
->com
.qp
) {
1485 attrs
.next_state
= IWCH_QP_STATE_IDLE
;
1486 iwch_modify_qp(ep
->com
.qp
->rhp
, ep
->com
.qp
,
1487 IWCH_QP_ATTR_NEXT_STATE
, &attrs
, 1);
1489 close_complete_upcall(ep
);
1490 __state_set(&ep
->com
, DEAD
);
1500 spin_unlock_irqrestore(&ep
->com
.lock
, flags
);
1502 iwch_ep_disconnect(ep
, 0, GFP_KERNEL
);
1504 release_ep_resources(ep
);
1505 return CPL_RET_BUF_DONE
;
1509 * Returns whether an ABORT_REQ_RSS message is a negative advice.
1511 static int is_neg_adv_abort(unsigned int status
)
1513 return status
== CPL_ERR_RTX_NEG_ADVICE
||
1514 status
== CPL_ERR_PERSIST_NEG_ADVICE
;
1517 static int peer_abort(struct t3cdev
*tdev
, struct sk_buff
*skb
, void *ctx
)
1519 struct cpl_abort_req_rss
*req
= cplhdr(skb
);
1520 struct iwch_ep
*ep
= ctx
;
1521 struct cpl_abort_rpl
*rpl
;
1522 struct sk_buff
*rpl_skb
;
1523 struct iwch_qp_attributes attrs
;
1526 unsigned long flags
;
1528 if (is_neg_adv_abort(req
->status
)) {
1529 PDBG("%s neg_adv_abort ep %p tid %d\n", __func__
, ep
,
1531 t3_l2t_send_event(ep
->com
.tdev
, ep
->l2t
);
1532 return CPL_RET_BUF_DONE
;
1536 * We get 2 peer aborts from the HW. The first one must
1537 * be ignored except for scribbling that we need one more.
1539 if (!test_and_set_bit(PEER_ABORT_IN_PROGRESS
, &ep
->com
.flags
)) {
1540 return CPL_RET_BUF_DONE
;
1543 spin_lock_irqsave(&ep
->com
.lock
, flags
);
1544 PDBG("%s ep %p state %u\n", __func__
, ep
, ep
->com
.state
);
1545 switch (ep
->com
.state
) {
1553 connect_reply_upcall(ep
, -ECONNRESET
);
1556 ep
->com
.rpl_done
= 1;
1557 ep
->com
.rpl_err
= -ECONNRESET
;
1558 PDBG("waking up ep %p\n", ep
);
1559 wake_up(&ep
->com
.waitq
);
1564 * We're gonna mark this puppy DEAD, but keep
1565 * the reference on it until the ULP accepts or
1566 * rejects the CR. Also wake up anyone waiting
1567 * in rdma connection migration (see iwch_accept_cr()).
1569 ep
->com
.rpl_done
= 1;
1570 ep
->com
.rpl_err
= -ECONNRESET
;
1571 PDBG("waking up ep %p\n", ep
);
1572 wake_up(&ep
->com
.waitq
);
1579 if (ep
->com
.cm_id
&& ep
->com
.qp
) {
1580 attrs
.next_state
= IWCH_QP_STATE_ERROR
;
1581 ret
= iwch_modify_qp(ep
->com
.qp
->rhp
,
1582 ep
->com
.qp
, IWCH_QP_ATTR_NEXT_STATE
,
1586 "%s - qp <- error failed!\n",
1589 peer_abort_upcall(ep
);
1594 PDBG("%s PEER_ABORT IN DEAD STATE!!!!\n", __func__
);
1595 spin_unlock_irqrestore(&ep
->com
.lock
, flags
);
1596 return CPL_RET_BUF_DONE
;
1601 dst_confirm(ep
->dst
);
1602 if (ep
->com
.state
!= ABORTING
) {
1603 __state_set(&ep
->com
, DEAD
);
1606 spin_unlock_irqrestore(&ep
->com
.lock
, flags
);
1608 rpl_skb
= get_skb(skb
, sizeof(*rpl
), GFP_KERNEL
);
1610 printk(KERN_ERR MOD
"%s - cannot allocate skb!\n",
1615 rpl_skb
->priority
= CPL_PRIORITY_DATA
;
1616 rpl
= (struct cpl_abort_rpl
*) skb_put(rpl_skb
, sizeof(*rpl
));
1617 rpl
->wr
.wr_hi
= htonl(V_WR_OP(FW_WROPCODE_OFLD_HOST_ABORT_CON_RPL
));
1618 rpl
->wr
.wr_lo
= htonl(V_WR_TID(ep
->hwtid
));
1619 OPCODE_TID(rpl
) = htonl(MK_OPCODE_TID(CPL_ABORT_RPL
, ep
->hwtid
));
1620 rpl
->cmd
= CPL_ABORT_NO_RST
;
1621 iwch_cxgb3_ofld_send(ep
->com
.tdev
, rpl_skb
);
1624 release_ep_resources(ep
);
1625 return CPL_RET_BUF_DONE
;
1628 static int close_con_rpl(struct t3cdev
*tdev
, struct sk_buff
*skb
, void *ctx
)
1630 struct iwch_ep
*ep
= ctx
;
1631 struct iwch_qp_attributes attrs
;
1632 unsigned long flags
;
1635 PDBG("%s ep %p\n", __func__
, ep
);
1638 /* The cm_id may be null if we failed to connect */
1639 spin_lock_irqsave(&ep
->com
.lock
, flags
);
1640 switch (ep
->com
.state
) {
1642 __state_set(&ep
->com
, MORIBUND
);
1646 if ((ep
->com
.cm_id
) && (ep
->com
.qp
)) {
1647 attrs
.next_state
= IWCH_QP_STATE_IDLE
;
1648 iwch_modify_qp(ep
->com
.qp
->rhp
,
1650 IWCH_QP_ATTR_NEXT_STATE
,
1653 close_complete_upcall(ep
);
1654 __state_set(&ep
->com
, DEAD
);
1664 spin_unlock_irqrestore(&ep
->com
.lock
, flags
);
1666 release_ep_resources(ep
);
1667 return CPL_RET_BUF_DONE
;
1671 * T3A does 3 things when a TERM is received:
1672 * 1) send up a CPL_RDMA_TERMINATE message with the TERM packet
1673 * 2) generate an async event on the QP with the TERMINATE opcode
1674 * 3) post a TERMINATE opcde cqe into the associated CQ.
1676 * For (1), we save the message in the qp for later consumer consumption.
1677 * For (2), we move the QP into TERMINATE, post a QP event and disconnect.
1678 * For (3), we toss the CQE in cxio_poll_cq().
1680 * terminate() handles case (1)...
1682 static int terminate(struct t3cdev
*tdev
, struct sk_buff
*skb
, void *ctx
)
1684 struct iwch_ep
*ep
= ctx
;
1686 if (state_read(&ep
->com
) != FPDU_MODE
)
1687 return CPL_RET_BUF_DONE
;
1689 PDBG("%s ep %p\n", __func__
, ep
);
1690 skb_pull(skb
, sizeof(struct cpl_rdma_terminate
));
1691 PDBG("%s saving %d bytes of term msg\n", __func__
, skb
->len
);
1692 skb_copy_from_linear_data(skb
, ep
->com
.qp
->attr
.terminate_buffer
,
1694 ep
->com
.qp
->attr
.terminate_msg_len
= skb
->len
;
1695 ep
->com
.qp
->attr
.is_terminate_local
= 0;
1696 return CPL_RET_BUF_DONE
;
1699 static int ec_status(struct t3cdev
*tdev
, struct sk_buff
*skb
, void *ctx
)
1701 struct cpl_rdma_ec_status
*rep
= cplhdr(skb
);
1702 struct iwch_ep
*ep
= ctx
;
1704 PDBG("%s ep %p tid %u status %d\n", __func__
, ep
, ep
->hwtid
,
1707 struct iwch_qp_attributes attrs
;
1709 printk(KERN_ERR MOD
"%s BAD CLOSE - Aborting tid %u\n",
1710 __func__
, ep
->hwtid
);
1712 attrs
.next_state
= IWCH_QP_STATE_ERROR
;
1713 iwch_modify_qp(ep
->com
.qp
->rhp
,
1714 ep
->com
.qp
, IWCH_QP_ATTR_NEXT_STATE
,
1716 abort_connection(ep
, NULL
, GFP_KERNEL
);
1718 return CPL_RET_BUF_DONE
;
1721 static void ep_timeout(unsigned long arg
)
1723 struct iwch_ep
*ep
= (struct iwch_ep
*)arg
;
1724 struct iwch_qp_attributes attrs
;
1725 unsigned long flags
;
1728 spin_lock_irqsave(&ep
->com
.lock
, flags
);
1729 PDBG("%s ep %p tid %u state %d\n", __func__
, ep
, ep
->hwtid
,
1731 switch (ep
->com
.state
) {
1733 __state_set(&ep
->com
, ABORTING
);
1734 connect_reply_upcall(ep
, -ETIMEDOUT
);
1737 __state_set(&ep
->com
, ABORTING
);
1741 if (ep
->com
.cm_id
&& ep
->com
.qp
) {
1742 attrs
.next_state
= IWCH_QP_STATE_ERROR
;
1743 iwch_modify_qp(ep
->com
.qp
->rhp
,
1744 ep
->com
.qp
, IWCH_QP_ATTR_NEXT_STATE
,
1747 __state_set(&ep
->com
, ABORTING
);
1750 printk(KERN_ERR
"%s unexpected state ep %p state %u\n",
1751 __func__
, ep
, ep
->com
.state
);
1755 spin_unlock_irqrestore(&ep
->com
.lock
, flags
);
1757 abort_connection(ep
, NULL
, GFP_ATOMIC
);
1761 int iwch_reject_cr(struct iw_cm_id
*cm_id
, const void *pdata
, u8 pdata_len
)
1764 struct iwch_ep
*ep
= to_ep(cm_id
);
1765 PDBG("%s ep %p tid %u\n", __func__
, ep
, ep
->hwtid
);
1767 if (state_read(&ep
->com
) == DEAD
) {
1771 BUG_ON(state_read(&ep
->com
) != MPA_REQ_RCVD
);
1773 abort_connection(ep
, NULL
, GFP_KERNEL
);
1775 err
= send_mpa_reject(ep
, pdata
, pdata_len
);
1776 err
= iwch_ep_disconnect(ep
, 0, GFP_KERNEL
);
1782 int iwch_accept_cr(struct iw_cm_id
*cm_id
, struct iw_cm_conn_param
*conn_param
)
1785 struct iwch_qp_attributes attrs
;
1786 enum iwch_qp_attr_mask mask
;
1787 struct iwch_ep
*ep
= to_ep(cm_id
);
1788 struct iwch_dev
*h
= to_iwch_dev(cm_id
->device
);
1789 struct iwch_qp
*qp
= get_qhp(h
, conn_param
->qpn
);
1791 PDBG("%s ep %p tid %u\n", __func__
, ep
, ep
->hwtid
);
1792 if (state_read(&ep
->com
) == DEAD
) {
1797 BUG_ON(state_read(&ep
->com
) != MPA_REQ_RCVD
);
1800 if ((conn_param
->ord
> qp
->rhp
->attr
.max_rdma_read_qp_depth
) ||
1801 (conn_param
->ird
> qp
->rhp
->attr
.max_rdma_reads_per_qp
)) {
1802 abort_connection(ep
, NULL
, GFP_KERNEL
);
1807 cm_id
->add_ref(cm_id
);
1808 ep
->com
.cm_id
= cm_id
;
1811 ep
->ird
= conn_param
->ird
;
1812 ep
->ord
= conn_param
->ord
;
1814 if (peer2peer
&& ep
->ird
== 0)
1817 PDBG("%s %d ird %d ord %d\n", __func__
, __LINE__
, ep
->ird
, ep
->ord
);
1819 /* bind QP to EP and move to RTS */
1820 attrs
.mpa_attr
= ep
->mpa_attr
;
1821 attrs
.max_ird
= ep
->ird
;
1822 attrs
.max_ord
= ep
->ord
;
1823 attrs
.llp_stream_handle
= ep
;
1824 attrs
.next_state
= IWCH_QP_STATE_RTS
;
1826 /* bind QP and TID with INIT_WR */
1827 mask
= IWCH_QP_ATTR_NEXT_STATE
|
1828 IWCH_QP_ATTR_LLP_STREAM_HANDLE
|
1829 IWCH_QP_ATTR_MPA_ATTR
|
1830 IWCH_QP_ATTR_MAX_IRD
|
1831 IWCH_QP_ATTR_MAX_ORD
;
1833 err
= iwch_modify_qp(ep
->com
.qp
->rhp
,
1834 ep
->com
.qp
, mask
, &attrs
, 1);
1838 /* if needed, wait for wr_ack */
1839 if (iwch_rqes_posted(qp
)) {
1840 wait_event(ep
->com
.waitq
, ep
->com
.rpl_done
);
1841 err
= ep
->com
.rpl_err
;
1846 err
= send_mpa_reply(ep
, conn_param
->private_data
,
1847 conn_param
->private_data_len
);
1852 state_set(&ep
->com
, FPDU_MODE
);
1853 established_upcall(ep
);
1857 ep
->com
.cm_id
= NULL
;
1859 cm_id
->rem_ref(cm_id
);
1865 static int is_loopback_dst(struct iw_cm_id
*cm_id
)
1867 struct net_device
*dev
;
1869 dev
= ip_dev_find(&init_net
, cm_id
->remote_addr
.sin_addr
.s_addr
);
1876 int iwch_connect(struct iw_cm_id
*cm_id
, struct iw_cm_conn_param
*conn_param
)
1879 struct iwch_dev
*h
= to_iwch_dev(cm_id
->device
);
1883 if (is_loopback_dst(cm_id
)) {
1888 ep
= alloc_ep(sizeof(*ep
), GFP_KERNEL
);
1890 printk(KERN_ERR MOD
"%s - cannot alloc ep.\n", __func__
);
1894 init_timer(&ep
->timer
);
1895 ep
->plen
= conn_param
->private_data_len
;
1897 memcpy(ep
->mpa_pkt
+ sizeof(struct mpa_message
),
1898 conn_param
->private_data
, ep
->plen
);
1899 ep
->ird
= conn_param
->ird
;
1900 ep
->ord
= conn_param
->ord
;
1902 if (peer2peer
&& ep
->ord
== 0)
1905 ep
->com
.tdev
= h
->rdev
.t3cdev_p
;
1907 cm_id
->add_ref(cm_id
);
1908 ep
->com
.cm_id
= cm_id
;
1909 ep
->com
.qp
= get_qhp(h
, conn_param
->qpn
);
1910 BUG_ON(!ep
->com
.qp
);
1911 PDBG("%s qpn 0x%x qp %p cm_id %p\n", __func__
, conn_param
->qpn
,
1915 * Allocate an active TID to initiate a TCP connection.
1917 ep
->atid
= cxgb3_alloc_atid(h
->rdev
.t3cdev_p
, &t3c_client
, ep
);
1918 if (ep
->atid
== -1) {
1919 printk(KERN_ERR MOD
"%s - cannot alloc atid.\n", __func__
);
1925 rt
= find_route(h
->rdev
.t3cdev_p
,
1926 cm_id
->local_addr
.sin_addr
.s_addr
,
1927 cm_id
->remote_addr
.sin_addr
.s_addr
,
1928 cm_id
->local_addr
.sin_port
,
1929 cm_id
->remote_addr
.sin_port
, IPTOS_LOWDELAY
);
1931 printk(KERN_ERR MOD
"%s - cannot find route.\n", __func__
);
1932 err
= -EHOSTUNREACH
;
1937 /* get a l2t entry */
1938 ep
->l2t
= t3_l2t_get(ep
->com
.tdev
, ep
->dst
->neighbour
,
1939 ep
->dst
->neighbour
->dev
);
1941 printk(KERN_ERR MOD
"%s - cannot alloc l2e.\n", __func__
);
1946 state_set(&ep
->com
, CONNECTING
);
1947 ep
->tos
= IPTOS_LOWDELAY
;
1948 ep
->com
.local_addr
= cm_id
->local_addr
;
1949 ep
->com
.remote_addr
= cm_id
->remote_addr
;
1951 /* send connect request to rnic */
1952 err
= send_connect(ep
);
1956 l2t_release(L2DATA(h
->rdev
.t3cdev_p
), ep
->l2t
);
1958 dst_release(ep
->dst
);
1960 cxgb3_free_atid(ep
->com
.tdev
, ep
->atid
);
1962 cm_id
->rem_ref(cm_id
);
1968 int iwch_create_listen(struct iw_cm_id
*cm_id
, int backlog
)
1971 struct iwch_dev
*h
= to_iwch_dev(cm_id
->device
);
1972 struct iwch_listen_ep
*ep
;
1977 ep
= alloc_ep(sizeof(*ep
), GFP_KERNEL
);
1979 printk(KERN_ERR MOD
"%s - cannot alloc ep.\n", __func__
);
1983 PDBG("%s ep %p\n", __func__
, ep
);
1984 ep
->com
.tdev
= h
->rdev
.t3cdev_p
;
1985 cm_id
->add_ref(cm_id
);
1986 ep
->com
.cm_id
= cm_id
;
1987 ep
->backlog
= backlog
;
1988 ep
->com
.local_addr
= cm_id
->local_addr
;
1991 * Allocate a server TID.
1993 ep
->stid
= cxgb3_alloc_stid(h
->rdev
.t3cdev_p
, &t3c_client
, ep
);
1994 if (ep
->stid
== -1) {
1995 printk(KERN_ERR MOD
"%s - cannot alloc atid.\n", __func__
);
2000 state_set(&ep
->com
, LISTEN
);
2001 err
= listen_start(ep
);
2005 /* wait for pass_open_rpl */
2006 wait_event(ep
->com
.waitq
, ep
->com
.rpl_done
);
2007 err
= ep
->com
.rpl_err
;
2009 cm_id
->provider_data
= ep
;
2013 cxgb3_free_stid(ep
->com
.tdev
, ep
->stid
);
2015 cm_id
->rem_ref(cm_id
);
2022 int iwch_destroy_listen(struct iw_cm_id
*cm_id
)
2025 struct iwch_listen_ep
*ep
= to_listen_ep(cm_id
);
2027 PDBG("%s ep %p\n", __func__
, ep
);
2030 state_set(&ep
->com
, DEAD
);
2031 ep
->com
.rpl_done
= 0;
2032 ep
->com
.rpl_err
= 0;
2033 err
= listen_stop(ep
);
2036 wait_event(ep
->com
.waitq
, ep
->com
.rpl_done
);
2037 cxgb3_free_stid(ep
->com
.tdev
, ep
->stid
);
2039 err
= ep
->com
.rpl_err
;
2040 cm_id
->rem_ref(cm_id
);
2045 int iwch_ep_disconnect(struct iwch_ep
*ep
, int abrupt
, gfp_t gfp
)
2048 unsigned long flags
;
2051 struct t3cdev
*tdev
;
2052 struct cxio_rdev
*rdev
;
2054 spin_lock_irqsave(&ep
->com
.lock
, flags
);
2056 PDBG("%s ep %p state %s, abrupt %d\n", __func__
, ep
,
2057 states
[ep
->com
.state
], abrupt
);
2059 tdev
= (struct t3cdev
*)ep
->com
.tdev
;
2060 rdev
= (struct cxio_rdev
*)tdev
->ulp
;
2061 if (cxio_fatal_error(rdev
)) {
2063 close_complete_upcall(ep
);
2064 ep
->com
.state
= DEAD
;
2066 switch (ep
->com
.state
) {
2074 ep
->com
.state
= ABORTING
;
2076 ep
->com
.state
= CLOSING
;
2079 set_bit(CLOSE_SENT
, &ep
->com
.flags
);
2082 if (!test_and_set_bit(CLOSE_SENT
, &ep
->com
.flags
)) {
2086 ep
->com
.state
= ABORTING
;
2088 ep
->com
.state
= MORIBUND
;
2094 PDBG("%s ignoring disconnect ep %p state %u\n",
2095 __func__
, ep
, ep
->com
.state
);
2102 spin_unlock_irqrestore(&ep
->com
.lock
, flags
);
2105 ret
= send_abort(ep
, NULL
, gfp
);
2107 ret
= send_halfclose(ep
, gfp
);
2112 release_ep_resources(ep
);
2116 int iwch_ep_redirect(void *ctx
, struct dst_entry
*old
, struct dst_entry
*new,
2117 struct l2t_entry
*l2t
)
2119 struct iwch_ep
*ep
= ctx
;
2124 PDBG("%s ep %p redirect to dst %p l2t %p\n", __func__
, ep
, new,
2127 l2t_release(L2DATA(ep
->com
.tdev
), ep
->l2t
);
2135 * All the CM events are handled on a work queue to have a safe context.
2136 * These are the real handlers that are called from the work queue.
2138 static const cxgb3_cpl_handler_func work_handlers
[NUM_CPL_CMDS
] = {
2139 [CPL_ACT_ESTABLISH
] = act_establish
,
2140 [CPL_ACT_OPEN_RPL
] = act_open_rpl
,
2141 [CPL_RX_DATA
] = rx_data
,
2142 [CPL_TX_DMA_ACK
] = tx_ack
,
2143 [CPL_ABORT_RPL_RSS
] = abort_rpl
,
2144 [CPL_ABORT_RPL
] = abort_rpl
,
2145 [CPL_PASS_OPEN_RPL
] = pass_open_rpl
,
2146 [CPL_CLOSE_LISTSRV_RPL
] = close_listsrv_rpl
,
2147 [CPL_PASS_ACCEPT_REQ
] = pass_accept_req
,
2148 [CPL_PASS_ESTABLISH
] = pass_establish
,
2149 [CPL_PEER_CLOSE
] = peer_close
,
2150 [CPL_ABORT_REQ_RSS
] = peer_abort
,
2151 [CPL_CLOSE_CON_RPL
] = close_con_rpl
,
2152 [CPL_RDMA_TERMINATE
] = terminate
,
2153 [CPL_RDMA_EC_STATUS
] = ec_status
,
2156 static void process_work(struct work_struct
*work
)
2158 struct sk_buff
*skb
= NULL
;
2160 struct t3cdev
*tdev
;
2163 while ((skb
= skb_dequeue(&rxq
))) {
2164 ep
= *((void **) (skb
->cb
));
2165 tdev
= *((struct t3cdev
**) (skb
->cb
+ sizeof(void *)));
2166 ret
= work_handlers
[G_OPCODE(ntohl((__force __be32
)skb
->csum
))](tdev
, skb
, ep
);
2167 if (ret
& CPL_RET_BUF_DONE
)
2171 * ep was referenced in sched(), and is freed here.
2173 put_ep((struct iwch_ep_common
*)ep
);
2177 static DECLARE_WORK(skb_work
, process_work
);
2179 static int sched(struct t3cdev
*tdev
, struct sk_buff
*skb
, void *ctx
)
2181 struct iwch_ep_common
*epc
= ctx
;
2186 * Save ctx and tdev in the skb->cb area.
2188 *((void **) skb
->cb
) = ctx
;
2189 *((struct t3cdev
**) (skb
->cb
+ sizeof(void *))) = tdev
;
2192 * Queue the skb and schedule the worker thread.
2194 skb_queue_tail(&rxq
, skb
);
2195 queue_work(workq
, &skb_work
);
2199 static int set_tcb_rpl(struct t3cdev
*tdev
, struct sk_buff
*skb
, void *ctx
)
2201 struct cpl_set_tcb_rpl
*rpl
= cplhdr(skb
);
2203 if (rpl
->status
!= CPL_ERR_NONE
) {
2204 printk(KERN_ERR MOD
"Unexpected SET_TCB_RPL status %u "
2205 "for tid %u\n", rpl
->status
, GET_TID(rpl
));
2207 return CPL_RET_BUF_DONE
;
2211 * All upcalls from the T3 Core go to sched() to schedule the
2212 * processing on a work queue.
2214 cxgb3_cpl_handler_func t3c_handlers
[NUM_CPL_CMDS
] = {
2215 [CPL_ACT_ESTABLISH
] = sched
,
2216 [CPL_ACT_OPEN_RPL
] = sched
,
2217 [CPL_RX_DATA
] = sched
,
2218 [CPL_TX_DMA_ACK
] = sched
,
2219 [CPL_ABORT_RPL_RSS
] = sched
,
2220 [CPL_ABORT_RPL
] = sched
,
2221 [CPL_PASS_OPEN_RPL
] = sched
,
2222 [CPL_CLOSE_LISTSRV_RPL
] = sched
,
2223 [CPL_PASS_ACCEPT_REQ
] = sched
,
2224 [CPL_PASS_ESTABLISH
] = sched
,
2225 [CPL_PEER_CLOSE
] = sched
,
2226 [CPL_CLOSE_CON_RPL
] = sched
,
2227 [CPL_ABORT_REQ_RSS
] = sched
,
2228 [CPL_RDMA_TERMINATE
] = sched
,
2229 [CPL_RDMA_EC_STATUS
] = sched
,
2230 [CPL_SET_TCB_RPL
] = set_tcb_rpl
,
2233 int __init
iwch_cm_init(void)
2235 skb_queue_head_init(&rxq
);
2237 workq
= create_singlethread_workqueue("iw_cxgb3");
2244 void __exit
iwch_cm_term(void)
2246 flush_workqueue(workq
);
2247 destroy_workqueue(workq
);