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