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