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> |
| 41 | |
| 42 | #include <net/neighbour.h> |
| 43 | #include <net/netevent.h> |
| 44 | #include <net/route.h> |
| 45 | |
| 46 | #include "iw_cxgb4.h" |
| 47 | |
| 48 | static char *states[] = { |
| 49 | "idle", |
| 50 | "listen", |
| 51 | "connecting", |
| 52 | "mpa_wait_req", |
| 53 | "mpa_req_sent", |
| 54 | "mpa_req_rcvd", |
| 55 | "mpa_rep_sent", |
| 56 | "fpdu_mode", |
| 57 | "aborting", |
| 58 | "closing", |
| 59 | "moribund", |
| 60 | "dead", |
| 61 | NULL, |
| 62 | }; |
| 63 | |
Steve Wise | ba6d392 | 2010-06-23 15:46:49 +0000 | [diff] [blame] | 64 | static int dack_mode; |
| 65 | module_param(dack_mode, int, 0644); |
| 66 | MODULE_PARM_DESC(dack_mode, "Delayed ack mode (default=0)"); |
| 67 | |
Roland Dreier | be4c9ba | 2010-05-05 14:45:40 -0700 | [diff] [blame] | 68 | int c4iw_max_read_depth = 8; |
| 69 | module_param(c4iw_max_read_depth, int, 0644); |
| 70 | MODULE_PARM_DESC(c4iw_max_read_depth, "Per-connection max ORD/IRD (default=8)"); |
| 71 | |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 72 | static int enable_tcp_timestamps; |
| 73 | module_param(enable_tcp_timestamps, int, 0644); |
| 74 | MODULE_PARM_DESC(enable_tcp_timestamps, "Enable tcp timestamps (default=0)"); |
| 75 | |
| 76 | static int enable_tcp_sack; |
| 77 | module_param(enable_tcp_sack, int, 0644); |
| 78 | MODULE_PARM_DESC(enable_tcp_sack, "Enable tcp SACK (default=0)"); |
| 79 | |
| 80 | static int enable_tcp_window_scaling = 1; |
| 81 | module_param(enable_tcp_window_scaling, int, 0644); |
| 82 | MODULE_PARM_DESC(enable_tcp_window_scaling, |
| 83 | "Enable tcp window scaling (default=1)"); |
| 84 | |
| 85 | int c4iw_debug; |
| 86 | module_param(c4iw_debug, int, 0644); |
| 87 | MODULE_PARM_DESC(c4iw_debug, "Enable debug logging (default=0)"); |
| 88 | |
| 89 | static int peer2peer; |
| 90 | module_param(peer2peer, int, 0644); |
| 91 | MODULE_PARM_DESC(peer2peer, "Support peer2peer ULPs (default=0)"); |
| 92 | |
| 93 | static int p2p_type = FW_RI_INIT_P2PTYPE_READ_REQ; |
| 94 | module_param(p2p_type, int, 0644); |
| 95 | MODULE_PARM_DESC(p2p_type, "RDMAP opcode to use for the RTR message: " |
| 96 | "1=RDMA_READ 0=RDMA_WRITE (default 1)"); |
| 97 | |
| 98 | static int ep_timeout_secs = 60; |
| 99 | module_param(ep_timeout_secs, int, 0644); |
| 100 | MODULE_PARM_DESC(ep_timeout_secs, "CM Endpoint operation timeout " |
| 101 | "in seconds (default=60)"); |
| 102 | |
| 103 | static int mpa_rev = 1; |
| 104 | module_param(mpa_rev, int, 0644); |
| 105 | MODULE_PARM_DESC(mpa_rev, "MPA Revision, 0 supports amso1100, " |
| 106 | "1 is spec compliant. (default=1)"); |
| 107 | |
| 108 | static int markers_enabled; |
| 109 | module_param(markers_enabled, int, 0644); |
| 110 | MODULE_PARM_DESC(markers_enabled, "Enable MPA MARKERS (default(0)=disabled)"); |
| 111 | |
| 112 | static int crc_enabled = 1; |
| 113 | module_param(crc_enabled, int, 0644); |
| 114 | MODULE_PARM_DESC(crc_enabled, "Enable MPA CRC (default(1)=enabled)"); |
| 115 | |
| 116 | static int rcv_win = 256 * 1024; |
| 117 | module_param(rcv_win, int, 0644); |
| 118 | MODULE_PARM_DESC(rcv_win, "TCP receive window in bytes (default=256KB)"); |
| 119 | |
Steve Wise | 98ae68b | 2010-09-10 11:15:41 -0500 | [diff] [blame] | 120 | static int snd_win = 128 * 1024; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 121 | module_param(snd_win, int, 0644); |
Steve Wise | 98ae68b | 2010-09-10 11:15:41 -0500 | [diff] [blame] | 122 | MODULE_PARM_DESC(snd_win, "TCP send window in bytes (default=128KB)"); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 123 | |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 124 | static struct workqueue_struct *workq; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 125 | |
| 126 | static struct sk_buff_head rxq; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 127 | |
| 128 | static struct sk_buff *get_skb(struct sk_buff *skb, int len, gfp_t gfp); |
| 129 | static void ep_timeout(unsigned long arg); |
| 130 | static void connect_reply_upcall(struct c4iw_ep *ep, int status); |
| 131 | |
Roland Dreier | be4c9ba | 2010-05-05 14:45:40 -0700 | [diff] [blame] | 132 | static LIST_HEAD(timeout_list); |
| 133 | static spinlock_t timeout_lock; |
| 134 | |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 135 | static void start_ep_timer(struct c4iw_ep *ep) |
| 136 | { |
| 137 | PDBG("%s ep %p\n", __func__, ep); |
| 138 | if (timer_pending(&ep->timer)) { |
| 139 | PDBG("%s stopped / restarted timer ep %p\n", __func__, ep); |
| 140 | del_timer_sync(&ep->timer); |
| 141 | } else |
| 142 | c4iw_get_ep(&ep->com); |
| 143 | ep->timer.expires = jiffies + ep_timeout_secs * HZ; |
| 144 | ep->timer.data = (unsigned long)ep; |
| 145 | ep->timer.function = ep_timeout; |
| 146 | add_timer(&ep->timer); |
| 147 | } |
| 148 | |
| 149 | static void stop_ep_timer(struct c4iw_ep *ep) |
| 150 | { |
| 151 | PDBG("%s ep %p\n", __func__, ep); |
| 152 | if (!timer_pending(&ep->timer)) { |
| 153 | printk(KERN_ERR "%s timer stopped when its not running! " |
| 154 | "ep %p state %u\n", __func__, ep, ep->com.state); |
| 155 | WARN_ON(1); |
| 156 | return; |
| 157 | } |
| 158 | del_timer_sync(&ep->timer); |
| 159 | c4iw_put_ep(&ep->com); |
| 160 | } |
| 161 | |
| 162 | static int c4iw_l2t_send(struct c4iw_rdev *rdev, struct sk_buff *skb, |
| 163 | struct l2t_entry *l2e) |
| 164 | { |
| 165 | int error = 0; |
| 166 | |
| 167 | if (c4iw_fatal_error(rdev)) { |
| 168 | kfree_skb(skb); |
| 169 | PDBG("%s - device in error state - dropping\n", __func__); |
| 170 | return -EIO; |
| 171 | } |
| 172 | error = cxgb4_l2t_send(rdev->lldi.ports[0], skb, l2e); |
| 173 | if (error < 0) |
| 174 | kfree_skb(skb); |
Steve Wise | 7459486 | 2010-09-10 11:14:58 -0500 | [diff] [blame] | 175 | return error < 0 ? error : 0; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 176 | } |
| 177 | |
| 178 | int c4iw_ofld_send(struct c4iw_rdev *rdev, struct sk_buff *skb) |
| 179 | { |
| 180 | int error = 0; |
| 181 | |
| 182 | if (c4iw_fatal_error(rdev)) { |
| 183 | kfree_skb(skb); |
| 184 | PDBG("%s - device in error state - dropping\n", __func__); |
| 185 | return -EIO; |
| 186 | } |
| 187 | error = cxgb4_ofld_send(rdev->lldi.ports[0], skb); |
| 188 | if (error < 0) |
| 189 | kfree_skb(skb); |
Steve Wise | 7459486 | 2010-09-10 11:14:58 -0500 | [diff] [blame] | 190 | return error < 0 ? error : 0; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 191 | } |
| 192 | |
| 193 | static void release_tid(struct c4iw_rdev *rdev, u32 hwtid, struct sk_buff *skb) |
| 194 | { |
| 195 | struct cpl_tid_release *req; |
| 196 | |
| 197 | skb = get_skb(skb, sizeof *req, GFP_KERNEL); |
| 198 | if (!skb) |
| 199 | return; |
| 200 | req = (struct cpl_tid_release *) skb_put(skb, sizeof(*req)); |
| 201 | INIT_TP_WR(req, hwtid); |
| 202 | OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_TID_RELEASE, hwtid)); |
| 203 | set_wr_txq(skb, CPL_PRIORITY_SETUP, 0); |
| 204 | c4iw_ofld_send(rdev, skb); |
| 205 | return; |
| 206 | } |
| 207 | |
| 208 | static void set_emss(struct c4iw_ep *ep, u16 opt) |
| 209 | { |
| 210 | ep->emss = ep->com.dev->rdev.lldi.mtus[GET_TCPOPT_MSS(opt)] - 40; |
| 211 | ep->mss = ep->emss; |
| 212 | if (GET_TCPOPT_TSTAMP(opt)) |
| 213 | ep->emss -= 12; |
| 214 | if (ep->emss < 128) |
| 215 | ep->emss = 128; |
| 216 | PDBG("%s mss_idx %u mss %u emss=%u\n", __func__, GET_TCPOPT_MSS(opt), |
| 217 | ep->mss, ep->emss); |
| 218 | } |
| 219 | |
| 220 | static enum c4iw_ep_state state_read(struct c4iw_ep_common *epc) |
| 221 | { |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 222 | enum c4iw_ep_state state; |
| 223 | |
Steve Wise | 2f5b48c | 2010-09-10 11:15:36 -0500 | [diff] [blame] | 224 | mutex_lock(&epc->mutex); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 225 | state = epc->state; |
Steve Wise | 2f5b48c | 2010-09-10 11:15:36 -0500 | [diff] [blame] | 226 | mutex_unlock(&epc->mutex); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 227 | return state; |
| 228 | } |
| 229 | |
| 230 | static void __state_set(struct c4iw_ep_common *epc, enum c4iw_ep_state new) |
| 231 | { |
| 232 | epc->state = new; |
| 233 | } |
| 234 | |
| 235 | static void state_set(struct c4iw_ep_common *epc, enum c4iw_ep_state new) |
| 236 | { |
Steve Wise | 2f5b48c | 2010-09-10 11:15:36 -0500 | [diff] [blame] | 237 | mutex_lock(&epc->mutex); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 238 | PDBG("%s - %s -> %s\n", __func__, states[epc->state], states[new]); |
| 239 | __state_set(epc, new); |
Steve Wise | 2f5b48c | 2010-09-10 11:15:36 -0500 | [diff] [blame] | 240 | mutex_unlock(&epc->mutex); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 241 | return; |
| 242 | } |
| 243 | |
| 244 | static void *alloc_ep(int size, gfp_t gfp) |
| 245 | { |
| 246 | struct c4iw_ep_common *epc; |
| 247 | |
| 248 | epc = kzalloc(size, gfp); |
| 249 | if (epc) { |
| 250 | kref_init(&epc->kref); |
Steve Wise | 2f5b48c | 2010-09-10 11:15:36 -0500 | [diff] [blame] | 251 | mutex_init(&epc->mutex); |
Steve Wise | aadc4df | 2010-09-10 11:15:25 -0500 | [diff] [blame] | 252 | c4iw_init_wr_wait(&epc->wr_wait); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 253 | } |
| 254 | PDBG("%s alloc ep %p\n", __func__, epc); |
| 255 | return epc; |
| 256 | } |
| 257 | |
| 258 | void _c4iw_free_ep(struct kref *kref) |
| 259 | { |
| 260 | struct c4iw_ep *ep; |
| 261 | |
| 262 | ep = container_of(kref, struct c4iw_ep, com.kref); |
| 263 | PDBG("%s ep %p state %s\n", __func__, ep, states[state_read(&ep->com)]); |
| 264 | if (test_bit(RELEASE_RESOURCES, &ep->com.flags)) { |
| 265 | cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, ep->hwtid); |
| 266 | dst_release(ep->dst); |
| 267 | cxgb4_l2t_release(ep->l2t); |
| 268 | } |
| 269 | kfree(ep); |
| 270 | } |
| 271 | |
| 272 | static void release_ep_resources(struct c4iw_ep *ep) |
| 273 | { |
| 274 | set_bit(RELEASE_RESOURCES, &ep->com.flags); |
| 275 | c4iw_put_ep(&ep->com); |
| 276 | } |
| 277 | |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 278 | static int status2errno(int status) |
| 279 | { |
| 280 | switch (status) { |
| 281 | case CPL_ERR_NONE: |
| 282 | return 0; |
| 283 | case CPL_ERR_CONN_RESET: |
| 284 | return -ECONNRESET; |
| 285 | case CPL_ERR_ARP_MISS: |
| 286 | return -EHOSTUNREACH; |
| 287 | case CPL_ERR_CONN_TIMEDOUT: |
| 288 | return -ETIMEDOUT; |
| 289 | case CPL_ERR_TCAM_FULL: |
| 290 | return -ENOMEM; |
| 291 | case CPL_ERR_CONN_EXIST: |
| 292 | return -EADDRINUSE; |
| 293 | default: |
| 294 | return -EIO; |
| 295 | } |
| 296 | } |
| 297 | |
| 298 | /* |
| 299 | * Try and reuse skbs already allocated... |
| 300 | */ |
| 301 | static struct sk_buff *get_skb(struct sk_buff *skb, int len, gfp_t gfp) |
| 302 | { |
| 303 | if (skb && !skb_is_nonlinear(skb) && !skb_cloned(skb)) { |
| 304 | skb_trim(skb, 0); |
| 305 | skb_get(skb); |
| 306 | skb_reset_transport_header(skb); |
| 307 | } else { |
| 308 | skb = alloc_skb(len, gfp); |
| 309 | } |
| 310 | return skb; |
| 311 | } |
| 312 | |
| 313 | static struct rtable *find_route(struct c4iw_dev *dev, __be32 local_ip, |
| 314 | __be32 peer_ip, __be16 local_port, |
| 315 | __be16 peer_port, u8 tos) |
| 316 | { |
| 317 | struct rtable *rt; |
| 318 | struct flowi fl = { |
| 319 | .oif = 0, |
| 320 | .nl_u = { |
| 321 | .ip4_u = { |
| 322 | .daddr = peer_ip, |
| 323 | .saddr = local_ip, |
| 324 | .tos = tos} |
| 325 | }, |
| 326 | .proto = IPPROTO_TCP, |
| 327 | .uli_u = { |
| 328 | .ports = { |
| 329 | .sport = local_port, |
| 330 | .dport = peer_port} |
| 331 | } |
| 332 | }; |
| 333 | |
David S. Miller | b23dd4f | 2011-03-02 14:31:35 -0800 | [diff] [blame] | 334 | rt = ip_route_output_flow(&init_net, &fl, NULL); |
| 335 | if (IS_ERR(rt)) |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 336 | return NULL; |
| 337 | return rt; |
| 338 | } |
| 339 | |
| 340 | static void arp_failure_discard(void *handle, struct sk_buff *skb) |
| 341 | { |
| 342 | PDBG("%s c4iw_dev %p\n", __func__, handle); |
| 343 | kfree_skb(skb); |
| 344 | } |
| 345 | |
| 346 | /* |
| 347 | * Handle an ARP failure for an active open. |
| 348 | */ |
| 349 | static void act_open_req_arp_failure(void *handle, struct sk_buff *skb) |
| 350 | { |
| 351 | printk(KERN_ERR MOD "ARP failure duing connect\n"); |
| 352 | kfree_skb(skb); |
| 353 | } |
| 354 | |
| 355 | /* |
| 356 | * Handle an ARP failure for a CPL_ABORT_REQ. Change it into a no RST variant |
| 357 | * and send it along. |
| 358 | */ |
| 359 | static void abort_arp_failure(void *handle, struct sk_buff *skb) |
| 360 | { |
| 361 | struct c4iw_rdev *rdev = handle; |
| 362 | struct cpl_abort_req *req = cplhdr(skb); |
| 363 | |
| 364 | PDBG("%s rdev %p\n", __func__, rdev); |
| 365 | req->cmd = CPL_ABORT_NO_RST; |
| 366 | c4iw_ofld_send(rdev, skb); |
| 367 | } |
| 368 | |
| 369 | static void send_flowc(struct c4iw_ep *ep, struct sk_buff *skb) |
| 370 | { |
| 371 | unsigned int flowclen = 80; |
| 372 | struct fw_flowc_wr *flowc; |
| 373 | int i; |
| 374 | |
| 375 | skb = get_skb(skb, flowclen, GFP_KERNEL); |
| 376 | flowc = (struct fw_flowc_wr *)__skb_put(skb, flowclen); |
| 377 | |
| 378 | flowc->op_to_nparams = cpu_to_be32(FW_WR_OP(FW_FLOWC_WR) | |
| 379 | FW_FLOWC_WR_NPARAMS(8)); |
| 380 | flowc->flowid_len16 = cpu_to_be32(FW_WR_LEN16(DIV_ROUND_UP(flowclen, |
| 381 | 16)) | FW_WR_FLOWID(ep->hwtid)); |
| 382 | |
| 383 | flowc->mnemval[0].mnemonic = FW_FLOWC_MNEM_PFNVFN; |
Steve Wise | 9478865 | 2011-01-21 17:00:34 +0000 | [diff] [blame] | 384 | 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] | 385 | flowc->mnemval[1].mnemonic = FW_FLOWC_MNEM_CH; |
| 386 | flowc->mnemval[1].val = cpu_to_be32(ep->tx_chan); |
| 387 | flowc->mnemval[2].mnemonic = FW_FLOWC_MNEM_PORT; |
| 388 | flowc->mnemval[2].val = cpu_to_be32(ep->tx_chan); |
| 389 | flowc->mnemval[3].mnemonic = FW_FLOWC_MNEM_IQID; |
| 390 | flowc->mnemval[3].val = cpu_to_be32(ep->rss_qid); |
| 391 | flowc->mnemval[4].mnemonic = FW_FLOWC_MNEM_SNDNXT; |
| 392 | flowc->mnemval[4].val = cpu_to_be32(ep->snd_seq); |
| 393 | flowc->mnemval[5].mnemonic = FW_FLOWC_MNEM_RCVNXT; |
| 394 | flowc->mnemval[5].val = cpu_to_be32(ep->rcv_seq); |
| 395 | flowc->mnemval[6].mnemonic = FW_FLOWC_MNEM_SNDBUF; |
| 396 | flowc->mnemval[6].val = cpu_to_be32(snd_win); |
| 397 | flowc->mnemval[7].mnemonic = FW_FLOWC_MNEM_MSS; |
| 398 | flowc->mnemval[7].val = cpu_to_be32(ep->emss); |
| 399 | /* Pad WR to 16 byte boundary */ |
| 400 | flowc->mnemval[8].mnemonic = 0; |
| 401 | flowc->mnemval[8].val = 0; |
| 402 | for (i = 0; i < 9; i++) { |
| 403 | flowc->mnemval[i].r4[0] = 0; |
| 404 | flowc->mnemval[i].r4[1] = 0; |
| 405 | flowc->mnemval[i].r4[2] = 0; |
| 406 | } |
| 407 | |
| 408 | set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx); |
| 409 | c4iw_ofld_send(&ep->com.dev->rdev, skb); |
| 410 | } |
| 411 | |
| 412 | static int send_halfclose(struct c4iw_ep *ep, gfp_t gfp) |
| 413 | { |
| 414 | struct cpl_close_con_req *req; |
| 415 | struct sk_buff *skb; |
| 416 | int wrlen = roundup(sizeof *req, 16); |
| 417 | |
| 418 | PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid); |
| 419 | skb = get_skb(NULL, wrlen, gfp); |
| 420 | if (!skb) { |
| 421 | printk(KERN_ERR MOD "%s - failed to alloc skb\n", __func__); |
| 422 | return -ENOMEM; |
| 423 | } |
| 424 | set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx); |
| 425 | t4_set_arp_err_handler(skb, NULL, arp_failure_discard); |
| 426 | req = (struct cpl_close_con_req *) skb_put(skb, wrlen); |
| 427 | memset(req, 0, wrlen); |
| 428 | INIT_TP_WR(req, ep->hwtid); |
| 429 | OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_CLOSE_CON_REQ, |
| 430 | ep->hwtid)); |
| 431 | return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t); |
| 432 | } |
| 433 | |
| 434 | static int send_abort(struct c4iw_ep *ep, struct sk_buff *skb, gfp_t gfp) |
| 435 | { |
| 436 | struct cpl_abort_req *req; |
| 437 | int wrlen = roundup(sizeof *req, 16); |
| 438 | |
| 439 | PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid); |
| 440 | skb = get_skb(skb, wrlen, gfp); |
| 441 | if (!skb) { |
| 442 | printk(KERN_ERR MOD "%s - failed to alloc skb.\n", |
| 443 | __func__); |
| 444 | return -ENOMEM; |
| 445 | } |
| 446 | set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx); |
| 447 | t4_set_arp_err_handler(skb, &ep->com.dev->rdev, abort_arp_failure); |
| 448 | req = (struct cpl_abort_req *) skb_put(skb, wrlen); |
| 449 | memset(req, 0, wrlen); |
| 450 | INIT_TP_WR(req, ep->hwtid); |
| 451 | OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_ABORT_REQ, ep->hwtid)); |
| 452 | req->cmd = CPL_ABORT_SEND_RST; |
| 453 | return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t); |
| 454 | } |
| 455 | |
| 456 | static int send_connect(struct c4iw_ep *ep) |
| 457 | { |
| 458 | struct cpl_act_open_req *req; |
| 459 | struct sk_buff *skb; |
| 460 | u64 opt0; |
| 461 | u32 opt2; |
| 462 | unsigned int mtu_idx; |
| 463 | int wscale; |
| 464 | int wrlen = roundup(sizeof *req, 16); |
| 465 | |
| 466 | PDBG("%s ep %p atid %u\n", __func__, ep, ep->atid); |
| 467 | |
| 468 | skb = get_skb(NULL, wrlen, GFP_KERNEL); |
| 469 | if (!skb) { |
| 470 | printk(KERN_ERR MOD "%s - failed to alloc skb.\n", |
| 471 | __func__); |
| 472 | return -ENOMEM; |
| 473 | } |
Steve Wise | d4f1a5c | 2010-07-23 19:12:32 +0000 | [diff] [blame] | 474 | set_wr_txq(skb, CPL_PRIORITY_SETUP, ep->ctrlq_idx); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 475 | |
| 476 | cxgb4_best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx); |
| 477 | wscale = compute_wscale(rcv_win); |
| 478 | opt0 = KEEP_ALIVE(1) | |
Steve Wise | ba6d392 | 2010-06-23 15:46:49 +0000 | [diff] [blame] | 479 | DELACK(1) | |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 480 | WND_SCALE(wscale) | |
| 481 | MSS_IDX(mtu_idx) | |
| 482 | L2T_IDX(ep->l2t->idx) | |
| 483 | TX_CHAN(ep->tx_chan) | |
| 484 | SMAC_SEL(ep->smac_idx) | |
| 485 | DSCP(ep->tos) | |
| 486 | RCV_BUFSIZ(rcv_win>>10); |
| 487 | opt2 = RX_CHANNEL(0) | |
| 488 | RSS_QUEUE_VALID | RSS_QUEUE(ep->rss_qid); |
| 489 | if (enable_tcp_timestamps) |
| 490 | opt2 |= TSTAMPS_EN(1); |
| 491 | if (enable_tcp_sack) |
| 492 | opt2 |= SACK_EN(1); |
| 493 | if (wscale && enable_tcp_window_scaling) |
| 494 | opt2 |= WND_SCALE_EN(1); |
| 495 | t4_set_arp_err_handler(skb, NULL, act_open_req_arp_failure); |
| 496 | |
| 497 | req = (struct cpl_act_open_req *) skb_put(skb, wrlen); |
| 498 | INIT_TP_WR(req, 0); |
| 499 | OPCODE_TID(req) = cpu_to_be32( |
| 500 | MK_OPCODE_TID(CPL_ACT_OPEN_REQ, ((ep->rss_qid<<14)|ep->atid))); |
| 501 | req->local_port = ep->com.local_addr.sin_port; |
| 502 | req->peer_port = ep->com.remote_addr.sin_port; |
| 503 | req->local_ip = ep->com.local_addr.sin_addr.s_addr; |
| 504 | req->peer_ip = ep->com.remote_addr.sin_addr.s_addr; |
| 505 | req->opt0 = cpu_to_be64(opt0); |
| 506 | req->params = 0; |
| 507 | req->opt2 = cpu_to_be32(opt2); |
| 508 | return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t); |
| 509 | } |
| 510 | |
| 511 | static void send_mpa_req(struct c4iw_ep *ep, struct sk_buff *skb) |
| 512 | { |
| 513 | int mpalen, wrlen; |
| 514 | struct fw_ofld_tx_data_wr *req; |
| 515 | struct mpa_message *mpa; |
| 516 | |
| 517 | PDBG("%s ep %p tid %u pd_len %d\n", __func__, ep, ep->hwtid, ep->plen); |
| 518 | |
| 519 | BUG_ON(skb_cloned(skb)); |
| 520 | |
| 521 | mpalen = sizeof(*mpa) + ep->plen; |
| 522 | wrlen = roundup(mpalen + sizeof *req, 16); |
| 523 | skb = get_skb(skb, wrlen, GFP_KERNEL); |
| 524 | if (!skb) { |
| 525 | connect_reply_upcall(ep, -ENOMEM); |
| 526 | return; |
| 527 | } |
| 528 | set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx); |
| 529 | |
| 530 | req = (struct fw_ofld_tx_data_wr *)skb_put(skb, wrlen); |
| 531 | memset(req, 0, wrlen); |
| 532 | req->op_to_immdlen = cpu_to_be32( |
| 533 | FW_WR_OP(FW_OFLD_TX_DATA_WR) | |
| 534 | FW_WR_COMPL(1) | |
| 535 | FW_WR_IMMDLEN(mpalen)); |
| 536 | req->flowid_len16 = cpu_to_be32( |
| 537 | FW_WR_FLOWID(ep->hwtid) | |
| 538 | FW_WR_LEN16(wrlen >> 4)); |
| 539 | req->plen = cpu_to_be32(mpalen); |
| 540 | req->tunnel_to_proxy = cpu_to_be32( |
| 541 | FW_OFLD_TX_DATA_WR_FLUSH(1) | |
| 542 | FW_OFLD_TX_DATA_WR_SHOVE(1)); |
| 543 | |
| 544 | mpa = (struct mpa_message *)(req + 1); |
| 545 | memcpy(mpa->key, MPA_KEY_REQ, sizeof(mpa->key)); |
| 546 | mpa->flags = (crc_enabled ? MPA_CRC : 0) | |
| 547 | (markers_enabled ? MPA_MARKERS : 0); |
| 548 | mpa->private_data_size = htons(ep->plen); |
| 549 | mpa->revision = mpa_rev; |
| 550 | |
| 551 | if (ep->plen) |
| 552 | memcpy(mpa->private_data, ep->mpa_pkt + sizeof(*mpa), ep->plen); |
| 553 | |
| 554 | /* |
| 555 | * Reference the mpa skb. This ensures the data area |
| 556 | * will remain in memory until the hw acks the tx. |
| 557 | * Function fw4_ack() will deref it. |
| 558 | */ |
| 559 | skb_get(skb); |
| 560 | t4_set_arp_err_handler(skb, NULL, arp_failure_discard); |
| 561 | BUG_ON(ep->mpa_skb); |
| 562 | ep->mpa_skb = skb; |
| 563 | c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t); |
| 564 | start_ep_timer(ep); |
| 565 | state_set(&ep->com, MPA_REQ_SENT); |
| 566 | ep->mpa_attr.initiator = 1; |
| 567 | return; |
| 568 | } |
| 569 | |
| 570 | static int send_mpa_reject(struct c4iw_ep *ep, const void *pdata, u8 plen) |
| 571 | { |
| 572 | int mpalen, wrlen; |
| 573 | struct fw_ofld_tx_data_wr *req; |
| 574 | struct mpa_message *mpa; |
| 575 | struct sk_buff *skb; |
| 576 | |
| 577 | PDBG("%s ep %p tid %u pd_len %d\n", __func__, ep, ep->hwtid, ep->plen); |
| 578 | |
| 579 | mpalen = sizeof(*mpa) + plen; |
| 580 | wrlen = roundup(mpalen + sizeof *req, 16); |
| 581 | |
| 582 | skb = get_skb(NULL, wrlen, GFP_KERNEL); |
| 583 | if (!skb) { |
| 584 | printk(KERN_ERR MOD "%s - cannot alloc skb!\n", __func__); |
| 585 | return -ENOMEM; |
| 586 | } |
| 587 | set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx); |
| 588 | |
| 589 | req = (struct fw_ofld_tx_data_wr *)skb_put(skb, wrlen); |
| 590 | memset(req, 0, wrlen); |
| 591 | req->op_to_immdlen = cpu_to_be32( |
| 592 | FW_WR_OP(FW_OFLD_TX_DATA_WR) | |
| 593 | FW_WR_COMPL(1) | |
| 594 | FW_WR_IMMDLEN(mpalen)); |
| 595 | req->flowid_len16 = cpu_to_be32( |
| 596 | FW_WR_FLOWID(ep->hwtid) | |
| 597 | FW_WR_LEN16(wrlen >> 4)); |
| 598 | req->plen = cpu_to_be32(mpalen); |
| 599 | req->tunnel_to_proxy = cpu_to_be32( |
| 600 | FW_OFLD_TX_DATA_WR_FLUSH(1) | |
| 601 | FW_OFLD_TX_DATA_WR_SHOVE(1)); |
| 602 | |
| 603 | mpa = (struct mpa_message *)(req + 1); |
| 604 | memset(mpa, 0, sizeof(*mpa)); |
| 605 | memcpy(mpa->key, MPA_KEY_REP, sizeof(mpa->key)); |
| 606 | mpa->flags = MPA_REJECT; |
| 607 | mpa->revision = mpa_rev; |
| 608 | mpa->private_data_size = htons(plen); |
| 609 | if (plen) |
| 610 | memcpy(mpa->private_data, pdata, plen); |
| 611 | |
| 612 | /* |
| 613 | * Reference the mpa skb again. This ensures the data area |
| 614 | * will remain in memory until the hw acks the tx. |
| 615 | * Function fw4_ack() will deref it. |
| 616 | */ |
| 617 | skb_get(skb); |
| 618 | set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx); |
| 619 | t4_set_arp_err_handler(skb, NULL, arp_failure_discard); |
| 620 | BUG_ON(ep->mpa_skb); |
| 621 | ep->mpa_skb = skb; |
| 622 | return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t); |
| 623 | } |
| 624 | |
| 625 | static int send_mpa_reply(struct c4iw_ep *ep, const void *pdata, u8 plen) |
| 626 | { |
| 627 | int mpalen, wrlen; |
| 628 | struct fw_ofld_tx_data_wr *req; |
| 629 | struct mpa_message *mpa; |
| 630 | struct sk_buff *skb; |
| 631 | |
| 632 | PDBG("%s ep %p tid %u pd_len %d\n", __func__, ep, ep->hwtid, ep->plen); |
| 633 | |
| 634 | mpalen = sizeof(*mpa) + plen; |
| 635 | wrlen = roundup(mpalen + sizeof *req, 16); |
| 636 | |
| 637 | skb = get_skb(NULL, wrlen, GFP_KERNEL); |
| 638 | if (!skb) { |
| 639 | printk(KERN_ERR MOD "%s - cannot alloc skb!\n", __func__); |
| 640 | return -ENOMEM; |
| 641 | } |
| 642 | set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx); |
| 643 | |
| 644 | req = (struct fw_ofld_tx_data_wr *) skb_put(skb, wrlen); |
| 645 | memset(req, 0, wrlen); |
| 646 | req->op_to_immdlen = cpu_to_be32( |
| 647 | FW_WR_OP(FW_OFLD_TX_DATA_WR) | |
| 648 | FW_WR_COMPL(1) | |
| 649 | FW_WR_IMMDLEN(mpalen)); |
| 650 | req->flowid_len16 = cpu_to_be32( |
| 651 | FW_WR_FLOWID(ep->hwtid) | |
| 652 | FW_WR_LEN16(wrlen >> 4)); |
| 653 | req->plen = cpu_to_be32(mpalen); |
| 654 | req->tunnel_to_proxy = cpu_to_be32( |
| 655 | FW_OFLD_TX_DATA_WR_FLUSH(1) | |
| 656 | FW_OFLD_TX_DATA_WR_SHOVE(1)); |
| 657 | |
| 658 | mpa = (struct mpa_message *)(req + 1); |
| 659 | memset(mpa, 0, sizeof(*mpa)); |
| 660 | memcpy(mpa->key, MPA_KEY_REP, sizeof(mpa->key)); |
| 661 | mpa->flags = (ep->mpa_attr.crc_enabled ? MPA_CRC : 0) | |
| 662 | (markers_enabled ? MPA_MARKERS : 0); |
| 663 | mpa->revision = mpa_rev; |
| 664 | mpa->private_data_size = htons(plen); |
| 665 | if (plen) |
| 666 | memcpy(mpa->private_data, pdata, plen); |
| 667 | |
| 668 | /* |
| 669 | * Reference the mpa skb. This ensures the data area |
| 670 | * will remain in memory until the hw acks the tx. |
| 671 | * Function fw4_ack() will deref it. |
| 672 | */ |
| 673 | skb_get(skb); |
| 674 | t4_set_arp_err_handler(skb, NULL, arp_failure_discard); |
| 675 | ep->mpa_skb = skb; |
| 676 | state_set(&ep->com, MPA_REP_SENT); |
| 677 | return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t); |
| 678 | } |
| 679 | |
| 680 | static int act_establish(struct c4iw_dev *dev, struct sk_buff *skb) |
| 681 | { |
| 682 | struct c4iw_ep *ep; |
| 683 | struct cpl_act_establish *req = cplhdr(skb); |
| 684 | unsigned int tid = GET_TID(req); |
| 685 | unsigned int atid = GET_TID_TID(ntohl(req->tos_atid)); |
| 686 | struct tid_info *t = dev->rdev.lldi.tids; |
| 687 | |
| 688 | ep = lookup_atid(t, atid); |
| 689 | |
| 690 | PDBG("%s ep %p tid %u snd_isn %u rcv_isn %u\n", __func__, ep, tid, |
| 691 | be32_to_cpu(req->snd_isn), be32_to_cpu(req->rcv_isn)); |
| 692 | |
| 693 | dst_confirm(ep->dst); |
| 694 | |
| 695 | /* setup the hwtid for this connection */ |
| 696 | ep->hwtid = tid; |
| 697 | cxgb4_insert_tid(t, ep, tid); |
| 698 | |
| 699 | ep->snd_seq = be32_to_cpu(req->snd_isn); |
| 700 | ep->rcv_seq = be32_to_cpu(req->rcv_isn); |
| 701 | |
| 702 | set_emss(ep, ntohs(req->tcp_opt)); |
| 703 | |
| 704 | /* dealloc the atid */ |
| 705 | cxgb4_free_atid(t, atid); |
| 706 | |
| 707 | /* start MPA negotiation */ |
| 708 | send_flowc(ep, NULL); |
| 709 | send_mpa_req(ep, skb); |
| 710 | |
| 711 | return 0; |
| 712 | } |
| 713 | |
| 714 | static void close_complete_upcall(struct c4iw_ep *ep) |
| 715 | { |
| 716 | struct iw_cm_event event; |
| 717 | |
| 718 | PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid); |
| 719 | memset(&event, 0, sizeof(event)); |
| 720 | event.event = IW_CM_EVENT_CLOSE; |
| 721 | if (ep->com.cm_id) { |
| 722 | PDBG("close complete delivered ep %p cm_id %p tid %u\n", |
| 723 | ep, ep->com.cm_id, ep->hwtid); |
| 724 | ep->com.cm_id->event_handler(ep->com.cm_id, &event); |
| 725 | ep->com.cm_id->rem_ref(ep->com.cm_id); |
| 726 | ep->com.cm_id = NULL; |
| 727 | ep->com.qp = NULL; |
| 728 | } |
| 729 | } |
| 730 | |
| 731 | static int abort_connection(struct c4iw_ep *ep, struct sk_buff *skb, gfp_t gfp) |
| 732 | { |
| 733 | PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid); |
| 734 | close_complete_upcall(ep); |
| 735 | state_set(&ep->com, ABORTING); |
| 736 | return send_abort(ep, skb, gfp); |
| 737 | } |
| 738 | |
| 739 | static void peer_close_upcall(struct c4iw_ep *ep) |
| 740 | { |
| 741 | struct iw_cm_event event; |
| 742 | |
| 743 | PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid); |
| 744 | memset(&event, 0, sizeof(event)); |
| 745 | event.event = IW_CM_EVENT_DISCONNECT; |
| 746 | if (ep->com.cm_id) { |
| 747 | PDBG("peer close delivered ep %p cm_id %p tid %u\n", |
| 748 | ep, ep->com.cm_id, ep->hwtid); |
| 749 | ep->com.cm_id->event_handler(ep->com.cm_id, &event); |
| 750 | } |
| 751 | } |
| 752 | |
| 753 | static void peer_abort_upcall(struct c4iw_ep *ep) |
| 754 | { |
| 755 | struct iw_cm_event event; |
| 756 | |
| 757 | PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid); |
| 758 | memset(&event, 0, sizeof(event)); |
| 759 | event.event = IW_CM_EVENT_CLOSE; |
| 760 | event.status = -ECONNRESET; |
| 761 | if (ep->com.cm_id) { |
| 762 | PDBG("abort delivered ep %p cm_id %p tid %u\n", ep, |
| 763 | ep->com.cm_id, ep->hwtid); |
| 764 | ep->com.cm_id->event_handler(ep->com.cm_id, &event); |
| 765 | ep->com.cm_id->rem_ref(ep->com.cm_id); |
| 766 | ep->com.cm_id = NULL; |
| 767 | ep->com.qp = NULL; |
| 768 | } |
| 769 | } |
| 770 | |
| 771 | static void connect_reply_upcall(struct c4iw_ep *ep, int status) |
| 772 | { |
| 773 | struct iw_cm_event event; |
| 774 | |
| 775 | PDBG("%s ep %p tid %u status %d\n", __func__, ep, ep->hwtid, status); |
| 776 | memset(&event, 0, sizeof(event)); |
| 777 | event.event = IW_CM_EVENT_CONNECT_REPLY; |
| 778 | event.status = status; |
| 779 | event.local_addr = ep->com.local_addr; |
| 780 | event.remote_addr = ep->com.remote_addr; |
| 781 | |
| 782 | if ((status == 0) || (status == -ECONNREFUSED)) { |
| 783 | event.private_data_len = ep->plen; |
| 784 | event.private_data = ep->mpa_pkt + sizeof(struct mpa_message); |
| 785 | } |
Roland Dreier | 85963e4 | 2010-07-19 13:13:09 -0700 | [diff] [blame] | 786 | |
| 787 | PDBG("%s ep %p tid %u status %d\n", __func__, ep, |
| 788 | ep->hwtid, status); |
| 789 | ep->com.cm_id->event_handler(ep->com.cm_id, &event); |
| 790 | |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 791 | if (status < 0) { |
| 792 | ep->com.cm_id->rem_ref(ep->com.cm_id); |
| 793 | ep->com.cm_id = NULL; |
| 794 | ep->com.qp = NULL; |
| 795 | } |
| 796 | } |
| 797 | |
| 798 | static void connect_request_upcall(struct c4iw_ep *ep) |
| 799 | { |
| 800 | struct iw_cm_event event; |
| 801 | |
| 802 | PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid); |
| 803 | memset(&event, 0, sizeof(event)); |
| 804 | event.event = IW_CM_EVENT_CONNECT_REQUEST; |
| 805 | event.local_addr = ep->com.local_addr; |
| 806 | event.remote_addr = ep->com.remote_addr; |
| 807 | event.private_data_len = ep->plen; |
| 808 | event.private_data = ep->mpa_pkt + sizeof(struct mpa_message); |
| 809 | event.provider_data = ep; |
| 810 | if (state_read(&ep->parent_ep->com) != DEAD) { |
| 811 | c4iw_get_ep(&ep->com); |
| 812 | ep->parent_ep->com.cm_id->event_handler( |
| 813 | ep->parent_ep->com.cm_id, |
| 814 | &event); |
| 815 | } |
| 816 | c4iw_put_ep(&ep->parent_ep->com); |
| 817 | ep->parent_ep = NULL; |
| 818 | } |
| 819 | |
| 820 | static void established_upcall(struct c4iw_ep *ep) |
| 821 | { |
| 822 | struct iw_cm_event event; |
| 823 | |
| 824 | PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid); |
| 825 | memset(&event, 0, sizeof(event)); |
| 826 | event.event = IW_CM_EVENT_ESTABLISHED; |
| 827 | if (ep->com.cm_id) { |
| 828 | PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid); |
| 829 | ep->com.cm_id->event_handler(ep->com.cm_id, &event); |
| 830 | } |
| 831 | } |
| 832 | |
| 833 | static int update_rx_credits(struct c4iw_ep *ep, u32 credits) |
| 834 | { |
| 835 | struct cpl_rx_data_ack *req; |
| 836 | struct sk_buff *skb; |
| 837 | int wrlen = roundup(sizeof *req, 16); |
| 838 | |
| 839 | PDBG("%s ep %p tid %u credits %u\n", __func__, ep, ep->hwtid, credits); |
| 840 | skb = get_skb(NULL, wrlen, GFP_KERNEL); |
| 841 | if (!skb) { |
| 842 | printk(KERN_ERR MOD "update_rx_credits - cannot alloc skb!\n"); |
| 843 | return 0; |
| 844 | } |
| 845 | |
| 846 | req = (struct cpl_rx_data_ack *) skb_put(skb, wrlen); |
| 847 | memset(req, 0, wrlen); |
| 848 | INIT_TP_WR(req, ep->hwtid); |
| 849 | OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_RX_DATA_ACK, |
| 850 | ep->hwtid)); |
Steve Wise | ba6d392 | 2010-06-23 15:46:49 +0000 | [diff] [blame] | 851 | req->credit_dack = cpu_to_be32(credits | RX_FORCE_ACK(1) | |
| 852 | F_RX_DACK_CHANGE | |
| 853 | V_RX_DACK_MODE(dack_mode)); |
Steve Wise | d4f1a5c | 2010-07-23 19:12:32 +0000 | [diff] [blame] | 854 | set_wr_txq(skb, CPL_PRIORITY_ACK, ep->ctrlq_idx); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 855 | c4iw_ofld_send(&ep->com.dev->rdev, skb); |
| 856 | return credits; |
| 857 | } |
| 858 | |
| 859 | static void process_mpa_reply(struct c4iw_ep *ep, struct sk_buff *skb) |
| 860 | { |
| 861 | struct mpa_message *mpa; |
| 862 | u16 plen; |
| 863 | struct c4iw_qp_attributes attrs; |
| 864 | enum c4iw_qp_attr_mask mask; |
| 865 | int err; |
| 866 | |
| 867 | PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid); |
| 868 | |
| 869 | /* |
| 870 | * Stop mpa timer. If it expired, then the state has |
| 871 | * changed and we bail since ep_timeout already aborted |
| 872 | * the connection. |
| 873 | */ |
| 874 | stop_ep_timer(ep); |
| 875 | if (state_read(&ep->com) != MPA_REQ_SENT) |
| 876 | return; |
| 877 | |
| 878 | /* |
| 879 | * If we get more than the supported amount of private data |
| 880 | * then we must fail this connection. |
| 881 | */ |
| 882 | if (ep->mpa_pkt_len + skb->len > sizeof(ep->mpa_pkt)) { |
| 883 | err = -EINVAL; |
| 884 | goto err; |
| 885 | } |
| 886 | |
| 887 | /* |
| 888 | * copy the new data into our accumulation buffer. |
| 889 | */ |
| 890 | skb_copy_from_linear_data(skb, &(ep->mpa_pkt[ep->mpa_pkt_len]), |
| 891 | skb->len); |
| 892 | ep->mpa_pkt_len += skb->len; |
| 893 | |
| 894 | /* |
| 895 | * if we don't even have the mpa message, then bail. |
| 896 | */ |
| 897 | if (ep->mpa_pkt_len < sizeof(*mpa)) |
| 898 | return; |
| 899 | mpa = (struct mpa_message *) ep->mpa_pkt; |
| 900 | |
| 901 | /* Validate MPA header. */ |
| 902 | if (mpa->revision != mpa_rev) { |
| 903 | err = -EPROTO; |
| 904 | goto err; |
| 905 | } |
| 906 | if (memcmp(mpa->key, MPA_KEY_REP, sizeof(mpa->key))) { |
| 907 | err = -EPROTO; |
| 908 | goto err; |
| 909 | } |
| 910 | |
| 911 | plen = ntohs(mpa->private_data_size); |
| 912 | |
| 913 | /* |
| 914 | * Fail if there's too much private data. |
| 915 | */ |
| 916 | if (plen > MPA_MAX_PRIVATE_DATA) { |
| 917 | err = -EPROTO; |
| 918 | goto err; |
| 919 | } |
| 920 | |
| 921 | /* |
| 922 | * If plen does not account for pkt size |
| 923 | */ |
| 924 | if (ep->mpa_pkt_len > (sizeof(*mpa) + plen)) { |
| 925 | err = -EPROTO; |
| 926 | goto err; |
| 927 | } |
| 928 | |
| 929 | ep->plen = (u8) plen; |
| 930 | |
| 931 | /* |
| 932 | * If we don't have all the pdata yet, then bail. |
| 933 | * We'll continue process when more data arrives. |
| 934 | */ |
| 935 | if (ep->mpa_pkt_len < (sizeof(*mpa) + plen)) |
| 936 | return; |
| 937 | |
| 938 | if (mpa->flags & MPA_REJECT) { |
| 939 | err = -ECONNREFUSED; |
| 940 | goto err; |
| 941 | } |
| 942 | |
| 943 | /* |
| 944 | * If we get here we have accumulated the entire mpa |
| 945 | * start reply message including private data. And |
| 946 | * the MPA header is valid. |
| 947 | */ |
| 948 | state_set(&ep->com, FPDU_MODE); |
| 949 | ep->mpa_attr.crc_enabled = (mpa->flags & MPA_CRC) | crc_enabled ? 1 : 0; |
| 950 | ep->mpa_attr.recv_marker_enabled = markers_enabled; |
| 951 | ep->mpa_attr.xmit_marker_enabled = mpa->flags & MPA_MARKERS ? 1 : 0; |
| 952 | ep->mpa_attr.version = mpa_rev; |
| 953 | ep->mpa_attr.p2p_type = peer2peer ? p2p_type : |
| 954 | FW_RI_INIT_P2PTYPE_DISABLED; |
| 955 | PDBG("%s - crc_enabled=%d, recv_marker_enabled=%d, " |
| 956 | "xmit_marker_enabled=%d, version=%d\n", __func__, |
| 957 | ep->mpa_attr.crc_enabled, ep->mpa_attr.recv_marker_enabled, |
| 958 | ep->mpa_attr.xmit_marker_enabled, ep->mpa_attr.version); |
| 959 | |
| 960 | attrs.mpa_attr = ep->mpa_attr; |
| 961 | attrs.max_ird = ep->ird; |
| 962 | attrs.max_ord = ep->ord; |
| 963 | attrs.llp_stream_handle = ep; |
| 964 | attrs.next_state = C4IW_QP_STATE_RTS; |
| 965 | |
| 966 | mask = C4IW_QP_ATTR_NEXT_STATE | |
| 967 | C4IW_QP_ATTR_LLP_STREAM_HANDLE | C4IW_QP_ATTR_MPA_ATTR | |
| 968 | C4IW_QP_ATTR_MAX_IRD | C4IW_QP_ATTR_MAX_ORD; |
| 969 | |
| 970 | /* bind QP and TID with INIT_WR */ |
| 971 | err = c4iw_modify_qp(ep->com.qp->rhp, |
| 972 | ep->com.qp, mask, &attrs, 1); |
| 973 | if (err) |
| 974 | goto err; |
| 975 | goto out; |
| 976 | err: |
Steve Wise | b21ef16 | 2010-06-10 19:02:55 +0000 | [diff] [blame] | 977 | state_set(&ep->com, ABORTING); |
| 978 | send_abort(ep, skb, GFP_KERNEL); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 979 | out: |
| 980 | connect_reply_upcall(ep, err); |
| 981 | return; |
| 982 | } |
| 983 | |
| 984 | static void process_mpa_request(struct c4iw_ep *ep, struct sk_buff *skb) |
| 985 | { |
| 986 | struct mpa_message *mpa; |
| 987 | u16 plen; |
| 988 | |
| 989 | PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid); |
| 990 | |
| 991 | if (state_read(&ep->com) != MPA_REQ_WAIT) |
| 992 | return; |
| 993 | |
| 994 | /* |
| 995 | * If we get more than the supported amount of private data |
| 996 | * then we must fail this connection. |
| 997 | */ |
| 998 | if (ep->mpa_pkt_len + skb->len > sizeof(ep->mpa_pkt)) { |
| 999 | stop_ep_timer(ep); |
| 1000 | abort_connection(ep, skb, GFP_KERNEL); |
| 1001 | return; |
| 1002 | } |
| 1003 | |
| 1004 | PDBG("%s enter (%s line %u)\n", __func__, __FILE__, __LINE__); |
| 1005 | |
| 1006 | /* |
| 1007 | * Copy the new data into our accumulation buffer. |
| 1008 | */ |
| 1009 | skb_copy_from_linear_data(skb, &(ep->mpa_pkt[ep->mpa_pkt_len]), |
| 1010 | skb->len); |
| 1011 | ep->mpa_pkt_len += skb->len; |
| 1012 | |
| 1013 | /* |
| 1014 | * If we don't even have the mpa message, then bail. |
| 1015 | * We'll continue process when more data arrives. |
| 1016 | */ |
| 1017 | if (ep->mpa_pkt_len < sizeof(*mpa)) |
| 1018 | return; |
| 1019 | |
| 1020 | PDBG("%s enter (%s line %u)\n", __func__, __FILE__, __LINE__); |
| 1021 | stop_ep_timer(ep); |
| 1022 | mpa = (struct mpa_message *) ep->mpa_pkt; |
| 1023 | |
| 1024 | /* |
| 1025 | * Validate MPA Header. |
| 1026 | */ |
| 1027 | if (mpa->revision != mpa_rev) { |
| 1028 | abort_connection(ep, skb, GFP_KERNEL); |
| 1029 | return; |
| 1030 | } |
| 1031 | |
| 1032 | if (memcmp(mpa->key, MPA_KEY_REQ, sizeof(mpa->key))) { |
| 1033 | abort_connection(ep, skb, GFP_KERNEL); |
| 1034 | return; |
| 1035 | } |
| 1036 | |
| 1037 | plen = ntohs(mpa->private_data_size); |
| 1038 | |
| 1039 | /* |
| 1040 | * Fail if there's too much private data. |
| 1041 | */ |
| 1042 | if (plen > MPA_MAX_PRIVATE_DATA) { |
| 1043 | abort_connection(ep, skb, GFP_KERNEL); |
| 1044 | return; |
| 1045 | } |
| 1046 | |
| 1047 | /* |
| 1048 | * If plen does not account for pkt size |
| 1049 | */ |
| 1050 | if (ep->mpa_pkt_len > (sizeof(*mpa) + plen)) { |
| 1051 | abort_connection(ep, skb, GFP_KERNEL); |
| 1052 | return; |
| 1053 | } |
| 1054 | ep->plen = (u8) plen; |
| 1055 | |
| 1056 | /* |
| 1057 | * If we don't have all the pdata yet, then bail. |
| 1058 | */ |
| 1059 | if (ep->mpa_pkt_len < (sizeof(*mpa) + plen)) |
| 1060 | return; |
| 1061 | |
| 1062 | /* |
| 1063 | * If we get here we have accumulated the entire mpa |
| 1064 | * start reply message including private data. |
| 1065 | */ |
| 1066 | ep->mpa_attr.initiator = 0; |
| 1067 | ep->mpa_attr.crc_enabled = (mpa->flags & MPA_CRC) | crc_enabled ? 1 : 0; |
| 1068 | ep->mpa_attr.recv_marker_enabled = markers_enabled; |
| 1069 | ep->mpa_attr.xmit_marker_enabled = mpa->flags & MPA_MARKERS ? 1 : 0; |
| 1070 | ep->mpa_attr.version = mpa_rev; |
| 1071 | ep->mpa_attr.p2p_type = peer2peer ? p2p_type : |
| 1072 | FW_RI_INIT_P2PTYPE_DISABLED; |
| 1073 | PDBG("%s - crc_enabled=%d, recv_marker_enabled=%d, " |
| 1074 | "xmit_marker_enabled=%d, version=%d p2p_type=%d\n", __func__, |
| 1075 | ep->mpa_attr.crc_enabled, ep->mpa_attr.recv_marker_enabled, |
| 1076 | ep->mpa_attr.xmit_marker_enabled, ep->mpa_attr.version, |
| 1077 | ep->mpa_attr.p2p_type); |
| 1078 | |
| 1079 | state_set(&ep->com, MPA_REQ_RCVD); |
| 1080 | |
| 1081 | /* drive upcall */ |
| 1082 | connect_request_upcall(ep); |
| 1083 | return; |
| 1084 | } |
| 1085 | |
| 1086 | static int rx_data(struct c4iw_dev *dev, struct sk_buff *skb) |
| 1087 | { |
| 1088 | struct c4iw_ep *ep; |
| 1089 | struct cpl_rx_data *hdr = cplhdr(skb); |
| 1090 | unsigned int dlen = ntohs(hdr->len); |
| 1091 | unsigned int tid = GET_TID(hdr); |
| 1092 | struct tid_info *t = dev->rdev.lldi.tids; |
| 1093 | |
| 1094 | ep = lookup_tid(t, tid); |
| 1095 | PDBG("%s ep %p tid %u dlen %u\n", __func__, ep, ep->hwtid, dlen); |
| 1096 | skb_pull(skb, sizeof(*hdr)); |
| 1097 | skb_trim(skb, dlen); |
| 1098 | |
| 1099 | ep->rcv_seq += dlen; |
| 1100 | BUG_ON(ep->rcv_seq != (ntohl(hdr->seq) + dlen)); |
| 1101 | |
| 1102 | /* update RX credits */ |
| 1103 | update_rx_credits(ep, dlen); |
| 1104 | |
| 1105 | switch (state_read(&ep->com)) { |
| 1106 | case MPA_REQ_SENT: |
| 1107 | process_mpa_reply(ep, skb); |
| 1108 | break; |
| 1109 | case MPA_REQ_WAIT: |
| 1110 | process_mpa_request(ep, skb); |
| 1111 | break; |
| 1112 | case MPA_REP_SENT: |
| 1113 | break; |
| 1114 | default: |
| 1115 | printk(KERN_ERR MOD "%s Unexpected streaming data." |
| 1116 | " ep %p state %d tid %u\n", |
| 1117 | __func__, ep, state_read(&ep->com), ep->hwtid); |
| 1118 | |
| 1119 | /* |
| 1120 | * The ep will timeout and inform the ULP of the failure. |
| 1121 | * See ep_timeout(). |
| 1122 | */ |
| 1123 | break; |
| 1124 | } |
| 1125 | return 0; |
| 1126 | } |
| 1127 | |
| 1128 | static int abort_rpl(struct c4iw_dev *dev, struct sk_buff *skb) |
| 1129 | { |
| 1130 | struct c4iw_ep *ep; |
| 1131 | struct cpl_abort_rpl_rss *rpl = cplhdr(skb); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1132 | int release = 0; |
| 1133 | unsigned int tid = GET_TID(rpl); |
| 1134 | struct tid_info *t = dev->rdev.lldi.tids; |
| 1135 | |
| 1136 | ep = lookup_tid(t, tid); |
| 1137 | PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid); |
| 1138 | BUG_ON(!ep); |
Steve Wise | 2f5b48c | 2010-09-10 11:15:36 -0500 | [diff] [blame] | 1139 | mutex_lock(&ep->com.mutex); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1140 | switch (ep->com.state) { |
| 1141 | case ABORTING: |
| 1142 | __state_set(&ep->com, DEAD); |
| 1143 | release = 1; |
| 1144 | break; |
| 1145 | default: |
| 1146 | printk(KERN_ERR "%s ep %p state %d\n", |
| 1147 | __func__, ep, ep->com.state); |
| 1148 | break; |
| 1149 | } |
Steve Wise | 2f5b48c | 2010-09-10 11:15:36 -0500 | [diff] [blame] | 1150 | mutex_unlock(&ep->com.mutex); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1151 | |
| 1152 | if (release) |
| 1153 | release_ep_resources(ep); |
| 1154 | return 0; |
| 1155 | } |
| 1156 | |
| 1157 | /* |
| 1158 | * Return whether a failed active open has allocated a TID |
| 1159 | */ |
| 1160 | static inline int act_open_has_tid(int status) |
| 1161 | { |
| 1162 | return status != CPL_ERR_TCAM_FULL && status != CPL_ERR_CONN_EXIST && |
| 1163 | status != CPL_ERR_ARP_MISS; |
| 1164 | } |
| 1165 | |
| 1166 | static int act_open_rpl(struct c4iw_dev *dev, struct sk_buff *skb) |
| 1167 | { |
| 1168 | struct c4iw_ep *ep; |
| 1169 | struct cpl_act_open_rpl *rpl = cplhdr(skb); |
| 1170 | unsigned int atid = GET_TID_TID(GET_AOPEN_ATID( |
| 1171 | ntohl(rpl->atid_status))); |
| 1172 | struct tid_info *t = dev->rdev.lldi.tids; |
| 1173 | int status = GET_AOPEN_STATUS(ntohl(rpl->atid_status)); |
| 1174 | |
| 1175 | ep = lookup_atid(t, atid); |
| 1176 | |
| 1177 | PDBG("%s ep %p atid %u status %u errno %d\n", __func__, ep, atid, |
| 1178 | status, status2errno(status)); |
| 1179 | |
| 1180 | if (status == CPL_ERR_RTX_NEG_ADVICE) { |
| 1181 | printk(KERN_WARNING MOD "Connection problems for atid %u\n", |
| 1182 | atid); |
| 1183 | return 0; |
| 1184 | } |
| 1185 | |
| 1186 | connect_reply_upcall(ep, status2errno(status)); |
| 1187 | state_set(&ep->com, DEAD); |
| 1188 | |
| 1189 | if (status && act_open_has_tid(status)) |
| 1190 | cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, GET_TID(rpl)); |
| 1191 | |
| 1192 | cxgb4_free_atid(t, atid); |
| 1193 | dst_release(ep->dst); |
| 1194 | cxgb4_l2t_release(ep->l2t); |
| 1195 | c4iw_put_ep(&ep->com); |
| 1196 | |
| 1197 | return 0; |
| 1198 | } |
| 1199 | |
| 1200 | static int pass_open_rpl(struct c4iw_dev *dev, struct sk_buff *skb) |
| 1201 | { |
| 1202 | struct cpl_pass_open_rpl *rpl = cplhdr(skb); |
| 1203 | struct tid_info *t = dev->rdev.lldi.tids; |
| 1204 | unsigned int stid = GET_TID(rpl); |
| 1205 | struct c4iw_listen_ep *ep = lookup_stid(t, stid); |
| 1206 | |
| 1207 | if (!ep) { |
| 1208 | printk(KERN_ERR MOD "stid %d lookup failure!\n", stid); |
| 1209 | return 0; |
| 1210 | } |
| 1211 | PDBG("%s ep %p status %d error %d\n", __func__, ep, |
| 1212 | rpl->status, status2errno(rpl->status)); |
Steve Wise | aadc4df | 2010-09-10 11:15:25 -0500 | [diff] [blame] | 1213 | ep->com.wr_wait.ret = status2errno(rpl->status); |
| 1214 | ep->com.wr_wait.done = 1; |
| 1215 | wake_up(&ep->com.wr_wait.wait); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1216 | |
| 1217 | return 0; |
| 1218 | } |
| 1219 | |
| 1220 | static int listen_stop(struct c4iw_listen_ep *ep) |
| 1221 | { |
| 1222 | struct sk_buff *skb; |
| 1223 | struct cpl_close_listsvr_req *req; |
| 1224 | |
| 1225 | PDBG("%s ep %p\n", __func__, ep); |
| 1226 | skb = get_skb(NULL, sizeof(*req), GFP_KERNEL); |
| 1227 | if (!skb) { |
| 1228 | printk(KERN_ERR MOD "%s - failed to alloc skb\n", __func__); |
| 1229 | return -ENOMEM; |
| 1230 | } |
| 1231 | req = (struct cpl_close_listsvr_req *) skb_put(skb, sizeof(*req)); |
| 1232 | INIT_TP_WR(req, 0); |
| 1233 | OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_CLOSE_LISTSRV_REQ, |
| 1234 | ep->stid)); |
| 1235 | req->reply_ctrl = cpu_to_be16( |
| 1236 | QUEUENO(ep->com.dev->rdev.lldi.rxq_ids[0])); |
| 1237 | set_wr_txq(skb, CPL_PRIORITY_SETUP, 0); |
| 1238 | return c4iw_ofld_send(&ep->com.dev->rdev, skb); |
| 1239 | } |
| 1240 | |
| 1241 | static int close_listsrv_rpl(struct c4iw_dev *dev, struct sk_buff *skb) |
| 1242 | { |
| 1243 | struct cpl_close_listsvr_rpl *rpl = cplhdr(skb); |
| 1244 | struct tid_info *t = dev->rdev.lldi.tids; |
| 1245 | unsigned int stid = GET_TID(rpl); |
| 1246 | struct c4iw_listen_ep *ep = lookup_stid(t, stid); |
| 1247 | |
| 1248 | PDBG("%s ep %p\n", __func__, ep); |
Steve Wise | aadc4df | 2010-09-10 11:15:25 -0500 | [diff] [blame] | 1249 | ep->com.wr_wait.ret = status2errno(rpl->status); |
| 1250 | ep->com.wr_wait.done = 1; |
| 1251 | wake_up(&ep->com.wr_wait.wait); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1252 | return 0; |
| 1253 | } |
| 1254 | |
| 1255 | static void accept_cr(struct c4iw_ep *ep, __be32 peer_ip, struct sk_buff *skb, |
| 1256 | struct cpl_pass_accept_req *req) |
| 1257 | { |
| 1258 | struct cpl_pass_accept_rpl *rpl; |
| 1259 | unsigned int mtu_idx; |
| 1260 | u64 opt0; |
| 1261 | u32 opt2; |
| 1262 | int wscale; |
| 1263 | |
| 1264 | PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid); |
| 1265 | BUG_ON(skb_cloned(skb)); |
| 1266 | skb_trim(skb, sizeof(*rpl)); |
| 1267 | skb_get(skb); |
| 1268 | cxgb4_best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx); |
| 1269 | wscale = compute_wscale(rcv_win); |
| 1270 | opt0 = KEEP_ALIVE(1) | |
Steve Wise | ba6d392 | 2010-06-23 15:46:49 +0000 | [diff] [blame] | 1271 | DELACK(1) | |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1272 | WND_SCALE(wscale) | |
| 1273 | MSS_IDX(mtu_idx) | |
| 1274 | L2T_IDX(ep->l2t->idx) | |
| 1275 | TX_CHAN(ep->tx_chan) | |
| 1276 | SMAC_SEL(ep->smac_idx) | |
| 1277 | DSCP(ep->tos) | |
| 1278 | RCV_BUFSIZ(rcv_win>>10); |
| 1279 | opt2 = RX_CHANNEL(0) | |
| 1280 | RSS_QUEUE_VALID | RSS_QUEUE(ep->rss_qid); |
| 1281 | |
| 1282 | if (enable_tcp_timestamps && req->tcpopt.tstamp) |
| 1283 | opt2 |= TSTAMPS_EN(1); |
| 1284 | if (enable_tcp_sack && req->tcpopt.sack) |
| 1285 | opt2 |= SACK_EN(1); |
| 1286 | if (wscale && enable_tcp_window_scaling) |
| 1287 | opt2 |= WND_SCALE_EN(1); |
| 1288 | |
| 1289 | rpl = cplhdr(skb); |
| 1290 | INIT_TP_WR(rpl, ep->hwtid); |
| 1291 | OPCODE_TID(rpl) = cpu_to_be32(MK_OPCODE_TID(CPL_PASS_ACCEPT_RPL, |
| 1292 | ep->hwtid)); |
| 1293 | rpl->opt0 = cpu_to_be64(opt0); |
| 1294 | rpl->opt2 = cpu_to_be32(opt2); |
Steve Wise | d4f1a5c | 2010-07-23 19:12:32 +0000 | [diff] [blame] | 1295 | set_wr_txq(skb, CPL_PRIORITY_SETUP, ep->ctrlq_idx); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1296 | c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t); |
| 1297 | |
| 1298 | return; |
| 1299 | } |
| 1300 | |
| 1301 | static void reject_cr(struct c4iw_dev *dev, u32 hwtid, __be32 peer_ip, |
| 1302 | struct sk_buff *skb) |
| 1303 | { |
| 1304 | PDBG("%s c4iw_dev %p tid %u peer_ip %x\n", __func__, dev, hwtid, |
| 1305 | peer_ip); |
| 1306 | BUG_ON(skb_cloned(skb)); |
| 1307 | skb_trim(skb, sizeof(struct cpl_tid_release)); |
| 1308 | skb_get(skb); |
| 1309 | release_tid(&dev->rdev, hwtid, skb); |
| 1310 | return; |
| 1311 | } |
| 1312 | |
| 1313 | static void get_4tuple(struct cpl_pass_accept_req *req, |
| 1314 | __be32 *local_ip, __be32 *peer_ip, |
| 1315 | __be16 *local_port, __be16 *peer_port) |
| 1316 | { |
| 1317 | int eth_len = G_ETH_HDR_LEN(be32_to_cpu(req->hdr_len)); |
| 1318 | int ip_len = G_IP_HDR_LEN(be32_to_cpu(req->hdr_len)); |
| 1319 | struct iphdr *ip = (struct iphdr *)((u8 *)(req + 1) + eth_len); |
| 1320 | struct tcphdr *tcp = (struct tcphdr *) |
| 1321 | ((u8 *)(req + 1) + eth_len + ip_len); |
| 1322 | |
| 1323 | PDBG("%s saddr 0x%x daddr 0x%x sport %u dport %u\n", __func__, |
| 1324 | ntohl(ip->saddr), ntohl(ip->daddr), ntohs(tcp->source), |
| 1325 | ntohs(tcp->dest)); |
| 1326 | |
| 1327 | *peer_ip = ip->saddr; |
| 1328 | *local_ip = ip->daddr; |
| 1329 | *peer_port = tcp->source; |
| 1330 | *local_port = tcp->dest; |
| 1331 | |
| 1332 | return; |
| 1333 | } |
| 1334 | |
| 1335 | static int pass_accept_req(struct c4iw_dev *dev, struct sk_buff *skb) |
| 1336 | { |
| 1337 | struct c4iw_ep *child_ep, *parent_ep; |
| 1338 | struct cpl_pass_accept_req *req = cplhdr(skb); |
| 1339 | unsigned int stid = GET_POPEN_TID(ntohl(req->tos_stid)); |
| 1340 | struct tid_info *t = dev->rdev.lldi.tids; |
| 1341 | unsigned int hwtid = GET_TID(req); |
| 1342 | struct dst_entry *dst; |
| 1343 | struct l2t_entry *l2t; |
| 1344 | struct rtable *rt; |
| 1345 | __be32 local_ip, peer_ip; |
| 1346 | __be16 local_port, peer_port; |
| 1347 | struct net_device *pdev; |
| 1348 | u32 tx_chan, smac_idx; |
| 1349 | u16 rss_qid; |
| 1350 | u32 mtu; |
| 1351 | int step; |
Steve Wise | d4f1a5c | 2010-07-23 19:12:32 +0000 | [diff] [blame] | 1352 | int txq_idx, ctrlq_idx; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1353 | |
| 1354 | parent_ep = lookup_stid(t, stid); |
| 1355 | PDBG("%s parent ep %p tid %u\n", __func__, parent_ep, hwtid); |
| 1356 | |
| 1357 | get_4tuple(req, &local_ip, &peer_ip, &local_port, &peer_port); |
| 1358 | |
| 1359 | if (state_read(&parent_ep->com) != LISTEN) { |
| 1360 | printk(KERN_ERR "%s - listening ep not in LISTEN\n", |
| 1361 | __func__); |
| 1362 | goto reject; |
| 1363 | } |
| 1364 | |
| 1365 | /* Find output route */ |
| 1366 | rt = find_route(dev, local_ip, peer_ip, local_port, peer_port, |
| 1367 | GET_POPEN_TOS(ntohl(req->tos_stid))); |
| 1368 | if (!rt) { |
| 1369 | printk(KERN_ERR MOD "%s - failed to find dst entry!\n", |
| 1370 | __func__); |
| 1371 | goto reject; |
| 1372 | } |
Changli Gao | d8d1f30 | 2010-06-10 23:31:35 -0700 | [diff] [blame] | 1373 | dst = &rt->dst; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1374 | if (dst->neighbour->dev->flags & IFF_LOOPBACK) { |
| 1375 | pdev = ip_dev_find(&init_net, peer_ip); |
| 1376 | BUG_ON(!pdev); |
| 1377 | l2t = cxgb4_l2t_get(dev->rdev.lldi.l2t, dst->neighbour, |
| 1378 | pdev, 0); |
| 1379 | mtu = pdev->mtu; |
| 1380 | tx_chan = cxgb4_port_chan(pdev); |
Steve Wise | 2c5934b | 2010-06-23 15:46:44 +0000 | [diff] [blame] | 1381 | smac_idx = (cxgb4_port_viid(pdev) & 0x7F) << 1; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1382 | step = dev->rdev.lldi.ntxq / dev->rdev.lldi.nchan; |
| 1383 | txq_idx = cxgb4_port_idx(pdev) * step; |
Steve Wise | d4f1a5c | 2010-07-23 19:12:32 +0000 | [diff] [blame] | 1384 | ctrlq_idx = cxgb4_port_idx(pdev); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1385 | step = dev->rdev.lldi.nrxq / dev->rdev.lldi.nchan; |
| 1386 | rss_qid = dev->rdev.lldi.rxq_ids[cxgb4_port_idx(pdev) * step]; |
| 1387 | dev_put(pdev); |
| 1388 | } else { |
| 1389 | l2t = cxgb4_l2t_get(dev->rdev.lldi.l2t, dst->neighbour, |
| 1390 | dst->neighbour->dev, 0); |
| 1391 | mtu = dst_mtu(dst); |
| 1392 | tx_chan = cxgb4_port_chan(dst->neighbour->dev); |
Steve Wise | 2c5934b | 2010-06-23 15:46:44 +0000 | [diff] [blame] | 1393 | smac_idx = (cxgb4_port_viid(dst->neighbour->dev) & 0x7F) << 1; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1394 | step = dev->rdev.lldi.ntxq / dev->rdev.lldi.nchan; |
| 1395 | txq_idx = cxgb4_port_idx(dst->neighbour->dev) * step; |
Steve Wise | d4f1a5c | 2010-07-23 19:12:32 +0000 | [diff] [blame] | 1396 | ctrlq_idx = cxgb4_port_idx(dst->neighbour->dev); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1397 | step = dev->rdev.lldi.nrxq / dev->rdev.lldi.nchan; |
| 1398 | rss_qid = dev->rdev.lldi.rxq_ids[ |
| 1399 | cxgb4_port_idx(dst->neighbour->dev) * step]; |
| 1400 | } |
| 1401 | if (!l2t) { |
| 1402 | printk(KERN_ERR MOD "%s - failed to allocate l2t entry!\n", |
| 1403 | __func__); |
| 1404 | dst_release(dst); |
| 1405 | goto reject; |
| 1406 | } |
| 1407 | |
| 1408 | child_ep = alloc_ep(sizeof(*child_ep), GFP_KERNEL); |
| 1409 | if (!child_ep) { |
| 1410 | printk(KERN_ERR MOD "%s - failed to allocate ep entry!\n", |
| 1411 | __func__); |
| 1412 | cxgb4_l2t_release(l2t); |
| 1413 | dst_release(dst); |
| 1414 | goto reject; |
| 1415 | } |
| 1416 | state_set(&child_ep->com, CONNECTING); |
| 1417 | child_ep->com.dev = dev; |
| 1418 | child_ep->com.cm_id = NULL; |
| 1419 | child_ep->com.local_addr.sin_family = PF_INET; |
| 1420 | child_ep->com.local_addr.sin_port = local_port; |
| 1421 | child_ep->com.local_addr.sin_addr.s_addr = local_ip; |
| 1422 | child_ep->com.remote_addr.sin_family = PF_INET; |
| 1423 | child_ep->com.remote_addr.sin_port = peer_port; |
| 1424 | child_ep->com.remote_addr.sin_addr.s_addr = peer_ip; |
| 1425 | c4iw_get_ep(&parent_ep->com); |
| 1426 | child_ep->parent_ep = parent_ep; |
| 1427 | child_ep->tos = GET_POPEN_TOS(ntohl(req->tos_stid)); |
| 1428 | child_ep->l2t = l2t; |
| 1429 | child_ep->dst = dst; |
| 1430 | child_ep->hwtid = hwtid; |
| 1431 | child_ep->tx_chan = tx_chan; |
| 1432 | child_ep->smac_idx = smac_idx; |
| 1433 | child_ep->rss_qid = rss_qid; |
| 1434 | child_ep->mtu = mtu; |
| 1435 | child_ep->txq_idx = txq_idx; |
Steve Wise | d4f1a5c | 2010-07-23 19:12:32 +0000 | [diff] [blame] | 1436 | child_ep->ctrlq_idx = ctrlq_idx; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1437 | |
| 1438 | PDBG("%s tx_chan %u smac_idx %u rss_qid %u\n", __func__, |
| 1439 | tx_chan, smac_idx, rss_qid); |
| 1440 | |
| 1441 | init_timer(&child_ep->timer); |
| 1442 | cxgb4_insert_tid(t, child_ep, hwtid); |
| 1443 | accept_cr(child_ep, peer_ip, skb, req); |
| 1444 | goto out; |
| 1445 | reject: |
| 1446 | reject_cr(dev, hwtid, peer_ip, skb); |
| 1447 | out: |
| 1448 | return 0; |
| 1449 | } |
| 1450 | |
| 1451 | static int pass_establish(struct c4iw_dev *dev, struct sk_buff *skb) |
| 1452 | { |
| 1453 | struct c4iw_ep *ep; |
| 1454 | struct cpl_pass_establish *req = cplhdr(skb); |
| 1455 | struct tid_info *t = dev->rdev.lldi.tids; |
| 1456 | unsigned int tid = GET_TID(req); |
| 1457 | |
| 1458 | ep = lookup_tid(t, tid); |
| 1459 | PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid); |
| 1460 | ep->snd_seq = be32_to_cpu(req->snd_isn); |
| 1461 | ep->rcv_seq = be32_to_cpu(req->rcv_isn); |
| 1462 | |
| 1463 | set_emss(ep, ntohs(req->tcp_opt)); |
| 1464 | |
| 1465 | dst_confirm(ep->dst); |
| 1466 | state_set(&ep->com, MPA_REQ_WAIT); |
| 1467 | start_ep_timer(ep); |
| 1468 | send_flowc(ep, skb); |
| 1469 | |
| 1470 | return 0; |
| 1471 | } |
| 1472 | |
| 1473 | static int peer_close(struct c4iw_dev *dev, struct sk_buff *skb) |
| 1474 | { |
| 1475 | struct cpl_peer_close *hdr = cplhdr(skb); |
| 1476 | struct c4iw_ep *ep; |
| 1477 | struct c4iw_qp_attributes attrs; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1478 | int disconnect = 1; |
| 1479 | int release = 0; |
| 1480 | int closing = 0; |
| 1481 | struct tid_info *t = dev->rdev.lldi.tids; |
| 1482 | unsigned int tid = GET_TID(hdr); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1483 | |
| 1484 | ep = lookup_tid(t, tid); |
| 1485 | PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid); |
| 1486 | dst_confirm(ep->dst); |
| 1487 | |
Steve Wise | 2f5b48c | 2010-09-10 11:15:36 -0500 | [diff] [blame] | 1488 | mutex_lock(&ep->com.mutex); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1489 | switch (ep->com.state) { |
| 1490 | case MPA_REQ_WAIT: |
| 1491 | __state_set(&ep->com, CLOSING); |
| 1492 | break; |
| 1493 | case MPA_REQ_SENT: |
| 1494 | __state_set(&ep->com, CLOSING); |
| 1495 | connect_reply_upcall(ep, -ECONNRESET); |
| 1496 | break; |
| 1497 | case MPA_REQ_RCVD: |
| 1498 | |
| 1499 | /* |
| 1500 | * We're gonna mark this puppy DEAD, but keep |
| 1501 | * the reference on it until the ULP accepts or |
| 1502 | * rejects the CR. Also wake up anyone waiting |
| 1503 | * in rdma connection migration (see c4iw_accept_cr()). |
| 1504 | */ |
| 1505 | __state_set(&ep->com, CLOSING); |
Steve Wise | aadc4df | 2010-09-10 11:15:25 -0500 | [diff] [blame] | 1506 | ep->com.wr_wait.done = 1; |
| 1507 | ep->com.wr_wait.ret = -ECONNRESET; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1508 | PDBG("waking up ep %p tid %u\n", ep, ep->hwtid); |
Steve Wise | aadc4df | 2010-09-10 11:15:25 -0500 | [diff] [blame] | 1509 | wake_up(&ep->com.wr_wait.wait); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1510 | break; |
| 1511 | case MPA_REP_SENT: |
| 1512 | __state_set(&ep->com, CLOSING); |
Steve Wise | aadc4df | 2010-09-10 11:15:25 -0500 | [diff] [blame] | 1513 | ep->com.wr_wait.done = 1; |
| 1514 | ep->com.wr_wait.ret = -ECONNRESET; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1515 | PDBG("waking up ep %p tid %u\n", ep, ep->hwtid); |
Steve Wise | aadc4df | 2010-09-10 11:15:25 -0500 | [diff] [blame] | 1516 | wake_up(&ep->com.wr_wait.wait); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1517 | break; |
| 1518 | case FPDU_MODE: |
Steve Wise | ca5a220 | 2010-07-23 19:12:37 +0000 | [diff] [blame] | 1519 | start_ep_timer(ep); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1520 | __state_set(&ep->com, CLOSING); |
| 1521 | closing = 1; |
| 1522 | peer_close_upcall(ep); |
| 1523 | break; |
| 1524 | case ABORTING: |
| 1525 | disconnect = 0; |
| 1526 | break; |
| 1527 | case CLOSING: |
| 1528 | __state_set(&ep->com, MORIBUND); |
| 1529 | disconnect = 0; |
| 1530 | break; |
| 1531 | case MORIBUND: |
Steve Wise | ca5a220 | 2010-07-23 19:12:37 +0000 | [diff] [blame] | 1532 | stop_ep_timer(ep); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1533 | if (ep->com.cm_id && ep->com.qp) { |
| 1534 | attrs.next_state = C4IW_QP_STATE_IDLE; |
| 1535 | c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp, |
| 1536 | C4IW_QP_ATTR_NEXT_STATE, &attrs, 1); |
| 1537 | } |
| 1538 | close_complete_upcall(ep); |
| 1539 | __state_set(&ep->com, DEAD); |
| 1540 | release = 1; |
| 1541 | disconnect = 0; |
| 1542 | break; |
| 1543 | case DEAD: |
| 1544 | disconnect = 0; |
| 1545 | break; |
| 1546 | default: |
| 1547 | BUG_ON(1); |
| 1548 | } |
Steve Wise | 2f5b48c | 2010-09-10 11:15:36 -0500 | [diff] [blame] | 1549 | mutex_unlock(&ep->com.mutex); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1550 | if (closing) { |
| 1551 | attrs.next_state = C4IW_QP_STATE_CLOSING; |
| 1552 | c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp, |
| 1553 | C4IW_QP_ATTR_NEXT_STATE, &attrs, 1); |
| 1554 | } |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1555 | if (disconnect) |
| 1556 | c4iw_ep_disconnect(ep, 0, GFP_KERNEL); |
| 1557 | if (release) |
| 1558 | release_ep_resources(ep); |
| 1559 | return 0; |
| 1560 | } |
| 1561 | |
| 1562 | /* |
| 1563 | * Returns whether an ABORT_REQ_RSS message is a negative advice. |
| 1564 | */ |
| 1565 | static int is_neg_adv_abort(unsigned int status) |
| 1566 | { |
| 1567 | return status == CPL_ERR_RTX_NEG_ADVICE || |
| 1568 | status == CPL_ERR_PERSIST_NEG_ADVICE; |
| 1569 | } |
| 1570 | |
| 1571 | static int peer_abort(struct c4iw_dev *dev, struct sk_buff *skb) |
| 1572 | { |
| 1573 | struct cpl_abort_req_rss *req = cplhdr(skb); |
| 1574 | struct c4iw_ep *ep; |
| 1575 | struct cpl_abort_rpl *rpl; |
| 1576 | struct sk_buff *rpl_skb; |
| 1577 | struct c4iw_qp_attributes attrs; |
| 1578 | int ret; |
| 1579 | int release = 0; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1580 | struct tid_info *t = dev->rdev.lldi.tids; |
| 1581 | unsigned int tid = GET_TID(req); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1582 | |
| 1583 | ep = lookup_tid(t, tid); |
| 1584 | if (is_neg_adv_abort(req->status)) { |
| 1585 | PDBG("%s neg_adv_abort ep %p tid %u\n", __func__, ep, |
| 1586 | ep->hwtid); |
| 1587 | return 0; |
| 1588 | } |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1589 | PDBG("%s ep %p tid %u state %u\n", __func__, ep, ep->hwtid, |
| 1590 | ep->com.state); |
Steve Wise | 2f5b48c | 2010-09-10 11:15:36 -0500 | [diff] [blame] | 1591 | |
| 1592 | /* |
| 1593 | * Wake up any threads in rdma_init() or rdma_fini(). |
| 1594 | */ |
| 1595 | ep->com.wr_wait.done = 1; |
| 1596 | ep->com.wr_wait.ret = -ECONNRESET; |
| 1597 | wake_up(&ep->com.wr_wait.wait); |
| 1598 | |
| 1599 | mutex_lock(&ep->com.mutex); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1600 | switch (ep->com.state) { |
| 1601 | case CONNECTING: |
| 1602 | break; |
| 1603 | case MPA_REQ_WAIT: |
Steve Wise | ca5a220 | 2010-07-23 19:12:37 +0000 | [diff] [blame] | 1604 | stop_ep_timer(ep); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1605 | break; |
| 1606 | case MPA_REQ_SENT: |
Steve Wise | ca5a220 | 2010-07-23 19:12:37 +0000 | [diff] [blame] | 1607 | stop_ep_timer(ep); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1608 | connect_reply_upcall(ep, -ECONNRESET); |
| 1609 | break; |
| 1610 | case MPA_REP_SENT: |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1611 | break; |
| 1612 | case MPA_REQ_RCVD: |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1613 | break; |
| 1614 | case MORIBUND: |
| 1615 | case CLOSING: |
Steve Wise | ca5a220 | 2010-07-23 19:12:37 +0000 | [diff] [blame] | 1616 | stop_ep_timer(ep); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1617 | /*FALLTHROUGH*/ |
| 1618 | case FPDU_MODE: |
| 1619 | if (ep->com.cm_id && ep->com.qp) { |
| 1620 | attrs.next_state = C4IW_QP_STATE_ERROR; |
| 1621 | ret = c4iw_modify_qp(ep->com.qp->rhp, |
| 1622 | ep->com.qp, C4IW_QP_ATTR_NEXT_STATE, |
| 1623 | &attrs, 1); |
| 1624 | if (ret) |
| 1625 | printk(KERN_ERR MOD |
| 1626 | "%s - qp <- error failed!\n", |
| 1627 | __func__); |
| 1628 | } |
| 1629 | peer_abort_upcall(ep); |
| 1630 | break; |
| 1631 | case ABORTING: |
| 1632 | break; |
| 1633 | case DEAD: |
| 1634 | PDBG("%s PEER_ABORT IN DEAD STATE!!!!\n", __func__); |
Steve Wise | 2f5b48c | 2010-09-10 11:15:36 -0500 | [diff] [blame] | 1635 | mutex_unlock(&ep->com.mutex); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1636 | return 0; |
| 1637 | default: |
| 1638 | BUG_ON(1); |
| 1639 | break; |
| 1640 | } |
| 1641 | dst_confirm(ep->dst); |
| 1642 | if (ep->com.state != ABORTING) { |
| 1643 | __state_set(&ep->com, DEAD); |
| 1644 | release = 1; |
| 1645 | } |
Steve Wise | 2f5b48c | 2010-09-10 11:15:36 -0500 | [diff] [blame] | 1646 | mutex_unlock(&ep->com.mutex); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1647 | |
| 1648 | rpl_skb = get_skb(skb, sizeof(*rpl), GFP_KERNEL); |
| 1649 | if (!rpl_skb) { |
| 1650 | printk(KERN_ERR MOD "%s - cannot allocate skb!\n", |
| 1651 | __func__); |
| 1652 | release = 1; |
| 1653 | goto out; |
| 1654 | } |
| 1655 | set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx); |
| 1656 | rpl = (struct cpl_abort_rpl *) skb_put(rpl_skb, sizeof(*rpl)); |
| 1657 | INIT_TP_WR(rpl, ep->hwtid); |
| 1658 | OPCODE_TID(rpl) = cpu_to_be32(MK_OPCODE_TID(CPL_ABORT_RPL, ep->hwtid)); |
| 1659 | rpl->cmd = CPL_ABORT_NO_RST; |
| 1660 | c4iw_ofld_send(&ep->com.dev->rdev, rpl_skb); |
| 1661 | out: |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1662 | if (release) |
| 1663 | release_ep_resources(ep); |
| 1664 | return 0; |
| 1665 | } |
| 1666 | |
| 1667 | static int close_con_rpl(struct c4iw_dev *dev, struct sk_buff *skb) |
| 1668 | { |
| 1669 | struct c4iw_ep *ep; |
| 1670 | struct c4iw_qp_attributes attrs; |
| 1671 | struct cpl_close_con_rpl *rpl = cplhdr(skb); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1672 | int release = 0; |
| 1673 | struct tid_info *t = dev->rdev.lldi.tids; |
| 1674 | unsigned int tid = GET_TID(rpl); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1675 | |
| 1676 | ep = lookup_tid(t, tid); |
| 1677 | |
| 1678 | PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid); |
| 1679 | BUG_ON(!ep); |
| 1680 | |
| 1681 | /* The cm_id may be null if we failed to connect */ |
Steve Wise | 2f5b48c | 2010-09-10 11:15:36 -0500 | [diff] [blame] | 1682 | mutex_lock(&ep->com.mutex); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1683 | switch (ep->com.state) { |
| 1684 | case CLOSING: |
| 1685 | __state_set(&ep->com, MORIBUND); |
| 1686 | break; |
| 1687 | case MORIBUND: |
Steve Wise | ca5a220 | 2010-07-23 19:12:37 +0000 | [diff] [blame] | 1688 | stop_ep_timer(ep); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1689 | if ((ep->com.cm_id) && (ep->com.qp)) { |
| 1690 | attrs.next_state = C4IW_QP_STATE_IDLE; |
| 1691 | c4iw_modify_qp(ep->com.qp->rhp, |
| 1692 | ep->com.qp, |
| 1693 | C4IW_QP_ATTR_NEXT_STATE, |
| 1694 | &attrs, 1); |
| 1695 | } |
| 1696 | close_complete_upcall(ep); |
| 1697 | __state_set(&ep->com, DEAD); |
| 1698 | release = 1; |
| 1699 | break; |
| 1700 | case ABORTING: |
| 1701 | case DEAD: |
| 1702 | break; |
| 1703 | default: |
| 1704 | BUG_ON(1); |
| 1705 | break; |
| 1706 | } |
Steve Wise | 2f5b48c | 2010-09-10 11:15:36 -0500 | [diff] [blame] | 1707 | mutex_unlock(&ep->com.mutex); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1708 | if (release) |
| 1709 | release_ep_resources(ep); |
| 1710 | return 0; |
| 1711 | } |
| 1712 | |
| 1713 | static int terminate(struct c4iw_dev *dev, struct sk_buff *skb) |
| 1714 | { |
Steve Wise | 0e42c1f | 2010-09-10 11:15:09 -0500 | [diff] [blame] | 1715 | struct cpl_rdma_terminate *rpl = cplhdr(skb); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1716 | struct tid_info *t = dev->rdev.lldi.tids; |
Steve Wise | 0e42c1f | 2010-09-10 11:15:09 -0500 | [diff] [blame] | 1717 | unsigned int tid = GET_TID(rpl); |
| 1718 | struct c4iw_ep *ep; |
| 1719 | struct c4iw_qp_attributes attrs; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1720 | |
| 1721 | ep = lookup_tid(t, tid); |
Steve Wise | 0e42c1f | 2010-09-10 11:15:09 -0500 | [diff] [blame] | 1722 | BUG_ON(!ep); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1723 | |
Steve Wise | 0e42c1f | 2010-09-10 11:15:09 -0500 | [diff] [blame] | 1724 | if (ep->com.qp) { |
| 1725 | printk(KERN_WARNING MOD "TERM received tid %u qpid %u\n", tid, |
| 1726 | ep->com.qp->wq.sq.qid); |
| 1727 | attrs.next_state = C4IW_QP_STATE_TERMINATE; |
| 1728 | c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp, |
| 1729 | C4IW_QP_ATTR_NEXT_STATE, &attrs, 1); |
| 1730 | } else |
| 1731 | printk(KERN_WARNING MOD "TERM received tid %u no qp\n", tid); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1732 | |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1733 | return 0; |
| 1734 | } |
| 1735 | |
| 1736 | /* |
| 1737 | * Upcall from the adapter indicating data has been transmitted. |
| 1738 | * For us its just the single MPA request or reply. We can now free |
| 1739 | * the skb holding the mpa message. |
| 1740 | */ |
| 1741 | static int fw4_ack(struct c4iw_dev *dev, struct sk_buff *skb) |
| 1742 | { |
| 1743 | struct c4iw_ep *ep; |
| 1744 | struct cpl_fw4_ack *hdr = cplhdr(skb); |
| 1745 | u8 credits = hdr->credits; |
| 1746 | unsigned int tid = GET_TID(hdr); |
| 1747 | struct tid_info *t = dev->rdev.lldi.tids; |
| 1748 | |
| 1749 | |
| 1750 | ep = lookup_tid(t, tid); |
| 1751 | PDBG("%s ep %p tid %u credits %u\n", __func__, ep, ep->hwtid, credits); |
| 1752 | if (credits == 0) { |
Joe Perches | aa1ad26 | 2010-10-25 19:44:22 -0700 | [diff] [blame] | 1753 | PDBG("%s 0 credit ack ep %p tid %u state %u\n", |
| 1754 | __func__, ep, ep->hwtid, state_read(&ep->com)); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1755 | return 0; |
| 1756 | } |
| 1757 | |
| 1758 | dst_confirm(ep->dst); |
| 1759 | if (ep->mpa_skb) { |
| 1760 | PDBG("%s last streaming msg ack ep %p tid %u state %u " |
| 1761 | "initiator %u freeing skb\n", __func__, ep, ep->hwtid, |
| 1762 | state_read(&ep->com), ep->mpa_attr.initiator ? 1 : 0); |
| 1763 | kfree_skb(ep->mpa_skb); |
| 1764 | ep->mpa_skb = NULL; |
| 1765 | } |
| 1766 | return 0; |
| 1767 | } |
| 1768 | |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1769 | int c4iw_reject_cr(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len) |
| 1770 | { |
| 1771 | int err; |
| 1772 | struct c4iw_ep *ep = to_ep(cm_id); |
| 1773 | PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid); |
| 1774 | |
| 1775 | if (state_read(&ep->com) == DEAD) { |
| 1776 | c4iw_put_ep(&ep->com); |
| 1777 | return -ECONNRESET; |
| 1778 | } |
| 1779 | BUG_ON(state_read(&ep->com) != MPA_REQ_RCVD); |
| 1780 | if (mpa_rev == 0) |
| 1781 | abort_connection(ep, NULL, GFP_KERNEL); |
| 1782 | else { |
| 1783 | err = send_mpa_reject(ep, pdata, pdata_len); |
| 1784 | err = c4iw_ep_disconnect(ep, 0, GFP_KERNEL); |
| 1785 | } |
| 1786 | c4iw_put_ep(&ep->com); |
| 1787 | return 0; |
| 1788 | } |
| 1789 | |
| 1790 | int c4iw_accept_cr(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param) |
| 1791 | { |
| 1792 | int err; |
| 1793 | struct c4iw_qp_attributes attrs; |
| 1794 | enum c4iw_qp_attr_mask mask; |
| 1795 | struct c4iw_ep *ep = to_ep(cm_id); |
| 1796 | struct c4iw_dev *h = to_c4iw_dev(cm_id->device); |
| 1797 | struct c4iw_qp *qp = get_qhp(h, conn_param->qpn); |
| 1798 | |
| 1799 | PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid); |
| 1800 | if (state_read(&ep->com) == DEAD) { |
| 1801 | err = -ECONNRESET; |
| 1802 | goto err; |
| 1803 | } |
| 1804 | |
| 1805 | BUG_ON(state_read(&ep->com) != MPA_REQ_RCVD); |
| 1806 | BUG_ON(!qp); |
| 1807 | |
Roland Dreier | be4c9ba | 2010-05-05 14:45:40 -0700 | [diff] [blame] | 1808 | if ((conn_param->ord > c4iw_max_read_depth) || |
| 1809 | (conn_param->ird > c4iw_max_read_depth)) { |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1810 | abort_connection(ep, NULL, GFP_KERNEL); |
| 1811 | err = -EINVAL; |
| 1812 | goto err; |
| 1813 | } |
| 1814 | |
| 1815 | cm_id->add_ref(cm_id); |
| 1816 | ep->com.cm_id = cm_id; |
| 1817 | ep->com.qp = qp; |
| 1818 | |
| 1819 | ep->ird = conn_param->ird; |
| 1820 | ep->ord = conn_param->ord; |
| 1821 | |
| 1822 | if (peer2peer && ep->ird == 0) |
| 1823 | ep->ird = 1; |
| 1824 | |
| 1825 | PDBG("%s %d ird %d ord %d\n", __func__, __LINE__, ep->ird, ep->ord); |
| 1826 | |
| 1827 | /* bind QP to EP and move to RTS */ |
| 1828 | attrs.mpa_attr = ep->mpa_attr; |
| 1829 | attrs.max_ird = ep->ird; |
| 1830 | attrs.max_ord = ep->ord; |
| 1831 | attrs.llp_stream_handle = ep; |
| 1832 | attrs.next_state = C4IW_QP_STATE_RTS; |
| 1833 | |
| 1834 | /* bind QP and TID with INIT_WR */ |
| 1835 | mask = C4IW_QP_ATTR_NEXT_STATE | |
| 1836 | C4IW_QP_ATTR_LLP_STREAM_HANDLE | |
| 1837 | C4IW_QP_ATTR_MPA_ATTR | |
| 1838 | C4IW_QP_ATTR_MAX_IRD | |
| 1839 | C4IW_QP_ATTR_MAX_ORD; |
| 1840 | |
| 1841 | err = c4iw_modify_qp(ep->com.qp->rhp, |
| 1842 | ep->com.qp, mask, &attrs, 1); |
| 1843 | if (err) |
| 1844 | goto err1; |
| 1845 | err = send_mpa_reply(ep, conn_param->private_data, |
| 1846 | conn_param->private_data_len); |
| 1847 | if (err) |
| 1848 | goto err1; |
| 1849 | |
| 1850 | state_set(&ep->com, FPDU_MODE); |
| 1851 | established_upcall(ep); |
| 1852 | c4iw_put_ep(&ep->com); |
| 1853 | return 0; |
| 1854 | err1: |
| 1855 | ep->com.cm_id = NULL; |
| 1856 | ep->com.qp = NULL; |
| 1857 | cm_id->rem_ref(cm_id); |
| 1858 | err: |
| 1859 | c4iw_put_ep(&ep->com); |
| 1860 | return err; |
| 1861 | } |
| 1862 | |
| 1863 | int c4iw_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param) |
| 1864 | { |
| 1865 | int err = 0; |
| 1866 | struct c4iw_dev *dev = to_c4iw_dev(cm_id->device); |
| 1867 | struct c4iw_ep *ep; |
| 1868 | struct rtable *rt; |
| 1869 | struct net_device *pdev; |
| 1870 | int step; |
| 1871 | |
Roland Dreier | be4c9ba | 2010-05-05 14:45:40 -0700 | [diff] [blame] | 1872 | if ((conn_param->ord > c4iw_max_read_depth) || |
| 1873 | (conn_param->ird > c4iw_max_read_depth)) { |
| 1874 | err = -EINVAL; |
| 1875 | goto out; |
| 1876 | } |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1877 | ep = alloc_ep(sizeof(*ep), GFP_KERNEL); |
| 1878 | if (!ep) { |
| 1879 | printk(KERN_ERR MOD "%s - cannot alloc ep.\n", __func__); |
| 1880 | err = -ENOMEM; |
| 1881 | goto out; |
| 1882 | } |
| 1883 | init_timer(&ep->timer); |
| 1884 | ep->plen = conn_param->private_data_len; |
| 1885 | if (ep->plen) |
| 1886 | memcpy(ep->mpa_pkt + sizeof(struct mpa_message), |
| 1887 | conn_param->private_data, ep->plen); |
| 1888 | ep->ird = conn_param->ird; |
| 1889 | ep->ord = conn_param->ord; |
| 1890 | |
| 1891 | if (peer2peer && ep->ord == 0) |
| 1892 | ep->ord = 1; |
| 1893 | |
| 1894 | cm_id->add_ref(cm_id); |
| 1895 | ep->com.dev = dev; |
| 1896 | ep->com.cm_id = cm_id; |
| 1897 | ep->com.qp = get_qhp(dev, conn_param->qpn); |
| 1898 | BUG_ON(!ep->com.qp); |
| 1899 | PDBG("%s qpn 0x%x qp %p cm_id %p\n", __func__, conn_param->qpn, |
| 1900 | ep->com.qp, cm_id); |
| 1901 | |
| 1902 | /* |
| 1903 | * Allocate an active TID to initiate a TCP connection. |
| 1904 | */ |
| 1905 | ep->atid = cxgb4_alloc_atid(dev->rdev.lldi.tids, ep); |
| 1906 | if (ep->atid == -1) { |
| 1907 | printk(KERN_ERR MOD "%s - cannot alloc atid.\n", __func__); |
| 1908 | err = -ENOMEM; |
| 1909 | goto fail2; |
| 1910 | } |
| 1911 | |
| 1912 | PDBG("%s saddr 0x%x sport 0x%x raddr 0x%x rport 0x%x\n", __func__, |
| 1913 | ntohl(cm_id->local_addr.sin_addr.s_addr), |
| 1914 | ntohs(cm_id->local_addr.sin_port), |
| 1915 | ntohl(cm_id->remote_addr.sin_addr.s_addr), |
| 1916 | ntohs(cm_id->remote_addr.sin_port)); |
| 1917 | |
| 1918 | /* find a route */ |
| 1919 | rt = find_route(dev, |
| 1920 | cm_id->local_addr.sin_addr.s_addr, |
| 1921 | cm_id->remote_addr.sin_addr.s_addr, |
| 1922 | cm_id->local_addr.sin_port, |
| 1923 | cm_id->remote_addr.sin_port, 0); |
| 1924 | if (!rt) { |
| 1925 | printk(KERN_ERR MOD "%s - cannot find route.\n", __func__); |
| 1926 | err = -EHOSTUNREACH; |
| 1927 | goto fail3; |
| 1928 | } |
Changli Gao | d8d1f30 | 2010-06-10 23:31:35 -0700 | [diff] [blame] | 1929 | ep->dst = &rt->dst; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1930 | |
| 1931 | /* get a l2t entry */ |
| 1932 | if (ep->dst->neighbour->dev->flags & IFF_LOOPBACK) { |
| 1933 | PDBG("%s LOOPBACK\n", __func__); |
| 1934 | pdev = ip_dev_find(&init_net, |
| 1935 | cm_id->remote_addr.sin_addr.s_addr); |
| 1936 | ep->l2t = cxgb4_l2t_get(ep->com.dev->rdev.lldi.l2t, |
| 1937 | ep->dst->neighbour, |
| 1938 | pdev, 0); |
| 1939 | ep->mtu = pdev->mtu; |
| 1940 | ep->tx_chan = cxgb4_port_chan(pdev); |
Steve Wise | 2c5934b | 2010-06-23 15:46:44 +0000 | [diff] [blame] | 1941 | ep->smac_idx = (cxgb4_port_viid(pdev) & 0x7F) << 1; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1942 | step = ep->com.dev->rdev.lldi.ntxq / |
| 1943 | ep->com.dev->rdev.lldi.nchan; |
| 1944 | ep->txq_idx = cxgb4_port_idx(pdev) * step; |
| 1945 | step = ep->com.dev->rdev.lldi.nrxq / |
| 1946 | ep->com.dev->rdev.lldi.nchan; |
Steve Wise | d4f1a5c | 2010-07-23 19:12:32 +0000 | [diff] [blame] | 1947 | ep->ctrlq_idx = cxgb4_port_idx(pdev); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1948 | ep->rss_qid = ep->com.dev->rdev.lldi.rxq_ids[ |
| 1949 | cxgb4_port_idx(pdev) * step]; |
| 1950 | dev_put(pdev); |
| 1951 | } else { |
| 1952 | ep->l2t = cxgb4_l2t_get(ep->com.dev->rdev.lldi.l2t, |
| 1953 | ep->dst->neighbour, |
| 1954 | ep->dst->neighbour->dev, 0); |
| 1955 | ep->mtu = dst_mtu(ep->dst); |
| 1956 | ep->tx_chan = cxgb4_port_chan(ep->dst->neighbour->dev); |
Steve Wise | 2c5934b | 2010-06-23 15:46:44 +0000 | [diff] [blame] | 1957 | ep->smac_idx = (cxgb4_port_viid(ep->dst->neighbour->dev) & |
| 1958 | 0x7F) << 1; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1959 | step = ep->com.dev->rdev.lldi.ntxq / |
| 1960 | ep->com.dev->rdev.lldi.nchan; |
| 1961 | ep->txq_idx = cxgb4_port_idx(ep->dst->neighbour->dev) * step; |
Steve Wise | d4f1a5c | 2010-07-23 19:12:32 +0000 | [diff] [blame] | 1962 | ep->ctrlq_idx = cxgb4_port_idx(ep->dst->neighbour->dev); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1963 | step = ep->com.dev->rdev.lldi.nrxq / |
| 1964 | ep->com.dev->rdev.lldi.nchan; |
| 1965 | ep->rss_qid = ep->com.dev->rdev.lldi.rxq_ids[ |
| 1966 | cxgb4_port_idx(ep->dst->neighbour->dev) * step]; |
| 1967 | } |
| 1968 | if (!ep->l2t) { |
| 1969 | printk(KERN_ERR MOD "%s - cannot alloc l2e.\n", __func__); |
| 1970 | err = -ENOMEM; |
| 1971 | goto fail4; |
| 1972 | } |
| 1973 | |
| 1974 | PDBG("%s txq_idx %u tx_chan %u smac_idx %u rss_qid %u l2t_idx %u\n", |
| 1975 | __func__, ep->txq_idx, ep->tx_chan, ep->smac_idx, ep->rss_qid, |
| 1976 | ep->l2t->idx); |
| 1977 | |
| 1978 | state_set(&ep->com, CONNECTING); |
| 1979 | ep->tos = 0; |
| 1980 | ep->com.local_addr = cm_id->local_addr; |
| 1981 | ep->com.remote_addr = cm_id->remote_addr; |
| 1982 | |
| 1983 | /* send connect request to rnic */ |
| 1984 | err = send_connect(ep); |
| 1985 | if (!err) |
| 1986 | goto out; |
| 1987 | |
| 1988 | cxgb4_l2t_release(ep->l2t); |
| 1989 | fail4: |
| 1990 | dst_release(ep->dst); |
| 1991 | fail3: |
| 1992 | cxgb4_free_atid(ep->com.dev->rdev.lldi.tids, ep->atid); |
| 1993 | fail2: |
| 1994 | cm_id->rem_ref(cm_id); |
| 1995 | c4iw_put_ep(&ep->com); |
| 1996 | out: |
| 1997 | return err; |
| 1998 | } |
| 1999 | |
| 2000 | int c4iw_create_listen(struct iw_cm_id *cm_id, int backlog) |
| 2001 | { |
| 2002 | int err = 0; |
| 2003 | struct c4iw_dev *dev = to_c4iw_dev(cm_id->device); |
| 2004 | struct c4iw_listen_ep *ep; |
| 2005 | |
| 2006 | |
| 2007 | might_sleep(); |
| 2008 | |
| 2009 | ep = alloc_ep(sizeof(*ep), GFP_KERNEL); |
| 2010 | if (!ep) { |
| 2011 | printk(KERN_ERR MOD "%s - cannot alloc ep.\n", __func__); |
| 2012 | err = -ENOMEM; |
| 2013 | goto fail1; |
| 2014 | } |
| 2015 | PDBG("%s ep %p\n", __func__, ep); |
| 2016 | cm_id->add_ref(cm_id); |
| 2017 | ep->com.cm_id = cm_id; |
| 2018 | ep->com.dev = dev; |
| 2019 | ep->backlog = backlog; |
| 2020 | ep->com.local_addr = cm_id->local_addr; |
| 2021 | |
| 2022 | /* |
| 2023 | * Allocate a server TID. |
| 2024 | */ |
| 2025 | ep->stid = cxgb4_alloc_stid(dev->rdev.lldi.tids, PF_INET, ep); |
| 2026 | if (ep->stid == -1) { |
Roland Dreier | be4c9ba | 2010-05-05 14:45:40 -0700 | [diff] [blame] | 2027 | printk(KERN_ERR MOD "%s - cannot alloc stid.\n", __func__); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2028 | err = -ENOMEM; |
| 2029 | goto fail2; |
| 2030 | } |
| 2031 | |
| 2032 | state_set(&ep->com, LISTEN); |
Steve Wise | aadc4df | 2010-09-10 11:15:25 -0500 | [diff] [blame] | 2033 | c4iw_init_wr_wait(&ep->com.wr_wait); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2034 | err = cxgb4_create_server(ep->com.dev->rdev.lldi.ports[0], ep->stid, |
| 2035 | ep->com.local_addr.sin_addr.s_addr, |
| 2036 | ep->com.local_addr.sin_port, |
| 2037 | ep->com.dev->rdev.lldi.rxq_ids[0]); |
| 2038 | if (err) |
| 2039 | goto fail3; |
| 2040 | |
| 2041 | /* wait for pass_open_rpl */ |
Steve Wise | aadc4df | 2010-09-10 11:15:25 -0500 | [diff] [blame] | 2042 | err = c4iw_wait_for_reply(&ep->com.dev->rdev, &ep->com.wr_wait, 0, 0, |
| 2043 | __func__); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2044 | if (!err) { |
| 2045 | cm_id->provider_data = ep; |
| 2046 | goto out; |
| 2047 | } |
| 2048 | fail3: |
| 2049 | cxgb4_free_stid(ep->com.dev->rdev.lldi.tids, ep->stid, PF_INET); |
| 2050 | fail2: |
| 2051 | cm_id->rem_ref(cm_id); |
| 2052 | c4iw_put_ep(&ep->com); |
| 2053 | fail1: |
| 2054 | out: |
| 2055 | return err; |
| 2056 | } |
| 2057 | |
| 2058 | int c4iw_destroy_listen(struct iw_cm_id *cm_id) |
| 2059 | { |
| 2060 | int err; |
| 2061 | struct c4iw_listen_ep *ep = to_listen_ep(cm_id); |
| 2062 | |
| 2063 | PDBG("%s ep %p\n", __func__, ep); |
| 2064 | |
| 2065 | might_sleep(); |
| 2066 | state_set(&ep->com, DEAD); |
Steve Wise | aadc4df | 2010-09-10 11:15:25 -0500 | [diff] [blame] | 2067 | c4iw_init_wr_wait(&ep->com.wr_wait); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2068 | err = listen_stop(ep); |
| 2069 | if (err) |
| 2070 | goto done; |
Steve Wise | aadc4df | 2010-09-10 11:15:25 -0500 | [diff] [blame] | 2071 | err = c4iw_wait_for_reply(&ep->com.dev->rdev, &ep->com.wr_wait, 0, 0, |
| 2072 | __func__); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2073 | cxgb4_free_stid(ep->com.dev->rdev.lldi.tids, ep->stid, PF_INET); |
| 2074 | done: |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2075 | cm_id->rem_ref(cm_id); |
| 2076 | c4iw_put_ep(&ep->com); |
| 2077 | return err; |
| 2078 | } |
| 2079 | |
| 2080 | int c4iw_ep_disconnect(struct c4iw_ep *ep, int abrupt, gfp_t gfp) |
| 2081 | { |
| 2082 | int ret = 0; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2083 | int close = 0; |
| 2084 | int fatal = 0; |
| 2085 | struct c4iw_rdev *rdev; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2086 | |
Steve Wise | 2f5b48c | 2010-09-10 11:15:36 -0500 | [diff] [blame] | 2087 | mutex_lock(&ep->com.mutex); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2088 | |
| 2089 | PDBG("%s ep %p state %s, abrupt %d\n", __func__, ep, |
| 2090 | states[ep->com.state], abrupt); |
| 2091 | |
| 2092 | rdev = &ep->com.dev->rdev; |
| 2093 | if (c4iw_fatal_error(rdev)) { |
| 2094 | fatal = 1; |
| 2095 | close_complete_upcall(ep); |
| 2096 | ep->com.state = DEAD; |
| 2097 | } |
| 2098 | switch (ep->com.state) { |
| 2099 | case MPA_REQ_WAIT: |
| 2100 | case MPA_REQ_SENT: |
| 2101 | case MPA_REQ_RCVD: |
| 2102 | case MPA_REP_SENT: |
| 2103 | case FPDU_MODE: |
| 2104 | close = 1; |
| 2105 | if (abrupt) |
| 2106 | ep->com.state = ABORTING; |
| 2107 | else { |
| 2108 | ep->com.state = CLOSING; |
Steve Wise | ca5a220 | 2010-07-23 19:12:37 +0000 | [diff] [blame] | 2109 | start_ep_timer(ep); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2110 | } |
| 2111 | set_bit(CLOSE_SENT, &ep->com.flags); |
| 2112 | break; |
| 2113 | case CLOSING: |
| 2114 | if (!test_and_set_bit(CLOSE_SENT, &ep->com.flags)) { |
| 2115 | close = 1; |
| 2116 | if (abrupt) { |
Steve Wise | ca5a220 | 2010-07-23 19:12:37 +0000 | [diff] [blame] | 2117 | stop_ep_timer(ep); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2118 | ep->com.state = ABORTING; |
| 2119 | } else |
| 2120 | ep->com.state = MORIBUND; |
| 2121 | } |
| 2122 | break; |
| 2123 | case MORIBUND: |
| 2124 | case ABORTING: |
| 2125 | case DEAD: |
| 2126 | PDBG("%s ignoring disconnect ep %p state %u\n", |
| 2127 | __func__, ep, ep->com.state); |
| 2128 | break; |
| 2129 | default: |
| 2130 | BUG(); |
| 2131 | break; |
| 2132 | } |
| 2133 | |
Steve Wise | 2f5b48c | 2010-09-10 11:15:36 -0500 | [diff] [blame] | 2134 | mutex_unlock(&ep->com.mutex); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2135 | if (close) { |
| 2136 | if (abrupt) |
| 2137 | ret = abort_connection(ep, NULL, gfp); |
| 2138 | else |
| 2139 | ret = send_halfclose(ep, gfp); |
| 2140 | if (ret) |
| 2141 | fatal = 1; |
| 2142 | } |
| 2143 | if (fatal) |
| 2144 | release_ep_resources(ep); |
| 2145 | return ret; |
| 2146 | } |
| 2147 | |
Steve Wise | 2f5b48c | 2010-09-10 11:15:36 -0500 | [diff] [blame] | 2148 | static int async_event(struct c4iw_dev *dev, struct sk_buff *skb) |
| 2149 | { |
| 2150 | struct cpl_fw6_msg *rpl = cplhdr(skb); |
| 2151 | c4iw_ev_dispatch(dev, (struct t4_cqe *)&rpl->data[0]); |
| 2152 | return 0; |
| 2153 | } |
| 2154 | |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2155 | /* |
Roland Dreier | be4c9ba | 2010-05-05 14:45:40 -0700 | [diff] [blame] | 2156 | * These are the real handlers that are called from a |
| 2157 | * work queue. |
| 2158 | */ |
| 2159 | static c4iw_handler_func work_handlers[NUM_CPL_CMDS] = { |
| 2160 | [CPL_ACT_ESTABLISH] = act_establish, |
| 2161 | [CPL_ACT_OPEN_RPL] = act_open_rpl, |
| 2162 | [CPL_RX_DATA] = rx_data, |
| 2163 | [CPL_ABORT_RPL_RSS] = abort_rpl, |
| 2164 | [CPL_ABORT_RPL] = abort_rpl, |
| 2165 | [CPL_PASS_OPEN_RPL] = pass_open_rpl, |
| 2166 | [CPL_CLOSE_LISTSRV_RPL] = close_listsrv_rpl, |
| 2167 | [CPL_PASS_ACCEPT_REQ] = pass_accept_req, |
| 2168 | [CPL_PASS_ESTABLISH] = pass_establish, |
| 2169 | [CPL_PEER_CLOSE] = peer_close, |
| 2170 | [CPL_ABORT_REQ_RSS] = peer_abort, |
| 2171 | [CPL_CLOSE_CON_RPL] = close_con_rpl, |
| 2172 | [CPL_RDMA_TERMINATE] = terminate, |
Steve Wise | 2f5b48c | 2010-09-10 11:15:36 -0500 | [diff] [blame] | 2173 | [CPL_FW4_ACK] = fw4_ack, |
| 2174 | [CPL_FW6_MSG] = async_event |
Roland Dreier | be4c9ba | 2010-05-05 14:45:40 -0700 | [diff] [blame] | 2175 | }; |
| 2176 | |
| 2177 | static void process_timeout(struct c4iw_ep *ep) |
| 2178 | { |
| 2179 | struct c4iw_qp_attributes attrs; |
| 2180 | int abort = 1; |
| 2181 | |
Steve Wise | 2f5b48c | 2010-09-10 11:15:36 -0500 | [diff] [blame] | 2182 | mutex_lock(&ep->com.mutex); |
Roland Dreier | be4c9ba | 2010-05-05 14:45:40 -0700 | [diff] [blame] | 2183 | PDBG("%s ep %p tid %u state %d\n", __func__, ep, ep->hwtid, |
| 2184 | ep->com.state); |
| 2185 | switch (ep->com.state) { |
| 2186 | case MPA_REQ_SENT: |
| 2187 | __state_set(&ep->com, ABORTING); |
| 2188 | connect_reply_upcall(ep, -ETIMEDOUT); |
| 2189 | break; |
| 2190 | case MPA_REQ_WAIT: |
| 2191 | __state_set(&ep->com, ABORTING); |
| 2192 | break; |
| 2193 | case CLOSING: |
| 2194 | case MORIBUND: |
| 2195 | if (ep->com.cm_id && ep->com.qp) { |
| 2196 | attrs.next_state = C4IW_QP_STATE_ERROR; |
| 2197 | c4iw_modify_qp(ep->com.qp->rhp, |
| 2198 | ep->com.qp, C4IW_QP_ATTR_NEXT_STATE, |
| 2199 | &attrs, 1); |
| 2200 | } |
| 2201 | __state_set(&ep->com, ABORTING); |
| 2202 | break; |
| 2203 | default: |
| 2204 | printk(KERN_ERR "%s unexpected state ep %p tid %u state %u\n", |
| 2205 | __func__, ep, ep->hwtid, ep->com.state); |
| 2206 | WARN_ON(1); |
| 2207 | abort = 0; |
| 2208 | } |
Steve Wise | 2f5b48c | 2010-09-10 11:15:36 -0500 | [diff] [blame] | 2209 | mutex_unlock(&ep->com.mutex); |
Roland Dreier | be4c9ba | 2010-05-05 14:45:40 -0700 | [diff] [blame] | 2210 | if (abort) |
| 2211 | abort_connection(ep, NULL, GFP_KERNEL); |
| 2212 | c4iw_put_ep(&ep->com); |
| 2213 | } |
| 2214 | |
| 2215 | static void process_timedout_eps(void) |
| 2216 | { |
| 2217 | struct c4iw_ep *ep; |
| 2218 | |
| 2219 | spin_lock_irq(&timeout_lock); |
| 2220 | while (!list_empty(&timeout_list)) { |
| 2221 | struct list_head *tmp; |
| 2222 | |
| 2223 | tmp = timeout_list.next; |
| 2224 | list_del(tmp); |
| 2225 | spin_unlock_irq(&timeout_lock); |
| 2226 | ep = list_entry(tmp, struct c4iw_ep, entry); |
| 2227 | process_timeout(ep); |
| 2228 | spin_lock_irq(&timeout_lock); |
| 2229 | } |
| 2230 | spin_unlock_irq(&timeout_lock); |
| 2231 | } |
| 2232 | |
| 2233 | static void process_work(struct work_struct *work) |
| 2234 | { |
| 2235 | struct sk_buff *skb = NULL; |
| 2236 | struct c4iw_dev *dev; |
Dan Carpenter | c1d7356 | 2010-05-31 14:00:53 +0000 | [diff] [blame] | 2237 | struct cpl_act_establish *rpl; |
Roland Dreier | be4c9ba | 2010-05-05 14:45:40 -0700 | [diff] [blame] | 2238 | unsigned int opcode; |
| 2239 | int ret; |
| 2240 | |
| 2241 | while ((skb = skb_dequeue(&rxq))) { |
| 2242 | rpl = cplhdr(skb); |
| 2243 | dev = *((struct c4iw_dev **) (skb->cb + sizeof(void *))); |
| 2244 | opcode = rpl->ot.opcode; |
| 2245 | |
| 2246 | BUG_ON(!work_handlers[opcode]); |
| 2247 | ret = work_handlers[opcode](dev, skb); |
| 2248 | if (!ret) |
| 2249 | kfree_skb(skb); |
| 2250 | } |
| 2251 | process_timedout_eps(); |
| 2252 | } |
| 2253 | |
| 2254 | static DECLARE_WORK(skb_work, process_work); |
| 2255 | |
| 2256 | static void ep_timeout(unsigned long arg) |
| 2257 | { |
| 2258 | struct c4iw_ep *ep = (struct c4iw_ep *)arg; |
| 2259 | |
| 2260 | spin_lock(&timeout_lock); |
| 2261 | list_add_tail(&ep->entry, &timeout_list); |
| 2262 | spin_unlock(&timeout_lock); |
| 2263 | queue_work(workq, &skb_work); |
| 2264 | } |
| 2265 | |
| 2266 | /* |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2267 | * All the CM events are handled on a work queue to have a safe context. |
| 2268 | */ |
| 2269 | static int sched(struct c4iw_dev *dev, struct sk_buff *skb) |
| 2270 | { |
| 2271 | |
| 2272 | /* |
| 2273 | * Save dev in the skb->cb area. |
| 2274 | */ |
| 2275 | *((struct c4iw_dev **) (skb->cb + sizeof(void *))) = dev; |
| 2276 | |
| 2277 | /* |
| 2278 | * Queue the skb and schedule the worker thread. |
| 2279 | */ |
| 2280 | skb_queue_tail(&rxq, skb); |
| 2281 | queue_work(workq, &skb_work); |
| 2282 | return 0; |
| 2283 | } |
| 2284 | |
| 2285 | static int set_tcb_rpl(struct c4iw_dev *dev, struct sk_buff *skb) |
| 2286 | { |
| 2287 | struct cpl_set_tcb_rpl *rpl = cplhdr(skb); |
| 2288 | |
| 2289 | if (rpl->status != CPL_ERR_NONE) { |
| 2290 | printk(KERN_ERR MOD "Unexpected SET_TCB_RPL status %u " |
| 2291 | "for tid %u\n", rpl->status, GET_TID(rpl)); |
| 2292 | } |
Steve Wise | 2f5b48c | 2010-09-10 11:15:36 -0500 | [diff] [blame] | 2293 | kfree_skb(skb); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2294 | return 0; |
| 2295 | } |
| 2296 | |
Roland Dreier | be4c9ba | 2010-05-05 14:45:40 -0700 | [diff] [blame] | 2297 | static int fw6_msg(struct c4iw_dev *dev, struct sk_buff *skb) |
| 2298 | { |
| 2299 | struct cpl_fw6_msg *rpl = cplhdr(skb); |
| 2300 | struct c4iw_wr_wait *wr_waitp; |
| 2301 | int ret; |
| 2302 | |
| 2303 | PDBG("%s type %u\n", __func__, rpl->type); |
| 2304 | |
| 2305 | switch (rpl->type) { |
| 2306 | case 1: |
| 2307 | ret = (int)((be64_to_cpu(rpl->data[0]) >> 8) & 0xff); |
Roland Dreier | c8e081a | 2010-09-27 17:51:04 -0700 | [diff] [blame] | 2308 | wr_waitp = (struct c4iw_wr_wait *)(__force unsigned long) rpl->data[1]; |
Roland Dreier | be4c9ba | 2010-05-05 14:45:40 -0700 | [diff] [blame] | 2309 | PDBG("%s wr_waitp %p ret %u\n", __func__, wr_waitp, ret); |
| 2310 | if (wr_waitp) { |
Steve Wise | 2f5b48c | 2010-09-10 11:15:36 -0500 | [diff] [blame] | 2311 | if (ret) |
| 2312 | wr_waitp->ret = -ret; |
| 2313 | else |
| 2314 | wr_waitp->ret = 0; |
Roland Dreier | be4c9ba | 2010-05-05 14:45:40 -0700 | [diff] [blame] | 2315 | wr_waitp->done = 1; |
| 2316 | wake_up(&wr_waitp->wait); |
| 2317 | } |
Steve Wise | 2f5b48c | 2010-09-10 11:15:36 -0500 | [diff] [blame] | 2318 | kfree_skb(skb); |
Roland Dreier | be4c9ba | 2010-05-05 14:45:40 -0700 | [diff] [blame] | 2319 | break; |
| 2320 | case 2: |
Steve Wise | 2f5b48c | 2010-09-10 11:15:36 -0500 | [diff] [blame] | 2321 | sched(dev, skb); |
Roland Dreier | be4c9ba | 2010-05-05 14:45:40 -0700 | [diff] [blame] | 2322 | break; |
| 2323 | default: |
| 2324 | printk(KERN_ERR MOD "%s unexpected fw6 msg type %u\n", __func__, |
| 2325 | rpl->type); |
Steve Wise | 2f5b48c | 2010-09-10 11:15:36 -0500 | [diff] [blame] | 2326 | kfree_skb(skb); |
Roland Dreier | be4c9ba | 2010-05-05 14:45:40 -0700 | [diff] [blame] | 2327 | break; |
| 2328 | } |
| 2329 | return 0; |
| 2330 | } |
| 2331 | |
| 2332 | /* |
| 2333 | * Most upcalls from the T4 Core go to sched() to |
| 2334 | * schedule the processing on a work queue. |
| 2335 | */ |
| 2336 | c4iw_handler_func c4iw_handlers[NUM_CPL_CMDS] = { |
| 2337 | [CPL_ACT_ESTABLISH] = sched, |
| 2338 | [CPL_ACT_OPEN_RPL] = sched, |
| 2339 | [CPL_RX_DATA] = sched, |
| 2340 | [CPL_ABORT_RPL_RSS] = sched, |
| 2341 | [CPL_ABORT_RPL] = sched, |
| 2342 | [CPL_PASS_OPEN_RPL] = sched, |
| 2343 | [CPL_CLOSE_LISTSRV_RPL] = sched, |
| 2344 | [CPL_PASS_ACCEPT_REQ] = sched, |
| 2345 | [CPL_PASS_ESTABLISH] = sched, |
| 2346 | [CPL_PEER_CLOSE] = sched, |
| 2347 | [CPL_CLOSE_CON_RPL] = sched, |
| 2348 | [CPL_ABORT_REQ_RSS] = sched, |
| 2349 | [CPL_RDMA_TERMINATE] = sched, |
| 2350 | [CPL_FW4_ACK] = sched, |
| 2351 | [CPL_SET_TCB_RPL] = set_tcb_rpl, |
| 2352 | [CPL_FW6_MSG] = fw6_msg |
| 2353 | }; |
| 2354 | |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2355 | int __init c4iw_cm_init(void) |
| 2356 | { |
Roland Dreier | be4c9ba | 2010-05-05 14:45:40 -0700 | [diff] [blame] | 2357 | spin_lock_init(&timeout_lock); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2358 | skb_queue_head_init(&rxq); |
| 2359 | |
| 2360 | workq = create_singlethread_workqueue("iw_cxgb4"); |
| 2361 | if (!workq) |
| 2362 | return -ENOMEM; |
| 2363 | |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2364 | return 0; |
| 2365 | } |
| 2366 | |
| 2367 | void __exit c4iw_cm_term(void) |
| 2368 | { |
Roland Dreier | be4c9ba | 2010-05-05 14:45:40 -0700 | [diff] [blame] | 2369 | WARN_ON(!list_empty(&timeout_list)); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2370 | flush_workqueue(workq); |
| 2371 | destroy_workqueue(workq); |
| 2372 | } |