1cfdda9d7SSteve Wise /* 29eccfe10SSteve Wise * Copyright (c) 2009-2014 Chelsio, Inc. All rights reserved. 3cfdda9d7SSteve Wise * 4cfdda9d7SSteve Wise * This software is available to you under a choice of one of two 5cfdda9d7SSteve Wise * licenses. You may choose to be licensed under the terms of the GNU 6cfdda9d7SSteve Wise * General Public License (GPL) Version 2, available from the file 7cfdda9d7SSteve Wise * COPYING in the main directory of this source tree, or the 8cfdda9d7SSteve Wise * OpenIB.org BSD license below: 9cfdda9d7SSteve Wise * 10cfdda9d7SSteve Wise * Redistribution and use in source and binary forms, with or 11cfdda9d7SSteve Wise * without modification, are permitted provided that the following 12cfdda9d7SSteve Wise * conditions are met: 13cfdda9d7SSteve Wise * 14cfdda9d7SSteve Wise * - Redistributions of source code must retain the above 15cfdda9d7SSteve Wise * copyright notice, this list of conditions and the following 16cfdda9d7SSteve Wise * disclaimer. 17cfdda9d7SSteve Wise * 18cfdda9d7SSteve Wise * - Redistributions in binary form must reproduce the above 19cfdda9d7SSteve Wise * copyright notice, this list of conditions and the following 20cfdda9d7SSteve Wise * disclaimer in the documentation and/or other materials 21cfdda9d7SSteve Wise * provided with the distribution. 22cfdda9d7SSteve Wise * 23cfdda9d7SSteve Wise * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 24cfdda9d7SSteve Wise * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 25cfdda9d7SSteve Wise * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 26cfdda9d7SSteve Wise * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 27cfdda9d7SSteve Wise * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 28cfdda9d7SSteve Wise * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 29cfdda9d7SSteve Wise * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 30cfdda9d7SSteve Wise * SOFTWARE. 31cfdda9d7SSteve Wise */ 32cfdda9d7SSteve Wise #include <linux/module.h> 33cfdda9d7SSteve Wise #include <linux/list.h> 34cfdda9d7SSteve Wise #include <linux/workqueue.h> 35cfdda9d7SSteve Wise #include <linux/skbuff.h> 36cfdda9d7SSteve Wise #include <linux/timer.h> 37cfdda9d7SSteve Wise #include <linux/notifier.h> 38cfdda9d7SSteve Wise #include <linux/inetdevice.h> 39cfdda9d7SSteve Wise #include <linux/ip.h> 40cfdda9d7SSteve Wise #include <linux/tcp.h> 411cab775cSVipul Pandya #include <linux/if_vlan.h> 42cfdda9d7SSteve Wise 43cfdda9d7SSteve Wise #include <net/neighbour.h> 44cfdda9d7SSteve Wise #include <net/netevent.h> 45cfdda9d7SSteve Wise #include <net/route.h> 461cab775cSVipul Pandya #include <net/tcp.h> 47830662f6SVipul Pandya #include <net/ip6_route.h> 48830662f6SVipul Pandya #include <net/addrconf.h> 49cfdda9d7SSteve Wise 5011b8e22dSSteve Wise #include <rdma/ib_addr.h> 5111b8e22dSSteve Wise 52cfdda9d7SSteve Wise #include "iw_cxgb4.h" 5384cc6ac6SHariprasad S #include "clip_tbl.h" 54cfdda9d7SSteve Wise 55cfdda9d7SSteve Wise static char *states[] = { 56cfdda9d7SSteve Wise "idle", 57cfdda9d7SSteve Wise "listen", 58cfdda9d7SSteve Wise "connecting", 59cfdda9d7SSteve Wise "mpa_wait_req", 60cfdda9d7SSteve Wise "mpa_req_sent", 61cfdda9d7SSteve Wise "mpa_req_rcvd", 62cfdda9d7SSteve Wise "mpa_rep_sent", 63cfdda9d7SSteve Wise "fpdu_mode", 64cfdda9d7SSteve Wise "aborting", 65cfdda9d7SSteve Wise "closing", 66cfdda9d7SSteve Wise "moribund", 67cfdda9d7SSteve Wise "dead", 68cfdda9d7SSteve Wise NULL, 69cfdda9d7SSteve Wise }; 70cfdda9d7SSteve Wise 715be78ee9SVipul Pandya static int nocong; 725be78ee9SVipul Pandya module_param(nocong, int, 0644); 735be78ee9SVipul Pandya MODULE_PARM_DESC(nocong, "Turn of congestion control (default=0)"); 745be78ee9SVipul Pandya 755be78ee9SVipul Pandya static int enable_ecn; 765be78ee9SVipul Pandya module_param(enable_ecn, int, 0644); 775be78ee9SVipul Pandya MODULE_PARM_DESC(enable_ecn, "Enable ECN (default=0/disabled)"); 785be78ee9SVipul Pandya 79b52fe09eSSteve Wise static int dack_mode = 1; 80ba6d3925SSteve Wise module_param(dack_mode, int, 0644); 81b52fe09eSSteve Wise MODULE_PARM_DESC(dack_mode, "Delayed ack mode (default=1)"); 82ba6d3925SSteve Wise 834c2c5763SHariprasad Shenai uint c4iw_max_read_depth = 32; 84be4c9badSRoland Dreier module_param(c4iw_max_read_depth, int, 0644); 854c2c5763SHariprasad Shenai MODULE_PARM_DESC(c4iw_max_read_depth, 864c2c5763SHariprasad Shenai "Per-connection max ORD/IRD (default=32)"); 87be4c9badSRoland Dreier 88cfdda9d7SSteve Wise static int enable_tcp_timestamps; 89cfdda9d7SSteve Wise module_param(enable_tcp_timestamps, int, 0644); 90cfdda9d7SSteve Wise MODULE_PARM_DESC(enable_tcp_timestamps, "Enable tcp timestamps (default=0)"); 91cfdda9d7SSteve Wise 92cfdda9d7SSteve Wise static int enable_tcp_sack; 93cfdda9d7SSteve Wise module_param(enable_tcp_sack, int, 0644); 94cfdda9d7SSteve Wise MODULE_PARM_DESC(enable_tcp_sack, "Enable tcp SACK (default=0)"); 95cfdda9d7SSteve Wise 96cfdda9d7SSteve Wise static int enable_tcp_window_scaling = 1; 97cfdda9d7SSteve Wise module_param(enable_tcp_window_scaling, int, 0644); 98cfdda9d7SSteve Wise MODULE_PARM_DESC(enable_tcp_window_scaling, 99cfdda9d7SSteve Wise "Enable tcp window scaling (default=1)"); 100cfdda9d7SSteve Wise 101cfdda9d7SSteve Wise int c4iw_debug; 102cfdda9d7SSteve Wise module_param(c4iw_debug, int, 0644); 103cfdda9d7SSteve Wise MODULE_PARM_DESC(c4iw_debug, "Enable debug logging (default=0)"); 104cfdda9d7SSteve Wise 105df2d5130SSteve Wise static int peer2peer = 1; 106cfdda9d7SSteve Wise module_param(peer2peer, int, 0644); 107df2d5130SSteve Wise MODULE_PARM_DESC(peer2peer, "Support peer2peer ULPs (default=1)"); 108cfdda9d7SSteve Wise 109cfdda9d7SSteve Wise static int p2p_type = FW_RI_INIT_P2PTYPE_READ_REQ; 110cfdda9d7SSteve Wise module_param(p2p_type, int, 0644); 111cfdda9d7SSteve Wise MODULE_PARM_DESC(p2p_type, "RDMAP opcode to use for the RTR message: " 112cfdda9d7SSteve Wise "1=RDMA_READ 0=RDMA_WRITE (default 1)"); 113cfdda9d7SSteve Wise 114cfdda9d7SSteve Wise static int ep_timeout_secs = 60; 115cfdda9d7SSteve Wise module_param(ep_timeout_secs, int, 0644); 116cfdda9d7SSteve Wise MODULE_PARM_DESC(ep_timeout_secs, "CM Endpoint operation timeout " 117cfdda9d7SSteve Wise "in seconds (default=60)"); 118cfdda9d7SSteve Wise 119b8ac3112SHariprasad S static int mpa_rev = 2; 120cfdda9d7SSteve Wise module_param(mpa_rev, int, 0644); 121cfdda9d7SSteve Wise MODULE_PARM_DESC(mpa_rev, "MPA Revision, 0 supports amso1100, " 122ccd2c30bSHariprasad S "1 is RFC5044 spec compliant, 2 is IETF MPA Peer Connect Draft" 123b8ac3112SHariprasad S " compliant (default=2)"); 124cfdda9d7SSteve Wise 125cfdda9d7SSteve Wise static int markers_enabled; 126cfdda9d7SSteve Wise module_param(markers_enabled, int, 0644); 127cfdda9d7SSteve Wise MODULE_PARM_DESC(markers_enabled, "Enable MPA MARKERS (default(0)=disabled)"); 128cfdda9d7SSteve Wise 129cfdda9d7SSteve Wise static int crc_enabled = 1; 130cfdda9d7SSteve Wise module_param(crc_enabled, int, 0644); 131cfdda9d7SSteve Wise MODULE_PARM_DESC(crc_enabled, "Enable MPA CRC (default(1)=enabled)"); 132cfdda9d7SSteve Wise 133cfdda9d7SSteve Wise static int rcv_win = 256 * 1024; 134cfdda9d7SSteve Wise module_param(rcv_win, int, 0644); 135cfdda9d7SSteve Wise MODULE_PARM_DESC(rcv_win, "TCP receive window in bytes (default=256KB)"); 136cfdda9d7SSteve Wise 13798ae68b7SSteve Wise static int snd_win = 128 * 1024; 138cfdda9d7SSteve Wise module_param(snd_win, int, 0644); 13998ae68b7SSteve Wise MODULE_PARM_DESC(snd_win, "TCP send window in bytes (default=128KB)"); 140cfdda9d7SSteve Wise 141cfdda9d7SSteve Wise static struct workqueue_struct *workq; 142cfdda9d7SSteve Wise 143cfdda9d7SSteve Wise static struct sk_buff_head rxq; 144cfdda9d7SSteve Wise 145cfdda9d7SSteve Wise static struct sk_buff *get_skb(struct sk_buff *skb, int len, gfp_t gfp); 146cfdda9d7SSteve Wise static void ep_timeout(unsigned long arg); 147cfdda9d7SSteve Wise static void connect_reply_upcall(struct c4iw_ep *ep, int status); 1489dec900cSHariprasad S static int sched(struct c4iw_dev *dev, struct sk_buff *skb); 149cfdda9d7SSteve Wise 150be4c9badSRoland Dreier static LIST_HEAD(timeout_list); 151be4c9badSRoland Dreier static spinlock_t timeout_lock; 152be4c9badSRoland Dreier 1539ca6f7cfSHariprasad S static void deref_cm_id(struct c4iw_ep_common *epc) 1549ca6f7cfSHariprasad S { 1559ca6f7cfSHariprasad S epc->cm_id->rem_ref(epc->cm_id); 1569ca6f7cfSHariprasad S epc->cm_id = NULL; 1579ca6f7cfSHariprasad S set_bit(CM_ID_DEREFED, &epc->history); 1589ca6f7cfSHariprasad S } 1599ca6f7cfSHariprasad S 1609ca6f7cfSHariprasad S static void ref_cm_id(struct c4iw_ep_common *epc) 1619ca6f7cfSHariprasad S { 1629ca6f7cfSHariprasad S set_bit(CM_ID_REFED, &epc->history); 1639ca6f7cfSHariprasad S epc->cm_id->add_ref(epc->cm_id); 1649ca6f7cfSHariprasad S } 1659ca6f7cfSHariprasad S 166325abeadSVipul Pandya static void deref_qp(struct c4iw_ep *ep) 167325abeadSVipul Pandya { 168325abeadSVipul Pandya c4iw_qp_rem_ref(&ep->com.qp->ibqp); 169325abeadSVipul Pandya clear_bit(QP_REFERENCED, &ep->com.flags); 1709ca6f7cfSHariprasad S set_bit(QP_DEREFED, &ep->com.history); 171325abeadSVipul Pandya } 172325abeadSVipul Pandya 173325abeadSVipul Pandya static void ref_qp(struct c4iw_ep *ep) 174325abeadSVipul Pandya { 175325abeadSVipul Pandya set_bit(QP_REFERENCED, &ep->com.flags); 1769ca6f7cfSHariprasad S set_bit(QP_REFED, &ep->com.history); 177325abeadSVipul Pandya c4iw_qp_add_ref(&ep->com.qp->ibqp); 178325abeadSVipul Pandya } 179325abeadSVipul Pandya 180cfdda9d7SSteve Wise static void start_ep_timer(struct c4iw_ep *ep) 181cfdda9d7SSteve Wise { 182cfdda9d7SSteve Wise PDBG("%s ep %p\n", __func__, ep); 183cfdda9d7SSteve Wise if (timer_pending(&ep->timer)) { 1841ec779ccSVipul Pandya pr_err("%s timer already started! ep %p\n", 1851ec779ccSVipul Pandya __func__, ep); 1861ec779ccSVipul Pandya return; 1871ec779ccSVipul Pandya } 1881ec779ccSVipul Pandya clear_bit(TIMEOUT, &ep->com.flags); 189cfdda9d7SSteve Wise c4iw_get_ep(&ep->com); 190cfdda9d7SSteve Wise ep->timer.expires = jiffies + ep_timeout_secs * HZ; 191cfdda9d7SSteve Wise ep->timer.data = (unsigned long)ep; 192cfdda9d7SSteve Wise ep->timer.function = ep_timeout; 193cfdda9d7SSteve Wise add_timer(&ep->timer); 194cfdda9d7SSteve Wise } 195cfdda9d7SSteve Wise 196b33bd0cbSSteve Wise static int stop_ep_timer(struct c4iw_ep *ep) 197cfdda9d7SSteve Wise { 1981ec779ccSVipul Pandya PDBG("%s ep %p stopping\n", __func__, ep); 199cfdda9d7SSteve Wise del_timer_sync(&ep->timer); 200b33bd0cbSSteve Wise if (!test_and_set_bit(TIMEOUT, &ep->com.flags)) { 201cfdda9d7SSteve Wise c4iw_put_ep(&ep->com); 202b33bd0cbSSteve Wise return 0; 203b33bd0cbSSteve Wise } 204b33bd0cbSSteve Wise return 1; 205cfdda9d7SSteve Wise } 206cfdda9d7SSteve Wise 207cfdda9d7SSteve Wise static int c4iw_l2t_send(struct c4iw_rdev *rdev, struct sk_buff *skb, 208cfdda9d7SSteve Wise struct l2t_entry *l2e) 209cfdda9d7SSteve Wise { 210cfdda9d7SSteve Wise int error = 0; 211cfdda9d7SSteve Wise 212cfdda9d7SSteve Wise if (c4iw_fatal_error(rdev)) { 213cfdda9d7SSteve Wise kfree_skb(skb); 214cfdda9d7SSteve Wise PDBG("%s - device in error state - dropping\n", __func__); 215cfdda9d7SSteve Wise return -EIO; 216cfdda9d7SSteve Wise } 217cfdda9d7SSteve Wise error = cxgb4_l2t_send(rdev->lldi.ports[0], skb, l2e); 218cfdda9d7SSteve Wise if (error < 0) 219cfdda9d7SSteve Wise kfree_skb(skb); 22074594861SSteve Wise return error < 0 ? error : 0; 221cfdda9d7SSteve Wise } 222cfdda9d7SSteve Wise 223cfdda9d7SSteve Wise int c4iw_ofld_send(struct c4iw_rdev *rdev, struct sk_buff *skb) 224cfdda9d7SSteve Wise { 225cfdda9d7SSteve Wise int error = 0; 226cfdda9d7SSteve Wise 227cfdda9d7SSteve Wise if (c4iw_fatal_error(rdev)) { 228cfdda9d7SSteve Wise kfree_skb(skb); 229cfdda9d7SSteve Wise PDBG("%s - device in error state - dropping\n", __func__); 230cfdda9d7SSteve Wise return -EIO; 231cfdda9d7SSteve Wise } 232cfdda9d7SSteve Wise error = cxgb4_ofld_send(rdev->lldi.ports[0], skb); 233cfdda9d7SSteve Wise if (error < 0) 234cfdda9d7SSteve Wise kfree_skb(skb); 23574594861SSteve Wise return error < 0 ? error : 0; 236cfdda9d7SSteve Wise } 237cfdda9d7SSteve Wise 238cfdda9d7SSteve Wise static void release_tid(struct c4iw_rdev *rdev, u32 hwtid, struct sk_buff *skb) 239cfdda9d7SSteve Wise { 240cfdda9d7SSteve Wise struct cpl_tid_release *req; 241cfdda9d7SSteve Wise 242cfdda9d7SSteve Wise skb = get_skb(skb, sizeof *req, GFP_KERNEL); 243cfdda9d7SSteve Wise if (!skb) 244cfdda9d7SSteve Wise return; 245cfdda9d7SSteve Wise req = (struct cpl_tid_release *) skb_put(skb, sizeof(*req)); 246cfdda9d7SSteve Wise INIT_TP_WR(req, hwtid); 247cfdda9d7SSteve Wise OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_TID_RELEASE, hwtid)); 248cfdda9d7SSteve Wise set_wr_txq(skb, CPL_PRIORITY_SETUP, 0); 249cfdda9d7SSteve Wise c4iw_ofld_send(rdev, skb); 250cfdda9d7SSteve Wise return; 251cfdda9d7SSteve Wise } 252cfdda9d7SSteve Wise 253cfdda9d7SSteve Wise static void set_emss(struct c4iw_ep *ep, u16 opt) 254cfdda9d7SSteve Wise { 2556c53e938SHariprasad Shenai ep->emss = ep->com.dev->rdev.lldi.mtus[TCPOPT_MSS_G(opt)] - 25604524a47SHariprasad S ((AF_INET == ep->com.remote_addr.ss_family) ? 25704524a47SHariprasad S sizeof(struct iphdr) : sizeof(struct ipv6hdr)) - 25804524a47SHariprasad S sizeof(struct tcphdr); 259cfdda9d7SSteve Wise ep->mss = ep->emss; 2606c53e938SHariprasad Shenai if (TCPOPT_TSTAMP_G(opt)) 26104524a47SHariprasad S ep->emss -= round_up(TCPOLEN_TIMESTAMP, 4); 262cfdda9d7SSteve Wise if (ep->emss < 128) 263cfdda9d7SSteve Wise ep->emss = 128; 26492e7ae71SHariprasad Shenai if (ep->emss & 7) 26592e7ae71SHariprasad Shenai PDBG("Warning: misaligned mtu idx %u mss %u emss=%u\n", 2666c53e938SHariprasad Shenai TCPOPT_MSS_G(opt), ep->mss, ep->emss); 2676c53e938SHariprasad Shenai PDBG("%s mss_idx %u mss %u emss=%u\n", __func__, TCPOPT_MSS_G(opt), 268cfdda9d7SSteve Wise ep->mss, ep->emss); 269cfdda9d7SSteve Wise } 270cfdda9d7SSteve Wise 271cfdda9d7SSteve Wise static enum c4iw_ep_state state_read(struct c4iw_ep_common *epc) 272cfdda9d7SSteve Wise { 273cfdda9d7SSteve Wise enum c4iw_ep_state state; 274cfdda9d7SSteve Wise 2752f5b48c3SSteve Wise mutex_lock(&epc->mutex); 276cfdda9d7SSteve Wise state = epc->state; 2772f5b48c3SSteve Wise mutex_unlock(&epc->mutex); 278cfdda9d7SSteve Wise return state; 279cfdda9d7SSteve Wise } 280cfdda9d7SSteve Wise 281cfdda9d7SSteve Wise static void __state_set(struct c4iw_ep_common *epc, enum c4iw_ep_state new) 282cfdda9d7SSteve Wise { 283cfdda9d7SSteve Wise epc->state = new; 284cfdda9d7SSteve Wise } 285cfdda9d7SSteve Wise 286cfdda9d7SSteve Wise static void state_set(struct c4iw_ep_common *epc, enum c4iw_ep_state new) 287cfdda9d7SSteve Wise { 2882f5b48c3SSteve Wise mutex_lock(&epc->mutex); 289cfdda9d7SSteve Wise PDBG("%s - %s -> %s\n", __func__, states[epc->state], states[new]); 290cfdda9d7SSteve Wise __state_set(epc, new); 2912f5b48c3SSteve Wise mutex_unlock(&epc->mutex); 292cfdda9d7SSteve Wise return; 293cfdda9d7SSteve Wise } 294cfdda9d7SSteve Wise 295cfdda9d7SSteve Wise static void *alloc_ep(int size, gfp_t gfp) 296cfdda9d7SSteve Wise { 297cfdda9d7SSteve Wise struct c4iw_ep_common *epc; 298cfdda9d7SSteve Wise 299cfdda9d7SSteve Wise epc = kzalloc(size, gfp); 300cfdda9d7SSteve Wise if (epc) { 301cfdda9d7SSteve Wise kref_init(&epc->kref); 3022f5b48c3SSteve Wise mutex_init(&epc->mutex); 303aadc4df3SSteve Wise c4iw_init_wr_wait(&epc->wr_wait); 304cfdda9d7SSteve Wise } 305cfdda9d7SSteve Wise PDBG("%s alloc ep %p\n", __func__, epc); 306cfdda9d7SSteve Wise return epc; 307cfdda9d7SSteve Wise } 308cfdda9d7SSteve Wise 309cfdda9d7SSteve Wise void _c4iw_free_ep(struct kref *kref) 310cfdda9d7SSteve Wise { 311cfdda9d7SSteve Wise struct c4iw_ep *ep; 312cfdda9d7SSteve Wise 313cfdda9d7SSteve Wise ep = container_of(kref, struct c4iw_ep, com.kref); 3149dec900cSHariprasad S PDBG("%s ep %p state %s\n", __func__, ep, states[ep->com.state]); 315325abeadSVipul Pandya if (test_bit(QP_REFERENCED, &ep->com.flags)) 316325abeadSVipul Pandya deref_qp(ep); 317cfdda9d7SSteve Wise if (test_bit(RELEASE_RESOURCES, &ep->com.flags)) { 31884cc6ac6SHariprasad S if (ep->com.remote_addr.ss_family == AF_INET6) { 31984cc6ac6SHariprasad S struct sockaddr_in6 *sin6 = 32084cc6ac6SHariprasad S (struct sockaddr_in6 *) 321170003c8SSteve Wise &ep->com.local_addr; 32284cc6ac6SHariprasad S 32384cc6ac6SHariprasad S cxgb4_clip_release( 32484cc6ac6SHariprasad S ep->com.dev->rdev.lldi.ports[0], 32584cc6ac6SHariprasad S (const u32 *)&sin6->sin6_addr.s6_addr, 32684cc6ac6SHariprasad S 1); 32784cc6ac6SHariprasad S } 328fe7e0a4dSVipul Pandya remove_handle(ep->com.dev, &ep->com.dev->hwtid_idr, ep->hwtid); 329cfdda9d7SSteve Wise cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, ep->hwtid); 330cfdda9d7SSteve Wise dst_release(ep->dst); 331cfdda9d7SSteve Wise cxgb4_l2t_release(ep->l2t); 332cfdda9d7SSteve Wise } 333cfdda9d7SSteve Wise kfree(ep); 334cfdda9d7SSteve Wise } 335cfdda9d7SSteve Wise 336cfdda9d7SSteve Wise static void release_ep_resources(struct c4iw_ep *ep) 337cfdda9d7SSteve Wise { 338cfdda9d7SSteve Wise set_bit(RELEASE_RESOURCES, &ep->com.flags); 339cfdda9d7SSteve Wise c4iw_put_ep(&ep->com); 340cfdda9d7SSteve Wise } 341cfdda9d7SSteve Wise 342cfdda9d7SSteve Wise static int status2errno(int status) 343cfdda9d7SSteve Wise { 344cfdda9d7SSteve Wise switch (status) { 345cfdda9d7SSteve Wise case CPL_ERR_NONE: 346cfdda9d7SSteve Wise return 0; 347cfdda9d7SSteve Wise case CPL_ERR_CONN_RESET: 348cfdda9d7SSteve Wise return -ECONNRESET; 349cfdda9d7SSteve Wise case CPL_ERR_ARP_MISS: 350cfdda9d7SSteve Wise return -EHOSTUNREACH; 351cfdda9d7SSteve Wise case CPL_ERR_CONN_TIMEDOUT: 352cfdda9d7SSteve Wise return -ETIMEDOUT; 353cfdda9d7SSteve Wise case CPL_ERR_TCAM_FULL: 354cfdda9d7SSteve Wise return -ENOMEM; 355cfdda9d7SSteve Wise case CPL_ERR_CONN_EXIST: 356cfdda9d7SSteve Wise return -EADDRINUSE; 357cfdda9d7SSteve Wise default: 358cfdda9d7SSteve Wise return -EIO; 359cfdda9d7SSteve Wise } 360cfdda9d7SSteve Wise } 361cfdda9d7SSteve Wise 362cfdda9d7SSteve Wise /* 363cfdda9d7SSteve Wise * Try and reuse skbs already allocated... 364cfdda9d7SSteve Wise */ 365cfdda9d7SSteve Wise static struct sk_buff *get_skb(struct sk_buff *skb, int len, gfp_t gfp) 366cfdda9d7SSteve Wise { 367cfdda9d7SSteve Wise if (skb && !skb_is_nonlinear(skb) && !skb_cloned(skb)) { 368cfdda9d7SSteve Wise skb_trim(skb, 0); 369cfdda9d7SSteve Wise skb_get(skb); 370cfdda9d7SSteve Wise skb_reset_transport_header(skb); 371cfdda9d7SSteve Wise } else { 372cfdda9d7SSteve Wise skb = alloc_skb(len, gfp); 373cfdda9d7SSteve Wise } 374b38a0ad8SSteve Wise t4_set_arp_err_handler(skb, NULL, NULL); 375cfdda9d7SSteve Wise return skb; 376cfdda9d7SSteve Wise } 377cfdda9d7SSteve Wise 378830662f6SVipul Pandya static struct net_device *get_real_dev(struct net_device *egress_dev) 379830662f6SVipul Pandya { 38011b8e22dSSteve Wise return rdma_vlan_dev_real_dev(egress_dev) ? : egress_dev; 381830662f6SVipul Pandya } 382830662f6SVipul Pandya 383830662f6SVipul Pandya static int our_interface(struct c4iw_dev *dev, struct net_device *egress_dev) 384830662f6SVipul Pandya { 385830662f6SVipul Pandya int i; 386830662f6SVipul Pandya 387830662f6SVipul Pandya egress_dev = get_real_dev(egress_dev); 388830662f6SVipul Pandya for (i = 0; i < dev->rdev.lldi.nports; i++) 389830662f6SVipul Pandya if (dev->rdev.lldi.ports[i] == egress_dev) 390830662f6SVipul Pandya return 1; 391830662f6SVipul Pandya return 0; 392830662f6SVipul Pandya } 393830662f6SVipul Pandya 394830662f6SVipul Pandya static struct dst_entry *find_route6(struct c4iw_dev *dev, __u8 *local_ip, 395830662f6SVipul Pandya __u8 *peer_ip, __be16 local_port, 396830662f6SVipul Pandya __be16 peer_port, u8 tos, 397830662f6SVipul Pandya __u32 sin6_scope_id) 398830662f6SVipul Pandya { 399830662f6SVipul Pandya struct dst_entry *dst = NULL; 400830662f6SVipul Pandya 401830662f6SVipul Pandya if (IS_ENABLED(CONFIG_IPV6)) { 402830662f6SVipul Pandya struct flowi6 fl6; 403830662f6SVipul Pandya 404830662f6SVipul Pandya memset(&fl6, 0, sizeof(fl6)); 405830662f6SVipul Pandya memcpy(&fl6.daddr, peer_ip, 16); 406830662f6SVipul Pandya memcpy(&fl6.saddr, local_ip, 16); 407830662f6SVipul Pandya if (ipv6_addr_type(&fl6.daddr) & IPV6_ADDR_LINKLOCAL) 408830662f6SVipul Pandya fl6.flowi6_oif = sin6_scope_id; 409830662f6SVipul Pandya dst = ip6_route_output(&init_net, NULL, &fl6); 410830662f6SVipul Pandya if (!dst) 411830662f6SVipul Pandya goto out; 412830662f6SVipul Pandya if (!our_interface(dev, ip6_dst_idev(dst)->dev) && 413830662f6SVipul Pandya !(ip6_dst_idev(dst)->dev->flags & IFF_LOOPBACK)) { 414830662f6SVipul Pandya dst_release(dst); 415830662f6SVipul Pandya dst = NULL; 416830662f6SVipul Pandya } 417830662f6SVipul Pandya } 418830662f6SVipul Pandya 419830662f6SVipul Pandya out: 420830662f6SVipul Pandya return dst; 421830662f6SVipul Pandya } 422830662f6SVipul Pandya 423830662f6SVipul Pandya static struct dst_entry *find_route(struct c4iw_dev *dev, __be32 local_ip, 424cfdda9d7SSteve Wise __be32 peer_ip, __be16 local_port, 425cfdda9d7SSteve Wise __be16 peer_port, u8 tos) 426cfdda9d7SSteve Wise { 427cfdda9d7SSteve Wise struct rtable *rt; 42831e4543dSDavid S. Miller struct flowi4 fl4; 429830662f6SVipul Pandya struct neighbour *n; 430cfdda9d7SSteve Wise 43131e4543dSDavid S. Miller rt = ip_route_output_ports(&init_net, &fl4, NULL, peer_ip, local_ip, 43278fbfd8aSDavid S. Miller peer_port, local_port, IPPROTO_TCP, 43378fbfd8aSDavid S. Miller tos, 0); 434b23dd4feSDavid S. Miller if (IS_ERR(rt)) 435cfdda9d7SSteve Wise return NULL; 436830662f6SVipul Pandya n = dst_neigh_lookup(&rt->dst, &peer_ip); 437830662f6SVipul Pandya if (!n) 438830662f6SVipul Pandya return NULL; 439f8e81908SSteve Wise if (!our_interface(dev, n->dev) && 440f8e81908SSteve Wise !(n->dev->flags & IFF_LOOPBACK)) { 441d480201bSHariprasad S neigh_release(n); 442830662f6SVipul Pandya dst_release(&rt->dst); 443830662f6SVipul Pandya return NULL; 444830662f6SVipul Pandya } 445830662f6SVipul Pandya neigh_release(n); 446830662f6SVipul Pandya return &rt->dst; 447cfdda9d7SSteve Wise } 448cfdda9d7SSteve Wise 449cfdda9d7SSteve Wise static void arp_failure_discard(void *handle, struct sk_buff *skb) 450cfdda9d7SSteve Wise { 4519dec900cSHariprasad S pr_err(MOD "ARP failure\n"); 452cfdda9d7SSteve Wise kfree_skb(skb); 453cfdda9d7SSteve Wise } 454cfdda9d7SSteve Wise 4559dec900cSHariprasad S enum { 4568d1f1a6bSHariprasad S NUM_FAKE_CPLS = 2, 4579dec900cSHariprasad S FAKE_CPL_PUT_EP_SAFE = NUM_CPL_CMDS + 0, 4588d1f1a6bSHariprasad S FAKE_CPL_PASS_PUT_EP_SAFE = NUM_CPL_CMDS + 1, 4599dec900cSHariprasad S }; 4609dec900cSHariprasad S 4619dec900cSHariprasad S static int _put_ep_safe(struct c4iw_dev *dev, struct sk_buff *skb) 4629dec900cSHariprasad S { 4639dec900cSHariprasad S struct c4iw_ep *ep; 4649dec900cSHariprasad S 4659dec900cSHariprasad S ep = *((struct c4iw_ep **)(skb->cb + 2 * sizeof(void *))); 4669dec900cSHariprasad S release_ep_resources(ep); 4679dec900cSHariprasad S return 0; 4689dec900cSHariprasad S } 4699dec900cSHariprasad S 4708d1f1a6bSHariprasad S static int _put_pass_ep_safe(struct c4iw_dev *dev, struct sk_buff *skb) 4718d1f1a6bSHariprasad S { 4728d1f1a6bSHariprasad S struct c4iw_ep *ep; 4738d1f1a6bSHariprasad S 4748d1f1a6bSHariprasad S ep = *((struct c4iw_ep **)(skb->cb + 2 * sizeof(void *))); 4758d1f1a6bSHariprasad S c4iw_put_ep(&ep->parent_ep->com); 4768d1f1a6bSHariprasad S release_ep_resources(ep); 4778d1f1a6bSHariprasad S return 0; 4788d1f1a6bSHariprasad S } 4798d1f1a6bSHariprasad S 4809dec900cSHariprasad S /* 4819dec900cSHariprasad S * Fake up a special CPL opcode and call sched() so process_work() will call 4829dec900cSHariprasad S * _put_ep_safe() in a safe context to free the ep resources. This is needed 4839dec900cSHariprasad S * because ARP error handlers are called in an ATOMIC context, and 4849dec900cSHariprasad S * _c4iw_free_ep() needs to block. 4859dec900cSHariprasad S */ 4868d1f1a6bSHariprasad S static void queue_arp_failure_cpl(struct c4iw_ep *ep, struct sk_buff *skb, 4878d1f1a6bSHariprasad S int cpl) 4889dec900cSHariprasad S { 4899dec900cSHariprasad S struct cpl_act_establish *rpl = cplhdr(skb); 4909dec900cSHariprasad S 4919dec900cSHariprasad S /* Set our special ARP_FAILURE opcode */ 4928d1f1a6bSHariprasad S rpl->ot.opcode = cpl; 4939dec900cSHariprasad S 4949dec900cSHariprasad S /* 4959dec900cSHariprasad S * Save ep in the skb->cb area, after where sched() will save the dev 4969dec900cSHariprasad S * ptr. 4979dec900cSHariprasad S */ 4989dec900cSHariprasad S *((struct c4iw_ep **)(skb->cb + 2 * sizeof(void *))) = ep; 4999dec900cSHariprasad S sched(ep->com.dev, skb); 5009dec900cSHariprasad S } 5019dec900cSHariprasad S 5029dec900cSHariprasad S /* Handle an ARP failure for an accept */ 5039dec900cSHariprasad S static void pass_accept_rpl_arp_failure(void *handle, struct sk_buff *skb) 5049dec900cSHariprasad S { 5059dec900cSHariprasad S struct c4iw_ep *ep = handle; 5069dec900cSHariprasad S 5079dec900cSHariprasad S pr_err(MOD "ARP failure during accept - tid %u -dropping connection\n", 5089dec900cSHariprasad S ep->hwtid); 5099dec900cSHariprasad S 5109dec900cSHariprasad S __state_set(&ep->com, DEAD); 5118d1f1a6bSHariprasad S queue_arp_failure_cpl(ep, skb, FAKE_CPL_PASS_PUT_EP_SAFE); 5129dec900cSHariprasad S } 5139dec900cSHariprasad S 514cfdda9d7SSteve Wise /* 515cfdda9d7SSteve Wise * Handle an ARP failure for an active open. 516cfdda9d7SSteve Wise */ 517cfdda9d7SSteve Wise static void act_open_req_arp_failure(void *handle, struct sk_buff *skb) 518cfdda9d7SSteve Wise { 5195dab6d3aSHariprasad S struct c4iw_ep *ep = handle; 5205dab6d3aSHariprasad S 521e3d132d1SMasanari Iida printk(KERN_ERR MOD "ARP failure during connect\n"); 5225dab6d3aSHariprasad S connect_reply_upcall(ep, -EHOSTUNREACH); 5239dec900cSHariprasad S __state_set(&ep->com, DEAD); 52484cc6ac6SHariprasad S if (ep->com.remote_addr.ss_family == AF_INET6) { 52584cc6ac6SHariprasad S struct sockaddr_in6 *sin6 = 526170003c8SSteve Wise (struct sockaddr_in6 *)&ep->com.local_addr; 52784cc6ac6SHariprasad S cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0], 52884cc6ac6SHariprasad S (const u32 *)&sin6->sin6_addr.s6_addr, 1); 52984cc6ac6SHariprasad S } 5305dab6d3aSHariprasad S remove_handle(ep->com.dev, &ep->com.dev->atid_idr, ep->atid); 5315dab6d3aSHariprasad S cxgb4_free_atid(ep->com.dev->rdev.lldi.tids, ep->atid); 5328d1f1a6bSHariprasad S queue_arp_failure_cpl(ep, skb, FAKE_CPL_PUT_EP_SAFE); 533cfdda9d7SSteve Wise } 534cfdda9d7SSteve Wise 535cfdda9d7SSteve Wise /* 536cfdda9d7SSteve Wise * Handle an ARP failure for a CPL_ABORT_REQ. Change it into a no RST variant 537cfdda9d7SSteve Wise * and send it along. 538cfdda9d7SSteve Wise */ 539cfdda9d7SSteve Wise static void abort_arp_failure(void *handle, struct sk_buff *skb) 540cfdda9d7SSteve Wise { 541cfdda9d7SSteve Wise struct c4iw_rdev *rdev = handle; 542cfdda9d7SSteve Wise struct cpl_abort_req *req = cplhdr(skb); 543cfdda9d7SSteve Wise 544cfdda9d7SSteve Wise PDBG("%s rdev %p\n", __func__, rdev); 545cfdda9d7SSteve Wise req->cmd = CPL_ABORT_NO_RST; 546cfdda9d7SSteve Wise c4iw_ofld_send(rdev, skb); 547cfdda9d7SSteve Wise } 548cfdda9d7SSteve Wise 549fef4422dSHariprasad S static int send_flowc(struct c4iw_ep *ep, struct sk_buff *skb) 550cfdda9d7SSteve Wise { 551cfdda9d7SSteve Wise unsigned int flowclen = 80; 552cfdda9d7SSteve Wise struct fw_flowc_wr *flowc; 553cfdda9d7SSteve Wise int i; 554ac8e4c69SHariprasad S u16 vlan = ep->l2t->vlan; 555ac8e4c69SHariprasad S int nparams; 556ac8e4c69SHariprasad S 557ac8e4c69SHariprasad S if (vlan == CPL_L2T_VLAN_NONE) 558ac8e4c69SHariprasad S nparams = 8; 559ac8e4c69SHariprasad S else 560ac8e4c69SHariprasad S nparams = 9; 561cfdda9d7SSteve Wise 562cfdda9d7SSteve Wise skb = get_skb(skb, flowclen, GFP_KERNEL); 563cfdda9d7SSteve Wise flowc = (struct fw_flowc_wr *)__skb_put(skb, flowclen); 564cfdda9d7SSteve Wise 565e2ac9628SHariprasad Shenai flowc->op_to_nparams = cpu_to_be32(FW_WR_OP_V(FW_FLOWC_WR) | 566ac8e4c69SHariprasad S FW_FLOWC_WR_NPARAMS_V(nparams)); 567e2ac9628SHariprasad Shenai flowc->flowid_len16 = cpu_to_be32(FW_WR_LEN16_V(DIV_ROUND_UP(flowclen, 568e2ac9628SHariprasad Shenai 16)) | FW_WR_FLOWID_V(ep->hwtid)); 569cfdda9d7SSteve Wise 570cfdda9d7SSteve Wise flowc->mnemval[0].mnemonic = FW_FLOWC_MNEM_PFNVFN; 5715167865aSHariprasad Shenai flowc->mnemval[0].val = cpu_to_be32(FW_PFVF_CMD_PFN_V 57235b1de55SHariprasad Shenai (ep->com.dev->rdev.lldi.pf)); 573cfdda9d7SSteve Wise flowc->mnemval[1].mnemonic = FW_FLOWC_MNEM_CH; 574cfdda9d7SSteve Wise flowc->mnemval[1].val = cpu_to_be32(ep->tx_chan); 575cfdda9d7SSteve Wise flowc->mnemval[2].mnemonic = FW_FLOWC_MNEM_PORT; 576cfdda9d7SSteve Wise flowc->mnemval[2].val = cpu_to_be32(ep->tx_chan); 577cfdda9d7SSteve Wise flowc->mnemval[3].mnemonic = FW_FLOWC_MNEM_IQID; 578cfdda9d7SSteve Wise flowc->mnemval[3].val = cpu_to_be32(ep->rss_qid); 579cfdda9d7SSteve Wise flowc->mnemval[4].mnemonic = FW_FLOWC_MNEM_SNDNXT; 580cfdda9d7SSteve Wise flowc->mnemval[4].val = cpu_to_be32(ep->snd_seq); 581cfdda9d7SSteve Wise flowc->mnemval[5].mnemonic = FW_FLOWC_MNEM_RCVNXT; 582cfdda9d7SSteve Wise flowc->mnemval[5].val = cpu_to_be32(ep->rcv_seq); 583cfdda9d7SSteve Wise flowc->mnemval[6].mnemonic = FW_FLOWC_MNEM_SNDBUF; 584b408ff28SHariprasad Shenai flowc->mnemval[6].val = cpu_to_be32(ep->snd_win); 585cfdda9d7SSteve Wise flowc->mnemval[7].mnemonic = FW_FLOWC_MNEM_MSS; 586cfdda9d7SSteve Wise flowc->mnemval[7].val = cpu_to_be32(ep->emss); 587ac8e4c69SHariprasad S if (nparams == 9) { 588ac8e4c69SHariprasad S u16 pri; 589ac8e4c69SHariprasad S 590ac8e4c69SHariprasad S pri = (vlan & VLAN_PRIO_MASK) >> VLAN_PRIO_SHIFT; 591ac8e4c69SHariprasad S flowc->mnemval[8].mnemonic = FW_FLOWC_MNEM_SCHEDCLASS; 592ac8e4c69SHariprasad S flowc->mnemval[8].val = cpu_to_be32(pri); 593ac8e4c69SHariprasad S } else { 594cfdda9d7SSteve Wise /* Pad WR to 16 byte boundary */ 595cfdda9d7SSteve Wise flowc->mnemval[8].mnemonic = 0; 596cfdda9d7SSteve Wise flowc->mnemval[8].val = 0; 597ac8e4c69SHariprasad S } 598cfdda9d7SSteve Wise for (i = 0; i < 9; i++) { 599cfdda9d7SSteve Wise flowc->mnemval[i].r4[0] = 0; 600cfdda9d7SSteve Wise flowc->mnemval[i].r4[1] = 0; 601cfdda9d7SSteve Wise flowc->mnemval[i].r4[2] = 0; 602cfdda9d7SSteve Wise } 603cfdda9d7SSteve Wise 604cfdda9d7SSteve Wise set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx); 605fef4422dSHariprasad S return c4iw_ofld_send(&ep->com.dev->rdev, skb); 606cfdda9d7SSteve Wise } 607cfdda9d7SSteve Wise 608cfdda9d7SSteve Wise static int send_halfclose(struct c4iw_ep *ep, gfp_t gfp) 609cfdda9d7SSteve Wise { 610cfdda9d7SSteve Wise struct cpl_close_con_req *req; 611cfdda9d7SSteve Wise struct sk_buff *skb; 612cfdda9d7SSteve Wise int wrlen = roundup(sizeof *req, 16); 613cfdda9d7SSteve Wise 614cfdda9d7SSteve Wise PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid); 615cfdda9d7SSteve Wise skb = get_skb(NULL, wrlen, gfp); 616cfdda9d7SSteve Wise if (!skb) { 617cfdda9d7SSteve Wise printk(KERN_ERR MOD "%s - failed to alloc skb\n", __func__); 618cfdda9d7SSteve Wise return -ENOMEM; 619cfdda9d7SSteve Wise } 620cfdda9d7SSteve Wise set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx); 621cfdda9d7SSteve Wise t4_set_arp_err_handler(skb, NULL, arp_failure_discard); 622cfdda9d7SSteve Wise req = (struct cpl_close_con_req *) skb_put(skb, wrlen); 623cfdda9d7SSteve Wise memset(req, 0, wrlen); 624cfdda9d7SSteve Wise INIT_TP_WR(req, ep->hwtid); 625cfdda9d7SSteve Wise OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_CLOSE_CON_REQ, 626cfdda9d7SSteve Wise ep->hwtid)); 627cfdda9d7SSteve Wise return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t); 628cfdda9d7SSteve Wise } 629cfdda9d7SSteve Wise 630cfdda9d7SSteve Wise static int send_abort(struct c4iw_ep *ep, struct sk_buff *skb, gfp_t gfp) 631cfdda9d7SSteve Wise { 632cfdda9d7SSteve Wise struct cpl_abort_req *req; 633cfdda9d7SSteve Wise int wrlen = roundup(sizeof *req, 16); 634cfdda9d7SSteve Wise 635cfdda9d7SSteve Wise PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid); 636cfdda9d7SSteve Wise skb = get_skb(skb, wrlen, gfp); 637cfdda9d7SSteve Wise if (!skb) { 638cfdda9d7SSteve Wise printk(KERN_ERR MOD "%s - failed to alloc skb.\n", 639cfdda9d7SSteve Wise __func__); 640cfdda9d7SSteve Wise return -ENOMEM; 641cfdda9d7SSteve Wise } 642cfdda9d7SSteve Wise set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx); 643cfdda9d7SSteve Wise t4_set_arp_err_handler(skb, &ep->com.dev->rdev, abort_arp_failure); 644cfdda9d7SSteve Wise req = (struct cpl_abort_req *) skb_put(skb, wrlen); 645cfdda9d7SSteve Wise memset(req, 0, wrlen); 646cfdda9d7SSteve Wise INIT_TP_WR(req, ep->hwtid); 647cfdda9d7SSteve Wise OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_ABORT_REQ, ep->hwtid)); 648cfdda9d7SSteve Wise req->cmd = CPL_ABORT_SEND_RST; 649cfdda9d7SSteve Wise return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t); 650cfdda9d7SSteve Wise } 651cfdda9d7SSteve Wise 65292e7ae71SHariprasad Shenai static void best_mtu(const unsigned short *mtus, unsigned short mtu, 65304524a47SHariprasad S unsigned int *idx, int use_ts, int ipv6) 65492e7ae71SHariprasad Shenai { 65504524a47SHariprasad S unsigned short hdr_size = (ipv6 ? 65604524a47SHariprasad S sizeof(struct ipv6hdr) : 65704524a47SHariprasad S sizeof(struct iphdr)) + 65892e7ae71SHariprasad Shenai sizeof(struct tcphdr) + 65904524a47SHariprasad S (use_ts ? 66004524a47SHariprasad S round_up(TCPOLEN_TIMESTAMP, 4) : 0); 66192e7ae71SHariprasad Shenai unsigned short data_size = mtu - hdr_size; 66292e7ae71SHariprasad Shenai 66392e7ae71SHariprasad Shenai cxgb4_best_aligned_mtu(mtus, hdr_size, data_size, 8, idx); 66492e7ae71SHariprasad Shenai } 66592e7ae71SHariprasad Shenai 666cfdda9d7SSteve Wise static int send_connect(struct c4iw_ep *ep) 667cfdda9d7SSteve Wise { 668963cab50SHariprasad S struct cpl_act_open_req *req = NULL; 669963cab50SHariprasad S struct cpl_t5_act_open_req *t5req = NULL; 670963cab50SHariprasad S struct cpl_t6_act_open_req *t6req = NULL; 671963cab50SHariprasad S struct cpl_act_open_req6 *req6 = NULL; 672963cab50SHariprasad S struct cpl_t5_act_open_req6 *t5req6 = NULL; 673963cab50SHariprasad S struct cpl_t6_act_open_req6 *t6req6 = NULL; 674cfdda9d7SSteve Wise struct sk_buff *skb; 675cfdda9d7SSteve Wise u64 opt0; 676cfdda9d7SSteve Wise u32 opt2; 677cfdda9d7SSteve Wise unsigned int mtu_idx; 678cfdda9d7SSteve Wise int wscale; 679963cab50SHariprasad S int win, sizev4, sizev6, wrlen; 6809eccfe10SSteve Wise struct sockaddr_in *la = (struct sockaddr_in *) 681170003c8SSteve Wise &ep->com.local_addr; 6829eccfe10SSteve Wise struct sockaddr_in *ra = (struct sockaddr_in *) 683170003c8SSteve Wise &ep->com.remote_addr; 6849eccfe10SSteve Wise struct sockaddr_in6 *la6 = (struct sockaddr_in6 *) 685170003c8SSteve Wise &ep->com.local_addr; 6869eccfe10SSteve Wise struct sockaddr_in6 *ra6 = (struct sockaddr_in6 *) 687170003c8SSteve Wise &ep->com.remote_addr; 68884cc6ac6SHariprasad S int ret; 689963cab50SHariprasad S enum chip_type adapter_type = ep->com.dev->rdev.lldi.adapter_type; 690963cab50SHariprasad S u32 isn = (prandom_u32() & ~7UL) - 1; 691963cab50SHariprasad S 692963cab50SHariprasad S switch (CHELSIO_CHIP_VERSION(adapter_type)) { 693963cab50SHariprasad S case CHELSIO_T4: 694963cab50SHariprasad S sizev4 = sizeof(struct cpl_act_open_req); 695963cab50SHariprasad S sizev6 = sizeof(struct cpl_act_open_req6); 696963cab50SHariprasad S break; 697963cab50SHariprasad S case CHELSIO_T5: 698963cab50SHariprasad S sizev4 = sizeof(struct cpl_t5_act_open_req); 699963cab50SHariprasad S sizev6 = sizeof(struct cpl_t5_act_open_req6); 700963cab50SHariprasad S break; 701963cab50SHariprasad S case CHELSIO_T6: 702963cab50SHariprasad S sizev4 = sizeof(struct cpl_t6_act_open_req); 703963cab50SHariprasad S sizev6 = sizeof(struct cpl_t6_act_open_req6); 704963cab50SHariprasad S break; 705963cab50SHariprasad S default: 706963cab50SHariprasad S pr_err("T%d Chip is not supported\n", 707963cab50SHariprasad S CHELSIO_CHIP_VERSION(adapter_type)); 708963cab50SHariprasad S return -EINVAL; 709963cab50SHariprasad S } 710830662f6SVipul Pandya 711830662f6SVipul Pandya wrlen = (ep->com.remote_addr.ss_family == AF_INET) ? 712830662f6SVipul Pandya roundup(sizev4, 16) : 713830662f6SVipul Pandya roundup(sizev6, 16); 714cfdda9d7SSteve Wise 715cfdda9d7SSteve Wise PDBG("%s ep %p atid %u\n", __func__, ep, ep->atid); 716cfdda9d7SSteve Wise 717cfdda9d7SSteve Wise skb = get_skb(NULL, wrlen, GFP_KERNEL); 718cfdda9d7SSteve Wise if (!skb) { 719cfdda9d7SSteve Wise printk(KERN_ERR MOD "%s - failed to alloc skb.\n", 720cfdda9d7SSteve Wise __func__); 721cfdda9d7SSteve Wise return -ENOMEM; 722cfdda9d7SSteve Wise } 723d4f1a5c6SSteve Wise set_wr_txq(skb, CPL_PRIORITY_SETUP, ep->ctrlq_idx); 724cfdda9d7SSteve Wise 72592e7ae71SHariprasad Shenai best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx, 72604524a47SHariprasad S enable_tcp_timestamps, 72704524a47SHariprasad S (AF_INET == ep->com.remote_addr.ss_family) ? 0 : 1); 728cfdda9d7SSteve Wise wscale = compute_wscale(rcv_win); 729b408ff28SHariprasad Shenai 730b408ff28SHariprasad Shenai /* 731b408ff28SHariprasad Shenai * Specify the largest window that will fit in opt0. The 732b408ff28SHariprasad Shenai * remainder will be specified in the rx_data_ack. 733b408ff28SHariprasad Shenai */ 734b408ff28SHariprasad Shenai win = ep->rcv_win >> 10; 735d7990b0cSAnish Bhatt if (win > RCV_BUFSIZ_M) 736d7990b0cSAnish Bhatt win = RCV_BUFSIZ_M; 737b408ff28SHariprasad Shenai 7386c53e938SHariprasad Shenai opt0 = (nocong ? NO_CONG_F : 0) | 739d7990b0cSAnish Bhatt KEEP_ALIVE_F | 7406c53e938SHariprasad Shenai DELACK_F | 741d7990b0cSAnish Bhatt WND_SCALE_V(wscale) | 742d7990b0cSAnish Bhatt MSS_IDX_V(mtu_idx) | 743d7990b0cSAnish Bhatt L2T_IDX_V(ep->l2t->idx) | 744d7990b0cSAnish Bhatt TX_CHAN_V(ep->tx_chan) | 745d7990b0cSAnish Bhatt SMAC_SEL_V(ep->smac_idx) | 746ac8e4c69SHariprasad S DSCP_V(ep->tos >> 2) | 747d7990b0cSAnish Bhatt ULP_MODE_V(ULP_MODE_TCPDDP) | 748d7990b0cSAnish Bhatt RCV_BUFSIZ_V(win); 749d7990b0cSAnish Bhatt opt2 = RX_CHANNEL_V(0) | 7506c53e938SHariprasad Shenai CCTRL_ECN_V(enable_ecn) | 751d7990b0cSAnish Bhatt RSS_QUEUE_VALID_F | RSS_QUEUE_V(ep->rss_qid); 752cfdda9d7SSteve Wise if (enable_tcp_timestamps) 7536c53e938SHariprasad Shenai opt2 |= TSTAMPS_EN_F; 754cfdda9d7SSteve Wise if (enable_tcp_sack) 7556c53e938SHariprasad Shenai opt2 |= SACK_EN_F; 756cfdda9d7SSteve Wise if (wscale && enable_tcp_window_scaling) 757d7990b0cSAnish Bhatt opt2 |= WND_SCALE_EN_F; 758963cab50SHariprasad S if (CHELSIO_CHIP_VERSION(adapter_type) > CHELSIO_T4) { 759963cab50SHariprasad S if (peer2peer) 760963cab50SHariprasad S isn += 4; 761963cab50SHariprasad S 762d7990b0cSAnish Bhatt opt2 |= T5_OPT_2_VALID_F; 763cf7fe64aSHariprasad Shenai opt2 |= CONG_CNTRL_V(CONG_ALG_TAHOE); 7640b741047SHariprasad S opt2 |= T5_ISS_F; 76592e5011aSSteve Wise } 76684cc6ac6SHariprasad S 76784cc6ac6SHariprasad S if (ep->com.remote_addr.ss_family == AF_INET6) 76884cc6ac6SHariprasad S cxgb4_clip_get(ep->com.dev->rdev.lldi.ports[0], 76984cc6ac6SHariprasad S (const u32 *)&la6->sin6_addr.s6_addr, 1); 77084cc6ac6SHariprasad S 7715dab6d3aSHariprasad S t4_set_arp_err_handler(skb, ep, act_open_req_arp_failure); 772cfdda9d7SSteve Wise 773830662f6SVipul Pandya if (ep->com.remote_addr.ss_family == AF_INET) { 774963cab50SHariprasad S switch (CHELSIO_CHIP_VERSION(adapter_type)) { 775963cab50SHariprasad S case CHELSIO_T4: 776cfdda9d7SSteve Wise req = (struct cpl_act_open_req *)skb_put(skb, wrlen); 777cfdda9d7SSteve Wise INIT_TP_WR(req, 0); 778963cab50SHariprasad S break; 779963cab50SHariprasad S case CHELSIO_T5: 780963cab50SHariprasad S t5req = (struct cpl_t5_act_open_req *)skb_put(skb, 781963cab50SHariprasad S wrlen); 782963cab50SHariprasad S INIT_TP_WR(t5req, 0); 783963cab50SHariprasad S req = (struct cpl_act_open_req *)t5req; 784963cab50SHariprasad S break; 785963cab50SHariprasad S case CHELSIO_T6: 786963cab50SHariprasad S t6req = (struct cpl_t6_act_open_req *)skb_put(skb, 787963cab50SHariprasad S wrlen); 788963cab50SHariprasad S INIT_TP_WR(t6req, 0); 789963cab50SHariprasad S req = (struct cpl_act_open_req *)t6req; 790963cab50SHariprasad S t5req = (struct cpl_t5_act_open_req *)t6req; 791963cab50SHariprasad S break; 792963cab50SHariprasad S default: 793963cab50SHariprasad S pr_err("T%d Chip is not supported\n", 794963cab50SHariprasad S CHELSIO_CHIP_VERSION(adapter_type)); 795963cab50SHariprasad S ret = -EINVAL; 796963cab50SHariprasad S goto clip_release; 797963cab50SHariprasad S } 798963cab50SHariprasad S 799963cab50SHariprasad S OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_ACT_OPEN_REQ, 800f079af7aSVipul Pandya ((ep->rss_qid<<14) | ep->atid))); 801830662f6SVipul Pandya req->local_port = la->sin_port; 802830662f6SVipul Pandya req->peer_port = ra->sin_port; 803830662f6SVipul Pandya req->local_ip = la->sin_addr.s_addr; 804830662f6SVipul Pandya req->peer_ip = ra->sin_addr.s_addr; 805cfdda9d7SSteve Wise req->opt0 = cpu_to_be64(opt0); 806963cab50SHariprasad S 807963cab50SHariprasad S if (is_t4(ep->com.dev->rdev.lldi.adapter_type)) { 80841b4f86cSKumar Sanghvi req->params = cpu_to_be32(cxgb4_select_ntuple( 80941b4f86cSKumar Sanghvi ep->com.dev->rdev.lldi.ports[0], 81041b4f86cSKumar Sanghvi ep->l2t)); 811cfdda9d7SSteve Wise req->opt2 = cpu_to_be32(opt2); 812f079af7aSVipul Pandya } else { 813963cab50SHariprasad S t5req->params = cpu_to_be64(FILTER_TUPLE_V( 814963cab50SHariprasad S cxgb4_select_ntuple( 815963cab50SHariprasad S ep->com.dev->rdev.lldi.ports[0], 816963cab50SHariprasad S ep->l2t))); 817963cab50SHariprasad S t5req->rsvd = cpu_to_be32(isn); 818963cab50SHariprasad S PDBG("%s snd_isn %u\n", __func__, t5req->rsvd); 819963cab50SHariprasad S t5req->opt2 = cpu_to_be32(opt2); 820963cab50SHariprasad S } 821963cab50SHariprasad S } else { 822963cab50SHariprasad S switch (CHELSIO_CHIP_VERSION(adapter_type)) { 823963cab50SHariprasad S case CHELSIO_T4: 824830662f6SVipul Pandya req6 = (struct cpl_act_open_req6 *)skb_put(skb, wrlen); 825830662f6SVipul Pandya INIT_TP_WR(req6, 0); 826963cab50SHariprasad S break; 827963cab50SHariprasad S case CHELSIO_T5: 828963cab50SHariprasad S t5req6 = (struct cpl_t5_act_open_req6 *)skb_put(skb, 829963cab50SHariprasad S wrlen); 830963cab50SHariprasad S INIT_TP_WR(t5req6, 0); 831963cab50SHariprasad S req6 = (struct cpl_act_open_req6 *)t5req6; 832963cab50SHariprasad S break; 833963cab50SHariprasad S case CHELSIO_T6: 834963cab50SHariprasad S t6req6 = (struct cpl_t6_act_open_req6 *)skb_put(skb, 835963cab50SHariprasad S wrlen); 836963cab50SHariprasad S INIT_TP_WR(t6req6, 0); 837963cab50SHariprasad S req6 = (struct cpl_act_open_req6 *)t6req6; 838963cab50SHariprasad S t5req6 = (struct cpl_t5_act_open_req6 *)t6req6; 839963cab50SHariprasad S break; 840963cab50SHariprasad S default: 841963cab50SHariprasad S pr_err("T%d Chip is not supported\n", 842963cab50SHariprasad S CHELSIO_CHIP_VERSION(adapter_type)); 843963cab50SHariprasad S ret = -EINVAL; 844963cab50SHariprasad S goto clip_release; 845963cab50SHariprasad S } 846963cab50SHariprasad S 847963cab50SHariprasad S OPCODE_TID(req6) = cpu_to_be32(MK_OPCODE_TID(CPL_ACT_OPEN_REQ6, 848830662f6SVipul Pandya ((ep->rss_qid<<14)|ep->atid))); 849830662f6SVipul Pandya req6->local_port = la6->sin6_port; 850830662f6SVipul Pandya req6->peer_port = ra6->sin6_port; 851963cab50SHariprasad S req6->local_ip_hi = *((__be64 *)(la6->sin6_addr.s6_addr)); 852963cab50SHariprasad S req6->local_ip_lo = *((__be64 *)(la6->sin6_addr.s6_addr + 8)); 853963cab50SHariprasad S req6->peer_ip_hi = *((__be64 *)(ra6->sin6_addr.s6_addr)); 854963cab50SHariprasad S req6->peer_ip_lo = *((__be64 *)(ra6->sin6_addr.s6_addr + 8)); 855830662f6SVipul Pandya req6->opt0 = cpu_to_be64(opt0); 856963cab50SHariprasad S 857963cab50SHariprasad S if (is_t4(ep->com.dev->rdev.lldi.adapter_type)) { 85841b4f86cSKumar Sanghvi req6->params = cpu_to_be32(cxgb4_select_ntuple( 85941b4f86cSKumar Sanghvi ep->com.dev->rdev.lldi.ports[0], 860830662f6SVipul Pandya ep->l2t)); 861830662f6SVipul Pandya req6->opt2 = cpu_to_be32(opt2); 862830662f6SVipul Pandya } else { 863963cab50SHariprasad S t5req6->params = cpu_to_be64(FILTER_TUPLE_V( 86441b4f86cSKumar Sanghvi cxgb4_select_ntuple( 86541b4f86cSKumar Sanghvi ep->com.dev->rdev.lldi.ports[0], 86641b4f86cSKumar Sanghvi ep->l2t))); 867963cab50SHariprasad S t5req6->rsvd = cpu_to_be32(isn); 868963cab50SHariprasad S PDBG("%s snd_isn %u\n", __func__, t5req6->rsvd); 869963cab50SHariprasad S t5req6->opt2 = cpu_to_be32(opt2); 870830662f6SVipul Pandya } 871f079af7aSVipul Pandya } 872f079af7aSVipul Pandya 873793dad94SVipul Pandya set_bit(ACT_OPEN_REQ, &ep->com.history); 87484cc6ac6SHariprasad S ret = c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t); 875963cab50SHariprasad S clip_release: 87684cc6ac6SHariprasad S if (ret && ep->com.remote_addr.ss_family == AF_INET6) 87784cc6ac6SHariprasad S cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0], 87884cc6ac6SHariprasad S (const u32 *)&la6->sin6_addr.s6_addr, 1); 87984cc6ac6SHariprasad S return ret; 880cfdda9d7SSteve Wise } 881cfdda9d7SSteve Wise 882d2fe99e8SKumar Sanghvi static void send_mpa_req(struct c4iw_ep *ep, struct sk_buff *skb, 883d2fe99e8SKumar Sanghvi u8 mpa_rev_to_use) 884cfdda9d7SSteve Wise { 885cfdda9d7SSteve Wise int mpalen, wrlen; 886cfdda9d7SSteve Wise struct fw_ofld_tx_data_wr *req; 887cfdda9d7SSteve Wise struct mpa_message *mpa; 888d2fe99e8SKumar Sanghvi struct mpa_v2_conn_params mpa_v2_params; 889cfdda9d7SSteve Wise 890cfdda9d7SSteve Wise PDBG("%s ep %p tid %u pd_len %d\n", __func__, ep, ep->hwtid, ep->plen); 891cfdda9d7SSteve Wise 892cfdda9d7SSteve Wise BUG_ON(skb_cloned(skb)); 893cfdda9d7SSteve Wise 894cfdda9d7SSteve Wise mpalen = sizeof(*mpa) + ep->plen; 895d2fe99e8SKumar Sanghvi if (mpa_rev_to_use == 2) 896d2fe99e8SKumar Sanghvi mpalen += sizeof(struct mpa_v2_conn_params); 897cfdda9d7SSteve Wise wrlen = roundup(mpalen + sizeof *req, 16); 898cfdda9d7SSteve Wise skb = get_skb(skb, wrlen, GFP_KERNEL); 899cfdda9d7SSteve Wise if (!skb) { 900cfdda9d7SSteve Wise connect_reply_upcall(ep, -ENOMEM); 901cfdda9d7SSteve Wise return; 902cfdda9d7SSteve Wise } 903cfdda9d7SSteve Wise set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx); 904cfdda9d7SSteve Wise 905cfdda9d7SSteve Wise req = (struct fw_ofld_tx_data_wr *)skb_put(skb, wrlen); 906cfdda9d7SSteve Wise memset(req, 0, wrlen); 907cfdda9d7SSteve Wise req->op_to_immdlen = cpu_to_be32( 908e2ac9628SHariprasad Shenai FW_WR_OP_V(FW_OFLD_TX_DATA_WR) | 909e2ac9628SHariprasad Shenai FW_WR_COMPL_F | 910e2ac9628SHariprasad Shenai FW_WR_IMMDLEN_V(mpalen)); 911cfdda9d7SSteve Wise req->flowid_len16 = cpu_to_be32( 912e2ac9628SHariprasad Shenai FW_WR_FLOWID_V(ep->hwtid) | 913e2ac9628SHariprasad Shenai FW_WR_LEN16_V(wrlen >> 4)); 914cfdda9d7SSteve Wise req->plen = cpu_to_be32(mpalen); 915cfdda9d7SSteve Wise req->tunnel_to_proxy = cpu_to_be32( 916e2ac9628SHariprasad Shenai FW_OFLD_TX_DATA_WR_FLUSH_F | 917e2ac9628SHariprasad Shenai FW_OFLD_TX_DATA_WR_SHOVE_F); 918cfdda9d7SSteve Wise 919cfdda9d7SSteve Wise mpa = (struct mpa_message *)(req + 1); 920cfdda9d7SSteve Wise memcpy(mpa->key, MPA_KEY_REQ, sizeof(mpa->key)); 921cfdda9d7SSteve Wise mpa->flags = (crc_enabled ? MPA_CRC : 0) | 922d2fe99e8SKumar Sanghvi (markers_enabled ? MPA_MARKERS : 0) | 923d2fe99e8SKumar Sanghvi (mpa_rev_to_use == 2 ? MPA_ENHANCED_RDMA_CONN : 0); 924cfdda9d7SSteve Wise mpa->private_data_size = htons(ep->plen); 925d2fe99e8SKumar Sanghvi mpa->revision = mpa_rev_to_use; 92601b225e1SKumar Sanghvi if (mpa_rev_to_use == 1) { 927d2fe99e8SKumar Sanghvi ep->tried_with_mpa_v1 = 1; 92801b225e1SKumar Sanghvi ep->retry_with_mpa_v1 = 0; 92901b225e1SKumar Sanghvi } 930d2fe99e8SKumar Sanghvi 931d2fe99e8SKumar Sanghvi if (mpa_rev_to_use == 2) { 932f747c34aSRoland Dreier mpa->private_data_size = htons(ntohs(mpa->private_data_size) + 933f747c34aSRoland Dreier sizeof (struct mpa_v2_conn_params)); 9344c2c5763SHariprasad Shenai PDBG("%s initiator ird %u ord %u\n", __func__, ep->ird, 9354c2c5763SHariprasad Shenai ep->ord); 936d2fe99e8SKumar Sanghvi mpa_v2_params.ird = htons((u16)ep->ird); 937d2fe99e8SKumar Sanghvi mpa_v2_params.ord = htons((u16)ep->ord); 938d2fe99e8SKumar Sanghvi 939d2fe99e8SKumar Sanghvi if (peer2peer) { 940d2fe99e8SKumar Sanghvi mpa_v2_params.ird |= htons(MPA_V2_PEER2PEER_MODEL); 941d2fe99e8SKumar Sanghvi if (p2p_type == FW_RI_INIT_P2PTYPE_RDMA_WRITE) 942d2fe99e8SKumar Sanghvi mpa_v2_params.ord |= 943d2fe99e8SKumar Sanghvi htons(MPA_V2_RDMA_WRITE_RTR); 944d2fe99e8SKumar Sanghvi else if (p2p_type == FW_RI_INIT_P2PTYPE_READ_REQ) 945d2fe99e8SKumar Sanghvi mpa_v2_params.ord |= 946d2fe99e8SKumar Sanghvi htons(MPA_V2_RDMA_READ_RTR); 947d2fe99e8SKumar Sanghvi } 948d2fe99e8SKumar Sanghvi memcpy(mpa->private_data, &mpa_v2_params, 949d2fe99e8SKumar Sanghvi sizeof(struct mpa_v2_conn_params)); 950cfdda9d7SSteve Wise 951cfdda9d7SSteve Wise if (ep->plen) 952d2fe99e8SKumar Sanghvi memcpy(mpa->private_data + 953d2fe99e8SKumar Sanghvi sizeof(struct mpa_v2_conn_params), 954d2fe99e8SKumar Sanghvi ep->mpa_pkt + sizeof(*mpa), ep->plen); 955d2fe99e8SKumar Sanghvi } else 956d2fe99e8SKumar Sanghvi if (ep->plen) 957d2fe99e8SKumar Sanghvi memcpy(mpa->private_data, 958d2fe99e8SKumar Sanghvi ep->mpa_pkt + sizeof(*mpa), ep->plen); 959cfdda9d7SSteve Wise 960cfdda9d7SSteve Wise /* 961cfdda9d7SSteve Wise * Reference the mpa skb. This ensures the data area 962cfdda9d7SSteve Wise * will remain in memory until the hw acks the tx. 963cfdda9d7SSteve Wise * Function fw4_ack() will deref it. 964cfdda9d7SSteve Wise */ 965cfdda9d7SSteve Wise skb_get(skb); 966cfdda9d7SSteve Wise t4_set_arp_err_handler(skb, NULL, arp_failure_discard); 967cfdda9d7SSteve Wise BUG_ON(ep->mpa_skb); 968cfdda9d7SSteve Wise ep->mpa_skb = skb; 969cfdda9d7SSteve Wise c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t); 970cfdda9d7SSteve Wise start_ep_timer(ep); 971a7db89ebSSteve Wise __state_set(&ep->com, MPA_REQ_SENT); 972cfdda9d7SSteve Wise ep->mpa_attr.initiator = 1; 9739c88aa00SSteve Wise ep->snd_seq += mpalen; 974cfdda9d7SSteve Wise return; 975cfdda9d7SSteve Wise } 976cfdda9d7SSteve Wise 977cfdda9d7SSteve Wise static int send_mpa_reject(struct c4iw_ep *ep, const void *pdata, u8 plen) 978cfdda9d7SSteve Wise { 979cfdda9d7SSteve Wise int mpalen, wrlen; 980cfdda9d7SSteve Wise struct fw_ofld_tx_data_wr *req; 981cfdda9d7SSteve Wise struct mpa_message *mpa; 982cfdda9d7SSteve Wise struct sk_buff *skb; 983d2fe99e8SKumar Sanghvi struct mpa_v2_conn_params mpa_v2_params; 984cfdda9d7SSteve Wise 985cfdda9d7SSteve Wise PDBG("%s ep %p tid %u pd_len %d\n", __func__, ep, ep->hwtid, ep->plen); 986cfdda9d7SSteve Wise 987cfdda9d7SSteve Wise mpalen = sizeof(*mpa) + plen; 988d2fe99e8SKumar Sanghvi if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) 989d2fe99e8SKumar Sanghvi mpalen += sizeof(struct mpa_v2_conn_params); 990cfdda9d7SSteve Wise wrlen = roundup(mpalen + sizeof *req, 16); 991cfdda9d7SSteve Wise 992cfdda9d7SSteve Wise skb = get_skb(NULL, wrlen, GFP_KERNEL); 993cfdda9d7SSteve Wise if (!skb) { 994cfdda9d7SSteve Wise printk(KERN_ERR MOD "%s - cannot alloc skb!\n", __func__); 995cfdda9d7SSteve Wise return -ENOMEM; 996cfdda9d7SSteve Wise } 997cfdda9d7SSteve Wise set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx); 998cfdda9d7SSteve Wise 999cfdda9d7SSteve Wise req = (struct fw_ofld_tx_data_wr *)skb_put(skb, wrlen); 1000cfdda9d7SSteve Wise memset(req, 0, wrlen); 1001cfdda9d7SSteve Wise req->op_to_immdlen = cpu_to_be32( 1002e2ac9628SHariprasad Shenai FW_WR_OP_V(FW_OFLD_TX_DATA_WR) | 1003e2ac9628SHariprasad Shenai FW_WR_COMPL_F | 1004e2ac9628SHariprasad Shenai FW_WR_IMMDLEN_V(mpalen)); 1005cfdda9d7SSteve Wise req->flowid_len16 = cpu_to_be32( 1006e2ac9628SHariprasad Shenai FW_WR_FLOWID_V(ep->hwtid) | 1007e2ac9628SHariprasad Shenai FW_WR_LEN16_V(wrlen >> 4)); 1008cfdda9d7SSteve Wise req->plen = cpu_to_be32(mpalen); 1009cfdda9d7SSteve Wise req->tunnel_to_proxy = cpu_to_be32( 1010e2ac9628SHariprasad Shenai FW_OFLD_TX_DATA_WR_FLUSH_F | 1011e2ac9628SHariprasad Shenai FW_OFLD_TX_DATA_WR_SHOVE_F); 1012cfdda9d7SSteve Wise 1013cfdda9d7SSteve Wise mpa = (struct mpa_message *)(req + 1); 1014cfdda9d7SSteve Wise memset(mpa, 0, sizeof(*mpa)); 1015cfdda9d7SSteve Wise memcpy(mpa->key, MPA_KEY_REP, sizeof(mpa->key)); 1016cfdda9d7SSteve Wise mpa->flags = MPA_REJECT; 1017fe7e0a4dSVipul Pandya mpa->revision = ep->mpa_attr.version; 1018cfdda9d7SSteve Wise mpa->private_data_size = htons(plen); 1019d2fe99e8SKumar Sanghvi 1020d2fe99e8SKumar Sanghvi if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) { 1021d2fe99e8SKumar Sanghvi mpa->flags |= MPA_ENHANCED_RDMA_CONN; 1022f747c34aSRoland Dreier mpa->private_data_size = htons(ntohs(mpa->private_data_size) + 1023f747c34aSRoland Dreier sizeof (struct mpa_v2_conn_params)); 1024d2fe99e8SKumar Sanghvi mpa_v2_params.ird = htons(((u16)ep->ird) | 1025d2fe99e8SKumar Sanghvi (peer2peer ? MPA_V2_PEER2PEER_MODEL : 1026d2fe99e8SKumar Sanghvi 0)); 1027d2fe99e8SKumar Sanghvi mpa_v2_params.ord = htons(((u16)ep->ord) | (peer2peer ? 1028d2fe99e8SKumar Sanghvi (p2p_type == 1029d2fe99e8SKumar Sanghvi FW_RI_INIT_P2PTYPE_RDMA_WRITE ? 1030d2fe99e8SKumar Sanghvi MPA_V2_RDMA_WRITE_RTR : p2p_type == 1031d2fe99e8SKumar Sanghvi FW_RI_INIT_P2PTYPE_READ_REQ ? 1032d2fe99e8SKumar Sanghvi MPA_V2_RDMA_READ_RTR : 0) : 0)); 1033d2fe99e8SKumar Sanghvi memcpy(mpa->private_data, &mpa_v2_params, 1034d2fe99e8SKumar Sanghvi sizeof(struct mpa_v2_conn_params)); 1035d2fe99e8SKumar Sanghvi 1036d2fe99e8SKumar Sanghvi if (ep->plen) 1037d2fe99e8SKumar Sanghvi memcpy(mpa->private_data + 1038d2fe99e8SKumar Sanghvi sizeof(struct mpa_v2_conn_params), pdata, plen); 1039d2fe99e8SKumar Sanghvi } else 1040cfdda9d7SSteve Wise if (plen) 1041cfdda9d7SSteve Wise memcpy(mpa->private_data, pdata, plen); 1042cfdda9d7SSteve Wise 1043cfdda9d7SSteve Wise /* 1044cfdda9d7SSteve Wise * Reference the mpa skb again. This ensures the data area 1045cfdda9d7SSteve Wise * will remain in memory until the hw acks the tx. 1046cfdda9d7SSteve Wise * Function fw4_ack() will deref it. 1047cfdda9d7SSteve Wise */ 1048cfdda9d7SSteve Wise skb_get(skb); 1049cfdda9d7SSteve Wise set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx); 1050cfdda9d7SSteve Wise BUG_ON(ep->mpa_skb); 1051cfdda9d7SSteve Wise ep->mpa_skb = skb; 10529c88aa00SSteve Wise ep->snd_seq += mpalen; 1053cfdda9d7SSteve Wise return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t); 1054cfdda9d7SSteve Wise } 1055cfdda9d7SSteve Wise 1056cfdda9d7SSteve Wise static int send_mpa_reply(struct c4iw_ep *ep, const void *pdata, u8 plen) 1057cfdda9d7SSteve Wise { 1058cfdda9d7SSteve Wise int mpalen, wrlen; 1059cfdda9d7SSteve Wise struct fw_ofld_tx_data_wr *req; 1060cfdda9d7SSteve Wise struct mpa_message *mpa; 1061cfdda9d7SSteve Wise struct sk_buff *skb; 1062d2fe99e8SKumar Sanghvi struct mpa_v2_conn_params mpa_v2_params; 1063cfdda9d7SSteve Wise 1064cfdda9d7SSteve Wise PDBG("%s ep %p tid %u pd_len %d\n", __func__, ep, ep->hwtid, ep->plen); 1065cfdda9d7SSteve Wise 1066cfdda9d7SSteve Wise mpalen = sizeof(*mpa) + plen; 1067d2fe99e8SKumar Sanghvi if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) 1068d2fe99e8SKumar Sanghvi mpalen += sizeof(struct mpa_v2_conn_params); 1069cfdda9d7SSteve Wise wrlen = roundup(mpalen + sizeof *req, 16); 1070cfdda9d7SSteve Wise 1071cfdda9d7SSteve Wise skb = get_skb(NULL, wrlen, GFP_KERNEL); 1072cfdda9d7SSteve Wise if (!skb) { 1073cfdda9d7SSteve Wise printk(KERN_ERR MOD "%s - cannot alloc skb!\n", __func__); 1074cfdda9d7SSteve Wise return -ENOMEM; 1075cfdda9d7SSteve Wise } 1076cfdda9d7SSteve Wise set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx); 1077cfdda9d7SSteve Wise 1078cfdda9d7SSteve Wise req = (struct fw_ofld_tx_data_wr *) skb_put(skb, wrlen); 1079cfdda9d7SSteve Wise memset(req, 0, wrlen); 1080cfdda9d7SSteve Wise req->op_to_immdlen = cpu_to_be32( 1081e2ac9628SHariprasad Shenai FW_WR_OP_V(FW_OFLD_TX_DATA_WR) | 1082e2ac9628SHariprasad Shenai FW_WR_COMPL_F | 1083e2ac9628SHariprasad Shenai FW_WR_IMMDLEN_V(mpalen)); 1084cfdda9d7SSteve Wise req->flowid_len16 = cpu_to_be32( 1085e2ac9628SHariprasad Shenai FW_WR_FLOWID_V(ep->hwtid) | 1086e2ac9628SHariprasad Shenai FW_WR_LEN16_V(wrlen >> 4)); 1087cfdda9d7SSteve Wise req->plen = cpu_to_be32(mpalen); 1088cfdda9d7SSteve Wise req->tunnel_to_proxy = cpu_to_be32( 1089e2ac9628SHariprasad Shenai FW_OFLD_TX_DATA_WR_FLUSH_F | 1090e2ac9628SHariprasad Shenai FW_OFLD_TX_DATA_WR_SHOVE_F); 1091cfdda9d7SSteve Wise 1092cfdda9d7SSteve Wise mpa = (struct mpa_message *)(req + 1); 1093cfdda9d7SSteve Wise memset(mpa, 0, sizeof(*mpa)); 1094cfdda9d7SSteve Wise memcpy(mpa->key, MPA_KEY_REP, sizeof(mpa->key)); 1095cfdda9d7SSteve Wise mpa->flags = (ep->mpa_attr.crc_enabled ? MPA_CRC : 0) | 1096cfdda9d7SSteve Wise (markers_enabled ? MPA_MARKERS : 0); 1097d2fe99e8SKumar Sanghvi mpa->revision = ep->mpa_attr.version; 1098cfdda9d7SSteve Wise mpa->private_data_size = htons(plen); 1099d2fe99e8SKumar Sanghvi 1100d2fe99e8SKumar Sanghvi if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) { 1101d2fe99e8SKumar Sanghvi mpa->flags |= MPA_ENHANCED_RDMA_CONN; 1102f747c34aSRoland Dreier mpa->private_data_size = htons(ntohs(mpa->private_data_size) + 1103f747c34aSRoland Dreier sizeof (struct mpa_v2_conn_params)); 1104d2fe99e8SKumar Sanghvi mpa_v2_params.ird = htons((u16)ep->ird); 1105d2fe99e8SKumar Sanghvi mpa_v2_params.ord = htons((u16)ep->ord); 1106d2fe99e8SKumar Sanghvi if (peer2peer && (ep->mpa_attr.p2p_type != 1107d2fe99e8SKumar Sanghvi FW_RI_INIT_P2PTYPE_DISABLED)) { 1108d2fe99e8SKumar Sanghvi mpa_v2_params.ird |= htons(MPA_V2_PEER2PEER_MODEL); 1109d2fe99e8SKumar Sanghvi 1110d2fe99e8SKumar Sanghvi if (p2p_type == FW_RI_INIT_P2PTYPE_RDMA_WRITE) 1111d2fe99e8SKumar Sanghvi mpa_v2_params.ord |= 1112d2fe99e8SKumar Sanghvi htons(MPA_V2_RDMA_WRITE_RTR); 1113d2fe99e8SKumar Sanghvi else if (p2p_type == FW_RI_INIT_P2PTYPE_READ_REQ) 1114d2fe99e8SKumar Sanghvi mpa_v2_params.ord |= 1115d2fe99e8SKumar Sanghvi htons(MPA_V2_RDMA_READ_RTR); 1116d2fe99e8SKumar Sanghvi } 1117d2fe99e8SKumar Sanghvi 1118d2fe99e8SKumar Sanghvi memcpy(mpa->private_data, &mpa_v2_params, 1119d2fe99e8SKumar Sanghvi sizeof(struct mpa_v2_conn_params)); 1120d2fe99e8SKumar Sanghvi 1121d2fe99e8SKumar Sanghvi if (ep->plen) 1122d2fe99e8SKumar Sanghvi memcpy(mpa->private_data + 1123d2fe99e8SKumar Sanghvi sizeof(struct mpa_v2_conn_params), pdata, plen); 1124d2fe99e8SKumar Sanghvi } else 1125cfdda9d7SSteve Wise if (plen) 1126cfdda9d7SSteve Wise memcpy(mpa->private_data, pdata, plen); 1127cfdda9d7SSteve Wise 1128cfdda9d7SSteve Wise /* 1129cfdda9d7SSteve Wise * Reference the mpa skb. This ensures the data area 1130cfdda9d7SSteve Wise * will remain in memory until the hw acks the tx. 1131cfdda9d7SSteve Wise * Function fw4_ack() will deref it. 1132cfdda9d7SSteve Wise */ 1133cfdda9d7SSteve Wise skb_get(skb); 1134cfdda9d7SSteve Wise ep->mpa_skb = skb; 1135a7db89ebSSteve Wise __state_set(&ep->com, MPA_REP_SENT); 11369c88aa00SSteve Wise ep->snd_seq += mpalen; 1137cfdda9d7SSteve Wise return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t); 1138cfdda9d7SSteve Wise } 1139cfdda9d7SSteve Wise 1140cfdda9d7SSteve Wise static int act_establish(struct c4iw_dev *dev, struct sk_buff *skb) 1141cfdda9d7SSteve Wise { 1142cfdda9d7SSteve Wise struct c4iw_ep *ep; 1143cfdda9d7SSteve Wise struct cpl_act_establish *req = cplhdr(skb); 1144cfdda9d7SSteve Wise unsigned int tid = GET_TID(req); 11456c53e938SHariprasad Shenai unsigned int atid = TID_TID_G(ntohl(req->tos_atid)); 1146cfdda9d7SSteve Wise struct tid_info *t = dev->rdev.lldi.tids; 1147fef4422dSHariprasad S int ret; 1148cfdda9d7SSteve Wise 1149cfdda9d7SSteve Wise ep = lookup_atid(t, atid); 1150cfdda9d7SSteve Wise 1151cfdda9d7SSteve Wise PDBG("%s ep %p tid %u snd_isn %u rcv_isn %u\n", __func__, ep, tid, 1152cfdda9d7SSteve Wise be32_to_cpu(req->snd_isn), be32_to_cpu(req->rcv_isn)); 1153cfdda9d7SSteve Wise 1154a7db89ebSSteve Wise mutex_lock(&ep->com.mutex); 1155cfdda9d7SSteve Wise dst_confirm(ep->dst); 1156cfdda9d7SSteve Wise 1157cfdda9d7SSteve Wise /* setup the hwtid for this connection */ 1158cfdda9d7SSteve Wise ep->hwtid = tid; 1159cfdda9d7SSteve Wise cxgb4_insert_tid(t, ep, tid); 1160793dad94SVipul Pandya insert_handle(dev, &dev->hwtid_idr, ep, ep->hwtid); 1161cfdda9d7SSteve Wise 1162cfdda9d7SSteve Wise ep->snd_seq = be32_to_cpu(req->snd_isn); 1163cfdda9d7SSteve Wise ep->rcv_seq = be32_to_cpu(req->rcv_isn); 1164cfdda9d7SSteve Wise 1165cfdda9d7SSteve Wise set_emss(ep, ntohs(req->tcp_opt)); 1166cfdda9d7SSteve Wise 1167cfdda9d7SSteve Wise /* dealloc the atid */ 1168793dad94SVipul Pandya remove_handle(ep->com.dev, &ep->com.dev->atid_idr, atid); 1169cfdda9d7SSteve Wise cxgb4_free_atid(t, atid); 1170793dad94SVipul Pandya set_bit(ACT_ESTAB, &ep->com.history); 1171cfdda9d7SSteve Wise 1172cfdda9d7SSteve Wise /* start MPA negotiation */ 1173fef4422dSHariprasad S ret = send_flowc(ep, NULL); 1174fef4422dSHariprasad S if (ret) 1175fef4422dSHariprasad S goto err; 1176d2fe99e8SKumar Sanghvi if (ep->retry_with_mpa_v1) 1177d2fe99e8SKumar Sanghvi send_mpa_req(ep, skb, 1); 1178d2fe99e8SKumar Sanghvi else 1179d2fe99e8SKumar Sanghvi send_mpa_req(ep, skb, mpa_rev); 1180a7db89ebSSteve Wise mutex_unlock(&ep->com.mutex); 1181cfdda9d7SSteve Wise return 0; 1182fef4422dSHariprasad S err: 1183fef4422dSHariprasad S mutex_unlock(&ep->com.mutex); 1184fef4422dSHariprasad S connect_reply_upcall(ep, -ENOMEM); 1185fef4422dSHariprasad S c4iw_ep_disconnect(ep, 0, GFP_KERNEL); 1186fef4422dSHariprasad S return 0; 1187cfdda9d7SSteve Wise } 1188cfdda9d7SSteve Wise 1189be13b2dfSSteve Wise static void close_complete_upcall(struct c4iw_ep *ep, int status) 1190cfdda9d7SSteve Wise { 1191cfdda9d7SSteve Wise struct iw_cm_event event; 1192cfdda9d7SSteve Wise 1193cfdda9d7SSteve Wise PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid); 1194cfdda9d7SSteve Wise memset(&event, 0, sizeof(event)); 1195cfdda9d7SSteve Wise event.event = IW_CM_EVENT_CLOSE; 1196be13b2dfSSteve Wise event.status = status; 1197cfdda9d7SSteve Wise if (ep->com.cm_id) { 1198cfdda9d7SSteve Wise PDBG("close complete delivered ep %p cm_id %p tid %u\n", 1199cfdda9d7SSteve Wise ep, ep->com.cm_id, ep->hwtid); 1200cfdda9d7SSteve Wise ep->com.cm_id->event_handler(ep->com.cm_id, &event); 12019ca6f7cfSHariprasad S deref_cm_id(&ep->com); 1202793dad94SVipul Pandya set_bit(CLOSE_UPCALL, &ep->com.history); 1203cfdda9d7SSteve Wise } 1204cfdda9d7SSteve Wise } 1205cfdda9d7SSteve Wise 1206cfdda9d7SSteve Wise static void peer_close_upcall(struct c4iw_ep *ep) 1207cfdda9d7SSteve Wise { 1208cfdda9d7SSteve Wise struct iw_cm_event event; 1209cfdda9d7SSteve Wise 1210cfdda9d7SSteve Wise PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid); 1211cfdda9d7SSteve Wise memset(&event, 0, sizeof(event)); 1212cfdda9d7SSteve Wise event.event = IW_CM_EVENT_DISCONNECT; 1213cfdda9d7SSteve Wise if (ep->com.cm_id) { 1214cfdda9d7SSteve Wise PDBG("peer close delivered ep %p cm_id %p tid %u\n", 1215cfdda9d7SSteve Wise ep, ep->com.cm_id, ep->hwtid); 1216cfdda9d7SSteve Wise ep->com.cm_id->event_handler(ep->com.cm_id, &event); 1217793dad94SVipul Pandya set_bit(DISCONN_UPCALL, &ep->com.history); 1218cfdda9d7SSteve Wise } 1219cfdda9d7SSteve Wise } 1220cfdda9d7SSteve Wise 1221cfdda9d7SSteve Wise static void peer_abort_upcall(struct c4iw_ep *ep) 1222cfdda9d7SSteve Wise { 1223cfdda9d7SSteve Wise struct iw_cm_event event; 1224cfdda9d7SSteve Wise 1225cfdda9d7SSteve Wise PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid); 1226cfdda9d7SSteve Wise memset(&event, 0, sizeof(event)); 1227cfdda9d7SSteve Wise event.event = IW_CM_EVENT_CLOSE; 1228cfdda9d7SSteve Wise event.status = -ECONNRESET; 1229cfdda9d7SSteve Wise if (ep->com.cm_id) { 1230cfdda9d7SSteve Wise PDBG("abort delivered ep %p cm_id %p tid %u\n", ep, 1231cfdda9d7SSteve Wise ep->com.cm_id, ep->hwtid); 1232cfdda9d7SSteve Wise ep->com.cm_id->event_handler(ep->com.cm_id, &event); 12339ca6f7cfSHariprasad S deref_cm_id(&ep->com); 1234793dad94SVipul Pandya set_bit(ABORT_UPCALL, &ep->com.history); 1235cfdda9d7SSteve Wise } 1236cfdda9d7SSteve Wise } 1237cfdda9d7SSteve Wise 1238cfdda9d7SSteve Wise static void connect_reply_upcall(struct c4iw_ep *ep, int status) 1239cfdda9d7SSteve Wise { 1240cfdda9d7SSteve Wise struct iw_cm_event event; 1241cfdda9d7SSteve Wise 1242cfdda9d7SSteve Wise PDBG("%s ep %p tid %u status %d\n", __func__, ep, ep->hwtid, status); 1243cfdda9d7SSteve Wise memset(&event, 0, sizeof(event)); 1244cfdda9d7SSteve Wise event.event = IW_CM_EVENT_CONNECT_REPLY; 1245cfdda9d7SSteve Wise event.status = status; 124624d44a39SSteve Wise memcpy(&event.local_addr, &ep->com.local_addr, 124724d44a39SSteve Wise sizeof(ep->com.local_addr)); 124824d44a39SSteve Wise memcpy(&event.remote_addr, &ep->com.remote_addr, 124924d44a39SSteve Wise sizeof(ep->com.remote_addr)); 1250cfdda9d7SSteve Wise 1251cfdda9d7SSteve Wise if ((status == 0) || (status == -ECONNREFUSED)) { 1252d2fe99e8SKumar Sanghvi if (!ep->tried_with_mpa_v1) { 1253d2fe99e8SKumar Sanghvi /* this means MPA_v2 is used */ 1254158c776dSHariprasad S event.ord = ep->ird; 1255158c776dSHariprasad S event.ird = ep->ord; 1256d2fe99e8SKumar Sanghvi event.private_data_len = ep->plen - 1257d2fe99e8SKumar Sanghvi sizeof(struct mpa_v2_conn_params); 1258d2fe99e8SKumar Sanghvi event.private_data = ep->mpa_pkt + 1259d2fe99e8SKumar Sanghvi sizeof(struct mpa_message) + 1260d2fe99e8SKumar Sanghvi sizeof(struct mpa_v2_conn_params); 1261d2fe99e8SKumar Sanghvi } else { 1262d2fe99e8SKumar Sanghvi /* this means MPA_v1 is used */ 1263158c776dSHariprasad S event.ord = cur_max_read_depth(ep->com.dev); 1264158c776dSHariprasad S event.ird = cur_max_read_depth(ep->com.dev); 1265cfdda9d7SSteve Wise event.private_data_len = ep->plen; 1266d2fe99e8SKumar Sanghvi event.private_data = ep->mpa_pkt + 1267d2fe99e8SKumar Sanghvi sizeof(struct mpa_message); 1268d2fe99e8SKumar Sanghvi } 1269cfdda9d7SSteve Wise } 127085963e4cSRoland Dreier 1271cfdda9d7SSteve Wise PDBG("%s ep %p tid %u status %d\n", __func__, ep, 1272cfdda9d7SSteve Wise ep->hwtid, status); 1273793dad94SVipul Pandya set_bit(CONN_RPL_UPCALL, &ep->com.history); 1274cfdda9d7SSteve Wise ep->com.cm_id->event_handler(ep->com.cm_id, &event); 127585963e4cSRoland Dreier 12769ca6f7cfSHariprasad S if (status < 0) 12779ca6f7cfSHariprasad S deref_cm_id(&ep->com); 1278cfdda9d7SSteve Wise } 1279cfdda9d7SSteve Wise 1280be13b2dfSSteve Wise static int connect_request_upcall(struct c4iw_ep *ep) 1281cfdda9d7SSteve Wise { 1282cfdda9d7SSteve Wise struct iw_cm_event event; 1283be13b2dfSSteve Wise int ret; 1284cfdda9d7SSteve Wise 1285cfdda9d7SSteve Wise PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid); 1286cfdda9d7SSteve Wise memset(&event, 0, sizeof(event)); 1287cfdda9d7SSteve Wise event.event = IW_CM_EVENT_CONNECT_REQUEST; 128824d44a39SSteve Wise memcpy(&event.local_addr, &ep->com.local_addr, 128924d44a39SSteve Wise sizeof(ep->com.local_addr)); 129024d44a39SSteve Wise memcpy(&event.remote_addr, &ep->com.remote_addr, 129124d44a39SSteve Wise sizeof(ep->com.remote_addr)); 1292d2fe99e8SKumar Sanghvi event.provider_data = ep; 1293d2fe99e8SKumar Sanghvi if (!ep->tried_with_mpa_v1) { 1294d2fe99e8SKumar Sanghvi /* this means MPA_v2 is used */ 1295d2fe99e8SKumar Sanghvi event.ord = ep->ord; 1296d2fe99e8SKumar Sanghvi event.ird = ep->ird; 1297d2fe99e8SKumar Sanghvi event.private_data_len = ep->plen - 1298d2fe99e8SKumar Sanghvi sizeof(struct mpa_v2_conn_params); 1299d2fe99e8SKumar Sanghvi event.private_data = ep->mpa_pkt + sizeof(struct mpa_message) + 1300d2fe99e8SKumar Sanghvi sizeof(struct mpa_v2_conn_params); 1301d2fe99e8SKumar Sanghvi } else { 1302d2fe99e8SKumar Sanghvi /* this means MPA_v1 is used. Send max supported */ 13034c2c5763SHariprasad Shenai event.ord = cur_max_read_depth(ep->com.dev); 13044c2c5763SHariprasad Shenai event.ird = cur_max_read_depth(ep->com.dev); 1305cfdda9d7SSteve Wise event.private_data_len = ep->plen; 1306cfdda9d7SSteve Wise event.private_data = ep->mpa_pkt + sizeof(struct mpa_message); 1307d2fe99e8SKumar Sanghvi } 1308cfdda9d7SSteve Wise c4iw_get_ep(&ep->com); 1309be13b2dfSSteve Wise ret = ep->parent_ep->com.cm_id->event_handler(ep->parent_ep->com.cm_id, 1310cfdda9d7SSteve Wise &event); 1311be13b2dfSSteve Wise if (ret) 1312be13b2dfSSteve Wise c4iw_put_ep(&ep->com); 1313793dad94SVipul Pandya set_bit(CONNREQ_UPCALL, &ep->com.history); 1314cfdda9d7SSteve Wise c4iw_put_ep(&ep->parent_ep->com); 1315be13b2dfSSteve Wise return ret; 1316cfdda9d7SSteve Wise } 1317cfdda9d7SSteve Wise 1318cfdda9d7SSteve Wise static void established_upcall(struct c4iw_ep *ep) 1319cfdda9d7SSteve Wise { 1320cfdda9d7SSteve Wise struct iw_cm_event event; 1321cfdda9d7SSteve Wise 1322cfdda9d7SSteve Wise PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid); 1323cfdda9d7SSteve Wise memset(&event, 0, sizeof(event)); 1324cfdda9d7SSteve Wise event.event = IW_CM_EVENT_ESTABLISHED; 13253dd9a5dcSHariprasad S event.ird = ep->ord; 13263dd9a5dcSHariprasad S event.ord = ep->ird; 1327cfdda9d7SSteve Wise if (ep->com.cm_id) { 1328cfdda9d7SSteve Wise PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid); 1329cfdda9d7SSteve Wise ep->com.cm_id->event_handler(ep->com.cm_id, &event); 1330793dad94SVipul Pandya set_bit(ESTAB_UPCALL, &ep->com.history); 1331cfdda9d7SSteve Wise } 1332cfdda9d7SSteve Wise } 1333cfdda9d7SSteve Wise 1334cfdda9d7SSteve Wise static int update_rx_credits(struct c4iw_ep *ep, u32 credits) 1335cfdda9d7SSteve Wise { 1336cfdda9d7SSteve Wise struct cpl_rx_data_ack *req; 1337cfdda9d7SSteve Wise struct sk_buff *skb; 1338cfdda9d7SSteve Wise int wrlen = roundup(sizeof *req, 16); 1339cfdda9d7SSteve Wise 1340cfdda9d7SSteve Wise PDBG("%s ep %p tid %u credits %u\n", __func__, ep, ep->hwtid, credits); 1341cfdda9d7SSteve Wise skb = get_skb(NULL, wrlen, GFP_KERNEL); 1342cfdda9d7SSteve Wise if (!skb) { 1343cfdda9d7SSteve Wise printk(KERN_ERR MOD "update_rx_credits - cannot alloc skb!\n"); 1344cfdda9d7SSteve Wise return 0; 1345cfdda9d7SSteve Wise } 1346cfdda9d7SSteve Wise 1347b408ff28SHariprasad Shenai /* 1348b408ff28SHariprasad Shenai * If we couldn't specify the entire rcv window at connection setup 1349b408ff28SHariprasad Shenai * due to the limit in the number of bits in the RCV_BUFSIZ field, 1350b408ff28SHariprasad Shenai * then add the overage in to the credits returned. 1351b408ff28SHariprasad Shenai */ 1352d7990b0cSAnish Bhatt if (ep->rcv_win > RCV_BUFSIZ_M * 1024) 1353d7990b0cSAnish Bhatt credits += ep->rcv_win - RCV_BUFSIZ_M * 1024; 1354b408ff28SHariprasad Shenai 1355cfdda9d7SSteve Wise req = (struct cpl_rx_data_ack *) skb_put(skb, wrlen); 1356cfdda9d7SSteve Wise memset(req, 0, wrlen); 1357cfdda9d7SSteve Wise INIT_TP_WR(req, ep->hwtid); 1358cfdda9d7SSteve Wise OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_RX_DATA_ACK, 1359cfdda9d7SSteve Wise ep->hwtid)); 1360d7990b0cSAnish Bhatt req->credit_dack = cpu_to_be32(credits | RX_FORCE_ACK_F | 1361cf7fe64aSHariprasad Shenai RX_DACK_CHANGE_F | 1362cf7fe64aSHariprasad Shenai RX_DACK_MODE_V(dack_mode)); 1363d4f1a5c6SSteve Wise set_wr_txq(skb, CPL_PRIORITY_ACK, ep->ctrlq_idx); 1364cfdda9d7SSteve Wise c4iw_ofld_send(&ep->com.dev->rdev, skb); 1365cfdda9d7SSteve Wise return credits; 1366cfdda9d7SSteve Wise } 1367cfdda9d7SSteve Wise 13684c2c5763SHariprasad Shenai #define RELAXED_IRD_NEGOTIATION 1 13694c2c5763SHariprasad Shenai 1370f8e1e1d1SHariprasad S /* 1371f8e1e1d1SHariprasad S * process_mpa_reply - process streaming mode MPA reply 1372f8e1e1d1SHariprasad S * 1373f8e1e1d1SHariprasad S * Returns: 1374f8e1e1d1SHariprasad S * 1375f8e1e1d1SHariprasad S * 0 upon success indicating a connect request was delivered to the ULP 1376f8e1e1d1SHariprasad S * or the mpa request is incomplete but valid so far. 1377f8e1e1d1SHariprasad S * 1378f8e1e1d1SHariprasad S * 1 if a failure requires the caller to close the connection. 1379f8e1e1d1SHariprasad S * 1380f8e1e1d1SHariprasad S * 2 if a failure requires the caller to abort the connection. 1381f8e1e1d1SHariprasad S */ 1382cc18b939SSteve Wise static int process_mpa_reply(struct c4iw_ep *ep, struct sk_buff *skb) 1383cfdda9d7SSteve Wise { 1384cfdda9d7SSteve Wise struct mpa_message *mpa; 1385d2fe99e8SKumar Sanghvi struct mpa_v2_conn_params *mpa_v2_params; 1386cfdda9d7SSteve Wise u16 plen; 1387d2fe99e8SKumar Sanghvi u16 resp_ird, resp_ord; 1388d2fe99e8SKumar Sanghvi u8 rtr_mismatch = 0, insuff_ird = 0; 1389cfdda9d7SSteve Wise struct c4iw_qp_attributes attrs; 1390cfdda9d7SSteve Wise enum c4iw_qp_attr_mask mask; 1391cfdda9d7SSteve Wise int err; 1392cc18b939SSteve Wise int disconnect = 0; 1393cfdda9d7SSteve Wise 1394cfdda9d7SSteve Wise PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid); 1395cfdda9d7SSteve Wise 1396cfdda9d7SSteve Wise /* 1397cfdda9d7SSteve Wise * If we get more than the supported amount of private data 1398cfdda9d7SSteve Wise * then we must fail this connection. 1399cfdda9d7SSteve Wise */ 1400cfdda9d7SSteve Wise if (ep->mpa_pkt_len + skb->len > sizeof(ep->mpa_pkt)) { 1401cfdda9d7SSteve Wise err = -EINVAL; 1402da1cecdfSHariprasad S goto err_stop_timer; 1403cfdda9d7SSteve Wise } 1404cfdda9d7SSteve Wise 1405cfdda9d7SSteve Wise /* 1406cfdda9d7SSteve Wise * copy the new data into our accumulation buffer. 1407cfdda9d7SSteve Wise */ 1408cfdda9d7SSteve Wise skb_copy_from_linear_data(skb, &(ep->mpa_pkt[ep->mpa_pkt_len]), 1409cfdda9d7SSteve Wise skb->len); 1410cfdda9d7SSteve Wise ep->mpa_pkt_len += skb->len; 1411cfdda9d7SSteve Wise 1412cfdda9d7SSteve Wise /* 1413cfdda9d7SSteve Wise * if we don't even have the mpa message, then bail. 1414cfdda9d7SSteve Wise */ 1415cfdda9d7SSteve Wise if (ep->mpa_pkt_len < sizeof(*mpa)) 1416cc18b939SSteve Wise return 0; 1417cfdda9d7SSteve Wise mpa = (struct mpa_message *) ep->mpa_pkt; 1418cfdda9d7SSteve Wise 1419cfdda9d7SSteve Wise /* Validate MPA header. */ 1420d2fe99e8SKumar Sanghvi if (mpa->revision > mpa_rev) { 1421d2fe99e8SKumar Sanghvi printk(KERN_ERR MOD "%s MPA version mismatch. Local = %d," 1422d2fe99e8SKumar Sanghvi " Received = %d\n", __func__, mpa_rev, mpa->revision); 1423cfdda9d7SSteve Wise err = -EPROTO; 1424da1cecdfSHariprasad S goto err_stop_timer; 1425cfdda9d7SSteve Wise } 1426cfdda9d7SSteve Wise if (memcmp(mpa->key, MPA_KEY_REP, sizeof(mpa->key))) { 1427cfdda9d7SSteve Wise err = -EPROTO; 1428da1cecdfSHariprasad S goto err_stop_timer; 1429cfdda9d7SSteve Wise } 1430cfdda9d7SSteve Wise 1431cfdda9d7SSteve Wise plen = ntohs(mpa->private_data_size); 1432cfdda9d7SSteve Wise 1433cfdda9d7SSteve Wise /* 1434cfdda9d7SSteve Wise * Fail if there's too much private data. 1435cfdda9d7SSteve Wise */ 1436cfdda9d7SSteve Wise if (plen > MPA_MAX_PRIVATE_DATA) { 1437cfdda9d7SSteve Wise err = -EPROTO; 1438da1cecdfSHariprasad S goto err_stop_timer; 1439cfdda9d7SSteve Wise } 1440cfdda9d7SSteve Wise 1441cfdda9d7SSteve Wise /* 1442cfdda9d7SSteve Wise * If plen does not account for pkt size 1443cfdda9d7SSteve Wise */ 1444cfdda9d7SSteve Wise if (ep->mpa_pkt_len > (sizeof(*mpa) + plen)) { 1445cfdda9d7SSteve Wise err = -EPROTO; 1446da1cecdfSHariprasad S goto err_stop_timer; 1447cfdda9d7SSteve Wise } 1448cfdda9d7SSteve Wise 1449cfdda9d7SSteve Wise ep->plen = (u8) plen; 1450cfdda9d7SSteve Wise 1451cfdda9d7SSteve Wise /* 1452cfdda9d7SSteve Wise * If we don't have all the pdata yet, then bail. 1453cfdda9d7SSteve Wise * We'll continue process when more data arrives. 1454cfdda9d7SSteve Wise */ 1455cfdda9d7SSteve Wise if (ep->mpa_pkt_len < (sizeof(*mpa) + plen)) 1456cc18b939SSteve Wise return 0; 1457cfdda9d7SSteve Wise 1458cfdda9d7SSteve Wise if (mpa->flags & MPA_REJECT) { 1459cfdda9d7SSteve Wise err = -ECONNREFUSED; 1460da1cecdfSHariprasad S goto err_stop_timer; 1461cfdda9d7SSteve Wise } 1462cfdda9d7SSteve Wise 1463cfdda9d7SSteve Wise /* 1464da1cecdfSHariprasad S * Stop mpa timer. If it expired, then 1465da1cecdfSHariprasad S * we ignore the MPA reply. process_timeout() 1466da1cecdfSHariprasad S * will abort the connection. 1467da1cecdfSHariprasad S */ 1468da1cecdfSHariprasad S if (stop_ep_timer(ep)) 1469da1cecdfSHariprasad S return 0; 1470da1cecdfSHariprasad S 1471da1cecdfSHariprasad S /* 1472cfdda9d7SSteve Wise * If we get here we have accumulated the entire mpa 1473cfdda9d7SSteve Wise * start reply message including private data. And 1474cfdda9d7SSteve Wise * the MPA header is valid. 1475cfdda9d7SSteve Wise */ 1476c529fb50SSteve Wise __state_set(&ep->com, FPDU_MODE); 1477cfdda9d7SSteve Wise ep->mpa_attr.crc_enabled = (mpa->flags & MPA_CRC) | crc_enabled ? 1 : 0; 1478cfdda9d7SSteve Wise ep->mpa_attr.recv_marker_enabled = markers_enabled; 1479cfdda9d7SSteve Wise ep->mpa_attr.xmit_marker_enabled = mpa->flags & MPA_MARKERS ? 1 : 0; 1480d2fe99e8SKumar Sanghvi ep->mpa_attr.version = mpa->revision; 1481d2fe99e8SKumar Sanghvi ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED; 1482d2fe99e8SKumar Sanghvi 1483d2fe99e8SKumar Sanghvi if (mpa->revision == 2) { 1484d2fe99e8SKumar Sanghvi ep->mpa_attr.enhanced_rdma_conn = 1485d2fe99e8SKumar Sanghvi mpa->flags & MPA_ENHANCED_RDMA_CONN ? 1 : 0; 1486d2fe99e8SKumar Sanghvi if (ep->mpa_attr.enhanced_rdma_conn) { 1487d2fe99e8SKumar Sanghvi mpa_v2_params = (struct mpa_v2_conn_params *) 1488d2fe99e8SKumar Sanghvi (ep->mpa_pkt + sizeof(*mpa)); 1489d2fe99e8SKumar Sanghvi resp_ird = ntohs(mpa_v2_params->ird) & 1490d2fe99e8SKumar Sanghvi MPA_V2_IRD_ORD_MASK; 1491d2fe99e8SKumar Sanghvi resp_ord = ntohs(mpa_v2_params->ord) & 1492d2fe99e8SKumar Sanghvi MPA_V2_IRD_ORD_MASK; 14934c2c5763SHariprasad Shenai PDBG("%s responder ird %u ord %u ep ird %u ord %u\n", 14944c2c5763SHariprasad Shenai __func__, resp_ird, resp_ord, ep->ird, ep->ord); 1495d2fe99e8SKumar Sanghvi 1496d2fe99e8SKumar Sanghvi /* 1497d2fe99e8SKumar Sanghvi * This is a double-check. Ideally, below checks are 1498d2fe99e8SKumar Sanghvi * not required since ird/ord stuff has been taken 1499d2fe99e8SKumar Sanghvi * care of in c4iw_accept_cr 1500d2fe99e8SKumar Sanghvi */ 15014c2c5763SHariprasad Shenai if (ep->ird < resp_ord) { 15024c2c5763SHariprasad Shenai if (RELAXED_IRD_NEGOTIATION && resp_ord <= 15034c2c5763SHariprasad Shenai ep->com.dev->rdev.lldi.max_ordird_qp) 15044c2c5763SHariprasad Shenai ep->ird = resp_ord; 15054c2c5763SHariprasad Shenai else 15064c2c5763SHariprasad Shenai insuff_ird = 1; 15074c2c5763SHariprasad Shenai } else if (ep->ird > resp_ord) { 15084c2c5763SHariprasad Shenai ep->ird = resp_ord; 15094c2c5763SHariprasad Shenai } 15104c2c5763SHariprasad Shenai if (ep->ord > resp_ird) { 15114c2c5763SHariprasad Shenai if (RELAXED_IRD_NEGOTIATION) 15124c2c5763SHariprasad Shenai ep->ord = resp_ird; 15134c2c5763SHariprasad Shenai else 15144c2c5763SHariprasad Shenai insuff_ird = 1; 15154c2c5763SHariprasad Shenai } 15164c2c5763SHariprasad Shenai if (insuff_ird) { 1517d2fe99e8SKumar Sanghvi err = -ENOMEM; 1518d2fe99e8SKumar Sanghvi ep->ird = resp_ord; 1519d2fe99e8SKumar Sanghvi ep->ord = resp_ird; 1520d2fe99e8SKumar Sanghvi } 1521d2fe99e8SKumar Sanghvi 1522d2fe99e8SKumar Sanghvi if (ntohs(mpa_v2_params->ird) & 1523d2fe99e8SKumar Sanghvi MPA_V2_PEER2PEER_MODEL) { 1524d2fe99e8SKumar Sanghvi if (ntohs(mpa_v2_params->ord) & 1525d2fe99e8SKumar Sanghvi MPA_V2_RDMA_WRITE_RTR) 1526d2fe99e8SKumar Sanghvi ep->mpa_attr.p2p_type = 1527d2fe99e8SKumar Sanghvi FW_RI_INIT_P2PTYPE_RDMA_WRITE; 1528d2fe99e8SKumar Sanghvi else if (ntohs(mpa_v2_params->ord) & 1529d2fe99e8SKumar Sanghvi MPA_V2_RDMA_READ_RTR) 1530d2fe99e8SKumar Sanghvi ep->mpa_attr.p2p_type = 1531d2fe99e8SKumar Sanghvi FW_RI_INIT_P2PTYPE_READ_REQ; 1532d2fe99e8SKumar Sanghvi } 1533d2fe99e8SKumar Sanghvi } 1534d2fe99e8SKumar Sanghvi } else if (mpa->revision == 1) 1535d2fe99e8SKumar Sanghvi if (peer2peer) 1536d2fe99e8SKumar Sanghvi ep->mpa_attr.p2p_type = p2p_type; 1537d2fe99e8SKumar Sanghvi 1538cfdda9d7SSteve Wise PDBG("%s - crc_enabled=%d, recv_marker_enabled=%d, " 1539d2fe99e8SKumar Sanghvi "xmit_marker_enabled=%d, version=%d p2p_type=%d local-p2p_type = " 1540d2fe99e8SKumar Sanghvi "%d\n", __func__, ep->mpa_attr.crc_enabled, 1541d2fe99e8SKumar Sanghvi ep->mpa_attr.recv_marker_enabled, 1542d2fe99e8SKumar Sanghvi ep->mpa_attr.xmit_marker_enabled, ep->mpa_attr.version, 1543d2fe99e8SKumar Sanghvi ep->mpa_attr.p2p_type, p2p_type); 1544d2fe99e8SKumar Sanghvi 1545d2fe99e8SKumar Sanghvi /* 1546d2fe99e8SKumar Sanghvi * If responder's RTR does not match with that of initiator, assign 1547d2fe99e8SKumar Sanghvi * FW_RI_INIT_P2PTYPE_DISABLED in mpa attributes so that RTR is not 1548d2fe99e8SKumar Sanghvi * generated when moving QP to RTS state. 1549d2fe99e8SKumar Sanghvi * A TERM message will be sent after QP has moved to RTS state 1550d2fe99e8SKumar Sanghvi */ 155191018f86SKumar Sanghvi if ((ep->mpa_attr.version == 2) && peer2peer && 1552d2fe99e8SKumar Sanghvi (ep->mpa_attr.p2p_type != p2p_type)) { 1553d2fe99e8SKumar Sanghvi ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED; 1554d2fe99e8SKumar Sanghvi rtr_mismatch = 1; 1555d2fe99e8SKumar Sanghvi } 1556cfdda9d7SSteve Wise 1557cfdda9d7SSteve Wise attrs.mpa_attr = ep->mpa_attr; 1558cfdda9d7SSteve Wise attrs.max_ird = ep->ird; 1559cfdda9d7SSteve Wise attrs.max_ord = ep->ord; 1560cfdda9d7SSteve Wise attrs.llp_stream_handle = ep; 1561cfdda9d7SSteve Wise attrs.next_state = C4IW_QP_STATE_RTS; 1562cfdda9d7SSteve Wise 1563cfdda9d7SSteve Wise mask = C4IW_QP_ATTR_NEXT_STATE | 1564cfdda9d7SSteve Wise C4IW_QP_ATTR_LLP_STREAM_HANDLE | C4IW_QP_ATTR_MPA_ATTR | 1565cfdda9d7SSteve Wise C4IW_QP_ATTR_MAX_IRD | C4IW_QP_ATTR_MAX_ORD; 1566cfdda9d7SSteve Wise 1567cfdda9d7SSteve Wise /* bind QP and TID with INIT_WR */ 1568cfdda9d7SSteve Wise err = c4iw_modify_qp(ep->com.qp->rhp, 1569cfdda9d7SSteve Wise ep->com.qp, mask, &attrs, 1); 1570cfdda9d7SSteve Wise if (err) 1571cfdda9d7SSteve Wise goto err; 1572d2fe99e8SKumar Sanghvi 1573d2fe99e8SKumar Sanghvi /* 1574d2fe99e8SKumar Sanghvi * If responder's RTR requirement did not match with what initiator 1575d2fe99e8SKumar Sanghvi * supports, generate TERM message 1576d2fe99e8SKumar Sanghvi */ 1577d2fe99e8SKumar Sanghvi if (rtr_mismatch) { 1578d2fe99e8SKumar Sanghvi printk(KERN_ERR "%s: RTR mismatch, sending TERM\n", __func__); 1579d2fe99e8SKumar Sanghvi attrs.layer_etype = LAYER_MPA | DDP_LLP; 1580d2fe99e8SKumar Sanghvi attrs.ecode = MPA_NOMATCH_RTR; 1581d2fe99e8SKumar Sanghvi attrs.next_state = C4IW_QP_STATE_TERMINATE; 1582cc18b939SSteve Wise attrs.send_term = 1; 1583d2fe99e8SKumar Sanghvi err = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp, 1584cc18b939SSteve Wise C4IW_QP_ATTR_NEXT_STATE, &attrs, 1); 1585d2fe99e8SKumar Sanghvi err = -ENOMEM; 1586cc18b939SSteve Wise disconnect = 1; 1587d2fe99e8SKumar Sanghvi goto out; 1588d2fe99e8SKumar Sanghvi } 1589d2fe99e8SKumar Sanghvi 1590d2fe99e8SKumar Sanghvi /* 1591d2fe99e8SKumar Sanghvi * Generate TERM if initiator IRD is not sufficient for responder 1592d2fe99e8SKumar Sanghvi * provided ORD. Currently, we do the same behaviour even when 1593d2fe99e8SKumar Sanghvi * responder provided IRD is also not sufficient as regards to 1594d2fe99e8SKumar Sanghvi * initiator ORD. 1595d2fe99e8SKumar Sanghvi */ 1596d2fe99e8SKumar Sanghvi if (insuff_ird) { 1597d2fe99e8SKumar Sanghvi printk(KERN_ERR "%s: Insufficient IRD, sending TERM\n", 1598d2fe99e8SKumar Sanghvi __func__); 1599d2fe99e8SKumar Sanghvi attrs.layer_etype = LAYER_MPA | DDP_LLP; 1600d2fe99e8SKumar Sanghvi attrs.ecode = MPA_INSUFF_IRD; 1601d2fe99e8SKumar Sanghvi attrs.next_state = C4IW_QP_STATE_TERMINATE; 1602cc18b939SSteve Wise attrs.send_term = 1; 1603d2fe99e8SKumar Sanghvi err = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp, 1604cc18b939SSteve Wise C4IW_QP_ATTR_NEXT_STATE, &attrs, 1); 1605d2fe99e8SKumar Sanghvi err = -ENOMEM; 1606cc18b939SSteve Wise disconnect = 1; 1607d2fe99e8SKumar Sanghvi goto out; 1608d2fe99e8SKumar Sanghvi } 1609cfdda9d7SSteve Wise goto out; 1610da1cecdfSHariprasad S err_stop_timer: 1611da1cecdfSHariprasad S stop_ep_timer(ep); 1612cfdda9d7SSteve Wise err: 1613f8e1e1d1SHariprasad S disconnect = 2; 1614cfdda9d7SSteve Wise out: 1615cfdda9d7SSteve Wise connect_reply_upcall(ep, err); 1616cc18b939SSteve Wise return disconnect; 1617cfdda9d7SSteve Wise } 1618cfdda9d7SSteve Wise 1619fd6aabe4SHariprasad S /* 1620fd6aabe4SHariprasad S * process_mpa_request - process streaming mode MPA request 1621fd6aabe4SHariprasad S * 1622fd6aabe4SHariprasad S * Returns: 1623fd6aabe4SHariprasad S * 1624fd6aabe4SHariprasad S * 0 upon success indicating a connect request was delivered to the ULP 1625fd6aabe4SHariprasad S * or the mpa request is incomplete but valid so far. 1626fd6aabe4SHariprasad S * 1627fd6aabe4SHariprasad S * 1 if a failure requires the caller to close the connection. 1628fd6aabe4SHariprasad S * 1629fd6aabe4SHariprasad S * 2 if a failure requires the caller to abort the connection. 1630fd6aabe4SHariprasad S */ 1631fd6aabe4SHariprasad S static int process_mpa_request(struct c4iw_ep *ep, struct sk_buff *skb) 1632cfdda9d7SSteve Wise { 1633cfdda9d7SSteve Wise struct mpa_message *mpa; 1634d2fe99e8SKumar Sanghvi struct mpa_v2_conn_params *mpa_v2_params; 1635cfdda9d7SSteve Wise u16 plen; 1636cfdda9d7SSteve Wise 1637cfdda9d7SSteve Wise PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid); 1638cfdda9d7SSteve Wise 1639cfdda9d7SSteve Wise /* 1640cfdda9d7SSteve Wise * If we get more than the supported amount of private data 1641cfdda9d7SSteve Wise * then we must fail this connection. 1642cfdda9d7SSteve Wise */ 1643fd6aabe4SHariprasad S if (ep->mpa_pkt_len + skb->len > sizeof(ep->mpa_pkt)) 1644fd6aabe4SHariprasad S goto err_stop_timer; 1645cfdda9d7SSteve Wise 1646cfdda9d7SSteve Wise PDBG("%s enter (%s line %u)\n", __func__, __FILE__, __LINE__); 1647cfdda9d7SSteve Wise 1648cfdda9d7SSteve Wise /* 1649cfdda9d7SSteve Wise * Copy the new data into our accumulation buffer. 1650cfdda9d7SSteve Wise */ 1651cfdda9d7SSteve Wise skb_copy_from_linear_data(skb, &(ep->mpa_pkt[ep->mpa_pkt_len]), 1652cfdda9d7SSteve Wise skb->len); 1653cfdda9d7SSteve Wise ep->mpa_pkt_len += skb->len; 1654cfdda9d7SSteve Wise 1655cfdda9d7SSteve Wise /* 1656cfdda9d7SSteve Wise * If we don't even have the mpa message, then bail. 1657cfdda9d7SSteve Wise * We'll continue process when more data arrives. 1658cfdda9d7SSteve Wise */ 1659cfdda9d7SSteve Wise if (ep->mpa_pkt_len < sizeof(*mpa)) 1660fd6aabe4SHariprasad S return 0; 1661cfdda9d7SSteve Wise 1662cfdda9d7SSteve Wise PDBG("%s enter (%s line %u)\n", __func__, __FILE__, __LINE__); 1663cfdda9d7SSteve Wise mpa = (struct mpa_message *) ep->mpa_pkt; 1664cfdda9d7SSteve Wise 1665cfdda9d7SSteve Wise /* 1666cfdda9d7SSteve Wise * Validate MPA Header. 1667cfdda9d7SSteve Wise */ 1668d2fe99e8SKumar Sanghvi if (mpa->revision > mpa_rev) { 1669d2fe99e8SKumar Sanghvi printk(KERN_ERR MOD "%s MPA version mismatch. Local = %d," 1670d2fe99e8SKumar Sanghvi " Received = %d\n", __func__, mpa_rev, mpa->revision); 1671fd6aabe4SHariprasad S goto err_stop_timer; 1672cfdda9d7SSteve Wise } 1673cfdda9d7SSteve Wise 1674fd6aabe4SHariprasad S if (memcmp(mpa->key, MPA_KEY_REQ, sizeof(mpa->key))) 1675fd6aabe4SHariprasad S goto err_stop_timer; 1676cfdda9d7SSteve Wise 1677cfdda9d7SSteve Wise plen = ntohs(mpa->private_data_size); 1678cfdda9d7SSteve Wise 1679cfdda9d7SSteve Wise /* 1680cfdda9d7SSteve Wise * Fail if there's too much private data. 1681cfdda9d7SSteve Wise */ 1682fd6aabe4SHariprasad S if (plen > MPA_MAX_PRIVATE_DATA) 1683fd6aabe4SHariprasad S goto err_stop_timer; 1684cfdda9d7SSteve Wise 1685cfdda9d7SSteve Wise /* 1686cfdda9d7SSteve Wise * If plen does not account for pkt size 1687cfdda9d7SSteve Wise */ 1688fd6aabe4SHariprasad S if (ep->mpa_pkt_len > (sizeof(*mpa) + plen)) 1689fd6aabe4SHariprasad S goto err_stop_timer; 1690cfdda9d7SSteve Wise ep->plen = (u8) plen; 1691cfdda9d7SSteve Wise 1692cfdda9d7SSteve Wise /* 1693cfdda9d7SSteve Wise * If we don't have all the pdata yet, then bail. 1694cfdda9d7SSteve Wise */ 1695cfdda9d7SSteve Wise if (ep->mpa_pkt_len < (sizeof(*mpa) + plen)) 1696fd6aabe4SHariprasad S return 0; 1697cfdda9d7SSteve Wise 1698cfdda9d7SSteve Wise /* 1699cfdda9d7SSteve Wise * If we get here we have accumulated the entire mpa 1700cfdda9d7SSteve Wise * start reply message including private data. 1701cfdda9d7SSteve Wise */ 1702cfdda9d7SSteve Wise ep->mpa_attr.initiator = 0; 1703cfdda9d7SSteve Wise ep->mpa_attr.crc_enabled = (mpa->flags & MPA_CRC) | crc_enabled ? 1 : 0; 1704cfdda9d7SSteve Wise ep->mpa_attr.recv_marker_enabled = markers_enabled; 1705cfdda9d7SSteve Wise ep->mpa_attr.xmit_marker_enabled = mpa->flags & MPA_MARKERS ? 1 : 0; 1706d2fe99e8SKumar Sanghvi ep->mpa_attr.version = mpa->revision; 1707d2fe99e8SKumar Sanghvi if (mpa->revision == 1) 1708d2fe99e8SKumar Sanghvi ep->tried_with_mpa_v1 = 1; 1709d2fe99e8SKumar Sanghvi ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED; 1710d2fe99e8SKumar Sanghvi 1711d2fe99e8SKumar Sanghvi if (mpa->revision == 2) { 1712d2fe99e8SKumar Sanghvi ep->mpa_attr.enhanced_rdma_conn = 1713d2fe99e8SKumar Sanghvi mpa->flags & MPA_ENHANCED_RDMA_CONN ? 1 : 0; 1714d2fe99e8SKumar Sanghvi if (ep->mpa_attr.enhanced_rdma_conn) { 1715d2fe99e8SKumar Sanghvi mpa_v2_params = (struct mpa_v2_conn_params *) 1716d2fe99e8SKumar Sanghvi (ep->mpa_pkt + sizeof(*mpa)); 1717d2fe99e8SKumar Sanghvi ep->ird = ntohs(mpa_v2_params->ird) & 1718d2fe99e8SKumar Sanghvi MPA_V2_IRD_ORD_MASK; 1719d2fe99e8SKumar Sanghvi ep->ord = ntohs(mpa_v2_params->ord) & 1720d2fe99e8SKumar Sanghvi MPA_V2_IRD_ORD_MASK; 17214c2c5763SHariprasad Shenai PDBG("%s initiator ird %u ord %u\n", __func__, ep->ird, 17224c2c5763SHariprasad Shenai ep->ord); 1723d2fe99e8SKumar Sanghvi if (ntohs(mpa_v2_params->ird) & MPA_V2_PEER2PEER_MODEL) 1724d2fe99e8SKumar Sanghvi if (peer2peer) { 1725d2fe99e8SKumar Sanghvi if (ntohs(mpa_v2_params->ord) & 1726d2fe99e8SKumar Sanghvi MPA_V2_RDMA_WRITE_RTR) 1727d2fe99e8SKumar Sanghvi ep->mpa_attr.p2p_type = 1728d2fe99e8SKumar Sanghvi FW_RI_INIT_P2PTYPE_RDMA_WRITE; 1729d2fe99e8SKumar Sanghvi else if (ntohs(mpa_v2_params->ord) & 1730d2fe99e8SKumar Sanghvi MPA_V2_RDMA_READ_RTR) 1731d2fe99e8SKumar Sanghvi ep->mpa_attr.p2p_type = 1732d2fe99e8SKumar Sanghvi FW_RI_INIT_P2PTYPE_READ_REQ; 1733d2fe99e8SKumar Sanghvi } 1734d2fe99e8SKumar Sanghvi } 1735d2fe99e8SKumar Sanghvi } else if (mpa->revision == 1) 1736d2fe99e8SKumar Sanghvi if (peer2peer) 1737d2fe99e8SKumar Sanghvi ep->mpa_attr.p2p_type = p2p_type; 1738d2fe99e8SKumar Sanghvi 1739cfdda9d7SSteve Wise PDBG("%s - crc_enabled=%d, recv_marker_enabled=%d, " 1740cfdda9d7SSteve Wise "xmit_marker_enabled=%d, version=%d p2p_type=%d\n", __func__, 1741cfdda9d7SSteve Wise ep->mpa_attr.crc_enabled, ep->mpa_attr.recv_marker_enabled, 1742cfdda9d7SSteve Wise ep->mpa_attr.xmit_marker_enabled, ep->mpa_attr.version, 1743cfdda9d7SSteve Wise ep->mpa_attr.p2p_type); 1744cfdda9d7SSteve Wise 1745c529fb50SSteve Wise __state_set(&ep->com, MPA_REQ_RCVD); 1746cfdda9d7SSteve Wise 1747cfdda9d7SSteve Wise /* drive upcall */ 1748e4b76a2aSHariprasad S mutex_lock_nested(&ep->parent_ep->com.mutex, SINGLE_DEPTH_NESTING); 1749be13b2dfSSteve Wise if (ep->parent_ep->com.state != DEAD) { 1750be13b2dfSSteve Wise if (connect_request_upcall(ep)) 1751fd6aabe4SHariprasad S goto err_unlock_parent; 1752be13b2dfSSteve Wise } else { 1753fd6aabe4SHariprasad S goto err_unlock_parent; 1754be13b2dfSSteve Wise } 1755be13b2dfSSteve Wise mutex_unlock(&ep->parent_ep->com.mutex); 1756fd6aabe4SHariprasad S return 0; 1757fd6aabe4SHariprasad S 1758fd6aabe4SHariprasad S err_unlock_parent: 1759fd6aabe4SHariprasad S mutex_unlock(&ep->parent_ep->com.mutex); 1760fd6aabe4SHariprasad S goto err_out; 1761fd6aabe4SHariprasad S err_stop_timer: 1762fd6aabe4SHariprasad S (void)stop_ep_timer(ep); 1763fd6aabe4SHariprasad S err_out: 1764fd6aabe4SHariprasad S return 2; 1765cfdda9d7SSteve Wise } 1766cfdda9d7SSteve Wise 1767cfdda9d7SSteve Wise static int rx_data(struct c4iw_dev *dev, struct sk_buff *skb) 1768cfdda9d7SSteve Wise { 1769cfdda9d7SSteve Wise struct c4iw_ep *ep; 1770cfdda9d7SSteve Wise struct cpl_rx_data *hdr = cplhdr(skb); 1771cfdda9d7SSteve Wise unsigned int dlen = ntohs(hdr->len); 1772cfdda9d7SSteve Wise unsigned int tid = GET_TID(hdr); 1773cfdda9d7SSteve Wise struct tid_info *t = dev->rdev.lldi.tids; 1774793dad94SVipul Pandya __u8 status = hdr->status; 1775cc18b939SSteve Wise int disconnect = 0; 1776cfdda9d7SSteve Wise 1777cfdda9d7SSteve Wise ep = lookup_tid(t, tid); 1778977116c6SSteve Wise if (!ep) 1779977116c6SSteve Wise return 0; 1780cfdda9d7SSteve Wise PDBG("%s ep %p tid %u dlen %u\n", __func__, ep, ep->hwtid, dlen); 1781cfdda9d7SSteve Wise skb_pull(skb, sizeof(*hdr)); 1782cfdda9d7SSteve Wise skb_trim(skb, dlen); 1783c529fb50SSteve Wise mutex_lock(&ep->com.mutex); 1784cfdda9d7SSteve Wise 1785cfdda9d7SSteve Wise /* update RX credits */ 1786cfdda9d7SSteve Wise update_rx_credits(ep, dlen); 1787cfdda9d7SSteve Wise 1788c529fb50SSteve Wise switch (ep->com.state) { 1789cfdda9d7SSteve Wise case MPA_REQ_SENT: 179055abf8dfSVipul Pandya ep->rcv_seq += dlen; 1791cc18b939SSteve Wise disconnect = process_mpa_reply(ep, skb); 1792cfdda9d7SSteve Wise break; 1793cfdda9d7SSteve Wise case MPA_REQ_WAIT: 179455abf8dfSVipul Pandya ep->rcv_seq += dlen; 1795cfdda9d7SSteve Wise process_mpa_request(ep, skb); 1796cfdda9d7SSteve Wise break; 17971557967bSVipul Pandya case FPDU_MODE: { 17981557967bSVipul Pandya struct c4iw_qp_attributes attrs; 17991557967bSVipul Pandya BUG_ON(!ep->com.qp); 1800e8e5b927SVipul Pandya if (status) 1801793dad94SVipul Pandya pr_err("%s Unexpected streaming data." \ 180204236df2SVipul Pandya " qpid %u ep %p state %d tid %u status %d\n", 180304236df2SVipul Pandya __func__, ep->com.qp->wq.sq.qid, ep, 1804c529fb50SSteve Wise ep->com.state, ep->hwtid, status); 180597d7ec0cSSteve Wise attrs.next_state = C4IW_QP_STATE_TERMINATE; 180655abf8dfSVipul Pandya c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp, 1807cc18b939SSteve Wise C4IW_QP_ATTR_NEXT_STATE, &attrs, 1); 1808cc18b939SSteve Wise disconnect = 1; 1809cfdda9d7SSteve Wise break; 1810cfdda9d7SSteve Wise } 18111557967bSVipul Pandya default: 18121557967bSVipul Pandya break; 18131557967bSVipul Pandya } 1814c529fb50SSteve Wise mutex_unlock(&ep->com.mutex); 1815cc18b939SSteve Wise if (disconnect) 1816cc18b939SSteve Wise c4iw_ep_disconnect(ep, 0, GFP_KERNEL); 1817cfdda9d7SSteve Wise return 0; 1818cfdda9d7SSteve Wise } 1819cfdda9d7SSteve Wise 1820cfdda9d7SSteve Wise static int abort_rpl(struct c4iw_dev *dev, struct sk_buff *skb) 1821cfdda9d7SSteve Wise { 1822cfdda9d7SSteve Wise struct c4iw_ep *ep; 1823cfdda9d7SSteve Wise struct cpl_abort_rpl_rss *rpl = cplhdr(skb); 1824cfdda9d7SSteve Wise int release = 0; 1825cfdda9d7SSteve Wise unsigned int tid = GET_TID(rpl); 1826cfdda9d7SSteve Wise struct tid_info *t = dev->rdev.lldi.tids; 1827cfdda9d7SSteve Wise 1828cfdda9d7SSteve Wise ep = lookup_tid(t, tid); 18294984037bSVipul Pandya if (!ep) { 18304984037bSVipul Pandya printk(KERN_WARNING MOD "Abort rpl to freed endpoint\n"); 18314984037bSVipul Pandya return 0; 18324984037bSVipul Pandya } 183392dd6c3dSWei Yongjun PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid); 18342f5b48c3SSteve Wise mutex_lock(&ep->com.mutex); 1835cfdda9d7SSteve Wise switch (ep->com.state) { 1836cfdda9d7SSteve Wise case ABORTING: 183791e9c071SVipul Pandya c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET); 1838cfdda9d7SSteve Wise __state_set(&ep->com, DEAD); 1839cfdda9d7SSteve Wise release = 1; 1840cfdda9d7SSteve Wise break; 1841cfdda9d7SSteve Wise default: 1842cfdda9d7SSteve Wise printk(KERN_ERR "%s ep %p state %d\n", 1843cfdda9d7SSteve Wise __func__, ep, ep->com.state); 1844cfdda9d7SSteve Wise break; 1845cfdda9d7SSteve Wise } 18462f5b48c3SSteve Wise mutex_unlock(&ep->com.mutex); 1847cfdda9d7SSteve Wise 1848cfdda9d7SSteve Wise if (release) 1849cfdda9d7SSteve Wise release_ep_resources(ep); 1850cfdda9d7SSteve Wise return 0; 1851cfdda9d7SSteve Wise } 1852cfdda9d7SSteve Wise 18535be78ee9SVipul Pandya static void send_fw_act_open_req(struct c4iw_ep *ep, unsigned int atid) 18545be78ee9SVipul Pandya { 18555be78ee9SVipul Pandya struct sk_buff *skb; 18565be78ee9SVipul Pandya struct fw_ofld_connection_wr *req; 18575be78ee9SVipul Pandya unsigned int mtu_idx; 18585be78ee9SVipul Pandya int wscale; 1859830662f6SVipul Pandya struct sockaddr_in *sin; 1860b408ff28SHariprasad Shenai int win; 18615be78ee9SVipul Pandya 18625be78ee9SVipul Pandya skb = get_skb(NULL, sizeof(*req), GFP_KERNEL); 18635be78ee9SVipul Pandya req = (struct fw_ofld_connection_wr *)__skb_put(skb, sizeof(*req)); 18645be78ee9SVipul Pandya memset(req, 0, sizeof(*req)); 18656c53e938SHariprasad Shenai req->op_compl = htonl(WR_OP_V(FW_OFLD_CONNECTION_WR)); 1866e2ac9628SHariprasad Shenai req->len16_pkd = htonl(FW_WR_LEN16_V(DIV_ROUND_UP(sizeof(*req), 16))); 186741b4f86cSKumar Sanghvi req->le.filter = cpu_to_be32(cxgb4_select_ntuple( 186841b4f86cSKumar Sanghvi ep->com.dev->rdev.lldi.ports[0], 18695be78ee9SVipul Pandya ep->l2t)); 1870170003c8SSteve Wise sin = (struct sockaddr_in *)&ep->com.local_addr; 1871830662f6SVipul Pandya req->le.lport = sin->sin_port; 1872830662f6SVipul Pandya req->le.u.ipv4.lip = sin->sin_addr.s_addr; 1873170003c8SSteve Wise sin = (struct sockaddr_in *)&ep->com.remote_addr; 1874830662f6SVipul Pandya req->le.pport = sin->sin_port; 1875830662f6SVipul Pandya req->le.u.ipv4.pip = sin->sin_addr.s_addr; 18765be78ee9SVipul Pandya req->tcb.t_state_to_astid = 187777a80e23SHariprasad Shenai htonl(FW_OFLD_CONNECTION_WR_T_STATE_V(TCP_SYN_SENT) | 187877a80e23SHariprasad Shenai FW_OFLD_CONNECTION_WR_ASTID_V(atid)); 18795be78ee9SVipul Pandya req->tcb.cplrxdataack_cplpassacceptrpl = 188077a80e23SHariprasad Shenai htons(FW_OFLD_CONNECTION_WR_CPLRXDATAACK_F); 1881ef5d6355SVipul Pandya req->tcb.tx_max = (__force __be32) jiffies; 1882793dad94SVipul Pandya req->tcb.rcv_adv = htons(1); 188392e7ae71SHariprasad Shenai best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx, 188404524a47SHariprasad S enable_tcp_timestamps, 188504524a47SHariprasad S (AF_INET == ep->com.remote_addr.ss_family) ? 0 : 1); 18865be78ee9SVipul Pandya wscale = compute_wscale(rcv_win); 1887b408ff28SHariprasad Shenai 1888b408ff28SHariprasad Shenai /* 1889b408ff28SHariprasad Shenai * Specify the largest window that will fit in opt0. The 1890b408ff28SHariprasad Shenai * remainder will be specified in the rx_data_ack. 1891b408ff28SHariprasad Shenai */ 1892b408ff28SHariprasad Shenai win = ep->rcv_win >> 10; 1893d7990b0cSAnish Bhatt if (win > RCV_BUFSIZ_M) 1894d7990b0cSAnish Bhatt win = RCV_BUFSIZ_M; 1895b408ff28SHariprasad Shenai 18966c53e938SHariprasad Shenai req->tcb.opt0 = (__force __be64) (TCAM_BYPASS_F | 18976c53e938SHariprasad Shenai (nocong ? NO_CONG_F : 0) | 1898d7990b0cSAnish Bhatt KEEP_ALIVE_F | 18996c53e938SHariprasad Shenai DELACK_F | 1900d7990b0cSAnish Bhatt WND_SCALE_V(wscale) | 1901d7990b0cSAnish Bhatt MSS_IDX_V(mtu_idx) | 1902d7990b0cSAnish Bhatt L2T_IDX_V(ep->l2t->idx) | 1903d7990b0cSAnish Bhatt TX_CHAN_V(ep->tx_chan) | 1904d7990b0cSAnish Bhatt SMAC_SEL_V(ep->smac_idx) | 1905ac8e4c69SHariprasad S DSCP_V(ep->tos >> 2) | 1906d7990b0cSAnish Bhatt ULP_MODE_V(ULP_MODE_TCPDDP) | 1907d7990b0cSAnish Bhatt RCV_BUFSIZ_V(win)); 19086c53e938SHariprasad Shenai req->tcb.opt2 = (__force __be32) (PACE_V(1) | 19096c53e938SHariprasad Shenai TX_QUEUE_V(ep->com.dev->rdev.lldi.tx_modq[ep->tx_chan]) | 1910d7990b0cSAnish Bhatt RX_CHANNEL_V(0) | 19116c53e938SHariprasad Shenai CCTRL_ECN_V(enable_ecn) | 1912d7990b0cSAnish Bhatt RSS_QUEUE_VALID_F | RSS_QUEUE_V(ep->rss_qid)); 19135be78ee9SVipul Pandya if (enable_tcp_timestamps) 19146c53e938SHariprasad Shenai req->tcb.opt2 |= (__force __be32)TSTAMPS_EN_F; 19155be78ee9SVipul Pandya if (enable_tcp_sack) 19166c53e938SHariprasad Shenai req->tcb.opt2 |= (__force __be32)SACK_EN_F; 19175be78ee9SVipul Pandya if (wscale && enable_tcp_window_scaling) 1918d7990b0cSAnish Bhatt req->tcb.opt2 |= (__force __be32)WND_SCALE_EN_F; 1919ef5d6355SVipul Pandya req->tcb.opt0 = cpu_to_be64((__force u64)req->tcb.opt0); 1920ef5d6355SVipul Pandya req->tcb.opt2 = cpu_to_be32((__force u32)req->tcb.opt2); 1921793dad94SVipul Pandya set_wr_txq(skb, CPL_PRIORITY_CONTROL, ep->ctrlq_idx); 1922793dad94SVipul Pandya set_bit(ACT_OFLD_CONN, &ep->com.history); 19235be78ee9SVipul Pandya c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t); 19245be78ee9SVipul Pandya } 19255be78ee9SVipul Pandya 1926cfdda9d7SSteve Wise /* 1927cfdda9d7SSteve Wise * Return whether a failed active open has allocated a TID 1928cfdda9d7SSteve Wise */ 1929cfdda9d7SSteve Wise static inline int act_open_has_tid(int status) 1930cfdda9d7SSteve Wise { 1931cfdda9d7SSteve Wise return status != CPL_ERR_TCAM_FULL && status != CPL_ERR_CONN_EXIST && 1932cfdda9d7SSteve Wise status != CPL_ERR_ARP_MISS; 1933cfdda9d7SSteve Wise } 1934cfdda9d7SSteve Wise 19357a2cea2aSSteve Wise /* Returns whether a CPL status conveys negative advice. 19367a2cea2aSSteve Wise */ 19377a2cea2aSSteve Wise static int is_neg_adv(unsigned int status) 19387a2cea2aSSteve Wise { 19397a2cea2aSSteve Wise return status == CPL_ERR_RTX_NEG_ADVICE || 19407a2cea2aSSteve Wise status == CPL_ERR_PERSIST_NEG_ADVICE || 19417a2cea2aSSteve Wise status == CPL_ERR_KEEPALV_NEG_ADVICE; 19427a2cea2aSSteve Wise } 19437a2cea2aSSteve Wise 1944dd92b124SHariprasad Shenai static char *neg_adv_str(unsigned int status) 1945dd92b124SHariprasad Shenai { 1946dd92b124SHariprasad Shenai switch (status) { 1947dd92b124SHariprasad Shenai case CPL_ERR_RTX_NEG_ADVICE: 1948dd92b124SHariprasad Shenai return "Retransmit timeout"; 1949dd92b124SHariprasad Shenai case CPL_ERR_PERSIST_NEG_ADVICE: 1950dd92b124SHariprasad Shenai return "Persist timeout"; 1951dd92b124SHariprasad Shenai case CPL_ERR_KEEPALV_NEG_ADVICE: 1952dd92b124SHariprasad Shenai return "Keepalive timeout"; 1953dd92b124SHariprasad Shenai default: 1954dd92b124SHariprasad Shenai return "Unknown"; 1955dd92b124SHariprasad Shenai } 1956dd92b124SHariprasad Shenai } 1957dd92b124SHariprasad Shenai 1958b408ff28SHariprasad Shenai static void set_tcp_window(struct c4iw_ep *ep, struct port_info *pi) 1959b408ff28SHariprasad Shenai { 1960b408ff28SHariprasad Shenai ep->snd_win = snd_win; 1961b408ff28SHariprasad Shenai ep->rcv_win = rcv_win; 1962b408ff28SHariprasad Shenai PDBG("%s snd_win %d rcv_win %d\n", __func__, ep->snd_win, ep->rcv_win); 1963b408ff28SHariprasad Shenai } 1964b408ff28SHariprasad Shenai 1965793dad94SVipul Pandya #define ACT_OPEN_RETRY_COUNT 2 1966793dad94SVipul Pandya 1967830662f6SVipul Pandya static int import_ep(struct c4iw_ep *ep, int iptype, __u8 *peer_ip, 1968830662f6SVipul Pandya struct dst_entry *dst, struct c4iw_dev *cdev, 1969ac8e4c69SHariprasad S bool clear_mpa_v1, enum chip_type adapter_type, u8 tos) 1970830662f6SVipul Pandya { 1971830662f6SVipul Pandya struct neighbour *n; 1972830662f6SVipul Pandya int err, step; 1973830662f6SVipul Pandya struct net_device *pdev; 1974830662f6SVipul Pandya 1975830662f6SVipul Pandya n = dst_neigh_lookup(dst, peer_ip); 1976830662f6SVipul Pandya if (!n) 1977830662f6SVipul Pandya return -ENODEV; 1978830662f6SVipul Pandya 1979830662f6SVipul Pandya rcu_read_lock(); 1980830662f6SVipul Pandya err = -ENOMEM; 1981830662f6SVipul Pandya if (n->dev->flags & IFF_LOOPBACK) { 1982830662f6SVipul Pandya if (iptype == 4) 1983830662f6SVipul Pandya pdev = ip_dev_find(&init_net, *(__be32 *)peer_ip); 1984830662f6SVipul Pandya else if (IS_ENABLED(CONFIG_IPV6)) 1985830662f6SVipul Pandya for_each_netdev(&init_net, pdev) { 1986830662f6SVipul Pandya if (ipv6_chk_addr(&init_net, 1987830662f6SVipul Pandya (struct in6_addr *)peer_ip, 1988830662f6SVipul Pandya pdev, 1)) 1989830662f6SVipul Pandya break; 1990830662f6SVipul Pandya } 1991830662f6SVipul Pandya else 1992830662f6SVipul Pandya pdev = NULL; 1993830662f6SVipul Pandya 1994830662f6SVipul Pandya if (!pdev) { 1995830662f6SVipul Pandya err = -ENODEV; 1996830662f6SVipul Pandya goto out; 1997830662f6SVipul Pandya } 1998830662f6SVipul Pandya ep->l2t = cxgb4_l2t_get(cdev->rdev.lldi.l2t, 1999ac8e4c69SHariprasad S n, pdev, rt_tos2priority(tos)); 2000830662f6SVipul Pandya if (!ep->l2t) 2001830662f6SVipul Pandya goto out; 2002830662f6SVipul Pandya ep->mtu = pdev->mtu; 2003830662f6SVipul Pandya ep->tx_chan = cxgb4_port_chan(pdev); 2004963cab50SHariprasad S ep->smac_idx = cxgb4_tp_smt_idx(adapter_type, 2005963cab50SHariprasad S cxgb4_port_viid(pdev)); 2006830662f6SVipul Pandya step = cdev->rdev.lldi.ntxq / 2007830662f6SVipul Pandya cdev->rdev.lldi.nchan; 2008830662f6SVipul Pandya ep->txq_idx = cxgb4_port_idx(pdev) * step; 2009830662f6SVipul Pandya step = cdev->rdev.lldi.nrxq / 2010830662f6SVipul Pandya cdev->rdev.lldi.nchan; 2011830662f6SVipul Pandya ep->ctrlq_idx = cxgb4_port_idx(pdev); 2012830662f6SVipul Pandya ep->rss_qid = cdev->rdev.lldi.rxq_ids[ 2013830662f6SVipul Pandya cxgb4_port_idx(pdev) * step]; 2014b408ff28SHariprasad Shenai set_tcp_window(ep, (struct port_info *)netdev_priv(pdev)); 2015830662f6SVipul Pandya dev_put(pdev); 2016830662f6SVipul Pandya } else { 2017830662f6SVipul Pandya pdev = get_real_dev(n->dev); 2018830662f6SVipul Pandya ep->l2t = cxgb4_l2t_get(cdev->rdev.lldi.l2t, 2019830662f6SVipul Pandya n, pdev, 0); 2020830662f6SVipul Pandya if (!ep->l2t) 2021830662f6SVipul Pandya goto out; 2022830662f6SVipul Pandya ep->mtu = dst_mtu(dst); 202311b8e22dSSteve Wise ep->tx_chan = cxgb4_port_chan(pdev); 2024963cab50SHariprasad S ep->smac_idx = cxgb4_tp_smt_idx(adapter_type, 2025963cab50SHariprasad S cxgb4_port_viid(pdev)); 2026830662f6SVipul Pandya step = cdev->rdev.lldi.ntxq / 2027830662f6SVipul Pandya cdev->rdev.lldi.nchan; 202811b8e22dSSteve Wise ep->txq_idx = cxgb4_port_idx(pdev) * step; 202911b8e22dSSteve Wise ep->ctrlq_idx = cxgb4_port_idx(pdev); 2030830662f6SVipul Pandya step = cdev->rdev.lldi.nrxq / 2031830662f6SVipul Pandya cdev->rdev.lldi.nchan; 2032830662f6SVipul Pandya ep->rss_qid = cdev->rdev.lldi.rxq_ids[ 203311b8e22dSSteve Wise cxgb4_port_idx(pdev) * step]; 2034b408ff28SHariprasad Shenai set_tcp_window(ep, (struct port_info *)netdev_priv(pdev)); 2035830662f6SVipul Pandya 2036830662f6SVipul Pandya if (clear_mpa_v1) { 2037830662f6SVipul Pandya ep->retry_with_mpa_v1 = 0; 2038830662f6SVipul Pandya ep->tried_with_mpa_v1 = 0; 2039830662f6SVipul Pandya } 2040830662f6SVipul Pandya } 2041830662f6SVipul Pandya err = 0; 2042830662f6SVipul Pandya out: 2043830662f6SVipul Pandya rcu_read_unlock(); 2044830662f6SVipul Pandya 2045830662f6SVipul Pandya neigh_release(n); 2046830662f6SVipul Pandya 2047830662f6SVipul Pandya return err; 2048830662f6SVipul Pandya } 2049830662f6SVipul Pandya 2050793dad94SVipul Pandya static int c4iw_reconnect(struct c4iw_ep *ep) 2051793dad94SVipul Pandya { 2052793dad94SVipul Pandya int err = 0; 205324d44a39SSteve Wise struct sockaddr_in *laddr = (struct sockaddr_in *) 2054170003c8SSteve Wise &ep->com.cm_id->m_local_addr; 205524d44a39SSteve Wise struct sockaddr_in *raddr = (struct sockaddr_in *) 2056170003c8SSteve Wise &ep->com.cm_id->m_remote_addr; 2057830662f6SVipul Pandya struct sockaddr_in6 *laddr6 = (struct sockaddr_in6 *) 2058170003c8SSteve Wise &ep->com.cm_id->m_local_addr; 2059830662f6SVipul Pandya struct sockaddr_in6 *raddr6 = (struct sockaddr_in6 *) 2060170003c8SSteve Wise &ep->com.cm_id->m_remote_addr; 2061830662f6SVipul Pandya int iptype; 2062830662f6SVipul Pandya __u8 *ra; 2063793dad94SVipul Pandya 2064793dad94SVipul Pandya PDBG("%s qp %p cm_id %p\n", __func__, ep->com.qp, ep->com.cm_id); 2065793dad94SVipul Pandya init_timer(&ep->timer); 2066793dad94SVipul Pandya 2067793dad94SVipul Pandya /* 2068793dad94SVipul Pandya * Allocate an active TID to initiate a TCP connection. 2069793dad94SVipul Pandya */ 2070793dad94SVipul Pandya ep->atid = cxgb4_alloc_atid(ep->com.dev->rdev.lldi.tids, ep); 2071793dad94SVipul Pandya if (ep->atid == -1) { 2072793dad94SVipul Pandya pr_err("%s - cannot alloc atid.\n", __func__); 2073793dad94SVipul Pandya err = -ENOMEM; 2074793dad94SVipul Pandya goto fail2; 2075793dad94SVipul Pandya } 2076793dad94SVipul Pandya insert_handle(ep->com.dev, &ep->com.dev->atid_idr, ep, ep->atid); 2077793dad94SVipul Pandya 2078793dad94SVipul Pandya /* find a route */ 2079170003c8SSteve Wise if (ep->com.cm_id->m_local_addr.ss_family == AF_INET) { 2080830662f6SVipul Pandya ep->dst = find_route(ep->com.dev, laddr->sin_addr.s_addr, 2081830662f6SVipul Pandya raddr->sin_addr.s_addr, laddr->sin_port, 2082ac8e4c69SHariprasad S raddr->sin_port, ep->com.cm_id->tos); 2083830662f6SVipul Pandya iptype = 4; 2084830662f6SVipul Pandya ra = (__u8 *)&raddr->sin_addr; 2085830662f6SVipul Pandya } else { 2086830662f6SVipul Pandya ep->dst = find_route6(ep->com.dev, laddr6->sin6_addr.s6_addr, 2087830662f6SVipul Pandya raddr6->sin6_addr.s6_addr, 2088830662f6SVipul Pandya laddr6->sin6_port, raddr6->sin6_port, 0, 2089830662f6SVipul Pandya raddr6->sin6_scope_id); 2090830662f6SVipul Pandya iptype = 6; 2091830662f6SVipul Pandya ra = (__u8 *)&raddr6->sin6_addr; 2092830662f6SVipul Pandya } 2093830662f6SVipul Pandya if (!ep->dst) { 2094793dad94SVipul Pandya pr_err("%s - cannot find route.\n", __func__); 2095793dad94SVipul Pandya err = -EHOSTUNREACH; 2096793dad94SVipul Pandya goto fail3; 2097793dad94SVipul Pandya } 2098963cab50SHariprasad S err = import_ep(ep, iptype, ra, ep->dst, ep->com.dev, false, 2099ac8e4c69SHariprasad S ep->com.dev->rdev.lldi.adapter_type, 2100ac8e4c69SHariprasad S ep->com.cm_id->tos); 2101830662f6SVipul Pandya if (err) { 2102793dad94SVipul Pandya pr_err("%s - cannot alloc l2e.\n", __func__); 2103793dad94SVipul Pandya goto fail4; 2104793dad94SVipul Pandya } 2105793dad94SVipul Pandya 2106793dad94SVipul Pandya PDBG("%s txq_idx %u tx_chan %u smac_idx %u rss_qid %u l2t_idx %u\n", 2107793dad94SVipul Pandya __func__, ep->txq_idx, ep->tx_chan, ep->smac_idx, ep->rss_qid, 2108793dad94SVipul Pandya ep->l2t->idx); 2109793dad94SVipul Pandya 2110793dad94SVipul Pandya state_set(&ep->com, CONNECTING); 2111ac8e4c69SHariprasad S ep->tos = ep->com.cm_id->tos; 2112793dad94SVipul Pandya 2113793dad94SVipul Pandya /* send connect request to rnic */ 2114793dad94SVipul Pandya err = send_connect(ep); 2115793dad94SVipul Pandya if (!err) 2116793dad94SVipul Pandya goto out; 2117793dad94SVipul Pandya 2118793dad94SVipul Pandya cxgb4_l2t_release(ep->l2t); 2119793dad94SVipul Pandya fail4: 2120793dad94SVipul Pandya dst_release(ep->dst); 2121793dad94SVipul Pandya fail3: 2122793dad94SVipul Pandya remove_handle(ep->com.dev, &ep->com.dev->atid_idr, ep->atid); 2123793dad94SVipul Pandya cxgb4_free_atid(ep->com.dev->rdev.lldi.tids, ep->atid); 2124793dad94SVipul Pandya fail2: 2125793dad94SVipul Pandya /* 2126793dad94SVipul Pandya * remember to send notification to upper layer. 2127793dad94SVipul Pandya * We are in here so the upper layer is not aware that this is 2128793dad94SVipul Pandya * re-connect attempt and so, upper layer is still waiting for 2129793dad94SVipul Pandya * response of 1st connect request. 2130793dad94SVipul Pandya */ 2131793dad94SVipul Pandya connect_reply_upcall(ep, -ECONNRESET); 2132793dad94SVipul Pandya c4iw_put_ep(&ep->com); 2133793dad94SVipul Pandya out: 2134793dad94SVipul Pandya return err; 2135793dad94SVipul Pandya } 2136793dad94SVipul Pandya 2137cfdda9d7SSteve Wise static int act_open_rpl(struct c4iw_dev *dev, struct sk_buff *skb) 2138cfdda9d7SSteve Wise { 2139cfdda9d7SSteve Wise struct c4iw_ep *ep; 2140cfdda9d7SSteve Wise struct cpl_act_open_rpl *rpl = cplhdr(skb); 21416c53e938SHariprasad Shenai unsigned int atid = TID_TID_G(AOPEN_ATID_G( 2142cfdda9d7SSteve Wise ntohl(rpl->atid_status))); 2143cfdda9d7SSteve Wise struct tid_info *t = dev->rdev.lldi.tids; 21446c53e938SHariprasad Shenai int status = AOPEN_STATUS_G(ntohl(rpl->atid_status)); 2145830662f6SVipul Pandya struct sockaddr_in *la; 2146830662f6SVipul Pandya struct sockaddr_in *ra; 2147830662f6SVipul Pandya struct sockaddr_in6 *la6; 2148830662f6SVipul Pandya struct sockaddr_in6 *ra6; 2149cfdda9d7SSteve Wise 2150cfdda9d7SSteve Wise ep = lookup_atid(t, atid); 2151170003c8SSteve Wise la = (struct sockaddr_in *)&ep->com.local_addr; 2152170003c8SSteve Wise ra = (struct sockaddr_in *)&ep->com.remote_addr; 2153170003c8SSteve Wise la6 = (struct sockaddr_in6 *)&ep->com.local_addr; 2154170003c8SSteve Wise ra6 = (struct sockaddr_in6 *)&ep->com.remote_addr; 2155cfdda9d7SSteve Wise 2156cfdda9d7SSteve Wise PDBG("%s ep %p atid %u status %u errno %d\n", __func__, ep, atid, 2157cfdda9d7SSteve Wise status, status2errno(status)); 2158cfdda9d7SSteve Wise 21597a2cea2aSSteve Wise if (is_neg_adv(status)) { 2160179d03bbSHariprasad S PDBG("%s Connection problems for atid %u status %u (%s)\n", 2161179d03bbSHariprasad S __func__, atid, status, neg_adv_str(status)); 2162179d03bbSHariprasad S ep->stats.connect_neg_adv++; 2163179d03bbSHariprasad S mutex_lock(&dev->rdev.stats.lock); 2164179d03bbSHariprasad S dev->rdev.stats.neg_adv++; 2165179d03bbSHariprasad S mutex_unlock(&dev->rdev.stats.lock); 2166cfdda9d7SSteve Wise return 0; 2167cfdda9d7SSteve Wise } 2168cfdda9d7SSteve Wise 2169793dad94SVipul Pandya set_bit(ACT_OPEN_RPL, &ep->com.history); 2170793dad94SVipul Pandya 2171d716a2a0SVipul Pandya /* 2172d716a2a0SVipul Pandya * Log interesting failures. 2173d716a2a0SVipul Pandya */ 2174d716a2a0SVipul Pandya switch (status) { 2175d716a2a0SVipul Pandya case CPL_ERR_CONN_RESET: 2176d716a2a0SVipul Pandya case CPL_ERR_CONN_TIMEDOUT: 2177d716a2a0SVipul Pandya break; 21785be78ee9SVipul Pandya case CPL_ERR_TCAM_FULL: 21795be78ee9SVipul Pandya mutex_lock(&dev->rdev.stats.lock); 2180830662f6SVipul Pandya dev->rdev.stats.tcam_full++; 21815be78ee9SVipul Pandya mutex_unlock(&dev->rdev.stats.lock); 2182830662f6SVipul Pandya if (ep->com.local_addr.ss_family == AF_INET && 2183830662f6SVipul Pandya dev->rdev.lldi.enable_fw_ofld_conn) { 21845be78ee9SVipul Pandya send_fw_act_open_req(ep, 21856c53e938SHariprasad Shenai TID_TID_G(AOPEN_ATID_G( 2186793dad94SVipul Pandya ntohl(rpl->atid_status)))); 21875be78ee9SVipul Pandya return 0; 2188793dad94SVipul Pandya } 2189793dad94SVipul Pandya break; 2190793dad94SVipul Pandya case CPL_ERR_CONN_EXIST: 2191793dad94SVipul Pandya if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) { 2192793dad94SVipul Pandya set_bit(ACT_RETRY_INUSE, &ep->com.history); 219384cc6ac6SHariprasad S if (ep->com.remote_addr.ss_family == AF_INET6) { 219484cc6ac6SHariprasad S struct sockaddr_in6 *sin6 = 219584cc6ac6SHariprasad S (struct sockaddr_in6 *) 2196170003c8SSteve Wise &ep->com.local_addr; 219784cc6ac6SHariprasad S cxgb4_clip_release( 219884cc6ac6SHariprasad S ep->com.dev->rdev.lldi.ports[0], 219984cc6ac6SHariprasad S (const u32 *) 220084cc6ac6SHariprasad S &sin6->sin6_addr.s6_addr, 1); 220184cc6ac6SHariprasad S } 2202793dad94SVipul Pandya remove_handle(ep->com.dev, &ep->com.dev->atid_idr, 2203793dad94SVipul Pandya atid); 2204793dad94SVipul Pandya cxgb4_free_atid(t, atid); 2205793dad94SVipul Pandya dst_release(ep->dst); 2206793dad94SVipul Pandya cxgb4_l2t_release(ep->l2t); 2207793dad94SVipul Pandya c4iw_reconnect(ep); 2208793dad94SVipul Pandya return 0; 2209793dad94SVipul Pandya } 22105be78ee9SVipul Pandya break; 2211d716a2a0SVipul Pandya default: 2212830662f6SVipul Pandya if (ep->com.local_addr.ss_family == AF_INET) { 2213830662f6SVipul Pandya pr_info("Active open failure - atid %u status %u errno %d %pI4:%u->%pI4:%u\n", 2214d716a2a0SVipul Pandya atid, status, status2errno(status), 2215830662f6SVipul Pandya &la->sin_addr.s_addr, ntohs(la->sin_port), 2216830662f6SVipul Pandya &ra->sin_addr.s_addr, ntohs(ra->sin_port)); 2217830662f6SVipul Pandya } else { 2218830662f6SVipul Pandya pr_info("Active open failure - atid %u status %u errno %d %pI6:%u->%pI6:%u\n", 2219830662f6SVipul Pandya atid, status, status2errno(status), 2220830662f6SVipul Pandya la6->sin6_addr.s6_addr, ntohs(la6->sin6_port), 2221830662f6SVipul Pandya ra6->sin6_addr.s6_addr, ntohs(ra6->sin6_port)); 2222830662f6SVipul Pandya } 2223d716a2a0SVipul Pandya break; 2224d716a2a0SVipul Pandya } 2225d716a2a0SVipul Pandya 2226cfdda9d7SSteve Wise connect_reply_upcall(ep, status2errno(status)); 2227cfdda9d7SSteve Wise state_set(&ep->com, DEAD); 2228cfdda9d7SSteve Wise 222984cc6ac6SHariprasad S if (ep->com.remote_addr.ss_family == AF_INET6) { 223084cc6ac6SHariprasad S struct sockaddr_in6 *sin6 = 2231170003c8SSteve Wise (struct sockaddr_in6 *)&ep->com.local_addr; 223284cc6ac6SHariprasad S cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0], 223384cc6ac6SHariprasad S (const u32 *)&sin6->sin6_addr.s6_addr, 1); 223484cc6ac6SHariprasad S } 2235cfdda9d7SSteve Wise if (status && act_open_has_tid(status)) 2236cfdda9d7SSteve Wise cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, GET_TID(rpl)); 2237cfdda9d7SSteve Wise 2238793dad94SVipul Pandya remove_handle(ep->com.dev, &ep->com.dev->atid_idr, atid); 2239cfdda9d7SSteve Wise cxgb4_free_atid(t, atid); 2240cfdda9d7SSteve Wise dst_release(ep->dst); 2241cfdda9d7SSteve Wise cxgb4_l2t_release(ep->l2t); 2242cfdda9d7SSteve Wise c4iw_put_ep(&ep->com); 2243cfdda9d7SSteve Wise 2244cfdda9d7SSteve Wise return 0; 2245cfdda9d7SSteve Wise } 2246cfdda9d7SSteve Wise 2247cfdda9d7SSteve Wise static int pass_open_rpl(struct c4iw_dev *dev, struct sk_buff *skb) 2248cfdda9d7SSteve Wise { 2249cfdda9d7SSteve Wise struct cpl_pass_open_rpl *rpl = cplhdr(skb); 2250cfdda9d7SSteve Wise struct tid_info *t = dev->rdev.lldi.tids; 2251cfdda9d7SSteve Wise unsigned int stid = GET_TID(rpl); 2252cfdda9d7SSteve Wise struct c4iw_listen_ep *ep = lookup_stid(t, stid); 2253cfdda9d7SSteve Wise 2254cfdda9d7SSteve Wise if (!ep) { 22551cab775cSVipul Pandya PDBG("%s stid %d lookup failure!\n", __func__, stid); 22561cab775cSVipul Pandya goto out; 2257cfdda9d7SSteve Wise } 2258cfdda9d7SSteve Wise PDBG("%s ep %p status %d error %d\n", __func__, ep, 2259cfdda9d7SSteve Wise rpl->status, status2errno(rpl->status)); 2260d9594d99SSteve Wise c4iw_wake_up(&ep->com.wr_wait, status2errno(rpl->status)); 2261cfdda9d7SSteve Wise 22621cab775cSVipul Pandya out: 2263cfdda9d7SSteve Wise return 0; 2264cfdda9d7SSteve Wise } 2265cfdda9d7SSteve Wise 2266cfdda9d7SSteve Wise static int close_listsrv_rpl(struct c4iw_dev *dev, struct sk_buff *skb) 2267cfdda9d7SSteve Wise { 2268cfdda9d7SSteve Wise struct cpl_close_listsvr_rpl *rpl = cplhdr(skb); 2269cfdda9d7SSteve Wise struct tid_info *t = dev->rdev.lldi.tids; 2270cfdda9d7SSteve Wise unsigned int stid = GET_TID(rpl); 2271cfdda9d7SSteve Wise struct c4iw_listen_ep *ep = lookup_stid(t, stid); 2272cfdda9d7SSteve Wise 2273cfdda9d7SSteve Wise PDBG("%s ep %p\n", __func__, ep); 2274d9594d99SSteve Wise c4iw_wake_up(&ep->com.wr_wait, status2errno(rpl->status)); 2275cfdda9d7SSteve Wise return 0; 2276cfdda9d7SSteve Wise } 2277cfdda9d7SSteve Wise 22789dec900cSHariprasad S static int accept_cr(struct c4iw_ep *ep, struct sk_buff *skb, 2279cfdda9d7SSteve Wise struct cpl_pass_accept_req *req) 2280cfdda9d7SSteve Wise { 2281cfdda9d7SSteve Wise struct cpl_pass_accept_rpl *rpl; 2282cfdda9d7SSteve Wise unsigned int mtu_idx; 2283cfdda9d7SSteve Wise u64 opt0; 2284cfdda9d7SSteve Wise u32 opt2; 2285cfdda9d7SSteve Wise int wscale; 228692e7ae71SHariprasad Shenai struct cpl_t5_pass_accept_rpl *rpl5 = NULL; 2287b408ff28SHariprasad Shenai int win; 2288963cab50SHariprasad S enum chip_type adapter_type = ep->com.dev->rdev.lldi.adapter_type; 2289cfdda9d7SSteve Wise 2290cfdda9d7SSteve Wise PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid); 2291cfdda9d7SSteve Wise BUG_ON(skb_cloned(skb)); 229292e7ae71SHariprasad Shenai 2293cfdda9d7SSteve Wise skb_get(skb); 229492e7ae71SHariprasad Shenai rpl = cplhdr(skb); 2295963cab50SHariprasad S if (!is_t4(adapter_type)) { 229692e7ae71SHariprasad Shenai skb_trim(skb, roundup(sizeof(*rpl5), 16)); 229792e7ae71SHariprasad Shenai rpl5 = (void *)rpl; 229892e7ae71SHariprasad Shenai INIT_TP_WR(rpl5, ep->hwtid); 229992e7ae71SHariprasad Shenai } else { 230092e7ae71SHariprasad Shenai skb_trim(skb, sizeof(*rpl)); 230192e7ae71SHariprasad Shenai INIT_TP_WR(rpl, ep->hwtid); 230292e7ae71SHariprasad Shenai } 230392e7ae71SHariprasad Shenai OPCODE_TID(rpl) = cpu_to_be32(MK_OPCODE_TID(CPL_PASS_ACCEPT_RPL, 230492e7ae71SHariprasad Shenai ep->hwtid)); 230592e7ae71SHariprasad Shenai 230692e7ae71SHariprasad Shenai best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx, 230704524a47SHariprasad S enable_tcp_timestamps && req->tcpopt.tstamp, 230804524a47SHariprasad S (AF_INET == ep->com.remote_addr.ss_family) ? 0 : 1); 2309cfdda9d7SSteve Wise wscale = compute_wscale(rcv_win); 2310b408ff28SHariprasad Shenai 2311b408ff28SHariprasad Shenai /* 2312b408ff28SHariprasad Shenai * Specify the largest window that will fit in opt0. The 2313b408ff28SHariprasad Shenai * remainder will be specified in the rx_data_ack. 2314b408ff28SHariprasad Shenai */ 2315b408ff28SHariprasad Shenai win = ep->rcv_win >> 10; 2316d7990b0cSAnish Bhatt if (win > RCV_BUFSIZ_M) 2317d7990b0cSAnish Bhatt win = RCV_BUFSIZ_M; 23186c53e938SHariprasad Shenai opt0 = (nocong ? NO_CONG_F : 0) | 2319d7990b0cSAnish Bhatt KEEP_ALIVE_F | 23206c53e938SHariprasad Shenai DELACK_F | 2321d7990b0cSAnish Bhatt WND_SCALE_V(wscale) | 2322d7990b0cSAnish Bhatt MSS_IDX_V(mtu_idx) | 2323d7990b0cSAnish Bhatt L2T_IDX_V(ep->l2t->idx) | 2324d7990b0cSAnish Bhatt TX_CHAN_V(ep->tx_chan) | 2325d7990b0cSAnish Bhatt SMAC_SEL_V(ep->smac_idx) | 23266c53e938SHariprasad Shenai DSCP_V(ep->tos >> 2) | 2327d7990b0cSAnish Bhatt ULP_MODE_V(ULP_MODE_TCPDDP) | 2328d7990b0cSAnish Bhatt RCV_BUFSIZ_V(win); 2329d7990b0cSAnish Bhatt opt2 = RX_CHANNEL_V(0) | 2330d7990b0cSAnish Bhatt RSS_QUEUE_VALID_F | RSS_QUEUE_V(ep->rss_qid); 2331cfdda9d7SSteve Wise 2332cfdda9d7SSteve Wise if (enable_tcp_timestamps && req->tcpopt.tstamp) 23336c53e938SHariprasad Shenai opt2 |= TSTAMPS_EN_F; 2334cfdda9d7SSteve Wise if (enable_tcp_sack && req->tcpopt.sack) 23356c53e938SHariprasad Shenai opt2 |= SACK_EN_F; 2336cfdda9d7SSteve Wise if (wscale && enable_tcp_window_scaling) 2337d7990b0cSAnish Bhatt opt2 |= WND_SCALE_EN_F; 23385be78ee9SVipul Pandya if (enable_ecn) { 23395be78ee9SVipul Pandya const struct tcphdr *tcph; 23405be78ee9SVipul Pandya u32 hlen = ntohl(req->hdr_len); 23415be78ee9SVipul Pandya 2342963cab50SHariprasad S if (CHELSIO_CHIP_VERSION(adapter_type) <= CHELSIO_T5) 2343cf7fe64aSHariprasad Shenai tcph = (const void *)(req + 1) + ETH_HDR_LEN_G(hlen) + 2344cf7fe64aSHariprasad Shenai IP_HDR_LEN_G(hlen); 2345963cab50SHariprasad S else 2346963cab50SHariprasad S tcph = (const void *)(req + 1) + 2347963cab50SHariprasad S T6_ETH_HDR_LEN_G(hlen) + T6_IP_HDR_LEN_G(hlen); 23485be78ee9SVipul Pandya if (tcph->ece && tcph->cwr) 23496c53e938SHariprasad Shenai opt2 |= CCTRL_ECN_V(1); 23505be78ee9SVipul Pandya } 2351963cab50SHariprasad S if (CHELSIO_CHIP_VERSION(adapter_type) > CHELSIO_T4) { 235292e7ae71SHariprasad Shenai u32 isn = (prandom_u32() & ~7UL) - 1; 2353d7990b0cSAnish Bhatt opt2 |= T5_OPT_2_VALID_F; 2354cf7fe64aSHariprasad Shenai opt2 |= CONG_CNTRL_V(CONG_ALG_TAHOE); 23550b741047SHariprasad S opt2 |= T5_ISS_F; 235692e7ae71SHariprasad Shenai rpl5 = (void *)rpl; 235792e7ae71SHariprasad Shenai memset(&rpl5->iss, 0, roundup(sizeof(*rpl5)-sizeof(*rpl), 16)); 235892e7ae71SHariprasad Shenai if (peer2peer) 235992e7ae71SHariprasad Shenai isn += 4; 236092e7ae71SHariprasad Shenai rpl5->iss = cpu_to_be32(isn); 236192e7ae71SHariprasad Shenai PDBG("%s iss %u\n", __func__, be32_to_cpu(rpl5->iss)); 236292e5011aSSteve Wise } 2363cfdda9d7SSteve Wise 2364cfdda9d7SSteve Wise rpl->opt0 = cpu_to_be64(opt0); 2365cfdda9d7SSteve Wise rpl->opt2 = cpu_to_be32(opt2); 2366d4f1a5c6SSteve Wise set_wr_txq(skb, CPL_PRIORITY_SETUP, ep->ctrlq_idx); 23679dec900cSHariprasad S t4_set_arp_err_handler(skb, ep, pass_accept_rpl_arp_failure); 2368cfdda9d7SSteve Wise 23699dec900cSHariprasad S return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t); 2370cfdda9d7SSteve Wise } 2371cfdda9d7SSteve Wise 2372830662f6SVipul Pandya static void reject_cr(struct c4iw_dev *dev, u32 hwtid, struct sk_buff *skb) 2373cfdda9d7SSteve Wise { 2374830662f6SVipul Pandya PDBG("%s c4iw_dev %p tid %u\n", __func__, dev, hwtid); 2375cfdda9d7SSteve Wise BUG_ON(skb_cloned(skb)); 2376cfdda9d7SSteve Wise skb_trim(skb, sizeof(struct cpl_tid_release)); 2377cfdda9d7SSteve Wise release_tid(&dev->rdev, hwtid, skb); 2378cfdda9d7SSteve Wise return; 2379cfdda9d7SSteve Wise } 2380cfdda9d7SSteve Wise 2381963cab50SHariprasad S static void get_4tuple(struct cpl_pass_accept_req *req, enum chip_type type, 2382963cab50SHariprasad S int *iptype, __u8 *local_ip, __u8 *peer_ip, 2383cfdda9d7SSteve Wise __be16 *local_port, __be16 *peer_port) 2384cfdda9d7SSteve Wise { 2385963cab50SHariprasad S int eth_len = (CHELSIO_CHIP_VERSION(type) <= CHELSIO_T5) ? 2386963cab50SHariprasad S ETH_HDR_LEN_G(be32_to_cpu(req->hdr_len)) : 2387963cab50SHariprasad S T6_ETH_HDR_LEN_G(be32_to_cpu(req->hdr_len)); 2388963cab50SHariprasad S int ip_len = (CHELSIO_CHIP_VERSION(type) <= CHELSIO_T5) ? 2389963cab50SHariprasad S IP_HDR_LEN_G(be32_to_cpu(req->hdr_len)) : 2390963cab50SHariprasad S T6_IP_HDR_LEN_G(be32_to_cpu(req->hdr_len)); 2391cfdda9d7SSteve Wise struct iphdr *ip = (struct iphdr *)((u8 *)(req + 1) + eth_len); 2392830662f6SVipul Pandya struct ipv6hdr *ip6 = (struct ipv6hdr *)((u8 *)(req + 1) + eth_len); 2393cfdda9d7SSteve Wise struct tcphdr *tcp = (struct tcphdr *) 2394cfdda9d7SSteve Wise ((u8 *)(req + 1) + eth_len + ip_len); 2395cfdda9d7SSteve Wise 2396830662f6SVipul Pandya if (ip->version == 4) { 2397cfdda9d7SSteve Wise PDBG("%s saddr 0x%x daddr 0x%x sport %u dport %u\n", __func__, 2398cfdda9d7SSteve Wise ntohl(ip->saddr), ntohl(ip->daddr), ntohs(tcp->source), 2399cfdda9d7SSteve Wise ntohs(tcp->dest)); 2400830662f6SVipul Pandya *iptype = 4; 2401830662f6SVipul Pandya memcpy(peer_ip, &ip->saddr, 4); 2402830662f6SVipul Pandya memcpy(local_ip, &ip->daddr, 4); 2403830662f6SVipul Pandya } else { 2404830662f6SVipul Pandya PDBG("%s saddr %pI6 daddr %pI6 sport %u dport %u\n", __func__, 2405830662f6SVipul Pandya ip6->saddr.s6_addr, ip6->daddr.s6_addr, ntohs(tcp->source), 2406830662f6SVipul Pandya ntohs(tcp->dest)); 2407830662f6SVipul Pandya *iptype = 6; 2408830662f6SVipul Pandya memcpy(peer_ip, ip6->saddr.s6_addr, 16); 2409830662f6SVipul Pandya memcpy(local_ip, ip6->daddr.s6_addr, 16); 2410830662f6SVipul Pandya } 2411cfdda9d7SSteve Wise *peer_port = tcp->source; 2412cfdda9d7SSteve Wise *local_port = tcp->dest; 2413cfdda9d7SSteve Wise 2414cfdda9d7SSteve Wise return; 2415cfdda9d7SSteve Wise } 2416cfdda9d7SSteve Wise 2417cfdda9d7SSteve Wise static int pass_accept_req(struct c4iw_dev *dev, struct sk_buff *skb) 2418cfdda9d7SSteve Wise { 2419793dad94SVipul Pandya struct c4iw_ep *child_ep = NULL, *parent_ep; 2420cfdda9d7SSteve Wise struct cpl_pass_accept_req *req = cplhdr(skb); 24216c53e938SHariprasad Shenai unsigned int stid = PASS_OPEN_TID_G(ntohl(req->tos_stid)); 2422cfdda9d7SSteve Wise struct tid_info *t = dev->rdev.lldi.tids; 2423cfdda9d7SSteve Wise unsigned int hwtid = GET_TID(req); 2424cfdda9d7SSteve Wise struct dst_entry *dst; 2425830662f6SVipul Pandya __u8 local_ip[16], peer_ip[16]; 2426cfdda9d7SSteve Wise __be16 local_port, peer_port; 242784cc6ac6SHariprasad S struct sockaddr_in6 *sin6; 24283786cf18SDavid Miller int err; 24291cab775cSVipul Pandya u16 peer_mss = ntohs(req->tcpopt.mss); 2430830662f6SVipul Pandya int iptype; 243192e7ae71SHariprasad Shenai unsigned short hdrs; 2432ac8e4c69SHariprasad S u8 tos = PASS_OPEN_TOS_G(ntohl(req->tos_stid)); 2433cfdda9d7SSteve Wise 2434cfdda9d7SSteve Wise parent_ep = lookup_stid(t, stid); 24351cab775cSVipul Pandya if (!parent_ep) { 24361cab775cSVipul Pandya PDBG("%s connect request on invalid stid %d\n", __func__, stid); 24371cab775cSVipul Pandya goto reject; 24381cab775cSVipul Pandya } 24391cab775cSVipul Pandya 2440cfdda9d7SSteve Wise if (state_read(&parent_ep->com) != LISTEN) { 24416812faefSHariprasad S PDBG("%s - listening ep not in LISTEN\n", __func__); 2442cfdda9d7SSteve Wise goto reject; 2443cfdda9d7SSteve Wise } 2444cfdda9d7SSteve Wise 2445963cab50SHariprasad S get_4tuple(req, parent_ep->com.dev->rdev.lldi.adapter_type, &iptype, 2446963cab50SHariprasad S local_ip, peer_ip, &local_port, &peer_port); 2447830662f6SVipul Pandya 2448cfdda9d7SSteve Wise /* Find output route */ 2449830662f6SVipul Pandya if (iptype == 4) { 2450830662f6SVipul Pandya PDBG("%s parent ep %p hwtid %u laddr %pI4 raddr %pI4 lport %d rport %d peer_mss %d\n" 2451830662f6SVipul Pandya , __func__, parent_ep, hwtid, 2452830662f6SVipul Pandya local_ip, peer_ip, ntohs(local_port), 2453830662f6SVipul Pandya ntohs(peer_port), peer_mss); 2454830662f6SVipul Pandya dst = find_route(dev, *(__be32 *)local_ip, *(__be32 *)peer_ip, 2455830662f6SVipul Pandya local_port, peer_port, 2456ac8e4c69SHariprasad S tos); 2457830662f6SVipul Pandya } else { 2458830662f6SVipul Pandya PDBG("%s parent ep %p hwtid %u laddr %pI6 raddr %pI6 lport %d rport %d peer_mss %d\n" 2459830662f6SVipul Pandya , __func__, parent_ep, hwtid, 2460830662f6SVipul Pandya local_ip, peer_ip, ntohs(local_port), 2461830662f6SVipul Pandya ntohs(peer_port), peer_mss); 2462830662f6SVipul Pandya dst = find_route6(dev, local_ip, peer_ip, local_port, peer_port, 24636c53e938SHariprasad Shenai PASS_OPEN_TOS_G(ntohl(req->tos_stid)), 2464830662f6SVipul Pandya ((struct sockaddr_in6 *) 2465830662f6SVipul Pandya &parent_ep->com.local_addr)->sin6_scope_id); 2466830662f6SVipul Pandya } 2467830662f6SVipul Pandya if (!dst) { 2468cfdda9d7SSteve Wise printk(KERN_ERR MOD "%s - failed to find dst entry!\n", 2469cfdda9d7SSteve Wise __func__); 2470cfdda9d7SSteve Wise goto reject; 2471cfdda9d7SSteve Wise } 2472cfdda9d7SSteve Wise 2473cfdda9d7SSteve Wise child_ep = alloc_ep(sizeof(*child_ep), GFP_KERNEL); 2474cfdda9d7SSteve Wise if (!child_ep) { 2475cfdda9d7SSteve Wise printk(KERN_ERR MOD "%s - failed to allocate ep entry!\n", 2476cfdda9d7SSteve Wise __func__); 2477cfdda9d7SSteve Wise dst_release(dst); 2478cfdda9d7SSteve Wise goto reject; 2479cfdda9d7SSteve Wise } 24803786cf18SDavid Miller 2481963cab50SHariprasad S err = import_ep(child_ep, iptype, peer_ip, dst, dev, false, 2482ac8e4c69SHariprasad S parent_ep->com.dev->rdev.lldi.adapter_type, tos); 24833786cf18SDavid Miller if (err) { 24843786cf18SDavid Miller printk(KERN_ERR MOD "%s - failed to allocate l2t entry!\n", 24853786cf18SDavid Miller __func__); 24863786cf18SDavid Miller dst_release(dst); 24873786cf18SDavid Miller kfree(child_ep); 24883786cf18SDavid Miller goto reject; 24893786cf18SDavid Miller } 24903786cf18SDavid Miller 249192e7ae71SHariprasad Shenai hdrs = sizeof(struct iphdr) + sizeof(struct tcphdr) + 249292e7ae71SHariprasad Shenai ((enable_tcp_timestamps && req->tcpopt.tstamp) ? 12 : 0); 249392e7ae71SHariprasad Shenai if (peer_mss && child_ep->mtu > (peer_mss + hdrs)) 249492e7ae71SHariprasad Shenai child_ep->mtu = peer_mss + hdrs; 24951cab775cSVipul Pandya 2496cfdda9d7SSteve Wise state_set(&child_ep->com, CONNECTING); 2497cfdda9d7SSteve Wise child_ep->com.dev = dev; 2498cfdda9d7SSteve Wise child_ep->com.cm_id = NULL; 24995b6b8fe6SSteve Wise 2500830662f6SVipul Pandya if (iptype == 4) { 2501830662f6SVipul Pandya struct sockaddr_in *sin = (struct sockaddr_in *) 2502170003c8SSteve Wise &child_ep->com.local_addr; 25035b6b8fe6SSteve Wise 2504830662f6SVipul Pandya sin->sin_family = PF_INET; 2505830662f6SVipul Pandya sin->sin_port = local_port; 2506830662f6SVipul Pandya sin->sin_addr.s_addr = *(__be32 *)local_ip; 25075b6b8fe6SSteve Wise 25085b6b8fe6SSteve Wise sin = (struct sockaddr_in *)&child_ep->com.local_addr; 25095b6b8fe6SSteve Wise sin->sin_family = PF_INET; 25105b6b8fe6SSteve Wise sin->sin_port = ((struct sockaddr_in *) 25115b6b8fe6SSteve Wise &parent_ep->com.local_addr)->sin_port; 25125b6b8fe6SSteve Wise sin->sin_addr.s_addr = *(__be32 *)local_ip; 25135b6b8fe6SSteve Wise 2514170003c8SSteve Wise sin = (struct sockaddr_in *)&child_ep->com.remote_addr; 2515830662f6SVipul Pandya sin->sin_family = PF_INET; 2516830662f6SVipul Pandya sin->sin_port = peer_port; 2517830662f6SVipul Pandya sin->sin_addr.s_addr = *(__be32 *)peer_ip; 2518830662f6SVipul Pandya } else { 2519170003c8SSteve Wise sin6 = (struct sockaddr_in6 *)&child_ep->com.local_addr; 2520830662f6SVipul Pandya sin6->sin6_family = PF_INET6; 2521830662f6SVipul Pandya sin6->sin6_port = local_port; 2522830662f6SVipul Pandya memcpy(sin6->sin6_addr.s6_addr, local_ip, 16); 25235b6b8fe6SSteve Wise 25245b6b8fe6SSteve Wise sin6 = (struct sockaddr_in6 *)&child_ep->com.local_addr; 25255b6b8fe6SSteve Wise sin6->sin6_family = PF_INET6; 25265b6b8fe6SSteve Wise sin6->sin6_port = ((struct sockaddr_in6 *) 25275b6b8fe6SSteve Wise &parent_ep->com.local_addr)->sin6_port; 25285b6b8fe6SSteve Wise memcpy(sin6->sin6_addr.s6_addr, local_ip, 16); 25295b6b8fe6SSteve Wise 2530170003c8SSteve Wise sin6 = (struct sockaddr_in6 *)&child_ep->com.remote_addr; 2531830662f6SVipul Pandya sin6->sin6_family = PF_INET6; 2532830662f6SVipul Pandya sin6->sin6_port = peer_port; 2533830662f6SVipul Pandya memcpy(sin6->sin6_addr.s6_addr, peer_ip, 16); 2534830662f6SVipul Pandya } 25355b6b8fe6SSteve Wise 2536cfdda9d7SSteve Wise c4iw_get_ep(&parent_ep->com); 2537cfdda9d7SSteve Wise child_ep->parent_ep = parent_ep; 2538ac8e4c69SHariprasad S child_ep->tos = tos; 2539cfdda9d7SSteve Wise child_ep->dst = dst; 2540cfdda9d7SSteve Wise child_ep->hwtid = hwtid; 2541cfdda9d7SSteve Wise 2542cfdda9d7SSteve Wise PDBG("%s tx_chan %u smac_idx %u rss_qid %u\n", __func__, 25433786cf18SDavid Miller child_ep->tx_chan, child_ep->smac_idx, child_ep->rss_qid); 2544cfdda9d7SSteve Wise 2545cfdda9d7SSteve Wise init_timer(&child_ep->timer); 2546cfdda9d7SSteve Wise cxgb4_insert_tid(t, child_ep, hwtid); 2547b3de6cfeSVipul Pandya insert_handle(dev, &dev->hwtid_idr, child_ep, child_ep->hwtid); 25489dec900cSHariprasad S if (accept_cr(child_ep, skb, req)) { 25499dec900cSHariprasad S c4iw_put_ep(&parent_ep->com); 25509dec900cSHariprasad S release_ep_resources(child_ep); 25519dec900cSHariprasad S } else { 2552793dad94SVipul Pandya set_bit(PASS_ACCEPT_REQ, &child_ep->com.history); 25539dec900cSHariprasad S } 255484cc6ac6SHariprasad S if (iptype == 6) { 2555170003c8SSteve Wise sin6 = (struct sockaddr_in6 *)&child_ep->com.local_addr; 255684cc6ac6SHariprasad S cxgb4_clip_get(child_ep->com.dev->rdev.lldi.ports[0], 255784cc6ac6SHariprasad S (const u32 *)&sin6->sin6_addr.s6_addr, 1); 255884cc6ac6SHariprasad S } 2559cfdda9d7SSteve Wise goto out; 2560cfdda9d7SSteve Wise reject: 2561830662f6SVipul Pandya reject_cr(dev, hwtid, skb); 2562cfdda9d7SSteve Wise out: 2563cfdda9d7SSteve Wise return 0; 2564cfdda9d7SSteve Wise } 2565cfdda9d7SSteve Wise 2566cfdda9d7SSteve Wise static int pass_establish(struct c4iw_dev *dev, struct sk_buff *skb) 2567cfdda9d7SSteve Wise { 2568cfdda9d7SSteve Wise struct c4iw_ep *ep; 2569cfdda9d7SSteve Wise struct cpl_pass_establish *req = cplhdr(skb); 2570cfdda9d7SSteve Wise struct tid_info *t = dev->rdev.lldi.tids; 2571cfdda9d7SSteve Wise unsigned int tid = GET_TID(req); 2572fef4422dSHariprasad S int ret; 2573cfdda9d7SSteve Wise 2574cfdda9d7SSteve Wise ep = lookup_tid(t, tid); 2575cfdda9d7SSteve Wise PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid); 2576cfdda9d7SSteve Wise ep->snd_seq = be32_to_cpu(req->snd_isn); 2577cfdda9d7SSteve Wise ep->rcv_seq = be32_to_cpu(req->rcv_isn); 2578cfdda9d7SSteve Wise 25791cab775cSVipul Pandya PDBG("%s ep %p hwtid %u tcp_opt 0x%02x\n", __func__, ep, tid, 25801cab775cSVipul Pandya ntohs(req->tcp_opt)); 25811cab775cSVipul Pandya 2582cfdda9d7SSteve Wise set_emss(ep, ntohs(req->tcp_opt)); 2583cfdda9d7SSteve Wise 2584cfdda9d7SSteve Wise dst_confirm(ep->dst); 2585fef4422dSHariprasad S mutex_lock(&ep->com.mutex); 2586fef4422dSHariprasad S ep->com.state = MPA_REQ_WAIT; 2587cfdda9d7SSteve Wise start_ep_timer(ep); 2588793dad94SVipul Pandya set_bit(PASS_ESTAB, &ep->com.history); 2589fef4422dSHariprasad S ret = send_flowc(ep, skb); 2590fef4422dSHariprasad S mutex_unlock(&ep->com.mutex); 2591fef4422dSHariprasad S if (ret) 2592fef4422dSHariprasad S c4iw_ep_disconnect(ep, 1, GFP_KERNEL); 2593cfdda9d7SSteve Wise 2594cfdda9d7SSteve Wise return 0; 2595cfdda9d7SSteve Wise } 2596cfdda9d7SSteve Wise 2597cfdda9d7SSteve Wise static int peer_close(struct c4iw_dev *dev, struct sk_buff *skb) 2598cfdda9d7SSteve Wise { 2599cfdda9d7SSteve Wise struct cpl_peer_close *hdr = cplhdr(skb); 2600cfdda9d7SSteve Wise struct c4iw_ep *ep; 2601cfdda9d7SSteve Wise struct c4iw_qp_attributes attrs; 2602cfdda9d7SSteve Wise int disconnect = 1; 2603cfdda9d7SSteve Wise int release = 0; 2604cfdda9d7SSteve Wise struct tid_info *t = dev->rdev.lldi.tids; 2605cfdda9d7SSteve Wise unsigned int tid = GET_TID(hdr); 26068da7e7a5SSteve Wise int ret; 2607cfdda9d7SSteve Wise 2608cfdda9d7SSteve Wise ep = lookup_tid(t, tid); 2609cfdda9d7SSteve Wise PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid); 2610cfdda9d7SSteve Wise dst_confirm(ep->dst); 2611cfdda9d7SSteve Wise 2612793dad94SVipul Pandya set_bit(PEER_CLOSE, &ep->com.history); 26132f5b48c3SSteve Wise mutex_lock(&ep->com.mutex); 2614cfdda9d7SSteve Wise switch (ep->com.state) { 2615cfdda9d7SSteve Wise case MPA_REQ_WAIT: 2616cfdda9d7SSteve Wise __state_set(&ep->com, CLOSING); 2617cfdda9d7SSteve Wise break; 2618cfdda9d7SSteve Wise case MPA_REQ_SENT: 2619cfdda9d7SSteve Wise __state_set(&ep->com, CLOSING); 2620cfdda9d7SSteve Wise connect_reply_upcall(ep, -ECONNRESET); 2621cfdda9d7SSteve Wise break; 2622cfdda9d7SSteve Wise case MPA_REQ_RCVD: 2623cfdda9d7SSteve Wise 2624cfdda9d7SSteve Wise /* 2625cfdda9d7SSteve Wise * We're gonna mark this puppy DEAD, but keep 2626cfdda9d7SSteve Wise * the reference on it until the ULP accepts or 2627cfdda9d7SSteve Wise * rejects the CR. Also wake up anyone waiting 2628cfdda9d7SSteve Wise * in rdma connection migration (see c4iw_accept_cr()). 2629cfdda9d7SSteve Wise */ 2630cfdda9d7SSteve Wise __state_set(&ep->com, CLOSING); 2631cfdda9d7SSteve Wise PDBG("waking up ep %p tid %u\n", ep, ep->hwtid); 2632d9594d99SSteve Wise c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET); 2633cfdda9d7SSteve Wise break; 2634cfdda9d7SSteve Wise case MPA_REP_SENT: 2635cfdda9d7SSteve Wise __state_set(&ep->com, CLOSING); 2636cfdda9d7SSteve Wise PDBG("waking up ep %p tid %u\n", ep, ep->hwtid); 2637d9594d99SSteve Wise c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET); 2638cfdda9d7SSteve Wise break; 2639cfdda9d7SSteve Wise case FPDU_MODE: 2640ca5a2202SSteve Wise start_ep_timer(ep); 2641cfdda9d7SSteve Wise __state_set(&ep->com, CLOSING); 264230c95c2dSSteve Wise attrs.next_state = C4IW_QP_STATE_CLOSING; 26438da7e7a5SSteve Wise ret = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp, 264430c95c2dSSteve Wise C4IW_QP_ATTR_NEXT_STATE, &attrs, 1); 26458da7e7a5SSteve Wise if (ret != -ECONNRESET) { 2646cfdda9d7SSteve Wise peer_close_upcall(ep); 264730c95c2dSSteve Wise disconnect = 1; 26488da7e7a5SSteve Wise } 2649cfdda9d7SSteve Wise break; 2650cfdda9d7SSteve Wise case ABORTING: 2651cfdda9d7SSteve Wise disconnect = 0; 2652cfdda9d7SSteve Wise break; 2653cfdda9d7SSteve Wise case CLOSING: 2654cfdda9d7SSteve Wise __state_set(&ep->com, MORIBUND); 2655cfdda9d7SSteve Wise disconnect = 0; 2656cfdda9d7SSteve Wise break; 2657cfdda9d7SSteve Wise case MORIBUND: 2658b33bd0cbSSteve Wise (void)stop_ep_timer(ep); 2659cfdda9d7SSteve Wise if (ep->com.cm_id && ep->com.qp) { 2660cfdda9d7SSteve Wise attrs.next_state = C4IW_QP_STATE_IDLE; 2661cfdda9d7SSteve Wise c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp, 2662cfdda9d7SSteve Wise C4IW_QP_ATTR_NEXT_STATE, &attrs, 1); 2663cfdda9d7SSteve Wise } 2664be13b2dfSSteve Wise close_complete_upcall(ep, 0); 2665cfdda9d7SSteve Wise __state_set(&ep->com, DEAD); 2666cfdda9d7SSteve Wise release = 1; 2667cfdda9d7SSteve Wise disconnect = 0; 2668cfdda9d7SSteve Wise break; 2669cfdda9d7SSteve Wise case DEAD: 2670cfdda9d7SSteve Wise disconnect = 0; 2671cfdda9d7SSteve Wise break; 2672cfdda9d7SSteve Wise default: 2673cfdda9d7SSteve Wise BUG_ON(1); 2674cfdda9d7SSteve Wise } 26752f5b48c3SSteve Wise mutex_unlock(&ep->com.mutex); 2676cfdda9d7SSteve Wise if (disconnect) 2677cfdda9d7SSteve Wise c4iw_ep_disconnect(ep, 0, GFP_KERNEL); 2678cfdda9d7SSteve Wise if (release) 2679cfdda9d7SSteve Wise release_ep_resources(ep); 2680cfdda9d7SSteve Wise return 0; 2681cfdda9d7SSteve Wise } 2682cfdda9d7SSteve Wise 2683cfdda9d7SSteve Wise static int peer_abort(struct c4iw_dev *dev, struct sk_buff *skb) 2684cfdda9d7SSteve Wise { 2685cfdda9d7SSteve Wise struct cpl_abort_req_rss *req = cplhdr(skb); 2686cfdda9d7SSteve Wise struct c4iw_ep *ep; 2687cfdda9d7SSteve Wise struct cpl_abort_rpl *rpl; 2688cfdda9d7SSteve Wise struct sk_buff *rpl_skb; 2689cfdda9d7SSteve Wise struct c4iw_qp_attributes attrs; 2690cfdda9d7SSteve Wise int ret; 2691cfdda9d7SSteve Wise int release = 0; 2692cfdda9d7SSteve Wise struct tid_info *t = dev->rdev.lldi.tids; 2693cfdda9d7SSteve Wise unsigned int tid = GET_TID(req); 2694cfdda9d7SSteve Wise 2695cfdda9d7SSteve Wise ep = lookup_tid(t, tid); 26967a2cea2aSSteve Wise if (is_neg_adv(req->status)) { 2697179d03bbSHariprasad S PDBG("%s Negative advice on abort- tid %u status %d (%s)\n", 2698179d03bbSHariprasad S __func__, ep->hwtid, req->status, 2699179d03bbSHariprasad S neg_adv_str(req->status)); 2700179d03bbSHariprasad S ep->stats.abort_neg_adv++; 2701179d03bbSHariprasad S mutex_lock(&dev->rdev.stats.lock); 2702179d03bbSHariprasad S dev->rdev.stats.neg_adv++; 2703179d03bbSHariprasad S mutex_unlock(&dev->rdev.stats.lock); 2704cfdda9d7SSteve Wise return 0; 2705cfdda9d7SSteve Wise } 2706cfdda9d7SSteve Wise PDBG("%s ep %p tid %u state %u\n", __func__, ep, ep->hwtid, 2707cfdda9d7SSteve Wise ep->com.state); 2708793dad94SVipul Pandya set_bit(PEER_ABORT, &ep->com.history); 27092f5b48c3SSteve Wise 27102f5b48c3SSteve Wise /* 27112f5b48c3SSteve Wise * Wake up any threads in rdma_init() or rdma_fini(). 2712d2fe99e8SKumar Sanghvi * However, this is not needed if com state is just 2713d2fe99e8SKumar Sanghvi * MPA_REQ_SENT 27142f5b48c3SSteve Wise */ 2715d2fe99e8SKumar Sanghvi if (ep->com.state != MPA_REQ_SENT) 2716d9594d99SSteve Wise c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET); 27172f5b48c3SSteve Wise 27182f5b48c3SSteve Wise mutex_lock(&ep->com.mutex); 2719cfdda9d7SSteve Wise switch (ep->com.state) { 2720cfdda9d7SSteve Wise case CONNECTING: 27219dec900cSHariprasad S c4iw_put_ep(&ep->parent_ep->com); 2722cfdda9d7SSteve Wise break; 2723cfdda9d7SSteve Wise case MPA_REQ_WAIT: 2724b33bd0cbSSteve Wise (void)stop_ep_timer(ep); 2725cfdda9d7SSteve Wise break; 2726cfdda9d7SSteve Wise case MPA_REQ_SENT: 2727b33bd0cbSSteve Wise (void)stop_ep_timer(ep); 2728fe7e0a4dSVipul Pandya if (mpa_rev == 1 || (mpa_rev == 2 && ep->tried_with_mpa_v1)) 2729cfdda9d7SSteve Wise connect_reply_upcall(ep, -ECONNRESET); 2730d2fe99e8SKumar Sanghvi else { 2731d2fe99e8SKumar Sanghvi /* 2732d2fe99e8SKumar Sanghvi * we just don't send notification upwards because we 2733d2fe99e8SKumar Sanghvi * want to retry with mpa_v1 without upper layers even 2734d2fe99e8SKumar Sanghvi * knowing it. 2735d2fe99e8SKumar Sanghvi * 2736d2fe99e8SKumar Sanghvi * do some housekeeping so as to re-initiate the 2737d2fe99e8SKumar Sanghvi * connection 2738d2fe99e8SKumar Sanghvi */ 2739d2fe99e8SKumar Sanghvi PDBG("%s: mpa_rev=%d. Retrying with mpav1\n", __func__, 2740d2fe99e8SKumar Sanghvi mpa_rev); 2741d2fe99e8SKumar Sanghvi ep->retry_with_mpa_v1 = 1; 2742d2fe99e8SKumar Sanghvi } 2743cfdda9d7SSteve Wise break; 2744cfdda9d7SSteve Wise case MPA_REP_SENT: 2745cfdda9d7SSteve Wise break; 2746cfdda9d7SSteve Wise case MPA_REQ_RCVD: 2747cfdda9d7SSteve Wise break; 2748cfdda9d7SSteve Wise case MORIBUND: 2749cfdda9d7SSteve Wise case CLOSING: 2750ca5a2202SSteve Wise stop_ep_timer(ep); 2751cfdda9d7SSteve Wise /*FALLTHROUGH*/ 2752cfdda9d7SSteve Wise case FPDU_MODE: 2753cfdda9d7SSteve Wise if (ep->com.cm_id && ep->com.qp) { 2754cfdda9d7SSteve Wise attrs.next_state = C4IW_QP_STATE_ERROR; 2755cfdda9d7SSteve Wise ret = c4iw_modify_qp(ep->com.qp->rhp, 2756cfdda9d7SSteve Wise ep->com.qp, C4IW_QP_ATTR_NEXT_STATE, 2757cfdda9d7SSteve Wise &attrs, 1); 2758cfdda9d7SSteve Wise if (ret) 2759cfdda9d7SSteve Wise printk(KERN_ERR MOD 2760cfdda9d7SSteve Wise "%s - qp <- error failed!\n", 2761cfdda9d7SSteve Wise __func__); 2762cfdda9d7SSteve Wise } 2763cfdda9d7SSteve Wise peer_abort_upcall(ep); 2764cfdda9d7SSteve Wise break; 2765cfdda9d7SSteve Wise case ABORTING: 2766cfdda9d7SSteve Wise break; 2767cfdda9d7SSteve Wise case DEAD: 2768cfdda9d7SSteve Wise PDBG("%s PEER_ABORT IN DEAD STATE!!!!\n", __func__); 27692f5b48c3SSteve Wise mutex_unlock(&ep->com.mutex); 2770cfdda9d7SSteve Wise return 0; 2771cfdda9d7SSteve Wise default: 2772cfdda9d7SSteve Wise BUG_ON(1); 2773cfdda9d7SSteve Wise break; 2774cfdda9d7SSteve Wise } 2775cfdda9d7SSteve Wise dst_confirm(ep->dst); 2776cfdda9d7SSteve Wise if (ep->com.state != ABORTING) { 2777cfdda9d7SSteve Wise __state_set(&ep->com, DEAD); 2778d2fe99e8SKumar Sanghvi /* we don't release if we want to retry with mpa_v1 */ 2779d2fe99e8SKumar Sanghvi if (!ep->retry_with_mpa_v1) 2780cfdda9d7SSteve Wise release = 1; 2781cfdda9d7SSteve Wise } 27822f5b48c3SSteve Wise mutex_unlock(&ep->com.mutex); 2783cfdda9d7SSteve Wise 2784cfdda9d7SSteve Wise rpl_skb = get_skb(skb, sizeof(*rpl), GFP_KERNEL); 2785cfdda9d7SSteve Wise if (!rpl_skb) { 2786cfdda9d7SSteve Wise printk(KERN_ERR MOD "%s - cannot allocate skb!\n", 2787cfdda9d7SSteve Wise __func__); 2788cfdda9d7SSteve Wise release = 1; 2789cfdda9d7SSteve Wise goto out; 2790cfdda9d7SSteve Wise } 2791cfdda9d7SSteve Wise set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx); 2792cfdda9d7SSteve Wise rpl = (struct cpl_abort_rpl *) skb_put(rpl_skb, sizeof(*rpl)); 2793cfdda9d7SSteve Wise INIT_TP_WR(rpl, ep->hwtid); 2794cfdda9d7SSteve Wise OPCODE_TID(rpl) = cpu_to_be32(MK_OPCODE_TID(CPL_ABORT_RPL, ep->hwtid)); 2795cfdda9d7SSteve Wise rpl->cmd = CPL_ABORT_NO_RST; 2796cfdda9d7SSteve Wise c4iw_ofld_send(&ep->com.dev->rdev, rpl_skb); 2797cfdda9d7SSteve Wise out: 2798cfdda9d7SSteve Wise if (release) 2799cfdda9d7SSteve Wise release_ep_resources(ep); 2800fe7e0a4dSVipul Pandya else if (ep->retry_with_mpa_v1) { 280184cc6ac6SHariprasad S if (ep->com.remote_addr.ss_family == AF_INET6) { 280284cc6ac6SHariprasad S struct sockaddr_in6 *sin6 = 280384cc6ac6SHariprasad S (struct sockaddr_in6 *) 2804170003c8SSteve Wise &ep->com.local_addr; 280584cc6ac6SHariprasad S cxgb4_clip_release( 280684cc6ac6SHariprasad S ep->com.dev->rdev.lldi.ports[0], 280784cc6ac6SHariprasad S (const u32 *)&sin6->sin6_addr.s6_addr, 280884cc6ac6SHariprasad S 1); 280984cc6ac6SHariprasad S } 2810fe7e0a4dSVipul Pandya remove_handle(ep->com.dev, &ep->com.dev->hwtid_idr, ep->hwtid); 2811d2fe99e8SKumar Sanghvi cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, ep->hwtid); 2812d2fe99e8SKumar Sanghvi dst_release(ep->dst); 2813d2fe99e8SKumar Sanghvi cxgb4_l2t_release(ep->l2t); 2814d2fe99e8SKumar Sanghvi c4iw_reconnect(ep); 2815d2fe99e8SKumar Sanghvi } 2816d2fe99e8SKumar Sanghvi 2817cfdda9d7SSteve Wise return 0; 2818cfdda9d7SSteve Wise } 2819cfdda9d7SSteve Wise 2820cfdda9d7SSteve Wise static int close_con_rpl(struct c4iw_dev *dev, struct sk_buff *skb) 2821cfdda9d7SSteve Wise { 2822cfdda9d7SSteve Wise struct c4iw_ep *ep; 2823cfdda9d7SSteve Wise struct c4iw_qp_attributes attrs; 2824cfdda9d7SSteve Wise struct cpl_close_con_rpl *rpl = cplhdr(skb); 2825cfdda9d7SSteve Wise int release = 0; 2826cfdda9d7SSteve Wise struct tid_info *t = dev->rdev.lldi.tids; 2827cfdda9d7SSteve Wise unsigned int tid = GET_TID(rpl); 2828cfdda9d7SSteve Wise 2829cfdda9d7SSteve Wise ep = lookup_tid(t, tid); 2830cfdda9d7SSteve Wise 2831cfdda9d7SSteve Wise PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid); 2832cfdda9d7SSteve Wise BUG_ON(!ep); 2833cfdda9d7SSteve Wise 2834cfdda9d7SSteve Wise /* The cm_id may be null if we failed to connect */ 28352f5b48c3SSteve Wise mutex_lock(&ep->com.mutex); 28369ca6f7cfSHariprasad S set_bit(CLOSE_CON_RPL, &ep->com.history); 2837cfdda9d7SSteve Wise switch (ep->com.state) { 2838cfdda9d7SSteve Wise case CLOSING: 2839cfdda9d7SSteve Wise __state_set(&ep->com, MORIBUND); 2840cfdda9d7SSteve Wise break; 2841cfdda9d7SSteve Wise case MORIBUND: 2842b33bd0cbSSteve Wise (void)stop_ep_timer(ep); 2843cfdda9d7SSteve Wise if ((ep->com.cm_id) && (ep->com.qp)) { 2844cfdda9d7SSteve Wise attrs.next_state = C4IW_QP_STATE_IDLE; 2845cfdda9d7SSteve Wise c4iw_modify_qp(ep->com.qp->rhp, 2846cfdda9d7SSteve Wise ep->com.qp, 2847cfdda9d7SSteve Wise C4IW_QP_ATTR_NEXT_STATE, 2848cfdda9d7SSteve Wise &attrs, 1); 2849cfdda9d7SSteve Wise } 2850be13b2dfSSteve Wise close_complete_upcall(ep, 0); 2851cfdda9d7SSteve Wise __state_set(&ep->com, DEAD); 2852cfdda9d7SSteve Wise release = 1; 2853cfdda9d7SSteve Wise break; 2854cfdda9d7SSteve Wise case ABORTING: 2855cfdda9d7SSteve Wise case DEAD: 2856cfdda9d7SSteve Wise break; 2857cfdda9d7SSteve Wise default: 2858cfdda9d7SSteve Wise BUG_ON(1); 2859cfdda9d7SSteve Wise break; 2860cfdda9d7SSteve Wise } 28612f5b48c3SSteve Wise mutex_unlock(&ep->com.mutex); 2862cfdda9d7SSteve Wise if (release) 2863cfdda9d7SSteve Wise release_ep_resources(ep); 2864cfdda9d7SSteve Wise return 0; 2865cfdda9d7SSteve Wise } 2866cfdda9d7SSteve Wise 2867cfdda9d7SSteve Wise static int terminate(struct c4iw_dev *dev, struct sk_buff *skb) 2868cfdda9d7SSteve Wise { 28690e42c1f4SSteve Wise struct cpl_rdma_terminate *rpl = cplhdr(skb); 2870cfdda9d7SSteve Wise struct tid_info *t = dev->rdev.lldi.tids; 28710e42c1f4SSteve Wise unsigned int tid = GET_TID(rpl); 28720e42c1f4SSteve Wise struct c4iw_ep *ep; 28730e42c1f4SSteve Wise struct c4iw_qp_attributes attrs; 2874cfdda9d7SSteve Wise 2875cfdda9d7SSteve Wise ep = lookup_tid(t, tid); 28760e42c1f4SSteve Wise BUG_ON(!ep); 2877cfdda9d7SSteve Wise 287830c95c2dSSteve Wise if (ep && ep->com.qp) { 28790e42c1f4SSteve Wise printk(KERN_WARNING MOD "TERM received tid %u qpid %u\n", tid, 28800e42c1f4SSteve Wise ep->com.qp->wq.sq.qid); 28810e42c1f4SSteve Wise attrs.next_state = C4IW_QP_STATE_TERMINATE; 28820e42c1f4SSteve Wise c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp, 28830e42c1f4SSteve Wise C4IW_QP_ATTR_NEXT_STATE, &attrs, 1); 28840e42c1f4SSteve Wise } else 288530c95c2dSSteve Wise printk(KERN_WARNING MOD "TERM received tid %u no ep/qp\n", tid); 2886cfdda9d7SSteve Wise 2887cfdda9d7SSteve Wise return 0; 2888cfdda9d7SSteve Wise } 2889cfdda9d7SSteve Wise 2890cfdda9d7SSteve Wise /* 2891cfdda9d7SSteve Wise * Upcall from the adapter indicating data has been transmitted. 2892cfdda9d7SSteve Wise * For us its just the single MPA request or reply. We can now free 2893cfdda9d7SSteve Wise * the skb holding the mpa message. 2894cfdda9d7SSteve Wise */ 2895cfdda9d7SSteve Wise static int fw4_ack(struct c4iw_dev *dev, struct sk_buff *skb) 2896cfdda9d7SSteve Wise { 2897cfdda9d7SSteve Wise struct c4iw_ep *ep; 2898cfdda9d7SSteve Wise struct cpl_fw4_ack *hdr = cplhdr(skb); 2899cfdda9d7SSteve Wise u8 credits = hdr->credits; 2900cfdda9d7SSteve Wise unsigned int tid = GET_TID(hdr); 2901cfdda9d7SSteve Wise struct tid_info *t = dev->rdev.lldi.tids; 2902cfdda9d7SSteve Wise 2903cfdda9d7SSteve Wise 2904cfdda9d7SSteve Wise ep = lookup_tid(t, tid); 2905cfdda9d7SSteve Wise PDBG("%s ep %p tid %u credits %u\n", __func__, ep, ep->hwtid, credits); 2906cfdda9d7SSteve Wise if (credits == 0) { 2907aa1ad260SJoe Perches PDBG("%s 0 credit ack ep %p tid %u state %u\n", 2908cfdda9d7SSteve Wise __func__, ep, ep->hwtid, state_read(&ep->com)); 2909cfdda9d7SSteve Wise return 0; 2910cfdda9d7SSteve Wise } 2911cfdda9d7SSteve Wise 2912cfdda9d7SSteve Wise dst_confirm(ep->dst); 2913cfdda9d7SSteve Wise if (ep->mpa_skb) { 2914cfdda9d7SSteve Wise PDBG("%s last streaming msg ack ep %p tid %u state %u " 2915cfdda9d7SSteve Wise "initiator %u freeing skb\n", __func__, ep, ep->hwtid, 2916cfdda9d7SSteve Wise state_read(&ep->com), ep->mpa_attr.initiator ? 1 : 0); 2917cfdda9d7SSteve Wise kfree_skb(ep->mpa_skb); 2918cfdda9d7SSteve Wise ep->mpa_skb = NULL; 2919e4b76a2aSHariprasad S mutex_lock(&ep->com.mutex); 2920e4b76a2aSHariprasad S if (test_bit(STOP_MPA_TIMER, &ep->com.flags)) 2921e4b76a2aSHariprasad S stop_ep_timer(ep); 2922e4b76a2aSHariprasad S mutex_unlock(&ep->com.mutex); 2923cfdda9d7SSteve Wise } 2924cfdda9d7SSteve Wise return 0; 2925cfdda9d7SSteve Wise } 2926cfdda9d7SSteve Wise 2927cfdda9d7SSteve Wise int c4iw_reject_cr(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len) 2928cfdda9d7SSteve Wise { 2929a7db89ebSSteve Wise int err = 0; 2930a7db89ebSSteve Wise int disconnect = 0; 2931cfdda9d7SSteve Wise struct c4iw_ep *ep = to_ep(cm_id); 2932cfdda9d7SSteve Wise PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid); 2933cfdda9d7SSteve Wise 2934a7db89ebSSteve Wise mutex_lock(&ep->com.mutex); 2935a7db89ebSSteve Wise if (ep->com.state == DEAD) { 2936a7db89ebSSteve Wise mutex_unlock(&ep->com.mutex); 2937cfdda9d7SSteve Wise c4iw_put_ep(&ep->com); 2938cfdda9d7SSteve Wise return -ECONNRESET; 2939cfdda9d7SSteve Wise } 2940793dad94SVipul Pandya set_bit(ULP_REJECT, &ep->com.history); 2941a7db89ebSSteve Wise BUG_ON(ep->com.state != MPA_REQ_RCVD); 2942cfdda9d7SSteve Wise if (mpa_rev == 0) 2943eaf4c6d4SHariprasad S disconnect = 2; 2944cfdda9d7SSteve Wise else { 2945cfdda9d7SSteve Wise err = send_mpa_reject(ep, pdata, pdata_len); 2946a7db89ebSSteve Wise disconnect = 1; 2947cfdda9d7SSteve Wise } 2948a7db89ebSSteve Wise mutex_unlock(&ep->com.mutex); 2949e4b76a2aSHariprasad S if (disconnect) { 2950e4b76a2aSHariprasad S stop_ep_timer(ep); 2951eaf4c6d4SHariprasad S err = c4iw_ep_disconnect(ep, disconnect == 2, GFP_KERNEL); 2952e4b76a2aSHariprasad S } 2953cfdda9d7SSteve Wise c4iw_put_ep(&ep->com); 2954cfdda9d7SSteve Wise return 0; 2955cfdda9d7SSteve Wise } 2956cfdda9d7SSteve Wise 2957cfdda9d7SSteve Wise int c4iw_accept_cr(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param) 2958cfdda9d7SSteve Wise { 2959cfdda9d7SSteve Wise int err; 2960cfdda9d7SSteve Wise struct c4iw_qp_attributes attrs; 2961cfdda9d7SSteve Wise enum c4iw_qp_attr_mask mask; 2962cfdda9d7SSteve Wise struct c4iw_ep *ep = to_ep(cm_id); 2963cfdda9d7SSteve Wise struct c4iw_dev *h = to_c4iw_dev(cm_id->device); 2964cfdda9d7SSteve Wise struct c4iw_qp *qp = get_qhp(h, conn_param->qpn); 2965eaf4c6d4SHariprasad S int abort = 0; 2966cfdda9d7SSteve Wise 2967cfdda9d7SSteve Wise PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid); 2968a7db89ebSSteve Wise 2969a7db89ebSSteve Wise mutex_lock(&ep->com.mutex); 2970a7db89ebSSteve Wise if (ep->com.state == DEAD) { 2971cfdda9d7SSteve Wise err = -ECONNRESET; 2972eaf4c6d4SHariprasad S goto err_out; 2973cfdda9d7SSteve Wise } 2974cfdda9d7SSteve Wise 2975a7db89ebSSteve Wise BUG_ON(ep->com.state != MPA_REQ_RCVD); 2976cfdda9d7SSteve Wise BUG_ON(!qp); 2977cfdda9d7SSteve Wise 2978793dad94SVipul Pandya set_bit(ULP_ACCEPT, &ep->com.history); 29794c2c5763SHariprasad Shenai if ((conn_param->ord > cur_max_read_depth(ep->com.dev)) || 29804c2c5763SHariprasad Shenai (conn_param->ird > cur_max_read_depth(ep->com.dev))) { 2981cfdda9d7SSteve Wise err = -EINVAL; 2982eaf4c6d4SHariprasad S goto err_abort; 2983cfdda9d7SSteve Wise } 2984cfdda9d7SSteve Wise 2985d2fe99e8SKumar Sanghvi if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) { 2986d2fe99e8SKumar Sanghvi if (conn_param->ord > ep->ird) { 29874c2c5763SHariprasad Shenai if (RELAXED_IRD_NEGOTIATION) { 29884c2c5763SHariprasad Shenai ep->ord = ep->ird; 29894c2c5763SHariprasad Shenai } else { 2990d2fe99e8SKumar Sanghvi ep->ird = conn_param->ird; 2991d2fe99e8SKumar Sanghvi ep->ord = conn_param->ord; 2992d2fe99e8SKumar Sanghvi send_mpa_reject(ep, conn_param->private_data, 2993d2fe99e8SKumar Sanghvi conn_param->private_data_len); 2994d2fe99e8SKumar Sanghvi err = -ENOMEM; 2995eaf4c6d4SHariprasad S goto err_abort; 2996d2fe99e8SKumar Sanghvi } 29974c2c5763SHariprasad Shenai } 29984c2c5763SHariprasad Shenai if (conn_param->ird < ep->ord) { 29994c2c5763SHariprasad Shenai if (RELAXED_IRD_NEGOTIATION && 30004c2c5763SHariprasad Shenai ep->ord <= h->rdev.lldi.max_ordird_qp) { 30014c2c5763SHariprasad Shenai conn_param->ird = ep->ord; 30024c2c5763SHariprasad Shenai } else { 3003d2fe99e8SKumar Sanghvi err = -ENOMEM; 3004eaf4c6d4SHariprasad S goto err_abort; 3005d2fe99e8SKumar Sanghvi } 3006d2fe99e8SKumar Sanghvi } 3007d2fe99e8SKumar Sanghvi } 3008cfdda9d7SSteve Wise ep->ird = conn_param->ird; 3009cfdda9d7SSteve Wise ep->ord = conn_param->ord; 3010cfdda9d7SSteve Wise 30114c2c5763SHariprasad Shenai if (ep->mpa_attr.version == 1) { 3012cfdda9d7SSteve Wise if (peer2peer && ep->ird == 0) 3013cfdda9d7SSteve Wise ep->ird = 1; 30144c2c5763SHariprasad Shenai } else { 30154c2c5763SHariprasad Shenai if (peer2peer && 30164c2c5763SHariprasad Shenai (ep->mpa_attr.p2p_type != FW_RI_INIT_P2PTYPE_DISABLED) && 3017f57b780cSHariprasad S (p2p_type == FW_RI_INIT_P2PTYPE_READ_REQ) && ep->ird == 0) 30184c2c5763SHariprasad Shenai ep->ird = 1; 30194c2c5763SHariprasad Shenai } 3020cfdda9d7SSteve Wise 3021cfdda9d7SSteve Wise PDBG("%s %d ird %d ord %d\n", __func__, __LINE__, ep->ird, ep->ord); 3022cfdda9d7SSteve Wise 3023d2fe99e8SKumar Sanghvi ep->com.cm_id = cm_id; 30249ca6f7cfSHariprasad S ref_cm_id(&ep->com); 3025d2fe99e8SKumar Sanghvi ep->com.qp = qp; 3026325abeadSVipul Pandya ref_qp(ep); 3027d2fe99e8SKumar Sanghvi 3028cfdda9d7SSteve Wise /* bind QP to EP and move to RTS */ 3029cfdda9d7SSteve Wise attrs.mpa_attr = ep->mpa_attr; 3030cfdda9d7SSteve Wise attrs.max_ird = ep->ird; 3031cfdda9d7SSteve Wise attrs.max_ord = ep->ord; 3032cfdda9d7SSteve Wise attrs.llp_stream_handle = ep; 3033cfdda9d7SSteve Wise attrs.next_state = C4IW_QP_STATE_RTS; 3034cfdda9d7SSteve Wise 3035cfdda9d7SSteve Wise /* bind QP and TID with INIT_WR */ 3036cfdda9d7SSteve Wise mask = C4IW_QP_ATTR_NEXT_STATE | 3037cfdda9d7SSteve Wise C4IW_QP_ATTR_LLP_STREAM_HANDLE | 3038cfdda9d7SSteve Wise C4IW_QP_ATTR_MPA_ATTR | 3039cfdda9d7SSteve Wise C4IW_QP_ATTR_MAX_IRD | 3040cfdda9d7SSteve Wise C4IW_QP_ATTR_MAX_ORD; 3041cfdda9d7SSteve Wise 3042cfdda9d7SSteve Wise err = c4iw_modify_qp(ep->com.qp->rhp, 3043cfdda9d7SSteve Wise ep->com.qp, mask, &attrs, 1); 3044cfdda9d7SSteve Wise if (err) 3045eaf4c6d4SHariprasad S goto err_deref_cm_id; 3046e4b76a2aSHariprasad S 3047e4b76a2aSHariprasad S set_bit(STOP_MPA_TIMER, &ep->com.flags); 3048cfdda9d7SSteve Wise err = send_mpa_reply(ep, conn_param->private_data, 3049cfdda9d7SSteve Wise conn_param->private_data_len); 3050cfdda9d7SSteve Wise if (err) 3051eaf4c6d4SHariprasad S goto err_deref_cm_id; 3052cfdda9d7SSteve Wise 3053a7db89ebSSteve Wise __state_set(&ep->com, FPDU_MODE); 3054cfdda9d7SSteve Wise established_upcall(ep); 3055a7db89ebSSteve Wise mutex_unlock(&ep->com.mutex); 3056cfdda9d7SSteve Wise c4iw_put_ep(&ep->com); 3057cfdda9d7SSteve Wise return 0; 3058eaf4c6d4SHariprasad S err_deref_cm_id: 30599ca6f7cfSHariprasad S deref_cm_id(&ep->com); 3060eaf4c6d4SHariprasad S err_abort: 3061eaf4c6d4SHariprasad S abort = 1; 3062eaf4c6d4SHariprasad S err_out: 3063a7db89ebSSteve Wise mutex_unlock(&ep->com.mutex); 3064eaf4c6d4SHariprasad S if (abort) 3065eaf4c6d4SHariprasad S c4iw_ep_disconnect(ep, 1, GFP_KERNEL); 3066cfdda9d7SSteve Wise c4iw_put_ep(&ep->com); 3067cfdda9d7SSteve Wise return err; 3068cfdda9d7SSteve Wise } 3069cfdda9d7SSteve Wise 3070830662f6SVipul Pandya static int pick_local_ipaddrs(struct c4iw_dev *dev, struct iw_cm_id *cm_id) 3071830662f6SVipul Pandya { 3072830662f6SVipul Pandya struct in_device *ind; 3073830662f6SVipul Pandya int found = 0; 3074170003c8SSteve Wise struct sockaddr_in *laddr = (struct sockaddr_in *)&cm_id->m_local_addr; 3075170003c8SSteve Wise struct sockaddr_in *raddr = (struct sockaddr_in *)&cm_id->m_remote_addr; 3076830662f6SVipul Pandya 3077830662f6SVipul Pandya ind = in_dev_get(dev->rdev.lldi.ports[0]); 3078830662f6SVipul Pandya if (!ind) 3079830662f6SVipul Pandya return -EADDRNOTAVAIL; 3080830662f6SVipul Pandya for_primary_ifa(ind) { 3081830662f6SVipul Pandya laddr->sin_addr.s_addr = ifa->ifa_address; 3082830662f6SVipul Pandya raddr->sin_addr.s_addr = ifa->ifa_address; 3083830662f6SVipul Pandya found = 1; 3084830662f6SVipul Pandya break; 3085830662f6SVipul Pandya } 3086830662f6SVipul Pandya endfor_ifa(ind); 3087830662f6SVipul Pandya in_dev_put(ind); 3088830662f6SVipul Pandya return found ? 0 : -EADDRNOTAVAIL; 3089830662f6SVipul Pandya } 3090830662f6SVipul Pandya 3091830662f6SVipul Pandya static int get_lladdr(struct net_device *dev, struct in6_addr *addr, 3092830662f6SVipul Pandya unsigned char banned_flags) 3093830662f6SVipul Pandya { 3094830662f6SVipul Pandya struct inet6_dev *idev; 3095830662f6SVipul Pandya int err = -EADDRNOTAVAIL; 3096830662f6SVipul Pandya 3097830662f6SVipul Pandya rcu_read_lock(); 3098830662f6SVipul Pandya idev = __in6_dev_get(dev); 3099830662f6SVipul Pandya if (idev != NULL) { 3100830662f6SVipul Pandya struct inet6_ifaddr *ifp; 3101830662f6SVipul Pandya 3102830662f6SVipul Pandya read_lock_bh(&idev->lock); 3103830662f6SVipul Pandya list_for_each_entry(ifp, &idev->addr_list, if_list) { 3104830662f6SVipul Pandya if (ifp->scope == IFA_LINK && 3105830662f6SVipul Pandya !(ifp->flags & banned_flags)) { 3106830662f6SVipul Pandya memcpy(addr, &ifp->addr, 16); 3107830662f6SVipul Pandya err = 0; 3108830662f6SVipul Pandya break; 3109830662f6SVipul Pandya } 3110830662f6SVipul Pandya } 3111830662f6SVipul Pandya read_unlock_bh(&idev->lock); 3112830662f6SVipul Pandya } 3113830662f6SVipul Pandya rcu_read_unlock(); 3114830662f6SVipul Pandya return err; 3115830662f6SVipul Pandya } 3116830662f6SVipul Pandya 3117830662f6SVipul Pandya static int pick_local_ip6addrs(struct c4iw_dev *dev, struct iw_cm_id *cm_id) 3118830662f6SVipul Pandya { 3119830662f6SVipul Pandya struct in6_addr uninitialized_var(addr); 3120170003c8SSteve Wise struct sockaddr_in6 *la6 = (struct sockaddr_in6 *)&cm_id->m_local_addr; 3121170003c8SSteve Wise struct sockaddr_in6 *ra6 = (struct sockaddr_in6 *)&cm_id->m_remote_addr; 3122830662f6SVipul Pandya 312354b9a96fSNicholas Krause if (!get_lladdr(dev->rdev.lldi.ports[0], &addr, IFA_F_TENTATIVE)) { 3124830662f6SVipul Pandya memcpy(la6->sin6_addr.s6_addr, &addr, 16); 3125830662f6SVipul Pandya memcpy(ra6->sin6_addr.s6_addr, &addr, 16); 3126830662f6SVipul Pandya return 0; 3127830662f6SVipul Pandya } 3128830662f6SVipul Pandya return -EADDRNOTAVAIL; 3129830662f6SVipul Pandya } 3130830662f6SVipul Pandya 3131cfdda9d7SSteve Wise int c4iw_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param) 3132cfdda9d7SSteve Wise { 3133cfdda9d7SSteve Wise struct c4iw_dev *dev = to_c4iw_dev(cm_id->device); 3134cfdda9d7SSteve Wise struct c4iw_ep *ep; 31353786cf18SDavid Miller int err = 0; 31369eccfe10SSteve Wise struct sockaddr_in *laddr; 31379eccfe10SSteve Wise struct sockaddr_in *raddr; 31389eccfe10SSteve Wise struct sockaddr_in6 *laddr6; 31399eccfe10SSteve Wise struct sockaddr_in6 *raddr6; 3140830662f6SVipul Pandya __u8 *ra; 3141830662f6SVipul Pandya int iptype; 3142cfdda9d7SSteve Wise 31434c2c5763SHariprasad Shenai if ((conn_param->ord > cur_max_read_depth(dev)) || 31444c2c5763SHariprasad Shenai (conn_param->ird > cur_max_read_depth(dev))) { 3145be4c9badSRoland Dreier err = -EINVAL; 3146be4c9badSRoland Dreier goto out; 3147be4c9badSRoland Dreier } 3148cfdda9d7SSteve Wise ep = alloc_ep(sizeof(*ep), GFP_KERNEL); 3149cfdda9d7SSteve Wise if (!ep) { 3150cfdda9d7SSteve Wise printk(KERN_ERR MOD "%s - cannot alloc ep.\n", __func__); 3151cfdda9d7SSteve Wise err = -ENOMEM; 3152cfdda9d7SSteve Wise goto out; 3153cfdda9d7SSteve Wise } 3154cfdda9d7SSteve Wise init_timer(&ep->timer); 3155cfdda9d7SSteve Wise ep->plen = conn_param->private_data_len; 3156cfdda9d7SSteve Wise if (ep->plen) 3157cfdda9d7SSteve Wise memcpy(ep->mpa_pkt + sizeof(struct mpa_message), 3158cfdda9d7SSteve Wise conn_param->private_data, ep->plen); 3159cfdda9d7SSteve Wise ep->ird = conn_param->ird; 3160cfdda9d7SSteve Wise ep->ord = conn_param->ord; 3161cfdda9d7SSteve Wise 3162cfdda9d7SSteve Wise if (peer2peer && ep->ord == 0) 3163cfdda9d7SSteve Wise ep->ord = 1; 3164cfdda9d7SSteve Wise 3165cfdda9d7SSteve Wise ep->com.cm_id = cm_id; 31669ca6f7cfSHariprasad S ref_cm_id(&ep->com); 31679ca6f7cfSHariprasad S ep->com.dev = dev; 3168cfdda9d7SSteve Wise ep->com.qp = get_qhp(dev, conn_param->qpn); 3169830662f6SVipul Pandya if (!ep->com.qp) { 3170830662f6SVipul Pandya PDBG("%s qpn 0x%x not found!\n", __func__, conn_param->qpn); 3171830662f6SVipul Pandya err = -EINVAL; 31729eccfe10SSteve Wise goto fail1; 3173830662f6SVipul Pandya } 3174325abeadSVipul Pandya ref_qp(ep); 3175cfdda9d7SSteve Wise PDBG("%s qpn 0x%x qp %p cm_id %p\n", __func__, conn_param->qpn, 3176cfdda9d7SSteve Wise ep->com.qp, cm_id); 3177cfdda9d7SSteve Wise 3178cfdda9d7SSteve Wise /* 3179cfdda9d7SSteve Wise * Allocate an active TID to initiate a TCP connection. 3180cfdda9d7SSteve Wise */ 3181cfdda9d7SSteve Wise ep->atid = cxgb4_alloc_atid(dev->rdev.lldi.tids, ep); 3182cfdda9d7SSteve Wise if (ep->atid == -1) { 3183cfdda9d7SSteve Wise printk(KERN_ERR MOD "%s - cannot alloc atid.\n", __func__); 3184cfdda9d7SSteve Wise err = -ENOMEM; 31859eccfe10SSteve Wise goto fail1; 3186cfdda9d7SSteve Wise } 3187793dad94SVipul Pandya insert_handle(dev, &dev->atid_idr, ep, ep->atid); 3188cfdda9d7SSteve Wise 3189170003c8SSteve Wise memcpy(&ep->com.local_addr, &cm_id->m_local_addr, 31909eccfe10SSteve Wise sizeof(ep->com.local_addr)); 3191170003c8SSteve Wise memcpy(&ep->com.remote_addr, &cm_id->m_remote_addr, 31929eccfe10SSteve Wise sizeof(ep->com.remote_addr)); 31939eccfe10SSteve Wise 3194170003c8SSteve Wise laddr = (struct sockaddr_in *)&ep->com.local_addr; 3195170003c8SSteve Wise raddr = (struct sockaddr_in *)&ep->com.remote_addr; 3196170003c8SSteve Wise laddr6 = (struct sockaddr_in6 *)&ep->com.local_addr; 3197170003c8SSteve Wise raddr6 = (struct sockaddr_in6 *) &ep->com.remote_addr; 31989eccfe10SSteve Wise 3199170003c8SSteve Wise if (cm_id->m_remote_addr.ss_family == AF_INET) { 3200830662f6SVipul Pandya iptype = 4; 3201830662f6SVipul Pandya ra = (__u8 *)&raddr->sin_addr; 3202830662f6SVipul Pandya 3203830662f6SVipul Pandya /* 3204830662f6SVipul Pandya * Handle loopback requests to INADDR_ANY. 3205830662f6SVipul Pandya */ 3206830662f6SVipul Pandya if ((__force int)raddr->sin_addr.s_addr == INADDR_ANY) { 3207830662f6SVipul Pandya err = pick_local_ipaddrs(dev, cm_id); 3208830662f6SVipul Pandya if (err) 32099eccfe10SSteve Wise goto fail1; 3210830662f6SVipul Pandya } 3211cfdda9d7SSteve Wise 3212cfdda9d7SSteve Wise /* find a route */ 3213830662f6SVipul Pandya PDBG("%s saddr %pI4 sport 0x%x raddr %pI4 rport 0x%x\n", 3214830662f6SVipul Pandya __func__, &laddr->sin_addr, ntohs(laddr->sin_port), 3215830662f6SVipul Pandya ra, ntohs(raddr->sin_port)); 3216830662f6SVipul Pandya ep->dst = find_route(dev, laddr->sin_addr.s_addr, 3217830662f6SVipul Pandya raddr->sin_addr.s_addr, laddr->sin_port, 3218ac8e4c69SHariprasad S raddr->sin_port, cm_id->tos); 3219830662f6SVipul Pandya } else { 3220830662f6SVipul Pandya iptype = 6; 3221830662f6SVipul Pandya ra = (__u8 *)&raddr6->sin6_addr; 3222830662f6SVipul Pandya 3223830662f6SVipul Pandya /* 3224830662f6SVipul Pandya * Handle loopback requests to INADDR_ANY. 3225830662f6SVipul Pandya */ 3226830662f6SVipul Pandya if (ipv6_addr_type(&raddr6->sin6_addr) == IPV6_ADDR_ANY) { 3227830662f6SVipul Pandya err = pick_local_ip6addrs(dev, cm_id); 3228830662f6SVipul Pandya if (err) 32299eccfe10SSteve Wise goto fail1; 3230830662f6SVipul Pandya } 3231830662f6SVipul Pandya 3232830662f6SVipul Pandya /* find a route */ 3233830662f6SVipul Pandya PDBG("%s saddr %pI6 sport 0x%x raddr %pI6 rport 0x%x\n", 3234830662f6SVipul Pandya __func__, laddr6->sin6_addr.s6_addr, 3235830662f6SVipul Pandya ntohs(laddr6->sin6_port), 3236830662f6SVipul Pandya raddr6->sin6_addr.s6_addr, ntohs(raddr6->sin6_port)); 3237830662f6SVipul Pandya ep->dst = find_route6(dev, laddr6->sin6_addr.s6_addr, 3238830662f6SVipul Pandya raddr6->sin6_addr.s6_addr, 3239830662f6SVipul Pandya laddr6->sin6_port, raddr6->sin6_port, 0, 3240830662f6SVipul Pandya raddr6->sin6_scope_id); 3241830662f6SVipul Pandya } 3242830662f6SVipul Pandya if (!ep->dst) { 3243cfdda9d7SSteve Wise printk(KERN_ERR MOD "%s - cannot find route.\n", __func__); 3244cfdda9d7SSteve Wise err = -EHOSTUNREACH; 32459eccfe10SSteve Wise goto fail2; 3246cfdda9d7SSteve Wise } 3247cfdda9d7SSteve Wise 3248963cab50SHariprasad S err = import_ep(ep, iptype, ra, ep->dst, ep->com.dev, true, 3249ac8e4c69SHariprasad S ep->com.dev->rdev.lldi.adapter_type, cm_id->tos); 32503786cf18SDavid Miller if (err) { 3251cfdda9d7SSteve Wise printk(KERN_ERR MOD "%s - cannot alloc l2e.\n", __func__); 32529eccfe10SSteve Wise goto fail3; 3253cfdda9d7SSteve Wise } 3254cfdda9d7SSteve Wise 3255cfdda9d7SSteve Wise PDBG("%s txq_idx %u tx_chan %u smac_idx %u rss_qid %u l2t_idx %u\n", 3256cfdda9d7SSteve Wise __func__, ep->txq_idx, ep->tx_chan, ep->smac_idx, ep->rss_qid, 3257cfdda9d7SSteve Wise ep->l2t->idx); 3258cfdda9d7SSteve Wise 3259cfdda9d7SSteve Wise state_set(&ep->com, CONNECTING); 3260ac8e4c69SHariprasad S ep->tos = cm_id->tos; 3261cfdda9d7SSteve Wise 3262cfdda9d7SSteve Wise /* send connect request to rnic */ 3263cfdda9d7SSteve Wise err = send_connect(ep); 3264cfdda9d7SSteve Wise if (!err) 3265cfdda9d7SSteve Wise goto out; 3266cfdda9d7SSteve Wise 3267cfdda9d7SSteve Wise cxgb4_l2t_release(ep->l2t); 3268cfdda9d7SSteve Wise fail3: 32699eccfe10SSteve Wise dst_release(ep->dst); 32709eccfe10SSteve Wise fail2: 3271793dad94SVipul Pandya remove_handle(ep->com.dev, &ep->com.dev->atid_idr, ep->atid); 3272cfdda9d7SSteve Wise cxgb4_free_atid(ep->com.dev->rdev.lldi.tids, ep->atid); 32739eccfe10SSteve Wise fail1: 32749ca6f7cfSHariprasad S deref_cm_id(&ep->com); 3275cfdda9d7SSteve Wise c4iw_put_ep(&ep->com); 3276cfdda9d7SSteve Wise out: 3277cfdda9d7SSteve Wise return err; 3278cfdda9d7SSteve Wise } 3279cfdda9d7SSteve Wise 3280830662f6SVipul Pandya static int create_server6(struct c4iw_dev *dev, struct c4iw_listen_ep *ep) 3281830662f6SVipul Pandya { 3282830662f6SVipul Pandya int err; 32839eccfe10SSteve Wise struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *) 3284170003c8SSteve Wise &ep->com.local_addr; 3285830662f6SVipul Pandya 328628de1f74SHariprasad S if (ipv6_addr_type(&sin6->sin6_addr) != IPV6_ADDR_ANY) { 328728de1f74SHariprasad S err = cxgb4_clip_get(ep->com.dev->rdev.lldi.ports[0], 328828de1f74SHariprasad S (const u32 *)&sin6->sin6_addr.s6_addr, 1); 328928de1f74SHariprasad S if (err) 329028de1f74SHariprasad S return err; 329128de1f74SHariprasad S } 3292830662f6SVipul Pandya c4iw_init_wr_wait(&ep->com.wr_wait); 3293830662f6SVipul Pandya err = cxgb4_create_server6(ep->com.dev->rdev.lldi.ports[0], 3294830662f6SVipul Pandya ep->stid, &sin6->sin6_addr, 3295830662f6SVipul Pandya sin6->sin6_port, 3296830662f6SVipul Pandya ep->com.dev->rdev.lldi.rxq_ids[0]); 3297830662f6SVipul Pandya if (!err) 3298830662f6SVipul Pandya err = c4iw_wait_for_reply(&ep->com.dev->rdev, 3299830662f6SVipul Pandya &ep->com.wr_wait, 3300830662f6SVipul Pandya 0, 0, __func__); 3301e6b11163SHariprasad S else if (err > 0) 3302e6b11163SHariprasad S err = net_xmit_errno(err); 330328de1f74SHariprasad S if (err) { 330428de1f74SHariprasad S cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0], 330528de1f74SHariprasad S (const u32 *)&sin6->sin6_addr.s6_addr, 1); 3306830662f6SVipul Pandya pr_err("cxgb4_create_server6/filter failed err %d stid %d laddr %pI6 lport %d\n", 3307830662f6SVipul Pandya err, ep->stid, 3308830662f6SVipul Pandya sin6->sin6_addr.s6_addr, ntohs(sin6->sin6_port)); 330928de1f74SHariprasad S } 3310830662f6SVipul Pandya return err; 3311830662f6SVipul Pandya } 3312830662f6SVipul Pandya 3313830662f6SVipul Pandya static int create_server4(struct c4iw_dev *dev, struct c4iw_listen_ep *ep) 3314830662f6SVipul Pandya { 3315830662f6SVipul Pandya int err; 33169eccfe10SSteve Wise struct sockaddr_in *sin = (struct sockaddr_in *) 3317170003c8SSteve Wise &ep->com.local_addr; 3318830662f6SVipul Pandya 3319830662f6SVipul Pandya if (dev->rdev.lldi.enable_fw_ofld_conn) { 3320830662f6SVipul Pandya do { 3321830662f6SVipul Pandya err = cxgb4_create_server_filter( 3322830662f6SVipul Pandya ep->com.dev->rdev.lldi.ports[0], ep->stid, 3323830662f6SVipul Pandya sin->sin_addr.s_addr, sin->sin_port, 0, 3324830662f6SVipul Pandya ep->com.dev->rdev.lldi.rxq_ids[0], 0, 0); 3325830662f6SVipul Pandya if (err == -EBUSY) { 332699718e59SHariprasad S if (c4iw_fatal_error(&ep->com.dev->rdev)) { 332799718e59SHariprasad S err = -EIO; 332899718e59SHariprasad S break; 332999718e59SHariprasad S } 3330830662f6SVipul Pandya set_current_state(TASK_UNINTERRUPTIBLE); 3331830662f6SVipul Pandya schedule_timeout(usecs_to_jiffies(100)); 3332830662f6SVipul Pandya } 3333830662f6SVipul Pandya } while (err == -EBUSY); 3334830662f6SVipul Pandya } else { 3335830662f6SVipul Pandya c4iw_init_wr_wait(&ep->com.wr_wait); 3336830662f6SVipul Pandya err = cxgb4_create_server(ep->com.dev->rdev.lldi.ports[0], 3337830662f6SVipul Pandya ep->stid, sin->sin_addr.s_addr, sin->sin_port, 3338830662f6SVipul Pandya 0, ep->com.dev->rdev.lldi.rxq_ids[0]); 3339830662f6SVipul Pandya if (!err) 3340830662f6SVipul Pandya err = c4iw_wait_for_reply(&ep->com.dev->rdev, 3341830662f6SVipul Pandya &ep->com.wr_wait, 3342830662f6SVipul Pandya 0, 0, __func__); 3343e6b11163SHariprasad S else if (err > 0) 3344e6b11163SHariprasad S err = net_xmit_errno(err); 3345830662f6SVipul Pandya } 3346830662f6SVipul Pandya if (err) 3347830662f6SVipul Pandya pr_err("cxgb4_create_server/filter failed err %d stid %d laddr %pI4 lport %d\n" 3348830662f6SVipul Pandya , err, ep->stid, 3349830662f6SVipul Pandya &sin->sin_addr, ntohs(sin->sin_port)); 3350830662f6SVipul Pandya return err; 3351830662f6SVipul Pandya } 3352830662f6SVipul Pandya 3353cfdda9d7SSteve Wise int c4iw_create_listen(struct iw_cm_id *cm_id, int backlog) 3354cfdda9d7SSteve Wise { 3355cfdda9d7SSteve Wise int err = 0; 3356cfdda9d7SSteve Wise struct c4iw_dev *dev = to_c4iw_dev(cm_id->device); 3357cfdda9d7SSteve Wise struct c4iw_listen_ep *ep; 3358cfdda9d7SSteve Wise 3359cfdda9d7SSteve Wise might_sleep(); 3360cfdda9d7SSteve Wise 3361cfdda9d7SSteve Wise ep = alloc_ep(sizeof(*ep), GFP_KERNEL); 3362cfdda9d7SSteve Wise if (!ep) { 3363cfdda9d7SSteve Wise printk(KERN_ERR MOD "%s - cannot alloc ep.\n", __func__); 3364cfdda9d7SSteve Wise err = -ENOMEM; 3365cfdda9d7SSteve Wise goto fail1; 3366cfdda9d7SSteve Wise } 3367cfdda9d7SSteve Wise PDBG("%s ep %p\n", __func__, ep); 3368cfdda9d7SSteve Wise ep->com.cm_id = cm_id; 33699ca6f7cfSHariprasad S ref_cm_id(&ep->com); 3370cfdda9d7SSteve Wise ep->com.dev = dev; 3371cfdda9d7SSteve Wise ep->backlog = backlog; 3372170003c8SSteve Wise memcpy(&ep->com.local_addr, &cm_id->m_local_addr, 337324d44a39SSteve Wise sizeof(ep->com.local_addr)); 3374cfdda9d7SSteve Wise 3375cfdda9d7SSteve Wise /* 3376cfdda9d7SSteve Wise * Allocate a server TID. 3377cfdda9d7SSteve Wise */ 33788c044690SKumar Sanghvi if (dev->rdev.lldi.enable_fw_ofld_conn && 33798c044690SKumar Sanghvi ep->com.local_addr.ss_family == AF_INET) 3380830662f6SVipul Pandya ep->stid = cxgb4_alloc_sftid(dev->rdev.lldi.tids, 3381170003c8SSteve Wise cm_id->m_local_addr.ss_family, ep); 33821cab775cSVipul Pandya else 3383830662f6SVipul Pandya ep->stid = cxgb4_alloc_stid(dev->rdev.lldi.tids, 3384170003c8SSteve Wise cm_id->m_local_addr.ss_family, ep); 33851cab775cSVipul Pandya 3386cfdda9d7SSteve Wise if (ep->stid == -1) { 3387be4c9badSRoland Dreier printk(KERN_ERR MOD "%s - cannot alloc stid.\n", __func__); 3388cfdda9d7SSteve Wise err = -ENOMEM; 3389cfdda9d7SSteve Wise goto fail2; 3390cfdda9d7SSteve Wise } 3391793dad94SVipul Pandya insert_handle(dev, &dev->stid_idr, ep, ep->stid); 33929eccfe10SSteve Wise 3393170003c8SSteve Wise memcpy(&ep->com.local_addr, &cm_id->m_local_addr, 33949eccfe10SSteve Wise sizeof(ep->com.local_addr)); 33959eccfe10SSteve Wise 3396cfdda9d7SSteve Wise state_set(&ep->com, LISTEN); 3397830662f6SVipul Pandya if (ep->com.local_addr.ss_family == AF_INET) 3398830662f6SVipul Pandya err = create_server4(dev, ep); 3399830662f6SVipul Pandya else 3400830662f6SVipul Pandya err = create_server6(dev, ep); 3401cfdda9d7SSteve Wise if (!err) { 3402cfdda9d7SSteve Wise cm_id->provider_data = ep; 3403cfdda9d7SSteve Wise goto out; 3404cfdda9d7SSteve Wise } 34059eccfe10SSteve Wise 3406830662f6SVipul Pandya cxgb4_free_stid(ep->com.dev->rdev.lldi.tids, ep->stid, 3407830662f6SVipul Pandya ep->com.local_addr.ss_family); 3408cfdda9d7SSteve Wise fail2: 34099ca6f7cfSHariprasad S deref_cm_id(&ep->com); 3410cfdda9d7SSteve Wise c4iw_put_ep(&ep->com); 3411cfdda9d7SSteve Wise fail1: 3412cfdda9d7SSteve Wise out: 3413cfdda9d7SSteve Wise return err; 3414cfdda9d7SSteve Wise } 3415cfdda9d7SSteve Wise 3416cfdda9d7SSteve Wise int c4iw_destroy_listen(struct iw_cm_id *cm_id) 3417cfdda9d7SSteve Wise { 3418cfdda9d7SSteve Wise int err; 3419cfdda9d7SSteve Wise struct c4iw_listen_ep *ep = to_listen_ep(cm_id); 3420cfdda9d7SSteve Wise 3421cfdda9d7SSteve Wise PDBG("%s ep %p\n", __func__, ep); 3422cfdda9d7SSteve Wise 3423cfdda9d7SSteve Wise might_sleep(); 3424cfdda9d7SSteve Wise state_set(&ep->com, DEAD); 3425830662f6SVipul Pandya if (ep->com.dev->rdev.lldi.enable_fw_ofld_conn && 3426830662f6SVipul Pandya ep->com.local_addr.ss_family == AF_INET) { 34271cab775cSVipul Pandya err = cxgb4_remove_server_filter( 34281cab775cSVipul Pandya ep->com.dev->rdev.lldi.ports[0], ep->stid, 34291cab775cSVipul Pandya ep->com.dev->rdev.lldi.rxq_ids[0], 0); 34301cab775cSVipul Pandya } else { 343184cc6ac6SHariprasad S struct sockaddr_in6 *sin6; 3432aadc4df3SSteve Wise c4iw_init_wr_wait(&ep->com.wr_wait); 3433830662f6SVipul Pandya err = cxgb4_remove_server( 3434830662f6SVipul Pandya ep->com.dev->rdev.lldi.ports[0], ep->stid, 3435830662f6SVipul Pandya ep->com.dev->rdev.lldi.rxq_ids[0], 0); 3436cfdda9d7SSteve Wise if (err) 3437cfdda9d7SSteve Wise goto done; 34381cab775cSVipul Pandya err = c4iw_wait_for_reply(&ep->com.dev->rdev, &ep->com.wr_wait, 34391cab775cSVipul Pandya 0, 0, __func__); 3440170003c8SSteve Wise sin6 = (struct sockaddr_in6 *)&ep->com.local_addr; 344184cc6ac6SHariprasad S cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0], 344284cc6ac6SHariprasad S (const u32 *)&sin6->sin6_addr.s6_addr, 1); 34431cab775cSVipul Pandya } 3444793dad94SVipul Pandya remove_handle(ep->com.dev, &ep->com.dev->stid_idr, ep->stid); 3445830662f6SVipul Pandya cxgb4_free_stid(ep->com.dev->rdev.lldi.tids, ep->stid, 3446830662f6SVipul Pandya ep->com.local_addr.ss_family); 3447cfdda9d7SSteve Wise done: 34489ca6f7cfSHariprasad S deref_cm_id(&ep->com); 3449cfdda9d7SSteve Wise c4iw_put_ep(&ep->com); 3450cfdda9d7SSteve Wise return err; 3451cfdda9d7SSteve Wise } 3452cfdda9d7SSteve Wise 3453cfdda9d7SSteve Wise int c4iw_ep_disconnect(struct c4iw_ep *ep, int abrupt, gfp_t gfp) 3454cfdda9d7SSteve Wise { 3455cfdda9d7SSteve Wise int ret = 0; 3456cfdda9d7SSteve Wise int close = 0; 3457cfdda9d7SSteve Wise int fatal = 0; 3458cfdda9d7SSteve Wise struct c4iw_rdev *rdev; 3459cfdda9d7SSteve Wise 34602f5b48c3SSteve Wise mutex_lock(&ep->com.mutex); 3461cfdda9d7SSteve Wise 3462cfdda9d7SSteve Wise PDBG("%s ep %p state %s, abrupt %d\n", __func__, ep, 3463cfdda9d7SSteve Wise states[ep->com.state], abrupt); 3464cfdda9d7SSteve Wise 34656e410d8fSHariprasad S /* 34666e410d8fSHariprasad S * Ref the ep here in case we have fatal errors causing the 34676e410d8fSHariprasad S * ep to be released and freed. 34686e410d8fSHariprasad S */ 34696e410d8fSHariprasad S c4iw_get_ep(&ep->com); 34706e410d8fSHariprasad S 3471cfdda9d7SSteve Wise rdev = &ep->com.dev->rdev; 3472cfdda9d7SSteve Wise if (c4iw_fatal_error(rdev)) { 3473cfdda9d7SSteve Wise fatal = 1; 3474be13b2dfSSteve Wise close_complete_upcall(ep, -EIO); 3475cfdda9d7SSteve Wise ep->com.state = DEAD; 3476cfdda9d7SSteve Wise } 3477cfdda9d7SSteve Wise switch (ep->com.state) { 3478cfdda9d7SSteve Wise case MPA_REQ_WAIT: 3479cfdda9d7SSteve Wise case MPA_REQ_SENT: 3480cfdda9d7SSteve Wise case MPA_REQ_RCVD: 3481cfdda9d7SSteve Wise case MPA_REP_SENT: 3482cfdda9d7SSteve Wise case FPDU_MODE: 3483cfdda9d7SSteve Wise close = 1; 3484cfdda9d7SSteve Wise if (abrupt) 3485cfdda9d7SSteve Wise ep->com.state = ABORTING; 3486cfdda9d7SSteve Wise else { 3487cfdda9d7SSteve Wise ep->com.state = CLOSING; 3488ca5a2202SSteve Wise start_ep_timer(ep); 3489cfdda9d7SSteve Wise } 3490cfdda9d7SSteve Wise set_bit(CLOSE_SENT, &ep->com.flags); 3491cfdda9d7SSteve Wise break; 3492cfdda9d7SSteve Wise case CLOSING: 3493cfdda9d7SSteve Wise if (!test_and_set_bit(CLOSE_SENT, &ep->com.flags)) { 3494cfdda9d7SSteve Wise close = 1; 3495cfdda9d7SSteve Wise if (abrupt) { 3496b33bd0cbSSteve Wise (void)stop_ep_timer(ep); 3497cfdda9d7SSteve Wise ep->com.state = ABORTING; 3498cfdda9d7SSteve Wise } else 3499cfdda9d7SSteve Wise ep->com.state = MORIBUND; 3500cfdda9d7SSteve Wise } 3501cfdda9d7SSteve Wise break; 3502cfdda9d7SSteve Wise case MORIBUND: 3503cfdda9d7SSteve Wise case ABORTING: 3504cfdda9d7SSteve Wise case DEAD: 3505cfdda9d7SSteve Wise PDBG("%s ignoring disconnect ep %p state %u\n", 3506cfdda9d7SSteve Wise __func__, ep, ep->com.state); 3507cfdda9d7SSteve Wise break; 3508cfdda9d7SSteve Wise default: 3509cfdda9d7SSteve Wise BUG(); 3510cfdda9d7SSteve Wise break; 3511cfdda9d7SSteve Wise } 3512cfdda9d7SSteve Wise 3513cfdda9d7SSteve Wise if (close) { 35148da7e7a5SSteve Wise if (abrupt) { 3515793dad94SVipul Pandya set_bit(EP_DISC_ABORT, &ep->com.history); 3516be13b2dfSSteve Wise close_complete_upcall(ep, -ECONNRESET); 35178da7e7a5SSteve Wise ret = send_abort(ep, NULL, gfp); 3518793dad94SVipul Pandya } else { 3519793dad94SVipul Pandya set_bit(EP_DISC_CLOSE, &ep->com.history); 3520cfdda9d7SSteve Wise ret = send_halfclose(ep, gfp); 3521793dad94SVipul Pandya } 352288bc230dSHariprasad S if (ret) { 35239ca6f7cfSHariprasad S set_bit(EP_DISC_FAIL, &ep->com.history); 352488bc230dSHariprasad S if (!abrupt) { 352588bc230dSHariprasad S stop_ep_timer(ep); 352688bc230dSHariprasad S close_complete_upcall(ep, -EIO); 352788bc230dSHariprasad S } 3528c00dcbafSHariprasad S if (ep->com.qp) { 3529c00dcbafSHariprasad S struct c4iw_qp_attributes attrs; 3530c00dcbafSHariprasad S 3531c00dcbafSHariprasad S attrs.next_state = C4IW_QP_STATE_ERROR; 3532c00dcbafSHariprasad S ret = c4iw_modify_qp(ep->com.qp->rhp, 3533c00dcbafSHariprasad S ep->com.qp, 3534c00dcbafSHariprasad S C4IW_QP_ATTR_NEXT_STATE, 3535c00dcbafSHariprasad S &attrs, 1); 3536c00dcbafSHariprasad S if (ret) 3537c00dcbafSHariprasad S pr_err(MOD 3538c00dcbafSHariprasad S "%s - qp <- error failed!\n", 3539c00dcbafSHariprasad S __func__); 3540c00dcbafSHariprasad S } 3541cfdda9d7SSteve Wise fatal = 1; 3542cfdda9d7SSteve Wise } 354388bc230dSHariprasad S } 35448da7e7a5SSteve Wise mutex_unlock(&ep->com.mutex); 35456e410d8fSHariprasad S c4iw_put_ep(&ep->com); 3546cfdda9d7SSteve Wise if (fatal) 3547cfdda9d7SSteve Wise release_ep_resources(ep); 3548cfdda9d7SSteve Wise return ret; 3549cfdda9d7SSteve Wise } 3550cfdda9d7SSteve Wise 35511cab775cSVipul Pandya static void active_ofld_conn_reply(struct c4iw_dev *dev, struct sk_buff *skb, 35521cab775cSVipul Pandya struct cpl_fw6_msg_ofld_connection_wr_rpl *req) 35531cab775cSVipul Pandya { 35541cab775cSVipul Pandya struct c4iw_ep *ep; 3555793dad94SVipul Pandya int atid = be32_to_cpu(req->tid); 35561cab775cSVipul Pandya 3557ef5d6355SVipul Pandya ep = (struct c4iw_ep *)lookup_atid(dev->rdev.lldi.tids, 3558ef5d6355SVipul Pandya (__force u32) req->tid); 35591cab775cSVipul Pandya if (!ep) 35601cab775cSVipul Pandya return; 35611cab775cSVipul Pandya 35621cab775cSVipul Pandya switch (req->retval) { 35631cab775cSVipul Pandya case FW_ENOMEM: 3564793dad94SVipul Pandya set_bit(ACT_RETRY_NOMEM, &ep->com.history); 3565793dad94SVipul Pandya if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) { 3566793dad94SVipul Pandya send_fw_act_open_req(ep, atid); 3567793dad94SVipul Pandya return; 3568793dad94SVipul Pandya } 35691cab775cSVipul Pandya case FW_EADDRINUSE: 3570793dad94SVipul Pandya set_bit(ACT_RETRY_INUSE, &ep->com.history); 3571793dad94SVipul Pandya if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) { 3572793dad94SVipul Pandya send_fw_act_open_req(ep, atid); 3573793dad94SVipul Pandya return; 3574793dad94SVipul Pandya } 35751cab775cSVipul Pandya break; 35761cab775cSVipul Pandya default: 35771cab775cSVipul Pandya pr_info("%s unexpected ofld conn wr retval %d\n", 35781cab775cSVipul Pandya __func__, req->retval); 35791cab775cSVipul Pandya break; 35801cab775cSVipul Pandya } 3581793dad94SVipul Pandya pr_err("active ofld_connect_wr failure %d atid %d\n", 3582793dad94SVipul Pandya req->retval, atid); 3583793dad94SVipul Pandya mutex_lock(&dev->rdev.stats.lock); 3584793dad94SVipul Pandya dev->rdev.stats.act_ofld_conn_fails++; 3585793dad94SVipul Pandya mutex_unlock(&dev->rdev.stats.lock); 35861cab775cSVipul Pandya connect_reply_upcall(ep, status2errno(req->retval)); 3587793dad94SVipul Pandya state_set(&ep->com, DEAD); 358884cc6ac6SHariprasad S if (ep->com.remote_addr.ss_family == AF_INET6) { 358984cc6ac6SHariprasad S struct sockaddr_in6 *sin6 = 3590170003c8SSteve Wise (struct sockaddr_in6 *)&ep->com.local_addr; 359184cc6ac6SHariprasad S cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0], 359284cc6ac6SHariprasad S (const u32 *)&sin6->sin6_addr.s6_addr, 1); 359384cc6ac6SHariprasad S } 3594793dad94SVipul Pandya remove_handle(dev, &dev->atid_idr, atid); 3595793dad94SVipul Pandya cxgb4_free_atid(dev->rdev.lldi.tids, atid); 3596793dad94SVipul Pandya dst_release(ep->dst); 3597793dad94SVipul Pandya cxgb4_l2t_release(ep->l2t); 3598793dad94SVipul Pandya c4iw_put_ep(&ep->com); 35991cab775cSVipul Pandya } 36001cab775cSVipul Pandya 36011cab775cSVipul Pandya static void passive_ofld_conn_reply(struct c4iw_dev *dev, struct sk_buff *skb, 36021cab775cSVipul Pandya struct cpl_fw6_msg_ofld_connection_wr_rpl *req) 36031cab775cSVipul Pandya { 36041cab775cSVipul Pandya struct sk_buff *rpl_skb; 36051cab775cSVipul Pandya struct cpl_pass_accept_req *cpl; 36061cab775cSVipul Pandya int ret; 36071cab775cSVipul Pandya 3608710a3110SPaul Bolle rpl_skb = (struct sk_buff *)(unsigned long)req->cookie; 36091cab775cSVipul Pandya BUG_ON(!rpl_skb); 36101cab775cSVipul Pandya if (req->retval) { 36111cab775cSVipul Pandya PDBG("%s passive open failure %d\n", __func__, req->retval); 3612793dad94SVipul Pandya mutex_lock(&dev->rdev.stats.lock); 3613793dad94SVipul Pandya dev->rdev.stats.pas_ofld_conn_fails++; 3614793dad94SVipul Pandya mutex_unlock(&dev->rdev.stats.lock); 36151cab775cSVipul Pandya kfree_skb(rpl_skb); 36161cab775cSVipul Pandya } else { 36171cab775cSVipul Pandya cpl = (struct cpl_pass_accept_req *)cplhdr(rpl_skb); 36181cab775cSVipul Pandya OPCODE_TID(cpl) = htonl(MK_OPCODE_TID(CPL_PASS_ACCEPT_REQ, 3619ef5d6355SVipul Pandya (__force u32) htonl( 3620ef5d6355SVipul Pandya (__force u32) req->tid))); 36211cab775cSVipul Pandya ret = pass_accept_req(dev, rpl_skb); 36221cab775cSVipul Pandya if (!ret) 36231cab775cSVipul Pandya kfree_skb(rpl_skb); 36241cab775cSVipul Pandya } 36251cab775cSVipul Pandya return; 36261cab775cSVipul Pandya } 36271cab775cSVipul Pandya 36281cab775cSVipul Pandya static int deferred_fw6_msg(struct c4iw_dev *dev, struct sk_buff *skb) 36292f5b48c3SSteve Wise { 36302f5b48c3SSteve Wise struct cpl_fw6_msg *rpl = cplhdr(skb); 36311cab775cSVipul Pandya struct cpl_fw6_msg_ofld_connection_wr_rpl *req; 36321cab775cSVipul Pandya 36331cab775cSVipul Pandya switch (rpl->type) { 36341cab775cSVipul Pandya case FW6_TYPE_CQE: 36352f5b48c3SSteve Wise c4iw_ev_dispatch(dev, (struct t4_cqe *)&rpl->data[0]); 36361cab775cSVipul Pandya break; 36371cab775cSVipul Pandya case FW6_TYPE_OFLD_CONNECTION_WR_RPL: 36381cab775cSVipul Pandya req = (struct cpl_fw6_msg_ofld_connection_wr_rpl *)rpl->data; 36391cab775cSVipul Pandya switch (req->t_state) { 36401cab775cSVipul Pandya case TCP_SYN_SENT: 36411cab775cSVipul Pandya active_ofld_conn_reply(dev, skb, req); 36421cab775cSVipul Pandya break; 36431cab775cSVipul Pandya case TCP_SYN_RECV: 36441cab775cSVipul Pandya passive_ofld_conn_reply(dev, skb, req); 36451cab775cSVipul Pandya break; 36461cab775cSVipul Pandya default: 36471cab775cSVipul Pandya pr_err("%s unexpected ofld conn wr state %d\n", 36481cab775cSVipul Pandya __func__, req->t_state); 36491cab775cSVipul Pandya break; 36501cab775cSVipul Pandya } 36511cab775cSVipul Pandya break; 36521cab775cSVipul Pandya } 36531cab775cSVipul Pandya return 0; 36541cab775cSVipul Pandya } 36551cab775cSVipul Pandya 36561cab775cSVipul Pandya static void build_cpl_pass_accept_req(struct sk_buff *skb, int stid , u8 tos) 36571cab775cSVipul Pandya { 3658963cab50SHariprasad S __be32 l2info; 3659963cab50SHariprasad S __be16 hdr_len, vlantag, len; 3660963cab50SHariprasad S u16 eth_hdr_len; 3661963cab50SHariprasad S int tcp_hdr_len, ip_hdr_len; 36621cab775cSVipul Pandya u8 intf; 36631cab775cSVipul Pandya struct cpl_rx_pkt *cpl = cplhdr(skb); 36641cab775cSVipul Pandya struct cpl_pass_accept_req *req; 36651cab775cSVipul Pandya struct tcp_options_received tmp_opt; 3666f079af7aSVipul Pandya struct c4iw_dev *dev; 3667963cab50SHariprasad S enum chip_type type; 36681cab775cSVipul Pandya 3669f079af7aSVipul Pandya dev = *((struct c4iw_dev **) (skb->cb + sizeof(void *))); 36701cab775cSVipul Pandya /* Store values from cpl_rx_pkt in temporary location. */ 3671963cab50SHariprasad S vlantag = cpl->vlan; 3672963cab50SHariprasad S len = cpl->len; 3673963cab50SHariprasad S l2info = cpl->l2info; 3674963cab50SHariprasad S hdr_len = cpl->hdr_len; 36751cab775cSVipul Pandya intf = cpl->iff; 36761cab775cSVipul Pandya 36771cab775cSVipul Pandya __skb_pull(skb, sizeof(*req) + sizeof(struct rss_header)); 36781cab775cSVipul Pandya 36791cab775cSVipul Pandya /* 36801cab775cSVipul Pandya * We need to parse the TCP options from SYN packet. 36811cab775cSVipul Pandya * to generate cpl_pass_accept_req. 36821cab775cSVipul Pandya */ 36831cab775cSVipul Pandya memset(&tmp_opt, 0, sizeof(tmp_opt)); 36841cab775cSVipul Pandya tcp_clear_options(&tmp_opt); 36851a2c6181SChristoph Paasch tcp_parse_options(skb, &tmp_opt, 0, NULL); 36861cab775cSVipul Pandya 36871cab775cSVipul Pandya req = (struct cpl_pass_accept_req *)__skb_push(skb, sizeof(*req)); 36881cab775cSVipul Pandya memset(req, 0, sizeof(*req)); 3689cf7fe64aSHariprasad Shenai req->l2info = cpu_to_be16(SYN_INTF_V(intf) | 3690cf7fe64aSHariprasad Shenai SYN_MAC_IDX_V(RX_MACIDX_G( 3691963cab50SHariprasad S be32_to_cpu(l2info))) | 3692cf7fe64aSHariprasad Shenai SYN_XACT_MATCH_F); 3693963cab50SHariprasad S type = dev->rdev.lldi.adapter_type; 3694963cab50SHariprasad S tcp_hdr_len = RX_TCPHDR_LEN_G(be16_to_cpu(hdr_len)); 3695963cab50SHariprasad S ip_hdr_len = RX_IPHDR_LEN_G(be16_to_cpu(hdr_len)); 3696963cab50SHariprasad S req->hdr_len = 3697963cab50SHariprasad S cpu_to_be32(SYN_RX_CHAN_V(RX_CHAN_G(be32_to_cpu(l2info)))); 3698963cab50SHariprasad S if (CHELSIO_CHIP_VERSION(type) <= CHELSIO_T5) { 3699963cab50SHariprasad S eth_hdr_len = is_t4(type) ? 3700963cab50SHariprasad S RX_ETHHDR_LEN_G(be32_to_cpu(l2info)) : 3701963cab50SHariprasad S RX_T5_ETHHDR_LEN_G(be32_to_cpu(l2info)); 3702963cab50SHariprasad S req->hdr_len |= cpu_to_be32(TCP_HDR_LEN_V(tcp_hdr_len) | 3703963cab50SHariprasad S IP_HDR_LEN_V(ip_hdr_len) | 3704963cab50SHariprasad S ETH_HDR_LEN_V(eth_hdr_len)); 3705963cab50SHariprasad S } else { /* T6 and later */ 3706963cab50SHariprasad S eth_hdr_len = RX_T6_ETHHDR_LEN_G(be32_to_cpu(l2info)); 3707963cab50SHariprasad S req->hdr_len |= cpu_to_be32(T6_TCP_HDR_LEN_V(tcp_hdr_len) | 3708963cab50SHariprasad S T6_IP_HDR_LEN_V(ip_hdr_len) | 3709963cab50SHariprasad S T6_ETH_HDR_LEN_V(eth_hdr_len)); 3710963cab50SHariprasad S } 3711963cab50SHariprasad S req->vlan = vlantag; 3712963cab50SHariprasad S req->len = len; 37136c53e938SHariprasad Shenai req->tos_stid = cpu_to_be32(PASS_OPEN_TID_V(stid) | 37146c53e938SHariprasad Shenai PASS_OPEN_TOS_V(tos)); 37151cab775cSVipul Pandya req->tcpopt.mss = htons(tmp_opt.mss_clamp); 37161cab775cSVipul Pandya if (tmp_opt.wscale_ok) 37171cab775cSVipul Pandya req->tcpopt.wsf = tmp_opt.snd_wscale; 37181cab775cSVipul Pandya req->tcpopt.tstamp = tmp_opt.saw_tstamp; 37191cab775cSVipul Pandya if (tmp_opt.sack_ok) 37201cab775cSVipul Pandya req->tcpopt.sack = 1; 37211cab775cSVipul Pandya OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_PASS_ACCEPT_REQ, 0)); 37221cab775cSVipul Pandya return; 37231cab775cSVipul Pandya } 37241cab775cSVipul Pandya 37251cab775cSVipul Pandya static void send_fw_pass_open_req(struct c4iw_dev *dev, struct sk_buff *skb, 37261cab775cSVipul Pandya __be32 laddr, __be16 lport, 37271cab775cSVipul Pandya __be32 raddr, __be16 rport, 37281cab775cSVipul Pandya u32 rcv_isn, u32 filter, u16 window, 37291cab775cSVipul Pandya u32 rss_qid, u8 port_id) 37301cab775cSVipul Pandya { 37311cab775cSVipul Pandya struct sk_buff *req_skb; 37321cab775cSVipul Pandya struct fw_ofld_connection_wr *req; 37331cab775cSVipul Pandya struct cpl_pass_accept_req *cpl = cplhdr(skb); 37341ce1d471SSteve Wise int ret; 37351cab775cSVipul Pandya 37361cab775cSVipul Pandya req_skb = alloc_skb(sizeof(struct fw_ofld_connection_wr), GFP_KERNEL); 37371cab775cSVipul Pandya req = (struct fw_ofld_connection_wr *)__skb_put(req_skb, sizeof(*req)); 37381cab775cSVipul Pandya memset(req, 0, sizeof(*req)); 37396c53e938SHariprasad Shenai req->op_compl = htonl(WR_OP_V(FW_OFLD_CONNECTION_WR) | FW_WR_COMPL_F); 3740e2ac9628SHariprasad Shenai req->len16_pkd = htonl(FW_WR_LEN16_V(DIV_ROUND_UP(sizeof(*req), 16))); 374177a80e23SHariprasad Shenai req->le.version_cpl = htonl(FW_OFLD_CONNECTION_WR_CPL_F); 3742ef5d6355SVipul Pandya req->le.filter = (__force __be32) filter; 37431cab775cSVipul Pandya req->le.lport = lport; 37441cab775cSVipul Pandya req->le.pport = rport; 37451cab775cSVipul Pandya req->le.u.ipv4.lip = laddr; 37461cab775cSVipul Pandya req->le.u.ipv4.pip = raddr; 37471cab775cSVipul Pandya req->tcb.rcv_nxt = htonl(rcv_isn + 1); 37481cab775cSVipul Pandya req->tcb.rcv_adv = htons(window); 37491cab775cSVipul Pandya req->tcb.t_state_to_astid = 375077a80e23SHariprasad Shenai htonl(FW_OFLD_CONNECTION_WR_T_STATE_V(TCP_SYN_RECV) | 375177a80e23SHariprasad Shenai FW_OFLD_CONNECTION_WR_RCV_SCALE_V(cpl->tcpopt.wsf) | 375277a80e23SHariprasad Shenai FW_OFLD_CONNECTION_WR_ASTID_V( 37536c53e938SHariprasad Shenai PASS_OPEN_TID_G(ntohl(cpl->tos_stid)))); 37541cab775cSVipul Pandya 37551cab775cSVipul Pandya /* 37561cab775cSVipul Pandya * We store the qid in opt2 which will be used by the firmware 37571cab775cSVipul Pandya * to send us the wr response. 37581cab775cSVipul Pandya */ 3759d7990b0cSAnish Bhatt req->tcb.opt2 = htonl(RSS_QUEUE_V(rss_qid)); 37601cab775cSVipul Pandya 37611cab775cSVipul Pandya /* 37621cab775cSVipul Pandya * We initialize the MSS index in TCB to 0xF. 37631cab775cSVipul Pandya * So that when driver sends cpl_pass_accept_rpl 37641cab775cSVipul Pandya * TCB picks up the correct value. If this was 0 37651cab775cSVipul Pandya * TP will ignore any value > 0 for MSS index. 37661cab775cSVipul Pandya */ 3767d7990b0cSAnish Bhatt req->tcb.opt0 = cpu_to_be64(MSS_IDX_V(0xF)); 37686198dd8dSHariprasad S req->cookie = (uintptr_t)skb; 37691cab775cSVipul Pandya 37701cab775cSVipul Pandya set_wr_txq(req_skb, CPL_PRIORITY_CONTROL, port_id); 37711ce1d471SSteve Wise ret = cxgb4_ofld_send(dev->rdev.lldi.ports[0], req_skb); 37721ce1d471SSteve Wise if (ret < 0) { 37731ce1d471SSteve Wise pr_err("%s - cxgb4_ofld_send error %d - dropping\n", __func__, 37741ce1d471SSteve Wise ret); 37751ce1d471SSteve Wise kfree_skb(skb); 37761ce1d471SSteve Wise kfree_skb(req_skb); 37771ce1d471SSteve Wise } 37781cab775cSVipul Pandya } 37791cab775cSVipul Pandya 37801cab775cSVipul Pandya /* 37811cab775cSVipul Pandya * Handler for CPL_RX_PKT message. Need to handle cpl_rx_pkt 37821cab775cSVipul Pandya * messages when a filter is being used instead of server to 37831cab775cSVipul Pandya * redirect a syn packet. When packets hit filter they are redirected 37841cab775cSVipul Pandya * to the offload queue and driver tries to establish the connection 37851cab775cSVipul Pandya * using firmware work request. 37861cab775cSVipul Pandya */ 37871cab775cSVipul Pandya static int rx_pkt(struct c4iw_dev *dev, struct sk_buff *skb) 37881cab775cSVipul Pandya { 37891cab775cSVipul Pandya int stid; 37901cab775cSVipul Pandya unsigned int filter; 37911cab775cSVipul Pandya struct ethhdr *eh = NULL; 37921cab775cSVipul Pandya struct vlan_ethhdr *vlan_eh = NULL; 37931cab775cSVipul Pandya struct iphdr *iph; 37941cab775cSVipul Pandya struct tcphdr *tcph; 37951cab775cSVipul Pandya struct rss_header *rss = (void *)skb->data; 37961cab775cSVipul Pandya struct cpl_rx_pkt *cpl = (void *)skb->data; 37971cab775cSVipul Pandya struct cpl_pass_accept_req *req = (void *)(rss + 1); 37981cab775cSVipul Pandya struct l2t_entry *e; 37991cab775cSVipul Pandya struct dst_entry *dst; 38001cab775cSVipul Pandya struct c4iw_ep *lep; 38011cab775cSVipul Pandya u16 window; 38021cab775cSVipul Pandya struct port_info *pi; 38031cab775cSVipul Pandya struct net_device *pdev; 3804f079af7aSVipul Pandya u16 rss_qid, eth_hdr_len; 38051cab775cSVipul Pandya int step; 38061cab775cSVipul Pandya u32 tx_chan; 38071cab775cSVipul Pandya struct neighbour *neigh; 38081cab775cSVipul Pandya 38091cab775cSVipul Pandya /* Drop all non-SYN packets */ 3810bdc590b9SHariprasad Shenai if (!(cpl->l2info & cpu_to_be32(RXF_SYN_F))) 38111cab775cSVipul Pandya goto reject; 38121cab775cSVipul Pandya 38131cab775cSVipul Pandya /* 38141cab775cSVipul Pandya * Drop all packets which did not hit the filter. 38151cab775cSVipul Pandya * Unlikely to happen. 38161cab775cSVipul Pandya */ 38171cab775cSVipul Pandya if (!(rss->filter_hit && rss->filter_tid)) 38181cab775cSVipul Pandya goto reject; 38191cab775cSVipul Pandya 38201cab775cSVipul Pandya /* 38211cab775cSVipul Pandya * Calculate the server tid from filter hit index from cpl_rx_pkt. 38221cab775cSVipul Pandya */ 3823a4ea025fSKumar Sanghvi stid = (__force int) cpu_to_be32((__force u32) rss->hash_val); 38241cab775cSVipul Pandya 38251cab775cSVipul Pandya lep = (struct c4iw_ep *)lookup_stid(dev->rdev.lldi.tids, stid); 38261cab775cSVipul Pandya if (!lep) { 38271cab775cSVipul Pandya PDBG("%s connect request on invalid stid %d\n", __func__, stid); 38281cab775cSVipul Pandya goto reject; 38291cab775cSVipul Pandya } 38301cab775cSVipul Pandya 3831963cab50SHariprasad S switch (CHELSIO_CHIP_VERSION(dev->rdev.lldi.adapter_type)) { 3832963cab50SHariprasad S case CHELSIO_T4: 3833963cab50SHariprasad S eth_hdr_len = RX_ETHHDR_LEN_G(be32_to_cpu(cpl->l2info)); 3834963cab50SHariprasad S break; 3835963cab50SHariprasad S case CHELSIO_T5: 3836963cab50SHariprasad S eth_hdr_len = RX_T5_ETHHDR_LEN_G(be32_to_cpu(cpl->l2info)); 3837963cab50SHariprasad S break; 3838963cab50SHariprasad S case CHELSIO_T6: 3839963cab50SHariprasad S eth_hdr_len = RX_T6_ETHHDR_LEN_G(be32_to_cpu(cpl->l2info)); 3840963cab50SHariprasad S break; 3841963cab50SHariprasad S default: 3842963cab50SHariprasad S pr_err("T%d Chip is not supported\n", 3843963cab50SHariprasad S CHELSIO_CHIP_VERSION(dev->rdev.lldi.adapter_type)); 3844963cab50SHariprasad S goto reject; 3845963cab50SHariprasad S } 3846963cab50SHariprasad S 3847f079af7aSVipul Pandya if (eth_hdr_len == ETH_HLEN) { 38481cab775cSVipul Pandya eh = (struct ethhdr *)(req + 1); 38491cab775cSVipul Pandya iph = (struct iphdr *)(eh + 1); 38501cab775cSVipul Pandya } else { 38511cab775cSVipul Pandya vlan_eh = (struct vlan_ethhdr *)(req + 1); 38521cab775cSVipul Pandya iph = (struct iphdr *)(vlan_eh + 1); 38531cab775cSVipul Pandya skb->vlan_tci = ntohs(cpl->vlan); 38541cab775cSVipul Pandya } 38551cab775cSVipul Pandya 38561cab775cSVipul Pandya if (iph->version != 0x4) 38571cab775cSVipul Pandya goto reject; 38581cab775cSVipul Pandya 38591cab775cSVipul Pandya tcph = (struct tcphdr *)(iph + 1); 38601cab775cSVipul Pandya skb_set_network_header(skb, (void *)iph - (void *)rss); 38611cab775cSVipul Pandya skb_set_transport_header(skb, (void *)tcph - (void *)rss); 38621cab775cSVipul Pandya skb_get(skb); 38631cab775cSVipul Pandya 38641cab775cSVipul Pandya PDBG("%s lip 0x%x lport %u pip 0x%x pport %u tos %d\n", __func__, 38651cab775cSVipul Pandya ntohl(iph->daddr), ntohs(tcph->dest), ntohl(iph->saddr), 38661cab775cSVipul Pandya ntohs(tcph->source), iph->tos); 38671cab775cSVipul Pandya 3868830662f6SVipul Pandya dst = find_route(dev, iph->daddr, iph->saddr, tcph->dest, tcph->source, 38691cab775cSVipul Pandya iph->tos); 3870830662f6SVipul Pandya if (!dst) { 38711cab775cSVipul Pandya pr_err("%s - failed to find dst entry!\n", 38721cab775cSVipul Pandya __func__); 38731cab775cSVipul Pandya goto reject; 38741cab775cSVipul Pandya } 38751cab775cSVipul Pandya neigh = dst_neigh_lookup_skb(dst, skb); 38761cab775cSVipul Pandya 3877aaa0c23cSZhouyi Zhou if (!neigh) { 3878aaa0c23cSZhouyi Zhou pr_err("%s - failed to allocate neigh!\n", 3879aaa0c23cSZhouyi Zhou __func__); 3880aaa0c23cSZhouyi Zhou goto free_dst; 3881aaa0c23cSZhouyi Zhou } 3882aaa0c23cSZhouyi Zhou 38831cab775cSVipul Pandya if (neigh->dev->flags & IFF_LOOPBACK) { 38841cab775cSVipul Pandya pdev = ip_dev_find(&init_net, iph->daddr); 38851cab775cSVipul Pandya e = cxgb4_l2t_get(dev->rdev.lldi.l2t, neigh, 38861cab775cSVipul Pandya pdev, 0); 38871cab775cSVipul Pandya pi = (struct port_info *)netdev_priv(pdev); 38881cab775cSVipul Pandya tx_chan = cxgb4_port_chan(pdev); 38891cab775cSVipul Pandya dev_put(pdev); 38901cab775cSVipul Pandya } else { 3891830662f6SVipul Pandya pdev = get_real_dev(neigh->dev); 38921cab775cSVipul Pandya e = cxgb4_l2t_get(dev->rdev.lldi.l2t, neigh, 3893830662f6SVipul Pandya pdev, 0); 3894830662f6SVipul Pandya pi = (struct port_info *)netdev_priv(pdev); 3895830662f6SVipul Pandya tx_chan = cxgb4_port_chan(pdev); 38961cab775cSVipul Pandya } 3897ebf00060SSteve Wise neigh_release(neigh); 38981cab775cSVipul Pandya if (!e) { 38991cab775cSVipul Pandya pr_err("%s - failed to allocate l2t entry!\n", 39001cab775cSVipul Pandya __func__); 39011cab775cSVipul Pandya goto free_dst; 39021cab775cSVipul Pandya } 39031cab775cSVipul Pandya 39041cab775cSVipul Pandya step = dev->rdev.lldi.nrxq / dev->rdev.lldi.nchan; 39051cab775cSVipul Pandya rss_qid = dev->rdev.lldi.rxq_ids[pi->port_id * step]; 3906ef5d6355SVipul Pandya window = (__force u16) htons((__force u16)tcph->window); 39071cab775cSVipul Pandya 39081cab775cSVipul Pandya /* Calcuate filter portion for LE region. */ 390941b4f86cSKumar Sanghvi filter = (__force unsigned int) cpu_to_be32(cxgb4_select_ntuple( 391041b4f86cSKumar Sanghvi dev->rdev.lldi.ports[0], 391141b4f86cSKumar Sanghvi e)); 39121cab775cSVipul Pandya 39131cab775cSVipul Pandya /* 39141cab775cSVipul Pandya * Synthesize the cpl_pass_accept_req. We have everything except the 39151cab775cSVipul Pandya * TID. Once firmware sends a reply with TID we update the TID field 39161cab775cSVipul Pandya * in cpl and pass it through the regular cpl_pass_accept_req path. 39171cab775cSVipul Pandya */ 39181cab775cSVipul Pandya build_cpl_pass_accept_req(skb, stid, iph->tos); 39191cab775cSVipul Pandya send_fw_pass_open_req(dev, skb, iph->daddr, tcph->dest, iph->saddr, 39201cab775cSVipul Pandya tcph->source, ntohl(tcph->seq), filter, window, 39211cab775cSVipul Pandya rss_qid, pi->port_id); 39221cab775cSVipul Pandya cxgb4_l2t_release(e); 39231cab775cSVipul Pandya free_dst: 39241cab775cSVipul Pandya dst_release(dst); 39251cab775cSVipul Pandya reject: 39262f5b48c3SSteve Wise return 0; 39272f5b48c3SSteve Wise } 39282f5b48c3SSteve Wise 3929cfdda9d7SSteve Wise /* 3930be4c9badSRoland Dreier * These are the real handlers that are called from a 3931be4c9badSRoland Dreier * work queue. 3932be4c9badSRoland Dreier */ 39339dec900cSHariprasad S static c4iw_handler_func work_handlers[NUM_CPL_CMDS + NUM_FAKE_CPLS] = { 3934be4c9badSRoland Dreier [CPL_ACT_ESTABLISH] = act_establish, 3935be4c9badSRoland Dreier [CPL_ACT_OPEN_RPL] = act_open_rpl, 3936be4c9badSRoland Dreier [CPL_RX_DATA] = rx_data, 3937be4c9badSRoland Dreier [CPL_ABORT_RPL_RSS] = abort_rpl, 3938be4c9badSRoland Dreier [CPL_ABORT_RPL] = abort_rpl, 3939be4c9badSRoland Dreier [CPL_PASS_OPEN_RPL] = pass_open_rpl, 3940be4c9badSRoland Dreier [CPL_CLOSE_LISTSRV_RPL] = close_listsrv_rpl, 3941be4c9badSRoland Dreier [CPL_PASS_ACCEPT_REQ] = pass_accept_req, 3942be4c9badSRoland Dreier [CPL_PASS_ESTABLISH] = pass_establish, 3943be4c9badSRoland Dreier [CPL_PEER_CLOSE] = peer_close, 3944be4c9badSRoland Dreier [CPL_ABORT_REQ_RSS] = peer_abort, 3945be4c9badSRoland Dreier [CPL_CLOSE_CON_RPL] = close_con_rpl, 3946be4c9badSRoland Dreier [CPL_RDMA_TERMINATE] = terminate, 39472f5b48c3SSteve Wise [CPL_FW4_ACK] = fw4_ack, 39481cab775cSVipul Pandya [CPL_FW6_MSG] = deferred_fw6_msg, 39499dec900cSHariprasad S [CPL_RX_PKT] = rx_pkt, 39508d1f1a6bSHariprasad S [FAKE_CPL_PUT_EP_SAFE] = _put_ep_safe, 39518d1f1a6bSHariprasad S [FAKE_CPL_PASS_PUT_EP_SAFE] = _put_pass_ep_safe 3952be4c9badSRoland Dreier }; 3953be4c9badSRoland Dreier 3954be4c9badSRoland Dreier static void process_timeout(struct c4iw_ep *ep) 3955be4c9badSRoland Dreier { 3956be4c9badSRoland Dreier struct c4iw_qp_attributes attrs; 3957be4c9badSRoland Dreier int abort = 1; 3958be4c9badSRoland Dreier 39592f5b48c3SSteve Wise mutex_lock(&ep->com.mutex); 3960be4c9badSRoland Dreier PDBG("%s ep %p tid %u state %d\n", __func__, ep, ep->hwtid, 3961be4c9badSRoland Dreier ep->com.state); 3962793dad94SVipul Pandya set_bit(TIMEDOUT, &ep->com.history); 3963be4c9badSRoland Dreier switch (ep->com.state) { 3964be4c9badSRoland Dreier case MPA_REQ_SENT: 3965be4c9badSRoland Dreier __state_set(&ep->com, ABORTING); 3966be4c9badSRoland Dreier connect_reply_upcall(ep, -ETIMEDOUT); 3967be4c9badSRoland Dreier break; 3968be4c9badSRoland Dreier case MPA_REQ_WAIT: 3969e4b76a2aSHariprasad S case MPA_REP_SENT: 3970be4c9badSRoland Dreier __state_set(&ep->com, ABORTING); 3971be4c9badSRoland Dreier break; 3972be4c9badSRoland Dreier case CLOSING: 3973be4c9badSRoland Dreier case MORIBUND: 3974be4c9badSRoland Dreier if (ep->com.cm_id && ep->com.qp) { 3975be4c9badSRoland Dreier attrs.next_state = C4IW_QP_STATE_ERROR; 3976be4c9badSRoland Dreier c4iw_modify_qp(ep->com.qp->rhp, 3977be4c9badSRoland Dreier ep->com.qp, C4IW_QP_ATTR_NEXT_STATE, 3978be4c9badSRoland Dreier &attrs, 1); 3979be4c9badSRoland Dreier } 3980be4c9badSRoland Dreier __state_set(&ep->com, ABORTING); 3981be13b2dfSSteve Wise close_complete_upcall(ep, -ETIMEDOUT); 3982be4c9badSRoland Dreier break; 3983b33bd0cbSSteve Wise case ABORTING: 3984b33bd0cbSSteve Wise case DEAD: 3985b33bd0cbSSteve Wise 3986b33bd0cbSSteve Wise /* 3987b33bd0cbSSteve Wise * These states are expected if the ep timed out at the same 3988b33bd0cbSSteve Wise * time as another thread was calling stop_ep_timer(). 3989b33bd0cbSSteve Wise * So we silently do nothing for these states. 3990b33bd0cbSSteve Wise */ 3991b33bd0cbSSteve Wise abort = 0; 3992b33bd0cbSSteve Wise break; 3993be4c9badSRoland Dreier default: 399476f267b7SJulia Lawall WARN(1, "%s unexpected state ep %p tid %u state %u\n", 3995be4c9badSRoland Dreier __func__, ep, ep->hwtid, ep->com.state); 3996be4c9badSRoland Dreier abort = 0; 3997be4c9badSRoland Dreier } 3998cc18b939SSteve Wise mutex_unlock(&ep->com.mutex); 399969736279SHariprasad S if (abort) 400069736279SHariprasad S c4iw_ep_disconnect(ep, 1, GFP_KERNEL); 4001be4c9badSRoland Dreier c4iw_put_ep(&ep->com); 4002be4c9badSRoland Dreier } 4003be4c9badSRoland Dreier 4004be4c9badSRoland Dreier static void process_timedout_eps(void) 4005be4c9badSRoland Dreier { 4006be4c9badSRoland Dreier struct c4iw_ep *ep; 4007be4c9badSRoland Dreier 4008be4c9badSRoland Dreier spin_lock_irq(&timeout_lock); 4009be4c9badSRoland Dreier while (!list_empty(&timeout_list)) { 4010be4c9badSRoland Dreier struct list_head *tmp; 4011be4c9badSRoland Dreier 4012be4c9badSRoland Dreier tmp = timeout_list.next; 4013be4c9badSRoland Dreier list_del(tmp); 4014b33bd0cbSSteve Wise tmp->next = NULL; 4015b33bd0cbSSteve Wise tmp->prev = NULL; 4016be4c9badSRoland Dreier spin_unlock_irq(&timeout_lock); 4017be4c9badSRoland Dreier ep = list_entry(tmp, struct c4iw_ep, entry); 4018be4c9badSRoland Dreier process_timeout(ep); 4019be4c9badSRoland Dreier spin_lock_irq(&timeout_lock); 4020be4c9badSRoland Dreier } 4021be4c9badSRoland Dreier spin_unlock_irq(&timeout_lock); 4022be4c9badSRoland Dreier } 4023be4c9badSRoland Dreier 4024be4c9badSRoland Dreier static void process_work(struct work_struct *work) 4025be4c9badSRoland Dreier { 4026be4c9badSRoland Dreier struct sk_buff *skb = NULL; 4027be4c9badSRoland Dreier struct c4iw_dev *dev; 4028c1d7356cSDan Carpenter struct cpl_act_establish *rpl; 4029be4c9badSRoland Dreier unsigned int opcode; 4030be4c9badSRoland Dreier int ret; 4031be4c9badSRoland Dreier 4032b33bd0cbSSteve Wise process_timedout_eps(); 4033be4c9badSRoland Dreier while ((skb = skb_dequeue(&rxq))) { 4034be4c9badSRoland Dreier rpl = cplhdr(skb); 4035be4c9badSRoland Dreier dev = *((struct c4iw_dev **) (skb->cb + sizeof(void *))); 4036be4c9badSRoland Dreier opcode = rpl->ot.opcode; 4037be4c9badSRoland Dreier 4038be4c9badSRoland Dreier BUG_ON(!work_handlers[opcode]); 4039be4c9badSRoland Dreier ret = work_handlers[opcode](dev, skb); 4040be4c9badSRoland Dreier if (!ret) 4041be4c9badSRoland Dreier kfree_skb(skb); 4042be4c9badSRoland Dreier process_timedout_eps(); 4043be4c9badSRoland Dreier } 4044b33bd0cbSSteve Wise } 4045be4c9badSRoland Dreier 4046be4c9badSRoland Dreier static DECLARE_WORK(skb_work, process_work); 4047be4c9badSRoland Dreier 4048be4c9badSRoland Dreier static void ep_timeout(unsigned long arg) 4049be4c9badSRoland Dreier { 4050be4c9badSRoland Dreier struct c4iw_ep *ep = (struct c4iw_ep *)arg; 40511ec779ccSVipul Pandya int kickit = 0; 4052be4c9badSRoland Dreier 4053be4c9badSRoland Dreier spin_lock(&timeout_lock); 40541ec779ccSVipul Pandya if (!test_and_set_bit(TIMEOUT, &ep->com.flags)) { 4055b33bd0cbSSteve Wise /* 4056b33bd0cbSSteve Wise * Only insert if it is not already on the list. 4057b33bd0cbSSteve Wise */ 4058b33bd0cbSSteve Wise if (!ep->entry.next) { 4059be4c9badSRoland Dreier list_add_tail(&ep->entry, &timeout_list); 40601ec779ccSVipul Pandya kickit = 1; 40611ec779ccSVipul Pandya } 4062b33bd0cbSSteve Wise } 4063be4c9badSRoland Dreier spin_unlock(&timeout_lock); 40641ec779ccSVipul Pandya if (kickit) 4065be4c9badSRoland Dreier queue_work(workq, &skb_work); 4066be4c9badSRoland Dreier } 4067be4c9badSRoland Dreier 4068be4c9badSRoland Dreier /* 4069cfdda9d7SSteve Wise * All the CM events are handled on a work queue to have a safe context. 4070cfdda9d7SSteve Wise */ 4071cfdda9d7SSteve Wise static int sched(struct c4iw_dev *dev, struct sk_buff *skb) 4072cfdda9d7SSteve Wise { 4073cfdda9d7SSteve Wise 4074cfdda9d7SSteve Wise /* 4075cfdda9d7SSteve Wise * Save dev in the skb->cb area. 4076cfdda9d7SSteve Wise */ 4077cfdda9d7SSteve Wise *((struct c4iw_dev **) (skb->cb + sizeof(void *))) = dev; 4078cfdda9d7SSteve Wise 4079cfdda9d7SSteve Wise /* 4080cfdda9d7SSteve Wise * Queue the skb and schedule the worker thread. 4081cfdda9d7SSteve Wise */ 4082cfdda9d7SSteve Wise skb_queue_tail(&rxq, skb); 4083cfdda9d7SSteve Wise queue_work(workq, &skb_work); 4084cfdda9d7SSteve Wise return 0; 4085cfdda9d7SSteve Wise } 4086cfdda9d7SSteve Wise 4087cfdda9d7SSteve Wise static int set_tcb_rpl(struct c4iw_dev *dev, struct sk_buff *skb) 4088cfdda9d7SSteve Wise { 4089cfdda9d7SSteve Wise struct cpl_set_tcb_rpl *rpl = cplhdr(skb); 4090cfdda9d7SSteve Wise 4091cfdda9d7SSteve Wise if (rpl->status != CPL_ERR_NONE) { 4092cfdda9d7SSteve Wise printk(KERN_ERR MOD "Unexpected SET_TCB_RPL status %u " 4093cfdda9d7SSteve Wise "for tid %u\n", rpl->status, GET_TID(rpl)); 4094cfdda9d7SSteve Wise } 40952f5b48c3SSteve Wise kfree_skb(skb); 4096cfdda9d7SSteve Wise return 0; 4097cfdda9d7SSteve Wise } 4098cfdda9d7SSteve Wise 4099be4c9badSRoland Dreier static int fw6_msg(struct c4iw_dev *dev, struct sk_buff *skb) 4100be4c9badSRoland Dreier { 4101be4c9badSRoland Dreier struct cpl_fw6_msg *rpl = cplhdr(skb); 4102be4c9badSRoland Dreier struct c4iw_wr_wait *wr_waitp; 4103be4c9badSRoland Dreier int ret; 4104be4c9badSRoland Dreier 4105be4c9badSRoland Dreier PDBG("%s type %u\n", __func__, rpl->type); 4106be4c9badSRoland Dreier 4107be4c9badSRoland Dreier switch (rpl->type) { 41085be78ee9SVipul Pandya case FW6_TYPE_WR_RPL: 4109be4c9badSRoland Dreier ret = (int)((be64_to_cpu(rpl->data[0]) >> 8) & 0xff); 4110c8e081a1SRoland Dreier wr_waitp = (struct c4iw_wr_wait *)(__force unsigned long) rpl->data[1]; 4111be4c9badSRoland Dreier PDBG("%s wr_waitp %p ret %u\n", __func__, wr_waitp, ret); 4112d9594d99SSteve Wise if (wr_waitp) 4113d9594d99SSteve Wise c4iw_wake_up(wr_waitp, ret ? -ret : 0); 41142f5b48c3SSteve Wise kfree_skb(skb); 4115be4c9badSRoland Dreier break; 41165be78ee9SVipul Pandya case FW6_TYPE_CQE: 41175be78ee9SVipul Pandya case FW6_TYPE_OFLD_CONNECTION_WR_RPL: 41181cab775cSVipul Pandya sched(dev, skb); 41195be78ee9SVipul Pandya break; 4120be4c9badSRoland Dreier default: 4121be4c9badSRoland Dreier printk(KERN_ERR MOD "%s unexpected fw6 msg type %u\n", __func__, 4122be4c9badSRoland Dreier rpl->type); 41232f5b48c3SSteve Wise kfree_skb(skb); 4124be4c9badSRoland Dreier break; 4125be4c9badSRoland Dreier } 4126be4c9badSRoland Dreier return 0; 4127be4c9badSRoland Dreier } 4128be4c9badSRoland Dreier 41298da7e7a5SSteve Wise static int peer_abort_intr(struct c4iw_dev *dev, struct sk_buff *skb) 41308da7e7a5SSteve Wise { 41318da7e7a5SSteve Wise struct cpl_abort_req_rss *req = cplhdr(skb); 41328da7e7a5SSteve Wise struct c4iw_ep *ep; 41338da7e7a5SSteve Wise struct tid_info *t = dev->rdev.lldi.tids; 41348da7e7a5SSteve Wise unsigned int tid = GET_TID(req); 41358da7e7a5SSteve Wise 41368da7e7a5SSteve Wise ep = lookup_tid(t, tid); 413714b92228SSteve Wise if (!ep) { 413814b92228SSteve Wise printk(KERN_WARNING MOD 413914b92228SSteve Wise "Abort on non-existent endpoint, tid %d\n", tid); 414014b92228SSteve Wise kfree_skb(skb); 414114b92228SSteve Wise return 0; 414214b92228SSteve Wise } 41437a2cea2aSSteve Wise if (is_neg_adv(req->status)) { 4144179d03bbSHariprasad S PDBG("%s Negative advice on abort- tid %u status %d (%s)\n", 4145179d03bbSHariprasad S __func__, ep->hwtid, req->status, 4146179d03bbSHariprasad S neg_adv_str(req->status)); 4147179d03bbSHariprasad S ep->stats.abort_neg_adv++; 4148179d03bbSHariprasad S dev->rdev.stats.neg_adv++; 41498da7e7a5SSteve Wise kfree_skb(skb); 41508da7e7a5SSteve Wise return 0; 41518da7e7a5SSteve Wise } 41528da7e7a5SSteve Wise PDBG("%s ep %p tid %u state %u\n", __func__, ep, ep->hwtid, 41538da7e7a5SSteve Wise ep->com.state); 41548da7e7a5SSteve Wise 41558da7e7a5SSteve Wise /* 41568da7e7a5SSteve Wise * Wake up any threads in rdma_init() or rdma_fini(). 41577c0a33d6SVipul Pandya * However, if we are on MPAv2 and want to retry with MPAv1 41587c0a33d6SVipul Pandya * then, don't wake up yet. 41598da7e7a5SSteve Wise */ 41607c0a33d6SVipul Pandya if (mpa_rev == 2 && !ep->tried_with_mpa_v1) { 41617c0a33d6SVipul Pandya if (ep->com.state != MPA_REQ_SENT) 41627c0a33d6SVipul Pandya c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET); 41637c0a33d6SVipul Pandya } else 41648da7e7a5SSteve Wise c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET); 41658da7e7a5SSteve Wise sched(dev, skb); 41668da7e7a5SSteve Wise return 0; 41678da7e7a5SSteve Wise } 41688da7e7a5SSteve Wise 4169be4c9badSRoland Dreier /* 4170be4c9badSRoland Dreier * Most upcalls from the T4 Core go to sched() to 4171be4c9badSRoland Dreier * schedule the processing on a work queue. 4172be4c9badSRoland Dreier */ 4173be4c9badSRoland Dreier c4iw_handler_func c4iw_handlers[NUM_CPL_CMDS] = { 4174be4c9badSRoland Dreier [CPL_ACT_ESTABLISH] = sched, 4175be4c9badSRoland Dreier [CPL_ACT_OPEN_RPL] = sched, 4176be4c9badSRoland Dreier [CPL_RX_DATA] = sched, 4177be4c9badSRoland Dreier [CPL_ABORT_RPL_RSS] = sched, 4178be4c9badSRoland Dreier [CPL_ABORT_RPL] = sched, 4179be4c9badSRoland Dreier [CPL_PASS_OPEN_RPL] = sched, 4180be4c9badSRoland Dreier [CPL_CLOSE_LISTSRV_RPL] = sched, 4181be4c9badSRoland Dreier [CPL_PASS_ACCEPT_REQ] = sched, 4182be4c9badSRoland Dreier [CPL_PASS_ESTABLISH] = sched, 4183be4c9badSRoland Dreier [CPL_PEER_CLOSE] = sched, 4184be4c9badSRoland Dreier [CPL_CLOSE_CON_RPL] = sched, 41858da7e7a5SSteve Wise [CPL_ABORT_REQ_RSS] = peer_abort_intr, 4186be4c9badSRoland Dreier [CPL_RDMA_TERMINATE] = sched, 4187be4c9badSRoland Dreier [CPL_FW4_ACK] = sched, 4188be4c9badSRoland Dreier [CPL_SET_TCB_RPL] = set_tcb_rpl, 41891cab775cSVipul Pandya [CPL_FW6_MSG] = fw6_msg, 41901cab775cSVipul Pandya [CPL_RX_PKT] = sched 4191be4c9badSRoland Dreier }; 4192be4c9badSRoland Dreier 4193cfdda9d7SSteve Wise int __init c4iw_cm_init(void) 4194cfdda9d7SSteve Wise { 4195be4c9badSRoland Dreier spin_lock_init(&timeout_lock); 4196cfdda9d7SSteve Wise skb_queue_head_init(&rxq); 4197cfdda9d7SSteve Wise 4198cfdda9d7SSteve Wise workq = create_singlethread_workqueue("iw_cxgb4"); 4199cfdda9d7SSteve Wise if (!workq) 4200cfdda9d7SSteve Wise return -ENOMEM; 4201cfdda9d7SSteve Wise 4202cfdda9d7SSteve Wise return 0; 4203cfdda9d7SSteve Wise } 4204cfdda9d7SSteve Wise 420546c1376dSSteve Wise void c4iw_cm_term(void) 4206cfdda9d7SSteve Wise { 4207be4c9badSRoland Dreier WARN_ON(!list_empty(&timeout_list)); 4208cfdda9d7SSteve Wise flush_workqueue(workq); 4209cfdda9d7SSteve Wise destroy_workqueue(workq); 4210cfdda9d7SSteve Wise } 4211