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