2 * Copyright (c) 2009-2010 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>
50 static char *states
[] = {
67 module_param(nocong
, int, 0644);
68 MODULE_PARM_DESC(nocong
, "Turn of congestion control (default=0)");
70 static int enable_ecn
;
71 module_param(enable_ecn
, int, 0644);
72 MODULE_PARM_DESC(enable_ecn
, "Enable ECN (default=0/disabled)");
74 static int dack_mode
= 1;
75 module_param(dack_mode
, int, 0644);
76 MODULE_PARM_DESC(dack_mode
, "Delayed ack mode (default=1)");
78 int c4iw_max_read_depth
= 8;
79 module_param(c4iw_max_read_depth
, int, 0644);
80 MODULE_PARM_DESC(c4iw_max_read_depth
, "Per-connection max ORD/IRD (default=8)");
82 static int enable_tcp_timestamps
;
83 module_param(enable_tcp_timestamps
, int, 0644);
84 MODULE_PARM_DESC(enable_tcp_timestamps
, "Enable tcp timestamps (default=0)");
86 static int enable_tcp_sack
;
87 module_param(enable_tcp_sack
, int, 0644);
88 MODULE_PARM_DESC(enable_tcp_sack
, "Enable tcp SACK (default=0)");
90 static int enable_tcp_window_scaling
= 1;
91 module_param(enable_tcp_window_scaling
, int, 0644);
92 MODULE_PARM_DESC(enable_tcp_window_scaling
,
93 "Enable tcp window scaling (default=1)");
96 module_param(c4iw_debug
, int, 0644);
97 MODULE_PARM_DESC(c4iw_debug
, "Enable debug logging (default=0)");
100 module_param(peer2peer
, int, 0644);
101 MODULE_PARM_DESC(peer2peer
, "Support peer2peer ULPs (default=0)");
103 static int p2p_type
= FW_RI_INIT_P2PTYPE_READ_REQ
;
104 module_param(p2p_type
, int, 0644);
105 MODULE_PARM_DESC(p2p_type
, "RDMAP opcode to use for the RTR message: "
106 "1=RDMA_READ 0=RDMA_WRITE (default 1)");
108 static int ep_timeout_secs
= 60;
109 module_param(ep_timeout_secs
, int, 0644);
110 MODULE_PARM_DESC(ep_timeout_secs
, "CM Endpoint operation timeout "
111 "in seconds (default=60)");
113 static int mpa_rev
= 1;
114 module_param(mpa_rev
, int, 0644);
115 MODULE_PARM_DESC(mpa_rev
, "MPA Revision, 0 supports amso1100, "
116 "1 is RFC0544 spec compliant, 2 is IETF MPA Peer Connect Draft"
117 " compliant (default=1)");
119 static int markers_enabled
;
120 module_param(markers_enabled
, int, 0644);
121 MODULE_PARM_DESC(markers_enabled
, "Enable MPA MARKERS (default(0)=disabled)");
123 static int crc_enabled
= 1;
124 module_param(crc_enabled
, int, 0644);
125 MODULE_PARM_DESC(crc_enabled
, "Enable MPA CRC (default(1)=enabled)");
127 static int rcv_win
= 256 * 1024;
128 module_param(rcv_win
, int, 0644);
129 MODULE_PARM_DESC(rcv_win
, "TCP receive window in bytes (default=256KB)");
131 static int snd_win
= 128 * 1024;
132 module_param(snd_win
, int, 0644);
133 MODULE_PARM_DESC(snd_win
, "TCP send window in bytes (default=128KB)");
135 static struct workqueue_struct
*workq
;
137 static struct sk_buff_head rxq
;
139 static struct sk_buff
*get_skb(struct sk_buff
*skb
, int len
, gfp_t gfp
);
140 static void ep_timeout(unsigned long arg
);
141 static void connect_reply_upcall(struct c4iw_ep
*ep
, int status
);
143 static LIST_HEAD(timeout_list
);
144 static spinlock_t timeout_lock
;
146 static void start_ep_timer(struct c4iw_ep
*ep
)
148 PDBG("%s ep %p\n", __func__
, ep
);
149 if (timer_pending(&ep
->timer
)) {
150 PDBG("%s stopped / restarted timer ep %p\n", __func__
, ep
);
151 del_timer_sync(&ep
->timer
);
153 c4iw_get_ep(&ep
->com
);
154 ep
->timer
.expires
= jiffies
+ ep_timeout_secs
* HZ
;
155 ep
->timer
.data
= (unsigned long)ep
;
156 ep
->timer
.function
= ep_timeout
;
157 add_timer(&ep
->timer
);
160 static void stop_ep_timer(struct c4iw_ep
*ep
)
162 PDBG("%s ep %p\n", __func__
, ep
);
163 if (!timer_pending(&ep
->timer
)) {
164 WARN(1, "%s timer stopped when its not running! "
165 "ep %p state %u\n", __func__
, ep
, ep
->com
.state
);
168 del_timer_sync(&ep
->timer
);
169 c4iw_put_ep(&ep
->com
);
172 static int c4iw_l2t_send(struct c4iw_rdev
*rdev
, struct sk_buff
*skb
,
173 struct l2t_entry
*l2e
)
177 if (c4iw_fatal_error(rdev
)) {
179 PDBG("%s - device in error state - dropping\n", __func__
);
182 error
= cxgb4_l2t_send(rdev
->lldi
.ports
[0], skb
, l2e
);
185 return error
< 0 ? error
: 0;
188 int c4iw_ofld_send(struct c4iw_rdev
*rdev
, struct sk_buff
*skb
)
192 if (c4iw_fatal_error(rdev
)) {
194 PDBG("%s - device in error state - dropping\n", __func__
);
197 error
= cxgb4_ofld_send(rdev
->lldi
.ports
[0], skb
);
200 return error
< 0 ? error
: 0;
203 static void release_tid(struct c4iw_rdev
*rdev
, u32 hwtid
, struct sk_buff
*skb
)
205 struct cpl_tid_release
*req
;
207 skb
= get_skb(skb
, sizeof *req
, GFP_KERNEL
);
210 req
= (struct cpl_tid_release
*) skb_put(skb
, sizeof(*req
));
211 INIT_TP_WR(req
, hwtid
);
212 OPCODE_TID(req
) = cpu_to_be32(MK_OPCODE_TID(CPL_TID_RELEASE
, hwtid
));
213 set_wr_txq(skb
, CPL_PRIORITY_SETUP
, 0);
214 c4iw_ofld_send(rdev
, skb
);
218 static void set_emss(struct c4iw_ep
*ep
, u16 opt
)
220 ep
->emss
= ep
->com
.dev
->rdev
.lldi
.mtus
[GET_TCPOPT_MSS(opt
)] - 40;
222 if (GET_TCPOPT_TSTAMP(opt
))
226 PDBG("%s mss_idx %u mss %u emss=%u\n", __func__
, GET_TCPOPT_MSS(opt
),
230 static enum c4iw_ep_state
state_read(struct c4iw_ep_common
*epc
)
232 enum c4iw_ep_state state
;
234 mutex_lock(&epc
->mutex
);
236 mutex_unlock(&epc
->mutex
);
240 static void __state_set(struct c4iw_ep_common
*epc
, enum c4iw_ep_state
new)
245 static void state_set(struct c4iw_ep_common
*epc
, enum c4iw_ep_state
new)
247 mutex_lock(&epc
->mutex
);
248 PDBG("%s - %s -> %s\n", __func__
, states
[epc
->state
], states
[new]);
249 __state_set(epc
, new);
250 mutex_unlock(&epc
->mutex
);
254 static void *alloc_ep(int size
, gfp_t gfp
)
256 struct c4iw_ep_common
*epc
;
258 epc
= kzalloc(size
, gfp
);
260 kref_init(&epc
->kref
);
261 mutex_init(&epc
->mutex
);
262 c4iw_init_wr_wait(&epc
->wr_wait
);
264 PDBG("%s alloc ep %p\n", __func__
, epc
);
268 void _c4iw_free_ep(struct kref
*kref
)
272 ep
= container_of(kref
, struct c4iw_ep
, com
.kref
);
273 PDBG("%s ep %p state %s\n", __func__
, ep
, states
[state_read(&ep
->com
)]);
274 if (test_bit(RELEASE_RESOURCES
, &ep
->com
.flags
)) {
275 cxgb4_remove_tid(ep
->com
.dev
->rdev
.lldi
.tids
, 0, ep
->hwtid
);
276 dst_release(ep
->dst
);
277 cxgb4_l2t_release(ep
->l2t
);
278 remove_handle(ep
->com
.dev
, &ep
->com
.dev
->hwtid_idr
, ep
->hwtid
);
283 static void release_ep_resources(struct c4iw_ep
*ep
)
285 set_bit(RELEASE_RESOURCES
, &ep
->com
.flags
);
286 c4iw_put_ep(&ep
->com
);
289 static int status2errno(int status
)
294 case CPL_ERR_CONN_RESET
:
296 case CPL_ERR_ARP_MISS
:
297 return -EHOSTUNREACH
;
298 case CPL_ERR_CONN_TIMEDOUT
:
300 case CPL_ERR_TCAM_FULL
:
302 case CPL_ERR_CONN_EXIST
:
310 * Try and reuse skbs already allocated...
312 static struct sk_buff
*get_skb(struct sk_buff
*skb
, int len
, gfp_t gfp
)
314 if (skb
&& !skb_is_nonlinear(skb
) && !skb_cloned(skb
)) {
317 skb_reset_transport_header(skb
);
319 skb
= alloc_skb(len
, gfp
);
324 static struct rtable
*find_route(struct c4iw_dev
*dev
, __be32 local_ip
,
325 __be32 peer_ip
, __be16 local_port
,
326 __be16 peer_port
, u8 tos
)
331 rt
= ip_route_output_ports(&init_net
, &fl4
, NULL
, peer_ip
, local_ip
,
332 peer_port
, local_port
, IPPROTO_TCP
,
339 static void arp_failure_discard(void *handle
, struct sk_buff
*skb
)
341 PDBG("%s c4iw_dev %p\n", __func__
, handle
);
346 * Handle an ARP failure for an active open.
348 static void act_open_req_arp_failure(void *handle
, struct sk_buff
*skb
)
350 printk(KERN_ERR MOD
"ARP failure duing connect\n");
355 * Handle an ARP failure for a CPL_ABORT_REQ. Change it into a no RST variant
358 static void abort_arp_failure(void *handle
, struct sk_buff
*skb
)
360 struct c4iw_rdev
*rdev
= handle
;
361 struct cpl_abort_req
*req
= cplhdr(skb
);
363 PDBG("%s rdev %p\n", __func__
, rdev
);
364 req
->cmd
= CPL_ABORT_NO_RST
;
365 c4iw_ofld_send(rdev
, skb
);
368 static void send_flowc(struct c4iw_ep
*ep
, struct sk_buff
*skb
)
370 unsigned int flowclen
= 80;
371 struct fw_flowc_wr
*flowc
;
374 skb
= get_skb(skb
, flowclen
, GFP_KERNEL
);
375 flowc
= (struct fw_flowc_wr
*)__skb_put(skb
, flowclen
);
377 flowc
->op_to_nparams
= cpu_to_be32(FW_WR_OP(FW_FLOWC_WR
) |
378 FW_FLOWC_WR_NPARAMS(8));
379 flowc
->flowid_len16
= cpu_to_be32(FW_WR_LEN16(DIV_ROUND_UP(flowclen
,
380 16)) | FW_WR_FLOWID(ep
->hwtid
));
382 flowc
->mnemval
[0].mnemonic
= FW_FLOWC_MNEM_PFNVFN
;
383 flowc
->mnemval
[0].val
= cpu_to_be32(PCI_FUNC(ep
->com
.dev
->rdev
.lldi
.pdev
->devfn
) << 8);
384 flowc
->mnemval
[1].mnemonic
= FW_FLOWC_MNEM_CH
;
385 flowc
->mnemval
[1].val
= cpu_to_be32(ep
->tx_chan
);
386 flowc
->mnemval
[2].mnemonic
= FW_FLOWC_MNEM_PORT
;
387 flowc
->mnemval
[2].val
= cpu_to_be32(ep
->tx_chan
);
388 flowc
->mnemval
[3].mnemonic
= FW_FLOWC_MNEM_IQID
;
389 flowc
->mnemval
[3].val
= cpu_to_be32(ep
->rss_qid
);
390 flowc
->mnemval
[4].mnemonic
= FW_FLOWC_MNEM_SNDNXT
;
391 flowc
->mnemval
[4].val
= cpu_to_be32(ep
->snd_seq
);
392 flowc
->mnemval
[5].mnemonic
= FW_FLOWC_MNEM_RCVNXT
;
393 flowc
->mnemval
[5].val
= cpu_to_be32(ep
->rcv_seq
);
394 flowc
->mnemval
[6].mnemonic
= FW_FLOWC_MNEM_SNDBUF
;
395 flowc
->mnemval
[6].val
= cpu_to_be32(snd_win
);
396 flowc
->mnemval
[7].mnemonic
= FW_FLOWC_MNEM_MSS
;
397 flowc
->mnemval
[7].val
= cpu_to_be32(ep
->emss
);
398 /* Pad WR to 16 byte boundary */
399 flowc
->mnemval
[8].mnemonic
= 0;
400 flowc
->mnemval
[8].val
= 0;
401 for (i
= 0; i
< 9; i
++) {
402 flowc
->mnemval
[i
].r4
[0] = 0;
403 flowc
->mnemval
[i
].r4
[1] = 0;
404 flowc
->mnemval
[i
].r4
[2] = 0;
407 set_wr_txq(skb
, CPL_PRIORITY_DATA
, ep
->txq_idx
);
408 c4iw_ofld_send(&ep
->com
.dev
->rdev
, skb
);
411 static int send_halfclose(struct c4iw_ep
*ep
, gfp_t gfp
)
413 struct cpl_close_con_req
*req
;
415 int wrlen
= roundup(sizeof *req
, 16);
417 PDBG("%s ep %p tid %u\n", __func__
, ep
, ep
->hwtid
);
418 skb
= get_skb(NULL
, wrlen
, gfp
);
420 printk(KERN_ERR MOD
"%s - failed to alloc skb\n", __func__
);
423 set_wr_txq(skb
, CPL_PRIORITY_DATA
, ep
->txq_idx
);
424 t4_set_arp_err_handler(skb
, NULL
, arp_failure_discard
);
425 req
= (struct cpl_close_con_req
*) skb_put(skb
, wrlen
);
426 memset(req
, 0, wrlen
);
427 INIT_TP_WR(req
, ep
->hwtid
);
428 OPCODE_TID(req
) = cpu_to_be32(MK_OPCODE_TID(CPL_CLOSE_CON_REQ
,
430 return c4iw_l2t_send(&ep
->com
.dev
->rdev
, skb
, ep
->l2t
);
433 static int send_abort(struct c4iw_ep
*ep
, struct sk_buff
*skb
, gfp_t gfp
)
435 struct cpl_abort_req
*req
;
436 int wrlen
= roundup(sizeof *req
, 16);
438 PDBG("%s ep %p tid %u\n", __func__
, ep
, ep
->hwtid
);
439 skb
= get_skb(skb
, wrlen
, gfp
);
441 printk(KERN_ERR MOD
"%s - failed to alloc skb.\n",
445 set_wr_txq(skb
, CPL_PRIORITY_DATA
, ep
->txq_idx
);
446 t4_set_arp_err_handler(skb
, &ep
->com
.dev
->rdev
, abort_arp_failure
);
447 req
= (struct cpl_abort_req
*) skb_put(skb
, wrlen
);
448 memset(req
, 0, wrlen
);
449 INIT_TP_WR(req
, ep
->hwtid
);
450 OPCODE_TID(req
) = cpu_to_be32(MK_OPCODE_TID(CPL_ABORT_REQ
, ep
->hwtid
));
451 req
->cmd
= CPL_ABORT_SEND_RST
;
452 return c4iw_l2t_send(&ep
->com
.dev
->rdev
, skb
, ep
->l2t
);
455 #define VLAN_NONE 0xfff
456 #define FILTER_SEL_VLAN_NONE 0xffff
457 #define FILTER_SEL_WIDTH_P_FC (3+1) /* port uses 3 bits, FCoE one bit */
458 #define FILTER_SEL_WIDTH_VIN_P_FC \
459 (6 + 7 + FILTER_SEL_WIDTH_P_FC) /* 6 bits are unused, VF uses 7 bits*/
460 #define FILTER_SEL_WIDTH_TAG_P_FC \
461 (3 + FILTER_SEL_WIDTH_VIN_P_FC) /* PF uses 3 bits */
462 #define FILTER_SEL_WIDTH_VLD_TAG_P_FC (1 + FILTER_SEL_WIDTH_TAG_P_FC)
464 static unsigned int select_ntuple(struct c4iw_dev
*dev
, struct dst_entry
*dst
,
465 struct l2t_entry
*l2t
)
467 unsigned int ntuple
= 0;
470 switch (dev
->rdev
.lldi
.filt_mode
) {
472 /* default filter mode */
473 case HW_TPL_FR_MT_PR_IV_P_FC
:
474 if (l2t
->vlan
== VLAN_NONE
)
475 ntuple
|= FILTER_SEL_VLAN_NONE
<< FILTER_SEL_WIDTH_P_FC
;
477 ntuple
|= l2t
->vlan
<< FILTER_SEL_WIDTH_P_FC
;
478 ntuple
|= 1 << FILTER_SEL_WIDTH_VLD_TAG_P_FC
;
480 ntuple
|= l2t
->lport
<< S_PORT
| IPPROTO_TCP
<<
481 FILTER_SEL_WIDTH_VLD_TAG_P_FC
;
483 case HW_TPL_FR_MT_PR_OV_P_FC
: {
484 viid
= cxgb4_port_viid(l2t
->neigh
->dev
);
486 ntuple
|= FW_VIID_VIN_GET(viid
) << FILTER_SEL_WIDTH_P_FC
;
487 ntuple
|= FW_VIID_PFN_GET(viid
) << FILTER_SEL_WIDTH_VIN_P_FC
;
488 ntuple
|= FW_VIID_VIVLD_GET(viid
) << FILTER_SEL_WIDTH_TAG_P_FC
;
489 ntuple
|= l2t
->lport
<< S_PORT
| IPPROTO_TCP
<<
490 FILTER_SEL_WIDTH_VLD_TAG_P_FC
;
499 static int send_connect(struct c4iw_ep
*ep
)
501 struct cpl_act_open_req
*req
;
505 unsigned int mtu_idx
;
507 int wrlen
= roundup(sizeof *req
, 16);
509 PDBG("%s ep %p atid %u\n", __func__
, ep
, ep
->atid
);
511 skb
= get_skb(NULL
, wrlen
, GFP_KERNEL
);
513 printk(KERN_ERR MOD
"%s - failed to alloc skb.\n",
517 set_wr_txq(skb
, CPL_PRIORITY_SETUP
, ep
->ctrlq_idx
);
519 cxgb4_best_mtu(ep
->com
.dev
->rdev
.lldi
.mtus
, ep
->mtu
, &mtu_idx
);
520 wscale
= compute_wscale(rcv_win
);
521 opt0
= (nocong
? NO_CONG(1) : 0) |
526 L2T_IDX(ep
->l2t
->idx
) |
527 TX_CHAN(ep
->tx_chan
) |
528 SMAC_SEL(ep
->smac_idx
) |
530 ULP_MODE(ULP_MODE_TCPDDP
) |
531 RCV_BUFSIZ(rcv_win
>>10);
532 opt2
= RX_CHANNEL(0) |
533 CCTRL_ECN(enable_ecn
) |
534 RSS_QUEUE_VALID
| RSS_QUEUE(ep
->rss_qid
);
535 if (enable_tcp_timestamps
)
536 opt2
|= TSTAMPS_EN(1);
539 if (wscale
&& enable_tcp_window_scaling
)
540 opt2
|= WND_SCALE_EN(1);
541 t4_set_arp_err_handler(skb
, NULL
, act_open_req_arp_failure
);
543 req
= (struct cpl_act_open_req
*) skb_put(skb
, wrlen
);
545 OPCODE_TID(req
) = cpu_to_be32(
546 MK_OPCODE_TID(CPL_ACT_OPEN_REQ
, ((ep
->rss_qid
<<14)|ep
->atid
)));
547 req
->local_port
= ep
->com
.local_addr
.sin_port
;
548 req
->peer_port
= ep
->com
.remote_addr
.sin_port
;
549 req
->local_ip
= ep
->com
.local_addr
.sin_addr
.s_addr
;
550 req
->peer_ip
= ep
->com
.remote_addr
.sin_addr
.s_addr
;
551 req
->opt0
= cpu_to_be64(opt0
);
552 req
->params
= cpu_to_be32(select_ntuple(ep
->com
.dev
, ep
->dst
, ep
->l2t
));
553 req
->opt2
= cpu_to_be32(opt2
);
554 set_bit(ACT_OPEN_REQ
, &ep
->com
.history
);
555 return c4iw_l2t_send(&ep
->com
.dev
->rdev
, skb
, ep
->l2t
);
558 static void send_mpa_req(struct c4iw_ep
*ep
, struct sk_buff
*skb
,
562 struct fw_ofld_tx_data_wr
*req
;
563 struct mpa_message
*mpa
;
564 struct mpa_v2_conn_params mpa_v2_params
;
566 PDBG("%s ep %p tid %u pd_len %d\n", __func__
, ep
, ep
->hwtid
, ep
->plen
);
568 BUG_ON(skb_cloned(skb
));
570 mpalen
= sizeof(*mpa
) + ep
->plen
;
571 if (mpa_rev_to_use
== 2)
572 mpalen
+= sizeof(struct mpa_v2_conn_params
);
573 wrlen
= roundup(mpalen
+ sizeof *req
, 16);
574 skb
= get_skb(skb
, wrlen
, GFP_KERNEL
);
576 connect_reply_upcall(ep
, -ENOMEM
);
579 set_wr_txq(skb
, CPL_PRIORITY_DATA
, ep
->txq_idx
);
581 req
= (struct fw_ofld_tx_data_wr
*)skb_put(skb
, wrlen
);
582 memset(req
, 0, wrlen
);
583 req
->op_to_immdlen
= cpu_to_be32(
584 FW_WR_OP(FW_OFLD_TX_DATA_WR
) |
586 FW_WR_IMMDLEN(mpalen
));
587 req
->flowid_len16
= cpu_to_be32(
588 FW_WR_FLOWID(ep
->hwtid
) |
589 FW_WR_LEN16(wrlen
>> 4));
590 req
->plen
= cpu_to_be32(mpalen
);
591 req
->tunnel_to_proxy
= cpu_to_be32(
592 FW_OFLD_TX_DATA_WR_FLUSH(1) |
593 FW_OFLD_TX_DATA_WR_SHOVE(1));
595 mpa
= (struct mpa_message
*)(req
+ 1);
596 memcpy(mpa
->key
, MPA_KEY_REQ
, sizeof(mpa
->key
));
597 mpa
->flags
= (crc_enabled
? MPA_CRC
: 0) |
598 (markers_enabled
? MPA_MARKERS
: 0) |
599 (mpa_rev_to_use
== 2 ? MPA_ENHANCED_RDMA_CONN
: 0);
600 mpa
->private_data_size
= htons(ep
->plen
);
601 mpa
->revision
= mpa_rev_to_use
;
602 if (mpa_rev_to_use
== 1) {
603 ep
->tried_with_mpa_v1
= 1;
604 ep
->retry_with_mpa_v1
= 0;
607 if (mpa_rev_to_use
== 2) {
608 mpa
->private_data_size
= htons(ntohs(mpa
->private_data_size
) +
609 sizeof (struct mpa_v2_conn_params
));
610 mpa_v2_params
.ird
= htons((u16
)ep
->ird
);
611 mpa_v2_params
.ord
= htons((u16
)ep
->ord
);
614 mpa_v2_params
.ird
|= htons(MPA_V2_PEER2PEER_MODEL
);
615 if (p2p_type
== FW_RI_INIT_P2PTYPE_RDMA_WRITE
)
617 htons(MPA_V2_RDMA_WRITE_RTR
);
618 else if (p2p_type
== FW_RI_INIT_P2PTYPE_READ_REQ
)
620 htons(MPA_V2_RDMA_READ_RTR
);
622 memcpy(mpa
->private_data
, &mpa_v2_params
,
623 sizeof(struct mpa_v2_conn_params
));
626 memcpy(mpa
->private_data
+
627 sizeof(struct mpa_v2_conn_params
),
628 ep
->mpa_pkt
+ sizeof(*mpa
), ep
->plen
);
631 memcpy(mpa
->private_data
,
632 ep
->mpa_pkt
+ sizeof(*mpa
), ep
->plen
);
635 * Reference the mpa skb. This ensures the data area
636 * will remain in memory until the hw acks the tx.
637 * Function fw4_ack() will deref it.
640 t4_set_arp_err_handler(skb
, NULL
, arp_failure_discard
);
643 c4iw_l2t_send(&ep
->com
.dev
->rdev
, skb
, ep
->l2t
);
645 state_set(&ep
->com
, MPA_REQ_SENT
);
646 ep
->mpa_attr
.initiator
= 1;
650 static int send_mpa_reject(struct c4iw_ep
*ep
, const void *pdata
, u8 plen
)
653 struct fw_ofld_tx_data_wr
*req
;
654 struct mpa_message
*mpa
;
656 struct mpa_v2_conn_params mpa_v2_params
;
658 PDBG("%s ep %p tid %u pd_len %d\n", __func__
, ep
, ep
->hwtid
, ep
->plen
);
660 mpalen
= sizeof(*mpa
) + plen
;
661 if (ep
->mpa_attr
.version
== 2 && ep
->mpa_attr
.enhanced_rdma_conn
)
662 mpalen
+= sizeof(struct mpa_v2_conn_params
);
663 wrlen
= roundup(mpalen
+ sizeof *req
, 16);
665 skb
= get_skb(NULL
, wrlen
, GFP_KERNEL
);
667 printk(KERN_ERR MOD
"%s - cannot alloc skb!\n", __func__
);
670 set_wr_txq(skb
, CPL_PRIORITY_DATA
, ep
->txq_idx
);
672 req
= (struct fw_ofld_tx_data_wr
*)skb_put(skb
, wrlen
);
673 memset(req
, 0, wrlen
);
674 req
->op_to_immdlen
= cpu_to_be32(
675 FW_WR_OP(FW_OFLD_TX_DATA_WR
) |
677 FW_WR_IMMDLEN(mpalen
));
678 req
->flowid_len16
= cpu_to_be32(
679 FW_WR_FLOWID(ep
->hwtid
) |
680 FW_WR_LEN16(wrlen
>> 4));
681 req
->plen
= cpu_to_be32(mpalen
);
682 req
->tunnel_to_proxy
= cpu_to_be32(
683 FW_OFLD_TX_DATA_WR_FLUSH(1) |
684 FW_OFLD_TX_DATA_WR_SHOVE(1));
686 mpa
= (struct mpa_message
*)(req
+ 1);
687 memset(mpa
, 0, sizeof(*mpa
));
688 memcpy(mpa
->key
, MPA_KEY_REP
, sizeof(mpa
->key
));
689 mpa
->flags
= MPA_REJECT
;
690 mpa
->revision
= mpa_rev
;
691 mpa
->private_data_size
= htons(plen
);
693 if (ep
->mpa_attr
.version
== 2 && ep
->mpa_attr
.enhanced_rdma_conn
) {
694 mpa
->flags
|= MPA_ENHANCED_RDMA_CONN
;
695 mpa
->private_data_size
= htons(ntohs(mpa
->private_data_size
) +
696 sizeof (struct mpa_v2_conn_params
));
697 mpa_v2_params
.ird
= htons(((u16
)ep
->ird
) |
698 (peer2peer
? MPA_V2_PEER2PEER_MODEL
:
700 mpa_v2_params
.ord
= htons(((u16
)ep
->ord
) | (peer2peer
?
702 FW_RI_INIT_P2PTYPE_RDMA_WRITE
?
703 MPA_V2_RDMA_WRITE_RTR
: p2p_type
==
704 FW_RI_INIT_P2PTYPE_READ_REQ
?
705 MPA_V2_RDMA_READ_RTR
: 0) : 0));
706 memcpy(mpa
->private_data
, &mpa_v2_params
,
707 sizeof(struct mpa_v2_conn_params
));
710 memcpy(mpa
->private_data
+
711 sizeof(struct mpa_v2_conn_params
), pdata
, plen
);
714 memcpy(mpa
->private_data
, pdata
, plen
);
717 * Reference the mpa skb again. This ensures the data area
718 * will remain in memory until the hw acks the tx.
719 * Function fw4_ack() will deref it.
722 set_wr_txq(skb
, CPL_PRIORITY_DATA
, ep
->txq_idx
);
723 t4_set_arp_err_handler(skb
, NULL
, arp_failure_discard
);
726 return c4iw_l2t_send(&ep
->com
.dev
->rdev
, skb
, ep
->l2t
);
729 static int send_mpa_reply(struct c4iw_ep
*ep
, const void *pdata
, u8 plen
)
732 struct fw_ofld_tx_data_wr
*req
;
733 struct mpa_message
*mpa
;
735 struct mpa_v2_conn_params mpa_v2_params
;
737 PDBG("%s ep %p tid %u pd_len %d\n", __func__
, ep
, ep
->hwtid
, ep
->plen
);
739 mpalen
= sizeof(*mpa
) + plen
;
740 if (ep
->mpa_attr
.version
== 2 && ep
->mpa_attr
.enhanced_rdma_conn
)
741 mpalen
+= sizeof(struct mpa_v2_conn_params
);
742 wrlen
= roundup(mpalen
+ sizeof *req
, 16);
744 skb
= get_skb(NULL
, wrlen
, GFP_KERNEL
);
746 printk(KERN_ERR MOD
"%s - cannot alloc skb!\n", __func__
);
749 set_wr_txq(skb
, CPL_PRIORITY_DATA
, ep
->txq_idx
);
751 req
= (struct fw_ofld_tx_data_wr
*) skb_put(skb
, wrlen
);
752 memset(req
, 0, wrlen
);
753 req
->op_to_immdlen
= cpu_to_be32(
754 FW_WR_OP(FW_OFLD_TX_DATA_WR
) |
756 FW_WR_IMMDLEN(mpalen
));
757 req
->flowid_len16
= cpu_to_be32(
758 FW_WR_FLOWID(ep
->hwtid
) |
759 FW_WR_LEN16(wrlen
>> 4));
760 req
->plen
= cpu_to_be32(mpalen
);
761 req
->tunnel_to_proxy
= cpu_to_be32(
762 FW_OFLD_TX_DATA_WR_FLUSH(1) |
763 FW_OFLD_TX_DATA_WR_SHOVE(1));
765 mpa
= (struct mpa_message
*)(req
+ 1);
766 memset(mpa
, 0, sizeof(*mpa
));
767 memcpy(mpa
->key
, MPA_KEY_REP
, sizeof(mpa
->key
));
768 mpa
->flags
= (ep
->mpa_attr
.crc_enabled
? MPA_CRC
: 0) |
769 (markers_enabled
? MPA_MARKERS
: 0);
770 mpa
->revision
= ep
->mpa_attr
.version
;
771 mpa
->private_data_size
= htons(plen
);
773 if (ep
->mpa_attr
.version
== 2 && ep
->mpa_attr
.enhanced_rdma_conn
) {
774 mpa
->flags
|= MPA_ENHANCED_RDMA_CONN
;
775 mpa
->private_data_size
= htons(ntohs(mpa
->private_data_size
) +
776 sizeof (struct mpa_v2_conn_params
));
777 mpa_v2_params
.ird
= htons((u16
)ep
->ird
);
778 mpa_v2_params
.ord
= htons((u16
)ep
->ord
);
779 if (peer2peer
&& (ep
->mpa_attr
.p2p_type
!=
780 FW_RI_INIT_P2PTYPE_DISABLED
)) {
781 mpa_v2_params
.ird
|= htons(MPA_V2_PEER2PEER_MODEL
);
783 if (p2p_type
== FW_RI_INIT_P2PTYPE_RDMA_WRITE
)
785 htons(MPA_V2_RDMA_WRITE_RTR
);
786 else if (p2p_type
== FW_RI_INIT_P2PTYPE_READ_REQ
)
788 htons(MPA_V2_RDMA_READ_RTR
);
791 memcpy(mpa
->private_data
, &mpa_v2_params
,
792 sizeof(struct mpa_v2_conn_params
));
795 memcpy(mpa
->private_data
+
796 sizeof(struct mpa_v2_conn_params
), pdata
, plen
);
799 memcpy(mpa
->private_data
, pdata
, plen
);
802 * Reference the mpa skb. This ensures the data area
803 * will remain in memory until the hw acks the tx.
804 * Function fw4_ack() will deref it.
807 t4_set_arp_err_handler(skb
, NULL
, arp_failure_discard
);
809 state_set(&ep
->com
, MPA_REP_SENT
);
810 return c4iw_l2t_send(&ep
->com
.dev
->rdev
, skb
, ep
->l2t
);
813 static int act_establish(struct c4iw_dev
*dev
, struct sk_buff
*skb
)
816 struct cpl_act_establish
*req
= cplhdr(skb
);
817 unsigned int tid
= GET_TID(req
);
818 unsigned int atid
= GET_TID_TID(ntohl(req
->tos_atid
));
819 struct tid_info
*t
= dev
->rdev
.lldi
.tids
;
821 ep
= lookup_atid(t
, atid
);
823 PDBG("%s ep %p tid %u snd_isn %u rcv_isn %u\n", __func__
, ep
, tid
,
824 be32_to_cpu(req
->snd_isn
), be32_to_cpu(req
->rcv_isn
));
826 dst_confirm(ep
->dst
);
828 /* setup the hwtid for this connection */
830 cxgb4_insert_tid(t
, ep
, tid
);
831 insert_handle(dev
, &dev
->hwtid_idr
, ep
, ep
->hwtid
);
833 ep
->snd_seq
= be32_to_cpu(req
->snd_isn
);
834 ep
->rcv_seq
= be32_to_cpu(req
->rcv_isn
);
836 set_emss(ep
, ntohs(req
->tcp_opt
));
838 /* dealloc the atid */
839 remove_handle(ep
->com
.dev
, &ep
->com
.dev
->atid_idr
, atid
);
840 cxgb4_free_atid(t
, atid
);
841 set_bit(ACT_ESTAB
, &ep
->com
.history
);
843 /* start MPA negotiation */
844 send_flowc(ep
, NULL
);
845 if (ep
->retry_with_mpa_v1
)
846 send_mpa_req(ep
, skb
, 1);
848 send_mpa_req(ep
, skb
, mpa_rev
);
853 static void close_complete_upcall(struct c4iw_ep
*ep
)
855 struct iw_cm_event event
;
857 PDBG("%s ep %p tid %u\n", __func__
, ep
, ep
->hwtid
);
858 memset(&event
, 0, sizeof(event
));
859 event
.event
= IW_CM_EVENT_CLOSE
;
861 PDBG("close complete delivered ep %p cm_id %p tid %u\n",
862 ep
, ep
->com
.cm_id
, ep
->hwtid
);
863 ep
->com
.cm_id
->event_handler(ep
->com
.cm_id
, &event
);
864 ep
->com
.cm_id
->rem_ref(ep
->com
.cm_id
);
865 ep
->com
.cm_id
= NULL
;
867 set_bit(CLOSE_UPCALL
, &ep
->com
.history
);
871 static int abort_connection(struct c4iw_ep
*ep
, struct sk_buff
*skb
, gfp_t gfp
)
873 PDBG("%s ep %p tid %u\n", __func__
, ep
, ep
->hwtid
);
874 close_complete_upcall(ep
);
875 state_set(&ep
->com
, ABORTING
);
876 set_bit(ABORT_CONN
, &ep
->com
.history
);
877 return send_abort(ep
, skb
, gfp
);
880 static void peer_close_upcall(struct c4iw_ep
*ep
)
882 struct iw_cm_event event
;
884 PDBG("%s ep %p tid %u\n", __func__
, ep
, ep
->hwtid
);
885 memset(&event
, 0, sizeof(event
));
886 event
.event
= IW_CM_EVENT_DISCONNECT
;
888 PDBG("peer close delivered ep %p cm_id %p tid %u\n",
889 ep
, ep
->com
.cm_id
, ep
->hwtid
);
890 ep
->com
.cm_id
->event_handler(ep
->com
.cm_id
, &event
);
891 set_bit(DISCONN_UPCALL
, &ep
->com
.history
);
895 static void peer_abort_upcall(struct c4iw_ep
*ep
)
897 struct iw_cm_event event
;
899 PDBG("%s ep %p tid %u\n", __func__
, ep
, ep
->hwtid
);
900 memset(&event
, 0, sizeof(event
));
901 event
.event
= IW_CM_EVENT_CLOSE
;
902 event
.status
= -ECONNRESET
;
904 PDBG("abort delivered ep %p cm_id %p tid %u\n", ep
,
905 ep
->com
.cm_id
, ep
->hwtid
);
906 ep
->com
.cm_id
->event_handler(ep
->com
.cm_id
, &event
);
907 ep
->com
.cm_id
->rem_ref(ep
->com
.cm_id
);
908 ep
->com
.cm_id
= NULL
;
910 set_bit(ABORT_UPCALL
, &ep
->com
.history
);
914 static void connect_reply_upcall(struct c4iw_ep
*ep
, int status
)
916 struct iw_cm_event event
;
918 PDBG("%s ep %p tid %u status %d\n", __func__
, ep
, ep
->hwtid
, status
);
919 memset(&event
, 0, sizeof(event
));
920 event
.event
= IW_CM_EVENT_CONNECT_REPLY
;
921 event
.status
= status
;
922 event
.local_addr
= ep
->com
.local_addr
;
923 event
.remote_addr
= ep
->com
.remote_addr
;
925 if ((status
== 0) || (status
== -ECONNREFUSED
)) {
926 if (!ep
->tried_with_mpa_v1
) {
927 /* this means MPA_v2 is used */
928 event
.private_data_len
= ep
->plen
-
929 sizeof(struct mpa_v2_conn_params
);
930 event
.private_data
= ep
->mpa_pkt
+
931 sizeof(struct mpa_message
) +
932 sizeof(struct mpa_v2_conn_params
);
934 /* this means MPA_v1 is used */
935 event
.private_data_len
= ep
->plen
;
936 event
.private_data
= ep
->mpa_pkt
+
937 sizeof(struct mpa_message
);
941 PDBG("%s ep %p tid %u status %d\n", __func__
, ep
,
943 set_bit(CONN_RPL_UPCALL
, &ep
->com
.history
);
944 ep
->com
.cm_id
->event_handler(ep
->com
.cm_id
, &event
);
947 ep
->com
.cm_id
->rem_ref(ep
->com
.cm_id
);
948 ep
->com
.cm_id
= NULL
;
953 static void connect_request_upcall(struct c4iw_ep
*ep
)
955 struct iw_cm_event event
;
957 PDBG("%s ep %p tid %u\n", __func__
, ep
, ep
->hwtid
);
958 memset(&event
, 0, sizeof(event
));
959 event
.event
= IW_CM_EVENT_CONNECT_REQUEST
;
960 event
.local_addr
= ep
->com
.local_addr
;
961 event
.remote_addr
= ep
->com
.remote_addr
;
962 event
.provider_data
= ep
;
963 if (!ep
->tried_with_mpa_v1
) {
964 /* this means MPA_v2 is used */
967 event
.private_data_len
= ep
->plen
-
968 sizeof(struct mpa_v2_conn_params
);
969 event
.private_data
= ep
->mpa_pkt
+ sizeof(struct mpa_message
) +
970 sizeof(struct mpa_v2_conn_params
);
972 /* this means MPA_v1 is used. Send max supported */
973 event
.ord
= c4iw_max_read_depth
;
974 event
.ird
= c4iw_max_read_depth
;
975 event
.private_data_len
= ep
->plen
;
976 event
.private_data
= ep
->mpa_pkt
+ sizeof(struct mpa_message
);
978 if (state_read(&ep
->parent_ep
->com
) != DEAD
) {
979 c4iw_get_ep(&ep
->com
);
980 ep
->parent_ep
->com
.cm_id
->event_handler(
981 ep
->parent_ep
->com
.cm_id
,
984 set_bit(CONNREQ_UPCALL
, &ep
->com
.history
);
985 c4iw_put_ep(&ep
->parent_ep
->com
);
986 ep
->parent_ep
= NULL
;
989 static void established_upcall(struct c4iw_ep
*ep
)
991 struct iw_cm_event event
;
993 PDBG("%s ep %p tid %u\n", __func__
, ep
, ep
->hwtid
);
994 memset(&event
, 0, sizeof(event
));
995 event
.event
= IW_CM_EVENT_ESTABLISHED
;
999 PDBG("%s ep %p tid %u\n", __func__
, ep
, ep
->hwtid
);
1000 ep
->com
.cm_id
->event_handler(ep
->com
.cm_id
, &event
);
1001 set_bit(ESTAB_UPCALL
, &ep
->com
.history
);
1005 static int update_rx_credits(struct c4iw_ep
*ep
, u32 credits
)
1007 struct cpl_rx_data_ack
*req
;
1008 struct sk_buff
*skb
;
1009 int wrlen
= roundup(sizeof *req
, 16);
1011 PDBG("%s ep %p tid %u credits %u\n", __func__
, ep
, ep
->hwtid
, credits
);
1012 skb
= get_skb(NULL
, wrlen
, GFP_KERNEL
);
1014 printk(KERN_ERR MOD
"update_rx_credits - cannot alloc skb!\n");
1018 req
= (struct cpl_rx_data_ack
*) skb_put(skb
, wrlen
);
1019 memset(req
, 0, wrlen
);
1020 INIT_TP_WR(req
, ep
->hwtid
);
1021 OPCODE_TID(req
) = cpu_to_be32(MK_OPCODE_TID(CPL_RX_DATA_ACK
,
1023 req
->credit_dack
= cpu_to_be32(credits
| RX_FORCE_ACK(1) |
1025 V_RX_DACK_MODE(dack_mode
));
1026 set_wr_txq(skb
, CPL_PRIORITY_ACK
, ep
->ctrlq_idx
);
1027 c4iw_ofld_send(&ep
->com
.dev
->rdev
, skb
);
1031 static void process_mpa_reply(struct c4iw_ep
*ep
, struct sk_buff
*skb
)
1033 struct mpa_message
*mpa
;
1034 struct mpa_v2_conn_params
*mpa_v2_params
;
1036 u16 resp_ird
, resp_ord
;
1037 u8 rtr_mismatch
= 0, insuff_ird
= 0;
1038 struct c4iw_qp_attributes attrs
;
1039 enum c4iw_qp_attr_mask mask
;
1042 PDBG("%s ep %p tid %u\n", __func__
, ep
, ep
->hwtid
);
1045 * Stop mpa timer. If it expired, then the state has
1046 * changed and we bail since ep_timeout already aborted
1050 if (state_read(&ep
->com
) != MPA_REQ_SENT
)
1054 * If we get more than the supported amount of private data
1055 * then we must fail this connection.
1057 if (ep
->mpa_pkt_len
+ skb
->len
> sizeof(ep
->mpa_pkt
)) {
1063 * copy the new data into our accumulation buffer.
1065 skb_copy_from_linear_data(skb
, &(ep
->mpa_pkt
[ep
->mpa_pkt_len
]),
1067 ep
->mpa_pkt_len
+= skb
->len
;
1070 * if we don't even have the mpa message, then bail.
1072 if (ep
->mpa_pkt_len
< sizeof(*mpa
))
1074 mpa
= (struct mpa_message
*) ep
->mpa_pkt
;
1076 /* Validate MPA header. */
1077 if (mpa
->revision
> mpa_rev
) {
1078 printk(KERN_ERR MOD
"%s MPA version mismatch. Local = %d,"
1079 " Received = %d\n", __func__
, mpa_rev
, mpa
->revision
);
1083 if (memcmp(mpa
->key
, MPA_KEY_REP
, sizeof(mpa
->key
))) {
1088 plen
= ntohs(mpa
->private_data_size
);
1091 * Fail if there's too much private data.
1093 if (plen
> MPA_MAX_PRIVATE_DATA
) {
1099 * If plen does not account for pkt size
1101 if (ep
->mpa_pkt_len
> (sizeof(*mpa
) + plen
)) {
1106 ep
->plen
= (u8
) plen
;
1109 * If we don't have all the pdata yet, then bail.
1110 * We'll continue process when more data arrives.
1112 if (ep
->mpa_pkt_len
< (sizeof(*mpa
) + plen
))
1115 if (mpa
->flags
& MPA_REJECT
) {
1116 err
= -ECONNREFUSED
;
1121 * If we get here we have accumulated the entire mpa
1122 * start reply message including private data. And
1123 * the MPA header is valid.
1125 state_set(&ep
->com
, FPDU_MODE
);
1126 ep
->mpa_attr
.crc_enabled
= (mpa
->flags
& MPA_CRC
) | crc_enabled
? 1 : 0;
1127 ep
->mpa_attr
.recv_marker_enabled
= markers_enabled
;
1128 ep
->mpa_attr
.xmit_marker_enabled
= mpa
->flags
& MPA_MARKERS
? 1 : 0;
1129 ep
->mpa_attr
.version
= mpa
->revision
;
1130 ep
->mpa_attr
.p2p_type
= FW_RI_INIT_P2PTYPE_DISABLED
;
1132 if (mpa
->revision
== 2) {
1133 ep
->mpa_attr
.enhanced_rdma_conn
=
1134 mpa
->flags
& MPA_ENHANCED_RDMA_CONN
? 1 : 0;
1135 if (ep
->mpa_attr
.enhanced_rdma_conn
) {
1136 mpa_v2_params
= (struct mpa_v2_conn_params
*)
1137 (ep
->mpa_pkt
+ sizeof(*mpa
));
1138 resp_ird
= ntohs(mpa_v2_params
->ird
) &
1139 MPA_V2_IRD_ORD_MASK
;
1140 resp_ord
= ntohs(mpa_v2_params
->ord
) &
1141 MPA_V2_IRD_ORD_MASK
;
1144 * This is a double-check. Ideally, below checks are
1145 * not required since ird/ord stuff has been taken
1146 * care of in c4iw_accept_cr
1148 if ((ep
->ird
< resp_ord
) || (ep
->ord
> resp_ird
)) {
1155 if (ntohs(mpa_v2_params
->ird
) &
1156 MPA_V2_PEER2PEER_MODEL
) {
1157 if (ntohs(mpa_v2_params
->ord
) &
1158 MPA_V2_RDMA_WRITE_RTR
)
1159 ep
->mpa_attr
.p2p_type
=
1160 FW_RI_INIT_P2PTYPE_RDMA_WRITE
;
1161 else if (ntohs(mpa_v2_params
->ord
) &
1162 MPA_V2_RDMA_READ_RTR
)
1163 ep
->mpa_attr
.p2p_type
=
1164 FW_RI_INIT_P2PTYPE_READ_REQ
;
1167 } else if (mpa
->revision
== 1)
1169 ep
->mpa_attr
.p2p_type
= p2p_type
;
1171 PDBG("%s - crc_enabled=%d, recv_marker_enabled=%d, "
1172 "xmit_marker_enabled=%d, version=%d p2p_type=%d local-p2p_type = "
1173 "%d\n", __func__
, ep
->mpa_attr
.crc_enabled
,
1174 ep
->mpa_attr
.recv_marker_enabled
,
1175 ep
->mpa_attr
.xmit_marker_enabled
, ep
->mpa_attr
.version
,
1176 ep
->mpa_attr
.p2p_type
, p2p_type
);
1179 * If responder's RTR does not match with that of initiator, assign
1180 * FW_RI_INIT_P2PTYPE_DISABLED in mpa attributes so that RTR is not
1181 * generated when moving QP to RTS state.
1182 * A TERM message will be sent after QP has moved to RTS state
1184 if ((ep
->mpa_attr
.version
== 2) && peer2peer
&&
1185 (ep
->mpa_attr
.p2p_type
!= p2p_type
)) {
1186 ep
->mpa_attr
.p2p_type
= FW_RI_INIT_P2PTYPE_DISABLED
;
1190 attrs
.mpa_attr
= ep
->mpa_attr
;
1191 attrs
.max_ird
= ep
->ird
;
1192 attrs
.max_ord
= ep
->ord
;
1193 attrs
.llp_stream_handle
= ep
;
1194 attrs
.next_state
= C4IW_QP_STATE_RTS
;
1196 mask
= C4IW_QP_ATTR_NEXT_STATE
|
1197 C4IW_QP_ATTR_LLP_STREAM_HANDLE
| C4IW_QP_ATTR_MPA_ATTR
|
1198 C4IW_QP_ATTR_MAX_IRD
| C4IW_QP_ATTR_MAX_ORD
;
1200 /* bind QP and TID with INIT_WR */
1201 err
= c4iw_modify_qp(ep
->com
.qp
->rhp
,
1202 ep
->com
.qp
, mask
, &attrs
, 1);
1207 * If responder's RTR requirement did not match with what initiator
1208 * supports, generate TERM message
1211 printk(KERN_ERR
"%s: RTR mismatch, sending TERM\n", __func__
);
1212 attrs
.layer_etype
= LAYER_MPA
| DDP_LLP
;
1213 attrs
.ecode
= MPA_NOMATCH_RTR
;
1214 attrs
.next_state
= C4IW_QP_STATE_TERMINATE
;
1215 err
= c4iw_modify_qp(ep
->com
.qp
->rhp
, ep
->com
.qp
,
1216 C4IW_QP_ATTR_NEXT_STATE
, &attrs
, 0);
1222 * Generate TERM if initiator IRD is not sufficient for responder
1223 * provided ORD. Currently, we do the same behaviour even when
1224 * responder provided IRD is also not sufficient as regards to
1228 printk(KERN_ERR
"%s: Insufficient IRD, sending TERM\n",
1230 attrs
.layer_etype
= LAYER_MPA
| DDP_LLP
;
1231 attrs
.ecode
= MPA_INSUFF_IRD
;
1232 attrs
.next_state
= C4IW_QP_STATE_TERMINATE
;
1233 err
= c4iw_modify_qp(ep
->com
.qp
->rhp
, ep
->com
.qp
,
1234 C4IW_QP_ATTR_NEXT_STATE
, &attrs
, 0);
1240 state_set(&ep
->com
, ABORTING
);
1241 send_abort(ep
, skb
, GFP_KERNEL
);
1243 connect_reply_upcall(ep
, err
);
1247 static void process_mpa_request(struct c4iw_ep
*ep
, struct sk_buff
*skb
)
1249 struct mpa_message
*mpa
;
1250 struct mpa_v2_conn_params
*mpa_v2_params
;
1253 PDBG("%s ep %p tid %u\n", __func__
, ep
, ep
->hwtid
);
1255 if (state_read(&ep
->com
) != MPA_REQ_WAIT
)
1259 * If we get more than the supported amount of private data
1260 * then we must fail this connection.
1262 if (ep
->mpa_pkt_len
+ skb
->len
> sizeof(ep
->mpa_pkt
)) {
1264 abort_connection(ep
, skb
, GFP_KERNEL
);
1268 PDBG("%s enter (%s line %u)\n", __func__
, __FILE__
, __LINE__
);
1271 * Copy the new data into our accumulation buffer.
1273 skb_copy_from_linear_data(skb
, &(ep
->mpa_pkt
[ep
->mpa_pkt_len
]),
1275 ep
->mpa_pkt_len
+= skb
->len
;
1278 * If we don't even have the mpa message, then bail.
1279 * We'll continue process when more data arrives.
1281 if (ep
->mpa_pkt_len
< sizeof(*mpa
))
1284 PDBG("%s enter (%s line %u)\n", __func__
, __FILE__
, __LINE__
);
1286 mpa
= (struct mpa_message
*) ep
->mpa_pkt
;
1289 * Validate MPA Header.
1291 if (mpa
->revision
> mpa_rev
) {
1292 printk(KERN_ERR MOD
"%s MPA version mismatch. Local = %d,"
1293 " Received = %d\n", __func__
, mpa_rev
, mpa
->revision
);
1294 abort_connection(ep
, skb
, GFP_KERNEL
);
1298 if (memcmp(mpa
->key
, MPA_KEY_REQ
, sizeof(mpa
->key
))) {
1299 abort_connection(ep
, skb
, GFP_KERNEL
);
1303 plen
= ntohs(mpa
->private_data_size
);
1306 * Fail if there's too much private data.
1308 if (plen
> MPA_MAX_PRIVATE_DATA
) {
1309 abort_connection(ep
, skb
, GFP_KERNEL
);
1314 * If plen does not account for pkt size
1316 if (ep
->mpa_pkt_len
> (sizeof(*mpa
) + plen
)) {
1317 abort_connection(ep
, skb
, GFP_KERNEL
);
1320 ep
->plen
= (u8
) plen
;
1323 * If we don't have all the pdata yet, then bail.
1325 if (ep
->mpa_pkt_len
< (sizeof(*mpa
) + plen
))
1329 * If we get here we have accumulated the entire mpa
1330 * start reply message including private data.
1332 ep
->mpa_attr
.initiator
= 0;
1333 ep
->mpa_attr
.crc_enabled
= (mpa
->flags
& MPA_CRC
) | crc_enabled
? 1 : 0;
1334 ep
->mpa_attr
.recv_marker_enabled
= markers_enabled
;
1335 ep
->mpa_attr
.xmit_marker_enabled
= mpa
->flags
& MPA_MARKERS
? 1 : 0;
1336 ep
->mpa_attr
.version
= mpa
->revision
;
1337 if (mpa
->revision
== 1)
1338 ep
->tried_with_mpa_v1
= 1;
1339 ep
->mpa_attr
.p2p_type
= FW_RI_INIT_P2PTYPE_DISABLED
;
1341 if (mpa
->revision
== 2) {
1342 ep
->mpa_attr
.enhanced_rdma_conn
=
1343 mpa
->flags
& MPA_ENHANCED_RDMA_CONN
? 1 : 0;
1344 if (ep
->mpa_attr
.enhanced_rdma_conn
) {
1345 mpa_v2_params
= (struct mpa_v2_conn_params
*)
1346 (ep
->mpa_pkt
+ sizeof(*mpa
));
1347 ep
->ird
= ntohs(mpa_v2_params
->ird
) &
1348 MPA_V2_IRD_ORD_MASK
;
1349 ep
->ord
= ntohs(mpa_v2_params
->ord
) &
1350 MPA_V2_IRD_ORD_MASK
;
1351 if (ntohs(mpa_v2_params
->ird
) & MPA_V2_PEER2PEER_MODEL
)
1353 if (ntohs(mpa_v2_params
->ord
) &
1354 MPA_V2_RDMA_WRITE_RTR
)
1355 ep
->mpa_attr
.p2p_type
=
1356 FW_RI_INIT_P2PTYPE_RDMA_WRITE
;
1357 else if (ntohs(mpa_v2_params
->ord
) &
1358 MPA_V2_RDMA_READ_RTR
)
1359 ep
->mpa_attr
.p2p_type
=
1360 FW_RI_INIT_P2PTYPE_READ_REQ
;
1363 } else if (mpa
->revision
== 1)
1365 ep
->mpa_attr
.p2p_type
= p2p_type
;
1367 PDBG("%s - crc_enabled=%d, recv_marker_enabled=%d, "
1368 "xmit_marker_enabled=%d, version=%d p2p_type=%d\n", __func__
,
1369 ep
->mpa_attr
.crc_enabled
, ep
->mpa_attr
.recv_marker_enabled
,
1370 ep
->mpa_attr
.xmit_marker_enabled
, ep
->mpa_attr
.version
,
1371 ep
->mpa_attr
.p2p_type
);
1373 state_set(&ep
->com
, MPA_REQ_RCVD
);
1376 connect_request_upcall(ep
);
1380 static int rx_data(struct c4iw_dev
*dev
, struct sk_buff
*skb
)
1383 struct cpl_rx_data
*hdr
= cplhdr(skb
);
1384 unsigned int dlen
= ntohs(hdr
->len
);
1385 unsigned int tid
= GET_TID(hdr
);
1386 struct tid_info
*t
= dev
->rdev
.lldi
.tids
;
1387 __u8 status
= hdr
->status
;
1389 ep
= lookup_tid(t
, tid
);
1390 PDBG("%s ep %p tid %u dlen %u\n", __func__
, ep
, ep
->hwtid
, dlen
);
1391 skb_pull(skb
, sizeof(*hdr
));
1392 skb_trim(skb
, dlen
);
1394 ep
->rcv_seq
+= dlen
;
1395 BUG_ON(ep
->rcv_seq
!= (ntohl(hdr
->seq
) + dlen
));
1397 /* update RX credits */
1398 update_rx_credits(ep
, dlen
);
1400 switch (state_read(&ep
->com
)) {
1402 process_mpa_reply(ep
, skb
);
1405 process_mpa_request(ep
, skb
);
1410 pr_err("%s Unexpected streaming data." \
1411 " ep %p state %d tid %u status %d\n",
1412 __func__
, ep
, state_read(&ep
->com
), ep
->hwtid
, status
);
1415 * The ep will timeout and inform the ULP of the failure.
1423 static int abort_rpl(struct c4iw_dev
*dev
, struct sk_buff
*skb
)
1426 struct cpl_abort_rpl_rss
*rpl
= cplhdr(skb
);
1428 unsigned int tid
= GET_TID(rpl
);
1429 struct tid_info
*t
= dev
->rdev
.lldi
.tids
;
1431 ep
= lookup_tid(t
, tid
);
1433 printk(KERN_WARNING MOD
"Abort rpl to freed endpoint\n");
1436 PDBG("%s ep %p tid %u\n", __func__
, ep
, ep
->hwtid
);
1437 mutex_lock(&ep
->com
.mutex
);
1438 switch (ep
->com
.state
) {
1440 __state_set(&ep
->com
, DEAD
);
1444 printk(KERN_ERR
"%s ep %p state %d\n",
1445 __func__
, ep
, ep
->com
.state
);
1448 mutex_unlock(&ep
->com
.mutex
);
1451 release_ep_resources(ep
);
1455 static void send_fw_act_open_req(struct c4iw_ep
*ep
, unsigned int atid
)
1457 struct sk_buff
*skb
;
1458 struct fw_ofld_connection_wr
*req
;
1459 unsigned int mtu_idx
;
1462 skb
= get_skb(NULL
, sizeof(*req
), GFP_KERNEL
);
1463 req
= (struct fw_ofld_connection_wr
*)__skb_put(skb
, sizeof(*req
));
1464 memset(req
, 0, sizeof(*req
));
1465 req
->op_compl
= htonl(V_WR_OP(FW_OFLD_CONNECTION_WR
));
1466 req
->len16_pkd
= htonl(FW_WR_LEN16(DIV_ROUND_UP(sizeof(*req
), 16)));
1467 req
->le
.filter
= cpu_to_be32(select_ntuple(ep
->com
.dev
, ep
->dst
,
1469 req
->le
.lport
= ep
->com
.local_addr
.sin_port
;
1470 req
->le
.pport
= ep
->com
.remote_addr
.sin_port
;
1471 req
->le
.u
.ipv4
.lip
= ep
->com
.local_addr
.sin_addr
.s_addr
;
1472 req
->le
.u
.ipv4
.pip
= ep
->com
.remote_addr
.sin_addr
.s_addr
;
1473 req
->tcb
.t_state_to_astid
=
1474 htonl(V_FW_OFLD_CONNECTION_WR_T_STATE(TCP_SYN_SENT
) |
1475 V_FW_OFLD_CONNECTION_WR_ASTID(atid
));
1476 req
->tcb
.cplrxdataack_cplpassacceptrpl
=
1477 htons(F_FW_OFLD_CONNECTION_WR_CPLRXDATAACK
);
1478 req
->tcb
.tx_max
= jiffies
;
1479 req
->tcb
.rcv_adv
= htons(1);
1480 cxgb4_best_mtu(ep
->com
.dev
->rdev
.lldi
.mtus
, ep
->mtu
, &mtu_idx
);
1481 wscale
= compute_wscale(rcv_win
);
1482 req
->tcb
.opt0
= TCAM_BYPASS(1) |
1483 (nocong
? NO_CONG(1) : 0) |
1488 L2T_IDX(ep
->l2t
->idx
) |
1489 TX_CHAN(ep
->tx_chan
) |
1490 SMAC_SEL(ep
->smac_idx
) |
1492 ULP_MODE(ULP_MODE_TCPDDP
) |
1493 RCV_BUFSIZ(rcv_win
>> 10);
1494 req
->tcb
.opt2
= PACE(1) |
1495 TX_QUEUE(ep
->com
.dev
->rdev
.lldi
.tx_modq
[ep
->tx_chan
]) |
1497 CCTRL_ECN(enable_ecn
) |
1498 RSS_QUEUE_VALID
| RSS_QUEUE(ep
->rss_qid
);
1499 if (enable_tcp_timestamps
)
1500 req
->tcb
.opt2
|= TSTAMPS_EN(1);
1501 if (enable_tcp_sack
)
1502 req
->tcb
.opt2
|= SACK_EN(1);
1503 if (wscale
&& enable_tcp_window_scaling
)
1504 req
->tcb
.opt2
|= WND_SCALE_EN(1);
1505 req
->tcb
.opt0
= cpu_to_be64(req
->tcb
.opt0
);
1506 req
->tcb
.opt2
= cpu_to_be32(req
->tcb
.opt2
);
1507 set_wr_txq(skb
, CPL_PRIORITY_CONTROL
, ep
->ctrlq_idx
);
1508 set_bit(ACT_OFLD_CONN
, &ep
->com
.history
);
1509 c4iw_l2t_send(&ep
->com
.dev
->rdev
, skb
, ep
->l2t
);
1513 * Return whether a failed active open has allocated a TID
1515 static inline int act_open_has_tid(int status
)
1517 return status
!= CPL_ERR_TCAM_FULL
&& status
!= CPL_ERR_CONN_EXIST
&&
1518 status
!= CPL_ERR_ARP_MISS
;
1521 #define ACT_OPEN_RETRY_COUNT 2
1523 static int c4iw_reconnect(struct c4iw_ep
*ep
)
1527 struct port_info
*pi
;
1528 struct net_device
*pdev
;
1530 struct neighbour
*neigh
;
1532 PDBG("%s qp %p cm_id %p\n", __func__
, ep
->com
.qp
, ep
->com
.cm_id
);
1533 init_timer(&ep
->timer
);
1536 * Allocate an active TID to initiate a TCP connection.
1538 ep
->atid
= cxgb4_alloc_atid(ep
->com
.dev
->rdev
.lldi
.tids
, ep
);
1539 if (ep
->atid
== -1) {
1540 pr_err("%s - cannot alloc atid.\n", __func__
);
1544 insert_handle(ep
->com
.dev
, &ep
->com
.dev
->atid_idr
, ep
, ep
->atid
);
1547 rt
= find_route(ep
->com
.dev
,
1548 ep
->com
.cm_id
->local_addr
.sin_addr
.s_addr
,
1549 ep
->com
.cm_id
->remote_addr
.sin_addr
.s_addr
,
1550 ep
->com
.cm_id
->local_addr
.sin_port
,
1551 ep
->com
.cm_id
->remote_addr
.sin_port
, 0);
1553 pr_err("%s - cannot find route.\n", __func__
);
1554 err
= -EHOSTUNREACH
;
1559 neigh
= dst_neigh_lookup(ep
->dst
,
1560 &ep
->com
.cm_id
->remote_addr
.sin_addr
.s_addr
);
1561 /* get a l2t entry */
1562 if (neigh
->dev
->flags
& IFF_LOOPBACK
) {
1563 PDBG("%s LOOPBACK\n", __func__
);
1564 pdev
= ip_dev_find(&init_net
,
1565 ep
->com
.cm_id
->remote_addr
.sin_addr
.s_addr
);
1566 ep
->l2t
= cxgb4_l2t_get(ep
->com
.dev
->rdev
.lldi
.l2t
,
1568 pi
= (struct port_info
*)netdev_priv(pdev
);
1569 ep
->mtu
= pdev
->mtu
;
1570 ep
->tx_chan
= cxgb4_port_chan(pdev
);
1571 ep
->smac_idx
= (cxgb4_port_viid(pdev
) & 0x7F) << 1;
1574 ep
->l2t
= cxgb4_l2t_get(ep
->com
.dev
->rdev
.lldi
.l2t
,
1575 neigh
, neigh
->dev
, 0);
1576 pi
= (struct port_info
*)netdev_priv(neigh
->dev
);
1577 ep
->mtu
= dst_mtu(ep
->dst
);
1578 ep
->tx_chan
= cxgb4_port_chan(neigh
->dev
);
1579 ep
->smac_idx
= (cxgb4_port_viid(neigh
->dev
) &
1583 step
= ep
->com
.dev
->rdev
.lldi
.ntxq
/ ep
->com
.dev
->rdev
.lldi
.nchan
;
1584 ep
->txq_idx
= pi
->port_id
* step
;
1585 ep
->ctrlq_idx
= pi
->port_id
;
1586 step
= ep
->com
.dev
->rdev
.lldi
.nrxq
/ ep
->com
.dev
->rdev
.lldi
.nchan
;
1587 ep
->rss_qid
= ep
->com
.dev
->rdev
.lldi
.rxq_ids
[pi
->port_id
* step
];
1590 pr_err("%s - cannot alloc l2e.\n", __func__
);
1595 PDBG("%s txq_idx %u tx_chan %u smac_idx %u rss_qid %u l2t_idx %u\n",
1596 __func__
, ep
->txq_idx
, ep
->tx_chan
, ep
->smac_idx
, ep
->rss_qid
,
1599 state_set(&ep
->com
, CONNECTING
);
1602 /* send connect request to rnic */
1603 err
= send_connect(ep
);
1607 cxgb4_l2t_release(ep
->l2t
);
1609 dst_release(ep
->dst
);
1611 remove_handle(ep
->com
.dev
, &ep
->com
.dev
->atid_idr
, ep
->atid
);
1612 cxgb4_free_atid(ep
->com
.dev
->rdev
.lldi
.tids
, ep
->atid
);
1615 * remember to send notification to upper layer.
1616 * We are in here so the upper layer is not aware that this is
1617 * re-connect attempt and so, upper layer is still waiting for
1618 * response of 1st connect request.
1620 connect_reply_upcall(ep
, -ECONNRESET
);
1621 c4iw_put_ep(&ep
->com
);
1626 static int act_open_rpl(struct c4iw_dev
*dev
, struct sk_buff
*skb
)
1629 struct cpl_act_open_rpl
*rpl
= cplhdr(skb
);
1630 unsigned int atid
= GET_TID_TID(GET_AOPEN_ATID(
1631 ntohl(rpl
->atid_status
)));
1632 struct tid_info
*t
= dev
->rdev
.lldi
.tids
;
1633 int status
= GET_AOPEN_STATUS(ntohl(rpl
->atid_status
));
1635 ep
= lookup_atid(t
, atid
);
1637 PDBG("%s ep %p atid %u status %u errno %d\n", __func__
, ep
, atid
,
1638 status
, status2errno(status
));
1640 if (status
== CPL_ERR_RTX_NEG_ADVICE
) {
1641 printk(KERN_WARNING MOD
"Connection problems for atid %u\n",
1646 set_bit(ACT_OPEN_RPL
, &ep
->com
.history
);
1649 * Log interesting failures.
1652 case CPL_ERR_CONN_RESET
:
1653 case CPL_ERR_CONN_TIMEDOUT
:
1655 case CPL_ERR_TCAM_FULL
:
1656 if (dev
->rdev
.lldi
.enable_fw_ofld_conn
) {
1657 mutex_lock(&dev
->rdev
.stats
.lock
);
1658 dev
->rdev
.stats
.tcam_full
++;
1659 mutex_unlock(&dev
->rdev
.stats
.lock
);
1660 send_fw_act_open_req(ep
,
1661 GET_TID_TID(GET_AOPEN_ATID(
1662 ntohl(rpl
->atid_status
))));
1666 case CPL_ERR_CONN_EXIST
:
1667 if (ep
->retry_count
++ < ACT_OPEN_RETRY_COUNT
) {
1668 set_bit(ACT_RETRY_INUSE
, &ep
->com
.history
);
1669 remove_handle(ep
->com
.dev
, &ep
->com
.dev
->atid_idr
,
1671 cxgb4_free_atid(t
, atid
);
1672 dst_release(ep
->dst
);
1673 cxgb4_l2t_release(ep
->l2t
);
1679 printk(KERN_INFO MOD
"Active open failure - "
1680 "atid %u status %u errno %d %pI4:%u->%pI4:%u\n",
1681 atid
, status
, status2errno(status
),
1682 &ep
->com
.local_addr
.sin_addr
.s_addr
,
1683 ntohs(ep
->com
.local_addr
.sin_port
),
1684 &ep
->com
.remote_addr
.sin_addr
.s_addr
,
1685 ntohs(ep
->com
.remote_addr
.sin_port
));
1689 connect_reply_upcall(ep
, status2errno(status
));
1690 state_set(&ep
->com
, DEAD
);
1692 if (status
&& act_open_has_tid(status
))
1693 cxgb4_remove_tid(ep
->com
.dev
->rdev
.lldi
.tids
, 0, GET_TID(rpl
));
1695 remove_handle(ep
->com
.dev
, &ep
->com
.dev
->atid_idr
, atid
);
1696 cxgb4_free_atid(t
, atid
);
1697 dst_release(ep
->dst
);
1698 cxgb4_l2t_release(ep
->l2t
);
1699 c4iw_put_ep(&ep
->com
);
1704 static int pass_open_rpl(struct c4iw_dev
*dev
, struct sk_buff
*skb
)
1706 struct cpl_pass_open_rpl
*rpl
= cplhdr(skb
);
1707 struct tid_info
*t
= dev
->rdev
.lldi
.tids
;
1708 unsigned int stid
= GET_TID(rpl
);
1709 struct c4iw_listen_ep
*ep
= lookup_stid(t
, stid
);
1712 PDBG("%s stid %d lookup failure!\n", __func__
, stid
);
1715 PDBG("%s ep %p status %d error %d\n", __func__
, ep
,
1716 rpl
->status
, status2errno(rpl
->status
));
1717 c4iw_wake_up(&ep
->com
.wr_wait
, status2errno(rpl
->status
));
1723 static int listen_stop(struct c4iw_listen_ep
*ep
)
1725 struct sk_buff
*skb
;
1726 struct cpl_close_listsvr_req
*req
;
1728 PDBG("%s ep %p\n", __func__
, ep
);
1729 skb
= get_skb(NULL
, sizeof(*req
), GFP_KERNEL
);
1731 printk(KERN_ERR MOD
"%s - failed to alloc skb\n", __func__
);
1734 req
= (struct cpl_close_listsvr_req
*) skb_put(skb
, sizeof(*req
));
1736 OPCODE_TID(req
) = cpu_to_be32(MK_OPCODE_TID(CPL_CLOSE_LISTSRV_REQ
,
1738 req
->reply_ctrl
= cpu_to_be16(
1739 QUEUENO(ep
->com
.dev
->rdev
.lldi
.rxq_ids
[0]));
1740 set_wr_txq(skb
, CPL_PRIORITY_SETUP
, 0);
1741 return c4iw_ofld_send(&ep
->com
.dev
->rdev
, skb
);
1744 static int close_listsrv_rpl(struct c4iw_dev
*dev
, struct sk_buff
*skb
)
1746 struct cpl_close_listsvr_rpl
*rpl
= cplhdr(skb
);
1747 struct tid_info
*t
= dev
->rdev
.lldi
.tids
;
1748 unsigned int stid
= GET_TID(rpl
);
1749 struct c4iw_listen_ep
*ep
= lookup_stid(t
, stid
);
1751 PDBG("%s ep %p\n", __func__
, ep
);
1752 c4iw_wake_up(&ep
->com
.wr_wait
, status2errno(rpl
->status
));
1756 static void accept_cr(struct c4iw_ep
*ep
, __be32 peer_ip
, struct sk_buff
*skb
,
1757 struct cpl_pass_accept_req
*req
)
1759 struct cpl_pass_accept_rpl
*rpl
;
1760 unsigned int mtu_idx
;
1765 PDBG("%s ep %p tid %u\n", __func__
, ep
, ep
->hwtid
);
1766 BUG_ON(skb_cloned(skb
));
1767 skb_trim(skb
, sizeof(*rpl
));
1769 cxgb4_best_mtu(ep
->com
.dev
->rdev
.lldi
.mtus
, ep
->mtu
, &mtu_idx
);
1770 wscale
= compute_wscale(rcv_win
);
1771 opt0
= (nocong
? NO_CONG(1) : 0) |
1776 L2T_IDX(ep
->l2t
->idx
) |
1777 TX_CHAN(ep
->tx_chan
) |
1778 SMAC_SEL(ep
->smac_idx
) |
1779 DSCP(ep
->tos
>> 2) |
1780 ULP_MODE(ULP_MODE_TCPDDP
) |
1781 RCV_BUFSIZ(rcv_win
>>10);
1782 opt2
= RX_CHANNEL(0) |
1783 RSS_QUEUE_VALID
| RSS_QUEUE(ep
->rss_qid
);
1785 if (enable_tcp_timestamps
&& req
->tcpopt
.tstamp
)
1786 opt2
|= TSTAMPS_EN(1);
1787 if (enable_tcp_sack
&& req
->tcpopt
.sack
)
1789 if (wscale
&& enable_tcp_window_scaling
)
1790 opt2
|= WND_SCALE_EN(1);
1792 const struct tcphdr
*tcph
;
1793 u32 hlen
= ntohl(req
->hdr_len
);
1795 tcph
= (const void *)(req
+ 1) + G_ETH_HDR_LEN(hlen
) +
1797 if (tcph
->ece
&& tcph
->cwr
)
1798 opt2
|= CCTRL_ECN(1);
1802 INIT_TP_WR(rpl
, ep
->hwtid
);
1803 OPCODE_TID(rpl
) = cpu_to_be32(MK_OPCODE_TID(CPL_PASS_ACCEPT_RPL
,
1805 rpl
->opt0
= cpu_to_be64(opt0
);
1806 rpl
->opt2
= cpu_to_be32(opt2
);
1807 set_wr_txq(skb
, CPL_PRIORITY_SETUP
, ep
->ctrlq_idx
);
1808 c4iw_l2t_send(&ep
->com
.dev
->rdev
, skb
, ep
->l2t
);
1813 static void reject_cr(struct c4iw_dev
*dev
, u32 hwtid
, __be32 peer_ip
,
1814 struct sk_buff
*skb
)
1816 PDBG("%s c4iw_dev %p tid %u peer_ip %x\n", __func__
, dev
, hwtid
,
1818 BUG_ON(skb_cloned(skb
));
1819 skb_trim(skb
, sizeof(struct cpl_tid_release
));
1821 release_tid(&dev
->rdev
, hwtid
, skb
);
1825 static void get_4tuple(struct cpl_pass_accept_req
*req
,
1826 __be32
*local_ip
, __be32
*peer_ip
,
1827 __be16
*local_port
, __be16
*peer_port
)
1829 int eth_len
= G_ETH_HDR_LEN(be32_to_cpu(req
->hdr_len
));
1830 int ip_len
= G_IP_HDR_LEN(be32_to_cpu(req
->hdr_len
));
1831 struct iphdr
*ip
= (struct iphdr
*)((u8
*)(req
+ 1) + eth_len
);
1832 struct tcphdr
*tcp
= (struct tcphdr
*)
1833 ((u8
*)(req
+ 1) + eth_len
+ ip_len
);
1835 PDBG("%s saddr 0x%x daddr 0x%x sport %u dport %u\n", __func__
,
1836 ntohl(ip
->saddr
), ntohl(ip
->daddr
), ntohs(tcp
->source
),
1839 *peer_ip
= ip
->saddr
;
1840 *local_ip
= ip
->daddr
;
1841 *peer_port
= tcp
->source
;
1842 *local_port
= tcp
->dest
;
1847 static int import_ep(struct c4iw_ep
*ep
, __be32 peer_ip
, struct dst_entry
*dst
,
1848 struct c4iw_dev
*cdev
, bool clear_mpa_v1
)
1850 struct neighbour
*n
;
1853 n
= dst_neigh_lookup(dst
, &peer_ip
);
1859 if (n
->dev
->flags
& IFF_LOOPBACK
) {
1860 struct net_device
*pdev
;
1862 pdev
= ip_dev_find(&init_net
, peer_ip
);
1867 ep
->l2t
= cxgb4_l2t_get(cdev
->rdev
.lldi
.l2t
,
1871 ep
->mtu
= pdev
->mtu
;
1872 ep
->tx_chan
= cxgb4_port_chan(pdev
);
1873 ep
->smac_idx
= (cxgb4_port_viid(pdev
) & 0x7F) << 1;
1874 step
= cdev
->rdev
.lldi
.ntxq
/
1875 cdev
->rdev
.lldi
.nchan
;
1876 ep
->txq_idx
= cxgb4_port_idx(pdev
) * step
;
1877 step
= cdev
->rdev
.lldi
.nrxq
/
1878 cdev
->rdev
.lldi
.nchan
;
1879 ep
->ctrlq_idx
= cxgb4_port_idx(pdev
);
1880 ep
->rss_qid
= cdev
->rdev
.lldi
.rxq_ids
[
1881 cxgb4_port_idx(pdev
) * step
];
1884 ep
->l2t
= cxgb4_l2t_get(cdev
->rdev
.lldi
.l2t
,
1888 ep
->mtu
= dst_mtu(dst
);
1889 ep
->tx_chan
= cxgb4_port_chan(n
->dev
);
1890 ep
->smac_idx
= (cxgb4_port_viid(n
->dev
) & 0x7F) << 1;
1891 step
= cdev
->rdev
.lldi
.ntxq
/
1892 cdev
->rdev
.lldi
.nchan
;
1893 ep
->txq_idx
= cxgb4_port_idx(n
->dev
) * step
;
1894 ep
->ctrlq_idx
= cxgb4_port_idx(n
->dev
);
1895 step
= cdev
->rdev
.lldi
.nrxq
/
1896 cdev
->rdev
.lldi
.nchan
;
1897 ep
->rss_qid
= cdev
->rdev
.lldi
.rxq_ids
[
1898 cxgb4_port_idx(n
->dev
) * step
];
1901 ep
->retry_with_mpa_v1
= 0;
1902 ep
->tried_with_mpa_v1
= 0;
1914 static int pass_accept_req(struct c4iw_dev
*dev
, struct sk_buff
*skb
)
1916 struct c4iw_ep
*child_ep
= NULL
, *parent_ep
;
1917 struct cpl_pass_accept_req
*req
= cplhdr(skb
);
1918 unsigned int stid
= GET_POPEN_TID(ntohl(req
->tos_stid
));
1919 struct tid_info
*t
= dev
->rdev
.lldi
.tids
;
1920 unsigned int hwtid
= GET_TID(req
);
1921 struct dst_entry
*dst
;
1923 __be32 local_ip
, peer_ip
= 0;
1924 __be16 local_port
, peer_port
;
1926 u16 peer_mss
= ntohs(req
->tcpopt
.mss
);
1928 parent_ep
= lookup_stid(t
, stid
);
1930 PDBG("%s connect request on invalid stid %d\n", __func__
, stid
);
1933 get_4tuple(req
, &local_ip
, &peer_ip
, &local_port
, &peer_port
);
1935 PDBG("%s parent ep %p hwtid %u laddr 0x%x raddr 0x%x lport %d " \
1936 "rport %d peer_mss %d\n", __func__
, parent_ep
, hwtid
,
1937 ntohl(local_ip
), ntohl(peer_ip
), ntohs(local_port
),
1938 ntohs(peer_port
), peer_mss
);
1940 if (state_read(&parent_ep
->com
) != LISTEN
) {
1941 printk(KERN_ERR
"%s - listening ep not in LISTEN\n",
1946 /* Find output route */
1947 rt
= find_route(dev
, local_ip
, peer_ip
, local_port
, peer_port
,
1948 GET_POPEN_TOS(ntohl(req
->tos_stid
)));
1950 printk(KERN_ERR MOD
"%s - failed to find dst entry!\n",
1956 child_ep
= alloc_ep(sizeof(*child_ep
), GFP_KERNEL
);
1958 printk(KERN_ERR MOD
"%s - failed to allocate ep entry!\n",
1964 err
= import_ep(child_ep
, peer_ip
, dst
, dev
, false);
1966 printk(KERN_ERR MOD
"%s - failed to allocate l2t entry!\n",
1973 if (peer_mss
&& child_ep
->mtu
> (peer_mss
+ 40))
1974 child_ep
->mtu
= peer_mss
+ 40;
1976 state_set(&child_ep
->com
, CONNECTING
);
1977 child_ep
->com
.dev
= dev
;
1978 child_ep
->com
.cm_id
= NULL
;
1979 child_ep
->com
.local_addr
.sin_family
= PF_INET
;
1980 child_ep
->com
.local_addr
.sin_port
= local_port
;
1981 child_ep
->com
.local_addr
.sin_addr
.s_addr
= local_ip
;
1982 child_ep
->com
.remote_addr
.sin_family
= PF_INET
;
1983 child_ep
->com
.remote_addr
.sin_port
= peer_port
;
1984 child_ep
->com
.remote_addr
.sin_addr
.s_addr
= peer_ip
;
1985 c4iw_get_ep(&parent_ep
->com
);
1986 child_ep
->parent_ep
= parent_ep
;
1987 child_ep
->tos
= GET_POPEN_TOS(ntohl(req
->tos_stid
));
1988 child_ep
->dst
= dst
;
1989 child_ep
->hwtid
= hwtid
;
1991 PDBG("%s tx_chan %u smac_idx %u rss_qid %u\n", __func__
,
1992 child_ep
->tx_chan
, child_ep
->smac_idx
, child_ep
->rss_qid
);
1994 init_timer(&child_ep
->timer
);
1995 cxgb4_insert_tid(t
, child_ep
, hwtid
);
1996 accept_cr(child_ep
, peer_ip
, skb
, req
);
1997 set_bit(PASS_ACCEPT_REQ
, &child_ep
->com
.history
);
2000 reject_cr(dev
, hwtid
, peer_ip
, skb
);
2005 static int pass_establish(struct c4iw_dev
*dev
, struct sk_buff
*skb
)
2008 struct cpl_pass_establish
*req
= cplhdr(skb
);
2009 struct tid_info
*t
= dev
->rdev
.lldi
.tids
;
2010 unsigned int tid
= GET_TID(req
);
2012 ep
= lookup_tid(t
, tid
);
2013 PDBG("%s ep %p tid %u\n", __func__
, ep
, ep
->hwtid
);
2014 ep
->snd_seq
= be32_to_cpu(req
->snd_isn
);
2015 ep
->rcv_seq
= be32_to_cpu(req
->rcv_isn
);
2017 PDBG("%s ep %p hwtid %u tcp_opt 0x%02x\n", __func__
, ep
, tid
,
2018 ntohs(req
->tcp_opt
));
2020 set_emss(ep
, ntohs(req
->tcp_opt
));
2021 insert_handle(dev
, &dev
->hwtid_idr
, ep
, ep
->hwtid
);
2023 dst_confirm(ep
->dst
);
2024 state_set(&ep
->com
, MPA_REQ_WAIT
);
2026 send_flowc(ep
, skb
);
2027 set_bit(PASS_ESTAB
, &ep
->com
.history
);
2032 static int peer_close(struct c4iw_dev
*dev
, struct sk_buff
*skb
)
2034 struct cpl_peer_close
*hdr
= cplhdr(skb
);
2036 struct c4iw_qp_attributes attrs
;
2039 struct tid_info
*t
= dev
->rdev
.lldi
.tids
;
2040 unsigned int tid
= GET_TID(hdr
);
2043 ep
= lookup_tid(t
, tid
);
2044 PDBG("%s ep %p tid %u\n", __func__
, ep
, ep
->hwtid
);
2045 dst_confirm(ep
->dst
);
2047 set_bit(PEER_CLOSE
, &ep
->com
.history
);
2048 mutex_lock(&ep
->com
.mutex
);
2049 switch (ep
->com
.state
) {
2051 __state_set(&ep
->com
, CLOSING
);
2054 __state_set(&ep
->com
, CLOSING
);
2055 connect_reply_upcall(ep
, -ECONNRESET
);
2060 * We're gonna mark this puppy DEAD, but keep
2061 * the reference on it until the ULP accepts or
2062 * rejects the CR. Also wake up anyone waiting
2063 * in rdma connection migration (see c4iw_accept_cr()).
2065 __state_set(&ep
->com
, CLOSING
);
2066 PDBG("waking up ep %p tid %u\n", ep
, ep
->hwtid
);
2067 c4iw_wake_up(&ep
->com
.wr_wait
, -ECONNRESET
);
2070 __state_set(&ep
->com
, CLOSING
);
2071 PDBG("waking up ep %p tid %u\n", ep
, ep
->hwtid
);
2072 c4iw_wake_up(&ep
->com
.wr_wait
, -ECONNRESET
);
2076 __state_set(&ep
->com
, CLOSING
);
2077 attrs
.next_state
= C4IW_QP_STATE_CLOSING
;
2078 ret
= c4iw_modify_qp(ep
->com
.qp
->rhp
, ep
->com
.qp
,
2079 C4IW_QP_ATTR_NEXT_STATE
, &attrs
, 1);
2080 if (ret
!= -ECONNRESET
) {
2081 peer_close_upcall(ep
);
2089 __state_set(&ep
->com
, MORIBUND
);
2094 if (ep
->com
.cm_id
&& ep
->com
.qp
) {
2095 attrs
.next_state
= C4IW_QP_STATE_IDLE
;
2096 c4iw_modify_qp(ep
->com
.qp
->rhp
, ep
->com
.qp
,
2097 C4IW_QP_ATTR_NEXT_STATE
, &attrs
, 1);
2099 close_complete_upcall(ep
);
2100 __state_set(&ep
->com
, DEAD
);
2110 mutex_unlock(&ep
->com
.mutex
);
2112 c4iw_ep_disconnect(ep
, 0, GFP_KERNEL
);
2114 release_ep_resources(ep
);
2119 * Returns whether an ABORT_REQ_RSS message is a negative advice.
2121 static int is_neg_adv_abort(unsigned int status
)
2123 return status
== CPL_ERR_RTX_NEG_ADVICE
||
2124 status
== CPL_ERR_PERSIST_NEG_ADVICE
;
2127 static int peer_abort(struct c4iw_dev
*dev
, struct sk_buff
*skb
)
2129 struct cpl_abort_req_rss
*req
= cplhdr(skb
);
2131 struct cpl_abort_rpl
*rpl
;
2132 struct sk_buff
*rpl_skb
;
2133 struct c4iw_qp_attributes attrs
;
2136 struct tid_info
*t
= dev
->rdev
.lldi
.tids
;
2137 unsigned int tid
= GET_TID(req
);
2139 ep
= lookup_tid(t
, tid
);
2140 if (is_neg_adv_abort(req
->status
)) {
2141 PDBG("%s neg_adv_abort ep %p tid %u\n", __func__
, ep
,
2145 PDBG("%s ep %p tid %u state %u\n", __func__
, ep
, ep
->hwtid
,
2147 set_bit(PEER_ABORT
, &ep
->com
.history
);
2150 * Wake up any threads in rdma_init() or rdma_fini().
2151 * However, this is not needed if com state is just
2154 if (ep
->com
.state
!= MPA_REQ_SENT
)
2155 c4iw_wake_up(&ep
->com
.wr_wait
, -ECONNRESET
);
2157 mutex_lock(&ep
->com
.mutex
);
2158 switch (ep
->com
.state
) {
2166 if (mpa_rev
== 2 && ep
->tried_with_mpa_v1
)
2167 connect_reply_upcall(ep
, -ECONNRESET
);
2170 * we just don't send notification upwards because we
2171 * want to retry with mpa_v1 without upper layers even
2174 * do some housekeeping so as to re-initiate the
2177 PDBG("%s: mpa_rev=%d. Retrying with mpav1\n", __func__
,
2179 ep
->retry_with_mpa_v1
= 1;
2191 if (ep
->com
.cm_id
&& ep
->com
.qp
) {
2192 attrs
.next_state
= C4IW_QP_STATE_ERROR
;
2193 ret
= c4iw_modify_qp(ep
->com
.qp
->rhp
,
2194 ep
->com
.qp
, C4IW_QP_ATTR_NEXT_STATE
,
2198 "%s - qp <- error failed!\n",
2201 peer_abort_upcall(ep
);
2206 PDBG("%s PEER_ABORT IN DEAD STATE!!!!\n", __func__
);
2207 mutex_unlock(&ep
->com
.mutex
);
2213 dst_confirm(ep
->dst
);
2214 if (ep
->com
.state
!= ABORTING
) {
2215 __state_set(&ep
->com
, DEAD
);
2216 /* we don't release if we want to retry with mpa_v1 */
2217 if (!ep
->retry_with_mpa_v1
)
2220 mutex_unlock(&ep
->com
.mutex
);
2222 rpl_skb
= get_skb(skb
, sizeof(*rpl
), GFP_KERNEL
);
2224 printk(KERN_ERR MOD
"%s - cannot allocate skb!\n",
2229 set_wr_txq(skb
, CPL_PRIORITY_DATA
, ep
->txq_idx
);
2230 rpl
= (struct cpl_abort_rpl
*) skb_put(rpl_skb
, sizeof(*rpl
));
2231 INIT_TP_WR(rpl
, ep
->hwtid
);
2232 OPCODE_TID(rpl
) = cpu_to_be32(MK_OPCODE_TID(CPL_ABORT_RPL
, ep
->hwtid
));
2233 rpl
->cmd
= CPL_ABORT_NO_RST
;
2234 c4iw_ofld_send(&ep
->com
.dev
->rdev
, rpl_skb
);
2237 release_ep_resources(ep
);
2239 /* retry with mpa-v1 */
2240 if (ep
&& ep
->retry_with_mpa_v1
) {
2241 cxgb4_remove_tid(ep
->com
.dev
->rdev
.lldi
.tids
, 0, ep
->hwtid
);
2242 dst_release(ep
->dst
);
2243 cxgb4_l2t_release(ep
->l2t
);
2250 static int close_con_rpl(struct c4iw_dev
*dev
, struct sk_buff
*skb
)
2253 struct c4iw_qp_attributes attrs
;
2254 struct cpl_close_con_rpl
*rpl
= cplhdr(skb
);
2256 struct tid_info
*t
= dev
->rdev
.lldi
.tids
;
2257 unsigned int tid
= GET_TID(rpl
);
2259 ep
= lookup_tid(t
, tid
);
2261 PDBG("%s ep %p tid %u\n", __func__
, ep
, ep
->hwtid
);
2264 /* The cm_id may be null if we failed to connect */
2265 mutex_lock(&ep
->com
.mutex
);
2266 switch (ep
->com
.state
) {
2268 __state_set(&ep
->com
, MORIBUND
);
2272 if ((ep
->com
.cm_id
) && (ep
->com
.qp
)) {
2273 attrs
.next_state
= C4IW_QP_STATE_IDLE
;
2274 c4iw_modify_qp(ep
->com
.qp
->rhp
,
2276 C4IW_QP_ATTR_NEXT_STATE
,
2279 close_complete_upcall(ep
);
2280 __state_set(&ep
->com
, DEAD
);
2290 mutex_unlock(&ep
->com
.mutex
);
2292 release_ep_resources(ep
);
2296 static int terminate(struct c4iw_dev
*dev
, struct sk_buff
*skb
)
2298 struct cpl_rdma_terminate
*rpl
= cplhdr(skb
);
2299 struct tid_info
*t
= dev
->rdev
.lldi
.tids
;
2300 unsigned int tid
= GET_TID(rpl
);
2302 struct c4iw_qp_attributes attrs
;
2304 ep
= lookup_tid(t
, tid
);
2307 if (ep
&& ep
->com
.qp
) {
2308 printk(KERN_WARNING MOD
"TERM received tid %u qpid %u\n", tid
,
2309 ep
->com
.qp
->wq
.sq
.qid
);
2310 attrs
.next_state
= C4IW_QP_STATE_TERMINATE
;
2311 c4iw_modify_qp(ep
->com
.qp
->rhp
, ep
->com
.qp
,
2312 C4IW_QP_ATTR_NEXT_STATE
, &attrs
, 1);
2314 printk(KERN_WARNING MOD
"TERM received tid %u no ep/qp\n", tid
);
2320 * Upcall from the adapter indicating data has been transmitted.
2321 * For us its just the single MPA request or reply. We can now free
2322 * the skb holding the mpa message.
2324 static int fw4_ack(struct c4iw_dev
*dev
, struct sk_buff
*skb
)
2327 struct cpl_fw4_ack
*hdr
= cplhdr(skb
);
2328 u8 credits
= hdr
->credits
;
2329 unsigned int tid
= GET_TID(hdr
);
2330 struct tid_info
*t
= dev
->rdev
.lldi
.tids
;
2333 ep
= lookup_tid(t
, tid
);
2334 PDBG("%s ep %p tid %u credits %u\n", __func__
, ep
, ep
->hwtid
, credits
);
2336 PDBG("%s 0 credit ack ep %p tid %u state %u\n",
2337 __func__
, ep
, ep
->hwtid
, state_read(&ep
->com
));
2341 dst_confirm(ep
->dst
);
2343 PDBG("%s last streaming msg ack ep %p tid %u state %u "
2344 "initiator %u freeing skb\n", __func__
, ep
, ep
->hwtid
,
2345 state_read(&ep
->com
), ep
->mpa_attr
.initiator
? 1 : 0);
2346 kfree_skb(ep
->mpa_skb
);
2352 int c4iw_reject_cr(struct iw_cm_id
*cm_id
, const void *pdata
, u8 pdata_len
)
2355 struct c4iw_ep
*ep
= to_ep(cm_id
);
2356 PDBG("%s ep %p tid %u\n", __func__
, ep
, ep
->hwtid
);
2358 if (state_read(&ep
->com
) == DEAD
) {
2359 c4iw_put_ep(&ep
->com
);
2362 set_bit(ULP_REJECT
, &ep
->com
.history
);
2363 BUG_ON(state_read(&ep
->com
) != MPA_REQ_RCVD
);
2365 abort_connection(ep
, NULL
, GFP_KERNEL
);
2367 err
= send_mpa_reject(ep
, pdata
, pdata_len
);
2368 err
= c4iw_ep_disconnect(ep
, 0, GFP_KERNEL
);
2370 c4iw_put_ep(&ep
->com
);
2374 int c4iw_accept_cr(struct iw_cm_id
*cm_id
, struct iw_cm_conn_param
*conn_param
)
2377 struct c4iw_qp_attributes attrs
;
2378 enum c4iw_qp_attr_mask mask
;
2379 struct c4iw_ep
*ep
= to_ep(cm_id
);
2380 struct c4iw_dev
*h
= to_c4iw_dev(cm_id
->device
);
2381 struct c4iw_qp
*qp
= get_qhp(h
, conn_param
->qpn
);
2383 PDBG("%s ep %p tid %u\n", __func__
, ep
, ep
->hwtid
);
2384 if (state_read(&ep
->com
) == DEAD
) {
2389 BUG_ON(state_read(&ep
->com
) != MPA_REQ_RCVD
);
2392 set_bit(ULP_ACCEPT
, &ep
->com
.history
);
2393 if ((conn_param
->ord
> c4iw_max_read_depth
) ||
2394 (conn_param
->ird
> c4iw_max_read_depth
)) {
2395 abort_connection(ep
, NULL
, GFP_KERNEL
);
2400 if (ep
->mpa_attr
.version
== 2 && ep
->mpa_attr
.enhanced_rdma_conn
) {
2401 if (conn_param
->ord
> ep
->ird
) {
2402 ep
->ird
= conn_param
->ird
;
2403 ep
->ord
= conn_param
->ord
;
2404 send_mpa_reject(ep
, conn_param
->private_data
,
2405 conn_param
->private_data_len
);
2406 abort_connection(ep
, NULL
, GFP_KERNEL
);
2410 if (conn_param
->ird
> ep
->ord
) {
2412 conn_param
->ird
= 1;
2414 abort_connection(ep
, NULL
, GFP_KERNEL
);
2421 ep
->ird
= conn_param
->ird
;
2422 ep
->ord
= conn_param
->ord
;
2424 if (ep
->mpa_attr
.version
!= 2)
2425 if (peer2peer
&& ep
->ird
== 0)
2428 PDBG("%s %d ird %d ord %d\n", __func__
, __LINE__
, ep
->ird
, ep
->ord
);
2430 cm_id
->add_ref(cm_id
);
2431 ep
->com
.cm_id
= cm_id
;
2434 /* bind QP to EP and move to RTS */
2435 attrs
.mpa_attr
= ep
->mpa_attr
;
2436 attrs
.max_ird
= ep
->ird
;
2437 attrs
.max_ord
= ep
->ord
;
2438 attrs
.llp_stream_handle
= ep
;
2439 attrs
.next_state
= C4IW_QP_STATE_RTS
;
2441 /* bind QP and TID with INIT_WR */
2442 mask
= C4IW_QP_ATTR_NEXT_STATE
|
2443 C4IW_QP_ATTR_LLP_STREAM_HANDLE
|
2444 C4IW_QP_ATTR_MPA_ATTR
|
2445 C4IW_QP_ATTR_MAX_IRD
|
2446 C4IW_QP_ATTR_MAX_ORD
;
2448 err
= c4iw_modify_qp(ep
->com
.qp
->rhp
,
2449 ep
->com
.qp
, mask
, &attrs
, 1);
2452 err
= send_mpa_reply(ep
, conn_param
->private_data
,
2453 conn_param
->private_data_len
);
2457 state_set(&ep
->com
, FPDU_MODE
);
2458 established_upcall(ep
);
2459 c4iw_put_ep(&ep
->com
);
2462 ep
->com
.cm_id
= NULL
;
2464 cm_id
->rem_ref(cm_id
);
2466 c4iw_put_ep(&ep
->com
);
2470 int c4iw_connect(struct iw_cm_id
*cm_id
, struct iw_cm_conn_param
*conn_param
)
2472 struct c4iw_dev
*dev
= to_c4iw_dev(cm_id
->device
);
2477 if ((conn_param
->ord
> c4iw_max_read_depth
) ||
2478 (conn_param
->ird
> c4iw_max_read_depth
)) {
2482 ep
= alloc_ep(sizeof(*ep
), GFP_KERNEL
);
2484 printk(KERN_ERR MOD
"%s - cannot alloc ep.\n", __func__
);
2488 init_timer(&ep
->timer
);
2489 ep
->plen
= conn_param
->private_data_len
;
2491 memcpy(ep
->mpa_pkt
+ sizeof(struct mpa_message
),
2492 conn_param
->private_data
, ep
->plen
);
2493 ep
->ird
= conn_param
->ird
;
2494 ep
->ord
= conn_param
->ord
;
2496 if (peer2peer
&& ep
->ord
== 0)
2499 cm_id
->add_ref(cm_id
);
2501 ep
->com
.cm_id
= cm_id
;
2502 ep
->com
.qp
= get_qhp(dev
, conn_param
->qpn
);
2503 BUG_ON(!ep
->com
.qp
);
2504 PDBG("%s qpn 0x%x qp %p cm_id %p\n", __func__
, conn_param
->qpn
,
2508 * Allocate an active TID to initiate a TCP connection.
2510 ep
->atid
= cxgb4_alloc_atid(dev
->rdev
.lldi
.tids
, ep
);
2511 if (ep
->atid
== -1) {
2512 printk(KERN_ERR MOD
"%s - cannot alloc atid.\n", __func__
);
2516 insert_handle(dev
, &dev
->atid_idr
, ep
, ep
->atid
);
2518 PDBG("%s saddr 0x%x sport 0x%x raddr 0x%x rport 0x%x\n", __func__
,
2519 ntohl(cm_id
->local_addr
.sin_addr
.s_addr
),
2520 ntohs(cm_id
->local_addr
.sin_port
),
2521 ntohl(cm_id
->remote_addr
.sin_addr
.s_addr
),
2522 ntohs(cm_id
->remote_addr
.sin_port
));
2525 rt
= find_route(dev
,
2526 cm_id
->local_addr
.sin_addr
.s_addr
,
2527 cm_id
->remote_addr
.sin_addr
.s_addr
,
2528 cm_id
->local_addr
.sin_port
,
2529 cm_id
->remote_addr
.sin_port
, 0);
2531 printk(KERN_ERR MOD
"%s - cannot find route.\n", __func__
);
2532 err
= -EHOSTUNREACH
;
2537 err
= import_ep(ep
, cm_id
->remote_addr
.sin_addr
.s_addr
,
2538 ep
->dst
, ep
->com
.dev
, true);
2540 printk(KERN_ERR MOD
"%s - cannot alloc l2e.\n", __func__
);
2544 PDBG("%s txq_idx %u tx_chan %u smac_idx %u rss_qid %u l2t_idx %u\n",
2545 __func__
, ep
->txq_idx
, ep
->tx_chan
, ep
->smac_idx
, ep
->rss_qid
,
2548 state_set(&ep
->com
, CONNECTING
);
2550 ep
->com
.local_addr
= cm_id
->local_addr
;
2551 ep
->com
.remote_addr
= cm_id
->remote_addr
;
2553 /* send connect request to rnic */
2554 err
= send_connect(ep
);
2558 cxgb4_l2t_release(ep
->l2t
);
2560 dst_release(ep
->dst
);
2562 remove_handle(ep
->com
.dev
, &ep
->com
.dev
->atid_idr
, ep
->atid
);
2563 cxgb4_free_atid(ep
->com
.dev
->rdev
.lldi
.tids
, ep
->atid
);
2565 cm_id
->rem_ref(cm_id
);
2566 c4iw_put_ep(&ep
->com
);
2571 int c4iw_create_listen(struct iw_cm_id
*cm_id
, int backlog
)
2574 struct c4iw_dev
*dev
= to_c4iw_dev(cm_id
->device
);
2575 struct c4iw_listen_ep
*ep
;
2579 ep
= alloc_ep(sizeof(*ep
), GFP_KERNEL
);
2581 printk(KERN_ERR MOD
"%s - cannot alloc ep.\n", __func__
);
2585 PDBG("%s ep %p\n", __func__
, ep
);
2586 cm_id
->add_ref(cm_id
);
2587 ep
->com
.cm_id
= cm_id
;
2589 ep
->backlog
= backlog
;
2590 ep
->com
.local_addr
= cm_id
->local_addr
;
2593 * Allocate a server TID.
2595 if (dev
->rdev
.lldi
.enable_fw_ofld_conn
)
2596 ep
->stid
= cxgb4_alloc_sftid(dev
->rdev
.lldi
.tids
, PF_INET
, ep
);
2598 ep
->stid
= cxgb4_alloc_stid(dev
->rdev
.lldi
.tids
, PF_INET
, ep
);
2600 if (ep
->stid
== -1) {
2601 printk(KERN_ERR MOD
"%s - cannot alloc stid.\n", __func__
);
2605 insert_handle(dev
, &dev
->stid_idr
, ep
, ep
->stid
);
2606 state_set(&ep
->com
, LISTEN
);
2607 if (dev
->rdev
.lldi
.enable_fw_ofld_conn
) {
2609 err
= cxgb4_create_server_filter(
2610 ep
->com
.dev
->rdev
.lldi
.ports
[0], ep
->stid
,
2611 ep
->com
.local_addr
.sin_addr
.s_addr
,
2612 ep
->com
.local_addr
.sin_port
,
2614 ep
->com
.dev
->rdev
.lldi
.rxq_ids
[0],
2617 if (err
== -EBUSY
) {
2618 set_current_state(TASK_UNINTERRUPTIBLE
);
2619 schedule_timeout(usecs_to_jiffies(100));
2621 } while (err
== -EBUSY
);
2623 c4iw_init_wr_wait(&ep
->com
.wr_wait
);
2624 err
= cxgb4_create_server(ep
->com
.dev
->rdev
.lldi
.ports
[0],
2625 ep
->stid
, ep
->com
.local_addr
.sin_addr
.s_addr
,
2626 ep
->com
.local_addr
.sin_port
,
2628 ep
->com
.dev
->rdev
.lldi
.rxq_ids
[0]);
2630 err
= c4iw_wait_for_reply(&ep
->com
.dev
->rdev
,
2635 cm_id
->provider_data
= ep
;
2638 pr_err("%s cxgb4_create_server/filter failed err %d " \
2639 "stid %d laddr %08x lport %d\n", \
2640 __func__
, err
, ep
->stid
,
2641 ntohl(ep
->com
.local_addr
.sin_addr
.s_addr
),
2642 ntohs(ep
->com
.local_addr
.sin_port
));
2643 cxgb4_free_stid(ep
->com
.dev
->rdev
.lldi
.tids
, ep
->stid
, PF_INET
);
2645 cm_id
->rem_ref(cm_id
);
2646 c4iw_put_ep(&ep
->com
);
2652 int c4iw_destroy_listen(struct iw_cm_id
*cm_id
)
2655 struct c4iw_listen_ep
*ep
= to_listen_ep(cm_id
);
2657 PDBG("%s ep %p\n", __func__
, ep
);
2660 state_set(&ep
->com
, DEAD
);
2661 if (ep
->com
.dev
->rdev
.lldi
.enable_fw_ofld_conn
) {
2662 err
= cxgb4_remove_server_filter(
2663 ep
->com
.dev
->rdev
.lldi
.ports
[0], ep
->stid
,
2664 ep
->com
.dev
->rdev
.lldi
.rxq_ids
[0], 0);
2666 c4iw_init_wr_wait(&ep
->com
.wr_wait
);
2667 err
= listen_stop(ep
);
2670 err
= c4iw_wait_for_reply(&ep
->com
.dev
->rdev
, &ep
->com
.wr_wait
,
2673 remove_handle(ep
->com
.dev
, &ep
->com
.dev
->stid_idr
, ep
->stid
);
2674 cxgb4_free_stid(ep
->com
.dev
->rdev
.lldi
.tids
, ep
->stid
, PF_INET
);
2676 cm_id
->rem_ref(cm_id
);
2677 c4iw_put_ep(&ep
->com
);
2681 int c4iw_ep_disconnect(struct c4iw_ep
*ep
, int abrupt
, gfp_t gfp
)
2686 struct c4iw_rdev
*rdev
;
2688 mutex_lock(&ep
->com
.mutex
);
2690 PDBG("%s ep %p state %s, abrupt %d\n", __func__
, ep
,
2691 states
[ep
->com
.state
], abrupt
);
2693 rdev
= &ep
->com
.dev
->rdev
;
2694 if (c4iw_fatal_error(rdev
)) {
2696 close_complete_upcall(ep
);
2697 ep
->com
.state
= DEAD
;
2699 switch (ep
->com
.state
) {
2707 ep
->com
.state
= ABORTING
;
2709 ep
->com
.state
= CLOSING
;
2712 set_bit(CLOSE_SENT
, &ep
->com
.flags
);
2715 if (!test_and_set_bit(CLOSE_SENT
, &ep
->com
.flags
)) {
2719 ep
->com
.state
= ABORTING
;
2721 ep
->com
.state
= MORIBUND
;
2727 PDBG("%s ignoring disconnect ep %p state %u\n",
2728 __func__
, ep
, ep
->com
.state
);
2737 set_bit(EP_DISC_ABORT
, &ep
->com
.history
);
2738 close_complete_upcall(ep
);
2739 ret
= send_abort(ep
, NULL
, gfp
);
2741 set_bit(EP_DISC_CLOSE
, &ep
->com
.history
);
2742 ret
= send_halfclose(ep
, gfp
);
2747 mutex_unlock(&ep
->com
.mutex
);
2749 release_ep_resources(ep
);
2753 static void active_ofld_conn_reply(struct c4iw_dev
*dev
, struct sk_buff
*skb
,
2754 struct cpl_fw6_msg_ofld_connection_wr_rpl
*req
)
2757 int atid
= be32_to_cpu(req
->tid
);
2759 ep
= (struct c4iw_ep
*)lookup_atid(dev
->rdev
.lldi
.tids
, req
->tid
);
2763 switch (req
->retval
) {
2765 set_bit(ACT_RETRY_NOMEM
, &ep
->com
.history
);
2766 if (ep
->retry_count
++ < ACT_OPEN_RETRY_COUNT
) {
2767 send_fw_act_open_req(ep
, atid
);
2771 set_bit(ACT_RETRY_INUSE
, &ep
->com
.history
);
2772 if (ep
->retry_count
++ < ACT_OPEN_RETRY_COUNT
) {
2773 send_fw_act_open_req(ep
, atid
);
2778 pr_info("%s unexpected ofld conn wr retval %d\n",
2779 __func__
, req
->retval
);
2782 pr_err("active ofld_connect_wr failure %d atid %d\n",
2784 mutex_lock(&dev
->rdev
.stats
.lock
);
2785 dev
->rdev
.stats
.act_ofld_conn_fails
++;
2786 mutex_unlock(&dev
->rdev
.stats
.lock
);
2787 connect_reply_upcall(ep
, status2errno(req
->retval
));
2788 state_set(&ep
->com
, DEAD
);
2789 remove_handle(dev
, &dev
->atid_idr
, atid
);
2790 cxgb4_free_atid(dev
->rdev
.lldi
.tids
, atid
);
2791 dst_release(ep
->dst
);
2792 cxgb4_l2t_release(ep
->l2t
);
2793 c4iw_put_ep(&ep
->com
);
2796 static void passive_ofld_conn_reply(struct c4iw_dev
*dev
, struct sk_buff
*skb
,
2797 struct cpl_fw6_msg_ofld_connection_wr_rpl
*req
)
2799 struct sk_buff
*rpl_skb
;
2800 struct cpl_pass_accept_req
*cpl
;
2803 rpl_skb
= (struct sk_buff
*)cpu_to_be64(req
->cookie
);
2806 PDBG("%s passive open failure %d\n", __func__
, req
->retval
);
2807 mutex_lock(&dev
->rdev
.stats
.lock
);
2808 dev
->rdev
.stats
.pas_ofld_conn_fails
++;
2809 mutex_unlock(&dev
->rdev
.stats
.lock
);
2812 cpl
= (struct cpl_pass_accept_req
*)cplhdr(rpl_skb
);
2813 OPCODE_TID(cpl
) = htonl(MK_OPCODE_TID(CPL_PASS_ACCEPT_REQ
,
2815 ret
= pass_accept_req(dev
, rpl_skb
);
2822 static int deferred_fw6_msg(struct c4iw_dev
*dev
, struct sk_buff
*skb
)
2824 struct cpl_fw6_msg
*rpl
= cplhdr(skb
);
2825 struct cpl_fw6_msg_ofld_connection_wr_rpl
*req
;
2827 switch (rpl
->type
) {
2829 c4iw_ev_dispatch(dev
, (struct t4_cqe
*)&rpl
->data
[0]);
2831 case FW6_TYPE_OFLD_CONNECTION_WR_RPL
:
2832 req
= (struct cpl_fw6_msg_ofld_connection_wr_rpl
*)rpl
->data
;
2833 switch (req
->t_state
) {
2835 active_ofld_conn_reply(dev
, skb
, req
);
2838 passive_ofld_conn_reply(dev
, skb
, req
);
2841 pr_err("%s unexpected ofld conn wr state %d\n",
2842 __func__
, req
->t_state
);
2850 static void build_cpl_pass_accept_req(struct sk_buff
*skb
, int stid
, u8 tos
)
2853 u16 vlantag
, len
, hdr_len
;
2855 struct cpl_rx_pkt
*cpl
= cplhdr(skb
);
2856 struct cpl_pass_accept_req
*req
;
2857 struct tcp_options_received tmp_opt
;
2859 /* Store values from cpl_rx_pkt in temporary location. */
2860 vlantag
= cpl
->vlan
;
2862 l2info
= cpl
->l2info
;
2863 hdr_len
= cpl
->hdr_len
;
2866 __skb_pull(skb
, sizeof(*req
) + sizeof(struct rss_header
));
2869 * We need to parse the TCP options from SYN packet.
2870 * to generate cpl_pass_accept_req.
2872 memset(&tmp_opt
, 0, sizeof(tmp_opt
));
2873 tcp_clear_options(&tmp_opt
);
2874 tcp_parse_options(skb
, &tmp_opt
, 0, 0, NULL
);
2876 req
= (struct cpl_pass_accept_req
*)__skb_push(skb
, sizeof(*req
));
2877 memset(req
, 0, sizeof(*req
));
2878 req
->l2info
= cpu_to_be16(V_SYN_INTF(intf
) |
2879 V_SYN_MAC_IDX(G_RX_MACIDX(htonl(l2info
))) |
2881 req
->hdr_len
= cpu_to_be32(V_SYN_RX_CHAN(G_RX_CHAN(htonl(l2info
))) |
2882 V_TCP_HDR_LEN(G_RX_TCPHDR_LEN(htons(hdr_len
))) |
2883 V_IP_HDR_LEN(G_RX_IPHDR_LEN(htons(hdr_len
))) |
2884 V_ETH_HDR_LEN(G_RX_ETHHDR_LEN(htonl(l2info
))));
2885 req
->vlan
= vlantag
;
2887 req
->tos_stid
= cpu_to_be32(PASS_OPEN_TID(stid
) |
2888 PASS_OPEN_TOS(tos
));
2889 req
->tcpopt
.mss
= htons(tmp_opt
.mss_clamp
);
2890 if (tmp_opt
.wscale_ok
)
2891 req
->tcpopt
.wsf
= tmp_opt
.snd_wscale
;
2892 req
->tcpopt
.tstamp
= tmp_opt
.saw_tstamp
;
2893 if (tmp_opt
.sack_ok
)
2894 req
->tcpopt
.sack
= 1;
2895 OPCODE_TID(req
) = htonl(MK_OPCODE_TID(CPL_PASS_ACCEPT_REQ
, 0));
2899 static void send_fw_pass_open_req(struct c4iw_dev
*dev
, struct sk_buff
*skb
,
2900 __be32 laddr
, __be16 lport
,
2901 __be32 raddr
, __be16 rport
,
2902 u32 rcv_isn
, u32 filter
, u16 window
,
2903 u32 rss_qid
, u8 port_id
)
2905 struct sk_buff
*req_skb
;
2906 struct fw_ofld_connection_wr
*req
;
2907 struct cpl_pass_accept_req
*cpl
= cplhdr(skb
);
2909 req_skb
= alloc_skb(sizeof(struct fw_ofld_connection_wr
), GFP_KERNEL
);
2910 req
= (struct fw_ofld_connection_wr
*)__skb_put(req_skb
, sizeof(*req
));
2911 memset(req
, 0, sizeof(*req
));
2912 req
->op_compl
= htonl(V_WR_OP(FW_OFLD_CONNECTION_WR
) | FW_WR_COMPL(1));
2913 req
->len16_pkd
= htonl(FW_WR_LEN16(DIV_ROUND_UP(sizeof(*req
), 16)));
2914 req
->le
.version_cpl
= htonl(F_FW_OFLD_CONNECTION_WR_CPL
);
2915 req
->le
.filter
= filter
;
2916 req
->le
.lport
= lport
;
2917 req
->le
.pport
= rport
;
2918 req
->le
.u
.ipv4
.lip
= laddr
;
2919 req
->le
.u
.ipv4
.pip
= raddr
;
2920 req
->tcb
.rcv_nxt
= htonl(rcv_isn
+ 1);
2921 req
->tcb
.rcv_adv
= htons(window
);
2922 req
->tcb
.t_state_to_astid
=
2923 htonl(V_FW_OFLD_CONNECTION_WR_T_STATE(TCP_SYN_RECV
) |
2924 V_FW_OFLD_CONNECTION_WR_RCV_SCALE(cpl
->tcpopt
.wsf
) |
2925 V_FW_OFLD_CONNECTION_WR_ASTID(
2926 GET_PASS_OPEN_TID(ntohl(cpl
->tos_stid
))));
2929 * We store the qid in opt2 which will be used by the firmware
2930 * to send us the wr response.
2932 req
->tcb
.opt2
= htonl(V_RSS_QUEUE(rss_qid
));
2935 * We initialize the MSS index in TCB to 0xF.
2936 * So that when driver sends cpl_pass_accept_rpl
2937 * TCB picks up the correct value. If this was 0
2938 * TP will ignore any value > 0 for MSS index.
2940 req
->tcb
.opt0
= cpu_to_be64(V_MSS_IDX(0xF));
2941 req
->cookie
= cpu_to_be64((u64
)skb
);
2943 set_wr_txq(req_skb
, CPL_PRIORITY_CONTROL
, port_id
);
2944 cxgb4_ofld_send(dev
->rdev
.lldi
.ports
[0], req_skb
);
2948 * Handler for CPL_RX_PKT message. Need to handle cpl_rx_pkt
2949 * messages when a filter is being used instead of server to
2950 * redirect a syn packet. When packets hit filter they are redirected
2951 * to the offload queue and driver tries to establish the connection
2952 * using firmware work request.
2954 static int rx_pkt(struct c4iw_dev
*dev
, struct sk_buff
*skb
)
2957 unsigned int filter
;
2958 struct ethhdr
*eh
= NULL
;
2959 struct vlan_ethhdr
*vlan_eh
= NULL
;
2961 struct tcphdr
*tcph
;
2962 struct rss_header
*rss
= (void *)skb
->data
;
2963 struct cpl_rx_pkt
*cpl
= (void *)skb
->data
;
2964 struct cpl_pass_accept_req
*req
= (void *)(rss
+ 1);
2965 struct l2t_entry
*e
;
2966 struct dst_entry
*dst
;
2968 struct c4iw_ep
*lep
;
2970 struct port_info
*pi
;
2971 struct net_device
*pdev
;
2975 struct neighbour
*neigh
;
2977 /* Drop all non-SYN packets */
2978 if (!(cpl
->l2info
& cpu_to_be32(F_RXF_SYN
)))
2982 * Drop all packets which did not hit the filter.
2983 * Unlikely to happen.
2985 if (!(rss
->filter_hit
&& rss
->filter_tid
))
2989 * Calculate the server tid from filter hit index from cpl_rx_pkt.
2991 stid
= cpu_to_be32(rss
->hash_val
) - dev
->rdev
.lldi
.tids
->sftid_base
2992 + dev
->rdev
.lldi
.tids
->nstids
;
2994 lep
= (struct c4iw_ep
*)lookup_stid(dev
->rdev
.lldi
.tids
, stid
);
2996 PDBG("%s connect request on invalid stid %d\n", __func__
, stid
);
3000 if (G_RX_ETHHDR_LEN(ntohl(cpl
->l2info
)) == ETH_HLEN
) {
3001 eh
= (struct ethhdr
*)(req
+ 1);
3002 iph
= (struct iphdr
*)(eh
+ 1);
3004 vlan_eh
= (struct vlan_ethhdr
*)(req
+ 1);
3005 iph
= (struct iphdr
*)(vlan_eh
+ 1);
3006 skb
->vlan_tci
= ntohs(cpl
->vlan
);
3009 if (iph
->version
!= 0x4)
3012 tcph
= (struct tcphdr
*)(iph
+ 1);
3013 skb_set_network_header(skb
, (void *)iph
- (void *)rss
);
3014 skb_set_transport_header(skb
, (void *)tcph
- (void *)rss
);
3017 PDBG("%s lip 0x%x lport %u pip 0x%x pport %u tos %d\n", __func__
,
3018 ntohl(iph
->daddr
), ntohs(tcph
->dest
), ntohl(iph
->saddr
),
3019 ntohs(tcph
->source
), iph
->tos
);
3021 rt
= find_route(dev
, iph
->daddr
, iph
->saddr
, tcph
->dest
, tcph
->source
,
3024 pr_err("%s - failed to find dst entry!\n",
3029 neigh
= dst_neigh_lookup_skb(dst
, skb
);
3031 if (neigh
->dev
->flags
& IFF_LOOPBACK
) {
3032 pdev
= ip_dev_find(&init_net
, iph
->daddr
);
3033 e
= cxgb4_l2t_get(dev
->rdev
.lldi
.l2t
, neigh
,
3035 pi
= (struct port_info
*)netdev_priv(pdev
);
3036 tx_chan
= cxgb4_port_chan(pdev
);
3039 e
= cxgb4_l2t_get(dev
->rdev
.lldi
.l2t
, neigh
,
3041 pi
= (struct port_info
*)netdev_priv(neigh
->dev
);
3042 tx_chan
= cxgb4_port_chan(neigh
->dev
);
3045 pr_err("%s - failed to allocate l2t entry!\n",
3050 step
= dev
->rdev
.lldi
.nrxq
/ dev
->rdev
.lldi
.nchan
;
3051 rss_qid
= dev
->rdev
.lldi
.rxq_ids
[pi
->port_id
* step
];
3052 window
= htons(tcph
->window
);
3054 /* Calcuate filter portion for LE region. */
3055 filter
= cpu_to_be32(select_ntuple(dev
, dst
, e
));
3058 * Synthesize the cpl_pass_accept_req. We have everything except the
3059 * TID. Once firmware sends a reply with TID we update the TID field
3060 * in cpl and pass it through the regular cpl_pass_accept_req path.
3062 build_cpl_pass_accept_req(skb
, stid
, iph
->tos
);
3063 send_fw_pass_open_req(dev
, skb
, iph
->daddr
, tcph
->dest
, iph
->saddr
,
3064 tcph
->source
, ntohl(tcph
->seq
), filter
, window
,
3065 rss_qid
, pi
->port_id
);
3066 cxgb4_l2t_release(e
);
3074 * These are the real handlers that are called from a
3077 static c4iw_handler_func work_handlers
[NUM_CPL_CMDS
] = {
3078 [CPL_ACT_ESTABLISH
] = act_establish
,
3079 [CPL_ACT_OPEN_RPL
] = act_open_rpl
,
3080 [CPL_RX_DATA
] = rx_data
,
3081 [CPL_ABORT_RPL_RSS
] = abort_rpl
,
3082 [CPL_ABORT_RPL
] = abort_rpl
,
3083 [CPL_PASS_OPEN_RPL
] = pass_open_rpl
,
3084 [CPL_CLOSE_LISTSRV_RPL
] = close_listsrv_rpl
,
3085 [CPL_PASS_ACCEPT_REQ
] = pass_accept_req
,
3086 [CPL_PASS_ESTABLISH
] = pass_establish
,
3087 [CPL_PEER_CLOSE
] = peer_close
,
3088 [CPL_ABORT_REQ_RSS
] = peer_abort
,
3089 [CPL_CLOSE_CON_RPL
] = close_con_rpl
,
3090 [CPL_RDMA_TERMINATE
] = terminate
,
3091 [CPL_FW4_ACK
] = fw4_ack
,
3092 [CPL_FW6_MSG
] = deferred_fw6_msg
,
3093 [CPL_RX_PKT
] = rx_pkt
3096 static void process_timeout(struct c4iw_ep
*ep
)
3098 struct c4iw_qp_attributes attrs
;
3101 mutex_lock(&ep
->com
.mutex
);
3102 PDBG("%s ep %p tid %u state %d\n", __func__
, ep
, ep
->hwtid
,
3104 set_bit(TIMEDOUT
, &ep
->com
.history
);
3105 switch (ep
->com
.state
) {
3107 __state_set(&ep
->com
, ABORTING
);
3108 connect_reply_upcall(ep
, -ETIMEDOUT
);
3111 __state_set(&ep
->com
, ABORTING
);
3115 if (ep
->com
.cm_id
&& ep
->com
.qp
) {
3116 attrs
.next_state
= C4IW_QP_STATE_ERROR
;
3117 c4iw_modify_qp(ep
->com
.qp
->rhp
,
3118 ep
->com
.qp
, C4IW_QP_ATTR_NEXT_STATE
,
3121 __state_set(&ep
->com
, ABORTING
);
3124 WARN(1, "%s unexpected state ep %p tid %u state %u\n",
3125 __func__
, ep
, ep
->hwtid
, ep
->com
.state
);
3128 mutex_unlock(&ep
->com
.mutex
);
3130 abort_connection(ep
, NULL
, GFP_KERNEL
);
3131 c4iw_put_ep(&ep
->com
);
3134 static void process_timedout_eps(void)
3138 spin_lock_irq(&timeout_lock
);
3139 while (!list_empty(&timeout_list
)) {
3140 struct list_head
*tmp
;
3142 tmp
= timeout_list
.next
;
3144 spin_unlock_irq(&timeout_lock
);
3145 ep
= list_entry(tmp
, struct c4iw_ep
, entry
);
3146 process_timeout(ep
);
3147 spin_lock_irq(&timeout_lock
);
3149 spin_unlock_irq(&timeout_lock
);
3152 static void process_work(struct work_struct
*work
)
3154 struct sk_buff
*skb
= NULL
;
3155 struct c4iw_dev
*dev
;
3156 struct cpl_act_establish
*rpl
;
3157 unsigned int opcode
;
3160 while ((skb
= skb_dequeue(&rxq
))) {
3162 dev
= *((struct c4iw_dev
**) (skb
->cb
+ sizeof(void *)));
3163 opcode
= rpl
->ot
.opcode
;
3165 BUG_ON(!work_handlers
[opcode
]);
3166 ret
= work_handlers
[opcode
](dev
, skb
);
3170 process_timedout_eps();
3173 static DECLARE_WORK(skb_work
, process_work
);
3175 static void ep_timeout(unsigned long arg
)
3177 struct c4iw_ep
*ep
= (struct c4iw_ep
*)arg
;
3179 spin_lock(&timeout_lock
);
3180 list_add_tail(&ep
->entry
, &timeout_list
);
3181 spin_unlock(&timeout_lock
);
3182 queue_work(workq
, &skb_work
);
3186 * All the CM events are handled on a work queue to have a safe context.
3188 static int sched(struct c4iw_dev
*dev
, struct sk_buff
*skb
)
3192 * Save dev in the skb->cb area.
3194 *((struct c4iw_dev
**) (skb
->cb
+ sizeof(void *))) = dev
;
3197 * Queue the skb and schedule the worker thread.
3199 skb_queue_tail(&rxq
, skb
);
3200 queue_work(workq
, &skb_work
);
3204 static int set_tcb_rpl(struct c4iw_dev
*dev
, struct sk_buff
*skb
)
3206 struct cpl_set_tcb_rpl
*rpl
= cplhdr(skb
);
3208 if (rpl
->status
!= CPL_ERR_NONE
) {
3209 printk(KERN_ERR MOD
"Unexpected SET_TCB_RPL status %u "
3210 "for tid %u\n", rpl
->status
, GET_TID(rpl
));
3216 static int fw6_msg(struct c4iw_dev
*dev
, struct sk_buff
*skb
)
3218 struct cpl_fw6_msg
*rpl
= cplhdr(skb
);
3219 struct c4iw_wr_wait
*wr_waitp
;
3222 PDBG("%s type %u\n", __func__
, rpl
->type
);
3224 switch (rpl
->type
) {
3225 case FW6_TYPE_WR_RPL
:
3226 ret
= (int)((be64_to_cpu(rpl
->data
[0]) >> 8) & 0xff);
3227 wr_waitp
= (struct c4iw_wr_wait
*)(__force
unsigned long) rpl
->data
[1];
3228 PDBG("%s wr_waitp %p ret %u\n", __func__
, wr_waitp
, ret
);
3230 c4iw_wake_up(wr_waitp
, ret
? -ret
: 0);
3234 case FW6_TYPE_OFLD_CONNECTION_WR_RPL
:
3238 printk(KERN_ERR MOD
"%s unexpected fw6 msg type %u\n", __func__
,
3246 static int peer_abort_intr(struct c4iw_dev
*dev
, struct sk_buff
*skb
)
3248 struct cpl_abort_req_rss
*req
= cplhdr(skb
);
3250 struct tid_info
*t
= dev
->rdev
.lldi
.tids
;
3251 unsigned int tid
= GET_TID(req
);
3253 ep
= lookup_tid(t
, tid
);
3255 printk(KERN_WARNING MOD
3256 "Abort on non-existent endpoint, tid %d\n", tid
);
3260 if (is_neg_adv_abort(req
->status
)) {
3261 PDBG("%s neg_adv_abort ep %p tid %u\n", __func__
, ep
,
3266 PDBG("%s ep %p tid %u state %u\n", __func__
, ep
, ep
->hwtid
,
3270 * Wake up any threads in rdma_init() or rdma_fini().
3272 c4iw_wake_up(&ep
->com
.wr_wait
, -ECONNRESET
);
3278 * Most upcalls from the T4 Core go to sched() to
3279 * schedule the processing on a work queue.
3281 c4iw_handler_func c4iw_handlers
[NUM_CPL_CMDS
] = {
3282 [CPL_ACT_ESTABLISH
] = sched
,
3283 [CPL_ACT_OPEN_RPL
] = sched
,
3284 [CPL_RX_DATA
] = sched
,
3285 [CPL_ABORT_RPL_RSS
] = sched
,
3286 [CPL_ABORT_RPL
] = sched
,
3287 [CPL_PASS_OPEN_RPL
] = sched
,
3288 [CPL_CLOSE_LISTSRV_RPL
] = sched
,
3289 [CPL_PASS_ACCEPT_REQ
] = sched
,
3290 [CPL_PASS_ESTABLISH
] = sched
,
3291 [CPL_PEER_CLOSE
] = sched
,
3292 [CPL_CLOSE_CON_RPL
] = sched
,
3293 [CPL_ABORT_REQ_RSS
] = peer_abort_intr
,
3294 [CPL_RDMA_TERMINATE
] = sched
,
3295 [CPL_FW4_ACK
] = sched
,
3296 [CPL_SET_TCB_RPL
] = set_tcb_rpl
,
3297 [CPL_FW6_MSG
] = fw6_msg
,
3298 [CPL_RX_PKT
] = sched
3301 int __init
c4iw_cm_init(void)
3303 spin_lock_init(&timeout_lock
);
3304 skb_queue_head_init(&rxq
);
3306 workq
= create_singlethread_workqueue("iw_cxgb4");
3313 void __exit
c4iw_cm_term(void)
3315 WARN_ON(!list_empty(&timeout_list
));
3316 flush_workqueue(workq
);
3317 destroy_workqueue(workq
);