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