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