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