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