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