Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1 | /* |
Steve Wise | 9eccfe1 | 2014-03-26 17:08:09 -0500 | [diff] [blame] | 2 | * Copyright (c) 2009-2014 Chelsio, Inc. All rights reserved. |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 3 | * |
| 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: |
| 9 | * |
| 10 | * Redistribution and use in source and binary forms, with or |
| 11 | * without modification, are permitted provided that the following |
| 12 | * conditions are met: |
| 13 | * |
| 14 | * - Redistributions of source code must retain the above |
| 15 | * copyright notice, this list of conditions and the following |
| 16 | * disclaimer. |
| 17 | * |
| 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. |
| 22 | * |
| 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 |
| 30 | * SOFTWARE. |
| 31 | */ |
| 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> |
| 39 | #include <linux/ip.h> |
| 40 | #include <linux/tcp.h> |
Vipul Pandya | 1cab775 | 2012-12-10 09:30:55 +0000 | [diff] [blame] | 41 | #include <linux/if_vlan.h> |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 42 | |
| 43 | #include <net/neighbour.h> |
| 44 | #include <net/netevent.h> |
| 45 | #include <net/route.h> |
Vipul Pandya | 1cab775 | 2012-12-10 09:30:55 +0000 | [diff] [blame] | 46 | #include <net/tcp.h> |
Vipul Pandya | 830662f | 2013-07-04 16:10:47 +0530 | [diff] [blame] | 47 | #include <net/ip6_route.h> |
| 48 | #include <net/addrconf.h> |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 49 | |
Steve Wise | 11b8e22 | 2014-05-16 12:42:46 -0500 | [diff] [blame] | 50 | #include <rdma/ib_addr.h> |
| 51 | |
Varun Prakash | 85e42b0 | 2016-09-13 21:23:56 +0530 | [diff] [blame] | 52 | #include <libcxgb_cm.h> |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 53 | #include "iw_cxgb4.h" |
Hariprasad S | 84cc6ac6 | 2015-08-25 14:08:23 +0530 | [diff] [blame] | 54 | #include "clip_tbl.h" |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 55 | |
| 56 | static char *states[] = { |
| 57 | "idle", |
| 58 | "listen", |
| 59 | "connecting", |
| 60 | "mpa_wait_req", |
| 61 | "mpa_req_sent", |
| 62 | "mpa_req_rcvd", |
| 63 | "mpa_rep_sent", |
| 64 | "fpdu_mode", |
| 65 | "aborting", |
| 66 | "closing", |
| 67 | "moribund", |
| 68 | "dead", |
| 69 | NULL, |
| 70 | }; |
| 71 | |
Vipul Pandya | 5be78ee | 2012-12-10 09:30:54 +0000 | [diff] [blame] | 72 | static int nocong; |
| 73 | module_param(nocong, int, 0644); |
| 74 | MODULE_PARM_DESC(nocong, "Turn of congestion control (default=0)"); |
| 75 | |
| 76 | static int enable_ecn; |
| 77 | module_param(enable_ecn, int, 0644); |
| 78 | MODULE_PARM_DESC(enable_ecn, "Enable ECN (default=0/disabled)"); |
| 79 | |
Steve Wise | b52fe09 | 2011-03-11 22:30:01 +0000 | [diff] [blame] | 80 | static int dack_mode = 1; |
Steve Wise | ba6d392 | 2010-06-23 15:46:49 +0000 | [diff] [blame] | 81 | module_param(dack_mode, int, 0644); |
Steve Wise | b52fe09 | 2011-03-11 22:30:01 +0000 | [diff] [blame] | 82 | MODULE_PARM_DESC(dack_mode, "Delayed ack mode (default=1)"); |
Steve Wise | ba6d392 | 2010-06-23 15:46:49 +0000 | [diff] [blame] | 83 | |
Hariprasad Shenai | 4c2c576 | 2014-07-14 21:34:52 +0530 | [diff] [blame] | 84 | uint c4iw_max_read_depth = 32; |
Roland Dreier | be4c9ba | 2010-05-05 14:45:40 -0700 | [diff] [blame] | 85 | module_param(c4iw_max_read_depth, int, 0644); |
Hariprasad Shenai | 4c2c576 | 2014-07-14 21:34:52 +0530 | [diff] [blame] | 86 | MODULE_PARM_DESC(c4iw_max_read_depth, |
| 87 | "Per-connection max ORD/IRD (default=32)"); |
Roland Dreier | be4c9ba | 2010-05-05 14:45:40 -0700 | [diff] [blame] | 88 | |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 89 | static int enable_tcp_timestamps; |
| 90 | module_param(enable_tcp_timestamps, int, 0644); |
| 91 | MODULE_PARM_DESC(enable_tcp_timestamps, "Enable tcp timestamps (default=0)"); |
| 92 | |
| 93 | static int enable_tcp_sack; |
| 94 | module_param(enable_tcp_sack, int, 0644); |
| 95 | MODULE_PARM_DESC(enable_tcp_sack, "Enable tcp SACK (default=0)"); |
| 96 | |
| 97 | static int enable_tcp_window_scaling = 1; |
| 98 | module_param(enable_tcp_window_scaling, int, 0644); |
| 99 | MODULE_PARM_DESC(enable_tcp_window_scaling, |
| 100 | "Enable tcp window scaling (default=1)"); |
| 101 | |
| 102 | int c4iw_debug; |
| 103 | module_param(c4iw_debug, int, 0644); |
| 104 | MODULE_PARM_DESC(c4iw_debug, "Enable debug logging (default=0)"); |
| 105 | |
Steve Wise | df2d513 | 2014-03-19 17:44:44 +0530 | [diff] [blame] | 106 | static int peer2peer = 1; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 107 | module_param(peer2peer, int, 0644); |
Steve Wise | df2d513 | 2014-03-19 17:44:44 +0530 | [diff] [blame] | 108 | MODULE_PARM_DESC(peer2peer, "Support peer2peer ULPs (default=1)"); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 109 | |
| 110 | static int p2p_type = FW_RI_INIT_P2PTYPE_READ_REQ; |
| 111 | module_param(p2p_type, int, 0644); |
| 112 | MODULE_PARM_DESC(p2p_type, "RDMAP opcode to use for the RTR message: " |
| 113 | "1=RDMA_READ 0=RDMA_WRITE (default 1)"); |
| 114 | |
| 115 | static int ep_timeout_secs = 60; |
| 116 | module_param(ep_timeout_secs, int, 0644); |
| 117 | MODULE_PARM_DESC(ep_timeout_secs, "CM Endpoint operation timeout " |
| 118 | "in seconds (default=60)"); |
| 119 | |
Hariprasad S | b8ac311 | 2015-07-27 14:08:52 +0530 | [diff] [blame] | 120 | static int mpa_rev = 2; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 121 | module_param(mpa_rev, int, 0644); |
| 122 | MODULE_PARM_DESC(mpa_rev, "MPA Revision, 0 supports amso1100, " |
Hariprasad S | ccd2c30 | 2016-05-06 22:17:55 +0530 | [diff] [blame] | 123 | "1 is RFC5044 spec compliant, 2 is IETF MPA Peer Connect Draft" |
Hariprasad S | b8ac311 | 2015-07-27 14:08:52 +0530 | [diff] [blame] | 124 | " compliant (default=2)"); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 125 | |
| 126 | static int markers_enabled; |
| 127 | module_param(markers_enabled, int, 0644); |
| 128 | MODULE_PARM_DESC(markers_enabled, "Enable MPA MARKERS (default(0)=disabled)"); |
| 129 | |
| 130 | static int crc_enabled = 1; |
| 131 | module_param(crc_enabled, int, 0644); |
| 132 | MODULE_PARM_DESC(crc_enabled, "Enable MPA CRC (default(1)=enabled)"); |
| 133 | |
| 134 | static int rcv_win = 256 * 1024; |
| 135 | module_param(rcv_win, int, 0644); |
| 136 | MODULE_PARM_DESC(rcv_win, "TCP receive window in bytes (default=256KB)"); |
| 137 | |
Steve Wise | 98ae68b | 2010-09-10 11:15:41 -0500 | [diff] [blame] | 138 | static int snd_win = 128 * 1024; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 139 | module_param(snd_win, int, 0644); |
Steve Wise | 98ae68b | 2010-09-10 11:15:41 -0500 | [diff] [blame] | 140 | MODULE_PARM_DESC(snd_win, "TCP send window in bytes (default=128KB)"); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 141 | |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 142 | static struct workqueue_struct *workq; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 143 | |
| 144 | static struct sk_buff_head rxq; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 145 | |
| 146 | static struct sk_buff *get_skb(struct sk_buff *skb, int len, gfp_t gfp); |
| 147 | static void ep_timeout(unsigned long arg); |
| 148 | static void connect_reply_upcall(struct c4iw_ep *ep, int status); |
Hariprasad S | 9dec900 | 2016-05-05 01:27:29 +0530 | [diff] [blame] | 149 | static int sched(struct c4iw_dev *dev, struct sk_buff *skb); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 150 | |
Roland Dreier | be4c9ba | 2010-05-05 14:45:40 -0700 | [diff] [blame] | 151 | static LIST_HEAD(timeout_list); |
| 152 | static spinlock_t timeout_lock; |
| 153 | |
Hariprasad S | 9ca6f7c | 2016-05-06 22:17:54 +0530 | [diff] [blame] | 154 | static void deref_cm_id(struct c4iw_ep_common *epc) |
| 155 | { |
| 156 | epc->cm_id->rem_ref(epc->cm_id); |
| 157 | epc->cm_id = NULL; |
| 158 | set_bit(CM_ID_DEREFED, &epc->history); |
| 159 | } |
| 160 | |
| 161 | static void ref_cm_id(struct c4iw_ep_common *epc) |
| 162 | { |
| 163 | set_bit(CM_ID_REFED, &epc->history); |
| 164 | epc->cm_id->add_ref(epc->cm_id); |
| 165 | } |
| 166 | |
Vipul Pandya | 325abea | 2013-01-07 13:11:53 +0000 | [diff] [blame] | 167 | static void deref_qp(struct c4iw_ep *ep) |
| 168 | { |
| 169 | c4iw_qp_rem_ref(&ep->com.qp->ibqp); |
| 170 | clear_bit(QP_REFERENCED, &ep->com.flags); |
Hariprasad S | 9ca6f7c | 2016-05-06 22:17:54 +0530 | [diff] [blame] | 171 | set_bit(QP_DEREFED, &ep->com.history); |
Vipul Pandya | 325abea | 2013-01-07 13:11:53 +0000 | [diff] [blame] | 172 | } |
| 173 | |
| 174 | static void ref_qp(struct c4iw_ep *ep) |
| 175 | { |
| 176 | set_bit(QP_REFERENCED, &ep->com.flags); |
Hariprasad S | 9ca6f7c | 2016-05-06 22:17:54 +0530 | [diff] [blame] | 177 | set_bit(QP_REFED, &ep->com.history); |
Vipul Pandya | 325abea | 2013-01-07 13:11:53 +0000 | [diff] [blame] | 178 | c4iw_qp_add_ref(&ep->com.qp->ibqp); |
| 179 | } |
| 180 | |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 181 | static void start_ep_timer(struct c4iw_ep *ep) |
| 182 | { |
| 183 | PDBG("%s ep %p\n", __func__, ep); |
| 184 | if (timer_pending(&ep->timer)) { |
Vipul Pandya | 1ec779c | 2013-01-07 13:11:56 +0000 | [diff] [blame] | 185 | pr_err("%s timer already started! ep %p\n", |
| 186 | __func__, ep); |
| 187 | return; |
| 188 | } |
| 189 | clear_bit(TIMEOUT, &ep->com.flags); |
| 190 | c4iw_get_ep(&ep->com); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 191 | ep->timer.expires = jiffies + ep_timeout_secs * HZ; |
| 192 | ep->timer.data = (unsigned long)ep; |
| 193 | ep->timer.function = ep_timeout; |
| 194 | add_timer(&ep->timer); |
| 195 | } |
| 196 | |
Steve Wise | b33bd0c | 2014-04-09 09:38:25 -0500 | [diff] [blame] | 197 | static int stop_ep_timer(struct c4iw_ep *ep) |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 198 | { |
Vipul Pandya | 1ec779c | 2013-01-07 13:11:56 +0000 | [diff] [blame] | 199 | PDBG("%s ep %p stopping\n", __func__, ep); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 200 | del_timer_sync(&ep->timer); |
Steve Wise | b33bd0c | 2014-04-09 09:38:25 -0500 | [diff] [blame] | 201 | if (!test_and_set_bit(TIMEOUT, &ep->com.flags)) { |
Vipul Pandya | 1ec779c | 2013-01-07 13:11:56 +0000 | [diff] [blame] | 202 | c4iw_put_ep(&ep->com); |
Steve Wise | b33bd0c | 2014-04-09 09:38:25 -0500 | [diff] [blame] | 203 | return 0; |
| 204 | } |
| 205 | return 1; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 206 | } |
| 207 | |
| 208 | static int c4iw_l2t_send(struct c4iw_rdev *rdev, struct sk_buff *skb, |
| 209 | struct l2t_entry *l2e) |
| 210 | { |
| 211 | int error = 0; |
| 212 | |
| 213 | if (c4iw_fatal_error(rdev)) { |
| 214 | kfree_skb(skb); |
| 215 | PDBG("%s - device in error state - dropping\n", __func__); |
| 216 | return -EIO; |
| 217 | } |
| 218 | error = cxgb4_l2t_send(rdev->lldi.ports[0], skb, l2e); |
| 219 | if (error < 0) |
| 220 | kfree_skb(skb); |
Hariprasad S | caa6c9f | 2016-05-06 22:18:00 +0530 | [diff] [blame] | 221 | else if (error == NET_XMIT_DROP) |
| 222 | return -ENOMEM; |
Steve Wise | 7459486 | 2010-09-10 11:14:58 -0500 | [diff] [blame] | 223 | return error < 0 ? error : 0; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 224 | } |
| 225 | |
| 226 | int c4iw_ofld_send(struct c4iw_rdev *rdev, struct sk_buff *skb) |
| 227 | { |
| 228 | int error = 0; |
| 229 | |
| 230 | if (c4iw_fatal_error(rdev)) { |
| 231 | kfree_skb(skb); |
| 232 | PDBG("%s - device in error state - dropping\n", __func__); |
| 233 | return -EIO; |
| 234 | } |
| 235 | error = cxgb4_ofld_send(rdev->lldi.ports[0], skb); |
| 236 | if (error < 0) |
| 237 | kfree_skb(skb); |
Steve Wise | 7459486 | 2010-09-10 11:14:58 -0500 | [diff] [blame] | 238 | return error < 0 ? error : 0; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 239 | } |
| 240 | |
| 241 | static void release_tid(struct c4iw_rdev *rdev, u32 hwtid, struct sk_buff *skb) |
| 242 | { |
Varun Prakash | a1a2345 | 2016-09-13 21:24:02 +0530 | [diff] [blame^] | 243 | u32 len = roundup(sizeof(struct cpl_tid_release), 16); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 244 | |
Varun Prakash | a1a2345 | 2016-09-13 21:24:02 +0530 | [diff] [blame^] | 245 | skb = get_skb(skb, len, GFP_KERNEL); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 246 | if (!skb) |
| 247 | return; |
Varun Prakash | a1a2345 | 2016-09-13 21:24:02 +0530 | [diff] [blame^] | 248 | |
| 249 | cxgb_mk_tid_release(skb, len, hwtid, 0); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 250 | c4iw_ofld_send(rdev, skb); |
| 251 | return; |
| 252 | } |
| 253 | |
| 254 | static void set_emss(struct c4iw_ep *ep, u16 opt) |
| 255 | { |
Hariprasad Shenai | 6c53e93 | 2015-01-08 21:38:15 -0800 | [diff] [blame] | 256 | ep->emss = ep->com.dev->rdev.lldi.mtus[TCPOPT_MSS_G(opt)] - |
Hariprasad S | 04524a4 | 2014-09-24 03:53:41 +0530 | [diff] [blame] | 257 | ((AF_INET == ep->com.remote_addr.ss_family) ? |
| 258 | sizeof(struct iphdr) : sizeof(struct ipv6hdr)) - |
| 259 | sizeof(struct tcphdr); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 260 | ep->mss = ep->emss; |
Hariprasad Shenai | 6c53e93 | 2015-01-08 21:38:15 -0800 | [diff] [blame] | 261 | if (TCPOPT_TSTAMP_G(opt)) |
Hariprasad S | 04524a4 | 2014-09-24 03:53:41 +0530 | [diff] [blame] | 262 | ep->emss -= round_up(TCPOLEN_TIMESTAMP, 4); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 263 | if (ep->emss < 128) |
| 264 | ep->emss = 128; |
Hariprasad Shenai | 92e7ae7 | 2014-06-06 21:40:43 +0530 | [diff] [blame] | 265 | if (ep->emss & 7) |
| 266 | PDBG("Warning: misaligned mtu idx %u mss %u emss=%u\n", |
Hariprasad Shenai | 6c53e93 | 2015-01-08 21:38:15 -0800 | [diff] [blame] | 267 | TCPOPT_MSS_G(opt), ep->mss, ep->emss); |
| 268 | PDBG("%s mss_idx %u mss %u emss=%u\n", __func__, TCPOPT_MSS_G(opt), |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 269 | ep->mss, ep->emss); |
| 270 | } |
| 271 | |
| 272 | static enum c4iw_ep_state state_read(struct c4iw_ep_common *epc) |
| 273 | { |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 274 | enum c4iw_ep_state state; |
| 275 | |
Steve Wise | 2f5b48c | 2010-09-10 11:15:36 -0500 | [diff] [blame] | 276 | mutex_lock(&epc->mutex); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 277 | state = epc->state; |
Steve Wise | 2f5b48c | 2010-09-10 11:15:36 -0500 | [diff] [blame] | 278 | mutex_unlock(&epc->mutex); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 279 | return state; |
| 280 | } |
| 281 | |
| 282 | static void __state_set(struct c4iw_ep_common *epc, enum c4iw_ep_state new) |
| 283 | { |
| 284 | epc->state = new; |
| 285 | } |
| 286 | |
| 287 | static void state_set(struct c4iw_ep_common *epc, enum c4iw_ep_state new) |
| 288 | { |
Steve Wise | 2f5b48c | 2010-09-10 11:15:36 -0500 | [diff] [blame] | 289 | mutex_lock(&epc->mutex); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 290 | PDBG("%s - %s -> %s\n", __func__, states[epc->state], states[new]); |
| 291 | __state_set(epc, new); |
Steve Wise | 2f5b48c | 2010-09-10 11:15:36 -0500 | [diff] [blame] | 292 | mutex_unlock(&epc->mutex); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 293 | return; |
| 294 | } |
| 295 | |
Hariprasad S | 4a74083 | 2016-06-10 01:05:15 +0530 | [diff] [blame] | 296 | static int alloc_ep_skb_list(struct sk_buff_head *ep_skb_list, int size) |
| 297 | { |
| 298 | struct sk_buff *skb; |
| 299 | unsigned int i; |
| 300 | size_t len; |
| 301 | |
| 302 | len = roundup(sizeof(union cpl_wr_size), 16); |
| 303 | for (i = 0; i < size; i++) { |
| 304 | skb = alloc_skb(len, GFP_KERNEL); |
| 305 | if (!skb) |
| 306 | goto fail; |
| 307 | skb_queue_tail(ep_skb_list, skb); |
| 308 | } |
| 309 | return 0; |
| 310 | fail: |
| 311 | skb_queue_purge(ep_skb_list); |
| 312 | return -ENOMEM; |
| 313 | } |
| 314 | |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 315 | static void *alloc_ep(int size, gfp_t gfp) |
| 316 | { |
| 317 | struct c4iw_ep_common *epc; |
| 318 | |
| 319 | epc = kzalloc(size, gfp); |
| 320 | if (epc) { |
| 321 | kref_init(&epc->kref); |
Steve Wise | 2f5b48c | 2010-09-10 11:15:36 -0500 | [diff] [blame] | 322 | mutex_init(&epc->mutex); |
Steve Wise | aadc4df | 2010-09-10 11:15:25 -0500 | [diff] [blame] | 323 | c4iw_init_wr_wait(&epc->wr_wait); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 324 | } |
| 325 | PDBG("%s alloc ep %p\n", __func__, epc); |
| 326 | return epc; |
| 327 | } |
| 328 | |
Hariprasad S | 944661d | 2016-05-06 22:18:03 +0530 | [diff] [blame] | 329 | static void remove_ep_tid(struct c4iw_ep *ep) |
| 330 | { |
| 331 | unsigned long flags; |
| 332 | |
| 333 | spin_lock_irqsave(&ep->com.dev->lock, flags); |
| 334 | _remove_handle(ep->com.dev, &ep->com.dev->hwtid_idr, ep->hwtid, 0); |
| 335 | spin_unlock_irqrestore(&ep->com.dev->lock, flags); |
| 336 | } |
| 337 | |
| 338 | static void insert_ep_tid(struct c4iw_ep *ep) |
| 339 | { |
| 340 | unsigned long flags; |
| 341 | |
| 342 | spin_lock_irqsave(&ep->com.dev->lock, flags); |
| 343 | _insert_handle(ep->com.dev, &ep->com.dev->hwtid_idr, ep, ep->hwtid, 0); |
| 344 | spin_unlock_irqrestore(&ep->com.dev->lock, flags); |
| 345 | } |
| 346 | |
| 347 | /* |
| 348 | * Atomically lookup the ep ptr given the tid and grab a reference on the ep. |
| 349 | */ |
| 350 | static struct c4iw_ep *get_ep_from_tid(struct c4iw_dev *dev, unsigned int tid) |
| 351 | { |
| 352 | struct c4iw_ep *ep; |
| 353 | unsigned long flags; |
| 354 | |
| 355 | spin_lock_irqsave(&dev->lock, flags); |
| 356 | ep = idr_find(&dev->hwtid_idr, tid); |
| 357 | if (ep) |
| 358 | c4iw_get_ep(&ep->com); |
| 359 | spin_unlock_irqrestore(&dev->lock, flags); |
| 360 | return ep; |
| 361 | } |
| 362 | |
Hariprasad S | f86fac7 | 2016-05-06 22:18:07 +0530 | [diff] [blame] | 363 | /* |
| 364 | * Atomically lookup the ep ptr given the stid and grab a reference on the ep. |
| 365 | */ |
| 366 | static struct c4iw_listen_ep *get_ep_from_stid(struct c4iw_dev *dev, |
| 367 | unsigned int stid) |
| 368 | { |
| 369 | struct c4iw_listen_ep *ep; |
| 370 | unsigned long flags; |
| 371 | |
| 372 | spin_lock_irqsave(&dev->lock, flags); |
| 373 | ep = idr_find(&dev->stid_idr, stid); |
| 374 | if (ep) |
| 375 | c4iw_get_ep(&ep->com); |
| 376 | spin_unlock_irqrestore(&dev->lock, flags); |
| 377 | return ep; |
| 378 | } |
| 379 | |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 380 | void _c4iw_free_ep(struct kref *kref) |
| 381 | { |
| 382 | struct c4iw_ep *ep; |
| 383 | |
| 384 | ep = container_of(kref, struct c4iw_ep, com.kref); |
Hariprasad S | 9dec900 | 2016-05-05 01:27:29 +0530 | [diff] [blame] | 385 | PDBG("%s ep %p state %s\n", __func__, ep, states[ep->com.state]); |
Vipul Pandya | 325abea | 2013-01-07 13:11:53 +0000 | [diff] [blame] | 386 | if (test_bit(QP_REFERENCED, &ep->com.flags)) |
| 387 | deref_qp(ep); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 388 | if (test_bit(RELEASE_RESOURCES, &ep->com.flags)) { |
Hariprasad S | 84cc6ac6 | 2015-08-25 14:08:23 +0530 | [diff] [blame] | 389 | if (ep->com.remote_addr.ss_family == AF_INET6) { |
| 390 | struct sockaddr_in6 *sin6 = |
| 391 | (struct sockaddr_in6 *) |
Steve Wise | 170003c | 2016-02-26 09:18:03 -0600 | [diff] [blame] | 392 | &ep->com.local_addr; |
Hariprasad S | 84cc6ac6 | 2015-08-25 14:08:23 +0530 | [diff] [blame] | 393 | |
| 394 | cxgb4_clip_release( |
| 395 | ep->com.dev->rdev.lldi.ports[0], |
| 396 | (const u32 *)&sin6->sin6_addr.s6_addr, |
| 397 | 1); |
| 398 | } |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 399 | cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, ep->hwtid); |
| 400 | dst_release(ep->dst); |
| 401 | cxgb4_l2t_release(ep->l2t); |
Hariprasad S | c878b70 | 2016-05-06 22:18:04 +0530 | [diff] [blame] | 402 | if (ep->mpa_skb) |
| 403 | kfree_skb(ep->mpa_skb); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 404 | } |
Hariprasad S | 4a74083 | 2016-06-10 01:05:15 +0530 | [diff] [blame] | 405 | if (!skb_queue_empty(&ep->com.ep_skb_list)) |
| 406 | skb_queue_purge(&ep->com.ep_skb_list); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 407 | kfree(ep); |
| 408 | } |
| 409 | |
| 410 | static void release_ep_resources(struct c4iw_ep *ep) |
| 411 | { |
| 412 | set_bit(RELEASE_RESOURCES, &ep->com.flags); |
Hariprasad S | 944661d | 2016-05-06 22:18:03 +0530 | [diff] [blame] | 413 | |
| 414 | /* |
| 415 | * If we have a hwtid, then remove it from the idr table |
| 416 | * so lookups will no longer find this endpoint. Otherwise |
| 417 | * we have a race where one thread finds the ep ptr just |
| 418 | * before the other thread is freeing the ep memory. |
| 419 | */ |
| 420 | if (ep->hwtid != -1) |
| 421 | remove_ep_tid(ep); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 422 | c4iw_put_ep(&ep->com); |
| 423 | } |
| 424 | |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 425 | static int status2errno(int status) |
| 426 | { |
| 427 | switch (status) { |
| 428 | case CPL_ERR_NONE: |
| 429 | return 0; |
| 430 | case CPL_ERR_CONN_RESET: |
| 431 | return -ECONNRESET; |
| 432 | case CPL_ERR_ARP_MISS: |
| 433 | return -EHOSTUNREACH; |
| 434 | case CPL_ERR_CONN_TIMEDOUT: |
| 435 | return -ETIMEDOUT; |
| 436 | case CPL_ERR_TCAM_FULL: |
| 437 | return -ENOMEM; |
| 438 | case CPL_ERR_CONN_EXIST: |
| 439 | return -EADDRINUSE; |
| 440 | default: |
| 441 | return -EIO; |
| 442 | } |
| 443 | } |
| 444 | |
| 445 | /* |
| 446 | * Try and reuse skbs already allocated... |
| 447 | */ |
| 448 | static struct sk_buff *get_skb(struct sk_buff *skb, int len, gfp_t gfp) |
| 449 | { |
| 450 | if (skb && !skb_is_nonlinear(skb) && !skb_cloned(skb)) { |
| 451 | skb_trim(skb, 0); |
| 452 | skb_get(skb); |
| 453 | skb_reset_transport_header(skb); |
| 454 | } else { |
| 455 | skb = alloc_skb(len, gfp); |
| 456 | } |
Steve Wise | b38a0ad | 2013-08-06 21:04:37 +0530 | [diff] [blame] | 457 | t4_set_arp_err_handler(skb, NULL, NULL); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 458 | return skb; |
| 459 | } |
| 460 | |
Vipul Pandya | 830662f | 2013-07-04 16:10:47 +0530 | [diff] [blame] | 461 | static struct net_device *get_real_dev(struct net_device *egress_dev) |
| 462 | { |
Steve Wise | 11b8e22 | 2014-05-16 12:42:46 -0500 | [diff] [blame] | 463 | return rdma_vlan_dev_real_dev(egress_dev) ? : egress_dev; |
Vipul Pandya | 830662f | 2013-07-04 16:10:47 +0530 | [diff] [blame] | 464 | } |
| 465 | |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 466 | static void arp_failure_discard(void *handle, struct sk_buff *skb) |
| 467 | { |
Hariprasad S | 9dec900 | 2016-05-05 01:27:29 +0530 | [diff] [blame] | 468 | pr_err(MOD "ARP failure\n"); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 469 | kfree_skb(skb); |
| 470 | } |
| 471 | |
Hariprasad S | 64bec74 | 2016-05-06 22:18:10 +0530 | [diff] [blame] | 472 | static void mpa_start_arp_failure(void *handle, struct sk_buff *skb) |
| 473 | { |
| 474 | pr_err("ARP failure during MPA Negotiation - Closing Connection\n"); |
| 475 | } |
| 476 | |
Hariprasad S | 9dec900 | 2016-05-05 01:27:29 +0530 | [diff] [blame] | 477 | enum { |
Hariprasad S | 8d1f1a6 | 2016-05-06 22:17:57 +0530 | [diff] [blame] | 478 | NUM_FAKE_CPLS = 2, |
Hariprasad S | 9dec900 | 2016-05-05 01:27:29 +0530 | [diff] [blame] | 479 | FAKE_CPL_PUT_EP_SAFE = NUM_CPL_CMDS + 0, |
Hariprasad S | 8d1f1a6 | 2016-05-06 22:17:57 +0530 | [diff] [blame] | 480 | FAKE_CPL_PASS_PUT_EP_SAFE = NUM_CPL_CMDS + 1, |
Hariprasad S | 9dec900 | 2016-05-05 01:27:29 +0530 | [diff] [blame] | 481 | }; |
| 482 | |
| 483 | static int _put_ep_safe(struct c4iw_dev *dev, struct sk_buff *skb) |
| 484 | { |
| 485 | struct c4iw_ep *ep; |
| 486 | |
| 487 | ep = *((struct c4iw_ep **)(skb->cb + 2 * sizeof(void *))); |
| 488 | release_ep_resources(ep); |
| 489 | return 0; |
| 490 | } |
| 491 | |
Hariprasad S | 8d1f1a6 | 2016-05-06 22:17:57 +0530 | [diff] [blame] | 492 | static int _put_pass_ep_safe(struct c4iw_dev *dev, struct sk_buff *skb) |
| 493 | { |
| 494 | struct c4iw_ep *ep; |
| 495 | |
| 496 | ep = *((struct c4iw_ep **)(skb->cb + 2 * sizeof(void *))); |
| 497 | c4iw_put_ep(&ep->parent_ep->com); |
| 498 | release_ep_resources(ep); |
| 499 | return 0; |
| 500 | } |
| 501 | |
Hariprasad S | 9dec900 | 2016-05-05 01:27:29 +0530 | [diff] [blame] | 502 | /* |
| 503 | * Fake up a special CPL opcode and call sched() so process_work() will call |
| 504 | * _put_ep_safe() in a safe context to free the ep resources. This is needed |
| 505 | * because ARP error handlers are called in an ATOMIC context, and |
| 506 | * _c4iw_free_ep() needs to block. |
| 507 | */ |
Hariprasad S | 8d1f1a6 | 2016-05-06 22:17:57 +0530 | [diff] [blame] | 508 | static void queue_arp_failure_cpl(struct c4iw_ep *ep, struct sk_buff *skb, |
| 509 | int cpl) |
Hariprasad S | 9dec900 | 2016-05-05 01:27:29 +0530 | [diff] [blame] | 510 | { |
| 511 | struct cpl_act_establish *rpl = cplhdr(skb); |
| 512 | |
| 513 | /* Set our special ARP_FAILURE opcode */ |
Hariprasad S | 8d1f1a6 | 2016-05-06 22:17:57 +0530 | [diff] [blame] | 514 | rpl->ot.opcode = cpl; |
Hariprasad S | 9dec900 | 2016-05-05 01:27:29 +0530 | [diff] [blame] | 515 | |
| 516 | /* |
| 517 | * Save ep in the skb->cb area, after where sched() will save the dev |
| 518 | * ptr. |
| 519 | */ |
| 520 | *((struct c4iw_ep **)(skb->cb + 2 * sizeof(void *))) = ep; |
| 521 | sched(ep->com.dev, skb); |
| 522 | } |
| 523 | |
| 524 | /* Handle an ARP failure for an accept */ |
| 525 | static void pass_accept_rpl_arp_failure(void *handle, struct sk_buff *skb) |
| 526 | { |
| 527 | struct c4iw_ep *ep = handle; |
| 528 | |
| 529 | pr_err(MOD "ARP failure during accept - tid %u -dropping connection\n", |
| 530 | ep->hwtid); |
| 531 | |
| 532 | __state_set(&ep->com, DEAD); |
Hariprasad S | 8d1f1a6 | 2016-05-06 22:17:57 +0530 | [diff] [blame] | 533 | queue_arp_failure_cpl(ep, skb, FAKE_CPL_PASS_PUT_EP_SAFE); |
Hariprasad S | 9dec900 | 2016-05-05 01:27:29 +0530 | [diff] [blame] | 534 | } |
| 535 | |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 536 | /* |
| 537 | * Handle an ARP failure for an active open. |
| 538 | */ |
| 539 | static void act_open_req_arp_failure(void *handle, struct sk_buff *skb) |
| 540 | { |
Hariprasad S | 5dab6d3 | 2014-06-23 19:12:36 +0530 | [diff] [blame] | 541 | struct c4iw_ep *ep = handle; |
| 542 | |
Masanari Iida | e3d132d | 2015-10-16 21:14:29 +0900 | [diff] [blame] | 543 | printk(KERN_ERR MOD "ARP failure during connect\n"); |
Hariprasad S | 5dab6d3 | 2014-06-23 19:12:36 +0530 | [diff] [blame] | 544 | connect_reply_upcall(ep, -EHOSTUNREACH); |
Hariprasad S | 9dec900 | 2016-05-05 01:27:29 +0530 | [diff] [blame] | 545 | __state_set(&ep->com, DEAD); |
Hariprasad S | 84cc6ac6 | 2015-08-25 14:08:23 +0530 | [diff] [blame] | 546 | if (ep->com.remote_addr.ss_family == AF_INET6) { |
| 547 | struct sockaddr_in6 *sin6 = |
Steve Wise | 170003c | 2016-02-26 09:18:03 -0600 | [diff] [blame] | 548 | (struct sockaddr_in6 *)&ep->com.local_addr; |
Hariprasad S | 84cc6ac6 | 2015-08-25 14:08:23 +0530 | [diff] [blame] | 549 | cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0], |
| 550 | (const u32 *)&sin6->sin6_addr.s6_addr, 1); |
| 551 | } |
Hariprasad S | 5dab6d3 | 2014-06-23 19:12:36 +0530 | [diff] [blame] | 552 | remove_handle(ep->com.dev, &ep->com.dev->atid_idr, ep->atid); |
| 553 | cxgb4_free_atid(ep->com.dev->rdev.lldi.tids, ep->atid); |
Hariprasad S | 8d1f1a6 | 2016-05-06 22:17:57 +0530 | [diff] [blame] | 554 | queue_arp_failure_cpl(ep, skb, FAKE_CPL_PUT_EP_SAFE); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 555 | } |
| 556 | |
| 557 | /* |
| 558 | * Handle an ARP failure for a CPL_ABORT_REQ. Change it into a no RST variant |
| 559 | * and send it along. |
| 560 | */ |
| 561 | static void abort_arp_failure(void *handle, struct sk_buff *skb) |
| 562 | { |
Hariprasad S | 761e19a | 2016-05-06 22:18:02 +0530 | [diff] [blame] | 563 | int ret; |
| 564 | struct c4iw_ep *ep = handle; |
| 565 | struct c4iw_rdev *rdev = &ep->com.dev->rdev; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 566 | struct cpl_abort_req *req = cplhdr(skb); |
| 567 | |
| 568 | PDBG("%s rdev %p\n", __func__, rdev); |
| 569 | req->cmd = CPL_ABORT_NO_RST; |
Hariprasad S | 761e19a | 2016-05-06 22:18:02 +0530 | [diff] [blame] | 570 | ret = c4iw_ofld_send(rdev, skb); |
| 571 | if (ret) { |
| 572 | __state_set(&ep->com, DEAD); |
| 573 | queue_arp_failure_cpl(ep, skb, FAKE_CPL_PUT_EP_SAFE); |
| 574 | } |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 575 | } |
| 576 | |
Hariprasad S | 4a74083 | 2016-06-10 01:05:15 +0530 | [diff] [blame] | 577 | static int send_flowc(struct c4iw_ep *ep) |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 578 | { |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 579 | struct fw_flowc_wr *flowc; |
Hariprasad S | 4a74083 | 2016-06-10 01:05:15 +0530 | [diff] [blame] | 580 | struct sk_buff *skb = skb_dequeue(&ep->com.ep_skb_list); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 581 | int i; |
Hariprasad S | ac8e4c6 | 2016-02-05 11:43:30 +0530 | [diff] [blame] | 582 | u16 vlan = ep->l2t->vlan; |
| 583 | int nparams; |
| 584 | |
Hariprasad S | 4a74083 | 2016-06-10 01:05:15 +0530 | [diff] [blame] | 585 | if (WARN_ON(!skb)) |
| 586 | return -ENOMEM; |
| 587 | |
Hariprasad S | ac8e4c6 | 2016-02-05 11:43:30 +0530 | [diff] [blame] | 588 | if (vlan == CPL_L2T_VLAN_NONE) |
| 589 | nparams = 8; |
| 590 | else |
| 591 | nparams = 9; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 592 | |
Hariprasad S | 4a74083 | 2016-06-10 01:05:15 +0530 | [diff] [blame] | 593 | flowc = (struct fw_flowc_wr *)__skb_put(skb, FLOWC_LEN); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 594 | |
Hariprasad Shenai | e2ac962 | 2014-11-07 09:35:25 +0530 | [diff] [blame] | 595 | flowc->op_to_nparams = cpu_to_be32(FW_WR_OP_V(FW_FLOWC_WR) | |
Hariprasad S | ac8e4c6 | 2016-02-05 11:43:30 +0530 | [diff] [blame] | 596 | FW_FLOWC_WR_NPARAMS_V(nparams)); |
Hariprasad S | 4a74083 | 2016-06-10 01:05:15 +0530 | [diff] [blame] | 597 | flowc->flowid_len16 = cpu_to_be32(FW_WR_LEN16_V(DIV_ROUND_UP(FLOWC_LEN, |
Hariprasad Shenai | e2ac962 | 2014-11-07 09:35:25 +0530 | [diff] [blame] | 598 | 16)) | FW_WR_FLOWID_V(ep->hwtid)); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 599 | |
| 600 | flowc->mnemval[0].mnemonic = FW_FLOWC_MNEM_PFNVFN; |
Hariprasad Shenai | 5167865 | 2014-11-21 12:52:02 +0530 | [diff] [blame] | 601 | flowc->mnemval[0].val = cpu_to_be32(FW_PFVF_CMD_PFN_V |
Hariprasad Shenai | 35b1de5 | 2014-06-27 19:23:47 +0530 | [diff] [blame] | 602 | (ep->com.dev->rdev.lldi.pf)); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 603 | flowc->mnemval[1].mnemonic = FW_FLOWC_MNEM_CH; |
| 604 | flowc->mnemval[1].val = cpu_to_be32(ep->tx_chan); |
| 605 | flowc->mnemval[2].mnemonic = FW_FLOWC_MNEM_PORT; |
| 606 | flowc->mnemval[2].val = cpu_to_be32(ep->tx_chan); |
| 607 | flowc->mnemval[3].mnemonic = FW_FLOWC_MNEM_IQID; |
| 608 | flowc->mnemval[3].val = cpu_to_be32(ep->rss_qid); |
| 609 | flowc->mnemval[4].mnemonic = FW_FLOWC_MNEM_SNDNXT; |
| 610 | flowc->mnemval[4].val = cpu_to_be32(ep->snd_seq); |
| 611 | flowc->mnemval[5].mnemonic = FW_FLOWC_MNEM_RCVNXT; |
| 612 | flowc->mnemval[5].val = cpu_to_be32(ep->rcv_seq); |
| 613 | flowc->mnemval[6].mnemonic = FW_FLOWC_MNEM_SNDBUF; |
Hariprasad Shenai | b408ff2 | 2014-06-06 21:40:44 +0530 | [diff] [blame] | 614 | flowc->mnemval[6].val = cpu_to_be32(ep->snd_win); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 615 | flowc->mnemval[7].mnemonic = FW_FLOWC_MNEM_MSS; |
| 616 | flowc->mnemval[7].val = cpu_to_be32(ep->emss); |
Hariprasad S | ac8e4c6 | 2016-02-05 11:43:30 +0530 | [diff] [blame] | 617 | if (nparams == 9) { |
| 618 | u16 pri; |
| 619 | |
| 620 | pri = (vlan & VLAN_PRIO_MASK) >> VLAN_PRIO_SHIFT; |
| 621 | flowc->mnemval[8].mnemonic = FW_FLOWC_MNEM_SCHEDCLASS; |
| 622 | flowc->mnemval[8].val = cpu_to_be32(pri); |
| 623 | } else { |
| 624 | /* Pad WR to 16 byte boundary */ |
| 625 | flowc->mnemval[8].mnemonic = 0; |
| 626 | flowc->mnemval[8].val = 0; |
| 627 | } |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 628 | for (i = 0; i < 9; i++) { |
| 629 | flowc->mnemval[i].r4[0] = 0; |
| 630 | flowc->mnemval[i].r4[1] = 0; |
| 631 | flowc->mnemval[i].r4[2] = 0; |
| 632 | } |
| 633 | |
| 634 | set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx); |
Hariprasad S | fef4422 | 2016-05-05 01:27:33 +0530 | [diff] [blame] | 635 | return c4iw_ofld_send(&ep->com.dev->rdev, skb); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 636 | } |
| 637 | |
Hariprasad S | 4a74083 | 2016-06-10 01:05:15 +0530 | [diff] [blame] | 638 | static int send_halfclose(struct c4iw_ep *ep) |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 639 | { |
| 640 | struct cpl_close_con_req *req; |
Hariprasad S | 4a74083 | 2016-06-10 01:05:15 +0530 | [diff] [blame] | 641 | struct sk_buff *skb = skb_dequeue(&ep->com.ep_skb_list); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 642 | int wrlen = roundup(sizeof *req, 16); |
| 643 | |
| 644 | PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid); |
Hariprasad S | 4a74083 | 2016-06-10 01:05:15 +0530 | [diff] [blame] | 645 | if (WARN_ON(!skb)) |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 646 | return -ENOMEM; |
Hariprasad S | 4a74083 | 2016-06-10 01:05:15 +0530 | [diff] [blame] | 647 | |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 648 | set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx); |
| 649 | t4_set_arp_err_handler(skb, NULL, arp_failure_discard); |
| 650 | req = (struct cpl_close_con_req *) skb_put(skb, wrlen); |
| 651 | memset(req, 0, wrlen); |
| 652 | INIT_TP_WR(req, ep->hwtid); |
| 653 | OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_CLOSE_CON_REQ, |
| 654 | ep->hwtid)); |
| 655 | return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t); |
| 656 | } |
| 657 | |
Hariprasad S | 4a74083 | 2016-06-10 01:05:15 +0530 | [diff] [blame] | 658 | static int send_abort(struct c4iw_ep *ep) |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 659 | { |
| 660 | struct cpl_abort_req *req; |
| 661 | int wrlen = roundup(sizeof *req, 16); |
Hariprasad S | 4a74083 | 2016-06-10 01:05:15 +0530 | [diff] [blame] | 662 | struct sk_buff *req_skb = skb_dequeue(&ep->com.ep_skb_list); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 663 | |
| 664 | PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid); |
Hariprasad S | 4a74083 | 2016-06-10 01:05:15 +0530 | [diff] [blame] | 665 | if (WARN_ON(!req_skb)) |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 666 | return -ENOMEM; |
Hariprasad S | 4a74083 | 2016-06-10 01:05:15 +0530 | [diff] [blame] | 667 | |
| 668 | set_wr_txq(req_skb, CPL_PRIORITY_DATA, ep->txq_idx); |
| 669 | t4_set_arp_err_handler(req_skb, ep, abort_arp_failure); |
| 670 | req = (struct cpl_abort_req *)skb_put(req_skb, wrlen); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 671 | memset(req, 0, wrlen); |
| 672 | INIT_TP_WR(req, ep->hwtid); |
| 673 | OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_ABORT_REQ, ep->hwtid)); |
| 674 | req->cmd = CPL_ABORT_SEND_RST; |
Hariprasad S | 4a74083 | 2016-06-10 01:05:15 +0530 | [diff] [blame] | 675 | return c4iw_l2t_send(&ep->com.dev->rdev, req_skb, ep->l2t); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 676 | } |
| 677 | |
| 678 | static int send_connect(struct c4iw_ep *ep) |
| 679 | { |
Hariprasad S | 963cab5 | 2015-09-23 17:19:27 +0530 | [diff] [blame] | 680 | struct cpl_act_open_req *req = NULL; |
| 681 | struct cpl_t5_act_open_req *t5req = NULL; |
| 682 | struct cpl_t6_act_open_req *t6req = NULL; |
| 683 | struct cpl_act_open_req6 *req6 = NULL; |
| 684 | struct cpl_t5_act_open_req6 *t5req6 = NULL; |
| 685 | struct cpl_t6_act_open_req6 *t6req6 = NULL; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 686 | struct sk_buff *skb; |
| 687 | u64 opt0; |
| 688 | u32 opt2; |
| 689 | unsigned int mtu_idx; |
Varun Prakash | cc51670 | 2016-09-13 21:24:01 +0530 | [diff] [blame] | 690 | u32 wscale; |
Hariprasad S | 963cab5 | 2015-09-23 17:19:27 +0530 | [diff] [blame] | 691 | int win, sizev4, sizev6, wrlen; |
Steve Wise | 9eccfe1 | 2014-03-26 17:08:09 -0500 | [diff] [blame] | 692 | struct sockaddr_in *la = (struct sockaddr_in *) |
Steve Wise | 170003c | 2016-02-26 09:18:03 -0600 | [diff] [blame] | 693 | &ep->com.local_addr; |
Steve Wise | 9eccfe1 | 2014-03-26 17:08:09 -0500 | [diff] [blame] | 694 | struct sockaddr_in *ra = (struct sockaddr_in *) |
Steve Wise | 170003c | 2016-02-26 09:18:03 -0600 | [diff] [blame] | 695 | &ep->com.remote_addr; |
Steve Wise | 9eccfe1 | 2014-03-26 17:08:09 -0500 | [diff] [blame] | 696 | struct sockaddr_in6 *la6 = (struct sockaddr_in6 *) |
Steve Wise | 170003c | 2016-02-26 09:18:03 -0600 | [diff] [blame] | 697 | &ep->com.local_addr; |
Steve Wise | 9eccfe1 | 2014-03-26 17:08:09 -0500 | [diff] [blame] | 698 | struct sockaddr_in6 *ra6 = (struct sockaddr_in6 *) |
Steve Wise | 170003c | 2016-02-26 09:18:03 -0600 | [diff] [blame] | 699 | &ep->com.remote_addr; |
Hariprasad S | 84cc6ac6 | 2015-08-25 14:08:23 +0530 | [diff] [blame] | 700 | int ret; |
Hariprasad S | 963cab5 | 2015-09-23 17:19:27 +0530 | [diff] [blame] | 701 | enum chip_type adapter_type = ep->com.dev->rdev.lldi.adapter_type; |
| 702 | u32 isn = (prandom_u32() & ~7UL) - 1; |
| 703 | |
| 704 | switch (CHELSIO_CHIP_VERSION(adapter_type)) { |
| 705 | case CHELSIO_T4: |
| 706 | sizev4 = sizeof(struct cpl_act_open_req); |
| 707 | sizev6 = sizeof(struct cpl_act_open_req6); |
| 708 | break; |
| 709 | case CHELSIO_T5: |
| 710 | sizev4 = sizeof(struct cpl_t5_act_open_req); |
| 711 | sizev6 = sizeof(struct cpl_t5_act_open_req6); |
| 712 | break; |
| 713 | case CHELSIO_T6: |
| 714 | sizev4 = sizeof(struct cpl_t6_act_open_req); |
| 715 | sizev6 = sizeof(struct cpl_t6_act_open_req6); |
| 716 | break; |
| 717 | default: |
| 718 | pr_err("T%d Chip is not supported\n", |
| 719 | CHELSIO_CHIP_VERSION(adapter_type)); |
| 720 | return -EINVAL; |
| 721 | } |
Vipul Pandya | 830662f | 2013-07-04 16:10:47 +0530 | [diff] [blame] | 722 | |
| 723 | wrlen = (ep->com.remote_addr.ss_family == AF_INET) ? |
| 724 | roundup(sizev4, 16) : |
| 725 | roundup(sizev6, 16); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 726 | |
| 727 | PDBG("%s ep %p atid %u\n", __func__, ep, ep->atid); |
| 728 | |
| 729 | skb = get_skb(NULL, wrlen, GFP_KERNEL); |
| 730 | if (!skb) { |
| 731 | printk(KERN_ERR MOD "%s - failed to alloc skb.\n", |
| 732 | __func__); |
| 733 | return -ENOMEM; |
| 734 | } |
Steve Wise | d4f1a5c | 2010-07-23 19:12:32 +0000 | [diff] [blame] | 735 | set_wr_txq(skb, CPL_PRIORITY_SETUP, ep->ctrlq_idx); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 736 | |
Varun Prakash | 44c6d06 | 2016-09-13 21:24:00 +0530 | [diff] [blame] | 737 | cxgb_best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx, |
| 738 | enable_tcp_timestamps, |
| 739 | (ep->com.remote_addr.ss_family == AF_INET) ? 0 : 1); |
Varun Prakash | cc51670 | 2016-09-13 21:24:01 +0530 | [diff] [blame] | 740 | wscale = cxgb_compute_wscale(rcv_win); |
Hariprasad Shenai | b408ff2 | 2014-06-06 21:40:44 +0530 | [diff] [blame] | 741 | |
| 742 | /* |
| 743 | * Specify the largest window that will fit in opt0. The |
| 744 | * remainder will be specified in the rx_data_ack. |
| 745 | */ |
| 746 | win = ep->rcv_win >> 10; |
Anish Bhatt | d7990b0 | 2014-11-12 17:15:57 -0800 | [diff] [blame] | 747 | if (win > RCV_BUFSIZ_M) |
| 748 | win = RCV_BUFSIZ_M; |
Hariprasad Shenai | b408ff2 | 2014-06-06 21:40:44 +0530 | [diff] [blame] | 749 | |
Hariprasad Shenai | 6c53e93 | 2015-01-08 21:38:15 -0800 | [diff] [blame] | 750 | opt0 = (nocong ? NO_CONG_F : 0) | |
Anish Bhatt | d7990b0 | 2014-11-12 17:15:57 -0800 | [diff] [blame] | 751 | KEEP_ALIVE_F | |
Hariprasad Shenai | 6c53e93 | 2015-01-08 21:38:15 -0800 | [diff] [blame] | 752 | DELACK_F | |
Anish Bhatt | d7990b0 | 2014-11-12 17:15:57 -0800 | [diff] [blame] | 753 | WND_SCALE_V(wscale) | |
| 754 | MSS_IDX_V(mtu_idx) | |
| 755 | L2T_IDX_V(ep->l2t->idx) | |
| 756 | TX_CHAN_V(ep->tx_chan) | |
| 757 | SMAC_SEL_V(ep->smac_idx) | |
Hariprasad S | ac8e4c6 | 2016-02-05 11:43:30 +0530 | [diff] [blame] | 758 | DSCP_V(ep->tos >> 2) | |
Anish Bhatt | d7990b0 | 2014-11-12 17:15:57 -0800 | [diff] [blame] | 759 | ULP_MODE_V(ULP_MODE_TCPDDP) | |
| 760 | RCV_BUFSIZ_V(win); |
| 761 | opt2 = RX_CHANNEL_V(0) | |
Hariprasad Shenai | 6c53e93 | 2015-01-08 21:38:15 -0800 | [diff] [blame] | 762 | CCTRL_ECN_V(enable_ecn) | |
Anish Bhatt | d7990b0 | 2014-11-12 17:15:57 -0800 | [diff] [blame] | 763 | RSS_QUEUE_VALID_F | RSS_QUEUE_V(ep->rss_qid); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 764 | if (enable_tcp_timestamps) |
Hariprasad Shenai | 6c53e93 | 2015-01-08 21:38:15 -0800 | [diff] [blame] | 765 | opt2 |= TSTAMPS_EN_F; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 766 | if (enable_tcp_sack) |
Hariprasad Shenai | 6c53e93 | 2015-01-08 21:38:15 -0800 | [diff] [blame] | 767 | opt2 |= SACK_EN_F; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 768 | if (wscale && enable_tcp_window_scaling) |
Anish Bhatt | d7990b0 | 2014-11-12 17:15:57 -0800 | [diff] [blame] | 769 | opt2 |= WND_SCALE_EN_F; |
Hariprasad S | 963cab5 | 2015-09-23 17:19:27 +0530 | [diff] [blame] | 770 | if (CHELSIO_CHIP_VERSION(adapter_type) > CHELSIO_T4) { |
| 771 | if (peer2peer) |
| 772 | isn += 4; |
| 773 | |
Anish Bhatt | d7990b0 | 2014-11-12 17:15:57 -0800 | [diff] [blame] | 774 | opt2 |= T5_OPT_2_VALID_F; |
Hariprasad Shenai | cf7fe64 | 2015-01-16 09:24:48 +0530 | [diff] [blame] | 775 | opt2 |= CONG_CNTRL_V(CONG_ALG_TAHOE); |
Hariprasad S | 0b74104 | 2015-04-22 01:44:58 +0530 | [diff] [blame] | 776 | opt2 |= T5_ISS_F; |
Steve Wise | 92e5011 | 2014-04-24 14:31:59 -0500 | [diff] [blame] | 777 | } |
Hariprasad S | 84cc6ac6 | 2015-08-25 14:08:23 +0530 | [diff] [blame] | 778 | |
| 779 | if (ep->com.remote_addr.ss_family == AF_INET6) |
| 780 | cxgb4_clip_get(ep->com.dev->rdev.lldi.ports[0], |
| 781 | (const u32 *)&la6->sin6_addr.s6_addr, 1); |
| 782 | |
Hariprasad S | 5dab6d3 | 2014-06-23 19:12:36 +0530 | [diff] [blame] | 783 | t4_set_arp_err_handler(skb, ep, act_open_req_arp_failure); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 784 | |
Hariprasad S | 963cab5 | 2015-09-23 17:19:27 +0530 | [diff] [blame] | 785 | if (ep->com.remote_addr.ss_family == AF_INET) { |
| 786 | switch (CHELSIO_CHIP_VERSION(adapter_type)) { |
| 787 | case CHELSIO_T4: |
| 788 | req = (struct cpl_act_open_req *)skb_put(skb, wrlen); |
Vipul Pandya | 830662f | 2013-07-04 16:10:47 +0530 | [diff] [blame] | 789 | INIT_TP_WR(req, 0); |
Hariprasad S | 963cab5 | 2015-09-23 17:19:27 +0530 | [diff] [blame] | 790 | break; |
| 791 | case CHELSIO_T5: |
| 792 | t5req = (struct cpl_t5_act_open_req *)skb_put(skb, |
| 793 | wrlen); |
| 794 | INIT_TP_WR(t5req, 0); |
| 795 | req = (struct cpl_act_open_req *)t5req; |
| 796 | break; |
| 797 | case CHELSIO_T6: |
| 798 | t6req = (struct cpl_t6_act_open_req *)skb_put(skb, |
| 799 | wrlen); |
| 800 | INIT_TP_WR(t6req, 0); |
| 801 | req = (struct cpl_act_open_req *)t6req; |
| 802 | t5req = (struct cpl_t5_act_open_req *)t6req; |
| 803 | break; |
| 804 | default: |
| 805 | pr_err("T%d Chip is not supported\n", |
| 806 | CHELSIO_CHIP_VERSION(adapter_type)); |
| 807 | ret = -EINVAL; |
| 808 | goto clip_release; |
| 809 | } |
| 810 | |
| 811 | OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_ACT_OPEN_REQ, |
| 812 | ((ep->rss_qid<<14) | ep->atid))); |
| 813 | req->local_port = la->sin_port; |
| 814 | req->peer_port = ra->sin_port; |
| 815 | req->local_ip = la->sin_addr.s_addr; |
| 816 | req->peer_ip = ra->sin_addr.s_addr; |
| 817 | req->opt0 = cpu_to_be64(opt0); |
| 818 | |
| 819 | if (is_t4(ep->com.dev->rdev.lldi.adapter_type)) { |
Kumar Sanghvi | 41b4f86 | 2013-12-18 16:38:26 +0530 | [diff] [blame] | 820 | req->params = cpu_to_be32(cxgb4_select_ntuple( |
| 821 | ep->com.dev->rdev.lldi.ports[0], |
| 822 | ep->l2t)); |
Vipul Pandya | 830662f | 2013-07-04 16:10:47 +0530 | [diff] [blame] | 823 | req->opt2 = cpu_to_be32(opt2); |
| 824 | } else { |
Hariprasad S | 963cab5 | 2015-09-23 17:19:27 +0530 | [diff] [blame] | 825 | t5req->params = cpu_to_be64(FILTER_TUPLE_V( |
| 826 | cxgb4_select_ntuple( |
| 827 | ep->com.dev->rdev.lldi.ports[0], |
| 828 | ep->l2t))); |
| 829 | t5req->rsvd = cpu_to_be32(isn); |
| 830 | PDBG("%s snd_isn %u\n", __func__, t5req->rsvd); |
| 831 | t5req->opt2 = cpu_to_be32(opt2); |
| 832 | } |
| 833 | } else { |
| 834 | switch (CHELSIO_CHIP_VERSION(adapter_type)) { |
| 835 | case CHELSIO_T4: |
Vipul Pandya | 830662f | 2013-07-04 16:10:47 +0530 | [diff] [blame] | 836 | req6 = (struct cpl_act_open_req6 *)skb_put(skb, wrlen); |
Vipul Pandya | 830662f | 2013-07-04 16:10:47 +0530 | [diff] [blame] | 837 | INIT_TP_WR(req6, 0); |
Hariprasad S | 963cab5 | 2015-09-23 17:19:27 +0530 | [diff] [blame] | 838 | break; |
| 839 | case CHELSIO_T5: |
| 840 | t5req6 = (struct cpl_t5_act_open_req6 *)skb_put(skb, |
| 841 | wrlen); |
| 842 | INIT_TP_WR(t5req6, 0); |
| 843 | req6 = (struct cpl_act_open_req6 *)t5req6; |
| 844 | break; |
| 845 | case CHELSIO_T6: |
| 846 | t6req6 = (struct cpl_t6_act_open_req6 *)skb_put(skb, |
| 847 | wrlen); |
| 848 | INIT_TP_WR(t6req6, 0); |
| 849 | req6 = (struct cpl_act_open_req6 *)t6req6; |
| 850 | t5req6 = (struct cpl_t5_act_open_req6 *)t6req6; |
| 851 | break; |
| 852 | default: |
| 853 | pr_err("T%d Chip is not supported\n", |
| 854 | CHELSIO_CHIP_VERSION(adapter_type)); |
| 855 | ret = -EINVAL; |
| 856 | goto clip_release; |
| 857 | } |
| 858 | |
| 859 | OPCODE_TID(req6) = cpu_to_be32(MK_OPCODE_TID(CPL_ACT_OPEN_REQ6, |
| 860 | ((ep->rss_qid<<14)|ep->atid))); |
| 861 | req6->local_port = la6->sin6_port; |
| 862 | req6->peer_port = ra6->sin6_port; |
| 863 | req6->local_ip_hi = *((__be64 *)(la6->sin6_addr.s6_addr)); |
| 864 | req6->local_ip_lo = *((__be64 *)(la6->sin6_addr.s6_addr + 8)); |
| 865 | req6->peer_ip_hi = *((__be64 *)(ra6->sin6_addr.s6_addr)); |
| 866 | req6->peer_ip_lo = *((__be64 *)(ra6->sin6_addr.s6_addr + 8)); |
| 867 | req6->opt0 = cpu_to_be64(opt0); |
| 868 | |
| 869 | if (is_t4(ep->com.dev->rdev.lldi.adapter_type)) { |
Kumar Sanghvi | 41b4f86 | 2013-12-18 16:38:26 +0530 | [diff] [blame] | 870 | req6->params = cpu_to_be32(cxgb4_select_ntuple( |
| 871 | ep->com.dev->rdev.lldi.ports[0], |
| 872 | ep->l2t)); |
Vipul Pandya | 830662f | 2013-07-04 16:10:47 +0530 | [diff] [blame] | 873 | req6->opt2 = cpu_to_be32(opt2); |
Vipul Pandya | 830662f | 2013-07-04 16:10:47 +0530 | [diff] [blame] | 874 | } else { |
Hariprasad S | 963cab5 | 2015-09-23 17:19:27 +0530 | [diff] [blame] | 875 | t5req6->params = cpu_to_be64(FILTER_TUPLE_V( |
| 876 | cxgb4_select_ntuple( |
Kumar Sanghvi | 41b4f86 | 2013-12-18 16:38:26 +0530 | [diff] [blame] | 877 | ep->com.dev->rdev.lldi.ports[0], |
Hariprasad S | da22b896 | 2014-09-24 03:53:43 +0530 | [diff] [blame] | 878 | ep->l2t))); |
Hariprasad S | 963cab5 | 2015-09-23 17:19:27 +0530 | [diff] [blame] | 879 | t5req6->rsvd = cpu_to_be32(isn); |
| 880 | PDBG("%s snd_isn %u\n", __func__, t5req6->rsvd); |
| 881 | t5req6->opt2 = cpu_to_be32(opt2); |
Vipul Pandya | 830662f | 2013-07-04 16:10:47 +0530 | [diff] [blame] | 882 | } |
Vipul Pandya | f079af7 | 2013-03-14 05:08:58 +0000 | [diff] [blame] | 883 | } |
| 884 | |
Vipul Pandya | 793dad9 | 2012-12-10 09:30:56 +0000 | [diff] [blame] | 885 | set_bit(ACT_OPEN_REQ, &ep->com.history); |
Hariprasad S | 84cc6ac6 | 2015-08-25 14:08:23 +0530 | [diff] [blame] | 886 | ret = c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t); |
Hariprasad S | 963cab5 | 2015-09-23 17:19:27 +0530 | [diff] [blame] | 887 | clip_release: |
Hariprasad S | 84cc6ac6 | 2015-08-25 14:08:23 +0530 | [diff] [blame] | 888 | if (ret && ep->com.remote_addr.ss_family == AF_INET6) |
| 889 | cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0], |
| 890 | (const u32 *)&la6->sin6_addr.s6_addr, 1); |
| 891 | return ret; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 892 | } |
| 893 | |
Hariprasad S | caa6c9f | 2016-05-06 22:18:00 +0530 | [diff] [blame] | 894 | static int send_mpa_req(struct c4iw_ep *ep, struct sk_buff *skb, |
| 895 | u8 mpa_rev_to_use) |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 896 | { |
Hariprasad S | caa6c9f | 2016-05-06 22:18:00 +0530 | [diff] [blame] | 897 | int mpalen, wrlen, ret; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 898 | struct fw_ofld_tx_data_wr *req; |
| 899 | struct mpa_message *mpa; |
Kumar Sanghvi | d2fe99e | 2011-09-25 20:17:44 +0530 | [diff] [blame] | 900 | struct mpa_v2_conn_params mpa_v2_params; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 901 | |
| 902 | PDBG("%s ep %p tid %u pd_len %d\n", __func__, ep, ep->hwtid, ep->plen); |
| 903 | |
| 904 | BUG_ON(skb_cloned(skb)); |
| 905 | |
| 906 | mpalen = sizeof(*mpa) + ep->plen; |
Kumar Sanghvi | d2fe99e | 2011-09-25 20:17:44 +0530 | [diff] [blame] | 907 | if (mpa_rev_to_use == 2) |
| 908 | mpalen += sizeof(struct mpa_v2_conn_params); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 909 | wrlen = roundup(mpalen + sizeof *req, 16); |
| 910 | skb = get_skb(skb, wrlen, GFP_KERNEL); |
| 911 | if (!skb) { |
| 912 | connect_reply_upcall(ep, -ENOMEM); |
Hariprasad S | caa6c9f | 2016-05-06 22:18:00 +0530 | [diff] [blame] | 913 | return -ENOMEM; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 914 | } |
| 915 | set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx); |
| 916 | |
| 917 | req = (struct fw_ofld_tx_data_wr *)skb_put(skb, wrlen); |
| 918 | memset(req, 0, wrlen); |
| 919 | req->op_to_immdlen = cpu_to_be32( |
Hariprasad Shenai | e2ac962 | 2014-11-07 09:35:25 +0530 | [diff] [blame] | 920 | FW_WR_OP_V(FW_OFLD_TX_DATA_WR) | |
| 921 | FW_WR_COMPL_F | |
| 922 | FW_WR_IMMDLEN_V(mpalen)); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 923 | req->flowid_len16 = cpu_to_be32( |
Hariprasad Shenai | e2ac962 | 2014-11-07 09:35:25 +0530 | [diff] [blame] | 924 | FW_WR_FLOWID_V(ep->hwtid) | |
| 925 | FW_WR_LEN16_V(wrlen >> 4)); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 926 | req->plen = cpu_to_be32(mpalen); |
| 927 | req->tunnel_to_proxy = cpu_to_be32( |
Hariprasad Shenai | e2ac962 | 2014-11-07 09:35:25 +0530 | [diff] [blame] | 928 | FW_OFLD_TX_DATA_WR_FLUSH_F | |
| 929 | FW_OFLD_TX_DATA_WR_SHOVE_F); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 930 | |
| 931 | mpa = (struct mpa_message *)(req + 1); |
| 932 | memcpy(mpa->key, MPA_KEY_REQ, sizeof(mpa->key)); |
Hariprasad S | 3d4e799 | 2016-06-10 01:05:11 +0530 | [diff] [blame] | 933 | |
| 934 | mpa->flags = 0; |
| 935 | if (crc_enabled) |
| 936 | mpa->flags |= MPA_CRC; |
| 937 | if (markers_enabled) { |
| 938 | mpa->flags |= MPA_MARKERS; |
| 939 | ep->mpa_attr.recv_marker_enabled = 1; |
| 940 | } else { |
| 941 | ep->mpa_attr.recv_marker_enabled = 0; |
| 942 | } |
| 943 | if (mpa_rev_to_use == 2) |
| 944 | mpa->flags |= MPA_ENHANCED_RDMA_CONN; |
| 945 | |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 946 | mpa->private_data_size = htons(ep->plen); |
Kumar Sanghvi | d2fe99e | 2011-09-25 20:17:44 +0530 | [diff] [blame] | 947 | mpa->revision = mpa_rev_to_use; |
Kumar Sanghvi | 01b225e | 2011-11-28 22:09:15 +0530 | [diff] [blame] | 948 | if (mpa_rev_to_use == 1) { |
Kumar Sanghvi | d2fe99e | 2011-09-25 20:17:44 +0530 | [diff] [blame] | 949 | ep->tried_with_mpa_v1 = 1; |
Kumar Sanghvi | 01b225e | 2011-11-28 22:09:15 +0530 | [diff] [blame] | 950 | ep->retry_with_mpa_v1 = 0; |
| 951 | } |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 952 | |
Kumar Sanghvi | d2fe99e | 2011-09-25 20:17:44 +0530 | [diff] [blame] | 953 | if (mpa_rev_to_use == 2) { |
Roland Dreier | f747c34 | 2012-07-05 14:16:54 -0700 | [diff] [blame] | 954 | mpa->private_data_size = htons(ntohs(mpa->private_data_size) + |
| 955 | sizeof (struct mpa_v2_conn_params)); |
Hariprasad Shenai | 4c2c576 | 2014-07-14 21:34:52 +0530 | [diff] [blame] | 956 | PDBG("%s initiator ird %u ord %u\n", __func__, ep->ird, |
| 957 | ep->ord); |
Kumar Sanghvi | d2fe99e | 2011-09-25 20:17:44 +0530 | [diff] [blame] | 958 | mpa_v2_params.ird = htons((u16)ep->ird); |
| 959 | mpa_v2_params.ord = htons((u16)ep->ord); |
| 960 | |
| 961 | if (peer2peer) { |
| 962 | mpa_v2_params.ird |= htons(MPA_V2_PEER2PEER_MODEL); |
| 963 | if (p2p_type == FW_RI_INIT_P2PTYPE_RDMA_WRITE) |
| 964 | mpa_v2_params.ord |= |
| 965 | htons(MPA_V2_RDMA_WRITE_RTR); |
| 966 | else if (p2p_type == FW_RI_INIT_P2PTYPE_READ_REQ) |
| 967 | mpa_v2_params.ord |= |
| 968 | htons(MPA_V2_RDMA_READ_RTR); |
| 969 | } |
| 970 | memcpy(mpa->private_data, &mpa_v2_params, |
| 971 | sizeof(struct mpa_v2_conn_params)); |
| 972 | |
| 973 | if (ep->plen) |
| 974 | memcpy(mpa->private_data + |
| 975 | sizeof(struct mpa_v2_conn_params), |
| 976 | ep->mpa_pkt + sizeof(*mpa), ep->plen); |
| 977 | } else |
| 978 | if (ep->plen) |
| 979 | memcpy(mpa->private_data, |
| 980 | ep->mpa_pkt + sizeof(*mpa), ep->plen); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 981 | |
| 982 | /* |
| 983 | * Reference the mpa skb. This ensures the data area |
| 984 | * will remain in memory until the hw acks the tx. |
| 985 | * Function fw4_ack() will deref it. |
| 986 | */ |
| 987 | skb_get(skb); |
| 988 | t4_set_arp_err_handler(skb, NULL, arp_failure_discard); |
| 989 | BUG_ON(ep->mpa_skb); |
| 990 | ep->mpa_skb = skb; |
Hariprasad S | caa6c9f | 2016-05-06 22:18:00 +0530 | [diff] [blame] | 991 | ret = c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t); |
| 992 | if (ret) |
| 993 | return ret; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 994 | start_ep_timer(ep); |
Steve Wise | a7db89e | 2014-03-21 20:40:35 +0530 | [diff] [blame] | 995 | __state_set(&ep->com, MPA_REQ_SENT); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 996 | ep->mpa_attr.initiator = 1; |
Steve Wise | 9c88aa0 | 2014-03-21 20:40:34 +0530 | [diff] [blame] | 997 | ep->snd_seq += mpalen; |
Hariprasad S | caa6c9f | 2016-05-06 22:18:00 +0530 | [diff] [blame] | 998 | return ret; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 999 | } |
| 1000 | |
| 1001 | static int send_mpa_reject(struct c4iw_ep *ep, const void *pdata, u8 plen) |
| 1002 | { |
| 1003 | int mpalen, wrlen; |
| 1004 | struct fw_ofld_tx_data_wr *req; |
| 1005 | struct mpa_message *mpa; |
| 1006 | struct sk_buff *skb; |
Kumar Sanghvi | d2fe99e | 2011-09-25 20:17:44 +0530 | [diff] [blame] | 1007 | struct mpa_v2_conn_params mpa_v2_params; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1008 | |
| 1009 | PDBG("%s ep %p tid %u pd_len %d\n", __func__, ep, ep->hwtid, ep->plen); |
| 1010 | |
| 1011 | mpalen = sizeof(*mpa) + plen; |
Kumar Sanghvi | d2fe99e | 2011-09-25 20:17:44 +0530 | [diff] [blame] | 1012 | if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) |
| 1013 | mpalen += sizeof(struct mpa_v2_conn_params); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1014 | wrlen = roundup(mpalen + sizeof *req, 16); |
| 1015 | |
| 1016 | skb = get_skb(NULL, wrlen, GFP_KERNEL); |
| 1017 | if (!skb) { |
| 1018 | printk(KERN_ERR MOD "%s - cannot alloc skb!\n", __func__); |
| 1019 | return -ENOMEM; |
| 1020 | } |
| 1021 | set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx); |
| 1022 | |
| 1023 | req = (struct fw_ofld_tx_data_wr *)skb_put(skb, wrlen); |
| 1024 | memset(req, 0, wrlen); |
| 1025 | req->op_to_immdlen = cpu_to_be32( |
Hariprasad Shenai | e2ac962 | 2014-11-07 09:35:25 +0530 | [diff] [blame] | 1026 | FW_WR_OP_V(FW_OFLD_TX_DATA_WR) | |
| 1027 | FW_WR_COMPL_F | |
| 1028 | FW_WR_IMMDLEN_V(mpalen)); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1029 | req->flowid_len16 = cpu_to_be32( |
Hariprasad Shenai | e2ac962 | 2014-11-07 09:35:25 +0530 | [diff] [blame] | 1030 | FW_WR_FLOWID_V(ep->hwtid) | |
| 1031 | FW_WR_LEN16_V(wrlen >> 4)); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1032 | req->plen = cpu_to_be32(mpalen); |
| 1033 | req->tunnel_to_proxy = cpu_to_be32( |
Hariprasad Shenai | e2ac962 | 2014-11-07 09:35:25 +0530 | [diff] [blame] | 1034 | FW_OFLD_TX_DATA_WR_FLUSH_F | |
| 1035 | FW_OFLD_TX_DATA_WR_SHOVE_F); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1036 | |
| 1037 | mpa = (struct mpa_message *)(req + 1); |
| 1038 | memset(mpa, 0, sizeof(*mpa)); |
| 1039 | memcpy(mpa->key, MPA_KEY_REP, sizeof(mpa->key)); |
| 1040 | mpa->flags = MPA_REJECT; |
Vipul Pandya | fe7e0a4 | 2013-01-07 13:11:57 +0000 | [diff] [blame] | 1041 | mpa->revision = ep->mpa_attr.version; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1042 | mpa->private_data_size = htons(plen); |
Kumar Sanghvi | d2fe99e | 2011-09-25 20:17:44 +0530 | [diff] [blame] | 1043 | |
| 1044 | if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) { |
| 1045 | mpa->flags |= MPA_ENHANCED_RDMA_CONN; |
Roland Dreier | f747c34 | 2012-07-05 14:16:54 -0700 | [diff] [blame] | 1046 | mpa->private_data_size = htons(ntohs(mpa->private_data_size) + |
| 1047 | sizeof (struct mpa_v2_conn_params)); |
Kumar Sanghvi | d2fe99e | 2011-09-25 20:17:44 +0530 | [diff] [blame] | 1048 | mpa_v2_params.ird = htons(((u16)ep->ird) | |
| 1049 | (peer2peer ? MPA_V2_PEER2PEER_MODEL : |
| 1050 | 0)); |
| 1051 | mpa_v2_params.ord = htons(((u16)ep->ord) | (peer2peer ? |
| 1052 | (p2p_type == |
| 1053 | FW_RI_INIT_P2PTYPE_RDMA_WRITE ? |
| 1054 | MPA_V2_RDMA_WRITE_RTR : p2p_type == |
| 1055 | FW_RI_INIT_P2PTYPE_READ_REQ ? |
| 1056 | MPA_V2_RDMA_READ_RTR : 0) : 0)); |
| 1057 | memcpy(mpa->private_data, &mpa_v2_params, |
| 1058 | sizeof(struct mpa_v2_conn_params)); |
| 1059 | |
| 1060 | if (ep->plen) |
| 1061 | memcpy(mpa->private_data + |
| 1062 | sizeof(struct mpa_v2_conn_params), pdata, plen); |
| 1063 | } else |
| 1064 | if (plen) |
| 1065 | memcpy(mpa->private_data, pdata, plen); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1066 | |
| 1067 | /* |
| 1068 | * Reference the mpa skb again. This ensures the data area |
| 1069 | * will remain in memory until the hw acks the tx. |
| 1070 | * Function fw4_ack() will deref it. |
| 1071 | */ |
| 1072 | skb_get(skb); |
| 1073 | set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx); |
Hariprasad S | 64bec74 | 2016-05-06 22:18:10 +0530 | [diff] [blame] | 1074 | t4_set_arp_err_handler(skb, NULL, mpa_start_arp_failure); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1075 | BUG_ON(ep->mpa_skb); |
| 1076 | ep->mpa_skb = skb; |
Steve Wise | 9c88aa0 | 2014-03-21 20:40:34 +0530 | [diff] [blame] | 1077 | ep->snd_seq += mpalen; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1078 | return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t); |
| 1079 | } |
| 1080 | |
| 1081 | static int send_mpa_reply(struct c4iw_ep *ep, const void *pdata, u8 plen) |
| 1082 | { |
| 1083 | int mpalen, wrlen; |
| 1084 | struct fw_ofld_tx_data_wr *req; |
| 1085 | struct mpa_message *mpa; |
| 1086 | struct sk_buff *skb; |
Kumar Sanghvi | d2fe99e | 2011-09-25 20:17:44 +0530 | [diff] [blame] | 1087 | struct mpa_v2_conn_params mpa_v2_params; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1088 | |
| 1089 | PDBG("%s ep %p tid %u pd_len %d\n", __func__, ep, ep->hwtid, ep->plen); |
| 1090 | |
| 1091 | mpalen = sizeof(*mpa) + plen; |
Kumar Sanghvi | d2fe99e | 2011-09-25 20:17:44 +0530 | [diff] [blame] | 1092 | if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) |
| 1093 | mpalen += sizeof(struct mpa_v2_conn_params); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1094 | wrlen = roundup(mpalen + sizeof *req, 16); |
| 1095 | |
| 1096 | skb = get_skb(NULL, wrlen, GFP_KERNEL); |
| 1097 | if (!skb) { |
| 1098 | printk(KERN_ERR MOD "%s - cannot alloc skb!\n", __func__); |
| 1099 | return -ENOMEM; |
| 1100 | } |
| 1101 | set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx); |
| 1102 | |
| 1103 | req = (struct fw_ofld_tx_data_wr *) skb_put(skb, wrlen); |
| 1104 | memset(req, 0, wrlen); |
| 1105 | req->op_to_immdlen = cpu_to_be32( |
Hariprasad Shenai | e2ac962 | 2014-11-07 09:35:25 +0530 | [diff] [blame] | 1106 | FW_WR_OP_V(FW_OFLD_TX_DATA_WR) | |
| 1107 | FW_WR_COMPL_F | |
| 1108 | FW_WR_IMMDLEN_V(mpalen)); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1109 | req->flowid_len16 = cpu_to_be32( |
Hariprasad Shenai | e2ac962 | 2014-11-07 09:35:25 +0530 | [diff] [blame] | 1110 | FW_WR_FLOWID_V(ep->hwtid) | |
| 1111 | FW_WR_LEN16_V(wrlen >> 4)); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1112 | req->plen = cpu_to_be32(mpalen); |
| 1113 | req->tunnel_to_proxy = cpu_to_be32( |
Hariprasad Shenai | e2ac962 | 2014-11-07 09:35:25 +0530 | [diff] [blame] | 1114 | FW_OFLD_TX_DATA_WR_FLUSH_F | |
| 1115 | FW_OFLD_TX_DATA_WR_SHOVE_F); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1116 | |
| 1117 | mpa = (struct mpa_message *)(req + 1); |
| 1118 | memset(mpa, 0, sizeof(*mpa)); |
| 1119 | memcpy(mpa->key, MPA_KEY_REP, sizeof(mpa->key)); |
Hariprasad S | 3d4e799 | 2016-06-10 01:05:11 +0530 | [diff] [blame] | 1120 | mpa->flags = 0; |
| 1121 | if (ep->mpa_attr.crc_enabled) |
| 1122 | mpa->flags |= MPA_CRC; |
| 1123 | if (ep->mpa_attr.recv_marker_enabled) |
| 1124 | mpa->flags |= MPA_MARKERS; |
Kumar Sanghvi | d2fe99e | 2011-09-25 20:17:44 +0530 | [diff] [blame] | 1125 | mpa->revision = ep->mpa_attr.version; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1126 | mpa->private_data_size = htons(plen); |
Kumar Sanghvi | d2fe99e | 2011-09-25 20:17:44 +0530 | [diff] [blame] | 1127 | |
| 1128 | if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) { |
| 1129 | mpa->flags |= MPA_ENHANCED_RDMA_CONN; |
Roland Dreier | f747c34 | 2012-07-05 14:16:54 -0700 | [diff] [blame] | 1130 | mpa->private_data_size = htons(ntohs(mpa->private_data_size) + |
| 1131 | sizeof (struct mpa_v2_conn_params)); |
Kumar Sanghvi | d2fe99e | 2011-09-25 20:17:44 +0530 | [diff] [blame] | 1132 | mpa_v2_params.ird = htons((u16)ep->ird); |
| 1133 | mpa_v2_params.ord = htons((u16)ep->ord); |
| 1134 | if (peer2peer && (ep->mpa_attr.p2p_type != |
| 1135 | FW_RI_INIT_P2PTYPE_DISABLED)) { |
| 1136 | mpa_v2_params.ird |= htons(MPA_V2_PEER2PEER_MODEL); |
| 1137 | |
| 1138 | if (p2p_type == FW_RI_INIT_P2PTYPE_RDMA_WRITE) |
| 1139 | mpa_v2_params.ord |= |
| 1140 | htons(MPA_V2_RDMA_WRITE_RTR); |
| 1141 | else if (p2p_type == FW_RI_INIT_P2PTYPE_READ_REQ) |
| 1142 | mpa_v2_params.ord |= |
| 1143 | htons(MPA_V2_RDMA_READ_RTR); |
| 1144 | } |
| 1145 | |
| 1146 | memcpy(mpa->private_data, &mpa_v2_params, |
| 1147 | sizeof(struct mpa_v2_conn_params)); |
| 1148 | |
| 1149 | if (ep->plen) |
| 1150 | memcpy(mpa->private_data + |
| 1151 | sizeof(struct mpa_v2_conn_params), pdata, plen); |
| 1152 | } else |
| 1153 | if (plen) |
| 1154 | memcpy(mpa->private_data, pdata, plen); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1155 | |
| 1156 | /* |
| 1157 | * Reference the mpa skb. This ensures the data area |
| 1158 | * will remain in memory until the hw acks the tx. |
| 1159 | * Function fw4_ack() will deref it. |
| 1160 | */ |
| 1161 | skb_get(skb); |
Hariprasad S | 64bec74 | 2016-05-06 22:18:10 +0530 | [diff] [blame] | 1162 | t4_set_arp_err_handler(skb, NULL, mpa_start_arp_failure); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1163 | ep->mpa_skb = skb; |
Steve Wise | a7db89e | 2014-03-21 20:40:35 +0530 | [diff] [blame] | 1164 | __state_set(&ep->com, MPA_REP_SENT); |
Steve Wise | 9c88aa0 | 2014-03-21 20:40:34 +0530 | [diff] [blame] | 1165 | ep->snd_seq += mpalen; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1166 | return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t); |
| 1167 | } |
| 1168 | |
| 1169 | static int act_establish(struct c4iw_dev *dev, struct sk_buff *skb) |
| 1170 | { |
| 1171 | struct c4iw_ep *ep; |
| 1172 | struct cpl_act_establish *req = cplhdr(skb); |
| 1173 | unsigned int tid = GET_TID(req); |
Hariprasad Shenai | 6c53e93 | 2015-01-08 21:38:15 -0800 | [diff] [blame] | 1174 | unsigned int atid = TID_TID_G(ntohl(req->tos_atid)); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1175 | struct tid_info *t = dev->rdev.lldi.tids; |
Hariprasad S | fef4422 | 2016-05-05 01:27:33 +0530 | [diff] [blame] | 1176 | int ret; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1177 | |
| 1178 | ep = lookup_atid(t, atid); |
| 1179 | |
| 1180 | PDBG("%s ep %p tid %u snd_isn %u rcv_isn %u\n", __func__, ep, tid, |
| 1181 | be32_to_cpu(req->snd_isn), be32_to_cpu(req->rcv_isn)); |
| 1182 | |
Steve Wise | a7db89e | 2014-03-21 20:40:35 +0530 | [diff] [blame] | 1183 | mutex_lock(&ep->com.mutex); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1184 | dst_confirm(ep->dst); |
| 1185 | |
| 1186 | /* setup the hwtid for this connection */ |
| 1187 | ep->hwtid = tid; |
| 1188 | cxgb4_insert_tid(t, ep, tid); |
Hariprasad S | 944661d | 2016-05-06 22:18:03 +0530 | [diff] [blame] | 1189 | insert_ep_tid(ep); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1190 | |
| 1191 | ep->snd_seq = be32_to_cpu(req->snd_isn); |
| 1192 | ep->rcv_seq = be32_to_cpu(req->rcv_isn); |
| 1193 | |
| 1194 | set_emss(ep, ntohs(req->tcp_opt)); |
| 1195 | |
| 1196 | /* dealloc the atid */ |
Vipul Pandya | 793dad9 | 2012-12-10 09:30:56 +0000 | [diff] [blame] | 1197 | remove_handle(ep->com.dev, &ep->com.dev->atid_idr, atid); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1198 | cxgb4_free_atid(t, atid); |
Vipul Pandya | 793dad9 | 2012-12-10 09:30:56 +0000 | [diff] [blame] | 1199 | set_bit(ACT_ESTAB, &ep->com.history); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1200 | |
| 1201 | /* start MPA negotiation */ |
Hariprasad S | 4a74083 | 2016-06-10 01:05:15 +0530 | [diff] [blame] | 1202 | ret = send_flowc(ep); |
Hariprasad S | fef4422 | 2016-05-05 01:27:33 +0530 | [diff] [blame] | 1203 | if (ret) |
| 1204 | goto err; |
Kumar Sanghvi | d2fe99e | 2011-09-25 20:17:44 +0530 | [diff] [blame] | 1205 | if (ep->retry_with_mpa_v1) |
Hariprasad S | caa6c9f | 2016-05-06 22:18:00 +0530 | [diff] [blame] | 1206 | ret = send_mpa_req(ep, skb, 1); |
Kumar Sanghvi | d2fe99e | 2011-09-25 20:17:44 +0530 | [diff] [blame] | 1207 | else |
Hariprasad S | caa6c9f | 2016-05-06 22:18:00 +0530 | [diff] [blame] | 1208 | ret = send_mpa_req(ep, skb, mpa_rev); |
| 1209 | if (ret) |
| 1210 | goto err; |
Steve Wise | a7db89e | 2014-03-21 20:40:35 +0530 | [diff] [blame] | 1211 | mutex_unlock(&ep->com.mutex); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1212 | return 0; |
Hariprasad S | fef4422 | 2016-05-05 01:27:33 +0530 | [diff] [blame] | 1213 | err: |
| 1214 | mutex_unlock(&ep->com.mutex); |
| 1215 | connect_reply_upcall(ep, -ENOMEM); |
| 1216 | c4iw_ep_disconnect(ep, 0, GFP_KERNEL); |
| 1217 | return 0; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1218 | } |
| 1219 | |
Steve Wise | be13b2d | 2014-03-21 20:40:33 +0530 | [diff] [blame] | 1220 | static void close_complete_upcall(struct c4iw_ep *ep, int status) |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1221 | { |
| 1222 | struct iw_cm_event event; |
| 1223 | |
| 1224 | PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid); |
| 1225 | memset(&event, 0, sizeof(event)); |
| 1226 | event.event = IW_CM_EVENT_CLOSE; |
Steve Wise | be13b2d | 2014-03-21 20:40:33 +0530 | [diff] [blame] | 1227 | event.status = status; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1228 | if (ep->com.cm_id) { |
| 1229 | PDBG("close complete delivered ep %p cm_id %p tid %u\n", |
| 1230 | ep, ep->com.cm_id, ep->hwtid); |
| 1231 | ep->com.cm_id->event_handler(ep->com.cm_id, &event); |
Hariprasad S | 9ca6f7c | 2016-05-06 22:17:54 +0530 | [diff] [blame] | 1232 | deref_cm_id(&ep->com); |
Vipul Pandya | 793dad9 | 2012-12-10 09:30:56 +0000 | [diff] [blame] | 1233 | set_bit(CLOSE_UPCALL, &ep->com.history); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1234 | } |
| 1235 | } |
| 1236 | |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1237 | static void peer_close_upcall(struct c4iw_ep *ep) |
| 1238 | { |
| 1239 | struct iw_cm_event event; |
| 1240 | |
| 1241 | PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid); |
| 1242 | memset(&event, 0, sizeof(event)); |
| 1243 | event.event = IW_CM_EVENT_DISCONNECT; |
| 1244 | if (ep->com.cm_id) { |
| 1245 | PDBG("peer close delivered ep %p cm_id %p tid %u\n", |
| 1246 | ep, ep->com.cm_id, ep->hwtid); |
| 1247 | ep->com.cm_id->event_handler(ep->com.cm_id, &event); |
Vipul Pandya | 793dad9 | 2012-12-10 09:30:56 +0000 | [diff] [blame] | 1248 | set_bit(DISCONN_UPCALL, &ep->com.history); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1249 | } |
| 1250 | } |
| 1251 | |
| 1252 | static void peer_abort_upcall(struct c4iw_ep *ep) |
| 1253 | { |
| 1254 | struct iw_cm_event event; |
| 1255 | |
| 1256 | PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid); |
| 1257 | memset(&event, 0, sizeof(event)); |
| 1258 | event.event = IW_CM_EVENT_CLOSE; |
| 1259 | event.status = -ECONNRESET; |
| 1260 | if (ep->com.cm_id) { |
| 1261 | PDBG("abort delivered ep %p cm_id %p tid %u\n", ep, |
| 1262 | ep->com.cm_id, ep->hwtid); |
| 1263 | ep->com.cm_id->event_handler(ep->com.cm_id, &event); |
Hariprasad S | 9ca6f7c | 2016-05-06 22:17:54 +0530 | [diff] [blame] | 1264 | deref_cm_id(&ep->com); |
Vipul Pandya | 793dad9 | 2012-12-10 09:30:56 +0000 | [diff] [blame] | 1265 | set_bit(ABORT_UPCALL, &ep->com.history); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1266 | } |
| 1267 | } |
| 1268 | |
| 1269 | static void connect_reply_upcall(struct c4iw_ep *ep, int status) |
| 1270 | { |
| 1271 | struct iw_cm_event event; |
| 1272 | |
| 1273 | PDBG("%s ep %p tid %u status %d\n", __func__, ep, ep->hwtid, status); |
| 1274 | memset(&event, 0, sizeof(event)); |
| 1275 | event.event = IW_CM_EVENT_CONNECT_REPLY; |
| 1276 | event.status = status; |
Steve Wise | 24d44a3 | 2013-07-04 16:10:44 +0530 | [diff] [blame] | 1277 | memcpy(&event.local_addr, &ep->com.local_addr, |
| 1278 | sizeof(ep->com.local_addr)); |
| 1279 | memcpy(&event.remote_addr, &ep->com.remote_addr, |
| 1280 | sizeof(ep->com.remote_addr)); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1281 | |
| 1282 | if ((status == 0) || (status == -ECONNREFUSED)) { |
Kumar Sanghvi | d2fe99e | 2011-09-25 20:17:44 +0530 | [diff] [blame] | 1283 | if (!ep->tried_with_mpa_v1) { |
| 1284 | /* this means MPA_v2 is used */ |
Hariprasad S | 158c776 | 2015-09-08 09:56:58 +0530 | [diff] [blame] | 1285 | event.ord = ep->ird; |
| 1286 | event.ird = ep->ord; |
Kumar Sanghvi | d2fe99e | 2011-09-25 20:17:44 +0530 | [diff] [blame] | 1287 | event.private_data_len = ep->plen - |
| 1288 | sizeof(struct mpa_v2_conn_params); |
| 1289 | event.private_data = ep->mpa_pkt + |
| 1290 | sizeof(struct mpa_message) + |
| 1291 | sizeof(struct mpa_v2_conn_params); |
| 1292 | } else { |
| 1293 | /* this means MPA_v1 is used */ |
Hariprasad S | 158c776 | 2015-09-08 09:56:58 +0530 | [diff] [blame] | 1294 | event.ord = cur_max_read_depth(ep->com.dev); |
| 1295 | event.ird = cur_max_read_depth(ep->com.dev); |
Kumar Sanghvi | d2fe99e | 2011-09-25 20:17:44 +0530 | [diff] [blame] | 1296 | event.private_data_len = ep->plen; |
| 1297 | event.private_data = ep->mpa_pkt + |
| 1298 | sizeof(struct mpa_message); |
| 1299 | } |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1300 | } |
Roland Dreier | 85963e4 | 2010-07-19 13:13:09 -0700 | [diff] [blame] | 1301 | |
| 1302 | PDBG("%s ep %p tid %u status %d\n", __func__, ep, |
| 1303 | ep->hwtid, status); |
Vipul Pandya | 793dad9 | 2012-12-10 09:30:56 +0000 | [diff] [blame] | 1304 | set_bit(CONN_RPL_UPCALL, &ep->com.history); |
Roland Dreier | 85963e4 | 2010-07-19 13:13:09 -0700 | [diff] [blame] | 1305 | ep->com.cm_id->event_handler(ep->com.cm_id, &event); |
| 1306 | |
Hariprasad S | 9ca6f7c | 2016-05-06 22:17:54 +0530 | [diff] [blame] | 1307 | if (status < 0) |
| 1308 | deref_cm_id(&ep->com); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1309 | } |
| 1310 | |
Steve Wise | be13b2d | 2014-03-21 20:40:33 +0530 | [diff] [blame] | 1311 | static int connect_request_upcall(struct c4iw_ep *ep) |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1312 | { |
| 1313 | struct iw_cm_event event; |
Steve Wise | be13b2d | 2014-03-21 20:40:33 +0530 | [diff] [blame] | 1314 | int ret; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1315 | |
| 1316 | PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid); |
| 1317 | memset(&event, 0, sizeof(event)); |
| 1318 | event.event = IW_CM_EVENT_CONNECT_REQUEST; |
Steve Wise | 24d44a3 | 2013-07-04 16:10:44 +0530 | [diff] [blame] | 1319 | memcpy(&event.local_addr, &ep->com.local_addr, |
| 1320 | sizeof(ep->com.local_addr)); |
| 1321 | memcpy(&event.remote_addr, &ep->com.remote_addr, |
| 1322 | sizeof(ep->com.remote_addr)); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1323 | event.provider_data = ep; |
Kumar Sanghvi | d2fe99e | 2011-09-25 20:17:44 +0530 | [diff] [blame] | 1324 | if (!ep->tried_with_mpa_v1) { |
| 1325 | /* this means MPA_v2 is used */ |
| 1326 | event.ord = ep->ord; |
| 1327 | event.ird = ep->ird; |
| 1328 | event.private_data_len = ep->plen - |
| 1329 | sizeof(struct mpa_v2_conn_params); |
| 1330 | event.private_data = ep->mpa_pkt + sizeof(struct mpa_message) + |
| 1331 | sizeof(struct mpa_v2_conn_params); |
| 1332 | } else { |
| 1333 | /* this means MPA_v1 is used. Send max supported */ |
Hariprasad Shenai | 4c2c576 | 2014-07-14 21:34:52 +0530 | [diff] [blame] | 1334 | event.ord = cur_max_read_depth(ep->com.dev); |
| 1335 | event.ird = cur_max_read_depth(ep->com.dev); |
Kumar Sanghvi | d2fe99e | 2011-09-25 20:17:44 +0530 | [diff] [blame] | 1336 | event.private_data_len = ep->plen; |
| 1337 | event.private_data = ep->mpa_pkt + sizeof(struct mpa_message); |
| 1338 | } |
Steve Wise | be13b2d | 2014-03-21 20:40:33 +0530 | [diff] [blame] | 1339 | c4iw_get_ep(&ep->com); |
| 1340 | ret = ep->parent_ep->com.cm_id->event_handler(ep->parent_ep->com.cm_id, |
| 1341 | &event); |
| 1342 | if (ret) |
| 1343 | c4iw_put_ep(&ep->com); |
Vipul Pandya | 793dad9 | 2012-12-10 09:30:56 +0000 | [diff] [blame] | 1344 | set_bit(CONNREQ_UPCALL, &ep->com.history); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1345 | c4iw_put_ep(&ep->parent_ep->com); |
Steve Wise | be13b2d | 2014-03-21 20:40:33 +0530 | [diff] [blame] | 1346 | return ret; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1347 | } |
| 1348 | |
| 1349 | static void established_upcall(struct c4iw_ep *ep) |
| 1350 | { |
| 1351 | struct iw_cm_event event; |
| 1352 | |
| 1353 | PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid); |
| 1354 | memset(&event, 0, sizeof(event)); |
| 1355 | event.event = IW_CM_EVENT_ESTABLISHED; |
Hariprasad S | 3dd9a5d | 2015-09-08 09:57:00 +0530 | [diff] [blame] | 1356 | event.ird = ep->ord; |
| 1357 | event.ord = ep->ird; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1358 | if (ep->com.cm_id) { |
| 1359 | PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid); |
| 1360 | ep->com.cm_id->event_handler(ep->com.cm_id, &event); |
Vipul Pandya | 793dad9 | 2012-12-10 09:30:56 +0000 | [diff] [blame] | 1361 | set_bit(ESTAB_UPCALL, &ep->com.history); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1362 | } |
| 1363 | } |
| 1364 | |
| 1365 | static int update_rx_credits(struct c4iw_ep *ep, u32 credits) |
| 1366 | { |
| 1367 | struct cpl_rx_data_ack *req; |
| 1368 | struct sk_buff *skb; |
| 1369 | int wrlen = roundup(sizeof *req, 16); |
| 1370 | |
| 1371 | PDBG("%s ep %p tid %u credits %u\n", __func__, ep, ep->hwtid, credits); |
| 1372 | skb = get_skb(NULL, wrlen, GFP_KERNEL); |
| 1373 | if (!skb) { |
| 1374 | printk(KERN_ERR MOD "update_rx_credits - cannot alloc skb!\n"); |
| 1375 | return 0; |
| 1376 | } |
| 1377 | |
Hariprasad Shenai | b408ff2 | 2014-06-06 21:40:44 +0530 | [diff] [blame] | 1378 | /* |
| 1379 | * If we couldn't specify the entire rcv window at connection setup |
| 1380 | * due to the limit in the number of bits in the RCV_BUFSIZ field, |
| 1381 | * then add the overage in to the credits returned. |
| 1382 | */ |
Anish Bhatt | d7990b0 | 2014-11-12 17:15:57 -0800 | [diff] [blame] | 1383 | if (ep->rcv_win > RCV_BUFSIZ_M * 1024) |
| 1384 | credits += ep->rcv_win - RCV_BUFSIZ_M * 1024; |
Hariprasad Shenai | b408ff2 | 2014-06-06 21:40:44 +0530 | [diff] [blame] | 1385 | |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1386 | req = (struct cpl_rx_data_ack *) skb_put(skb, wrlen); |
| 1387 | memset(req, 0, wrlen); |
| 1388 | INIT_TP_WR(req, ep->hwtid); |
| 1389 | OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_RX_DATA_ACK, |
| 1390 | ep->hwtid)); |
Anish Bhatt | d7990b0 | 2014-11-12 17:15:57 -0800 | [diff] [blame] | 1391 | req->credit_dack = cpu_to_be32(credits | RX_FORCE_ACK_F | |
Hariprasad Shenai | cf7fe64 | 2015-01-16 09:24:48 +0530 | [diff] [blame] | 1392 | RX_DACK_CHANGE_F | |
| 1393 | RX_DACK_MODE_V(dack_mode)); |
Steve Wise | d4f1a5c | 2010-07-23 19:12:32 +0000 | [diff] [blame] | 1394 | set_wr_txq(skb, CPL_PRIORITY_ACK, ep->ctrlq_idx); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1395 | c4iw_ofld_send(&ep->com.dev->rdev, skb); |
| 1396 | return credits; |
| 1397 | } |
| 1398 | |
Hariprasad Shenai | 4c2c576 | 2014-07-14 21:34:52 +0530 | [diff] [blame] | 1399 | #define RELAXED_IRD_NEGOTIATION 1 |
| 1400 | |
Hariprasad S | f8e1e1d | 2016-05-05 01:27:32 +0530 | [diff] [blame] | 1401 | /* |
| 1402 | * process_mpa_reply - process streaming mode MPA reply |
| 1403 | * |
| 1404 | * Returns: |
| 1405 | * |
| 1406 | * 0 upon success indicating a connect request was delivered to the ULP |
| 1407 | * or the mpa request is incomplete but valid so far. |
| 1408 | * |
| 1409 | * 1 if a failure requires the caller to close the connection. |
| 1410 | * |
| 1411 | * 2 if a failure requires the caller to abort the connection. |
| 1412 | */ |
Steve Wise | cc18b93 | 2014-04-24 14:31:53 -0500 | [diff] [blame] | 1413 | static int process_mpa_reply(struct c4iw_ep *ep, struct sk_buff *skb) |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1414 | { |
| 1415 | struct mpa_message *mpa; |
Kumar Sanghvi | d2fe99e | 2011-09-25 20:17:44 +0530 | [diff] [blame] | 1416 | struct mpa_v2_conn_params *mpa_v2_params; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1417 | u16 plen; |
Kumar Sanghvi | d2fe99e | 2011-09-25 20:17:44 +0530 | [diff] [blame] | 1418 | u16 resp_ird, resp_ord; |
| 1419 | u8 rtr_mismatch = 0, insuff_ird = 0; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1420 | struct c4iw_qp_attributes attrs; |
| 1421 | enum c4iw_qp_attr_mask mask; |
| 1422 | int err; |
Steve Wise | cc18b93 | 2014-04-24 14:31:53 -0500 | [diff] [blame] | 1423 | int disconnect = 0; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1424 | |
| 1425 | PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid); |
| 1426 | |
| 1427 | /* |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1428 | * If we get more than the supported amount of private data |
| 1429 | * then we must fail this connection. |
| 1430 | */ |
| 1431 | if (ep->mpa_pkt_len + skb->len > sizeof(ep->mpa_pkt)) { |
| 1432 | err = -EINVAL; |
Hariprasad S | da1cecd | 2016-05-06 22:17:58 +0530 | [diff] [blame] | 1433 | goto err_stop_timer; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1434 | } |
| 1435 | |
| 1436 | /* |
| 1437 | * copy the new data into our accumulation buffer. |
| 1438 | */ |
| 1439 | skb_copy_from_linear_data(skb, &(ep->mpa_pkt[ep->mpa_pkt_len]), |
| 1440 | skb->len); |
| 1441 | ep->mpa_pkt_len += skb->len; |
| 1442 | |
| 1443 | /* |
| 1444 | * if we don't even have the mpa message, then bail. |
| 1445 | */ |
| 1446 | if (ep->mpa_pkt_len < sizeof(*mpa)) |
Steve Wise | cc18b93 | 2014-04-24 14:31:53 -0500 | [diff] [blame] | 1447 | return 0; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1448 | mpa = (struct mpa_message *) ep->mpa_pkt; |
| 1449 | |
| 1450 | /* Validate MPA header. */ |
Kumar Sanghvi | d2fe99e | 2011-09-25 20:17:44 +0530 | [diff] [blame] | 1451 | if (mpa->revision > mpa_rev) { |
| 1452 | printk(KERN_ERR MOD "%s MPA version mismatch. Local = %d," |
| 1453 | " Received = %d\n", __func__, mpa_rev, mpa->revision); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1454 | err = -EPROTO; |
Hariprasad S | da1cecd | 2016-05-06 22:17:58 +0530 | [diff] [blame] | 1455 | goto err_stop_timer; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1456 | } |
| 1457 | if (memcmp(mpa->key, MPA_KEY_REP, sizeof(mpa->key))) { |
| 1458 | err = -EPROTO; |
Hariprasad S | da1cecd | 2016-05-06 22:17:58 +0530 | [diff] [blame] | 1459 | goto err_stop_timer; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1460 | } |
| 1461 | |
| 1462 | plen = ntohs(mpa->private_data_size); |
| 1463 | |
| 1464 | /* |
| 1465 | * Fail if there's too much private data. |
| 1466 | */ |
| 1467 | if (plen > MPA_MAX_PRIVATE_DATA) { |
| 1468 | err = -EPROTO; |
Hariprasad S | da1cecd | 2016-05-06 22:17:58 +0530 | [diff] [blame] | 1469 | goto err_stop_timer; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1470 | } |
| 1471 | |
| 1472 | /* |
| 1473 | * If plen does not account for pkt size |
| 1474 | */ |
| 1475 | if (ep->mpa_pkt_len > (sizeof(*mpa) + plen)) { |
| 1476 | err = -EPROTO; |
Hariprasad S | da1cecd | 2016-05-06 22:17:58 +0530 | [diff] [blame] | 1477 | goto err_stop_timer; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1478 | } |
| 1479 | |
| 1480 | ep->plen = (u8) plen; |
| 1481 | |
| 1482 | /* |
| 1483 | * If we don't have all the pdata yet, then bail. |
| 1484 | * We'll continue process when more data arrives. |
| 1485 | */ |
| 1486 | if (ep->mpa_pkt_len < (sizeof(*mpa) + plen)) |
Steve Wise | cc18b93 | 2014-04-24 14:31:53 -0500 | [diff] [blame] | 1487 | return 0; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1488 | |
| 1489 | if (mpa->flags & MPA_REJECT) { |
| 1490 | err = -ECONNREFUSED; |
Hariprasad S | da1cecd | 2016-05-06 22:17:58 +0530 | [diff] [blame] | 1491 | goto err_stop_timer; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1492 | } |
| 1493 | |
| 1494 | /* |
Hariprasad S | da1cecd | 2016-05-06 22:17:58 +0530 | [diff] [blame] | 1495 | * Stop mpa timer. If it expired, then |
| 1496 | * we ignore the MPA reply. process_timeout() |
| 1497 | * will abort the connection. |
| 1498 | */ |
| 1499 | if (stop_ep_timer(ep)) |
| 1500 | return 0; |
| 1501 | |
| 1502 | /* |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1503 | * If we get here we have accumulated the entire mpa |
| 1504 | * start reply message including private data. And |
| 1505 | * the MPA header is valid. |
| 1506 | */ |
Steve Wise | c529fb5 | 2014-03-21 20:40:37 +0530 | [diff] [blame] | 1507 | __state_set(&ep->com, FPDU_MODE); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1508 | ep->mpa_attr.crc_enabled = (mpa->flags & MPA_CRC) | crc_enabled ? 1 : 0; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1509 | ep->mpa_attr.xmit_marker_enabled = mpa->flags & MPA_MARKERS ? 1 : 0; |
Kumar Sanghvi | d2fe99e | 2011-09-25 20:17:44 +0530 | [diff] [blame] | 1510 | ep->mpa_attr.version = mpa->revision; |
| 1511 | ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED; |
| 1512 | |
| 1513 | if (mpa->revision == 2) { |
| 1514 | ep->mpa_attr.enhanced_rdma_conn = |
| 1515 | mpa->flags & MPA_ENHANCED_RDMA_CONN ? 1 : 0; |
| 1516 | if (ep->mpa_attr.enhanced_rdma_conn) { |
| 1517 | mpa_v2_params = (struct mpa_v2_conn_params *) |
| 1518 | (ep->mpa_pkt + sizeof(*mpa)); |
| 1519 | resp_ird = ntohs(mpa_v2_params->ird) & |
| 1520 | MPA_V2_IRD_ORD_MASK; |
| 1521 | resp_ord = ntohs(mpa_v2_params->ord) & |
| 1522 | MPA_V2_IRD_ORD_MASK; |
Hariprasad Shenai | 4c2c576 | 2014-07-14 21:34:52 +0530 | [diff] [blame] | 1523 | PDBG("%s responder ird %u ord %u ep ird %u ord %u\n", |
| 1524 | __func__, resp_ird, resp_ord, ep->ird, ep->ord); |
Kumar Sanghvi | d2fe99e | 2011-09-25 20:17:44 +0530 | [diff] [blame] | 1525 | |
| 1526 | /* |
| 1527 | * This is a double-check. Ideally, below checks are |
| 1528 | * not required since ird/ord stuff has been taken |
| 1529 | * care of in c4iw_accept_cr |
| 1530 | */ |
Hariprasad Shenai | 4c2c576 | 2014-07-14 21:34:52 +0530 | [diff] [blame] | 1531 | if (ep->ird < resp_ord) { |
| 1532 | if (RELAXED_IRD_NEGOTIATION && resp_ord <= |
| 1533 | ep->com.dev->rdev.lldi.max_ordird_qp) |
| 1534 | ep->ird = resp_ord; |
| 1535 | else |
| 1536 | insuff_ird = 1; |
| 1537 | } else if (ep->ird > resp_ord) { |
| 1538 | ep->ird = resp_ord; |
| 1539 | } |
| 1540 | if (ep->ord > resp_ird) { |
| 1541 | if (RELAXED_IRD_NEGOTIATION) |
| 1542 | ep->ord = resp_ird; |
| 1543 | else |
| 1544 | insuff_ird = 1; |
| 1545 | } |
| 1546 | if (insuff_ird) { |
Kumar Sanghvi | d2fe99e | 2011-09-25 20:17:44 +0530 | [diff] [blame] | 1547 | err = -ENOMEM; |
| 1548 | ep->ird = resp_ord; |
| 1549 | ep->ord = resp_ird; |
Kumar Sanghvi | d2fe99e | 2011-09-25 20:17:44 +0530 | [diff] [blame] | 1550 | } |
| 1551 | |
| 1552 | if (ntohs(mpa_v2_params->ird) & |
| 1553 | MPA_V2_PEER2PEER_MODEL) { |
| 1554 | if (ntohs(mpa_v2_params->ord) & |
| 1555 | MPA_V2_RDMA_WRITE_RTR) |
| 1556 | ep->mpa_attr.p2p_type = |
| 1557 | FW_RI_INIT_P2PTYPE_RDMA_WRITE; |
| 1558 | else if (ntohs(mpa_v2_params->ord) & |
| 1559 | MPA_V2_RDMA_READ_RTR) |
| 1560 | ep->mpa_attr.p2p_type = |
| 1561 | FW_RI_INIT_P2PTYPE_READ_REQ; |
| 1562 | } |
| 1563 | } |
| 1564 | } else if (mpa->revision == 1) |
| 1565 | if (peer2peer) |
| 1566 | ep->mpa_attr.p2p_type = p2p_type; |
| 1567 | |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1568 | PDBG("%s - crc_enabled=%d, recv_marker_enabled=%d, " |
Kumar Sanghvi | d2fe99e | 2011-09-25 20:17:44 +0530 | [diff] [blame] | 1569 | "xmit_marker_enabled=%d, version=%d p2p_type=%d local-p2p_type = " |
| 1570 | "%d\n", __func__, ep->mpa_attr.crc_enabled, |
| 1571 | ep->mpa_attr.recv_marker_enabled, |
| 1572 | ep->mpa_attr.xmit_marker_enabled, ep->mpa_attr.version, |
| 1573 | ep->mpa_attr.p2p_type, p2p_type); |
| 1574 | |
| 1575 | /* |
| 1576 | * If responder's RTR does not match with that of initiator, assign |
| 1577 | * FW_RI_INIT_P2PTYPE_DISABLED in mpa attributes so that RTR is not |
| 1578 | * generated when moving QP to RTS state. |
| 1579 | * A TERM message will be sent after QP has moved to RTS state |
| 1580 | */ |
Kumar Sanghvi | 91018f8 | 2012-02-25 17:45:02 -0800 | [diff] [blame] | 1581 | if ((ep->mpa_attr.version == 2) && peer2peer && |
Kumar Sanghvi | d2fe99e | 2011-09-25 20:17:44 +0530 | [diff] [blame] | 1582 | (ep->mpa_attr.p2p_type != p2p_type)) { |
| 1583 | ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED; |
| 1584 | rtr_mismatch = 1; |
| 1585 | } |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1586 | |
| 1587 | attrs.mpa_attr = ep->mpa_attr; |
| 1588 | attrs.max_ird = ep->ird; |
| 1589 | attrs.max_ord = ep->ord; |
| 1590 | attrs.llp_stream_handle = ep; |
| 1591 | attrs.next_state = C4IW_QP_STATE_RTS; |
| 1592 | |
| 1593 | mask = C4IW_QP_ATTR_NEXT_STATE | |
| 1594 | C4IW_QP_ATTR_LLP_STREAM_HANDLE | C4IW_QP_ATTR_MPA_ATTR | |
| 1595 | C4IW_QP_ATTR_MAX_IRD | C4IW_QP_ATTR_MAX_ORD; |
| 1596 | |
| 1597 | /* bind QP and TID with INIT_WR */ |
| 1598 | err = c4iw_modify_qp(ep->com.qp->rhp, |
| 1599 | ep->com.qp, mask, &attrs, 1); |
| 1600 | if (err) |
| 1601 | goto err; |
Kumar Sanghvi | d2fe99e | 2011-09-25 20:17:44 +0530 | [diff] [blame] | 1602 | |
| 1603 | /* |
| 1604 | * If responder's RTR requirement did not match with what initiator |
| 1605 | * supports, generate TERM message |
| 1606 | */ |
| 1607 | if (rtr_mismatch) { |
| 1608 | printk(KERN_ERR "%s: RTR mismatch, sending TERM\n", __func__); |
| 1609 | attrs.layer_etype = LAYER_MPA | DDP_LLP; |
| 1610 | attrs.ecode = MPA_NOMATCH_RTR; |
| 1611 | attrs.next_state = C4IW_QP_STATE_TERMINATE; |
Steve Wise | cc18b93 | 2014-04-24 14:31:53 -0500 | [diff] [blame] | 1612 | attrs.send_term = 1; |
Kumar Sanghvi | d2fe99e | 2011-09-25 20:17:44 +0530 | [diff] [blame] | 1613 | err = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp, |
Steve Wise | cc18b93 | 2014-04-24 14:31:53 -0500 | [diff] [blame] | 1614 | C4IW_QP_ATTR_NEXT_STATE, &attrs, 1); |
Kumar Sanghvi | d2fe99e | 2011-09-25 20:17:44 +0530 | [diff] [blame] | 1615 | err = -ENOMEM; |
Steve Wise | cc18b93 | 2014-04-24 14:31:53 -0500 | [diff] [blame] | 1616 | disconnect = 1; |
Kumar Sanghvi | d2fe99e | 2011-09-25 20:17:44 +0530 | [diff] [blame] | 1617 | goto out; |
| 1618 | } |
| 1619 | |
| 1620 | /* |
| 1621 | * Generate TERM if initiator IRD is not sufficient for responder |
| 1622 | * provided ORD. Currently, we do the same behaviour even when |
| 1623 | * responder provided IRD is also not sufficient as regards to |
| 1624 | * initiator ORD. |
| 1625 | */ |
| 1626 | if (insuff_ird) { |
| 1627 | printk(KERN_ERR "%s: Insufficient IRD, sending TERM\n", |
| 1628 | __func__); |
| 1629 | attrs.layer_etype = LAYER_MPA | DDP_LLP; |
| 1630 | attrs.ecode = MPA_INSUFF_IRD; |
| 1631 | attrs.next_state = C4IW_QP_STATE_TERMINATE; |
Steve Wise | cc18b93 | 2014-04-24 14:31:53 -0500 | [diff] [blame] | 1632 | attrs.send_term = 1; |
Kumar Sanghvi | d2fe99e | 2011-09-25 20:17:44 +0530 | [diff] [blame] | 1633 | err = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp, |
Steve Wise | cc18b93 | 2014-04-24 14:31:53 -0500 | [diff] [blame] | 1634 | C4IW_QP_ATTR_NEXT_STATE, &attrs, 1); |
Kumar Sanghvi | d2fe99e | 2011-09-25 20:17:44 +0530 | [diff] [blame] | 1635 | err = -ENOMEM; |
Steve Wise | cc18b93 | 2014-04-24 14:31:53 -0500 | [diff] [blame] | 1636 | disconnect = 1; |
Kumar Sanghvi | d2fe99e | 2011-09-25 20:17:44 +0530 | [diff] [blame] | 1637 | goto out; |
| 1638 | } |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1639 | goto out; |
Hariprasad S | da1cecd | 2016-05-06 22:17:58 +0530 | [diff] [blame] | 1640 | err_stop_timer: |
| 1641 | stop_ep_timer(ep); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1642 | err: |
Hariprasad S | f8e1e1d | 2016-05-05 01:27:32 +0530 | [diff] [blame] | 1643 | disconnect = 2; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1644 | out: |
| 1645 | connect_reply_upcall(ep, err); |
Steve Wise | cc18b93 | 2014-04-24 14:31:53 -0500 | [diff] [blame] | 1646 | return disconnect; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1647 | } |
| 1648 | |
Hariprasad S | fd6aabe | 2016-05-05 01:27:35 +0530 | [diff] [blame] | 1649 | /* |
| 1650 | * process_mpa_request - process streaming mode MPA request |
| 1651 | * |
| 1652 | * Returns: |
| 1653 | * |
| 1654 | * 0 upon success indicating a connect request was delivered to the ULP |
| 1655 | * or the mpa request is incomplete but valid so far. |
| 1656 | * |
| 1657 | * 1 if a failure requires the caller to close the connection. |
| 1658 | * |
| 1659 | * 2 if a failure requires the caller to abort the connection. |
| 1660 | */ |
| 1661 | static int process_mpa_request(struct c4iw_ep *ep, struct sk_buff *skb) |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1662 | { |
| 1663 | struct mpa_message *mpa; |
Kumar Sanghvi | d2fe99e | 2011-09-25 20:17:44 +0530 | [diff] [blame] | 1664 | struct mpa_v2_conn_params *mpa_v2_params; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1665 | u16 plen; |
| 1666 | |
| 1667 | PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid); |
| 1668 | |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1669 | /* |
| 1670 | * If we get more than the supported amount of private data |
| 1671 | * then we must fail this connection. |
| 1672 | */ |
Hariprasad S | fd6aabe | 2016-05-05 01:27:35 +0530 | [diff] [blame] | 1673 | if (ep->mpa_pkt_len + skb->len > sizeof(ep->mpa_pkt)) |
| 1674 | goto err_stop_timer; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1675 | |
| 1676 | PDBG("%s enter (%s line %u)\n", __func__, __FILE__, __LINE__); |
| 1677 | |
| 1678 | /* |
| 1679 | * Copy the new data into our accumulation buffer. |
| 1680 | */ |
| 1681 | skb_copy_from_linear_data(skb, &(ep->mpa_pkt[ep->mpa_pkt_len]), |
| 1682 | skb->len); |
| 1683 | ep->mpa_pkt_len += skb->len; |
| 1684 | |
| 1685 | /* |
| 1686 | * If we don't even have the mpa message, then bail. |
| 1687 | * We'll continue process when more data arrives. |
| 1688 | */ |
| 1689 | if (ep->mpa_pkt_len < sizeof(*mpa)) |
Hariprasad S | fd6aabe | 2016-05-05 01:27:35 +0530 | [diff] [blame] | 1690 | return 0; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1691 | |
| 1692 | PDBG("%s enter (%s line %u)\n", __func__, __FILE__, __LINE__); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1693 | mpa = (struct mpa_message *) ep->mpa_pkt; |
| 1694 | |
| 1695 | /* |
| 1696 | * Validate MPA Header. |
| 1697 | */ |
Kumar Sanghvi | d2fe99e | 2011-09-25 20:17:44 +0530 | [diff] [blame] | 1698 | if (mpa->revision > mpa_rev) { |
| 1699 | printk(KERN_ERR MOD "%s MPA version mismatch. Local = %d," |
| 1700 | " Received = %d\n", __func__, mpa_rev, mpa->revision); |
Hariprasad S | fd6aabe | 2016-05-05 01:27:35 +0530 | [diff] [blame] | 1701 | goto err_stop_timer; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1702 | } |
| 1703 | |
Hariprasad S | fd6aabe | 2016-05-05 01:27:35 +0530 | [diff] [blame] | 1704 | if (memcmp(mpa->key, MPA_KEY_REQ, sizeof(mpa->key))) |
| 1705 | goto err_stop_timer; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1706 | |
| 1707 | plen = ntohs(mpa->private_data_size); |
| 1708 | |
| 1709 | /* |
| 1710 | * Fail if there's too much private data. |
| 1711 | */ |
Hariprasad S | fd6aabe | 2016-05-05 01:27:35 +0530 | [diff] [blame] | 1712 | if (plen > MPA_MAX_PRIVATE_DATA) |
| 1713 | goto err_stop_timer; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1714 | |
| 1715 | /* |
| 1716 | * If plen does not account for pkt size |
| 1717 | */ |
Hariprasad S | fd6aabe | 2016-05-05 01:27:35 +0530 | [diff] [blame] | 1718 | if (ep->mpa_pkt_len > (sizeof(*mpa) + plen)) |
| 1719 | goto err_stop_timer; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1720 | ep->plen = (u8) plen; |
| 1721 | |
| 1722 | /* |
| 1723 | * If we don't have all the pdata yet, then bail. |
| 1724 | */ |
| 1725 | if (ep->mpa_pkt_len < (sizeof(*mpa) + plen)) |
Hariprasad S | fd6aabe | 2016-05-05 01:27:35 +0530 | [diff] [blame] | 1726 | return 0; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1727 | |
| 1728 | /* |
| 1729 | * If we get here we have accumulated the entire mpa |
| 1730 | * start reply message including private data. |
| 1731 | */ |
| 1732 | ep->mpa_attr.initiator = 0; |
| 1733 | ep->mpa_attr.crc_enabled = (mpa->flags & MPA_CRC) | crc_enabled ? 1 : 0; |
| 1734 | ep->mpa_attr.recv_marker_enabled = markers_enabled; |
| 1735 | ep->mpa_attr.xmit_marker_enabled = mpa->flags & MPA_MARKERS ? 1 : 0; |
Kumar Sanghvi | d2fe99e | 2011-09-25 20:17:44 +0530 | [diff] [blame] | 1736 | ep->mpa_attr.version = mpa->revision; |
| 1737 | if (mpa->revision == 1) |
| 1738 | ep->tried_with_mpa_v1 = 1; |
| 1739 | ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED; |
| 1740 | |
| 1741 | if (mpa->revision == 2) { |
| 1742 | ep->mpa_attr.enhanced_rdma_conn = |
| 1743 | mpa->flags & MPA_ENHANCED_RDMA_CONN ? 1 : 0; |
| 1744 | if (ep->mpa_attr.enhanced_rdma_conn) { |
| 1745 | mpa_v2_params = (struct mpa_v2_conn_params *) |
| 1746 | (ep->mpa_pkt + sizeof(*mpa)); |
| 1747 | ep->ird = ntohs(mpa_v2_params->ird) & |
| 1748 | MPA_V2_IRD_ORD_MASK; |
Steve Wise | 7f446ab | 2016-08-19 07:29:07 -0700 | [diff] [blame] | 1749 | ep->ird = min_t(u32, ep->ird, |
| 1750 | cur_max_read_depth(ep->com.dev)); |
Kumar Sanghvi | d2fe99e | 2011-09-25 20:17:44 +0530 | [diff] [blame] | 1751 | ep->ord = ntohs(mpa_v2_params->ord) & |
| 1752 | MPA_V2_IRD_ORD_MASK; |
Steve Wise | 7f446ab | 2016-08-19 07:29:07 -0700 | [diff] [blame] | 1753 | ep->ord = min_t(u32, ep->ord, |
| 1754 | cur_max_read_depth(ep->com.dev)); |
Hariprasad Shenai | 4c2c576 | 2014-07-14 21:34:52 +0530 | [diff] [blame] | 1755 | PDBG("%s initiator ird %u ord %u\n", __func__, ep->ird, |
| 1756 | ep->ord); |
Kumar Sanghvi | d2fe99e | 2011-09-25 20:17:44 +0530 | [diff] [blame] | 1757 | if (ntohs(mpa_v2_params->ird) & MPA_V2_PEER2PEER_MODEL) |
| 1758 | if (peer2peer) { |
| 1759 | if (ntohs(mpa_v2_params->ord) & |
| 1760 | MPA_V2_RDMA_WRITE_RTR) |
| 1761 | ep->mpa_attr.p2p_type = |
| 1762 | FW_RI_INIT_P2PTYPE_RDMA_WRITE; |
| 1763 | else if (ntohs(mpa_v2_params->ord) & |
| 1764 | MPA_V2_RDMA_READ_RTR) |
| 1765 | ep->mpa_attr.p2p_type = |
| 1766 | FW_RI_INIT_P2PTYPE_READ_REQ; |
| 1767 | } |
| 1768 | } |
| 1769 | } else if (mpa->revision == 1) |
| 1770 | if (peer2peer) |
| 1771 | ep->mpa_attr.p2p_type = p2p_type; |
| 1772 | |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1773 | PDBG("%s - crc_enabled=%d, recv_marker_enabled=%d, " |
| 1774 | "xmit_marker_enabled=%d, version=%d p2p_type=%d\n", __func__, |
| 1775 | ep->mpa_attr.crc_enabled, ep->mpa_attr.recv_marker_enabled, |
| 1776 | ep->mpa_attr.xmit_marker_enabled, ep->mpa_attr.version, |
| 1777 | ep->mpa_attr.p2p_type); |
| 1778 | |
Hariprasad S | e4b76a2 | 2016-05-06 22:17:59 +0530 | [diff] [blame] | 1779 | __state_set(&ep->com, MPA_REQ_RCVD); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1780 | |
Hariprasad S | e4b76a2 | 2016-05-06 22:17:59 +0530 | [diff] [blame] | 1781 | /* drive upcall */ |
| 1782 | mutex_lock_nested(&ep->parent_ep->com.mutex, SINGLE_DEPTH_NESTING); |
| 1783 | if (ep->parent_ep->com.state != DEAD) { |
| 1784 | if (connect_request_upcall(ep)) |
Hariprasad S | fd6aabe | 2016-05-05 01:27:35 +0530 | [diff] [blame] | 1785 | goto err_unlock_parent; |
Hariprasad S | e4b76a2 | 2016-05-06 22:17:59 +0530 | [diff] [blame] | 1786 | } else { |
| 1787 | goto err_unlock_parent; |
Steve Wise | be13b2d | 2014-03-21 20:40:33 +0530 | [diff] [blame] | 1788 | } |
Hariprasad S | e4b76a2 | 2016-05-06 22:17:59 +0530 | [diff] [blame] | 1789 | mutex_unlock(&ep->parent_ep->com.mutex); |
Hariprasad S | fd6aabe | 2016-05-05 01:27:35 +0530 | [diff] [blame] | 1790 | return 0; |
| 1791 | |
| 1792 | err_unlock_parent: |
| 1793 | mutex_unlock(&ep->parent_ep->com.mutex); |
| 1794 | goto err_out; |
| 1795 | err_stop_timer: |
| 1796 | (void)stop_ep_timer(ep); |
| 1797 | err_out: |
| 1798 | return 2; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1799 | } |
| 1800 | |
| 1801 | static int rx_data(struct c4iw_dev *dev, struct sk_buff *skb) |
| 1802 | { |
| 1803 | struct c4iw_ep *ep; |
| 1804 | struct cpl_rx_data *hdr = cplhdr(skb); |
| 1805 | unsigned int dlen = ntohs(hdr->len); |
| 1806 | unsigned int tid = GET_TID(hdr); |
Vipul Pandya | 793dad9 | 2012-12-10 09:30:56 +0000 | [diff] [blame] | 1807 | __u8 status = hdr->status; |
Steve Wise | cc18b93 | 2014-04-24 14:31:53 -0500 | [diff] [blame] | 1808 | int disconnect = 0; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1809 | |
Hariprasad S | 944661d | 2016-05-06 22:18:03 +0530 | [diff] [blame] | 1810 | ep = get_ep_from_tid(dev, tid); |
Steve Wise | 977116c | 2014-03-21 20:40:36 +0530 | [diff] [blame] | 1811 | if (!ep) |
| 1812 | return 0; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1813 | PDBG("%s ep %p tid %u dlen %u\n", __func__, ep, ep->hwtid, dlen); |
| 1814 | skb_pull(skb, sizeof(*hdr)); |
| 1815 | skb_trim(skb, dlen); |
Steve Wise | c529fb5 | 2014-03-21 20:40:37 +0530 | [diff] [blame] | 1816 | mutex_lock(&ep->com.mutex); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1817 | |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1818 | /* update RX credits */ |
| 1819 | update_rx_credits(ep, dlen); |
| 1820 | |
Steve Wise | c529fb5 | 2014-03-21 20:40:37 +0530 | [diff] [blame] | 1821 | switch (ep->com.state) { |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1822 | case MPA_REQ_SENT: |
Vipul Pandya | 55abf8d | 2013-01-07 13:11:50 +0000 | [diff] [blame] | 1823 | ep->rcv_seq += dlen; |
Steve Wise | cc18b93 | 2014-04-24 14:31:53 -0500 | [diff] [blame] | 1824 | disconnect = process_mpa_reply(ep, skb); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1825 | break; |
| 1826 | case MPA_REQ_WAIT: |
Vipul Pandya | 55abf8d | 2013-01-07 13:11:50 +0000 | [diff] [blame] | 1827 | ep->rcv_seq += dlen; |
Hariprasad S | 4a4dd8d | 2016-05-06 22:18:08 +0530 | [diff] [blame] | 1828 | disconnect = process_mpa_request(ep, skb); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1829 | break; |
Vipul Pandya | 1557967 | 2013-01-07 13:11:52 +0000 | [diff] [blame] | 1830 | case FPDU_MODE: { |
| 1831 | struct c4iw_qp_attributes attrs; |
| 1832 | BUG_ON(!ep->com.qp); |
Vipul Pandya | e8e5b92 | 2013-01-07 13:11:55 +0000 | [diff] [blame] | 1833 | if (status) |
Vipul Pandya | 1557967 | 2013-01-07 13:11:52 +0000 | [diff] [blame] | 1834 | pr_err("%s Unexpected streaming data." \ |
Vipul Pandya | 04236df | 2013-01-07 13:11:54 +0000 | [diff] [blame] | 1835 | " qpid %u ep %p state %d tid %u status %d\n", |
| 1836 | __func__, ep->com.qp->wq.sq.qid, ep, |
Steve Wise | c529fb5 | 2014-03-21 20:40:37 +0530 | [diff] [blame] | 1837 | ep->com.state, ep->hwtid, status); |
Steve Wise | 97d7ec0 | 2013-08-06 21:04:34 +0530 | [diff] [blame] | 1838 | attrs.next_state = C4IW_QP_STATE_TERMINATE; |
Vipul Pandya | 1557967 | 2013-01-07 13:11:52 +0000 | [diff] [blame] | 1839 | c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp, |
Steve Wise | cc18b93 | 2014-04-24 14:31:53 -0500 | [diff] [blame] | 1840 | C4IW_QP_ATTR_NEXT_STATE, &attrs, 1); |
| 1841 | disconnect = 1; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1842 | break; |
| 1843 | } |
Vipul Pandya | 1557967 | 2013-01-07 13:11:52 +0000 | [diff] [blame] | 1844 | default: |
| 1845 | break; |
| 1846 | } |
Steve Wise | c529fb5 | 2014-03-21 20:40:37 +0530 | [diff] [blame] | 1847 | mutex_unlock(&ep->com.mutex); |
Steve Wise | cc18b93 | 2014-04-24 14:31:53 -0500 | [diff] [blame] | 1848 | if (disconnect) |
Hariprasad S | 4a4dd8d | 2016-05-06 22:18:08 +0530 | [diff] [blame] | 1849 | c4iw_ep_disconnect(ep, disconnect == 2, GFP_KERNEL); |
Hariprasad S | 944661d | 2016-05-06 22:18:03 +0530 | [diff] [blame] | 1850 | c4iw_put_ep(&ep->com); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1851 | return 0; |
| 1852 | } |
| 1853 | |
| 1854 | static int abort_rpl(struct c4iw_dev *dev, struct sk_buff *skb) |
| 1855 | { |
| 1856 | struct c4iw_ep *ep; |
| 1857 | struct cpl_abort_rpl_rss *rpl = cplhdr(skb); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1858 | int release = 0; |
| 1859 | unsigned int tid = GET_TID(rpl); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1860 | |
Hariprasad S | 944661d | 2016-05-06 22:18:03 +0530 | [diff] [blame] | 1861 | ep = get_ep_from_tid(dev, tid); |
Vipul Pandya | 4984037 | 2012-05-18 15:29:29 +0530 | [diff] [blame] | 1862 | if (!ep) { |
| 1863 | printk(KERN_WARNING MOD "Abort rpl to freed endpoint\n"); |
| 1864 | return 0; |
| 1865 | } |
Wei Yongjun | 92dd6c3 | 2012-09-07 06:51:23 +0000 | [diff] [blame] | 1866 | PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid); |
Steve Wise | 2f5b48c | 2010-09-10 11:15:36 -0500 | [diff] [blame] | 1867 | mutex_lock(&ep->com.mutex); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1868 | switch (ep->com.state) { |
| 1869 | case ABORTING: |
Vipul Pandya | 91e9c071 | 2013-01-07 13:11:51 +0000 | [diff] [blame] | 1870 | c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1871 | __state_set(&ep->com, DEAD); |
| 1872 | release = 1; |
| 1873 | break; |
| 1874 | default: |
| 1875 | printk(KERN_ERR "%s ep %p state %d\n", |
| 1876 | __func__, ep, ep->com.state); |
| 1877 | break; |
| 1878 | } |
Steve Wise | 2f5b48c | 2010-09-10 11:15:36 -0500 | [diff] [blame] | 1879 | mutex_unlock(&ep->com.mutex); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1880 | |
| 1881 | if (release) |
| 1882 | release_ep_resources(ep); |
Hariprasad S | 944661d | 2016-05-06 22:18:03 +0530 | [diff] [blame] | 1883 | c4iw_put_ep(&ep->com); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1884 | return 0; |
| 1885 | } |
| 1886 | |
Hariprasad S | caa6c9f | 2016-05-06 22:18:00 +0530 | [diff] [blame] | 1887 | static int send_fw_act_open_req(struct c4iw_ep *ep, unsigned int atid) |
Vipul Pandya | 5be78ee | 2012-12-10 09:30:54 +0000 | [diff] [blame] | 1888 | { |
| 1889 | struct sk_buff *skb; |
| 1890 | struct fw_ofld_connection_wr *req; |
| 1891 | unsigned int mtu_idx; |
Varun Prakash | cc51670 | 2016-09-13 21:24:01 +0530 | [diff] [blame] | 1892 | u32 wscale; |
Vipul Pandya | 830662f | 2013-07-04 16:10:47 +0530 | [diff] [blame] | 1893 | struct sockaddr_in *sin; |
Hariprasad Shenai | b408ff2 | 2014-06-06 21:40:44 +0530 | [diff] [blame] | 1894 | int win; |
Vipul Pandya | 5be78ee | 2012-12-10 09:30:54 +0000 | [diff] [blame] | 1895 | |
| 1896 | skb = get_skb(NULL, sizeof(*req), GFP_KERNEL); |
| 1897 | req = (struct fw_ofld_connection_wr *)__skb_put(skb, sizeof(*req)); |
| 1898 | memset(req, 0, sizeof(*req)); |
Hariprasad Shenai | 6c53e93 | 2015-01-08 21:38:15 -0800 | [diff] [blame] | 1899 | req->op_compl = htonl(WR_OP_V(FW_OFLD_CONNECTION_WR)); |
Hariprasad Shenai | e2ac962 | 2014-11-07 09:35:25 +0530 | [diff] [blame] | 1900 | req->len16_pkd = htonl(FW_WR_LEN16_V(DIV_ROUND_UP(sizeof(*req), 16))); |
Kumar Sanghvi | 41b4f86 | 2013-12-18 16:38:26 +0530 | [diff] [blame] | 1901 | req->le.filter = cpu_to_be32(cxgb4_select_ntuple( |
| 1902 | ep->com.dev->rdev.lldi.ports[0], |
Vipul Pandya | 5be78ee | 2012-12-10 09:30:54 +0000 | [diff] [blame] | 1903 | ep->l2t)); |
Steve Wise | 170003c | 2016-02-26 09:18:03 -0600 | [diff] [blame] | 1904 | sin = (struct sockaddr_in *)&ep->com.local_addr; |
Vipul Pandya | 830662f | 2013-07-04 16:10:47 +0530 | [diff] [blame] | 1905 | req->le.lport = sin->sin_port; |
| 1906 | req->le.u.ipv4.lip = sin->sin_addr.s_addr; |
Steve Wise | 170003c | 2016-02-26 09:18:03 -0600 | [diff] [blame] | 1907 | sin = (struct sockaddr_in *)&ep->com.remote_addr; |
Vipul Pandya | 830662f | 2013-07-04 16:10:47 +0530 | [diff] [blame] | 1908 | req->le.pport = sin->sin_port; |
| 1909 | req->le.u.ipv4.pip = sin->sin_addr.s_addr; |
Vipul Pandya | 5be78ee | 2012-12-10 09:30:54 +0000 | [diff] [blame] | 1910 | req->tcb.t_state_to_astid = |
Hariprasad Shenai | 77a80e2 | 2014-11-21 12:52:01 +0530 | [diff] [blame] | 1911 | htonl(FW_OFLD_CONNECTION_WR_T_STATE_V(TCP_SYN_SENT) | |
| 1912 | FW_OFLD_CONNECTION_WR_ASTID_V(atid)); |
Vipul Pandya | 5be78ee | 2012-12-10 09:30:54 +0000 | [diff] [blame] | 1913 | req->tcb.cplrxdataack_cplpassacceptrpl = |
Hariprasad Shenai | 77a80e2 | 2014-11-21 12:52:01 +0530 | [diff] [blame] | 1914 | htons(FW_OFLD_CONNECTION_WR_CPLRXDATAACK_F); |
Vipul Pandya | ef5d635 | 2013-01-07 13:12:00 +0000 | [diff] [blame] | 1915 | req->tcb.tx_max = (__force __be32) jiffies; |
Vipul Pandya | 793dad9 | 2012-12-10 09:30:56 +0000 | [diff] [blame] | 1916 | req->tcb.rcv_adv = htons(1); |
Varun Prakash | 44c6d06 | 2016-09-13 21:24:00 +0530 | [diff] [blame] | 1917 | cxgb_best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx, |
| 1918 | enable_tcp_timestamps, |
| 1919 | (ep->com.remote_addr.ss_family == AF_INET) ? 0 : 1); |
Varun Prakash | cc51670 | 2016-09-13 21:24:01 +0530 | [diff] [blame] | 1920 | wscale = cxgb_compute_wscale(rcv_win); |
Hariprasad Shenai | b408ff2 | 2014-06-06 21:40:44 +0530 | [diff] [blame] | 1921 | |
| 1922 | /* |
| 1923 | * Specify the largest window that will fit in opt0. The |
| 1924 | * remainder will be specified in the rx_data_ack. |
| 1925 | */ |
| 1926 | win = ep->rcv_win >> 10; |
Anish Bhatt | d7990b0 | 2014-11-12 17:15:57 -0800 | [diff] [blame] | 1927 | if (win > RCV_BUFSIZ_M) |
| 1928 | win = RCV_BUFSIZ_M; |
Hariprasad Shenai | b408ff2 | 2014-06-06 21:40:44 +0530 | [diff] [blame] | 1929 | |
Hariprasad Shenai | 6c53e93 | 2015-01-08 21:38:15 -0800 | [diff] [blame] | 1930 | req->tcb.opt0 = (__force __be64) (TCAM_BYPASS_F | |
| 1931 | (nocong ? NO_CONG_F : 0) | |
Anish Bhatt | d7990b0 | 2014-11-12 17:15:57 -0800 | [diff] [blame] | 1932 | KEEP_ALIVE_F | |
Hariprasad Shenai | 6c53e93 | 2015-01-08 21:38:15 -0800 | [diff] [blame] | 1933 | DELACK_F | |
Anish Bhatt | d7990b0 | 2014-11-12 17:15:57 -0800 | [diff] [blame] | 1934 | WND_SCALE_V(wscale) | |
| 1935 | MSS_IDX_V(mtu_idx) | |
| 1936 | L2T_IDX_V(ep->l2t->idx) | |
| 1937 | TX_CHAN_V(ep->tx_chan) | |
| 1938 | SMAC_SEL_V(ep->smac_idx) | |
Hariprasad S | ac8e4c6 | 2016-02-05 11:43:30 +0530 | [diff] [blame] | 1939 | DSCP_V(ep->tos >> 2) | |
Anish Bhatt | d7990b0 | 2014-11-12 17:15:57 -0800 | [diff] [blame] | 1940 | ULP_MODE_V(ULP_MODE_TCPDDP) | |
| 1941 | RCV_BUFSIZ_V(win)); |
Hariprasad Shenai | 6c53e93 | 2015-01-08 21:38:15 -0800 | [diff] [blame] | 1942 | req->tcb.opt2 = (__force __be32) (PACE_V(1) | |
| 1943 | TX_QUEUE_V(ep->com.dev->rdev.lldi.tx_modq[ep->tx_chan]) | |
Anish Bhatt | d7990b0 | 2014-11-12 17:15:57 -0800 | [diff] [blame] | 1944 | RX_CHANNEL_V(0) | |
Hariprasad Shenai | 6c53e93 | 2015-01-08 21:38:15 -0800 | [diff] [blame] | 1945 | CCTRL_ECN_V(enable_ecn) | |
Anish Bhatt | d7990b0 | 2014-11-12 17:15:57 -0800 | [diff] [blame] | 1946 | RSS_QUEUE_VALID_F | RSS_QUEUE_V(ep->rss_qid)); |
Vipul Pandya | 5be78ee | 2012-12-10 09:30:54 +0000 | [diff] [blame] | 1947 | if (enable_tcp_timestamps) |
Hariprasad Shenai | 6c53e93 | 2015-01-08 21:38:15 -0800 | [diff] [blame] | 1948 | req->tcb.opt2 |= (__force __be32)TSTAMPS_EN_F; |
Vipul Pandya | 5be78ee | 2012-12-10 09:30:54 +0000 | [diff] [blame] | 1949 | if (enable_tcp_sack) |
Hariprasad Shenai | 6c53e93 | 2015-01-08 21:38:15 -0800 | [diff] [blame] | 1950 | req->tcb.opt2 |= (__force __be32)SACK_EN_F; |
Vipul Pandya | 5be78ee | 2012-12-10 09:30:54 +0000 | [diff] [blame] | 1951 | if (wscale && enable_tcp_window_scaling) |
Anish Bhatt | d7990b0 | 2014-11-12 17:15:57 -0800 | [diff] [blame] | 1952 | req->tcb.opt2 |= (__force __be32)WND_SCALE_EN_F; |
| 1953 | req->tcb.opt0 = cpu_to_be64((__force u64)req->tcb.opt0); |
| 1954 | req->tcb.opt2 = cpu_to_be32((__force u32)req->tcb.opt2); |
Vipul Pandya | 793dad9 | 2012-12-10 09:30:56 +0000 | [diff] [blame] | 1955 | set_wr_txq(skb, CPL_PRIORITY_CONTROL, ep->ctrlq_idx); |
| 1956 | set_bit(ACT_OFLD_CONN, &ep->com.history); |
Hariprasad S | caa6c9f | 2016-05-06 22:18:00 +0530 | [diff] [blame] | 1957 | return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t); |
Vipul Pandya | 5be78ee | 2012-12-10 09:30:54 +0000 | [diff] [blame] | 1958 | } |
| 1959 | |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1960 | /* |
Hariprasad S | 4c72efe | 2016-06-10 01:05:14 +0530 | [diff] [blame] | 1961 | * Some of the error codes above implicitly indicate that there is no TID |
| 1962 | * allocated with the result of an ACT_OPEN. We use this predicate to make |
| 1963 | * that explicit. |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1964 | */ |
| 1965 | static inline int act_open_has_tid(int status) |
| 1966 | { |
Hariprasad S | 4c72efe | 2016-06-10 01:05:14 +0530 | [diff] [blame] | 1967 | return (status != CPL_ERR_TCAM_PARITY && |
| 1968 | status != CPL_ERR_TCAM_MISS && |
| 1969 | status != CPL_ERR_TCAM_FULL && |
| 1970 | status != CPL_ERR_CONN_EXIST_SYNRECV && |
| 1971 | status != CPL_ERR_CONN_EXIST); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1972 | } |
| 1973 | |
Hariprasad Shenai | dd92b12 | 2014-07-21 20:55:13 +0530 | [diff] [blame] | 1974 | static char *neg_adv_str(unsigned int status) |
| 1975 | { |
| 1976 | switch (status) { |
| 1977 | case CPL_ERR_RTX_NEG_ADVICE: |
| 1978 | return "Retransmit timeout"; |
| 1979 | case CPL_ERR_PERSIST_NEG_ADVICE: |
| 1980 | return "Persist timeout"; |
| 1981 | case CPL_ERR_KEEPALV_NEG_ADVICE: |
| 1982 | return "Keepalive timeout"; |
| 1983 | default: |
| 1984 | return "Unknown"; |
| 1985 | } |
| 1986 | } |
| 1987 | |
Hariprasad Shenai | b408ff2 | 2014-06-06 21:40:44 +0530 | [diff] [blame] | 1988 | static void set_tcp_window(struct c4iw_ep *ep, struct port_info *pi) |
| 1989 | { |
| 1990 | ep->snd_win = snd_win; |
| 1991 | ep->rcv_win = rcv_win; |
| 1992 | PDBG("%s snd_win %d rcv_win %d\n", __func__, ep->snd_win, ep->rcv_win); |
| 1993 | } |
| 1994 | |
Vipul Pandya | 793dad9 | 2012-12-10 09:30:56 +0000 | [diff] [blame] | 1995 | #define ACT_OPEN_RETRY_COUNT 2 |
| 1996 | |
Vipul Pandya | 830662f | 2013-07-04 16:10:47 +0530 | [diff] [blame] | 1997 | static int import_ep(struct c4iw_ep *ep, int iptype, __u8 *peer_ip, |
| 1998 | struct dst_entry *dst, struct c4iw_dev *cdev, |
Hariprasad S | ac8e4c6 | 2016-02-05 11:43:30 +0530 | [diff] [blame] | 1999 | bool clear_mpa_v1, enum chip_type adapter_type, u8 tos) |
Vipul Pandya | 830662f | 2013-07-04 16:10:47 +0530 | [diff] [blame] | 2000 | { |
| 2001 | struct neighbour *n; |
| 2002 | int err, step; |
| 2003 | struct net_device *pdev; |
| 2004 | |
| 2005 | n = dst_neigh_lookup(dst, peer_ip); |
| 2006 | if (!n) |
| 2007 | return -ENODEV; |
| 2008 | |
| 2009 | rcu_read_lock(); |
| 2010 | err = -ENOMEM; |
| 2011 | if (n->dev->flags & IFF_LOOPBACK) { |
| 2012 | if (iptype == 4) |
| 2013 | pdev = ip_dev_find(&init_net, *(__be32 *)peer_ip); |
| 2014 | else if (IS_ENABLED(CONFIG_IPV6)) |
| 2015 | for_each_netdev(&init_net, pdev) { |
| 2016 | if (ipv6_chk_addr(&init_net, |
| 2017 | (struct in6_addr *)peer_ip, |
| 2018 | pdev, 1)) |
| 2019 | break; |
| 2020 | } |
| 2021 | else |
| 2022 | pdev = NULL; |
| 2023 | |
| 2024 | if (!pdev) { |
| 2025 | err = -ENODEV; |
| 2026 | goto out; |
| 2027 | } |
| 2028 | ep->l2t = cxgb4_l2t_get(cdev->rdev.lldi.l2t, |
Hariprasad S | ac8e4c6 | 2016-02-05 11:43:30 +0530 | [diff] [blame] | 2029 | n, pdev, rt_tos2priority(tos)); |
Vipul Pandya | 830662f | 2013-07-04 16:10:47 +0530 | [diff] [blame] | 2030 | if (!ep->l2t) |
| 2031 | goto out; |
| 2032 | ep->mtu = pdev->mtu; |
| 2033 | ep->tx_chan = cxgb4_port_chan(pdev); |
Hariprasad S | 963cab5 | 2015-09-23 17:19:27 +0530 | [diff] [blame] | 2034 | ep->smac_idx = cxgb4_tp_smt_idx(adapter_type, |
| 2035 | cxgb4_port_viid(pdev)); |
Vipul Pandya | 830662f | 2013-07-04 16:10:47 +0530 | [diff] [blame] | 2036 | step = cdev->rdev.lldi.ntxq / |
| 2037 | cdev->rdev.lldi.nchan; |
| 2038 | ep->txq_idx = cxgb4_port_idx(pdev) * step; |
| 2039 | step = cdev->rdev.lldi.nrxq / |
| 2040 | cdev->rdev.lldi.nchan; |
| 2041 | ep->ctrlq_idx = cxgb4_port_idx(pdev); |
| 2042 | ep->rss_qid = cdev->rdev.lldi.rxq_ids[ |
| 2043 | cxgb4_port_idx(pdev) * step]; |
Hariprasad Shenai | b408ff2 | 2014-06-06 21:40:44 +0530 | [diff] [blame] | 2044 | set_tcp_window(ep, (struct port_info *)netdev_priv(pdev)); |
Vipul Pandya | 830662f | 2013-07-04 16:10:47 +0530 | [diff] [blame] | 2045 | dev_put(pdev); |
| 2046 | } else { |
| 2047 | pdev = get_real_dev(n->dev); |
| 2048 | ep->l2t = cxgb4_l2t_get(cdev->rdev.lldi.l2t, |
| 2049 | n, pdev, 0); |
| 2050 | if (!ep->l2t) |
| 2051 | goto out; |
| 2052 | ep->mtu = dst_mtu(dst); |
Steve Wise | 11b8e22 | 2014-05-16 12:42:46 -0500 | [diff] [blame] | 2053 | ep->tx_chan = cxgb4_port_chan(pdev); |
Hariprasad S | 963cab5 | 2015-09-23 17:19:27 +0530 | [diff] [blame] | 2054 | ep->smac_idx = cxgb4_tp_smt_idx(adapter_type, |
| 2055 | cxgb4_port_viid(pdev)); |
Vipul Pandya | 830662f | 2013-07-04 16:10:47 +0530 | [diff] [blame] | 2056 | step = cdev->rdev.lldi.ntxq / |
| 2057 | cdev->rdev.lldi.nchan; |
Steve Wise | 11b8e22 | 2014-05-16 12:42:46 -0500 | [diff] [blame] | 2058 | ep->txq_idx = cxgb4_port_idx(pdev) * step; |
| 2059 | ep->ctrlq_idx = cxgb4_port_idx(pdev); |
Vipul Pandya | 830662f | 2013-07-04 16:10:47 +0530 | [diff] [blame] | 2060 | step = cdev->rdev.lldi.nrxq / |
| 2061 | cdev->rdev.lldi.nchan; |
| 2062 | ep->rss_qid = cdev->rdev.lldi.rxq_ids[ |
Steve Wise | 11b8e22 | 2014-05-16 12:42:46 -0500 | [diff] [blame] | 2063 | cxgb4_port_idx(pdev) * step]; |
Hariprasad Shenai | b408ff2 | 2014-06-06 21:40:44 +0530 | [diff] [blame] | 2064 | set_tcp_window(ep, (struct port_info *)netdev_priv(pdev)); |
Vipul Pandya | 830662f | 2013-07-04 16:10:47 +0530 | [diff] [blame] | 2065 | |
| 2066 | if (clear_mpa_v1) { |
| 2067 | ep->retry_with_mpa_v1 = 0; |
| 2068 | ep->tried_with_mpa_v1 = 0; |
| 2069 | } |
| 2070 | } |
| 2071 | err = 0; |
| 2072 | out: |
| 2073 | rcu_read_unlock(); |
| 2074 | |
| 2075 | neigh_release(n); |
| 2076 | |
| 2077 | return err; |
| 2078 | } |
| 2079 | |
Vipul Pandya | 793dad9 | 2012-12-10 09:30:56 +0000 | [diff] [blame] | 2080 | static int c4iw_reconnect(struct c4iw_ep *ep) |
| 2081 | { |
| 2082 | int err = 0; |
Hariprasad S | 4a74083 | 2016-06-10 01:05:15 +0530 | [diff] [blame] | 2083 | int size = 0; |
Steve Wise | 24d44a3 | 2013-07-04 16:10:44 +0530 | [diff] [blame] | 2084 | struct sockaddr_in *laddr = (struct sockaddr_in *) |
Steve Wise | 170003c | 2016-02-26 09:18:03 -0600 | [diff] [blame] | 2085 | &ep->com.cm_id->m_local_addr; |
Steve Wise | 24d44a3 | 2013-07-04 16:10:44 +0530 | [diff] [blame] | 2086 | struct sockaddr_in *raddr = (struct sockaddr_in *) |
Steve Wise | 170003c | 2016-02-26 09:18:03 -0600 | [diff] [blame] | 2087 | &ep->com.cm_id->m_remote_addr; |
Vipul Pandya | 830662f | 2013-07-04 16:10:47 +0530 | [diff] [blame] | 2088 | struct sockaddr_in6 *laddr6 = (struct sockaddr_in6 *) |
Steve Wise | 170003c | 2016-02-26 09:18:03 -0600 | [diff] [blame] | 2089 | &ep->com.cm_id->m_local_addr; |
Vipul Pandya | 830662f | 2013-07-04 16:10:47 +0530 | [diff] [blame] | 2090 | struct sockaddr_in6 *raddr6 = (struct sockaddr_in6 *) |
Steve Wise | 170003c | 2016-02-26 09:18:03 -0600 | [diff] [blame] | 2091 | &ep->com.cm_id->m_remote_addr; |
Vipul Pandya | 830662f | 2013-07-04 16:10:47 +0530 | [diff] [blame] | 2092 | int iptype; |
| 2093 | __u8 *ra; |
Vipul Pandya | 793dad9 | 2012-12-10 09:30:56 +0000 | [diff] [blame] | 2094 | |
| 2095 | PDBG("%s qp %p cm_id %p\n", __func__, ep->com.qp, ep->com.cm_id); |
| 2096 | init_timer(&ep->timer); |
Hariprasad S | 093108c | 2016-05-06 22:18:09 +0530 | [diff] [blame] | 2097 | c4iw_init_wr_wait(&ep->com.wr_wait); |
Vipul Pandya | 793dad9 | 2012-12-10 09:30:56 +0000 | [diff] [blame] | 2098 | |
Hariprasad S | 4a74083 | 2016-06-10 01:05:15 +0530 | [diff] [blame] | 2099 | /* When MPA revision is different on nodes, the node with MPA_rev=2 |
| 2100 | * tries to reconnect with MPA_rev 1 for the same EP through |
| 2101 | * c4iw_reconnect(), where the same EP is assigned with new tid for |
| 2102 | * further connection establishment. As we are using the same EP pointer |
| 2103 | * for reconnect, few skbs are used during the previous c4iw_connect(), |
| 2104 | * which leaves the EP with inadequate skbs for further |
| 2105 | * c4iw_reconnect(), Further causing an assert BUG_ON() due to empty |
| 2106 | * skb_list() during peer_abort(). Allocate skbs which is already used. |
| 2107 | */ |
| 2108 | size = (CN_MAX_CON_BUF - skb_queue_len(&ep->com.ep_skb_list)); |
| 2109 | if (alloc_ep_skb_list(&ep->com.ep_skb_list, size)) { |
| 2110 | err = -ENOMEM; |
| 2111 | goto fail1; |
| 2112 | } |
| 2113 | |
Vipul Pandya | 793dad9 | 2012-12-10 09:30:56 +0000 | [diff] [blame] | 2114 | /* |
| 2115 | * Allocate an active TID to initiate a TCP connection. |
| 2116 | */ |
| 2117 | ep->atid = cxgb4_alloc_atid(ep->com.dev->rdev.lldi.tids, ep); |
| 2118 | if (ep->atid == -1) { |
| 2119 | pr_err("%s - cannot alloc atid.\n", __func__); |
| 2120 | err = -ENOMEM; |
| 2121 | goto fail2; |
| 2122 | } |
| 2123 | insert_handle(ep->com.dev, &ep->com.dev->atid_idr, ep, ep->atid); |
| 2124 | |
| 2125 | /* find a route */ |
Steve Wise | 170003c | 2016-02-26 09:18:03 -0600 | [diff] [blame] | 2126 | if (ep->com.cm_id->m_local_addr.ss_family == AF_INET) { |
Varun Prakash | 804c2f3 | 2016-09-13 21:23:57 +0530 | [diff] [blame] | 2127 | ep->dst = cxgb_find_route(&ep->com.dev->rdev.lldi, get_real_dev, |
| 2128 | laddr->sin_addr.s_addr, |
| 2129 | raddr->sin_addr.s_addr, |
| 2130 | laddr->sin_port, |
| 2131 | raddr->sin_port, ep->com.cm_id->tos); |
Vipul Pandya | 830662f | 2013-07-04 16:10:47 +0530 | [diff] [blame] | 2132 | iptype = 4; |
| 2133 | ra = (__u8 *)&raddr->sin_addr; |
| 2134 | } else { |
Varun Prakash | 9555476 | 2016-09-13 21:23:58 +0530 | [diff] [blame] | 2135 | ep->dst = cxgb_find_route6(&ep->com.dev->rdev.lldi, |
| 2136 | get_real_dev, |
| 2137 | laddr6->sin6_addr.s6_addr, |
| 2138 | raddr6->sin6_addr.s6_addr, |
| 2139 | laddr6->sin6_port, |
| 2140 | raddr6->sin6_port, 0, |
| 2141 | raddr6->sin6_scope_id); |
Vipul Pandya | 830662f | 2013-07-04 16:10:47 +0530 | [diff] [blame] | 2142 | iptype = 6; |
| 2143 | ra = (__u8 *)&raddr6->sin6_addr; |
| 2144 | } |
| 2145 | if (!ep->dst) { |
Vipul Pandya | 793dad9 | 2012-12-10 09:30:56 +0000 | [diff] [blame] | 2146 | pr_err("%s - cannot find route.\n", __func__); |
| 2147 | err = -EHOSTUNREACH; |
| 2148 | goto fail3; |
| 2149 | } |
Hariprasad S | 963cab5 | 2015-09-23 17:19:27 +0530 | [diff] [blame] | 2150 | err = import_ep(ep, iptype, ra, ep->dst, ep->com.dev, false, |
Hariprasad S | ac8e4c6 | 2016-02-05 11:43:30 +0530 | [diff] [blame] | 2151 | ep->com.dev->rdev.lldi.adapter_type, |
| 2152 | ep->com.cm_id->tos); |
Vipul Pandya | 830662f | 2013-07-04 16:10:47 +0530 | [diff] [blame] | 2153 | if (err) { |
Vipul Pandya | 793dad9 | 2012-12-10 09:30:56 +0000 | [diff] [blame] | 2154 | pr_err("%s - cannot alloc l2e.\n", __func__); |
Vipul Pandya | 793dad9 | 2012-12-10 09:30:56 +0000 | [diff] [blame] | 2155 | goto fail4; |
| 2156 | } |
| 2157 | |
| 2158 | PDBG("%s txq_idx %u tx_chan %u smac_idx %u rss_qid %u l2t_idx %u\n", |
| 2159 | __func__, ep->txq_idx, ep->tx_chan, ep->smac_idx, ep->rss_qid, |
| 2160 | ep->l2t->idx); |
| 2161 | |
| 2162 | state_set(&ep->com, CONNECTING); |
Hariprasad S | ac8e4c6 | 2016-02-05 11:43:30 +0530 | [diff] [blame] | 2163 | ep->tos = ep->com.cm_id->tos; |
Vipul Pandya | 793dad9 | 2012-12-10 09:30:56 +0000 | [diff] [blame] | 2164 | |
| 2165 | /* send connect request to rnic */ |
| 2166 | err = send_connect(ep); |
| 2167 | if (!err) |
| 2168 | goto out; |
| 2169 | |
| 2170 | cxgb4_l2t_release(ep->l2t); |
| 2171 | fail4: |
| 2172 | dst_release(ep->dst); |
| 2173 | fail3: |
| 2174 | remove_handle(ep->com.dev, &ep->com.dev->atid_idr, ep->atid); |
| 2175 | cxgb4_free_atid(ep->com.dev->rdev.lldi.tids, ep->atid); |
| 2176 | fail2: |
| 2177 | /* |
| 2178 | * remember to send notification to upper layer. |
| 2179 | * We are in here so the upper layer is not aware that this is |
| 2180 | * re-connect attempt and so, upper layer is still waiting for |
| 2181 | * response of 1st connect request. |
| 2182 | */ |
| 2183 | connect_reply_upcall(ep, -ECONNRESET); |
Hariprasad S | 4a74083 | 2016-06-10 01:05:15 +0530 | [diff] [blame] | 2184 | fail1: |
Vipul Pandya | 793dad9 | 2012-12-10 09:30:56 +0000 | [diff] [blame] | 2185 | c4iw_put_ep(&ep->com); |
| 2186 | out: |
| 2187 | return err; |
| 2188 | } |
| 2189 | |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2190 | static int act_open_rpl(struct c4iw_dev *dev, struct sk_buff *skb) |
| 2191 | { |
| 2192 | struct c4iw_ep *ep; |
| 2193 | struct cpl_act_open_rpl *rpl = cplhdr(skb); |
Hariprasad Shenai | 6c53e93 | 2015-01-08 21:38:15 -0800 | [diff] [blame] | 2194 | unsigned int atid = TID_TID_G(AOPEN_ATID_G( |
| 2195 | ntohl(rpl->atid_status))); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2196 | struct tid_info *t = dev->rdev.lldi.tids; |
Hariprasad Shenai | 6c53e93 | 2015-01-08 21:38:15 -0800 | [diff] [blame] | 2197 | int status = AOPEN_STATUS_G(ntohl(rpl->atid_status)); |
Vipul Pandya | 830662f | 2013-07-04 16:10:47 +0530 | [diff] [blame] | 2198 | struct sockaddr_in *la; |
| 2199 | struct sockaddr_in *ra; |
| 2200 | struct sockaddr_in6 *la6; |
| 2201 | struct sockaddr_in6 *ra6; |
Hariprasad S | caa6c9f | 2016-05-06 22:18:00 +0530 | [diff] [blame] | 2202 | int ret = 0; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2203 | |
| 2204 | ep = lookup_atid(t, atid); |
Steve Wise | 170003c | 2016-02-26 09:18:03 -0600 | [diff] [blame] | 2205 | la = (struct sockaddr_in *)&ep->com.local_addr; |
| 2206 | ra = (struct sockaddr_in *)&ep->com.remote_addr; |
| 2207 | la6 = (struct sockaddr_in6 *)&ep->com.local_addr; |
| 2208 | ra6 = (struct sockaddr_in6 *)&ep->com.remote_addr; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2209 | |
| 2210 | PDBG("%s ep %p atid %u status %u errno %d\n", __func__, ep, atid, |
| 2211 | status, status2errno(status)); |
| 2212 | |
Varun Prakash | b65eef0 | 2016-09-13 21:23:59 +0530 | [diff] [blame] | 2213 | if (cxgb_is_neg_adv(status)) { |
Hariprasad S | 179d03b | 2015-05-05 03:55:24 +0530 | [diff] [blame] | 2214 | PDBG("%s Connection problems for atid %u status %u (%s)\n", |
| 2215 | __func__, atid, status, neg_adv_str(status)); |
| 2216 | ep->stats.connect_neg_adv++; |
| 2217 | mutex_lock(&dev->rdev.stats.lock); |
| 2218 | dev->rdev.stats.neg_adv++; |
| 2219 | mutex_unlock(&dev->rdev.stats.lock); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2220 | return 0; |
| 2221 | } |
| 2222 | |
Vipul Pandya | 793dad9 | 2012-12-10 09:30:56 +0000 | [diff] [blame] | 2223 | set_bit(ACT_OPEN_RPL, &ep->com.history); |
| 2224 | |
Vipul Pandya | d716a2a | 2012-05-18 15:29:31 +0530 | [diff] [blame] | 2225 | /* |
| 2226 | * Log interesting failures. |
| 2227 | */ |
| 2228 | switch (status) { |
| 2229 | case CPL_ERR_CONN_RESET: |
| 2230 | case CPL_ERR_CONN_TIMEDOUT: |
| 2231 | break; |
Vipul Pandya | 5be78ee | 2012-12-10 09:30:54 +0000 | [diff] [blame] | 2232 | case CPL_ERR_TCAM_FULL: |
Vipul Pandya | 830662f | 2013-07-04 16:10:47 +0530 | [diff] [blame] | 2233 | mutex_lock(&dev->rdev.stats.lock); |
Vipul Pandya | 3b174d9 | 2013-03-14 05:09:03 +0000 | [diff] [blame] | 2234 | dev->rdev.stats.tcam_full++; |
Vipul Pandya | 830662f | 2013-07-04 16:10:47 +0530 | [diff] [blame] | 2235 | mutex_unlock(&dev->rdev.stats.lock); |
| 2236 | if (ep->com.local_addr.ss_family == AF_INET && |
| 2237 | dev->rdev.lldi.enable_fw_ofld_conn) { |
Hariprasad S | caa6c9f | 2016-05-06 22:18:00 +0530 | [diff] [blame] | 2238 | ret = send_fw_act_open_req(ep, TID_TID_G(AOPEN_ATID_G( |
| 2239 | ntohl(rpl->atid_status)))); |
| 2240 | if (ret) |
| 2241 | goto fail; |
Vipul Pandya | 793dad9 | 2012-12-10 09:30:56 +0000 | [diff] [blame] | 2242 | return 0; |
| 2243 | } |
| 2244 | break; |
| 2245 | case CPL_ERR_CONN_EXIST: |
| 2246 | if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) { |
| 2247 | set_bit(ACT_RETRY_INUSE, &ep->com.history); |
Hariprasad S | 84cc6ac6 | 2015-08-25 14:08:23 +0530 | [diff] [blame] | 2248 | if (ep->com.remote_addr.ss_family == AF_INET6) { |
| 2249 | struct sockaddr_in6 *sin6 = |
| 2250 | (struct sockaddr_in6 *) |
Steve Wise | 170003c | 2016-02-26 09:18:03 -0600 | [diff] [blame] | 2251 | &ep->com.local_addr; |
Hariprasad S | 84cc6ac6 | 2015-08-25 14:08:23 +0530 | [diff] [blame] | 2252 | cxgb4_clip_release( |
| 2253 | ep->com.dev->rdev.lldi.ports[0], |
| 2254 | (const u32 *) |
| 2255 | &sin6->sin6_addr.s6_addr, 1); |
| 2256 | } |
Vipul Pandya | 793dad9 | 2012-12-10 09:30:56 +0000 | [diff] [blame] | 2257 | remove_handle(ep->com.dev, &ep->com.dev->atid_idr, |
| 2258 | atid); |
| 2259 | cxgb4_free_atid(t, atid); |
| 2260 | dst_release(ep->dst); |
| 2261 | cxgb4_l2t_release(ep->l2t); |
| 2262 | c4iw_reconnect(ep); |
| 2263 | return 0; |
| 2264 | } |
Vipul Pandya | 5be78ee | 2012-12-10 09:30:54 +0000 | [diff] [blame] | 2265 | break; |
Vipul Pandya | d716a2a | 2012-05-18 15:29:31 +0530 | [diff] [blame] | 2266 | default: |
Vipul Pandya | 830662f | 2013-07-04 16:10:47 +0530 | [diff] [blame] | 2267 | if (ep->com.local_addr.ss_family == AF_INET) { |
| 2268 | pr_info("Active open failure - atid %u status %u errno %d %pI4:%u->%pI4:%u\n", |
| 2269 | atid, status, status2errno(status), |
| 2270 | &la->sin_addr.s_addr, ntohs(la->sin_port), |
| 2271 | &ra->sin_addr.s_addr, ntohs(ra->sin_port)); |
| 2272 | } else { |
| 2273 | pr_info("Active open failure - atid %u status %u errno %d %pI6:%u->%pI6:%u\n", |
| 2274 | atid, status, status2errno(status), |
| 2275 | la6->sin6_addr.s6_addr, ntohs(la6->sin6_port), |
| 2276 | ra6->sin6_addr.s6_addr, ntohs(ra6->sin6_port)); |
| 2277 | } |
Vipul Pandya | d716a2a | 2012-05-18 15:29:31 +0530 | [diff] [blame] | 2278 | break; |
| 2279 | } |
| 2280 | |
Hariprasad S | caa6c9f | 2016-05-06 22:18:00 +0530 | [diff] [blame] | 2281 | fail: |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2282 | connect_reply_upcall(ep, status2errno(status)); |
| 2283 | state_set(&ep->com, DEAD); |
| 2284 | |
Hariprasad S | 84cc6ac6 | 2015-08-25 14:08:23 +0530 | [diff] [blame] | 2285 | if (ep->com.remote_addr.ss_family == AF_INET6) { |
| 2286 | struct sockaddr_in6 *sin6 = |
Steve Wise | 170003c | 2016-02-26 09:18:03 -0600 | [diff] [blame] | 2287 | (struct sockaddr_in6 *)&ep->com.local_addr; |
Hariprasad S | 84cc6ac6 | 2015-08-25 14:08:23 +0530 | [diff] [blame] | 2288 | cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0], |
| 2289 | (const u32 *)&sin6->sin6_addr.s6_addr, 1); |
| 2290 | } |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2291 | if (status && act_open_has_tid(status)) |
| 2292 | cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, GET_TID(rpl)); |
| 2293 | |
Vipul Pandya | 793dad9 | 2012-12-10 09:30:56 +0000 | [diff] [blame] | 2294 | remove_handle(ep->com.dev, &ep->com.dev->atid_idr, atid); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2295 | cxgb4_free_atid(t, atid); |
| 2296 | dst_release(ep->dst); |
| 2297 | cxgb4_l2t_release(ep->l2t); |
| 2298 | c4iw_put_ep(&ep->com); |
| 2299 | |
| 2300 | return 0; |
| 2301 | } |
| 2302 | |
| 2303 | static int pass_open_rpl(struct c4iw_dev *dev, struct sk_buff *skb) |
| 2304 | { |
| 2305 | struct cpl_pass_open_rpl *rpl = cplhdr(skb); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2306 | unsigned int stid = GET_TID(rpl); |
Hariprasad S | f86fac7 | 2016-05-06 22:18:07 +0530 | [diff] [blame] | 2307 | struct c4iw_listen_ep *ep = get_ep_from_stid(dev, stid); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2308 | |
| 2309 | if (!ep) { |
Vipul Pandya | 1cab775 | 2012-12-10 09:30:55 +0000 | [diff] [blame] | 2310 | PDBG("%s stid %d lookup failure!\n", __func__, stid); |
| 2311 | goto out; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2312 | } |
| 2313 | PDBG("%s ep %p status %d error %d\n", __func__, ep, |
| 2314 | rpl->status, status2errno(rpl->status)); |
Steve Wise | d9594d9 | 2011-05-09 22:06:22 -0700 | [diff] [blame] | 2315 | c4iw_wake_up(&ep->com.wr_wait, status2errno(rpl->status)); |
Hariprasad S | f86fac7 | 2016-05-06 22:18:07 +0530 | [diff] [blame] | 2316 | c4iw_put_ep(&ep->com); |
Vipul Pandya | 1cab775 | 2012-12-10 09:30:55 +0000 | [diff] [blame] | 2317 | out: |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2318 | return 0; |
| 2319 | } |
| 2320 | |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2321 | static int close_listsrv_rpl(struct c4iw_dev *dev, struct sk_buff *skb) |
| 2322 | { |
| 2323 | struct cpl_close_listsvr_rpl *rpl = cplhdr(skb); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2324 | unsigned int stid = GET_TID(rpl); |
Hariprasad S | f86fac7 | 2016-05-06 22:18:07 +0530 | [diff] [blame] | 2325 | struct c4iw_listen_ep *ep = get_ep_from_stid(dev, stid); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2326 | |
| 2327 | PDBG("%s ep %p\n", __func__, ep); |
Steve Wise | d9594d9 | 2011-05-09 22:06:22 -0700 | [diff] [blame] | 2328 | c4iw_wake_up(&ep->com.wr_wait, status2errno(rpl->status)); |
Hariprasad S | f86fac7 | 2016-05-06 22:18:07 +0530 | [diff] [blame] | 2329 | c4iw_put_ep(&ep->com); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2330 | return 0; |
| 2331 | } |
| 2332 | |
Hariprasad S | 9dec900 | 2016-05-05 01:27:29 +0530 | [diff] [blame] | 2333 | static int accept_cr(struct c4iw_ep *ep, struct sk_buff *skb, |
| 2334 | struct cpl_pass_accept_req *req) |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2335 | { |
| 2336 | struct cpl_pass_accept_rpl *rpl; |
| 2337 | unsigned int mtu_idx; |
| 2338 | u64 opt0; |
| 2339 | u32 opt2; |
Varun Prakash | cc51670 | 2016-09-13 21:24:01 +0530 | [diff] [blame] | 2340 | u32 wscale; |
Hariprasad Shenai | 92e7ae7 | 2014-06-06 21:40:43 +0530 | [diff] [blame] | 2341 | struct cpl_t5_pass_accept_rpl *rpl5 = NULL; |
Hariprasad Shenai | b408ff2 | 2014-06-06 21:40:44 +0530 | [diff] [blame] | 2342 | int win; |
Hariprasad S | 963cab5 | 2015-09-23 17:19:27 +0530 | [diff] [blame] | 2343 | enum chip_type adapter_type = ep->com.dev->rdev.lldi.adapter_type; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2344 | |
| 2345 | PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid); |
| 2346 | BUG_ON(skb_cloned(skb)); |
Hariprasad Shenai | 92e7ae7 | 2014-06-06 21:40:43 +0530 | [diff] [blame] | 2347 | |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2348 | skb_get(skb); |
Hariprasad Shenai | 92e7ae7 | 2014-06-06 21:40:43 +0530 | [diff] [blame] | 2349 | rpl = cplhdr(skb); |
Hariprasad S | 963cab5 | 2015-09-23 17:19:27 +0530 | [diff] [blame] | 2350 | if (!is_t4(adapter_type)) { |
Hariprasad Shenai | 92e7ae7 | 2014-06-06 21:40:43 +0530 | [diff] [blame] | 2351 | skb_trim(skb, roundup(sizeof(*rpl5), 16)); |
| 2352 | rpl5 = (void *)rpl; |
| 2353 | INIT_TP_WR(rpl5, ep->hwtid); |
| 2354 | } else { |
| 2355 | skb_trim(skb, sizeof(*rpl)); |
| 2356 | INIT_TP_WR(rpl, ep->hwtid); |
| 2357 | } |
| 2358 | OPCODE_TID(rpl) = cpu_to_be32(MK_OPCODE_TID(CPL_PASS_ACCEPT_RPL, |
| 2359 | ep->hwtid)); |
| 2360 | |
Varun Prakash | 44c6d06 | 2016-09-13 21:24:00 +0530 | [diff] [blame] | 2361 | cxgb_best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx, |
| 2362 | enable_tcp_timestamps && req->tcpopt.tstamp, |
| 2363 | (ep->com.remote_addr.ss_family == AF_INET) ? 0 : 1); |
Varun Prakash | cc51670 | 2016-09-13 21:24:01 +0530 | [diff] [blame] | 2364 | wscale = cxgb_compute_wscale(rcv_win); |
Hariprasad Shenai | b408ff2 | 2014-06-06 21:40:44 +0530 | [diff] [blame] | 2365 | |
| 2366 | /* |
| 2367 | * Specify the largest window that will fit in opt0. The |
| 2368 | * remainder will be specified in the rx_data_ack. |
| 2369 | */ |
| 2370 | win = ep->rcv_win >> 10; |
Anish Bhatt | d7990b0 | 2014-11-12 17:15:57 -0800 | [diff] [blame] | 2371 | if (win > RCV_BUFSIZ_M) |
| 2372 | win = RCV_BUFSIZ_M; |
Hariprasad Shenai | 6c53e93 | 2015-01-08 21:38:15 -0800 | [diff] [blame] | 2373 | opt0 = (nocong ? NO_CONG_F : 0) | |
Anish Bhatt | d7990b0 | 2014-11-12 17:15:57 -0800 | [diff] [blame] | 2374 | KEEP_ALIVE_F | |
Hariprasad Shenai | 6c53e93 | 2015-01-08 21:38:15 -0800 | [diff] [blame] | 2375 | DELACK_F | |
Anish Bhatt | d7990b0 | 2014-11-12 17:15:57 -0800 | [diff] [blame] | 2376 | WND_SCALE_V(wscale) | |
| 2377 | MSS_IDX_V(mtu_idx) | |
| 2378 | L2T_IDX_V(ep->l2t->idx) | |
| 2379 | TX_CHAN_V(ep->tx_chan) | |
| 2380 | SMAC_SEL_V(ep->smac_idx) | |
Hariprasad Shenai | 6c53e93 | 2015-01-08 21:38:15 -0800 | [diff] [blame] | 2381 | DSCP_V(ep->tos >> 2) | |
Anish Bhatt | d7990b0 | 2014-11-12 17:15:57 -0800 | [diff] [blame] | 2382 | ULP_MODE_V(ULP_MODE_TCPDDP) | |
| 2383 | RCV_BUFSIZ_V(win); |
| 2384 | opt2 = RX_CHANNEL_V(0) | |
| 2385 | RSS_QUEUE_VALID_F | RSS_QUEUE_V(ep->rss_qid); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2386 | |
| 2387 | if (enable_tcp_timestamps && req->tcpopt.tstamp) |
Hariprasad Shenai | 6c53e93 | 2015-01-08 21:38:15 -0800 | [diff] [blame] | 2388 | opt2 |= TSTAMPS_EN_F; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2389 | if (enable_tcp_sack && req->tcpopt.sack) |
Hariprasad Shenai | 6c53e93 | 2015-01-08 21:38:15 -0800 | [diff] [blame] | 2390 | opt2 |= SACK_EN_F; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2391 | if (wscale && enable_tcp_window_scaling) |
Anish Bhatt | d7990b0 | 2014-11-12 17:15:57 -0800 | [diff] [blame] | 2392 | opt2 |= WND_SCALE_EN_F; |
Vipul Pandya | 5be78ee | 2012-12-10 09:30:54 +0000 | [diff] [blame] | 2393 | if (enable_ecn) { |
| 2394 | const struct tcphdr *tcph; |
| 2395 | u32 hlen = ntohl(req->hdr_len); |
| 2396 | |
Hariprasad S | 963cab5 | 2015-09-23 17:19:27 +0530 | [diff] [blame] | 2397 | if (CHELSIO_CHIP_VERSION(adapter_type) <= CHELSIO_T5) |
| 2398 | tcph = (const void *)(req + 1) + ETH_HDR_LEN_G(hlen) + |
| 2399 | IP_HDR_LEN_G(hlen); |
| 2400 | else |
| 2401 | tcph = (const void *)(req + 1) + |
| 2402 | T6_ETH_HDR_LEN_G(hlen) + T6_IP_HDR_LEN_G(hlen); |
Vipul Pandya | 5be78ee | 2012-12-10 09:30:54 +0000 | [diff] [blame] | 2403 | if (tcph->ece && tcph->cwr) |
Hariprasad Shenai | 6c53e93 | 2015-01-08 21:38:15 -0800 | [diff] [blame] | 2404 | opt2 |= CCTRL_ECN_V(1); |
Vipul Pandya | 5be78ee | 2012-12-10 09:30:54 +0000 | [diff] [blame] | 2405 | } |
Hariprasad S | 963cab5 | 2015-09-23 17:19:27 +0530 | [diff] [blame] | 2406 | if (CHELSIO_CHIP_VERSION(adapter_type) > CHELSIO_T4) { |
Hariprasad Shenai | 92e7ae7 | 2014-06-06 21:40:43 +0530 | [diff] [blame] | 2407 | u32 isn = (prandom_u32() & ~7UL) - 1; |
Anish Bhatt | d7990b0 | 2014-11-12 17:15:57 -0800 | [diff] [blame] | 2408 | opt2 |= T5_OPT_2_VALID_F; |
Hariprasad Shenai | cf7fe64 | 2015-01-16 09:24:48 +0530 | [diff] [blame] | 2409 | opt2 |= CONG_CNTRL_V(CONG_ALG_TAHOE); |
Hariprasad S | 0b74104 | 2015-04-22 01:44:58 +0530 | [diff] [blame] | 2410 | opt2 |= T5_ISS_F; |
Hariprasad Shenai | 92e7ae7 | 2014-06-06 21:40:43 +0530 | [diff] [blame] | 2411 | rpl5 = (void *)rpl; |
| 2412 | memset(&rpl5->iss, 0, roundup(sizeof(*rpl5)-sizeof(*rpl), 16)); |
| 2413 | if (peer2peer) |
| 2414 | isn += 4; |
| 2415 | rpl5->iss = cpu_to_be32(isn); |
| 2416 | PDBG("%s iss %u\n", __func__, be32_to_cpu(rpl5->iss)); |
Steve Wise | 92e5011 | 2014-04-24 14:31:59 -0500 | [diff] [blame] | 2417 | } |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2418 | |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2419 | rpl->opt0 = cpu_to_be64(opt0); |
| 2420 | rpl->opt2 = cpu_to_be32(opt2); |
Steve Wise | d4f1a5c | 2010-07-23 19:12:32 +0000 | [diff] [blame] | 2421 | set_wr_txq(skb, CPL_PRIORITY_SETUP, ep->ctrlq_idx); |
Hariprasad S | 9dec900 | 2016-05-05 01:27:29 +0530 | [diff] [blame] | 2422 | t4_set_arp_err_handler(skb, ep, pass_accept_rpl_arp_failure); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2423 | |
Hariprasad S | 9dec900 | 2016-05-05 01:27:29 +0530 | [diff] [blame] | 2424 | return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2425 | } |
| 2426 | |
Vipul Pandya | 830662f | 2013-07-04 16:10:47 +0530 | [diff] [blame] | 2427 | static void reject_cr(struct c4iw_dev *dev, u32 hwtid, struct sk_buff *skb) |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2428 | { |
Vipul Pandya | 830662f | 2013-07-04 16:10:47 +0530 | [diff] [blame] | 2429 | PDBG("%s c4iw_dev %p tid %u\n", __func__, dev, hwtid); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2430 | BUG_ON(skb_cloned(skb)); |
| 2431 | skb_trim(skb, sizeof(struct cpl_tid_release)); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2432 | release_tid(&dev->rdev, hwtid, skb); |
| 2433 | return; |
| 2434 | } |
| 2435 | |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2436 | static int pass_accept_req(struct c4iw_dev *dev, struct sk_buff *skb) |
| 2437 | { |
Vipul Pandya | 793dad9 | 2012-12-10 09:30:56 +0000 | [diff] [blame] | 2438 | struct c4iw_ep *child_ep = NULL, *parent_ep; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2439 | struct cpl_pass_accept_req *req = cplhdr(skb); |
Hariprasad Shenai | 6c53e93 | 2015-01-08 21:38:15 -0800 | [diff] [blame] | 2440 | unsigned int stid = PASS_OPEN_TID_G(ntohl(req->tos_stid)); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2441 | struct tid_info *t = dev->rdev.lldi.tids; |
| 2442 | unsigned int hwtid = GET_TID(req); |
| 2443 | struct dst_entry *dst; |
Vipul Pandya | 830662f | 2013-07-04 16:10:47 +0530 | [diff] [blame] | 2444 | __u8 local_ip[16], peer_ip[16]; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2445 | __be16 local_port, peer_port; |
Hariprasad S | 84cc6ac6 | 2015-08-25 14:08:23 +0530 | [diff] [blame] | 2446 | struct sockaddr_in6 *sin6; |
David Miller | 3786cf1 | 2011-12-02 16:52:31 +0000 | [diff] [blame] | 2447 | int err; |
Vipul Pandya | 1cab775 | 2012-12-10 09:30:55 +0000 | [diff] [blame] | 2448 | u16 peer_mss = ntohs(req->tcpopt.mss); |
Vipul Pandya | 830662f | 2013-07-04 16:10:47 +0530 | [diff] [blame] | 2449 | int iptype; |
Hariprasad Shenai | 92e7ae7 | 2014-06-06 21:40:43 +0530 | [diff] [blame] | 2450 | unsigned short hdrs; |
Hariprasad S | ac8e4c6 | 2016-02-05 11:43:30 +0530 | [diff] [blame] | 2451 | u8 tos = PASS_OPEN_TOS_G(ntohl(req->tos_stid)); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2452 | |
Hariprasad S | f86fac7 | 2016-05-06 22:18:07 +0530 | [diff] [blame] | 2453 | parent_ep = (struct c4iw_ep *)get_ep_from_stid(dev, stid); |
Vipul Pandya | 1cab775 | 2012-12-10 09:30:55 +0000 | [diff] [blame] | 2454 | if (!parent_ep) { |
| 2455 | PDBG("%s connect request on invalid stid %d\n", __func__, stid); |
| 2456 | goto reject; |
| 2457 | } |
Vipul Pandya | 1cab775 | 2012-12-10 09:30:55 +0000 | [diff] [blame] | 2458 | |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2459 | if (state_read(&parent_ep->com) != LISTEN) { |
Hariprasad S | 6812fae | 2016-02-05 11:43:29 +0530 | [diff] [blame] | 2460 | PDBG("%s - listening ep not in LISTEN\n", __func__); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2461 | goto reject; |
| 2462 | } |
| 2463 | |
Varun Prakash | 85e42b0 | 2016-09-13 21:23:56 +0530 | [diff] [blame] | 2464 | cxgb_get_4tuple(req, parent_ep->com.dev->rdev.lldi.adapter_type, |
| 2465 | &iptype, local_ip, peer_ip, &local_port, &peer_port); |
Vipul Pandya | 830662f | 2013-07-04 16:10:47 +0530 | [diff] [blame] | 2466 | |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2467 | /* Find output route */ |
Vipul Pandya | 830662f | 2013-07-04 16:10:47 +0530 | [diff] [blame] | 2468 | if (iptype == 4) { |
| 2469 | PDBG("%s parent ep %p hwtid %u laddr %pI4 raddr %pI4 lport %d rport %d peer_mss %d\n" |
| 2470 | , __func__, parent_ep, hwtid, |
| 2471 | local_ip, peer_ip, ntohs(local_port), |
| 2472 | ntohs(peer_port), peer_mss); |
Varun Prakash | 804c2f3 | 2016-09-13 21:23:57 +0530 | [diff] [blame] | 2473 | dst = cxgb_find_route(&dev->rdev.lldi, get_real_dev, |
| 2474 | *(__be32 *)local_ip, *(__be32 *)peer_ip, |
| 2475 | local_port, peer_port, tos); |
Vipul Pandya | 830662f | 2013-07-04 16:10:47 +0530 | [diff] [blame] | 2476 | } else { |
| 2477 | PDBG("%s parent ep %p hwtid %u laddr %pI6 raddr %pI6 lport %d rport %d peer_mss %d\n" |
| 2478 | , __func__, parent_ep, hwtid, |
| 2479 | local_ip, peer_ip, ntohs(local_port), |
| 2480 | ntohs(peer_port), peer_mss); |
Varun Prakash | 9555476 | 2016-09-13 21:23:58 +0530 | [diff] [blame] | 2481 | dst = cxgb_find_route6(&dev->rdev.lldi, get_real_dev, |
| 2482 | local_ip, peer_ip, local_port, peer_port, |
| 2483 | PASS_OPEN_TOS_G(ntohl(req->tos_stid)), |
| 2484 | ((struct sockaddr_in6 *) |
| 2485 | &parent_ep->com.local_addr)->sin6_scope_id); |
Vipul Pandya | 830662f | 2013-07-04 16:10:47 +0530 | [diff] [blame] | 2486 | } |
| 2487 | if (!dst) { |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2488 | printk(KERN_ERR MOD "%s - failed to find dst entry!\n", |
| 2489 | __func__); |
| 2490 | goto reject; |
| 2491 | } |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2492 | |
| 2493 | child_ep = alloc_ep(sizeof(*child_ep), GFP_KERNEL); |
| 2494 | if (!child_ep) { |
| 2495 | printk(KERN_ERR MOD "%s - failed to allocate ep entry!\n", |
| 2496 | __func__); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2497 | dst_release(dst); |
| 2498 | goto reject; |
| 2499 | } |
David Miller | 3786cf1 | 2011-12-02 16:52:31 +0000 | [diff] [blame] | 2500 | |
Hariprasad S | 963cab5 | 2015-09-23 17:19:27 +0530 | [diff] [blame] | 2501 | err = import_ep(child_ep, iptype, peer_ip, dst, dev, false, |
Hariprasad S | ac8e4c6 | 2016-02-05 11:43:30 +0530 | [diff] [blame] | 2502 | parent_ep->com.dev->rdev.lldi.adapter_type, tos); |
David Miller | 3786cf1 | 2011-12-02 16:52:31 +0000 | [diff] [blame] | 2503 | if (err) { |
| 2504 | printk(KERN_ERR MOD "%s - failed to allocate l2t entry!\n", |
| 2505 | __func__); |
| 2506 | dst_release(dst); |
| 2507 | kfree(child_ep); |
| 2508 | goto reject; |
| 2509 | } |
| 2510 | |
Hariprasad Shenai | 92e7ae7 | 2014-06-06 21:40:43 +0530 | [diff] [blame] | 2511 | hdrs = sizeof(struct iphdr) + sizeof(struct tcphdr) + |
| 2512 | ((enable_tcp_timestamps && req->tcpopt.tstamp) ? 12 : 0); |
| 2513 | if (peer_mss && child_ep->mtu > (peer_mss + hdrs)) |
| 2514 | child_ep->mtu = peer_mss + hdrs; |
Vipul Pandya | 1cab775 | 2012-12-10 09:30:55 +0000 | [diff] [blame] | 2515 | |
Hariprasad S | 4a74083 | 2016-06-10 01:05:15 +0530 | [diff] [blame] | 2516 | skb_queue_head_init(&child_ep->com.ep_skb_list); |
| 2517 | if (alloc_ep_skb_list(&child_ep->com.ep_skb_list, CN_MAX_CON_BUF)) |
| 2518 | goto fail; |
| 2519 | |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2520 | state_set(&child_ep->com, CONNECTING); |
| 2521 | child_ep->com.dev = dev; |
| 2522 | child_ep->com.cm_id = NULL; |
Steve Wise | 5b6b8fe | 2015-04-21 16:28:41 -0400 | [diff] [blame] | 2523 | |
Vipul Pandya | 830662f | 2013-07-04 16:10:47 +0530 | [diff] [blame] | 2524 | if (iptype == 4) { |
| 2525 | struct sockaddr_in *sin = (struct sockaddr_in *) |
Steve Wise | 170003c | 2016-02-26 09:18:03 -0600 | [diff] [blame] | 2526 | &child_ep->com.local_addr; |
Steve Wise | 5b6b8fe | 2015-04-21 16:28:41 -0400 | [diff] [blame] | 2527 | |
Vipul Pandya | 830662f | 2013-07-04 16:10:47 +0530 | [diff] [blame] | 2528 | sin->sin_family = PF_INET; |
| 2529 | sin->sin_port = local_port; |
| 2530 | sin->sin_addr.s_addr = *(__be32 *)local_ip; |
Steve Wise | 5b6b8fe | 2015-04-21 16:28:41 -0400 | [diff] [blame] | 2531 | |
| 2532 | sin = (struct sockaddr_in *)&child_ep->com.local_addr; |
| 2533 | sin->sin_family = PF_INET; |
| 2534 | sin->sin_port = ((struct sockaddr_in *) |
| 2535 | &parent_ep->com.local_addr)->sin_port; |
| 2536 | sin->sin_addr.s_addr = *(__be32 *)local_ip; |
| 2537 | |
Steve Wise | 170003c | 2016-02-26 09:18:03 -0600 | [diff] [blame] | 2538 | sin = (struct sockaddr_in *)&child_ep->com.remote_addr; |
Vipul Pandya | 830662f | 2013-07-04 16:10:47 +0530 | [diff] [blame] | 2539 | sin->sin_family = PF_INET; |
| 2540 | sin->sin_port = peer_port; |
| 2541 | sin->sin_addr.s_addr = *(__be32 *)peer_ip; |
| 2542 | } else { |
Steve Wise | 170003c | 2016-02-26 09:18:03 -0600 | [diff] [blame] | 2543 | sin6 = (struct sockaddr_in6 *)&child_ep->com.local_addr; |
Vipul Pandya | 830662f | 2013-07-04 16:10:47 +0530 | [diff] [blame] | 2544 | sin6->sin6_family = PF_INET6; |
| 2545 | sin6->sin6_port = local_port; |
| 2546 | memcpy(sin6->sin6_addr.s6_addr, local_ip, 16); |
Steve Wise | 5b6b8fe | 2015-04-21 16:28:41 -0400 | [diff] [blame] | 2547 | |
| 2548 | sin6 = (struct sockaddr_in6 *)&child_ep->com.local_addr; |
| 2549 | sin6->sin6_family = PF_INET6; |
| 2550 | sin6->sin6_port = ((struct sockaddr_in6 *) |
| 2551 | &parent_ep->com.local_addr)->sin6_port; |
| 2552 | memcpy(sin6->sin6_addr.s6_addr, local_ip, 16); |
| 2553 | |
Steve Wise | 170003c | 2016-02-26 09:18:03 -0600 | [diff] [blame] | 2554 | sin6 = (struct sockaddr_in6 *)&child_ep->com.remote_addr; |
Vipul Pandya | 830662f | 2013-07-04 16:10:47 +0530 | [diff] [blame] | 2555 | sin6->sin6_family = PF_INET6; |
| 2556 | sin6->sin6_port = peer_port; |
| 2557 | memcpy(sin6->sin6_addr.s6_addr, peer_ip, 16); |
| 2558 | } |
Steve Wise | 5b6b8fe | 2015-04-21 16:28:41 -0400 | [diff] [blame] | 2559 | |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2560 | c4iw_get_ep(&parent_ep->com); |
| 2561 | child_ep->parent_ep = parent_ep; |
Hariprasad S | ac8e4c6 | 2016-02-05 11:43:30 +0530 | [diff] [blame] | 2562 | child_ep->tos = tos; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2563 | child_ep->dst = dst; |
| 2564 | child_ep->hwtid = hwtid; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2565 | |
| 2566 | PDBG("%s tx_chan %u smac_idx %u rss_qid %u\n", __func__, |
David Miller | 3786cf1 | 2011-12-02 16:52:31 +0000 | [diff] [blame] | 2567 | child_ep->tx_chan, child_ep->smac_idx, child_ep->rss_qid); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2568 | |
| 2569 | init_timer(&child_ep->timer); |
| 2570 | cxgb4_insert_tid(t, child_ep, hwtid); |
Hariprasad S | 944661d | 2016-05-06 22:18:03 +0530 | [diff] [blame] | 2571 | insert_ep_tid(child_ep); |
Hariprasad S | 9dec900 | 2016-05-05 01:27:29 +0530 | [diff] [blame] | 2572 | if (accept_cr(child_ep, skb, req)) { |
| 2573 | c4iw_put_ep(&parent_ep->com); |
| 2574 | release_ep_resources(child_ep); |
| 2575 | } else { |
| 2576 | set_bit(PASS_ACCEPT_REQ, &child_ep->com.history); |
| 2577 | } |
Hariprasad S | 84cc6ac6 | 2015-08-25 14:08:23 +0530 | [diff] [blame] | 2578 | if (iptype == 6) { |
Steve Wise | 170003c | 2016-02-26 09:18:03 -0600 | [diff] [blame] | 2579 | sin6 = (struct sockaddr_in6 *)&child_ep->com.local_addr; |
Hariprasad S | 84cc6ac6 | 2015-08-25 14:08:23 +0530 | [diff] [blame] | 2580 | cxgb4_clip_get(child_ep->com.dev->rdev.lldi.ports[0], |
| 2581 | (const u32 *)&sin6->sin6_addr.s6_addr, 1); |
| 2582 | } |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2583 | goto out; |
Hariprasad S | 4a74083 | 2016-06-10 01:05:15 +0530 | [diff] [blame] | 2584 | fail: |
| 2585 | c4iw_put_ep(&child_ep->com); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2586 | reject: |
Vipul Pandya | 830662f | 2013-07-04 16:10:47 +0530 | [diff] [blame] | 2587 | reject_cr(dev, hwtid, skb); |
Hariprasad S | f86fac7 | 2016-05-06 22:18:07 +0530 | [diff] [blame] | 2588 | if (parent_ep) |
| 2589 | c4iw_put_ep(&parent_ep->com); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2590 | out: |
| 2591 | return 0; |
| 2592 | } |
| 2593 | |
| 2594 | static int pass_establish(struct c4iw_dev *dev, struct sk_buff *skb) |
| 2595 | { |
| 2596 | struct c4iw_ep *ep; |
| 2597 | struct cpl_pass_establish *req = cplhdr(skb); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2598 | unsigned int tid = GET_TID(req); |
Hariprasad S | fef4422 | 2016-05-05 01:27:33 +0530 | [diff] [blame] | 2599 | int ret; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2600 | |
Hariprasad S | 944661d | 2016-05-06 22:18:03 +0530 | [diff] [blame] | 2601 | ep = get_ep_from_tid(dev, tid); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2602 | PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid); |
| 2603 | ep->snd_seq = be32_to_cpu(req->snd_isn); |
| 2604 | ep->rcv_seq = be32_to_cpu(req->rcv_isn); |
| 2605 | |
Vipul Pandya | 1cab775 | 2012-12-10 09:30:55 +0000 | [diff] [blame] | 2606 | PDBG("%s ep %p hwtid %u tcp_opt 0x%02x\n", __func__, ep, tid, |
| 2607 | ntohs(req->tcp_opt)); |
| 2608 | |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2609 | set_emss(ep, ntohs(req->tcp_opt)); |
| 2610 | |
| 2611 | dst_confirm(ep->dst); |
Hariprasad S | fef4422 | 2016-05-05 01:27:33 +0530 | [diff] [blame] | 2612 | mutex_lock(&ep->com.mutex); |
| 2613 | ep->com.state = MPA_REQ_WAIT; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2614 | start_ep_timer(ep); |
Vipul Pandya | 793dad9 | 2012-12-10 09:30:56 +0000 | [diff] [blame] | 2615 | set_bit(PASS_ESTAB, &ep->com.history); |
Hariprasad S | 4a74083 | 2016-06-10 01:05:15 +0530 | [diff] [blame] | 2616 | ret = send_flowc(ep); |
Hariprasad S | fef4422 | 2016-05-05 01:27:33 +0530 | [diff] [blame] | 2617 | mutex_unlock(&ep->com.mutex); |
| 2618 | if (ret) |
| 2619 | c4iw_ep_disconnect(ep, 1, GFP_KERNEL); |
Hariprasad S | 944661d | 2016-05-06 22:18:03 +0530 | [diff] [blame] | 2620 | c4iw_put_ep(&ep->com); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2621 | |
| 2622 | return 0; |
| 2623 | } |
| 2624 | |
| 2625 | static int peer_close(struct c4iw_dev *dev, struct sk_buff *skb) |
| 2626 | { |
| 2627 | struct cpl_peer_close *hdr = cplhdr(skb); |
| 2628 | struct c4iw_ep *ep; |
| 2629 | struct c4iw_qp_attributes attrs; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2630 | int disconnect = 1; |
| 2631 | int release = 0; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2632 | unsigned int tid = GET_TID(hdr); |
Steve Wise | 8da7e7a | 2011-06-14 20:59:27 +0000 | [diff] [blame] | 2633 | int ret; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2634 | |
Hariprasad S | 944661d | 2016-05-06 22:18:03 +0530 | [diff] [blame] | 2635 | ep = get_ep_from_tid(dev, tid); |
| 2636 | if (!ep) |
| 2637 | return 0; |
| 2638 | |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2639 | PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid); |
| 2640 | dst_confirm(ep->dst); |
| 2641 | |
Vipul Pandya | 793dad9 | 2012-12-10 09:30:56 +0000 | [diff] [blame] | 2642 | set_bit(PEER_CLOSE, &ep->com.history); |
Steve Wise | 2f5b48c | 2010-09-10 11:15:36 -0500 | [diff] [blame] | 2643 | mutex_lock(&ep->com.mutex); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2644 | switch (ep->com.state) { |
| 2645 | case MPA_REQ_WAIT: |
| 2646 | __state_set(&ep->com, CLOSING); |
| 2647 | break; |
| 2648 | case MPA_REQ_SENT: |
| 2649 | __state_set(&ep->com, CLOSING); |
| 2650 | connect_reply_upcall(ep, -ECONNRESET); |
| 2651 | break; |
| 2652 | case MPA_REQ_RCVD: |
| 2653 | |
| 2654 | /* |
| 2655 | * We're gonna mark this puppy DEAD, but keep |
| 2656 | * the reference on it until the ULP accepts or |
| 2657 | * rejects the CR. Also wake up anyone waiting |
| 2658 | * in rdma connection migration (see c4iw_accept_cr()). |
| 2659 | */ |
| 2660 | __state_set(&ep->com, CLOSING); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2661 | PDBG("waking up ep %p tid %u\n", ep, ep->hwtid); |
Steve Wise | d9594d9 | 2011-05-09 22:06:22 -0700 | [diff] [blame] | 2662 | c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2663 | break; |
| 2664 | case MPA_REP_SENT: |
| 2665 | __state_set(&ep->com, CLOSING); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2666 | PDBG("waking up ep %p tid %u\n", ep, ep->hwtid); |
Steve Wise | d9594d9 | 2011-05-09 22:06:22 -0700 | [diff] [blame] | 2667 | c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2668 | break; |
| 2669 | case FPDU_MODE: |
Steve Wise | ca5a220 | 2010-07-23 19:12:37 +0000 | [diff] [blame] | 2670 | start_ep_timer(ep); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2671 | __state_set(&ep->com, CLOSING); |
Steve Wise | 30c95c2 | 2011-05-09 22:06:22 -0700 | [diff] [blame] | 2672 | attrs.next_state = C4IW_QP_STATE_CLOSING; |
Steve Wise | 8da7e7a | 2011-06-14 20:59:27 +0000 | [diff] [blame] | 2673 | ret = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp, |
Steve Wise | 30c95c2 | 2011-05-09 22:06:22 -0700 | [diff] [blame] | 2674 | C4IW_QP_ATTR_NEXT_STATE, &attrs, 1); |
Steve Wise | 8da7e7a | 2011-06-14 20:59:27 +0000 | [diff] [blame] | 2675 | if (ret != -ECONNRESET) { |
| 2676 | peer_close_upcall(ep); |
| 2677 | disconnect = 1; |
| 2678 | } |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2679 | break; |
| 2680 | case ABORTING: |
| 2681 | disconnect = 0; |
| 2682 | break; |
| 2683 | case CLOSING: |
| 2684 | __state_set(&ep->com, MORIBUND); |
| 2685 | disconnect = 0; |
| 2686 | break; |
| 2687 | case MORIBUND: |
Steve Wise | b33bd0c | 2014-04-09 09:38:25 -0500 | [diff] [blame] | 2688 | (void)stop_ep_timer(ep); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2689 | if (ep->com.cm_id && ep->com.qp) { |
| 2690 | attrs.next_state = C4IW_QP_STATE_IDLE; |
| 2691 | c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp, |
| 2692 | C4IW_QP_ATTR_NEXT_STATE, &attrs, 1); |
| 2693 | } |
Steve Wise | be13b2d | 2014-03-21 20:40:33 +0530 | [diff] [blame] | 2694 | close_complete_upcall(ep, 0); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2695 | __state_set(&ep->com, DEAD); |
| 2696 | release = 1; |
| 2697 | disconnect = 0; |
| 2698 | break; |
| 2699 | case DEAD: |
| 2700 | disconnect = 0; |
| 2701 | break; |
| 2702 | default: |
| 2703 | BUG_ON(1); |
| 2704 | } |
Steve Wise | 2f5b48c | 2010-09-10 11:15:36 -0500 | [diff] [blame] | 2705 | mutex_unlock(&ep->com.mutex); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2706 | if (disconnect) |
| 2707 | c4iw_ep_disconnect(ep, 0, GFP_KERNEL); |
| 2708 | if (release) |
| 2709 | release_ep_resources(ep); |
Hariprasad S | 944661d | 2016-05-06 22:18:03 +0530 | [diff] [blame] | 2710 | c4iw_put_ep(&ep->com); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2711 | return 0; |
| 2712 | } |
| 2713 | |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2714 | static int peer_abort(struct c4iw_dev *dev, struct sk_buff *skb) |
| 2715 | { |
| 2716 | struct cpl_abort_req_rss *req = cplhdr(skb); |
| 2717 | struct c4iw_ep *ep; |
| 2718 | struct cpl_abort_rpl *rpl; |
| 2719 | struct sk_buff *rpl_skb; |
| 2720 | struct c4iw_qp_attributes attrs; |
| 2721 | int ret; |
| 2722 | int release = 0; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2723 | unsigned int tid = GET_TID(req); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2724 | |
Hariprasad S | 944661d | 2016-05-06 22:18:03 +0530 | [diff] [blame] | 2725 | ep = get_ep_from_tid(dev, tid); |
| 2726 | if (!ep) |
| 2727 | return 0; |
| 2728 | |
Varun Prakash | b65eef0 | 2016-09-13 21:23:59 +0530 | [diff] [blame] | 2729 | if (cxgb_is_neg_adv(req->status)) { |
Hariprasad S | 179d03b | 2015-05-05 03:55:24 +0530 | [diff] [blame] | 2730 | PDBG("%s Negative advice on abort- tid %u status %d (%s)\n", |
| 2731 | __func__, ep->hwtid, req->status, |
| 2732 | neg_adv_str(req->status)); |
| 2733 | ep->stats.abort_neg_adv++; |
| 2734 | mutex_lock(&dev->rdev.stats.lock); |
| 2735 | dev->rdev.stats.neg_adv++; |
| 2736 | mutex_unlock(&dev->rdev.stats.lock); |
Hariprasad S | 944661d | 2016-05-06 22:18:03 +0530 | [diff] [blame] | 2737 | goto deref_ep; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2738 | } |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2739 | PDBG("%s ep %p tid %u state %u\n", __func__, ep, ep->hwtid, |
| 2740 | ep->com.state); |
Vipul Pandya | 793dad9 | 2012-12-10 09:30:56 +0000 | [diff] [blame] | 2741 | set_bit(PEER_ABORT, &ep->com.history); |
Steve Wise | 2f5b48c | 2010-09-10 11:15:36 -0500 | [diff] [blame] | 2742 | |
| 2743 | /* |
| 2744 | * Wake up any threads in rdma_init() or rdma_fini(). |
Kumar Sanghvi | d2fe99e | 2011-09-25 20:17:44 +0530 | [diff] [blame] | 2745 | * However, this is not needed if com state is just |
| 2746 | * MPA_REQ_SENT |
Steve Wise | 2f5b48c | 2010-09-10 11:15:36 -0500 | [diff] [blame] | 2747 | */ |
Kumar Sanghvi | d2fe99e | 2011-09-25 20:17:44 +0530 | [diff] [blame] | 2748 | if (ep->com.state != MPA_REQ_SENT) |
| 2749 | c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET); |
Steve Wise | 2f5b48c | 2010-09-10 11:15:36 -0500 | [diff] [blame] | 2750 | |
| 2751 | mutex_lock(&ep->com.mutex); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2752 | switch (ep->com.state) { |
| 2753 | case CONNECTING: |
Hariprasad S | 9dec900 | 2016-05-05 01:27:29 +0530 | [diff] [blame] | 2754 | c4iw_put_ep(&ep->parent_ep->com); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2755 | break; |
| 2756 | case MPA_REQ_WAIT: |
Steve Wise | b33bd0c | 2014-04-09 09:38:25 -0500 | [diff] [blame] | 2757 | (void)stop_ep_timer(ep); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2758 | break; |
| 2759 | case MPA_REQ_SENT: |
Steve Wise | b33bd0c | 2014-04-09 09:38:25 -0500 | [diff] [blame] | 2760 | (void)stop_ep_timer(ep); |
Vipul Pandya | fe7e0a4 | 2013-01-07 13:11:57 +0000 | [diff] [blame] | 2761 | if (mpa_rev == 1 || (mpa_rev == 2 && ep->tried_with_mpa_v1)) |
Kumar Sanghvi | d2fe99e | 2011-09-25 20:17:44 +0530 | [diff] [blame] | 2762 | connect_reply_upcall(ep, -ECONNRESET); |
| 2763 | else { |
| 2764 | /* |
| 2765 | * we just don't send notification upwards because we |
| 2766 | * want to retry with mpa_v1 without upper layers even |
| 2767 | * knowing it. |
| 2768 | * |
| 2769 | * do some housekeeping so as to re-initiate the |
| 2770 | * connection |
| 2771 | */ |
| 2772 | PDBG("%s: mpa_rev=%d. Retrying with mpav1\n", __func__, |
| 2773 | mpa_rev); |
| 2774 | ep->retry_with_mpa_v1 = 1; |
| 2775 | } |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2776 | break; |
| 2777 | case MPA_REP_SENT: |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2778 | break; |
| 2779 | case MPA_REQ_RCVD: |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2780 | break; |
| 2781 | case MORIBUND: |
| 2782 | case CLOSING: |
Steve Wise | ca5a220 | 2010-07-23 19:12:37 +0000 | [diff] [blame] | 2783 | stop_ep_timer(ep); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2784 | /*FALLTHROUGH*/ |
| 2785 | case FPDU_MODE: |
| 2786 | if (ep->com.cm_id && ep->com.qp) { |
| 2787 | attrs.next_state = C4IW_QP_STATE_ERROR; |
| 2788 | ret = c4iw_modify_qp(ep->com.qp->rhp, |
| 2789 | ep->com.qp, C4IW_QP_ATTR_NEXT_STATE, |
| 2790 | &attrs, 1); |
| 2791 | if (ret) |
| 2792 | printk(KERN_ERR MOD |
| 2793 | "%s - qp <- error failed!\n", |
| 2794 | __func__); |
| 2795 | } |
| 2796 | peer_abort_upcall(ep); |
| 2797 | break; |
| 2798 | case ABORTING: |
| 2799 | break; |
| 2800 | case DEAD: |
| 2801 | PDBG("%s PEER_ABORT IN DEAD STATE!!!!\n", __func__); |
Steve Wise | 2f5b48c | 2010-09-10 11:15:36 -0500 | [diff] [blame] | 2802 | mutex_unlock(&ep->com.mutex); |
Hariprasad S | 944661d | 2016-05-06 22:18:03 +0530 | [diff] [blame] | 2803 | goto deref_ep; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2804 | default: |
| 2805 | BUG_ON(1); |
| 2806 | break; |
| 2807 | } |
| 2808 | dst_confirm(ep->dst); |
| 2809 | if (ep->com.state != ABORTING) { |
| 2810 | __state_set(&ep->com, DEAD); |
Kumar Sanghvi | d2fe99e | 2011-09-25 20:17:44 +0530 | [diff] [blame] | 2811 | /* we don't release if we want to retry with mpa_v1 */ |
| 2812 | if (!ep->retry_with_mpa_v1) |
| 2813 | release = 1; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2814 | } |
Steve Wise | 2f5b48c | 2010-09-10 11:15:36 -0500 | [diff] [blame] | 2815 | mutex_unlock(&ep->com.mutex); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2816 | |
Hariprasad S | 4a74083 | 2016-06-10 01:05:15 +0530 | [diff] [blame] | 2817 | rpl_skb = skb_dequeue(&ep->com.ep_skb_list); |
| 2818 | if (WARN_ON(!rpl_skb)) { |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2819 | release = 1; |
| 2820 | goto out; |
| 2821 | } |
| 2822 | set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx); |
| 2823 | rpl = (struct cpl_abort_rpl *) skb_put(rpl_skb, sizeof(*rpl)); |
| 2824 | INIT_TP_WR(rpl, ep->hwtid); |
| 2825 | OPCODE_TID(rpl) = cpu_to_be32(MK_OPCODE_TID(CPL_ABORT_RPL, ep->hwtid)); |
| 2826 | rpl->cmd = CPL_ABORT_NO_RST; |
| 2827 | c4iw_ofld_send(&ep->com.dev->rdev, rpl_skb); |
| 2828 | out: |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2829 | if (release) |
| 2830 | release_ep_resources(ep); |
Vipul Pandya | fe7e0a4 | 2013-01-07 13:11:57 +0000 | [diff] [blame] | 2831 | else if (ep->retry_with_mpa_v1) { |
Hariprasad S | 84cc6ac6 | 2015-08-25 14:08:23 +0530 | [diff] [blame] | 2832 | if (ep->com.remote_addr.ss_family == AF_INET6) { |
| 2833 | struct sockaddr_in6 *sin6 = |
| 2834 | (struct sockaddr_in6 *) |
Steve Wise | 170003c | 2016-02-26 09:18:03 -0600 | [diff] [blame] | 2835 | &ep->com.local_addr; |
Hariprasad S | 84cc6ac6 | 2015-08-25 14:08:23 +0530 | [diff] [blame] | 2836 | cxgb4_clip_release( |
| 2837 | ep->com.dev->rdev.lldi.ports[0], |
| 2838 | (const u32 *)&sin6->sin6_addr.s6_addr, |
| 2839 | 1); |
| 2840 | } |
Vipul Pandya | fe7e0a4 | 2013-01-07 13:11:57 +0000 | [diff] [blame] | 2841 | remove_handle(ep->com.dev, &ep->com.dev->hwtid_idr, ep->hwtid); |
Kumar Sanghvi | d2fe99e | 2011-09-25 20:17:44 +0530 | [diff] [blame] | 2842 | cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, ep->hwtid); |
| 2843 | dst_release(ep->dst); |
| 2844 | cxgb4_l2t_release(ep->l2t); |
| 2845 | c4iw_reconnect(ep); |
| 2846 | } |
| 2847 | |
Hariprasad S | 944661d | 2016-05-06 22:18:03 +0530 | [diff] [blame] | 2848 | deref_ep: |
| 2849 | c4iw_put_ep(&ep->com); |
| 2850 | /* Dereferencing ep, referenced in peer_abort_intr() */ |
| 2851 | c4iw_put_ep(&ep->com); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2852 | return 0; |
| 2853 | } |
| 2854 | |
| 2855 | static int close_con_rpl(struct c4iw_dev *dev, struct sk_buff *skb) |
| 2856 | { |
| 2857 | struct c4iw_ep *ep; |
| 2858 | struct c4iw_qp_attributes attrs; |
| 2859 | struct cpl_close_con_rpl *rpl = cplhdr(skb); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2860 | int release = 0; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2861 | unsigned int tid = GET_TID(rpl); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2862 | |
Hariprasad S | 944661d | 2016-05-06 22:18:03 +0530 | [diff] [blame] | 2863 | ep = get_ep_from_tid(dev, tid); |
| 2864 | if (!ep) |
| 2865 | return 0; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2866 | |
| 2867 | PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid); |
| 2868 | BUG_ON(!ep); |
| 2869 | |
| 2870 | /* The cm_id may be null if we failed to connect */ |
Steve Wise | 2f5b48c | 2010-09-10 11:15:36 -0500 | [diff] [blame] | 2871 | mutex_lock(&ep->com.mutex); |
Hariprasad S | 9ca6f7c | 2016-05-06 22:17:54 +0530 | [diff] [blame] | 2872 | set_bit(CLOSE_CON_RPL, &ep->com.history); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2873 | switch (ep->com.state) { |
| 2874 | case CLOSING: |
| 2875 | __state_set(&ep->com, MORIBUND); |
| 2876 | break; |
| 2877 | case MORIBUND: |
Steve Wise | b33bd0c | 2014-04-09 09:38:25 -0500 | [diff] [blame] | 2878 | (void)stop_ep_timer(ep); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2879 | if ((ep->com.cm_id) && (ep->com.qp)) { |
| 2880 | attrs.next_state = C4IW_QP_STATE_IDLE; |
| 2881 | c4iw_modify_qp(ep->com.qp->rhp, |
| 2882 | ep->com.qp, |
| 2883 | C4IW_QP_ATTR_NEXT_STATE, |
| 2884 | &attrs, 1); |
| 2885 | } |
Steve Wise | be13b2d | 2014-03-21 20:40:33 +0530 | [diff] [blame] | 2886 | close_complete_upcall(ep, 0); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2887 | __state_set(&ep->com, DEAD); |
| 2888 | release = 1; |
| 2889 | break; |
| 2890 | case ABORTING: |
| 2891 | case DEAD: |
| 2892 | break; |
| 2893 | default: |
| 2894 | BUG_ON(1); |
| 2895 | break; |
| 2896 | } |
Steve Wise | 2f5b48c | 2010-09-10 11:15:36 -0500 | [diff] [blame] | 2897 | mutex_unlock(&ep->com.mutex); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2898 | if (release) |
| 2899 | release_ep_resources(ep); |
Hariprasad S | 944661d | 2016-05-06 22:18:03 +0530 | [diff] [blame] | 2900 | c4iw_put_ep(&ep->com); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2901 | return 0; |
| 2902 | } |
| 2903 | |
| 2904 | static int terminate(struct c4iw_dev *dev, struct sk_buff *skb) |
| 2905 | { |
Steve Wise | 0e42c1f | 2010-09-10 11:15:09 -0500 | [diff] [blame] | 2906 | struct cpl_rdma_terminate *rpl = cplhdr(skb); |
Steve Wise | 0e42c1f | 2010-09-10 11:15:09 -0500 | [diff] [blame] | 2907 | unsigned int tid = GET_TID(rpl); |
| 2908 | struct c4iw_ep *ep; |
| 2909 | struct c4iw_qp_attributes attrs; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2910 | |
Hariprasad S | 944661d | 2016-05-06 22:18:03 +0530 | [diff] [blame] | 2911 | ep = get_ep_from_tid(dev, tid); |
Steve Wise | 0e42c1f | 2010-09-10 11:15:09 -0500 | [diff] [blame] | 2912 | BUG_ON(!ep); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2913 | |
Steve Wise | 30c95c2 | 2011-05-09 22:06:22 -0700 | [diff] [blame] | 2914 | if (ep && ep->com.qp) { |
Steve Wise | 0e42c1f | 2010-09-10 11:15:09 -0500 | [diff] [blame] | 2915 | printk(KERN_WARNING MOD "TERM received tid %u qpid %u\n", tid, |
| 2916 | ep->com.qp->wq.sq.qid); |
| 2917 | attrs.next_state = C4IW_QP_STATE_TERMINATE; |
| 2918 | c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp, |
| 2919 | C4IW_QP_ATTR_NEXT_STATE, &attrs, 1); |
| 2920 | } else |
Steve Wise | 30c95c2 | 2011-05-09 22:06:22 -0700 | [diff] [blame] | 2921 | printk(KERN_WARNING MOD "TERM received tid %u no ep/qp\n", tid); |
Hariprasad S | 944661d | 2016-05-06 22:18:03 +0530 | [diff] [blame] | 2922 | c4iw_put_ep(&ep->com); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2923 | |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2924 | return 0; |
| 2925 | } |
| 2926 | |
| 2927 | /* |
| 2928 | * Upcall from the adapter indicating data has been transmitted. |
| 2929 | * For us its just the single MPA request or reply. We can now free |
| 2930 | * the skb holding the mpa message. |
| 2931 | */ |
| 2932 | static int fw4_ack(struct c4iw_dev *dev, struct sk_buff *skb) |
| 2933 | { |
| 2934 | struct c4iw_ep *ep; |
| 2935 | struct cpl_fw4_ack *hdr = cplhdr(skb); |
| 2936 | u8 credits = hdr->credits; |
| 2937 | unsigned int tid = GET_TID(hdr); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2938 | |
| 2939 | |
Hariprasad S | 944661d | 2016-05-06 22:18:03 +0530 | [diff] [blame] | 2940 | ep = get_ep_from_tid(dev, tid); |
| 2941 | if (!ep) |
| 2942 | return 0; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2943 | PDBG("%s ep %p tid %u credits %u\n", __func__, ep, ep->hwtid, credits); |
| 2944 | if (credits == 0) { |
Joe Perches | aa1ad26 | 2010-10-25 19:44:22 -0700 | [diff] [blame] | 2945 | PDBG("%s 0 credit ack ep %p tid %u state %u\n", |
| 2946 | __func__, ep, ep->hwtid, state_read(&ep->com)); |
Hariprasad S | 944661d | 2016-05-06 22:18:03 +0530 | [diff] [blame] | 2947 | goto out; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2948 | } |
| 2949 | |
| 2950 | dst_confirm(ep->dst); |
| 2951 | if (ep->mpa_skb) { |
| 2952 | PDBG("%s last streaming msg ack ep %p tid %u state %u " |
| 2953 | "initiator %u freeing skb\n", __func__, ep, ep->hwtid, |
| 2954 | state_read(&ep->com), ep->mpa_attr.initiator ? 1 : 0); |
Steve Wise | 12eb513 | 2016-07-29 08:38:44 -0700 | [diff] [blame] | 2955 | mutex_lock(&ep->com.mutex); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2956 | kfree_skb(ep->mpa_skb); |
| 2957 | ep->mpa_skb = NULL; |
Hariprasad S | e4b76a2 | 2016-05-06 22:17:59 +0530 | [diff] [blame] | 2958 | if (test_bit(STOP_MPA_TIMER, &ep->com.flags)) |
| 2959 | stop_ep_timer(ep); |
| 2960 | mutex_unlock(&ep->com.mutex); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2961 | } |
Hariprasad S | 944661d | 2016-05-06 22:18:03 +0530 | [diff] [blame] | 2962 | out: |
| 2963 | c4iw_put_ep(&ep->com); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2964 | return 0; |
| 2965 | } |
| 2966 | |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2967 | int c4iw_reject_cr(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len) |
| 2968 | { |
Hariprasad S | bce2841 | 2016-06-10 01:05:13 +0530 | [diff] [blame] | 2969 | int abort; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2970 | struct c4iw_ep *ep = to_ep(cm_id); |
Hariprasad S | bce2841 | 2016-06-10 01:05:13 +0530 | [diff] [blame] | 2971 | |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2972 | PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid); |
| 2973 | |
Steve Wise | a7db89e | 2014-03-21 20:40:35 +0530 | [diff] [blame] | 2974 | mutex_lock(&ep->com.mutex); |
Hariprasad S | e8667a9 | 2016-05-06 22:18:06 +0530 | [diff] [blame] | 2975 | if (ep->com.state != MPA_REQ_RCVD) { |
Steve Wise | a7db89e | 2014-03-21 20:40:35 +0530 | [diff] [blame] | 2976 | mutex_unlock(&ep->com.mutex); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2977 | c4iw_put_ep(&ep->com); |
| 2978 | return -ECONNRESET; |
| 2979 | } |
Vipul Pandya | 793dad9 | 2012-12-10 09:30:56 +0000 | [diff] [blame] | 2980 | set_bit(ULP_REJECT, &ep->com.history); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2981 | if (mpa_rev == 0) |
Hariprasad S | bce2841 | 2016-06-10 01:05:13 +0530 | [diff] [blame] | 2982 | abort = 1; |
| 2983 | else |
| 2984 | abort = send_mpa_reject(ep, pdata, pdata_len); |
Steve Wise | a7db89e | 2014-03-21 20:40:35 +0530 | [diff] [blame] | 2985 | mutex_unlock(&ep->com.mutex); |
Hariprasad S | bce2841 | 2016-06-10 01:05:13 +0530 | [diff] [blame] | 2986 | |
| 2987 | stop_ep_timer(ep); |
| 2988 | c4iw_ep_disconnect(ep, abort != 0, GFP_KERNEL); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2989 | c4iw_put_ep(&ep->com); |
| 2990 | return 0; |
| 2991 | } |
| 2992 | |
| 2993 | int c4iw_accept_cr(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param) |
| 2994 | { |
| 2995 | int err; |
| 2996 | struct c4iw_qp_attributes attrs; |
| 2997 | enum c4iw_qp_attr_mask mask; |
| 2998 | struct c4iw_ep *ep = to_ep(cm_id); |
| 2999 | struct c4iw_dev *h = to_c4iw_dev(cm_id->device); |
| 3000 | struct c4iw_qp *qp = get_qhp(h, conn_param->qpn); |
Hariprasad S | eaf4c6d | 2016-05-05 01:27:34 +0530 | [diff] [blame] | 3001 | int abort = 0; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 3002 | |
| 3003 | PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid); |
Steve Wise | a7db89e | 2014-03-21 20:40:35 +0530 | [diff] [blame] | 3004 | |
| 3005 | mutex_lock(&ep->com.mutex); |
Hariprasad S | e8667a9 | 2016-05-06 22:18:06 +0530 | [diff] [blame] | 3006 | if (ep->com.state != MPA_REQ_RCVD) { |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 3007 | err = -ECONNRESET; |
Hariprasad S | eaf4c6d | 2016-05-05 01:27:34 +0530 | [diff] [blame] | 3008 | goto err_out; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 3009 | } |
| 3010 | |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 3011 | BUG_ON(!qp); |
| 3012 | |
Vipul Pandya | 793dad9 | 2012-12-10 09:30:56 +0000 | [diff] [blame] | 3013 | set_bit(ULP_ACCEPT, &ep->com.history); |
Hariprasad Shenai | 4c2c576 | 2014-07-14 21:34:52 +0530 | [diff] [blame] | 3014 | if ((conn_param->ord > cur_max_read_depth(ep->com.dev)) || |
| 3015 | (conn_param->ird > cur_max_read_depth(ep->com.dev))) { |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 3016 | err = -EINVAL; |
Hariprasad S | eaf4c6d | 2016-05-05 01:27:34 +0530 | [diff] [blame] | 3017 | goto err_abort; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 3018 | } |
| 3019 | |
Kumar Sanghvi | d2fe99e | 2011-09-25 20:17:44 +0530 | [diff] [blame] | 3020 | if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) { |
| 3021 | if (conn_param->ord > ep->ird) { |
Hariprasad Shenai | 4c2c576 | 2014-07-14 21:34:52 +0530 | [diff] [blame] | 3022 | if (RELAXED_IRD_NEGOTIATION) { |
Steve Wise | 30b03b1 | 2016-08-19 07:29:08 -0700 | [diff] [blame] | 3023 | conn_param->ord = ep->ird; |
Hariprasad Shenai | 4c2c576 | 2014-07-14 21:34:52 +0530 | [diff] [blame] | 3024 | } else { |
| 3025 | ep->ird = conn_param->ird; |
| 3026 | ep->ord = conn_param->ord; |
| 3027 | send_mpa_reject(ep, conn_param->private_data, |
| 3028 | conn_param->private_data_len); |
Kumar Sanghvi | d2fe99e | 2011-09-25 20:17:44 +0530 | [diff] [blame] | 3029 | err = -ENOMEM; |
Hariprasad S | eaf4c6d | 2016-05-05 01:27:34 +0530 | [diff] [blame] | 3030 | goto err_abort; |
Kumar Sanghvi | d2fe99e | 2011-09-25 20:17:44 +0530 | [diff] [blame] | 3031 | } |
| 3032 | } |
Hariprasad Shenai | 4c2c576 | 2014-07-14 21:34:52 +0530 | [diff] [blame] | 3033 | if (conn_param->ird < ep->ord) { |
| 3034 | if (RELAXED_IRD_NEGOTIATION && |
| 3035 | ep->ord <= h->rdev.lldi.max_ordird_qp) { |
| 3036 | conn_param->ird = ep->ord; |
| 3037 | } else { |
Hariprasad Shenai | 4c2c576 | 2014-07-14 21:34:52 +0530 | [diff] [blame] | 3038 | err = -ENOMEM; |
Hariprasad S | eaf4c6d | 2016-05-05 01:27:34 +0530 | [diff] [blame] | 3039 | goto err_abort; |
Hariprasad Shenai | 4c2c576 | 2014-07-14 21:34:52 +0530 | [diff] [blame] | 3040 | } |
| 3041 | } |
Kumar Sanghvi | d2fe99e | 2011-09-25 20:17:44 +0530 | [diff] [blame] | 3042 | } |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 3043 | ep->ird = conn_param->ird; |
| 3044 | ep->ord = conn_param->ord; |
| 3045 | |
Hariprasad Shenai | 4c2c576 | 2014-07-14 21:34:52 +0530 | [diff] [blame] | 3046 | if (ep->mpa_attr.version == 1) { |
Kumar Sanghvi | d2fe99e | 2011-09-25 20:17:44 +0530 | [diff] [blame] | 3047 | if (peer2peer && ep->ird == 0) |
| 3048 | ep->ird = 1; |
Hariprasad Shenai | 4c2c576 | 2014-07-14 21:34:52 +0530 | [diff] [blame] | 3049 | } else { |
| 3050 | if (peer2peer && |
| 3051 | (ep->mpa_attr.p2p_type != FW_RI_INIT_P2PTYPE_DISABLED) && |
Hariprasad S | f57b780 | 2015-09-08 09:56:59 +0530 | [diff] [blame] | 3052 | (p2p_type == FW_RI_INIT_P2PTYPE_READ_REQ) && ep->ird == 0) |
Hariprasad Shenai | 4c2c576 | 2014-07-14 21:34:52 +0530 | [diff] [blame] | 3053 | ep->ird = 1; |
| 3054 | } |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 3055 | |
| 3056 | PDBG("%s %d ird %d ord %d\n", __func__, __LINE__, ep->ird, ep->ord); |
| 3057 | |
Kumar Sanghvi | d2fe99e | 2011-09-25 20:17:44 +0530 | [diff] [blame] | 3058 | ep->com.cm_id = cm_id; |
Hariprasad S | 9ca6f7c | 2016-05-06 22:17:54 +0530 | [diff] [blame] | 3059 | ref_cm_id(&ep->com); |
Kumar Sanghvi | d2fe99e | 2011-09-25 20:17:44 +0530 | [diff] [blame] | 3060 | ep->com.qp = qp; |
Vipul Pandya | 325abea | 2013-01-07 13:11:53 +0000 | [diff] [blame] | 3061 | ref_qp(ep); |
Kumar Sanghvi | d2fe99e | 2011-09-25 20:17:44 +0530 | [diff] [blame] | 3062 | |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 3063 | /* bind QP to EP and move to RTS */ |
| 3064 | attrs.mpa_attr = ep->mpa_attr; |
| 3065 | attrs.max_ird = ep->ird; |
| 3066 | attrs.max_ord = ep->ord; |
| 3067 | attrs.llp_stream_handle = ep; |
| 3068 | attrs.next_state = C4IW_QP_STATE_RTS; |
| 3069 | |
| 3070 | /* bind QP and TID with INIT_WR */ |
| 3071 | mask = C4IW_QP_ATTR_NEXT_STATE | |
| 3072 | C4IW_QP_ATTR_LLP_STREAM_HANDLE | |
| 3073 | C4IW_QP_ATTR_MPA_ATTR | |
| 3074 | C4IW_QP_ATTR_MAX_IRD | |
| 3075 | C4IW_QP_ATTR_MAX_ORD; |
| 3076 | |
| 3077 | err = c4iw_modify_qp(ep->com.qp->rhp, |
| 3078 | ep->com.qp, mask, &attrs, 1); |
| 3079 | if (err) |
Hariprasad S | eaf4c6d | 2016-05-05 01:27:34 +0530 | [diff] [blame] | 3080 | goto err_deref_cm_id; |
Hariprasad S | e4b76a2 | 2016-05-06 22:17:59 +0530 | [diff] [blame] | 3081 | |
| 3082 | set_bit(STOP_MPA_TIMER, &ep->com.flags); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 3083 | err = send_mpa_reply(ep, conn_param->private_data, |
| 3084 | conn_param->private_data_len); |
| 3085 | if (err) |
Hariprasad S | eaf4c6d | 2016-05-05 01:27:34 +0530 | [diff] [blame] | 3086 | goto err_deref_cm_id; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 3087 | |
Steve Wise | a7db89e | 2014-03-21 20:40:35 +0530 | [diff] [blame] | 3088 | __state_set(&ep->com, FPDU_MODE); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 3089 | established_upcall(ep); |
Steve Wise | a7db89e | 2014-03-21 20:40:35 +0530 | [diff] [blame] | 3090 | mutex_unlock(&ep->com.mutex); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 3091 | c4iw_put_ep(&ep->com); |
| 3092 | return 0; |
Hariprasad S | eaf4c6d | 2016-05-05 01:27:34 +0530 | [diff] [blame] | 3093 | err_deref_cm_id: |
Hariprasad S | 9ca6f7c | 2016-05-06 22:17:54 +0530 | [diff] [blame] | 3094 | deref_cm_id(&ep->com); |
Hariprasad S | eaf4c6d | 2016-05-05 01:27:34 +0530 | [diff] [blame] | 3095 | err_abort: |
| 3096 | abort = 1; |
| 3097 | err_out: |
Steve Wise | a7db89e | 2014-03-21 20:40:35 +0530 | [diff] [blame] | 3098 | mutex_unlock(&ep->com.mutex); |
Hariprasad S | eaf4c6d | 2016-05-05 01:27:34 +0530 | [diff] [blame] | 3099 | if (abort) |
| 3100 | c4iw_ep_disconnect(ep, 1, GFP_KERNEL); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 3101 | c4iw_put_ep(&ep->com); |
| 3102 | return err; |
| 3103 | } |
| 3104 | |
Vipul Pandya | 830662f | 2013-07-04 16:10:47 +0530 | [diff] [blame] | 3105 | static int pick_local_ipaddrs(struct c4iw_dev *dev, struct iw_cm_id *cm_id) |
| 3106 | { |
| 3107 | struct in_device *ind; |
| 3108 | int found = 0; |
Steve Wise | 170003c | 2016-02-26 09:18:03 -0600 | [diff] [blame] | 3109 | struct sockaddr_in *laddr = (struct sockaddr_in *)&cm_id->m_local_addr; |
| 3110 | struct sockaddr_in *raddr = (struct sockaddr_in *)&cm_id->m_remote_addr; |
Vipul Pandya | 830662f | 2013-07-04 16:10:47 +0530 | [diff] [blame] | 3111 | |
| 3112 | ind = in_dev_get(dev->rdev.lldi.ports[0]); |
| 3113 | if (!ind) |
| 3114 | return -EADDRNOTAVAIL; |
| 3115 | for_primary_ifa(ind) { |
| 3116 | laddr->sin_addr.s_addr = ifa->ifa_address; |
| 3117 | raddr->sin_addr.s_addr = ifa->ifa_address; |
| 3118 | found = 1; |
| 3119 | break; |
| 3120 | } |
| 3121 | endfor_ifa(ind); |
| 3122 | in_dev_put(ind); |
| 3123 | return found ? 0 : -EADDRNOTAVAIL; |
| 3124 | } |
| 3125 | |
| 3126 | static int get_lladdr(struct net_device *dev, struct in6_addr *addr, |
| 3127 | unsigned char banned_flags) |
| 3128 | { |
| 3129 | struct inet6_dev *idev; |
| 3130 | int err = -EADDRNOTAVAIL; |
| 3131 | |
| 3132 | rcu_read_lock(); |
| 3133 | idev = __in6_dev_get(dev); |
| 3134 | if (idev != NULL) { |
| 3135 | struct inet6_ifaddr *ifp; |
| 3136 | |
| 3137 | read_lock_bh(&idev->lock); |
| 3138 | list_for_each_entry(ifp, &idev->addr_list, if_list) { |
| 3139 | if (ifp->scope == IFA_LINK && |
| 3140 | !(ifp->flags & banned_flags)) { |
| 3141 | memcpy(addr, &ifp->addr, 16); |
| 3142 | err = 0; |
| 3143 | break; |
| 3144 | } |
| 3145 | } |
| 3146 | read_unlock_bh(&idev->lock); |
| 3147 | } |
| 3148 | rcu_read_unlock(); |
| 3149 | return err; |
| 3150 | } |
| 3151 | |
| 3152 | static int pick_local_ip6addrs(struct c4iw_dev *dev, struct iw_cm_id *cm_id) |
| 3153 | { |
| 3154 | struct in6_addr uninitialized_var(addr); |
Steve Wise | 170003c | 2016-02-26 09:18:03 -0600 | [diff] [blame] | 3155 | struct sockaddr_in6 *la6 = (struct sockaddr_in6 *)&cm_id->m_local_addr; |
| 3156 | struct sockaddr_in6 *ra6 = (struct sockaddr_in6 *)&cm_id->m_remote_addr; |
Vipul Pandya | 830662f | 2013-07-04 16:10:47 +0530 | [diff] [blame] | 3157 | |
Nicholas Krause | 54b9a96 | 2015-08-26 23:00:59 -0400 | [diff] [blame] | 3158 | if (!get_lladdr(dev->rdev.lldi.ports[0], &addr, IFA_F_TENTATIVE)) { |
Vipul Pandya | 830662f | 2013-07-04 16:10:47 +0530 | [diff] [blame] | 3159 | memcpy(la6->sin6_addr.s6_addr, &addr, 16); |
| 3160 | memcpy(ra6->sin6_addr.s6_addr, &addr, 16); |
| 3161 | return 0; |
| 3162 | } |
| 3163 | return -EADDRNOTAVAIL; |
| 3164 | } |
| 3165 | |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 3166 | int c4iw_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param) |
| 3167 | { |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 3168 | struct c4iw_dev *dev = to_c4iw_dev(cm_id->device); |
| 3169 | struct c4iw_ep *ep; |
David Miller | 3786cf1 | 2011-12-02 16:52:31 +0000 | [diff] [blame] | 3170 | int err = 0; |
Steve Wise | 9eccfe1 | 2014-03-26 17:08:09 -0500 | [diff] [blame] | 3171 | struct sockaddr_in *laddr; |
| 3172 | struct sockaddr_in *raddr; |
| 3173 | struct sockaddr_in6 *laddr6; |
| 3174 | struct sockaddr_in6 *raddr6; |
Vipul Pandya | 830662f | 2013-07-04 16:10:47 +0530 | [diff] [blame] | 3175 | __u8 *ra; |
| 3176 | int iptype; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 3177 | |
Hariprasad Shenai | 4c2c576 | 2014-07-14 21:34:52 +0530 | [diff] [blame] | 3178 | if ((conn_param->ord > cur_max_read_depth(dev)) || |
| 3179 | (conn_param->ird > cur_max_read_depth(dev))) { |
Roland Dreier | be4c9ba | 2010-05-05 14:45:40 -0700 | [diff] [blame] | 3180 | err = -EINVAL; |
| 3181 | goto out; |
| 3182 | } |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 3183 | ep = alloc_ep(sizeof(*ep), GFP_KERNEL); |
| 3184 | if (!ep) { |
| 3185 | printk(KERN_ERR MOD "%s - cannot alloc ep.\n", __func__); |
| 3186 | err = -ENOMEM; |
| 3187 | goto out; |
| 3188 | } |
Hariprasad S | 4a74083 | 2016-06-10 01:05:15 +0530 | [diff] [blame] | 3189 | |
| 3190 | skb_queue_head_init(&ep->com.ep_skb_list); |
| 3191 | if (alloc_ep_skb_list(&ep->com.ep_skb_list, CN_MAX_CON_BUF)) { |
| 3192 | err = -ENOMEM; |
| 3193 | goto fail1; |
| 3194 | } |
| 3195 | |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 3196 | init_timer(&ep->timer); |
| 3197 | ep->plen = conn_param->private_data_len; |
| 3198 | if (ep->plen) |
| 3199 | memcpy(ep->mpa_pkt + sizeof(struct mpa_message), |
| 3200 | conn_param->private_data, ep->plen); |
| 3201 | ep->ird = conn_param->ird; |
| 3202 | ep->ord = conn_param->ord; |
| 3203 | |
| 3204 | if (peer2peer && ep->ord == 0) |
| 3205 | ep->ord = 1; |
| 3206 | |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 3207 | ep->com.cm_id = cm_id; |
Hariprasad S | 9ca6f7c | 2016-05-06 22:17:54 +0530 | [diff] [blame] | 3208 | ref_cm_id(&ep->com); |
| 3209 | ep->com.dev = dev; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 3210 | ep->com.qp = get_qhp(dev, conn_param->qpn); |
Vipul Pandya | 830662f | 2013-07-04 16:10:47 +0530 | [diff] [blame] | 3211 | if (!ep->com.qp) { |
| 3212 | PDBG("%s qpn 0x%x not found!\n", __func__, conn_param->qpn); |
| 3213 | err = -EINVAL; |
Hariprasad S | 4a74083 | 2016-06-10 01:05:15 +0530 | [diff] [blame] | 3214 | goto fail2; |
Vipul Pandya | 830662f | 2013-07-04 16:10:47 +0530 | [diff] [blame] | 3215 | } |
Vipul Pandya | 325abea | 2013-01-07 13:11:53 +0000 | [diff] [blame] | 3216 | ref_qp(ep); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 3217 | PDBG("%s qpn 0x%x qp %p cm_id %p\n", __func__, conn_param->qpn, |
| 3218 | ep->com.qp, cm_id); |
| 3219 | |
| 3220 | /* |
| 3221 | * Allocate an active TID to initiate a TCP connection. |
| 3222 | */ |
| 3223 | ep->atid = cxgb4_alloc_atid(dev->rdev.lldi.tids, ep); |
| 3224 | if (ep->atid == -1) { |
| 3225 | printk(KERN_ERR MOD "%s - cannot alloc atid.\n", __func__); |
| 3226 | err = -ENOMEM; |
Hariprasad S | 4a74083 | 2016-06-10 01:05:15 +0530 | [diff] [blame] | 3227 | goto fail2; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 3228 | } |
Vipul Pandya | 793dad9 | 2012-12-10 09:30:56 +0000 | [diff] [blame] | 3229 | insert_handle(dev, &dev->atid_idr, ep, ep->atid); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 3230 | |
Steve Wise | 170003c | 2016-02-26 09:18:03 -0600 | [diff] [blame] | 3231 | memcpy(&ep->com.local_addr, &cm_id->m_local_addr, |
Steve Wise | 9eccfe1 | 2014-03-26 17:08:09 -0500 | [diff] [blame] | 3232 | sizeof(ep->com.local_addr)); |
Steve Wise | 170003c | 2016-02-26 09:18:03 -0600 | [diff] [blame] | 3233 | memcpy(&ep->com.remote_addr, &cm_id->m_remote_addr, |
Steve Wise | 9eccfe1 | 2014-03-26 17:08:09 -0500 | [diff] [blame] | 3234 | sizeof(ep->com.remote_addr)); |
| 3235 | |
Steve Wise | 170003c | 2016-02-26 09:18:03 -0600 | [diff] [blame] | 3236 | laddr = (struct sockaddr_in *)&ep->com.local_addr; |
| 3237 | raddr = (struct sockaddr_in *)&ep->com.remote_addr; |
| 3238 | laddr6 = (struct sockaddr_in6 *)&ep->com.local_addr; |
| 3239 | raddr6 = (struct sockaddr_in6 *) &ep->com.remote_addr; |
Steve Wise | 9eccfe1 | 2014-03-26 17:08:09 -0500 | [diff] [blame] | 3240 | |
Steve Wise | 170003c | 2016-02-26 09:18:03 -0600 | [diff] [blame] | 3241 | if (cm_id->m_remote_addr.ss_family == AF_INET) { |
Vipul Pandya | 830662f | 2013-07-04 16:10:47 +0530 | [diff] [blame] | 3242 | iptype = 4; |
| 3243 | ra = (__u8 *)&raddr->sin_addr; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 3244 | |
Vipul Pandya | 830662f | 2013-07-04 16:10:47 +0530 | [diff] [blame] | 3245 | /* |
| 3246 | * Handle loopback requests to INADDR_ANY. |
| 3247 | */ |
Bart Van Assche | ba987e5 | 2016-04-12 14:45:24 -0700 | [diff] [blame] | 3248 | if (raddr->sin_addr.s_addr == htonl(INADDR_ANY)) { |
Vipul Pandya | 830662f | 2013-07-04 16:10:47 +0530 | [diff] [blame] | 3249 | err = pick_local_ipaddrs(dev, cm_id); |
| 3250 | if (err) |
Hariprasad S | 4a74083 | 2016-06-10 01:05:15 +0530 | [diff] [blame] | 3251 | goto fail2; |
Vipul Pandya | 830662f | 2013-07-04 16:10:47 +0530 | [diff] [blame] | 3252 | } |
| 3253 | |
| 3254 | /* find a route */ |
| 3255 | PDBG("%s saddr %pI4 sport 0x%x raddr %pI4 rport 0x%x\n", |
| 3256 | __func__, &laddr->sin_addr, ntohs(laddr->sin_port), |
| 3257 | ra, ntohs(raddr->sin_port)); |
Varun Prakash | 804c2f3 | 2016-09-13 21:23:57 +0530 | [diff] [blame] | 3258 | ep->dst = cxgb_find_route(&dev->rdev.lldi, get_real_dev, |
| 3259 | laddr->sin_addr.s_addr, |
| 3260 | raddr->sin_addr.s_addr, |
| 3261 | laddr->sin_port, |
| 3262 | raddr->sin_port, cm_id->tos); |
Vipul Pandya | 830662f | 2013-07-04 16:10:47 +0530 | [diff] [blame] | 3263 | } else { |
| 3264 | iptype = 6; |
| 3265 | ra = (__u8 *)&raddr6->sin6_addr; |
| 3266 | |
| 3267 | /* |
| 3268 | * Handle loopback requests to INADDR_ANY. |
| 3269 | */ |
| 3270 | if (ipv6_addr_type(&raddr6->sin6_addr) == IPV6_ADDR_ANY) { |
| 3271 | err = pick_local_ip6addrs(dev, cm_id); |
| 3272 | if (err) |
Hariprasad S | 4a74083 | 2016-06-10 01:05:15 +0530 | [diff] [blame] | 3273 | goto fail2; |
Vipul Pandya | 830662f | 2013-07-04 16:10:47 +0530 | [diff] [blame] | 3274 | } |
| 3275 | |
| 3276 | /* find a route */ |
| 3277 | PDBG("%s saddr %pI6 sport 0x%x raddr %pI6 rport 0x%x\n", |
| 3278 | __func__, laddr6->sin6_addr.s6_addr, |
| 3279 | ntohs(laddr6->sin6_port), |
| 3280 | raddr6->sin6_addr.s6_addr, ntohs(raddr6->sin6_port)); |
Varun Prakash | 9555476 | 2016-09-13 21:23:58 +0530 | [diff] [blame] | 3281 | ep->dst = cxgb_find_route6(&dev->rdev.lldi, get_real_dev, |
| 3282 | laddr6->sin6_addr.s6_addr, |
| 3283 | raddr6->sin6_addr.s6_addr, |
| 3284 | laddr6->sin6_port, |
| 3285 | raddr6->sin6_port, 0, |
| 3286 | raddr6->sin6_scope_id); |
Vipul Pandya | 830662f | 2013-07-04 16:10:47 +0530 | [diff] [blame] | 3287 | } |
| 3288 | if (!ep->dst) { |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 3289 | printk(KERN_ERR MOD "%s - cannot find route.\n", __func__); |
| 3290 | err = -EHOSTUNREACH; |
Hariprasad S | 4a74083 | 2016-06-10 01:05:15 +0530 | [diff] [blame] | 3291 | goto fail3; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 3292 | } |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 3293 | |
Hariprasad S | 963cab5 | 2015-09-23 17:19:27 +0530 | [diff] [blame] | 3294 | err = import_ep(ep, iptype, ra, ep->dst, ep->com.dev, true, |
Hariprasad S | ac8e4c6 | 2016-02-05 11:43:30 +0530 | [diff] [blame] | 3295 | ep->com.dev->rdev.lldi.adapter_type, cm_id->tos); |
David Miller | 3786cf1 | 2011-12-02 16:52:31 +0000 | [diff] [blame] | 3296 | if (err) { |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 3297 | printk(KERN_ERR MOD "%s - cannot alloc l2e.\n", __func__); |
Hariprasad S | 4a74083 | 2016-06-10 01:05:15 +0530 | [diff] [blame] | 3298 | goto fail4; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 3299 | } |
| 3300 | |
| 3301 | PDBG("%s txq_idx %u tx_chan %u smac_idx %u rss_qid %u l2t_idx %u\n", |
| 3302 | __func__, ep->txq_idx, ep->tx_chan, ep->smac_idx, ep->rss_qid, |
| 3303 | ep->l2t->idx); |
| 3304 | |
| 3305 | state_set(&ep->com, CONNECTING); |
Hariprasad S | ac8e4c6 | 2016-02-05 11:43:30 +0530 | [diff] [blame] | 3306 | ep->tos = cm_id->tos; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 3307 | |
| 3308 | /* send connect request to rnic */ |
| 3309 | err = send_connect(ep); |
| 3310 | if (!err) |
| 3311 | goto out; |
| 3312 | |
| 3313 | cxgb4_l2t_release(ep->l2t); |
Hariprasad S | 4a74083 | 2016-06-10 01:05:15 +0530 | [diff] [blame] | 3314 | fail4: |
Steve Wise | 9eccfe1 | 2014-03-26 17:08:09 -0500 | [diff] [blame] | 3315 | dst_release(ep->dst); |
Hariprasad S | 4a74083 | 2016-06-10 01:05:15 +0530 | [diff] [blame] | 3316 | fail3: |
Vipul Pandya | 793dad9 | 2012-12-10 09:30:56 +0000 | [diff] [blame] | 3317 | remove_handle(ep->com.dev, &ep->com.dev->atid_idr, ep->atid); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 3318 | cxgb4_free_atid(ep->com.dev->rdev.lldi.tids, ep->atid); |
Hariprasad S | 4a74083 | 2016-06-10 01:05:15 +0530 | [diff] [blame] | 3319 | fail2: |
| 3320 | skb_queue_purge(&ep->com.ep_skb_list); |
Hariprasad S | 9ca6f7c | 2016-05-06 22:17:54 +0530 | [diff] [blame] | 3321 | deref_cm_id(&ep->com); |
Hariprasad S | 4a74083 | 2016-06-10 01:05:15 +0530 | [diff] [blame] | 3322 | fail1: |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 3323 | c4iw_put_ep(&ep->com); |
| 3324 | out: |
| 3325 | return err; |
| 3326 | } |
| 3327 | |
Vipul Pandya | 830662f | 2013-07-04 16:10:47 +0530 | [diff] [blame] | 3328 | static int create_server6(struct c4iw_dev *dev, struct c4iw_listen_ep *ep) |
| 3329 | { |
| 3330 | int err; |
Steve Wise | 9eccfe1 | 2014-03-26 17:08:09 -0500 | [diff] [blame] | 3331 | struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *) |
Steve Wise | 170003c | 2016-02-26 09:18:03 -0600 | [diff] [blame] | 3332 | &ep->com.local_addr; |
Vipul Pandya | 830662f | 2013-07-04 16:10:47 +0530 | [diff] [blame] | 3333 | |
Hariprasad S | 28de1f7 | 2016-01-13 10:03:14 +0530 | [diff] [blame] | 3334 | if (ipv6_addr_type(&sin6->sin6_addr) != IPV6_ADDR_ANY) { |
| 3335 | err = cxgb4_clip_get(ep->com.dev->rdev.lldi.ports[0], |
| 3336 | (const u32 *)&sin6->sin6_addr.s6_addr, 1); |
| 3337 | if (err) |
| 3338 | return err; |
| 3339 | } |
Vipul Pandya | 830662f | 2013-07-04 16:10:47 +0530 | [diff] [blame] | 3340 | c4iw_init_wr_wait(&ep->com.wr_wait); |
| 3341 | err = cxgb4_create_server6(ep->com.dev->rdev.lldi.ports[0], |
| 3342 | ep->stid, &sin6->sin6_addr, |
| 3343 | sin6->sin6_port, |
| 3344 | ep->com.dev->rdev.lldi.rxq_ids[0]); |
| 3345 | if (!err) |
| 3346 | err = c4iw_wait_for_reply(&ep->com.dev->rdev, |
| 3347 | &ep->com.wr_wait, |
| 3348 | 0, 0, __func__); |
Hariprasad S | e6b1116 | 2014-12-08 15:02:47 +0530 | [diff] [blame] | 3349 | else if (err > 0) |
| 3350 | err = net_xmit_errno(err); |
Hariprasad S | 28de1f7 | 2016-01-13 10:03:14 +0530 | [diff] [blame] | 3351 | if (err) { |
| 3352 | cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0], |
| 3353 | (const u32 *)&sin6->sin6_addr.s6_addr, 1); |
Vipul Pandya | 830662f | 2013-07-04 16:10:47 +0530 | [diff] [blame] | 3354 | pr_err("cxgb4_create_server6/filter failed err %d stid %d laddr %pI6 lport %d\n", |
| 3355 | err, ep->stid, |
| 3356 | sin6->sin6_addr.s6_addr, ntohs(sin6->sin6_port)); |
Hariprasad S | 28de1f7 | 2016-01-13 10:03:14 +0530 | [diff] [blame] | 3357 | } |
Vipul Pandya | 830662f | 2013-07-04 16:10:47 +0530 | [diff] [blame] | 3358 | return err; |
| 3359 | } |
| 3360 | |
| 3361 | static int create_server4(struct c4iw_dev *dev, struct c4iw_listen_ep *ep) |
| 3362 | { |
| 3363 | int err; |
Steve Wise | 9eccfe1 | 2014-03-26 17:08:09 -0500 | [diff] [blame] | 3364 | struct sockaddr_in *sin = (struct sockaddr_in *) |
Steve Wise | 170003c | 2016-02-26 09:18:03 -0600 | [diff] [blame] | 3365 | &ep->com.local_addr; |
Vipul Pandya | 830662f | 2013-07-04 16:10:47 +0530 | [diff] [blame] | 3366 | |
| 3367 | if (dev->rdev.lldi.enable_fw_ofld_conn) { |
| 3368 | do { |
| 3369 | err = cxgb4_create_server_filter( |
| 3370 | ep->com.dev->rdev.lldi.ports[0], ep->stid, |
| 3371 | sin->sin_addr.s_addr, sin->sin_port, 0, |
| 3372 | ep->com.dev->rdev.lldi.rxq_ids[0], 0, 0); |
| 3373 | if (err == -EBUSY) { |
Hariprasad S | 99718e5 | 2015-09-08 09:56:57 +0530 | [diff] [blame] | 3374 | if (c4iw_fatal_error(&ep->com.dev->rdev)) { |
| 3375 | err = -EIO; |
| 3376 | break; |
| 3377 | } |
Vipul Pandya | 830662f | 2013-07-04 16:10:47 +0530 | [diff] [blame] | 3378 | set_current_state(TASK_UNINTERRUPTIBLE); |
| 3379 | schedule_timeout(usecs_to_jiffies(100)); |
| 3380 | } |
| 3381 | } while (err == -EBUSY); |
| 3382 | } else { |
| 3383 | c4iw_init_wr_wait(&ep->com.wr_wait); |
| 3384 | err = cxgb4_create_server(ep->com.dev->rdev.lldi.ports[0], |
| 3385 | ep->stid, sin->sin_addr.s_addr, sin->sin_port, |
| 3386 | 0, ep->com.dev->rdev.lldi.rxq_ids[0]); |
| 3387 | if (!err) |
| 3388 | err = c4iw_wait_for_reply(&ep->com.dev->rdev, |
| 3389 | &ep->com.wr_wait, |
| 3390 | 0, 0, __func__); |
Hariprasad S | e6b1116 | 2014-12-08 15:02:47 +0530 | [diff] [blame] | 3391 | else if (err > 0) |
| 3392 | err = net_xmit_errno(err); |
Vipul Pandya | 830662f | 2013-07-04 16:10:47 +0530 | [diff] [blame] | 3393 | } |
| 3394 | if (err) |
| 3395 | pr_err("cxgb4_create_server/filter failed err %d stid %d laddr %pI4 lport %d\n" |
| 3396 | , err, ep->stid, |
| 3397 | &sin->sin_addr, ntohs(sin->sin_port)); |
| 3398 | return err; |
| 3399 | } |
| 3400 | |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 3401 | int c4iw_create_listen(struct iw_cm_id *cm_id, int backlog) |
| 3402 | { |
| 3403 | int err = 0; |
| 3404 | struct c4iw_dev *dev = to_c4iw_dev(cm_id->device); |
| 3405 | struct c4iw_listen_ep *ep; |
| 3406 | |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 3407 | might_sleep(); |
| 3408 | |
| 3409 | ep = alloc_ep(sizeof(*ep), GFP_KERNEL); |
| 3410 | if (!ep) { |
| 3411 | printk(KERN_ERR MOD "%s - cannot alloc ep.\n", __func__); |
| 3412 | err = -ENOMEM; |
| 3413 | goto fail1; |
| 3414 | } |
Hariprasad S | 4a74083 | 2016-06-10 01:05:15 +0530 | [diff] [blame] | 3415 | skb_queue_head_init(&ep->com.ep_skb_list); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 3416 | PDBG("%s ep %p\n", __func__, ep); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 3417 | ep->com.cm_id = cm_id; |
Hariprasad S | 9ca6f7c | 2016-05-06 22:17:54 +0530 | [diff] [blame] | 3418 | ref_cm_id(&ep->com); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 3419 | ep->com.dev = dev; |
| 3420 | ep->backlog = backlog; |
Steve Wise | 170003c | 2016-02-26 09:18:03 -0600 | [diff] [blame] | 3421 | memcpy(&ep->com.local_addr, &cm_id->m_local_addr, |
Steve Wise | 24d44a3 | 2013-07-04 16:10:44 +0530 | [diff] [blame] | 3422 | sizeof(ep->com.local_addr)); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 3423 | |
| 3424 | /* |
| 3425 | * Allocate a server TID. |
| 3426 | */ |
Kumar Sanghvi | 8c04469 | 2013-12-18 16:38:25 +0530 | [diff] [blame] | 3427 | if (dev->rdev.lldi.enable_fw_ofld_conn && |
| 3428 | ep->com.local_addr.ss_family == AF_INET) |
Vipul Pandya | 830662f | 2013-07-04 16:10:47 +0530 | [diff] [blame] | 3429 | ep->stid = cxgb4_alloc_sftid(dev->rdev.lldi.tids, |
Steve Wise | 170003c | 2016-02-26 09:18:03 -0600 | [diff] [blame] | 3430 | cm_id->m_local_addr.ss_family, ep); |
Vipul Pandya | 1cab775 | 2012-12-10 09:30:55 +0000 | [diff] [blame] | 3431 | else |
Vipul Pandya | 830662f | 2013-07-04 16:10:47 +0530 | [diff] [blame] | 3432 | ep->stid = cxgb4_alloc_stid(dev->rdev.lldi.tids, |
Steve Wise | 170003c | 2016-02-26 09:18:03 -0600 | [diff] [blame] | 3433 | cm_id->m_local_addr.ss_family, ep); |
Vipul Pandya | 1cab775 | 2012-12-10 09:30:55 +0000 | [diff] [blame] | 3434 | |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 3435 | if (ep->stid == -1) { |
Roland Dreier | be4c9ba | 2010-05-05 14:45:40 -0700 | [diff] [blame] | 3436 | printk(KERN_ERR MOD "%s - cannot alloc stid.\n", __func__); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 3437 | err = -ENOMEM; |
| 3438 | goto fail2; |
| 3439 | } |
Vipul Pandya | 793dad9 | 2012-12-10 09:30:56 +0000 | [diff] [blame] | 3440 | insert_handle(dev, &dev->stid_idr, ep, ep->stid); |
Steve Wise | 9eccfe1 | 2014-03-26 17:08:09 -0500 | [diff] [blame] | 3441 | |
Steve Wise | 170003c | 2016-02-26 09:18:03 -0600 | [diff] [blame] | 3442 | memcpy(&ep->com.local_addr, &cm_id->m_local_addr, |
| 3443 | sizeof(ep->com.local_addr)); |
Steve Wise | 9eccfe1 | 2014-03-26 17:08:09 -0500 | [diff] [blame] | 3444 | |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 3445 | state_set(&ep->com, LISTEN); |
Vipul Pandya | 830662f | 2013-07-04 16:10:47 +0530 | [diff] [blame] | 3446 | if (ep->com.local_addr.ss_family == AF_INET) |
| 3447 | err = create_server4(dev, ep); |
| 3448 | else |
| 3449 | err = create_server6(dev, ep); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 3450 | if (!err) { |
| 3451 | cm_id->provider_data = ep; |
| 3452 | goto out; |
| 3453 | } |
Steve Wise | 9eccfe1 | 2014-03-26 17:08:09 -0500 | [diff] [blame] | 3454 | |
Vipul Pandya | 830662f | 2013-07-04 16:10:47 +0530 | [diff] [blame] | 3455 | cxgb4_free_stid(ep->com.dev->rdev.lldi.tids, ep->stid, |
| 3456 | ep->com.local_addr.ss_family); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 3457 | fail2: |
Hariprasad S | 9ca6f7c | 2016-05-06 22:17:54 +0530 | [diff] [blame] | 3458 | deref_cm_id(&ep->com); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 3459 | c4iw_put_ep(&ep->com); |
| 3460 | fail1: |
| 3461 | out: |
| 3462 | return err; |
| 3463 | } |
| 3464 | |
| 3465 | int c4iw_destroy_listen(struct iw_cm_id *cm_id) |
| 3466 | { |
| 3467 | int err; |
| 3468 | struct c4iw_listen_ep *ep = to_listen_ep(cm_id); |
| 3469 | |
| 3470 | PDBG("%s ep %p\n", __func__, ep); |
| 3471 | |
| 3472 | might_sleep(); |
| 3473 | state_set(&ep->com, DEAD); |
Vipul Pandya | 830662f | 2013-07-04 16:10:47 +0530 | [diff] [blame] | 3474 | if (ep->com.dev->rdev.lldi.enable_fw_ofld_conn && |
| 3475 | ep->com.local_addr.ss_family == AF_INET) { |
Vipul Pandya | 1cab775 | 2012-12-10 09:30:55 +0000 | [diff] [blame] | 3476 | err = cxgb4_remove_server_filter( |
| 3477 | ep->com.dev->rdev.lldi.ports[0], ep->stid, |
| 3478 | ep->com.dev->rdev.lldi.rxq_ids[0], 0); |
| 3479 | } else { |
Hariprasad S | 84cc6ac6 | 2015-08-25 14:08:23 +0530 | [diff] [blame] | 3480 | struct sockaddr_in6 *sin6; |
Vipul Pandya | 1cab775 | 2012-12-10 09:30:55 +0000 | [diff] [blame] | 3481 | c4iw_init_wr_wait(&ep->com.wr_wait); |
Vipul Pandya | 830662f | 2013-07-04 16:10:47 +0530 | [diff] [blame] | 3482 | err = cxgb4_remove_server( |
| 3483 | ep->com.dev->rdev.lldi.ports[0], ep->stid, |
| 3484 | ep->com.dev->rdev.lldi.rxq_ids[0], 0); |
Vipul Pandya | 1cab775 | 2012-12-10 09:30:55 +0000 | [diff] [blame] | 3485 | if (err) |
| 3486 | goto done; |
| 3487 | err = c4iw_wait_for_reply(&ep->com.dev->rdev, &ep->com.wr_wait, |
| 3488 | 0, 0, __func__); |
Steve Wise | 170003c | 2016-02-26 09:18:03 -0600 | [diff] [blame] | 3489 | sin6 = (struct sockaddr_in6 *)&ep->com.local_addr; |
Hariprasad S | 84cc6ac6 | 2015-08-25 14:08:23 +0530 | [diff] [blame] | 3490 | cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0], |
| 3491 | (const u32 *)&sin6->sin6_addr.s6_addr, 1); |
Vipul Pandya | 1cab775 | 2012-12-10 09:30:55 +0000 | [diff] [blame] | 3492 | } |
Vipul Pandya | 793dad9 | 2012-12-10 09:30:56 +0000 | [diff] [blame] | 3493 | remove_handle(ep->com.dev, &ep->com.dev->stid_idr, ep->stid); |
Vipul Pandya | 830662f | 2013-07-04 16:10:47 +0530 | [diff] [blame] | 3494 | cxgb4_free_stid(ep->com.dev->rdev.lldi.tids, ep->stid, |
| 3495 | ep->com.local_addr.ss_family); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 3496 | done: |
Hariprasad S | 9ca6f7c | 2016-05-06 22:17:54 +0530 | [diff] [blame] | 3497 | deref_cm_id(&ep->com); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 3498 | c4iw_put_ep(&ep->com); |
| 3499 | return err; |
| 3500 | } |
| 3501 | |
| 3502 | int c4iw_ep_disconnect(struct c4iw_ep *ep, int abrupt, gfp_t gfp) |
| 3503 | { |
| 3504 | int ret = 0; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 3505 | int close = 0; |
| 3506 | int fatal = 0; |
| 3507 | struct c4iw_rdev *rdev; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 3508 | |
Steve Wise | 2f5b48c | 2010-09-10 11:15:36 -0500 | [diff] [blame] | 3509 | mutex_lock(&ep->com.mutex); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 3510 | |
| 3511 | PDBG("%s ep %p state %s, abrupt %d\n", __func__, ep, |
| 3512 | states[ep->com.state], abrupt); |
| 3513 | |
Hariprasad S | 6e410d8 | 2016-05-05 01:27:31 +0530 | [diff] [blame] | 3514 | /* |
| 3515 | * Ref the ep here in case we have fatal errors causing the |
| 3516 | * ep to be released and freed. |
| 3517 | */ |
| 3518 | c4iw_get_ep(&ep->com); |
| 3519 | |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 3520 | rdev = &ep->com.dev->rdev; |
| 3521 | if (c4iw_fatal_error(rdev)) { |
| 3522 | fatal = 1; |
Steve Wise | be13b2d | 2014-03-21 20:40:33 +0530 | [diff] [blame] | 3523 | close_complete_upcall(ep, -EIO); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 3524 | ep->com.state = DEAD; |
| 3525 | } |
| 3526 | switch (ep->com.state) { |
| 3527 | case MPA_REQ_WAIT: |
| 3528 | case MPA_REQ_SENT: |
| 3529 | case MPA_REQ_RCVD: |
| 3530 | case MPA_REP_SENT: |
| 3531 | case FPDU_MODE: |
Hariprasad S | 4a74083 | 2016-06-10 01:05:15 +0530 | [diff] [blame] | 3532 | case CONNECTING: |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 3533 | close = 1; |
| 3534 | if (abrupt) |
| 3535 | ep->com.state = ABORTING; |
| 3536 | else { |
| 3537 | ep->com.state = CLOSING; |
Steve Wise | 12eb513 | 2016-07-29 08:38:44 -0700 | [diff] [blame] | 3538 | |
| 3539 | /* |
| 3540 | * if we close before we see the fw4_ack() then we fix |
| 3541 | * up the timer state since we're reusing it. |
| 3542 | */ |
| 3543 | if (ep->mpa_skb && |
| 3544 | test_bit(STOP_MPA_TIMER, &ep->com.flags)) { |
| 3545 | clear_bit(STOP_MPA_TIMER, &ep->com.flags); |
| 3546 | stop_ep_timer(ep); |
| 3547 | } |
Steve Wise | ca5a220 | 2010-07-23 19:12:37 +0000 | [diff] [blame] | 3548 | start_ep_timer(ep); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 3549 | } |
| 3550 | set_bit(CLOSE_SENT, &ep->com.flags); |
| 3551 | break; |
| 3552 | case CLOSING: |
| 3553 | if (!test_and_set_bit(CLOSE_SENT, &ep->com.flags)) { |
| 3554 | close = 1; |
| 3555 | if (abrupt) { |
Steve Wise | b33bd0c | 2014-04-09 09:38:25 -0500 | [diff] [blame] | 3556 | (void)stop_ep_timer(ep); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 3557 | ep->com.state = ABORTING; |
| 3558 | } else |
| 3559 | ep->com.state = MORIBUND; |
| 3560 | } |
| 3561 | break; |
| 3562 | case MORIBUND: |
| 3563 | case ABORTING: |
| 3564 | case DEAD: |
| 3565 | PDBG("%s ignoring disconnect ep %p state %u\n", |
| 3566 | __func__, ep, ep->com.state); |
| 3567 | break; |
| 3568 | default: |
| 3569 | BUG(); |
| 3570 | break; |
| 3571 | } |
| 3572 | |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 3573 | if (close) { |
Steve Wise | 8da7e7a | 2011-06-14 20:59:27 +0000 | [diff] [blame] | 3574 | if (abrupt) { |
Vipul Pandya | 793dad9 | 2012-12-10 09:30:56 +0000 | [diff] [blame] | 3575 | set_bit(EP_DISC_ABORT, &ep->com.history); |
Steve Wise | be13b2d | 2014-03-21 20:40:33 +0530 | [diff] [blame] | 3576 | close_complete_upcall(ep, -ECONNRESET); |
Hariprasad S | 4a74083 | 2016-06-10 01:05:15 +0530 | [diff] [blame] | 3577 | ret = send_abort(ep); |
Vipul Pandya | 793dad9 | 2012-12-10 09:30:56 +0000 | [diff] [blame] | 3578 | } else { |
| 3579 | set_bit(EP_DISC_CLOSE, &ep->com.history); |
Hariprasad S | 4a74083 | 2016-06-10 01:05:15 +0530 | [diff] [blame] | 3580 | ret = send_halfclose(ep); |
Vipul Pandya | 793dad9 | 2012-12-10 09:30:56 +0000 | [diff] [blame] | 3581 | } |
Hariprasad S | 88bc230d | 2016-05-05 01:27:30 +0530 | [diff] [blame] | 3582 | if (ret) { |
Hariprasad S | 9ca6f7c | 2016-05-06 22:17:54 +0530 | [diff] [blame] | 3583 | set_bit(EP_DISC_FAIL, &ep->com.history); |
Hariprasad S | 88bc230d | 2016-05-05 01:27:30 +0530 | [diff] [blame] | 3584 | if (!abrupt) { |
| 3585 | stop_ep_timer(ep); |
| 3586 | close_complete_upcall(ep, -EIO); |
| 3587 | } |
Hariprasad S | c00dcba | 2016-05-05 01:27:36 +0530 | [diff] [blame] | 3588 | if (ep->com.qp) { |
| 3589 | struct c4iw_qp_attributes attrs; |
| 3590 | |
| 3591 | attrs.next_state = C4IW_QP_STATE_ERROR; |
| 3592 | ret = c4iw_modify_qp(ep->com.qp->rhp, |
| 3593 | ep->com.qp, |
| 3594 | C4IW_QP_ATTR_NEXT_STATE, |
| 3595 | &attrs, 1); |
| 3596 | if (ret) |
| 3597 | pr_err(MOD |
| 3598 | "%s - qp <- error failed!\n", |
| 3599 | __func__); |
| 3600 | } |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 3601 | fatal = 1; |
Hariprasad S | 88bc230d | 2016-05-05 01:27:30 +0530 | [diff] [blame] | 3602 | } |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 3603 | } |
Steve Wise | 8da7e7a | 2011-06-14 20:59:27 +0000 | [diff] [blame] | 3604 | mutex_unlock(&ep->com.mutex); |
Hariprasad S | 6e410d8 | 2016-05-05 01:27:31 +0530 | [diff] [blame] | 3605 | c4iw_put_ep(&ep->com); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 3606 | if (fatal) |
| 3607 | release_ep_resources(ep); |
| 3608 | return ret; |
| 3609 | } |
| 3610 | |
Vipul Pandya | 1cab775 | 2012-12-10 09:30:55 +0000 | [diff] [blame] | 3611 | static void active_ofld_conn_reply(struct c4iw_dev *dev, struct sk_buff *skb, |
| 3612 | struct cpl_fw6_msg_ofld_connection_wr_rpl *req) |
| 3613 | { |
| 3614 | struct c4iw_ep *ep; |
Vipul Pandya | 793dad9 | 2012-12-10 09:30:56 +0000 | [diff] [blame] | 3615 | int atid = be32_to_cpu(req->tid); |
Vipul Pandya | 1cab775 | 2012-12-10 09:30:55 +0000 | [diff] [blame] | 3616 | |
Vipul Pandya | ef5d635 | 2013-01-07 13:12:00 +0000 | [diff] [blame] | 3617 | ep = (struct c4iw_ep *)lookup_atid(dev->rdev.lldi.tids, |
| 3618 | (__force u32) req->tid); |
Vipul Pandya | 1cab775 | 2012-12-10 09:30:55 +0000 | [diff] [blame] | 3619 | if (!ep) |
| 3620 | return; |
| 3621 | |
| 3622 | switch (req->retval) { |
| 3623 | case FW_ENOMEM: |
Vipul Pandya | 793dad9 | 2012-12-10 09:30:56 +0000 | [diff] [blame] | 3624 | set_bit(ACT_RETRY_NOMEM, &ep->com.history); |
| 3625 | if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) { |
| 3626 | send_fw_act_open_req(ep, atid); |
| 3627 | return; |
| 3628 | } |
Vipul Pandya | 1cab775 | 2012-12-10 09:30:55 +0000 | [diff] [blame] | 3629 | case FW_EADDRINUSE: |
Vipul Pandya | 793dad9 | 2012-12-10 09:30:56 +0000 | [diff] [blame] | 3630 | set_bit(ACT_RETRY_INUSE, &ep->com.history); |
| 3631 | if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) { |
| 3632 | send_fw_act_open_req(ep, atid); |
| 3633 | return; |
| 3634 | } |
Vipul Pandya | 1cab775 | 2012-12-10 09:30:55 +0000 | [diff] [blame] | 3635 | break; |
| 3636 | default: |
| 3637 | pr_info("%s unexpected ofld conn wr retval %d\n", |
| 3638 | __func__, req->retval); |
| 3639 | break; |
| 3640 | } |
Vipul Pandya | 793dad9 | 2012-12-10 09:30:56 +0000 | [diff] [blame] | 3641 | pr_err("active ofld_connect_wr failure %d atid %d\n", |
| 3642 | req->retval, atid); |
| 3643 | mutex_lock(&dev->rdev.stats.lock); |
| 3644 | dev->rdev.stats.act_ofld_conn_fails++; |
| 3645 | mutex_unlock(&dev->rdev.stats.lock); |
Vipul Pandya | 1cab775 | 2012-12-10 09:30:55 +0000 | [diff] [blame] | 3646 | connect_reply_upcall(ep, status2errno(req->retval)); |
Vipul Pandya | 793dad9 | 2012-12-10 09:30:56 +0000 | [diff] [blame] | 3647 | state_set(&ep->com, DEAD); |
Hariprasad S | 84cc6ac6 | 2015-08-25 14:08:23 +0530 | [diff] [blame] | 3648 | if (ep->com.remote_addr.ss_family == AF_INET6) { |
| 3649 | struct sockaddr_in6 *sin6 = |
Steve Wise | 170003c | 2016-02-26 09:18:03 -0600 | [diff] [blame] | 3650 | (struct sockaddr_in6 *)&ep->com.local_addr; |
Hariprasad S | 84cc6ac6 | 2015-08-25 14:08:23 +0530 | [diff] [blame] | 3651 | cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0], |
| 3652 | (const u32 *)&sin6->sin6_addr.s6_addr, 1); |
| 3653 | } |
Vipul Pandya | 793dad9 | 2012-12-10 09:30:56 +0000 | [diff] [blame] | 3654 | remove_handle(dev, &dev->atid_idr, atid); |
| 3655 | cxgb4_free_atid(dev->rdev.lldi.tids, atid); |
| 3656 | dst_release(ep->dst); |
| 3657 | cxgb4_l2t_release(ep->l2t); |
| 3658 | c4iw_put_ep(&ep->com); |
Vipul Pandya | 1cab775 | 2012-12-10 09:30:55 +0000 | [diff] [blame] | 3659 | } |
| 3660 | |
| 3661 | static void passive_ofld_conn_reply(struct c4iw_dev *dev, struct sk_buff *skb, |
| 3662 | struct cpl_fw6_msg_ofld_connection_wr_rpl *req) |
| 3663 | { |
| 3664 | struct sk_buff *rpl_skb; |
| 3665 | struct cpl_pass_accept_req *cpl; |
| 3666 | int ret; |
| 3667 | |
Paul Bolle | 710a311 | 2013-02-05 20:51:30 +0000 | [diff] [blame] | 3668 | rpl_skb = (struct sk_buff *)(unsigned long)req->cookie; |
Vipul Pandya | 1cab775 | 2012-12-10 09:30:55 +0000 | [diff] [blame] | 3669 | BUG_ON(!rpl_skb); |
| 3670 | if (req->retval) { |
| 3671 | PDBG("%s passive open failure %d\n", __func__, req->retval); |
Vipul Pandya | 793dad9 | 2012-12-10 09:30:56 +0000 | [diff] [blame] | 3672 | mutex_lock(&dev->rdev.stats.lock); |
| 3673 | dev->rdev.stats.pas_ofld_conn_fails++; |
| 3674 | mutex_unlock(&dev->rdev.stats.lock); |
Vipul Pandya | 1cab775 | 2012-12-10 09:30:55 +0000 | [diff] [blame] | 3675 | kfree_skb(rpl_skb); |
| 3676 | } else { |
| 3677 | cpl = (struct cpl_pass_accept_req *)cplhdr(rpl_skb); |
| 3678 | OPCODE_TID(cpl) = htonl(MK_OPCODE_TID(CPL_PASS_ACCEPT_REQ, |
Vipul Pandya | ef5d635 | 2013-01-07 13:12:00 +0000 | [diff] [blame] | 3679 | (__force u32) htonl( |
| 3680 | (__force u32) req->tid))); |
Vipul Pandya | 1cab775 | 2012-12-10 09:30:55 +0000 | [diff] [blame] | 3681 | ret = pass_accept_req(dev, rpl_skb); |
| 3682 | if (!ret) |
| 3683 | kfree_skb(rpl_skb); |
| 3684 | } |
| 3685 | return; |
| 3686 | } |
| 3687 | |
| 3688 | static int deferred_fw6_msg(struct c4iw_dev *dev, struct sk_buff *skb) |
Steve Wise | 2f5b48c | 2010-09-10 11:15:36 -0500 | [diff] [blame] | 3689 | { |
| 3690 | struct cpl_fw6_msg *rpl = cplhdr(skb); |
Vipul Pandya | 1cab775 | 2012-12-10 09:30:55 +0000 | [diff] [blame] | 3691 | struct cpl_fw6_msg_ofld_connection_wr_rpl *req; |
| 3692 | |
| 3693 | switch (rpl->type) { |
| 3694 | case FW6_TYPE_CQE: |
| 3695 | c4iw_ev_dispatch(dev, (struct t4_cqe *)&rpl->data[0]); |
| 3696 | break; |
| 3697 | case FW6_TYPE_OFLD_CONNECTION_WR_RPL: |
| 3698 | req = (struct cpl_fw6_msg_ofld_connection_wr_rpl *)rpl->data; |
| 3699 | switch (req->t_state) { |
| 3700 | case TCP_SYN_SENT: |
| 3701 | active_ofld_conn_reply(dev, skb, req); |
| 3702 | break; |
| 3703 | case TCP_SYN_RECV: |
| 3704 | passive_ofld_conn_reply(dev, skb, req); |
| 3705 | break; |
| 3706 | default: |
| 3707 | pr_err("%s unexpected ofld conn wr state %d\n", |
| 3708 | __func__, req->t_state); |
| 3709 | break; |
| 3710 | } |
| 3711 | break; |
| 3712 | } |
| 3713 | return 0; |
| 3714 | } |
| 3715 | |
| 3716 | static void build_cpl_pass_accept_req(struct sk_buff *skb, int stid , u8 tos) |
| 3717 | { |
Hariprasad S | 963cab5 | 2015-09-23 17:19:27 +0530 | [diff] [blame] | 3718 | __be32 l2info; |
| 3719 | __be16 hdr_len, vlantag, len; |
| 3720 | u16 eth_hdr_len; |
| 3721 | int tcp_hdr_len, ip_hdr_len; |
Vipul Pandya | 1cab775 | 2012-12-10 09:30:55 +0000 | [diff] [blame] | 3722 | u8 intf; |
| 3723 | struct cpl_rx_pkt *cpl = cplhdr(skb); |
| 3724 | struct cpl_pass_accept_req *req; |
| 3725 | struct tcp_options_received tmp_opt; |
Vipul Pandya | f079af7 | 2013-03-14 05:08:58 +0000 | [diff] [blame] | 3726 | struct c4iw_dev *dev; |
Hariprasad S | 963cab5 | 2015-09-23 17:19:27 +0530 | [diff] [blame] | 3727 | enum chip_type type; |
Vipul Pandya | 1cab775 | 2012-12-10 09:30:55 +0000 | [diff] [blame] | 3728 | |
Vipul Pandya | f079af7 | 2013-03-14 05:08:58 +0000 | [diff] [blame] | 3729 | dev = *((struct c4iw_dev **) (skb->cb + sizeof(void *))); |
Vipul Pandya | 1cab775 | 2012-12-10 09:30:55 +0000 | [diff] [blame] | 3730 | /* Store values from cpl_rx_pkt in temporary location. */ |
Hariprasad S | 963cab5 | 2015-09-23 17:19:27 +0530 | [diff] [blame] | 3731 | vlantag = cpl->vlan; |
| 3732 | len = cpl->len; |
| 3733 | l2info = cpl->l2info; |
| 3734 | hdr_len = cpl->hdr_len; |
Vipul Pandya | 1cab775 | 2012-12-10 09:30:55 +0000 | [diff] [blame] | 3735 | intf = cpl->iff; |
| 3736 | |
| 3737 | __skb_pull(skb, sizeof(*req) + sizeof(struct rss_header)); |
| 3738 | |
| 3739 | /* |
| 3740 | * We need to parse the TCP options from SYN packet. |
| 3741 | * to generate cpl_pass_accept_req. |
| 3742 | */ |
| 3743 | memset(&tmp_opt, 0, sizeof(tmp_opt)); |
| 3744 | tcp_clear_options(&tmp_opt); |
Christoph Paasch | 1a2c618 | 2013-03-17 08:23:34 +0000 | [diff] [blame] | 3745 | tcp_parse_options(skb, &tmp_opt, 0, NULL); |
Vipul Pandya | 1cab775 | 2012-12-10 09:30:55 +0000 | [diff] [blame] | 3746 | |
| 3747 | req = (struct cpl_pass_accept_req *)__skb_push(skb, sizeof(*req)); |
| 3748 | memset(req, 0, sizeof(*req)); |
Hariprasad Shenai | cf7fe64 | 2015-01-16 09:24:48 +0530 | [diff] [blame] | 3749 | req->l2info = cpu_to_be16(SYN_INTF_V(intf) | |
| 3750 | SYN_MAC_IDX_V(RX_MACIDX_G( |
Hariprasad S | 963cab5 | 2015-09-23 17:19:27 +0530 | [diff] [blame] | 3751 | be32_to_cpu(l2info))) | |
Hariprasad Shenai | cf7fe64 | 2015-01-16 09:24:48 +0530 | [diff] [blame] | 3752 | SYN_XACT_MATCH_F); |
Hariprasad S | 963cab5 | 2015-09-23 17:19:27 +0530 | [diff] [blame] | 3753 | type = dev->rdev.lldi.adapter_type; |
| 3754 | tcp_hdr_len = RX_TCPHDR_LEN_G(be16_to_cpu(hdr_len)); |
| 3755 | ip_hdr_len = RX_IPHDR_LEN_G(be16_to_cpu(hdr_len)); |
| 3756 | req->hdr_len = |
| 3757 | cpu_to_be32(SYN_RX_CHAN_V(RX_CHAN_G(be32_to_cpu(l2info)))); |
| 3758 | if (CHELSIO_CHIP_VERSION(type) <= CHELSIO_T5) { |
| 3759 | eth_hdr_len = is_t4(type) ? |
| 3760 | RX_ETHHDR_LEN_G(be32_to_cpu(l2info)) : |
| 3761 | RX_T5_ETHHDR_LEN_G(be32_to_cpu(l2info)); |
| 3762 | req->hdr_len |= cpu_to_be32(TCP_HDR_LEN_V(tcp_hdr_len) | |
| 3763 | IP_HDR_LEN_V(ip_hdr_len) | |
| 3764 | ETH_HDR_LEN_V(eth_hdr_len)); |
| 3765 | } else { /* T6 and later */ |
| 3766 | eth_hdr_len = RX_T6_ETHHDR_LEN_G(be32_to_cpu(l2info)); |
| 3767 | req->hdr_len |= cpu_to_be32(T6_TCP_HDR_LEN_V(tcp_hdr_len) | |
| 3768 | T6_IP_HDR_LEN_V(ip_hdr_len) | |
| 3769 | T6_ETH_HDR_LEN_V(eth_hdr_len)); |
| 3770 | } |
| 3771 | req->vlan = vlantag; |
| 3772 | req->len = len; |
Hariprasad Shenai | 6c53e93 | 2015-01-08 21:38:15 -0800 | [diff] [blame] | 3773 | req->tos_stid = cpu_to_be32(PASS_OPEN_TID_V(stid) | |
| 3774 | PASS_OPEN_TOS_V(tos)); |
Vipul Pandya | 1cab775 | 2012-12-10 09:30:55 +0000 | [diff] [blame] | 3775 | req->tcpopt.mss = htons(tmp_opt.mss_clamp); |
| 3776 | if (tmp_opt.wscale_ok) |
| 3777 | req->tcpopt.wsf = tmp_opt.snd_wscale; |
| 3778 | req->tcpopt.tstamp = tmp_opt.saw_tstamp; |
| 3779 | if (tmp_opt.sack_ok) |
| 3780 | req->tcpopt.sack = 1; |
| 3781 | OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_PASS_ACCEPT_REQ, 0)); |
| 3782 | return; |
| 3783 | } |
| 3784 | |
| 3785 | static void send_fw_pass_open_req(struct c4iw_dev *dev, struct sk_buff *skb, |
| 3786 | __be32 laddr, __be16 lport, |
| 3787 | __be32 raddr, __be16 rport, |
| 3788 | u32 rcv_isn, u32 filter, u16 window, |
| 3789 | u32 rss_qid, u8 port_id) |
| 3790 | { |
| 3791 | struct sk_buff *req_skb; |
| 3792 | struct fw_ofld_connection_wr *req; |
| 3793 | struct cpl_pass_accept_req *cpl = cplhdr(skb); |
Steve Wise | 1ce1d47 | 2014-03-21 20:40:31 +0530 | [diff] [blame] | 3794 | int ret; |
Vipul Pandya | 1cab775 | 2012-12-10 09:30:55 +0000 | [diff] [blame] | 3795 | |
| 3796 | req_skb = alloc_skb(sizeof(struct fw_ofld_connection_wr), GFP_KERNEL); |
| 3797 | req = (struct fw_ofld_connection_wr *)__skb_put(req_skb, sizeof(*req)); |
| 3798 | memset(req, 0, sizeof(*req)); |
Hariprasad Shenai | 6c53e93 | 2015-01-08 21:38:15 -0800 | [diff] [blame] | 3799 | req->op_compl = htonl(WR_OP_V(FW_OFLD_CONNECTION_WR) | FW_WR_COMPL_F); |
Hariprasad Shenai | e2ac962 | 2014-11-07 09:35:25 +0530 | [diff] [blame] | 3800 | req->len16_pkd = htonl(FW_WR_LEN16_V(DIV_ROUND_UP(sizeof(*req), 16))); |
Hariprasad Shenai | 77a80e2 | 2014-11-21 12:52:01 +0530 | [diff] [blame] | 3801 | req->le.version_cpl = htonl(FW_OFLD_CONNECTION_WR_CPL_F); |
Vipul Pandya | ef5d635 | 2013-01-07 13:12:00 +0000 | [diff] [blame] | 3802 | req->le.filter = (__force __be32) filter; |
Vipul Pandya | 1cab775 | 2012-12-10 09:30:55 +0000 | [diff] [blame] | 3803 | req->le.lport = lport; |
| 3804 | req->le.pport = rport; |
| 3805 | req->le.u.ipv4.lip = laddr; |
| 3806 | req->le.u.ipv4.pip = raddr; |
| 3807 | req->tcb.rcv_nxt = htonl(rcv_isn + 1); |
| 3808 | req->tcb.rcv_adv = htons(window); |
| 3809 | req->tcb.t_state_to_astid = |
Hariprasad Shenai | 77a80e2 | 2014-11-21 12:52:01 +0530 | [diff] [blame] | 3810 | htonl(FW_OFLD_CONNECTION_WR_T_STATE_V(TCP_SYN_RECV) | |
| 3811 | FW_OFLD_CONNECTION_WR_RCV_SCALE_V(cpl->tcpopt.wsf) | |
| 3812 | FW_OFLD_CONNECTION_WR_ASTID_V( |
Hariprasad Shenai | 6c53e93 | 2015-01-08 21:38:15 -0800 | [diff] [blame] | 3813 | PASS_OPEN_TID_G(ntohl(cpl->tos_stid)))); |
Vipul Pandya | 1cab775 | 2012-12-10 09:30:55 +0000 | [diff] [blame] | 3814 | |
| 3815 | /* |
| 3816 | * We store the qid in opt2 which will be used by the firmware |
| 3817 | * to send us the wr response. |
| 3818 | */ |
Anish Bhatt | d7990b0 | 2014-11-12 17:15:57 -0800 | [diff] [blame] | 3819 | req->tcb.opt2 = htonl(RSS_QUEUE_V(rss_qid)); |
Vipul Pandya | 1cab775 | 2012-12-10 09:30:55 +0000 | [diff] [blame] | 3820 | |
| 3821 | /* |
| 3822 | * We initialize the MSS index in TCB to 0xF. |
| 3823 | * So that when driver sends cpl_pass_accept_rpl |
| 3824 | * TCB picks up the correct value. If this was 0 |
| 3825 | * TP will ignore any value > 0 for MSS index. |
| 3826 | */ |
Anish Bhatt | d7990b0 | 2014-11-12 17:15:57 -0800 | [diff] [blame] | 3827 | req->tcb.opt0 = cpu_to_be64(MSS_IDX_V(0xF)); |
Hariprasad S | 6198dd8 | 2015-04-22 01:44:59 +0530 | [diff] [blame] | 3828 | req->cookie = (uintptr_t)skb; |
Vipul Pandya | 1cab775 | 2012-12-10 09:30:55 +0000 | [diff] [blame] | 3829 | |
| 3830 | set_wr_txq(req_skb, CPL_PRIORITY_CONTROL, port_id); |
Steve Wise | 1ce1d47 | 2014-03-21 20:40:31 +0530 | [diff] [blame] | 3831 | ret = cxgb4_ofld_send(dev->rdev.lldi.ports[0], req_skb); |
| 3832 | if (ret < 0) { |
| 3833 | pr_err("%s - cxgb4_ofld_send error %d - dropping\n", __func__, |
| 3834 | ret); |
| 3835 | kfree_skb(skb); |
| 3836 | kfree_skb(req_skb); |
| 3837 | } |
Vipul Pandya | 1cab775 | 2012-12-10 09:30:55 +0000 | [diff] [blame] | 3838 | } |
| 3839 | |
| 3840 | /* |
| 3841 | * Handler for CPL_RX_PKT message. Need to handle cpl_rx_pkt |
| 3842 | * messages when a filter is being used instead of server to |
| 3843 | * redirect a syn packet. When packets hit filter they are redirected |
| 3844 | * to the offload queue and driver tries to establish the connection |
| 3845 | * using firmware work request. |
| 3846 | */ |
| 3847 | static int rx_pkt(struct c4iw_dev *dev, struct sk_buff *skb) |
| 3848 | { |
| 3849 | int stid; |
| 3850 | unsigned int filter; |
| 3851 | struct ethhdr *eh = NULL; |
| 3852 | struct vlan_ethhdr *vlan_eh = NULL; |
| 3853 | struct iphdr *iph; |
| 3854 | struct tcphdr *tcph; |
| 3855 | struct rss_header *rss = (void *)skb->data; |
| 3856 | struct cpl_rx_pkt *cpl = (void *)skb->data; |
| 3857 | struct cpl_pass_accept_req *req = (void *)(rss + 1); |
| 3858 | struct l2t_entry *e; |
| 3859 | struct dst_entry *dst; |
Hariprasad S | f86fac7 | 2016-05-06 22:18:07 +0530 | [diff] [blame] | 3860 | struct c4iw_ep *lep = NULL; |
Vipul Pandya | 1cab775 | 2012-12-10 09:30:55 +0000 | [diff] [blame] | 3861 | u16 window; |
| 3862 | struct port_info *pi; |
| 3863 | struct net_device *pdev; |
Vipul Pandya | f079af7 | 2013-03-14 05:08:58 +0000 | [diff] [blame] | 3864 | u16 rss_qid, eth_hdr_len; |
Vipul Pandya | 1cab775 | 2012-12-10 09:30:55 +0000 | [diff] [blame] | 3865 | int step; |
| 3866 | u32 tx_chan; |
| 3867 | struct neighbour *neigh; |
| 3868 | |
| 3869 | /* Drop all non-SYN packets */ |
Hariprasad Shenai | bdc590b | 2015-01-08 21:38:16 -0800 | [diff] [blame] | 3870 | if (!(cpl->l2info & cpu_to_be32(RXF_SYN_F))) |
Vipul Pandya | 1cab775 | 2012-12-10 09:30:55 +0000 | [diff] [blame] | 3871 | goto reject; |
| 3872 | |
| 3873 | /* |
| 3874 | * Drop all packets which did not hit the filter. |
| 3875 | * Unlikely to happen. |
| 3876 | */ |
| 3877 | if (!(rss->filter_hit && rss->filter_tid)) |
| 3878 | goto reject; |
| 3879 | |
| 3880 | /* |
| 3881 | * Calculate the server tid from filter hit index from cpl_rx_pkt. |
| 3882 | */ |
Kumar Sanghvi | a4ea025 | 2013-12-18 16:38:24 +0530 | [diff] [blame] | 3883 | stid = (__force int) cpu_to_be32((__force u32) rss->hash_val); |
Vipul Pandya | 1cab775 | 2012-12-10 09:30:55 +0000 | [diff] [blame] | 3884 | |
Hariprasad S | f86fac7 | 2016-05-06 22:18:07 +0530 | [diff] [blame] | 3885 | lep = (struct c4iw_ep *)get_ep_from_stid(dev, stid); |
Vipul Pandya | 1cab775 | 2012-12-10 09:30:55 +0000 | [diff] [blame] | 3886 | if (!lep) { |
| 3887 | PDBG("%s connect request on invalid stid %d\n", __func__, stid); |
| 3888 | goto reject; |
| 3889 | } |
| 3890 | |
Hariprasad S | 963cab5 | 2015-09-23 17:19:27 +0530 | [diff] [blame] | 3891 | switch (CHELSIO_CHIP_VERSION(dev->rdev.lldi.adapter_type)) { |
| 3892 | case CHELSIO_T4: |
| 3893 | eth_hdr_len = RX_ETHHDR_LEN_G(be32_to_cpu(cpl->l2info)); |
| 3894 | break; |
| 3895 | case CHELSIO_T5: |
| 3896 | eth_hdr_len = RX_T5_ETHHDR_LEN_G(be32_to_cpu(cpl->l2info)); |
| 3897 | break; |
| 3898 | case CHELSIO_T6: |
| 3899 | eth_hdr_len = RX_T6_ETHHDR_LEN_G(be32_to_cpu(cpl->l2info)); |
| 3900 | break; |
| 3901 | default: |
| 3902 | pr_err("T%d Chip is not supported\n", |
| 3903 | CHELSIO_CHIP_VERSION(dev->rdev.lldi.adapter_type)); |
| 3904 | goto reject; |
| 3905 | } |
| 3906 | |
Vipul Pandya | f079af7 | 2013-03-14 05:08:58 +0000 | [diff] [blame] | 3907 | if (eth_hdr_len == ETH_HLEN) { |
Vipul Pandya | 1cab775 | 2012-12-10 09:30:55 +0000 | [diff] [blame] | 3908 | eh = (struct ethhdr *)(req + 1); |
| 3909 | iph = (struct iphdr *)(eh + 1); |
| 3910 | } else { |
| 3911 | vlan_eh = (struct vlan_ethhdr *)(req + 1); |
| 3912 | iph = (struct iphdr *)(vlan_eh + 1); |
| 3913 | skb->vlan_tci = ntohs(cpl->vlan); |
| 3914 | } |
| 3915 | |
| 3916 | if (iph->version != 0x4) |
| 3917 | goto reject; |
| 3918 | |
| 3919 | tcph = (struct tcphdr *)(iph + 1); |
| 3920 | skb_set_network_header(skb, (void *)iph - (void *)rss); |
| 3921 | skb_set_transport_header(skb, (void *)tcph - (void *)rss); |
| 3922 | skb_get(skb); |
| 3923 | |
| 3924 | PDBG("%s lip 0x%x lport %u pip 0x%x pport %u tos %d\n", __func__, |
| 3925 | ntohl(iph->daddr), ntohs(tcph->dest), ntohl(iph->saddr), |
| 3926 | ntohs(tcph->source), iph->tos); |
| 3927 | |
Varun Prakash | 804c2f3 | 2016-09-13 21:23:57 +0530 | [diff] [blame] | 3928 | dst = cxgb_find_route(&dev->rdev.lldi, get_real_dev, |
| 3929 | iph->daddr, iph->saddr, tcph->dest, |
| 3930 | tcph->source, iph->tos); |
Vipul Pandya | 830662f | 2013-07-04 16:10:47 +0530 | [diff] [blame] | 3931 | if (!dst) { |
Vipul Pandya | 1cab775 | 2012-12-10 09:30:55 +0000 | [diff] [blame] | 3932 | pr_err("%s - failed to find dst entry!\n", |
| 3933 | __func__); |
| 3934 | goto reject; |
| 3935 | } |
Vipul Pandya | 1cab775 | 2012-12-10 09:30:55 +0000 | [diff] [blame] | 3936 | neigh = dst_neigh_lookup_skb(dst, skb); |
| 3937 | |
Zhouyi Zhou | aaa0c23 | 2013-03-14 17:21:50 +0000 | [diff] [blame] | 3938 | if (!neigh) { |
| 3939 | pr_err("%s - failed to allocate neigh!\n", |
| 3940 | __func__); |
| 3941 | goto free_dst; |
| 3942 | } |
| 3943 | |
Vipul Pandya | 1cab775 | 2012-12-10 09:30:55 +0000 | [diff] [blame] | 3944 | if (neigh->dev->flags & IFF_LOOPBACK) { |
| 3945 | pdev = ip_dev_find(&init_net, iph->daddr); |
| 3946 | e = cxgb4_l2t_get(dev->rdev.lldi.l2t, neigh, |
| 3947 | pdev, 0); |
| 3948 | pi = (struct port_info *)netdev_priv(pdev); |
| 3949 | tx_chan = cxgb4_port_chan(pdev); |
| 3950 | dev_put(pdev); |
| 3951 | } else { |
Vipul Pandya | 830662f | 2013-07-04 16:10:47 +0530 | [diff] [blame] | 3952 | pdev = get_real_dev(neigh->dev); |
Vipul Pandya | 1cab775 | 2012-12-10 09:30:55 +0000 | [diff] [blame] | 3953 | e = cxgb4_l2t_get(dev->rdev.lldi.l2t, neigh, |
Vipul Pandya | 830662f | 2013-07-04 16:10:47 +0530 | [diff] [blame] | 3954 | pdev, 0); |
| 3955 | pi = (struct port_info *)netdev_priv(pdev); |
| 3956 | tx_chan = cxgb4_port_chan(pdev); |
Vipul Pandya | 1cab775 | 2012-12-10 09:30:55 +0000 | [diff] [blame] | 3957 | } |
Steve Wise | ebf0006 | 2014-03-19 17:44:40 +0530 | [diff] [blame] | 3958 | neigh_release(neigh); |
Vipul Pandya | 1cab775 | 2012-12-10 09:30:55 +0000 | [diff] [blame] | 3959 | if (!e) { |
| 3960 | pr_err("%s - failed to allocate l2t entry!\n", |
| 3961 | __func__); |
| 3962 | goto free_dst; |
| 3963 | } |
| 3964 | |
| 3965 | step = dev->rdev.lldi.nrxq / dev->rdev.lldi.nchan; |
| 3966 | rss_qid = dev->rdev.lldi.rxq_ids[pi->port_id * step]; |
Vipul Pandya | ef5d635 | 2013-01-07 13:12:00 +0000 | [diff] [blame] | 3967 | window = (__force u16) htons((__force u16)tcph->window); |
Vipul Pandya | 1cab775 | 2012-12-10 09:30:55 +0000 | [diff] [blame] | 3968 | |
| 3969 | /* Calcuate filter portion for LE region. */ |
Kumar Sanghvi | 41b4f86 | 2013-12-18 16:38:26 +0530 | [diff] [blame] | 3970 | filter = (__force unsigned int) cpu_to_be32(cxgb4_select_ntuple( |
| 3971 | dev->rdev.lldi.ports[0], |
| 3972 | e)); |
Vipul Pandya | 1cab775 | 2012-12-10 09:30:55 +0000 | [diff] [blame] | 3973 | |
| 3974 | /* |
| 3975 | * Synthesize the cpl_pass_accept_req. We have everything except the |
| 3976 | * TID. Once firmware sends a reply with TID we update the TID field |
| 3977 | * in cpl and pass it through the regular cpl_pass_accept_req path. |
| 3978 | */ |
| 3979 | build_cpl_pass_accept_req(skb, stid, iph->tos); |
| 3980 | send_fw_pass_open_req(dev, skb, iph->daddr, tcph->dest, iph->saddr, |
| 3981 | tcph->source, ntohl(tcph->seq), filter, window, |
| 3982 | rss_qid, pi->port_id); |
| 3983 | cxgb4_l2t_release(e); |
| 3984 | free_dst: |
| 3985 | dst_release(dst); |
| 3986 | reject: |
Hariprasad S | f86fac7 | 2016-05-06 22:18:07 +0530 | [diff] [blame] | 3987 | if (lep) |
| 3988 | c4iw_put_ep(&lep->com); |
Steve Wise | 2f5b48c | 2010-09-10 11:15:36 -0500 | [diff] [blame] | 3989 | return 0; |
| 3990 | } |
| 3991 | |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 3992 | /* |
Roland Dreier | be4c9ba | 2010-05-05 14:45:40 -0700 | [diff] [blame] | 3993 | * These are the real handlers that are called from a |
| 3994 | * work queue. |
| 3995 | */ |
Hariprasad S | 9dec900 | 2016-05-05 01:27:29 +0530 | [diff] [blame] | 3996 | static c4iw_handler_func work_handlers[NUM_CPL_CMDS + NUM_FAKE_CPLS] = { |
Roland Dreier | be4c9ba | 2010-05-05 14:45:40 -0700 | [diff] [blame] | 3997 | [CPL_ACT_ESTABLISH] = act_establish, |
| 3998 | [CPL_ACT_OPEN_RPL] = act_open_rpl, |
| 3999 | [CPL_RX_DATA] = rx_data, |
| 4000 | [CPL_ABORT_RPL_RSS] = abort_rpl, |
| 4001 | [CPL_ABORT_RPL] = abort_rpl, |
| 4002 | [CPL_PASS_OPEN_RPL] = pass_open_rpl, |
| 4003 | [CPL_CLOSE_LISTSRV_RPL] = close_listsrv_rpl, |
| 4004 | [CPL_PASS_ACCEPT_REQ] = pass_accept_req, |
| 4005 | [CPL_PASS_ESTABLISH] = pass_establish, |
| 4006 | [CPL_PEER_CLOSE] = peer_close, |
| 4007 | [CPL_ABORT_REQ_RSS] = peer_abort, |
| 4008 | [CPL_CLOSE_CON_RPL] = close_con_rpl, |
| 4009 | [CPL_RDMA_TERMINATE] = terminate, |
Steve Wise | 2f5b48c | 2010-09-10 11:15:36 -0500 | [diff] [blame] | 4010 | [CPL_FW4_ACK] = fw4_ack, |
Vipul Pandya | 1cab775 | 2012-12-10 09:30:55 +0000 | [diff] [blame] | 4011 | [CPL_FW6_MSG] = deferred_fw6_msg, |
Hariprasad S | 9dec900 | 2016-05-05 01:27:29 +0530 | [diff] [blame] | 4012 | [CPL_RX_PKT] = rx_pkt, |
Hariprasad S | 8d1f1a6 | 2016-05-06 22:17:57 +0530 | [diff] [blame] | 4013 | [FAKE_CPL_PUT_EP_SAFE] = _put_ep_safe, |
| 4014 | [FAKE_CPL_PASS_PUT_EP_SAFE] = _put_pass_ep_safe |
Roland Dreier | be4c9ba | 2010-05-05 14:45:40 -0700 | [diff] [blame] | 4015 | }; |
| 4016 | |
| 4017 | static void process_timeout(struct c4iw_ep *ep) |
| 4018 | { |
| 4019 | struct c4iw_qp_attributes attrs; |
| 4020 | int abort = 1; |
| 4021 | |
Steve Wise | 2f5b48c | 2010-09-10 11:15:36 -0500 | [diff] [blame] | 4022 | mutex_lock(&ep->com.mutex); |
Roland Dreier | be4c9ba | 2010-05-05 14:45:40 -0700 | [diff] [blame] | 4023 | PDBG("%s ep %p tid %u state %d\n", __func__, ep, ep->hwtid, |
| 4024 | ep->com.state); |
Vipul Pandya | 793dad9 | 2012-12-10 09:30:56 +0000 | [diff] [blame] | 4025 | set_bit(TIMEDOUT, &ep->com.history); |
Roland Dreier | be4c9ba | 2010-05-05 14:45:40 -0700 | [diff] [blame] | 4026 | switch (ep->com.state) { |
| 4027 | case MPA_REQ_SENT: |
Roland Dreier | be4c9ba | 2010-05-05 14:45:40 -0700 | [diff] [blame] | 4028 | connect_reply_upcall(ep, -ETIMEDOUT); |
| 4029 | break; |
| 4030 | case MPA_REQ_WAIT: |
Hariprasad S | ceb110a | 2016-05-06 22:18:05 +0530 | [diff] [blame] | 4031 | case MPA_REQ_RCVD: |
Hariprasad S | e4b76a2 | 2016-05-06 22:17:59 +0530 | [diff] [blame] | 4032 | case MPA_REP_SENT: |
Hariprasad S | ceb110a | 2016-05-06 22:18:05 +0530 | [diff] [blame] | 4033 | case FPDU_MODE: |
Roland Dreier | be4c9ba | 2010-05-05 14:45:40 -0700 | [diff] [blame] | 4034 | break; |
| 4035 | case CLOSING: |
| 4036 | case MORIBUND: |
| 4037 | if (ep->com.cm_id && ep->com.qp) { |
| 4038 | attrs.next_state = C4IW_QP_STATE_ERROR; |
| 4039 | c4iw_modify_qp(ep->com.qp->rhp, |
| 4040 | ep->com.qp, C4IW_QP_ATTR_NEXT_STATE, |
| 4041 | &attrs, 1); |
| 4042 | } |
Steve Wise | be13b2d | 2014-03-21 20:40:33 +0530 | [diff] [blame] | 4043 | close_complete_upcall(ep, -ETIMEDOUT); |
Roland Dreier | be4c9ba | 2010-05-05 14:45:40 -0700 | [diff] [blame] | 4044 | break; |
Steve Wise | b33bd0c | 2014-04-09 09:38:25 -0500 | [diff] [blame] | 4045 | case ABORTING: |
| 4046 | case DEAD: |
| 4047 | |
| 4048 | /* |
| 4049 | * These states are expected if the ep timed out at the same |
| 4050 | * time as another thread was calling stop_ep_timer(). |
| 4051 | * So we silently do nothing for these states. |
| 4052 | */ |
| 4053 | abort = 0; |
| 4054 | break; |
Roland Dreier | be4c9ba | 2010-05-05 14:45:40 -0700 | [diff] [blame] | 4055 | default: |
Julia Lawall | 76f267b | 2012-11-03 10:58:27 +0000 | [diff] [blame] | 4056 | WARN(1, "%s unexpected state ep %p tid %u state %u\n", |
Roland Dreier | be4c9ba | 2010-05-05 14:45:40 -0700 | [diff] [blame] | 4057 | __func__, ep, ep->hwtid, ep->com.state); |
Roland Dreier | be4c9ba | 2010-05-05 14:45:40 -0700 | [diff] [blame] | 4058 | abort = 0; |
| 4059 | } |
Steve Wise | cc18b93 | 2014-04-24 14:31:53 -0500 | [diff] [blame] | 4060 | mutex_unlock(&ep->com.mutex); |
Hariprasad S | 6973627 | 2016-05-05 01:27:37 +0530 | [diff] [blame] | 4061 | if (abort) |
| 4062 | c4iw_ep_disconnect(ep, 1, GFP_KERNEL); |
Roland Dreier | be4c9ba | 2010-05-05 14:45:40 -0700 | [diff] [blame] | 4063 | c4iw_put_ep(&ep->com); |
| 4064 | } |
| 4065 | |
| 4066 | static void process_timedout_eps(void) |
| 4067 | { |
| 4068 | struct c4iw_ep *ep; |
| 4069 | |
| 4070 | spin_lock_irq(&timeout_lock); |
| 4071 | while (!list_empty(&timeout_list)) { |
| 4072 | struct list_head *tmp; |
| 4073 | |
| 4074 | tmp = timeout_list.next; |
| 4075 | list_del(tmp); |
Steve Wise | b33bd0c | 2014-04-09 09:38:25 -0500 | [diff] [blame] | 4076 | tmp->next = NULL; |
| 4077 | tmp->prev = NULL; |
Roland Dreier | be4c9ba | 2010-05-05 14:45:40 -0700 | [diff] [blame] | 4078 | spin_unlock_irq(&timeout_lock); |
| 4079 | ep = list_entry(tmp, struct c4iw_ep, entry); |
| 4080 | process_timeout(ep); |
| 4081 | spin_lock_irq(&timeout_lock); |
| 4082 | } |
| 4083 | spin_unlock_irq(&timeout_lock); |
| 4084 | } |
| 4085 | |
| 4086 | static void process_work(struct work_struct *work) |
| 4087 | { |
| 4088 | struct sk_buff *skb = NULL; |
| 4089 | struct c4iw_dev *dev; |
Dan Carpenter | c1d7356 | 2010-05-31 14:00:53 +0000 | [diff] [blame] | 4090 | struct cpl_act_establish *rpl; |
Roland Dreier | be4c9ba | 2010-05-05 14:45:40 -0700 | [diff] [blame] | 4091 | unsigned int opcode; |
| 4092 | int ret; |
| 4093 | |
Steve Wise | b33bd0c | 2014-04-09 09:38:25 -0500 | [diff] [blame] | 4094 | process_timedout_eps(); |
Roland Dreier | be4c9ba | 2010-05-05 14:45:40 -0700 | [diff] [blame] | 4095 | while ((skb = skb_dequeue(&rxq))) { |
| 4096 | rpl = cplhdr(skb); |
| 4097 | dev = *((struct c4iw_dev **) (skb->cb + sizeof(void *))); |
| 4098 | opcode = rpl->ot.opcode; |
| 4099 | |
| 4100 | BUG_ON(!work_handlers[opcode]); |
| 4101 | ret = work_handlers[opcode](dev, skb); |
| 4102 | if (!ret) |
| 4103 | kfree_skb(skb); |
Steve Wise | b33bd0c | 2014-04-09 09:38:25 -0500 | [diff] [blame] | 4104 | process_timedout_eps(); |
Roland Dreier | be4c9ba | 2010-05-05 14:45:40 -0700 | [diff] [blame] | 4105 | } |
Roland Dreier | be4c9ba | 2010-05-05 14:45:40 -0700 | [diff] [blame] | 4106 | } |
| 4107 | |
| 4108 | static DECLARE_WORK(skb_work, process_work); |
| 4109 | |
| 4110 | static void ep_timeout(unsigned long arg) |
| 4111 | { |
| 4112 | struct c4iw_ep *ep = (struct c4iw_ep *)arg; |
Vipul Pandya | 1ec779c | 2013-01-07 13:11:56 +0000 | [diff] [blame] | 4113 | int kickit = 0; |
Roland Dreier | be4c9ba | 2010-05-05 14:45:40 -0700 | [diff] [blame] | 4114 | |
| 4115 | spin_lock(&timeout_lock); |
Vipul Pandya | 1ec779c | 2013-01-07 13:11:56 +0000 | [diff] [blame] | 4116 | if (!test_and_set_bit(TIMEOUT, &ep->com.flags)) { |
Steve Wise | b33bd0c | 2014-04-09 09:38:25 -0500 | [diff] [blame] | 4117 | /* |
| 4118 | * Only insert if it is not already on the list. |
| 4119 | */ |
| 4120 | if (!ep->entry.next) { |
| 4121 | list_add_tail(&ep->entry, &timeout_list); |
| 4122 | kickit = 1; |
| 4123 | } |
Vipul Pandya | 1ec779c | 2013-01-07 13:11:56 +0000 | [diff] [blame] | 4124 | } |
Roland Dreier | be4c9ba | 2010-05-05 14:45:40 -0700 | [diff] [blame] | 4125 | spin_unlock(&timeout_lock); |
Vipul Pandya | 1ec779c | 2013-01-07 13:11:56 +0000 | [diff] [blame] | 4126 | if (kickit) |
| 4127 | queue_work(workq, &skb_work); |
Roland Dreier | be4c9ba | 2010-05-05 14:45:40 -0700 | [diff] [blame] | 4128 | } |
| 4129 | |
| 4130 | /* |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 4131 | * All the CM events are handled on a work queue to have a safe context. |
| 4132 | */ |
| 4133 | static int sched(struct c4iw_dev *dev, struct sk_buff *skb) |
| 4134 | { |
| 4135 | |
| 4136 | /* |
| 4137 | * Save dev in the skb->cb area. |
| 4138 | */ |
| 4139 | *((struct c4iw_dev **) (skb->cb + sizeof(void *))) = dev; |
| 4140 | |
| 4141 | /* |
| 4142 | * Queue the skb and schedule the worker thread. |
| 4143 | */ |
| 4144 | skb_queue_tail(&rxq, skb); |
| 4145 | queue_work(workq, &skb_work); |
| 4146 | return 0; |
| 4147 | } |
| 4148 | |
| 4149 | static int set_tcb_rpl(struct c4iw_dev *dev, struct sk_buff *skb) |
| 4150 | { |
| 4151 | struct cpl_set_tcb_rpl *rpl = cplhdr(skb); |
| 4152 | |
| 4153 | if (rpl->status != CPL_ERR_NONE) { |
| 4154 | printk(KERN_ERR MOD "Unexpected SET_TCB_RPL status %u " |
| 4155 | "for tid %u\n", rpl->status, GET_TID(rpl)); |
| 4156 | } |
Steve Wise | 2f5b48c | 2010-09-10 11:15:36 -0500 | [diff] [blame] | 4157 | kfree_skb(skb); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 4158 | return 0; |
| 4159 | } |
| 4160 | |
Roland Dreier | be4c9ba | 2010-05-05 14:45:40 -0700 | [diff] [blame] | 4161 | static int fw6_msg(struct c4iw_dev *dev, struct sk_buff *skb) |
| 4162 | { |
| 4163 | struct cpl_fw6_msg *rpl = cplhdr(skb); |
| 4164 | struct c4iw_wr_wait *wr_waitp; |
| 4165 | int ret; |
| 4166 | |
| 4167 | PDBG("%s type %u\n", __func__, rpl->type); |
| 4168 | |
| 4169 | switch (rpl->type) { |
Vipul Pandya | 5be78ee | 2012-12-10 09:30:54 +0000 | [diff] [blame] | 4170 | case FW6_TYPE_WR_RPL: |
Roland Dreier | be4c9ba | 2010-05-05 14:45:40 -0700 | [diff] [blame] | 4171 | ret = (int)((be64_to_cpu(rpl->data[0]) >> 8) & 0xff); |
Roland Dreier | c8e081a | 2010-09-27 17:51:04 -0700 | [diff] [blame] | 4172 | wr_waitp = (struct c4iw_wr_wait *)(__force unsigned long) rpl->data[1]; |
Roland Dreier | be4c9ba | 2010-05-05 14:45:40 -0700 | [diff] [blame] | 4173 | PDBG("%s wr_waitp %p ret %u\n", __func__, wr_waitp, ret); |
Steve Wise | d9594d9 | 2011-05-09 22:06:22 -0700 | [diff] [blame] | 4174 | if (wr_waitp) |
| 4175 | c4iw_wake_up(wr_waitp, ret ? -ret : 0); |
Steve Wise | 2f5b48c | 2010-09-10 11:15:36 -0500 | [diff] [blame] | 4176 | kfree_skb(skb); |
Roland Dreier | be4c9ba | 2010-05-05 14:45:40 -0700 | [diff] [blame] | 4177 | break; |
Vipul Pandya | 5be78ee | 2012-12-10 09:30:54 +0000 | [diff] [blame] | 4178 | case FW6_TYPE_CQE: |
Vipul Pandya | 5be78ee | 2012-12-10 09:30:54 +0000 | [diff] [blame] | 4179 | case FW6_TYPE_OFLD_CONNECTION_WR_RPL: |
Vipul Pandya | 1cab775 | 2012-12-10 09:30:55 +0000 | [diff] [blame] | 4180 | sched(dev, skb); |
Vipul Pandya | 5be78ee | 2012-12-10 09:30:54 +0000 | [diff] [blame] | 4181 | break; |
Roland Dreier | be4c9ba | 2010-05-05 14:45:40 -0700 | [diff] [blame] | 4182 | default: |
| 4183 | printk(KERN_ERR MOD "%s unexpected fw6 msg type %u\n", __func__, |
| 4184 | rpl->type); |
Steve Wise | 2f5b48c | 2010-09-10 11:15:36 -0500 | [diff] [blame] | 4185 | kfree_skb(skb); |
Roland Dreier | be4c9ba | 2010-05-05 14:45:40 -0700 | [diff] [blame] | 4186 | break; |
| 4187 | } |
| 4188 | return 0; |
| 4189 | } |
| 4190 | |
Steve Wise | 8da7e7a | 2011-06-14 20:59:27 +0000 | [diff] [blame] | 4191 | static int peer_abort_intr(struct c4iw_dev *dev, struct sk_buff *skb) |
| 4192 | { |
| 4193 | struct cpl_abort_req_rss *req = cplhdr(skb); |
| 4194 | struct c4iw_ep *ep; |
Steve Wise | 8da7e7a | 2011-06-14 20:59:27 +0000 | [diff] [blame] | 4195 | unsigned int tid = GET_TID(req); |
| 4196 | |
Hariprasad S | 944661d | 2016-05-06 22:18:03 +0530 | [diff] [blame] | 4197 | ep = get_ep_from_tid(dev, tid); |
| 4198 | /* This EP will be dereferenced in peer_abort() */ |
Steve Wise | 14b9222 | 2012-04-30 15:31:29 -0500 | [diff] [blame] | 4199 | if (!ep) { |
| 4200 | printk(KERN_WARNING MOD |
| 4201 | "Abort on non-existent endpoint, tid %d\n", tid); |
| 4202 | kfree_skb(skb); |
| 4203 | return 0; |
| 4204 | } |
Varun Prakash | b65eef0 | 2016-09-13 21:23:59 +0530 | [diff] [blame] | 4205 | if (cxgb_is_neg_adv(req->status)) { |
Hariprasad S | 179d03b | 2015-05-05 03:55:24 +0530 | [diff] [blame] | 4206 | PDBG("%s Negative advice on abort- tid %u status %d (%s)\n", |
| 4207 | __func__, ep->hwtid, req->status, |
| 4208 | neg_adv_str(req->status)); |
Hariprasad S | 944661d | 2016-05-06 22:18:03 +0530 | [diff] [blame] | 4209 | goto out; |
Steve Wise | 8da7e7a | 2011-06-14 20:59:27 +0000 | [diff] [blame] | 4210 | } |
| 4211 | PDBG("%s ep %p tid %u state %u\n", __func__, ep, ep->hwtid, |
| 4212 | ep->com.state); |
| 4213 | |
Hariprasad S | 093108c | 2016-05-06 22:18:09 +0530 | [diff] [blame] | 4214 | c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET); |
Hariprasad S | 944661d | 2016-05-06 22:18:03 +0530 | [diff] [blame] | 4215 | out: |
Steve Wise | 8da7e7a | 2011-06-14 20:59:27 +0000 | [diff] [blame] | 4216 | sched(dev, skb); |
| 4217 | return 0; |
| 4218 | } |
| 4219 | |
Roland Dreier | be4c9ba | 2010-05-05 14:45:40 -0700 | [diff] [blame] | 4220 | /* |
| 4221 | * Most upcalls from the T4 Core go to sched() to |
| 4222 | * schedule the processing on a work queue. |
| 4223 | */ |
| 4224 | c4iw_handler_func c4iw_handlers[NUM_CPL_CMDS] = { |
| 4225 | [CPL_ACT_ESTABLISH] = sched, |
| 4226 | [CPL_ACT_OPEN_RPL] = sched, |
| 4227 | [CPL_RX_DATA] = sched, |
| 4228 | [CPL_ABORT_RPL_RSS] = sched, |
| 4229 | [CPL_ABORT_RPL] = sched, |
| 4230 | [CPL_PASS_OPEN_RPL] = sched, |
| 4231 | [CPL_CLOSE_LISTSRV_RPL] = sched, |
| 4232 | [CPL_PASS_ACCEPT_REQ] = sched, |
| 4233 | [CPL_PASS_ESTABLISH] = sched, |
| 4234 | [CPL_PEER_CLOSE] = sched, |
| 4235 | [CPL_CLOSE_CON_RPL] = sched, |
Steve Wise | 8da7e7a | 2011-06-14 20:59:27 +0000 | [diff] [blame] | 4236 | [CPL_ABORT_REQ_RSS] = peer_abort_intr, |
Roland Dreier | be4c9ba | 2010-05-05 14:45:40 -0700 | [diff] [blame] | 4237 | [CPL_RDMA_TERMINATE] = sched, |
| 4238 | [CPL_FW4_ACK] = sched, |
| 4239 | [CPL_SET_TCB_RPL] = set_tcb_rpl, |
Vipul Pandya | 1cab775 | 2012-12-10 09:30:55 +0000 | [diff] [blame] | 4240 | [CPL_FW6_MSG] = fw6_msg, |
| 4241 | [CPL_RX_PKT] = sched |
Roland Dreier | be4c9ba | 2010-05-05 14:45:40 -0700 | [diff] [blame] | 4242 | }; |
| 4243 | |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 4244 | int __init c4iw_cm_init(void) |
| 4245 | { |
Roland Dreier | be4c9ba | 2010-05-05 14:45:40 -0700 | [diff] [blame] | 4246 | spin_lock_init(&timeout_lock); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 4247 | skb_queue_head_init(&rxq); |
| 4248 | |
| 4249 | workq = create_singlethread_workqueue("iw_cxgb4"); |
| 4250 | if (!workq) |
| 4251 | return -ENOMEM; |
| 4252 | |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 4253 | return 0; |
| 4254 | } |
| 4255 | |
Steve Wise | 46c1376 | 2014-06-20 14:26:25 -0500 | [diff] [blame] | 4256 | void c4iw_cm_term(void) |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 4257 | { |
Roland Dreier | be4c9ba | 2010-05-05 14:45:40 -0700 | [diff] [blame] | 4258 | WARN_ON(!list_empty(&timeout_list)); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 4259 | flush_workqueue(workq); |
| 4260 | destroy_workqueue(workq); |
| 4261 | } |