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