17b36b6e0Skxie@chelsio.com /* 27b36b6e0Skxie@chelsio.com * cxgb4i.c: Chelsio T4 iSCSI driver. 37b36b6e0Skxie@chelsio.com * 41149a5edSKaren Xie * Copyright (c) 2010-2015 Chelsio Communications, Inc. 57b36b6e0Skxie@chelsio.com * 67b36b6e0Skxie@chelsio.com * This program is free software; you can redistribute it and/or modify 77b36b6e0Skxie@chelsio.com * it under the terms of the GNU General Public License as published by 87b36b6e0Skxie@chelsio.com * the Free Software Foundation. 97b36b6e0Skxie@chelsio.com * 107b36b6e0Skxie@chelsio.com * Written by: Karen Xie (kxie@chelsio.com) 117b36b6e0Skxie@chelsio.com * Rakesh Ranjan (rranjan@chelsio.com) 127b36b6e0Skxie@chelsio.com */ 137b36b6e0Skxie@chelsio.com 147b36b6e0Skxie@chelsio.com #define pr_fmt(fmt) KBUILD_MODNAME ":%s: " fmt, __func__ 157b36b6e0Skxie@chelsio.com 1628466e0fSNicolas Dichtel #include <linux/kernel.h> 177b36b6e0Skxie@chelsio.com #include <linux/module.h> 187b36b6e0Skxie@chelsio.com #include <linux/moduleparam.h> 197b36b6e0Skxie@chelsio.com #include <scsi/scsi_host.h> 207b36b6e0Skxie@chelsio.com #include <net/tcp.h> 217b36b6e0Skxie@chelsio.com #include <net/dst.h> 227b36b6e0Skxie@chelsio.com #include <linux/netdevice.h> 23759a0cc5SAnish Bhatt #include <net/addrconf.h> 247b36b6e0Skxie@chelsio.com 253bd3e8bfSKaren Xie #include "t4_regs.h" 267b36b6e0Skxie@chelsio.com #include "t4_msg.h" 277b36b6e0Skxie@chelsio.com #include "cxgb4.h" 287b36b6e0Skxie@chelsio.com #include "cxgb4_uld.h" 297b36b6e0Skxie@chelsio.com #include "t4fw_api.h" 307b36b6e0Skxie@chelsio.com #include "l2t.h" 317b36b6e0Skxie@chelsio.com #include "cxgb4i.h" 32211a84e3SAnish Bhatt #include "clip_tbl.h" 337b36b6e0Skxie@chelsio.com 347b36b6e0Skxie@chelsio.com static unsigned int dbg_level; 357b36b6e0Skxie@chelsio.com 367b36b6e0Skxie@chelsio.com #include "../libcxgbi.h" 377b36b6e0Skxie@chelsio.com 38b5a5fe4eSVarun Prakash #ifdef CONFIG_CHELSIO_T4_DCB 39b5a5fe4eSVarun Prakash #include <net/dcbevent.h> 40b5a5fe4eSVarun Prakash #include "cxgb4_dcb.h" 41b5a5fe4eSVarun Prakash #endif 42b5a5fe4eSVarun Prakash 437b36b6e0Skxie@chelsio.com #define DRV_MODULE_NAME "cxgb4i" 44cb22bdc8SVarun Prakash #define DRV_MODULE_DESC "Chelsio T4-T6 iSCSI Driver" 450ea5bf3dSKaren Xie #define DRV_MODULE_VERSION "0.9.5-ko" 460ea5bf3dSKaren Xie #define DRV_MODULE_RELDATE "Apr. 2015" 477b36b6e0Skxie@chelsio.com 487b36b6e0Skxie@chelsio.com static char version[] = 497b36b6e0Skxie@chelsio.com DRV_MODULE_DESC " " DRV_MODULE_NAME 500ea5bf3dSKaren Xie " v" DRV_MODULE_VERSION " (" DRV_MODULE_RELDATE ")\n"; 517b36b6e0Skxie@chelsio.com 527b36b6e0Skxie@chelsio.com MODULE_AUTHOR("Chelsio Communications, Inc."); 537b36b6e0Skxie@chelsio.com MODULE_DESCRIPTION(DRV_MODULE_DESC); 547b36b6e0Skxie@chelsio.com MODULE_VERSION(DRV_MODULE_VERSION); 557b36b6e0Skxie@chelsio.com MODULE_LICENSE("GPL"); 567b36b6e0Skxie@chelsio.com 577b36b6e0Skxie@chelsio.com module_param(dbg_level, uint, 0644); 587b36b6e0Skxie@chelsio.com MODULE_PARM_DESC(dbg_level, "Debug flag (default=0)"); 597b36b6e0Skxie@chelsio.com 6081daf10cSKaren Xie #define CXGB4I_DEFAULT_10G_RCV_WIN (256 * 1024) 6181daf10cSKaren Xie static int cxgb4i_rcv_win = -1; 627b36b6e0Skxie@chelsio.com module_param(cxgb4i_rcv_win, int, 0644); 63*21112e13SVarun Prakash MODULE_PARM_DESC(cxgb4i_rcv_win, "TCP receive window in bytes"); 647b36b6e0Skxie@chelsio.com 6581daf10cSKaren Xie #define CXGB4I_DEFAULT_10G_SND_WIN (128 * 1024) 6681daf10cSKaren Xie static int cxgb4i_snd_win = -1; 677b36b6e0Skxie@chelsio.com module_param(cxgb4i_snd_win, int, 0644); 687b36b6e0Skxie@chelsio.com MODULE_PARM_DESC(cxgb4i_snd_win, "TCP send window in bytes"); 697b36b6e0Skxie@chelsio.com 707b36b6e0Skxie@chelsio.com static int cxgb4i_rx_credit_thres = 10 * 1024; 717b36b6e0Skxie@chelsio.com module_param(cxgb4i_rx_credit_thres, int, 0644); 727b36b6e0Skxie@chelsio.com MODULE_PARM_DESC(cxgb4i_rx_credit_thres, 737b36b6e0Skxie@chelsio.com "RX credits return threshold in bytes (default=10KB)"); 747b36b6e0Skxie@chelsio.com 757b36b6e0Skxie@chelsio.com static unsigned int cxgb4i_max_connect = (8 * 1024); 767b36b6e0Skxie@chelsio.com module_param(cxgb4i_max_connect, uint, 0644); 777b36b6e0Skxie@chelsio.com MODULE_PARM_DESC(cxgb4i_max_connect, "Maximum number of connections"); 787b36b6e0Skxie@chelsio.com 797b36b6e0Skxie@chelsio.com static unsigned short cxgb4i_sport_base = 20000; 807b36b6e0Skxie@chelsio.com module_param(cxgb4i_sport_base, ushort, 0644); 817b36b6e0Skxie@chelsio.com MODULE_PARM_DESC(cxgb4i_sport_base, "Starting port number (default 20000)"); 827b36b6e0Skxie@chelsio.com 837b36b6e0Skxie@chelsio.com typedef void (*cxgb4i_cplhandler_func)(struct cxgbi_device *, struct sk_buff *); 847b36b6e0Skxie@chelsio.com 857b36b6e0Skxie@chelsio.com static void *t4_uld_add(const struct cxgb4_lld_info *); 867b36b6e0Skxie@chelsio.com static int t4_uld_rx_handler(void *, const __be64 *, const struct pkt_gl *); 877b36b6e0Skxie@chelsio.com static int t4_uld_state_change(void *, enum cxgb4_state state); 8864bfead8SKaren Xie static inline int send_tx_flowc_wr(struct cxgbi_sock *); 897b36b6e0Skxie@chelsio.com 907b36b6e0Skxie@chelsio.com static const struct cxgb4_uld_info cxgb4i_uld_info = { 917b36b6e0Skxie@chelsio.com .name = DRV_MODULE_NAME, 920fbc81b3SHariprasad Shenai .nrxq = MAX_ULD_QSETS, 93ab677ff4SHariprasad Shenai .ntxq = MAX_ULD_QSETS, 940fbc81b3SHariprasad Shenai .rxq_size = 1024, 950fbc81b3SHariprasad Shenai .lro = false, 967b36b6e0Skxie@chelsio.com .add = t4_uld_add, 977b36b6e0Skxie@chelsio.com .rx_handler = t4_uld_rx_handler, 987b36b6e0Skxie@chelsio.com .state_change = t4_uld_state_change, 997b36b6e0Skxie@chelsio.com }; 1007b36b6e0Skxie@chelsio.com 1017b36b6e0Skxie@chelsio.com static struct scsi_host_template cxgb4i_host_template = { 1027b36b6e0Skxie@chelsio.com .module = THIS_MODULE, 1037b36b6e0Skxie@chelsio.com .name = DRV_MODULE_NAME, 1047b36b6e0Skxie@chelsio.com .proc_name = DRV_MODULE_NAME, 1057b36b6e0Skxie@chelsio.com .can_queue = CXGB4I_SCSI_HOST_QDEPTH, 1067b36b6e0Skxie@chelsio.com .queuecommand = iscsi_queuecommand, 107db5ed4dfSChristoph Hellwig .change_queue_depth = scsi_change_queue_depth, 1087b36b6e0Skxie@chelsio.com .sg_tablesize = SG_ALL, 1097b36b6e0Skxie@chelsio.com .max_sectors = 0xFFFF, 1107b36b6e0Skxie@chelsio.com .cmd_per_lun = ISCSI_DEF_CMD_PER_LUN, 111b6a05c82SChristoph Hellwig .eh_timed_out = iscsi_eh_cmd_timed_out, 1127b36b6e0Skxie@chelsio.com .eh_abort_handler = iscsi_eh_abort, 1137b36b6e0Skxie@chelsio.com .eh_device_reset_handler = iscsi_eh_device_reset, 1147b36b6e0Skxie@chelsio.com .eh_target_reset_handler = iscsi_eh_recover_target, 1157b36b6e0Skxie@chelsio.com .target_alloc = iscsi_target_alloc, 1164af14d11SChristoph Hellwig .dma_boundary = PAGE_SIZE - 1, 1177b36b6e0Skxie@chelsio.com .this_id = -1, 118c40ecc12SChristoph Hellwig .track_queue_depth = 1, 1197b36b6e0Skxie@chelsio.com }; 1207b36b6e0Skxie@chelsio.com 1217b36b6e0Skxie@chelsio.com static struct iscsi_transport cxgb4i_iscsi_transport = { 1227b36b6e0Skxie@chelsio.com .owner = THIS_MODULE, 1237b36b6e0Skxie@chelsio.com .name = DRV_MODULE_NAME, 1247b36b6e0Skxie@chelsio.com .caps = CAP_RECOVERY_L0 | CAP_MULTI_R2T | CAP_HDRDGST | 1257b36b6e0Skxie@chelsio.com CAP_DATADGST | CAP_DIGEST_OFFLOAD | 126fdafd4dfSMike Christie CAP_PADDING_OFFLOAD | CAP_TEXT_NEGO, 1273128c6c7SMike Christie .attr_is_visible = cxgbi_attr_is_visible, 1287b36b6e0Skxie@chelsio.com .get_host_param = cxgbi_get_host_param, 1297b36b6e0Skxie@chelsio.com .set_host_param = cxgbi_set_host_param, 1307b36b6e0Skxie@chelsio.com /* session management */ 1317b36b6e0Skxie@chelsio.com .create_session = cxgbi_create_session, 1327b36b6e0Skxie@chelsio.com .destroy_session = cxgbi_destroy_session, 1337b36b6e0Skxie@chelsio.com .get_session_param = iscsi_session_get_param, 1347b36b6e0Skxie@chelsio.com /* connection management */ 1357b36b6e0Skxie@chelsio.com .create_conn = cxgbi_create_conn, 1367b36b6e0Skxie@chelsio.com .bind_conn = cxgbi_bind_conn, 1377b36b6e0Skxie@chelsio.com .destroy_conn = iscsi_tcp_conn_teardown, 1387b36b6e0Skxie@chelsio.com .start_conn = iscsi_conn_start, 1397b36b6e0Skxie@chelsio.com .stop_conn = iscsi_conn_stop, 140c71b9b66SMike Christie .get_conn_param = iscsi_conn_get_param, 1417b36b6e0Skxie@chelsio.com .set_param = cxgbi_set_conn_param, 1427b36b6e0Skxie@chelsio.com .get_stats = cxgbi_get_conn_stats, 1437b36b6e0Skxie@chelsio.com /* pdu xmit req from user space */ 1447b36b6e0Skxie@chelsio.com .send_pdu = iscsi_conn_send_pdu, 1457b36b6e0Skxie@chelsio.com /* task */ 1467b36b6e0Skxie@chelsio.com .init_task = iscsi_tcp_task_init, 1477b36b6e0Skxie@chelsio.com .xmit_task = iscsi_tcp_task_xmit, 1487b36b6e0Skxie@chelsio.com .cleanup_task = cxgbi_cleanup_task, 1497b36b6e0Skxie@chelsio.com /* pdu */ 1507b36b6e0Skxie@chelsio.com .alloc_pdu = cxgbi_conn_alloc_pdu, 1517b36b6e0Skxie@chelsio.com .init_pdu = cxgbi_conn_init_pdu, 1527b36b6e0Skxie@chelsio.com .xmit_pdu = cxgbi_conn_xmit_pdu, 1537b36b6e0Skxie@chelsio.com .parse_pdu_itt = cxgbi_parse_pdu_itt, 1547b36b6e0Skxie@chelsio.com /* TCP connect/disconnect */ 155c71b9b66SMike Christie .get_ep_param = cxgbi_get_ep_param, 1567b36b6e0Skxie@chelsio.com .ep_connect = cxgbi_ep_connect, 1577b36b6e0Skxie@chelsio.com .ep_poll = cxgbi_ep_poll, 1587b36b6e0Skxie@chelsio.com .ep_disconnect = cxgbi_ep_disconnect, 1597b36b6e0Skxie@chelsio.com /* Error recovery timeout call */ 1607b36b6e0Skxie@chelsio.com .session_recovery_timedout = iscsi_session_recovery_timedout, 1617b36b6e0Skxie@chelsio.com }; 1627b36b6e0Skxie@chelsio.com 163b5a5fe4eSVarun Prakash #ifdef CONFIG_CHELSIO_T4_DCB 164b5a5fe4eSVarun Prakash static int 165b5a5fe4eSVarun Prakash cxgb4_dcb_change_notify(struct notifier_block *, unsigned long, void *); 166b5a5fe4eSVarun Prakash 167b5a5fe4eSVarun Prakash static struct notifier_block cxgb4_dcb_change = { 168b5a5fe4eSVarun Prakash .notifier_call = cxgb4_dcb_change_notify, 169b5a5fe4eSVarun Prakash }; 170b5a5fe4eSVarun Prakash #endif 171b5a5fe4eSVarun Prakash 1727b36b6e0Skxie@chelsio.com static struct scsi_transport_template *cxgb4i_stt; 1737b36b6e0Skxie@chelsio.com 1747b36b6e0Skxie@chelsio.com /* 1757b36b6e0Skxie@chelsio.com * CPL (Chelsio Protocol Language) defines a message passing interface between 1767b36b6e0Skxie@chelsio.com * the host driver and Chelsio asic. 1777b36b6e0Skxie@chelsio.com * The section below implments CPLs that related to iscsi tcp connection 1787b36b6e0Skxie@chelsio.com * open/close/abort and data send/receive. 1797b36b6e0Skxie@chelsio.com */ 180759a0cc5SAnish Bhatt 1817b36b6e0Skxie@chelsio.com #define RCV_BUFSIZ_MASK 0x3FFU 182d3074cceSKaren Xie #define MAX_IMM_TX_PKT_LEN 256 1837b36b6e0Skxie@chelsio.com 1847b36b6e0Skxie@chelsio.com static int push_tx_frames(struct cxgbi_sock *, int); 1857b36b6e0Skxie@chelsio.com 1867b36b6e0Skxie@chelsio.com /* 1877b36b6e0Skxie@chelsio.com * is_ofld_imm - check whether a packet can be sent as immediate data 1887b36b6e0Skxie@chelsio.com * @skb: the packet 1897b36b6e0Skxie@chelsio.com * 1907b36b6e0Skxie@chelsio.com * Returns true if a packet can be sent as an offload WR with immediate 1917b36b6e0Skxie@chelsio.com * data. We currently use the same limit as for Ethernet packets. 1927b36b6e0Skxie@chelsio.com */ 19384944d8cSKaren Xie static inline bool is_ofld_imm(const struct sk_buff *skb) 1947b36b6e0Skxie@chelsio.com { 19584944d8cSKaren Xie int len = skb->len; 19684944d8cSKaren Xie 19784944d8cSKaren Xie if (likely(cxgbi_skcb_test_flag(skb, SKCBF_TX_NEED_HDR))) 19884944d8cSKaren Xie len += sizeof(struct fw_ofld_tx_data_wr); 19984944d8cSKaren Xie 20084944d8cSKaren Xie return len <= MAX_IMM_TX_PKT_LEN; 2017b36b6e0Skxie@chelsio.com } 2027b36b6e0Skxie@chelsio.com 2037b36b6e0Skxie@chelsio.com static void send_act_open_req(struct cxgbi_sock *csk, struct sk_buff *skb, 2047b36b6e0Skxie@chelsio.com struct l2t_entry *e) 2057b36b6e0Skxie@chelsio.com { 2063bd3e8bfSKaren Xie struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(csk->cdev); 2077b36b6e0Skxie@chelsio.com int wscale = cxgbi_sock_compute_wscale(csk->mss_idx); 2087b36b6e0Skxie@chelsio.com unsigned long long opt0; 2097b36b6e0Skxie@chelsio.com unsigned int opt2; 2107b36b6e0Skxie@chelsio.com unsigned int qid_atid = ((unsigned int)csk->atid) | 2117b36b6e0Skxie@chelsio.com (((unsigned int)csk->rss_qid) << 14); 2127b36b6e0Skxie@chelsio.com 213d7990b0cSAnish Bhatt opt0 = KEEP_ALIVE_F | 214d7990b0cSAnish Bhatt WND_SCALE_V(wscale) | 215d7990b0cSAnish Bhatt MSS_IDX_V(csk->mss_idx) | 216d7990b0cSAnish Bhatt L2T_IDX_V(((struct l2t_entry *)csk->l2t)->idx) | 217d7990b0cSAnish Bhatt TX_CHAN_V(csk->tx_chan) | 218d7990b0cSAnish Bhatt SMAC_SEL_V(csk->smac_idx) | 219d7990b0cSAnish Bhatt ULP_MODE_V(ULP_MODE_ISCSI) | 22081daf10cSKaren Xie RCV_BUFSIZ_V(csk->rcv_win >> 10); 2211eb88a5dSKaren Xie 222d7990b0cSAnish Bhatt opt2 = RX_CHANNEL_V(0) | 223d7990b0cSAnish Bhatt RSS_QUEUE_VALID_F | 224d7990b0cSAnish Bhatt RSS_QUEUE_V(csk->rss_qid); 2257b36b6e0Skxie@chelsio.com 2263bd3e8bfSKaren Xie if (is_t4(lldi->adapter_type)) { 2273bd3e8bfSKaren Xie struct cpl_act_open_req *req = 2283bd3e8bfSKaren Xie (struct cpl_act_open_req *)skb->head; 2293bd3e8bfSKaren Xie 2307b36b6e0Skxie@chelsio.com INIT_TP_WR(req, 0); 2317b36b6e0Skxie@chelsio.com OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_ACT_OPEN_REQ, 2327b36b6e0Skxie@chelsio.com qid_atid)); 2337b36b6e0Skxie@chelsio.com req->local_port = csk->saddr.sin_port; 2347b36b6e0Skxie@chelsio.com req->peer_port = csk->daddr.sin_port; 2357b36b6e0Skxie@chelsio.com req->local_ip = csk->saddr.sin_addr.s_addr; 2367b36b6e0Skxie@chelsio.com req->peer_ip = csk->daddr.sin_addr.s_addr; 2377b36b6e0Skxie@chelsio.com req->opt0 = cpu_to_be64(opt0); 238ac0245ffSKaren Xie req->params = cpu_to_be32(cxgb4_select_ntuple( 239ac0245ffSKaren Xie csk->cdev->ports[csk->port_id], 240ac0245ffSKaren Xie csk->l2t)); 241d7990b0cSAnish Bhatt opt2 |= RX_FC_VALID_F; 2427b36b6e0Skxie@chelsio.com req->opt2 = cpu_to_be32(opt2); 2437b36b6e0Skxie@chelsio.com 2447b36b6e0Skxie@chelsio.com log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK, 2453bd3e8bfSKaren Xie "csk t4 0x%p, %pI4:%u-%pI4:%u, atid %d, qid %u.\n", 2467b36b6e0Skxie@chelsio.com csk, &req->local_ip, ntohs(req->local_port), 2477b36b6e0Skxie@chelsio.com &req->peer_ip, ntohs(req->peer_port), 2487b36b6e0Skxie@chelsio.com csk->atid, csk->rss_qid); 249586be7cbSVarun Prakash } else if (is_t5(lldi->adapter_type)) { 2503bd3e8bfSKaren Xie struct cpl_t5_act_open_req *req = 2513bd3e8bfSKaren Xie (struct cpl_t5_act_open_req *)skb->head; 2521eb88a5dSKaren Xie u32 isn = (prandom_u32() & ~7UL) - 1; 2537b36b6e0Skxie@chelsio.com 2543bd3e8bfSKaren Xie INIT_TP_WR(req, 0); 2553bd3e8bfSKaren Xie OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_ACT_OPEN_REQ, 2563bd3e8bfSKaren Xie qid_atid)); 2573bd3e8bfSKaren Xie req->local_port = csk->saddr.sin_port; 2583bd3e8bfSKaren Xie req->peer_port = csk->daddr.sin_port; 2593bd3e8bfSKaren Xie req->local_ip = csk->saddr.sin_addr.s_addr; 2603bd3e8bfSKaren Xie req->peer_ip = csk->daddr.sin_addr.s_addr; 2613bd3e8bfSKaren Xie req->opt0 = cpu_to_be64(opt0); 262d7990b0cSAnish Bhatt req->params = cpu_to_be64(FILTER_TUPLE_V( 263ac0245ffSKaren Xie cxgb4_select_ntuple( 264ac0245ffSKaren Xie csk->cdev->ports[csk->port_id], 265ac0245ffSKaren Xie csk->l2t))); 2661eb88a5dSKaren Xie req->rsvd = cpu_to_be32(isn); 2671eb88a5dSKaren Xie opt2 |= T5_ISS_VALID; 2681eb88a5dSKaren Xie opt2 |= T5_OPT_2_VALID_F; 2691eb88a5dSKaren Xie 2703bd3e8bfSKaren Xie req->opt2 = cpu_to_be32(opt2); 2713bd3e8bfSKaren Xie 2723bd3e8bfSKaren Xie log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK, 2733bd3e8bfSKaren Xie "csk t5 0x%p, %pI4:%u-%pI4:%u, atid %d, qid %u.\n", 2743bd3e8bfSKaren Xie csk, &req->local_ip, ntohs(req->local_port), 2753bd3e8bfSKaren Xie &req->peer_ip, ntohs(req->peer_port), 2763bd3e8bfSKaren Xie csk->atid, csk->rss_qid); 277586be7cbSVarun Prakash } else { 278586be7cbSVarun Prakash struct cpl_t6_act_open_req *req = 279586be7cbSVarun Prakash (struct cpl_t6_act_open_req *)skb->head; 280586be7cbSVarun Prakash u32 isn = (prandom_u32() & ~7UL) - 1; 281586be7cbSVarun Prakash 282586be7cbSVarun Prakash INIT_TP_WR(req, 0); 283586be7cbSVarun Prakash OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_ACT_OPEN_REQ, 284586be7cbSVarun Prakash qid_atid)); 285586be7cbSVarun Prakash req->local_port = csk->saddr.sin_port; 286586be7cbSVarun Prakash req->peer_port = csk->daddr.sin_port; 287586be7cbSVarun Prakash req->local_ip = csk->saddr.sin_addr.s_addr; 288586be7cbSVarun Prakash req->peer_ip = csk->daddr.sin_addr.s_addr; 289586be7cbSVarun Prakash req->opt0 = cpu_to_be64(opt0); 290586be7cbSVarun Prakash req->params = cpu_to_be64(FILTER_TUPLE_V( 291586be7cbSVarun Prakash cxgb4_select_ntuple( 292586be7cbSVarun Prakash csk->cdev->ports[csk->port_id], 293586be7cbSVarun Prakash csk->l2t))); 294586be7cbSVarun Prakash req->rsvd = cpu_to_be32(isn); 295586be7cbSVarun Prakash 296586be7cbSVarun Prakash opt2 |= T5_ISS_VALID; 297586be7cbSVarun Prakash opt2 |= RX_FC_DISABLE_F; 298586be7cbSVarun Prakash opt2 |= T5_OPT_2_VALID_F; 299586be7cbSVarun Prakash 300586be7cbSVarun Prakash req->opt2 = cpu_to_be32(opt2); 301586be7cbSVarun Prakash req->rsvd2 = cpu_to_be32(0); 302586be7cbSVarun Prakash req->opt3 = cpu_to_be32(0); 303586be7cbSVarun Prakash 304586be7cbSVarun Prakash log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK, 305586be7cbSVarun Prakash "csk t6 0x%p, %pI4:%u-%pI4:%u, atid %d, qid %u.\n", 306586be7cbSVarun Prakash csk, &req->local_ip, ntohs(req->local_port), 307586be7cbSVarun Prakash &req->peer_ip, ntohs(req->peer_port), 308586be7cbSVarun Prakash csk->atid, csk->rss_qid); 3093bd3e8bfSKaren Xie } 3103bd3e8bfSKaren Xie 3113bd3e8bfSKaren Xie set_wr_txq(skb, CPL_PRIORITY_SETUP, csk->port_id); 312759a0cc5SAnish Bhatt 313759a0cc5SAnish Bhatt pr_info_ipaddr("t%d csk 0x%p,%u,0x%lx,%u, rss_qid %u.\n", 314586be7cbSVarun Prakash (&csk->saddr), (&csk->daddr), 315586be7cbSVarun Prakash CHELSIO_CHIP_VERSION(lldi->adapter_type), csk, 316759a0cc5SAnish Bhatt csk->state, csk->flags, csk->atid, csk->rss_qid); 317759a0cc5SAnish Bhatt 318759a0cc5SAnish Bhatt cxgb4_l2t_send(csk->cdev->ports[csk->port_id], skb, csk->l2t); 319759a0cc5SAnish Bhatt } 320759a0cc5SAnish Bhatt 321f42bb57cSAnish Bhatt #if IS_ENABLED(CONFIG_IPV6) 322759a0cc5SAnish Bhatt static void send_act_open_req6(struct cxgbi_sock *csk, struct sk_buff *skb, 323759a0cc5SAnish Bhatt struct l2t_entry *e) 324759a0cc5SAnish Bhatt { 325759a0cc5SAnish Bhatt struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(csk->cdev); 326759a0cc5SAnish Bhatt int wscale = cxgbi_sock_compute_wscale(csk->mss_idx); 327759a0cc5SAnish Bhatt unsigned long long opt0; 328759a0cc5SAnish Bhatt unsigned int opt2; 329759a0cc5SAnish Bhatt unsigned int qid_atid = ((unsigned int)csk->atid) | 330759a0cc5SAnish Bhatt (((unsigned int)csk->rss_qid) << 14); 331759a0cc5SAnish Bhatt 332d7990b0cSAnish Bhatt opt0 = KEEP_ALIVE_F | 333d7990b0cSAnish Bhatt WND_SCALE_V(wscale) | 334d7990b0cSAnish Bhatt MSS_IDX_V(csk->mss_idx) | 335d7990b0cSAnish Bhatt L2T_IDX_V(((struct l2t_entry *)csk->l2t)->idx) | 336d7990b0cSAnish Bhatt TX_CHAN_V(csk->tx_chan) | 337d7990b0cSAnish Bhatt SMAC_SEL_V(csk->smac_idx) | 338d7990b0cSAnish Bhatt ULP_MODE_V(ULP_MODE_ISCSI) | 33981daf10cSKaren Xie RCV_BUFSIZ_V(csk->rcv_win >> 10); 340759a0cc5SAnish Bhatt 341d7990b0cSAnish Bhatt opt2 = RX_CHANNEL_V(0) | 342d7990b0cSAnish Bhatt RSS_QUEUE_VALID_F | 343d7990b0cSAnish Bhatt RSS_QUEUE_V(csk->rss_qid); 344759a0cc5SAnish Bhatt 345586be7cbSVarun Prakash if (is_t4(lldi->adapter_type)) { 346759a0cc5SAnish Bhatt struct cpl_act_open_req6 *req = 347759a0cc5SAnish Bhatt (struct cpl_act_open_req6 *)skb->head; 348759a0cc5SAnish Bhatt 349759a0cc5SAnish Bhatt INIT_TP_WR(req, 0); 350759a0cc5SAnish Bhatt OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_ACT_OPEN_REQ6, 351759a0cc5SAnish Bhatt qid_atid)); 352759a0cc5SAnish Bhatt req->local_port = csk->saddr6.sin6_port; 353759a0cc5SAnish Bhatt req->peer_port = csk->daddr6.sin6_port; 354759a0cc5SAnish Bhatt 355759a0cc5SAnish Bhatt req->local_ip_hi = *(__be64 *)(csk->saddr6.sin6_addr.s6_addr); 356759a0cc5SAnish Bhatt req->local_ip_lo = *(__be64 *)(csk->saddr6.sin6_addr.s6_addr + 357759a0cc5SAnish Bhatt 8); 358759a0cc5SAnish Bhatt req->peer_ip_hi = *(__be64 *)(csk->daddr6.sin6_addr.s6_addr); 359759a0cc5SAnish Bhatt req->peer_ip_lo = *(__be64 *)(csk->daddr6.sin6_addr.s6_addr + 360759a0cc5SAnish Bhatt 8); 361759a0cc5SAnish Bhatt 362759a0cc5SAnish Bhatt req->opt0 = cpu_to_be64(opt0); 363759a0cc5SAnish Bhatt 364d7990b0cSAnish Bhatt opt2 |= RX_FC_VALID_F; 365759a0cc5SAnish Bhatt req->opt2 = cpu_to_be32(opt2); 366759a0cc5SAnish Bhatt 367759a0cc5SAnish Bhatt req->params = cpu_to_be32(cxgb4_select_ntuple( 368759a0cc5SAnish Bhatt csk->cdev->ports[csk->port_id], 369759a0cc5SAnish Bhatt csk->l2t)); 370586be7cbSVarun Prakash } else if (is_t5(lldi->adapter_type)) { 371759a0cc5SAnish Bhatt struct cpl_t5_act_open_req6 *req = 372759a0cc5SAnish Bhatt (struct cpl_t5_act_open_req6 *)skb->head; 373759a0cc5SAnish Bhatt 374759a0cc5SAnish Bhatt INIT_TP_WR(req, 0); 375759a0cc5SAnish Bhatt OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_ACT_OPEN_REQ6, 376759a0cc5SAnish Bhatt qid_atid)); 377759a0cc5SAnish Bhatt req->local_port = csk->saddr6.sin6_port; 378759a0cc5SAnish Bhatt req->peer_port = csk->daddr6.sin6_port; 379759a0cc5SAnish Bhatt req->local_ip_hi = *(__be64 *)(csk->saddr6.sin6_addr.s6_addr); 380759a0cc5SAnish Bhatt req->local_ip_lo = *(__be64 *)(csk->saddr6.sin6_addr.s6_addr + 381759a0cc5SAnish Bhatt 8); 382759a0cc5SAnish Bhatt req->peer_ip_hi = *(__be64 *)(csk->daddr6.sin6_addr.s6_addr); 383759a0cc5SAnish Bhatt req->peer_ip_lo = *(__be64 *)(csk->daddr6.sin6_addr.s6_addr + 384759a0cc5SAnish Bhatt 8); 385759a0cc5SAnish Bhatt req->opt0 = cpu_to_be64(opt0); 386759a0cc5SAnish Bhatt 387d7990b0cSAnish Bhatt opt2 |= T5_OPT_2_VALID_F; 388759a0cc5SAnish Bhatt req->opt2 = cpu_to_be32(opt2); 389759a0cc5SAnish Bhatt 390d7990b0cSAnish Bhatt req->params = cpu_to_be64(FILTER_TUPLE_V(cxgb4_select_ntuple( 391759a0cc5SAnish Bhatt csk->cdev->ports[csk->port_id], 392759a0cc5SAnish Bhatt csk->l2t))); 393586be7cbSVarun Prakash } else { 394586be7cbSVarun Prakash struct cpl_t6_act_open_req6 *req = 395586be7cbSVarun Prakash (struct cpl_t6_act_open_req6 *)skb->head; 396586be7cbSVarun Prakash 397586be7cbSVarun Prakash INIT_TP_WR(req, 0); 398586be7cbSVarun Prakash OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_ACT_OPEN_REQ6, 399586be7cbSVarun Prakash qid_atid)); 400586be7cbSVarun Prakash req->local_port = csk->saddr6.sin6_port; 401586be7cbSVarun Prakash req->peer_port = csk->daddr6.sin6_port; 402586be7cbSVarun Prakash req->local_ip_hi = *(__be64 *)(csk->saddr6.sin6_addr.s6_addr); 403586be7cbSVarun Prakash req->local_ip_lo = *(__be64 *)(csk->saddr6.sin6_addr.s6_addr + 404586be7cbSVarun Prakash 8); 405586be7cbSVarun Prakash req->peer_ip_hi = *(__be64 *)(csk->daddr6.sin6_addr.s6_addr); 406586be7cbSVarun Prakash req->peer_ip_lo = *(__be64 *)(csk->daddr6.sin6_addr.s6_addr + 407586be7cbSVarun Prakash 8); 408586be7cbSVarun Prakash req->opt0 = cpu_to_be64(opt0); 409586be7cbSVarun Prakash 410586be7cbSVarun Prakash opt2 |= RX_FC_DISABLE_F; 411586be7cbSVarun Prakash opt2 |= T5_OPT_2_VALID_F; 412586be7cbSVarun Prakash 413586be7cbSVarun Prakash req->opt2 = cpu_to_be32(opt2); 414586be7cbSVarun Prakash 415586be7cbSVarun Prakash req->params = cpu_to_be64(FILTER_TUPLE_V(cxgb4_select_ntuple( 416586be7cbSVarun Prakash csk->cdev->ports[csk->port_id], 417586be7cbSVarun Prakash csk->l2t))); 418586be7cbSVarun Prakash 419586be7cbSVarun Prakash req->rsvd2 = cpu_to_be32(0); 420586be7cbSVarun Prakash req->opt3 = cpu_to_be32(0); 421759a0cc5SAnish Bhatt } 422759a0cc5SAnish Bhatt 423759a0cc5SAnish Bhatt set_wr_txq(skb, CPL_PRIORITY_SETUP, csk->port_id); 424759a0cc5SAnish Bhatt 425759a0cc5SAnish Bhatt pr_info("t%d csk 0x%p,%u,0x%lx,%u, [%pI6]:%u-[%pI6]:%u, rss_qid %u.\n", 426586be7cbSVarun Prakash CHELSIO_CHIP_VERSION(lldi->adapter_type), csk, csk->state, 427586be7cbSVarun Prakash csk->flags, csk->atid, 428759a0cc5SAnish Bhatt &csk->saddr6.sin6_addr, ntohs(csk->saddr.sin_port), 429759a0cc5SAnish Bhatt &csk->daddr6.sin6_addr, ntohs(csk->daddr.sin_port), 430759a0cc5SAnish Bhatt csk->rss_qid); 431759a0cc5SAnish Bhatt 4327b36b6e0Skxie@chelsio.com cxgb4_l2t_send(csk->cdev->ports[csk->port_id], skb, csk->l2t); 4337b36b6e0Skxie@chelsio.com } 434f42bb57cSAnish Bhatt #endif 4357b36b6e0Skxie@chelsio.com 4367b36b6e0Skxie@chelsio.com static void send_close_req(struct cxgbi_sock *csk) 4377b36b6e0Skxie@chelsio.com { 4387b36b6e0Skxie@chelsio.com struct sk_buff *skb = csk->cpl_close; 4397b36b6e0Skxie@chelsio.com struct cpl_close_con_req *req = (struct cpl_close_con_req *)skb->head; 4407b36b6e0Skxie@chelsio.com unsigned int tid = csk->tid; 4417b36b6e0Skxie@chelsio.com 4427b36b6e0Skxie@chelsio.com log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK, 4437b36b6e0Skxie@chelsio.com "csk 0x%p,%u,0x%lx, tid %u.\n", 4447b36b6e0Skxie@chelsio.com csk, csk->state, csk->flags, csk->tid); 4457b36b6e0Skxie@chelsio.com csk->cpl_close = NULL; 4467b36b6e0Skxie@chelsio.com set_wr_txq(skb, CPL_PRIORITY_DATA, csk->port_id); 4477b36b6e0Skxie@chelsio.com INIT_TP_WR(req, tid); 4487b36b6e0Skxie@chelsio.com OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_CLOSE_CON_REQ, tid)); 4497b36b6e0Skxie@chelsio.com req->rsvd = 0; 4507b36b6e0Skxie@chelsio.com 4517b36b6e0Skxie@chelsio.com cxgbi_sock_skb_entail(csk, skb); 4527b36b6e0Skxie@chelsio.com if (csk->state >= CTP_ESTABLISHED) 4537b36b6e0Skxie@chelsio.com push_tx_frames(csk, 1); 4547b36b6e0Skxie@chelsio.com } 4557b36b6e0Skxie@chelsio.com 4567b36b6e0Skxie@chelsio.com static void abort_arp_failure(void *handle, struct sk_buff *skb) 4577b36b6e0Skxie@chelsio.com { 4587b36b6e0Skxie@chelsio.com struct cxgbi_sock *csk = (struct cxgbi_sock *)handle; 4597b36b6e0Skxie@chelsio.com struct cpl_abort_req *req; 4607b36b6e0Skxie@chelsio.com 4617b36b6e0Skxie@chelsio.com log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK, 4627b36b6e0Skxie@chelsio.com "csk 0x%p,%u,0x%lx, tid %u, abort.\n", 4637b36b6e0Skxie@chelsio.com csk, csk->state, csk->flags, csk->tid); 4647b36b6e0Skxie@chelsio.com req = (struct cpl_abort_req *)skb->data; 4657b36b6e0Skxie@chelsio.com req->cmd = CPL_ABORT_NO_RST; 4667b36b6e0Skxie@chelsio.com cxgb4_ofld_send(csk->cdev->ports[csk->port_id], skb); 4677b36b6e0Skxie@chelsio.com } 4687b36b6e0Skxie@chelsio.com 4697b36b6e0Skxie@chelsio.com static void send_abort_req(struct cxgbi_sock *csk) 4707b36b6e0Skxie@chelsio.com { 4717b36b6e0Skxie@chelsio.com struct cpl_abort_req *req; 4727b36b6e0Skxie@chelsio.com struct sk_buff *skb = csk->cpl_abort_req; 4737b36b6e0Skxie@chelsio.com 4747b36b6e0Skxie@chelsio.com if (unlikely(csk->state == CTP_ABORTING) || !skb || !csk->cdev) 4757b36b6e0Skxie@chelsio.com return; 47664bfead8SKaren Xie 47764bfead8SKaren Xie if (!cxgbi_sock_flag(csk, CTPF_TX_DATA_SENT)) { 47864bfead8SKaren Xie send_tx_flowc_wr(csk); 47964bfead8SKaren Xie cxgbi_sock_set_flag(csk, CTPF_TX_DATA_SENT); 48064bfead8SKaren Xie } 48164bfead8SKaren Xie 4827b36b6e0Skxie@chelsio.com cxgbi_sock_set_state(csk, CTP_ABORTING); 4837b36b6e0Skxie@chelsio.com cxgbi_sock_set_flag(csk, CTPF_ABORT_RPL_PENDING); 4847b36b6e0Skxie@chelsio.com cxgbi_sock_purge_write_queue(csk); 4857b36b6e0Skxie@chelsio.com 4867b36b6e0Skxie@chelsio.com csk->cpl_abort_req = NULL; 4877b36b6e0Skxie@chelsio.com req = (struct cpl_abort_req *)skb->head; 4882126bc5eSKaren Xie set_wr_txq(skb, CPL_PRIORITY_DATA, csk->port_id); 4897b36b6e0Skxie@chelsio.com req->cmd = CPL_ABORT_SEND_RST; 4907b36b6e0Skxie@chelsio.com t4_set_arp_err_handler(skb, csk, abort_arp_failure); 4917b36b6e0Skxie@chelsio.com INIT_TP_WR(req, csk->tid); 4927b36b6e0Skxie@chelsio.com OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_ABORT_REQ, csk->tid)); 4937b36b6e0Skxie@chelsio.com req->rsvd0 = htonl(csk->snd_nxt); 4947b36b6e0Skxie@chelsio.com req->rsvd1 = !cxgbi_sock_flag(csk, CTPF_TX_DATA_SENT); 4957b36b6e0Skxie@chelsio.com 4967b36b6e0Skxie@chelsio.com log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK, 4977b36b6e0Skxie@chelsio.com "csk 0x%p,%u,0x%lx,%u, snd_nxt %u, 0x%x.\n", 4987b36b6e0Skxie@chelsio.com csk, csk->state, csk->flags, csk->tid, csk->snd_nxt, 4997b36b6e0Skxie@chelsio.com req->rsvd1); 5007b36b6e0Skxie@chelsio.com 5017b36b6e0Skxie@chelsio.com cxgb4_l2t_send(csk->cdev->ports[csk->port_id], skb, csk->l2t); 5027b36b6e0Skxie@chelsio.com } 5037b36b6e0Skxie@chelsio.com 5047b36b6e0Skxie@chelsio.com static void send_abort_rpl(struct cxgbi_sock *csk, int rst_status) 5057b36b6e0Skxie@chelsio.com { 5067b36b6e0Skxie@chelsio.com struct sk_buff *skb = csk->cpl_abort_rpl; 5077b36b6e0Skxie@chelsio.com struct cpl_abort_rpl *rpl = (struct cpl_abort_rpl *)skb->head; 5087b36b6e0Skxie@chelsio.com 5097b36b6e0Skxie@chelsio.com log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK, 5107b36b6e0Skxie@chelsio.com "csk 0x%p,%u,0x%lx,%u, status %d.\n", 5117b36b6e0Skxie@chelsio.com csk, csk->state, csk->flags, csk->tid, rst_status); 5127b36b6e0Skxie@chelsio.com 5137b36b6e0Skxie@chelsio.com csk->cpl_abort_rpl = NULL; 5142126bc5eSKaren Xie set_wr_txq(skb, CPL_PRIORITY_DATA, csk->port_id); 5157b36b6e0Skxie@chelsio.com INIT_TP_WR(rpl, csk->tid); 5167b36b6e0Skxie@chelsio.com OPCODE_TID(rpl) = cpu_to_be32(MK_OPCODE_TID(CPL_ABORT_RPL, csk->tid)); 5177b36b6e0Skxie@chelsio.com rpl->cmd = rst_status; 5187b36b6e0Skxie@chelsio.com cxgb4_ofld_send(csk->cdev->ports[csk->port_id], skb); 5197b36b6e0Skxie@chelsio.com } 5207b36b6e0Skxie@chelsio.com 5217b36b6e0Skxie@chelsio.com /* 5227b36b6e0Skxie@chelsio.com * CPL connection rx data ack: host -> 5237b36b6e0Skxie@chelsio.com * Send RX credits through an RX_DATA_ACK CPL message. Returns the number of 5247b36b6e0Skxie@chelsio.com * credits sent. 5257b36b6e0Skxie@chelsio.com */ 5267b36b6e0Skxie@chelsio.com static u32 send_rx_credits(struct cxgbi_sock *csk, u32 credits) 5277b36b6e0Skxie@chelsio.com { 5287b36b6e0Skxie@chelsio.com struct sk_buff *skb; 5297b36b6e0Skxie@chelsio.com struct cpl_rx_data_ack *req; 5307b36b6e0Skxie@chelsio.com 5317b36b6e0Skxie@chelsio.com log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_PDU_RX, 5327b36b6e0Skxie@chelsio.com "csk 0x%p,%u,0x%lx,%u, credit %u.\n", 5337b36b6e0Skxie@chelsio.com csk, csk->state, csk->flags, csk->tid, credits); 5347b36b6e0Skxie@chelsio.com 53524d3f95aSkxie@chelsio.com skb = alloc_wr(sizeof(*req), 0, GFP_ATOMIC); 5367b36b6e0Skxie@chelsio.com if (!skb) { 5377b36b6e0Skxie@chelsio.com pr_info("csk 0x%p, credit %u, OOM.\n", csk, credits); 5387b36b6e0Skxie@chelsio.com return 0; 5397b36b6e0Skxie@chelsio.com } 5407b36b6e0Skxie@chelsio.com req = (struct cpl_rx_data_ack *)skb->head; 5417b36b6e0Skxie@chelsio.com 5427b36b6e0Skxie@chelsio.com set_wr_txq(skb, CPL_PRIORITY_ACK, csk->port_id); 5437b36b6e0Skxie@chelsio.com INIT_TP_WR(req, csk->tid); 5447b36b6e0Skxie@chelsio.com OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_RX_DATA_ACK, 5457b36b6e0Skxie@chelsio.com csk->tid)); 546d7990b0cSAnish Bhatt req->credit_dack = cpu_to_be32(RX_CREDITS_V(credits) 547d7990b0cSAnish Bhatt | RX_FORCE_ACK_F); 5487b36b6e0Skxie@chelsio.com cxgb4_ofld_send(csk->cdev->ports[csk->port_id], skb); 5497b36b6e0Skxie@chelsio.com return credits; 5507b36b6e0Skxie@chelsio.com } 5517b36b6e0Skxie@chelsio.com 5527b36b6e0Skxie@chelsio.com /* 5537b36b6e0Skxie@chelsio.com * sgl_len - calculates the size of an SGL of the given capacity 5547b36b6e0Skxie@chelsio.com * @n: the number of SGL entries 5557b36b6e0Skxie@chelsio.com * Calculates the number of flits needed for a scatter/gather list that 5567b36b6e0Skxie@chelsio.com * can hold the given number of entries. 5577b36b6e0Skxie@chelsio.com */ 5587b36b6e0Skxie@chelsio.com static inline unsigned int sgl_len(unsigned int n) 5597b36b6e0Skxie@chelsio.com { 5607b36b6e0Skxie@chelsio.com n--; 5617b36b6e0Skxie@chelsio.com return (3 * n) / 2 + (n & 1) + 2; 5627b36b6e0Skxie@chelsio.com } 5637b36b6e0Skxie@chelsio.com 5647b36b6e0Skxie@chelsio.com /* 5657b36b6e0Skxie@chelsio.com * calc_tx_flits_ofld - calculate # of flits for an offload packet 5667b36b6e0Skxie@chelsio.com * @skb: the packet 5677b36b6e0Skxie@chelsio.com * 5687b36b6e0Skxie@chelsio.com * Returns the number of flits needed for the given offload packet. 5697b36b6e0Skxie@chelsio.com * These packets are already fully constructed and no additional headers 5707b36b6e0Skxie@chelsio.com * will be added. 5717b36b6e0Skxie@chelsio.com */ 5727b36b6e0Skxie@chelsio.com static inline unsigned int calc_tx_flits_ofld(const struct sk_buff *skb) 5737b36b6e0Skxie@chelsio.com { 5747b36b6e0Skxie@chelsio.com unsigned int flits, cnt; 5757b36b6e0Skxie@chelsio.com 5767b36b6e0Skxie@chelsio.com if (is_ofld_imm(skb)) 5777b36b6e0Skxie@chelsio.com return DIV_ROUND_UP(skb->len, 8); 5787b36b6e0Skxie@chelsio.com flits = skb_transport_offset(skb) / 8; 5797b36b6e0Skxie@chelsio.com cnt = skb_shinfo(skb)->nr_frags; 580499e2e6fSIsaku Yamahata if (skb_tail_pointer(skb) != skb_transport_header(skb)) 5817b36b6e0Skxie@chelsio.com cnt++; 5827b36b6e0Skxie@chelsio.com return flits + sgl_len(cnt); 5837b36b6e0Skxie@chelsio.com } 5847b36b6e0Skxie@chelsio.com 58564bfead8SKaren Xie #define FLOWC_WR_NPARAMS_MIN 9 58664bfead8SKaren Xie static inline int tx_flowc_wr_credits(int *nparamsp, int *flowclenp) 58764bfead8SKaren Xie { 58864bfead8SKaren Xie int nparams, flowclen16, flowclen; 58964bfead8SKaren Xie 59064bfead8SKaren Xie nparams = FLOWC_WR_NPARAMS_MIN; 591b5a5fe4eSVarun Prakash #ifdef CONFIG_CHELSIO_T4_DCB 592b5a5fe4eSVarun Prakash nparams++; 593b5a5fe4eSVarun Prakash #endif 59464bfead8SKaren Xie flowclen = offsetof(struct fw_flowc_wr, mnemval[nparams]); 59564bfead8SKaren Xie flowclen16 = DIV_ROUND_UP(flowclen, 16); 59664bfead8SKaren Xie flowclen = flowclen16 * 16; 59764bfead8SKaren Xie /* 59864bfead8SKaren Xie * Return the number of 16-byte credits used by the FlowC request. 59964bfead8SKaren Xie * Pass back the nparams and actual FlowC length if requested. 60064bfead8SKaren Xie */ 60164bfead8SKaren Xie if (nparamsp) 60264bfead8SKaren Xie *nparamsp = nparams; 60364bfead8SKaren Xie if (flowclenp) 60464bfead8SKaren Xie *flowclenp = flowclen; 60564bfead8SKaren Xie 60664bfead8SKaren Xie return flowclen16; 60764bfead8SKaren Xie } 60864bfead8SKaren Xie 60964bfead8SKaren Xie static inline int send_tx_flowc_wr(struct cxgbi_sock *csk) 6107b36b6e0Skxie@chelsio.com { 6117b36b6e0Skxie@chelsio.com struct sk_buff *skb; 6127b36b6e0Skxie@chelsio.com struct fw_flowc_wr *flowc; 61364bfead8SKaren Xie int nparams, flowclen16, flowclen; 6147b36b6e0Skxie@chelsio.com 615b5a5fe4eSVarun Prakash #ifdef CONFIG_CHELSIO_T4_DCB 616b5a5fe4eSVarun Prakash u16 vlan = ((struct l2t_entry *)csk->l2t)->vlan; 617b5a5fe4eSVarun Prakash #endif 61864bfead8SKaren Xie flowclen16 = tx_flowc_wr_credits(&nparams, &flowclen); 61924d3f95aSkxie@chelsio.com skb = alloc_wr(flowclen, 0, GFP_ATOMIC); 6207b36b6e0Skxie@chelsio.com flowc = (struct fw_flowc_wr *)skb->head; 6217b36b6e0Skxie@chelsio.com flowc->op_to_nparams = 62264bfead8SKaren Xie htonl(FW_WR_OP_V(FW_FLOWC_WR) | FW_FLOWC_WR_NPARAMS_V(nparams)); 6237b36b6e0Skxie@chelsio.com flowc->flowid_len16 = 62464bfead8SKaren Xie htonl(FW_WR_LEN16_V(flowclen16) | FW_WR_FLOWID_V(csk->tid)); 6257b36b6e0Skxie@chelsio.com flowc->mnemval[0].mnemonic = FW_FLOWC_MNEM_PFNVFN; 626e27d6169Skxie@chelsio.com flowc->mnemval[0].val = htonl(csk->cdev->pfvf); 6277b36b6e0Skxie@chelsio.com flowc->mnemval[1].mnemonic = FW_FLOWC_MNEM_CH; 6287b36b6e0Skxie@chelsio.com flowc->mnemval[1].val = htonl(csk->tx_chan); 6297b36b6e0Skxie@chelsio.com flowc->mnemval[2].mnemonic = FW_FLOWC_MNEM_PORT; 6307b36b6e0Skxie@chelsio.com flowc->mnemval[2].val = htonl(csk->tx_chan); 6317b36b6e0Skxie@chelsio.com flowc->mnemval[3].mnemonic = FW_FLOWC_MNEM_IQID; 6327b36b6e0Skxie@chelsio.com flowc->mnemval[3].val = htonl(csk->rss_qid); 6337b36b6e0Skxie@chelsio.com flowc->mnemval[4].mnemonic = FW_FLOWC_MNEM_SNDNXT; 6347b36b6e0Skxie@chelsio.com flowc->mnemval[4].val = htonl(csk->snd_nxt); 6357b36b6e0Skxie@chelsio.com flowc->mnemval[5].mnemonic = FW_FLOWC_MNEM_RCVNXT; 6367b36b6e0Skxie@chelsio.com flowc->mnemval[5].val = htonl(csk->rcv_nxt); 6377b36b6e0Skxie@chelsio.com flowc->mnemval[6].mnemonic = FW_FLOWC_MNEM_SNDBUF; 63881daf10cSKaren Xie flowc->mnemval[6].val = htonl(csk->snd_win); 6397b36b6e0Skxie@chelsio.com flowc->mnemval[7].mnemonic = FW_FLOWC_MNEM_MSS; 6407b36b6e0Skxie@chelsio.com flowc->mnemval[7].val = htonl(csk->advmss); 6417b36b6e0Skxie@chelsio.com flowc->mnemval[8].mnemonic = 0; 6427b36b6e0Skxie@chelsio.com flowc->mnemval[8].val = 0; 64364bfead8SKaren Xie flowc->mnemval[8].mnemonic = FW_FLOWC_MNEM_TXDATAPLEN_MAX; 64464bfead8SKaren Xie flowc->mnemval[8].val = 16384; 645b5a5fe4eSVarun Prakash #ifdef CONFIG_CHELSIO_T4_DCB 646b5a5fe4eSVarun Prakash flowc->mnemval[9].mnemonic = FW_FLOWC_MNEM_DCBPRIO; 647b5a5fe4eSVarun Prakash if (vlan == CPL_L2T_VLAN_NONE) { 648b5a5fe4eSVarun Prakash pr_warn_ratelimited("csk %u without VLAN Tag on DCB Link\n", 649b5a5fe4eSVarun Prakash csk->tid); 650b5a5fe4eSVarun Prakash flowc->mnemval[9].val = cpu_to_be32(0); 651b5a5fe4eSVarun Prakash } else { 652b5a5fe4eSVarun Prakash flowc->mnemval[9].val = cpu_to_be32((vlan & VLAN_PRIO_MASK) >> 653b5a5fe4eSVarun Prakash VLAN_PRIO_SHIFT); 654b5a5fe4eSVarun Prakash } 655b5a5fe4eSVarun Prakash #endif 65664bfead8SKaren Xie 6572126bc5eSKaren Xie set_wr_txq(skb, CPL_PRIORITY_DATA, csk->port_id); 6587b36b6e0Skxie@chelsio.com 6597b36b6e0Skxie@chelsio.com log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK, 6607b36b6e0Skxie@chelsio.com "csk 0x%p, tid 0x%x, %u,%u,%u,%u,%u,%u,%u.\n", 6617b36b6e0Skxie@chelsio.com csk, csk->tid, 0, csk->tx_chan, csk->rss_qid, 66281daf10cSKaren Xie csk->snd_nxt, csk->rcv_nxt, csk->snd_win, 6637b36b6e0Skxie@chelsio.com csk->advmss); 6647b36b6e0Skxie@chelsio.com 6657b36b6e0Skxie@chelsio.com cxgb4_ofld_send(csk->cdev->ports[csk->port_id], skb); 66664bfead8SKaren Xie 66764bfead8SKaren Xie return flowclen16; 6687b36b6e0Skxie@chelsio.com } 6697b36b6e0Skxie@chelsio.com 6707b36b6e0Skxie@chelsio.com static inline void make_tx_data_wr(struct cxgbi_sock *csk, struct sk_buff *skb, 6717b36b6e0Skxie@chelsio.com int dlen, int len, u32 credits, int compl) 6727b36b6e0Skxie@chelsio.com { 6737b36b6e0Skxie@chelsio.com struct fw_ofld_tx_data_wr *req; 6747b36b6e0Skxie@chelsio.com unsigned int submode = cxgbi_skcb_ulp_mode(skb) & 3; 675e2ac9628SHariprasad Shenai unsigned int wr_ulp_mode = 0, val; 6767857c62aSKaren Xie bool imm = is_ofld_imm(skb); 6777b36b6e0Skxie@chelsio.com 678d58ff351SJohannes Berg req = __skb_push(skb, sizeof(*req)); 6797b36b6e0Skxie@chelsio.com 6807857c62aSKaren Xie if (imm) { 681e2ac9628SHariprasad Shenai req->op_to_immdlen = htonl(FW_WR_OP_V(FW_OFLD_TX_DATA_WR) | 682e2ac9628SHariprasad Shenai FW_WR_COMPL_F | 683e2ac9628SHariprasad Shenai FW_WR_IMMDLEN_V(dlen)); 684e2ac9628SHariprasad Shenai req->flowid_len16 = htonl(FW_WR_FLOWID_V(csk->tid) | 685e2ac9628SHariprasad Shenai FW_WR_LEN16_V(credits)); 6867b36b6e0Skxie@chelsio.com } else { 6877b36b6e0Skxie@chelsio.com req->op_to_immdlen = 688e2ac9628SHariprasad Shenai cpu_to_be32(FW_WR_OP_V(FW_OFLD_TX_DATA_WR) | 689e2ac9628SHariprasad Shenai FW_WR_COMPL_F | 690e2ac9628SHariprasad Shenai FW_WR_IMMDLEN_V(0)); 6917b36b6e0Skxie@chelsio.com req->flowid_len16 = 692e2ac9628SHariprasad Shenai cpu_to_be32(FW_WR_FLOWID_V(csk->tid) | 693e2ac9628SHariprasad Shenai FW_WR_LEN16_V(credits)); 6947b36b6e0Skxie@chelsio.com } 6957b36b6e0Skxie@chelsio.com if (submode) 696e2ac9628SHariprasad Shenai wr_ulp_mode = FW_OFLD_TX_DATA_WR_ULPMODE_V(ULP2_MODE_ISCSI) | 697e2ac9628SHariprasad Shenai FW_OFLD_TX_DATA_WR_ULPSUBMODE_V(submode); 698e2ac9628SHariprasad Shenai val = skb_peek(&csk->write_queue) ? 0 : 1; 6996aca4112SKaren Xie req->tunnel_to_proxy = htonl(wr_ulp_mode | 700e2ac9628SHariprasad Shenai FW_OFLD_TX_DATA_WR_SHOVE_V(val)); 7017b36b6e0Skxie@chelsio.com req->plen = htonl(len); 7027b36b6e0Skxie@chelsio.com if (!cxgbi_sock_flag(csk, CTPF_TX_DATA_SENT)) 7037b36b6e0Skxie@chelsio.com cxgbi_sock_set_flag(csk, CTPF_TX_DATA_SENT); 7047b36b6e0Skxie@chelsio.com } 7057b36b6e0Skxie@chelsio.com 7067b36b6e0Skxie@chelsio.com static void arp_failure_skb_discard(void *handle, struct sk_buff *skb) 7077b36b6e0Skxie@chelsio.com { 7087b36b6e0Skxie@chelsio.com kfree_skb(skb); 7097b36b6e0Skxie@chelsio.com } 7107b36b6e0Skxie@chelsio.com 7117b36b6e0Skxie@chelsio.com static int push_tx_frames(struct cxgbi_sock *csk, int req_completion) 7127b36b6e0Skxie@chelsio.com { 7137b36b6e0Skxie@chelsio.com int total_size = 0; 7147b36b6e0Skxie@chelsio.com struct sk_buff *skb; 7157b36b6e0Skxie@chelsio.com 7167b36b6e0Skxie@chelsio.com if (unlikely(csk->state < CTP_ESTABLISHED || 7177b36b6e0Skxie@chelsio.com csk->state == CTP_CLOSE_WAIT_1 || csk->state >= CTP_ABORTING)) { 7187b36b6e0Skxie@chelsio.com log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK | 7197b36b6e0Skxie@chelsio.com 1 << CXGBI_DBG_PDU_TX, 7207b36b6e0Skxie@chelsio.com "csk 0x%p,%u,0x%lx,%u, in closing state.\n", 7217b36b6e0Skxie@chelsio.com csk, csk->state, csk->flags, csk->tid); 7227b36b6e0Skxie@chelsio.com return 0; 7237b36b6e0Skxie@chelsio.com } 7247b36b6e0Skxie@chelsio.com 7257b36b6e0Skxie@chelsio.com while (csk->wr_cred && (skb = skb_peek(&csk->write_queue)) != NULL) { 7267b36b6e0Skxie@chelsio.com int dlen = skb->len; 7277b36b6e0Skxie@chelsio.com int len = skb->len; 7287b36b6e0Skxie@chelsio.com unsigned int credits_needed; 72964bfead8SKaren Xie int flowclen16 = 0; 7307b36b6e0Skxie@chelsio.com 7317b36b6e0Skxie@chelsio.com skb_reset_transport_header(skb); 7327b36b6e0Skxie@chelsio.com if (is_ofld_imm(skb)) 73384944d8cSKaren Xie credits_needed = DIV_ROUND_UP(dlen, 16); 7347b36b6e0Skxie@chelsio.com else 73584944d8cSKaren Xie credits_needed = DIV_ROUND_UP( 73684944d8cSKaren Xie 8 * calc_tx_flits_ofld(skb), 73784944d8cSKaren Xie 16); 73884944d8cSKaren Xie 73984944d8cSKaren Xie if (likely(cxgbi_skcb_test_flag(skb, SKCBF_TX_NEED_HDR))) 74084944d8cSKaren Xie credits_needed += DIV_ROUND_UP( 74184944d8cSKaren Xie sizeof(struct fw_ofld_tx_data_wr), 7427b36b6e0Skxie@chelsio.com 16); 7437b36b6e0Skxie@chelsio.com 74464bfead8SKaren Xie /* 74564bfead8SKaren Xie * Assumes the initial credits is large enough to support 74664bfead8SKaren Xie * fw_flowc_wr plus largest possible first payload 74764bfead8SKaren Xie */ 74864bfead8SKaren Xie if (!cxgbi_sock_flag(csk, CTPF_TX_DATA_SENT)) { 74964bfead8SKaren Xie flowclen16 = send_tx_flowc_wr(csk); 75064bfead8SKaren Xie csk->wr_cred -= flowclen16; 75164bfead8SKaren Xie csk->wr_una_cred += flowclen16; 75264bfead8SKaren Xie cxgbi_sock_set_flag(csk, CTPF_TX_DATA_SENT); 75364bfead8SKaren Xie } 75464bfead8SKaren Xie 7557b36b6e0Skxie@chelsio.com if (csk->wr_cred < credits_needed) { 7567b36b6e0Skxie@chelsio.com log_debug(1 << CXGBI_DBG_PDU_TX, 7577b36b6e0Skxie@chelsio.com "csk 0x%p, skb %u/%u, wr %d < %u.\n", 7587b36b6e0Skxie@chelsio.com csk, skb->len, skb->data_len, 7597b36b6e0Skxie@chelsio.com credits_needed, csk->wr_cred); 7607b36b6e0Skxie@chelsio.com break; 7617b36b6e0Skxie@chelsio.com } 7627b36b6e0Skxie@chelsio.com __skb_unlink(skb, &csk->write_queue); 7632126bc5eSKaren Xie set_wr_txq(skb, CPL_PRIORITY_DATA, csk->port_id); 76464bfead8SKaren Xie skb->csum = credits_needed + flowclen16; 7657b36b6e0Skxie@chelsio.com csk->wr_cred -= credits_needed; 7667b36b6e0Skxie@chelsio.com csk->wr_una_cred += credits_needed; 7677b36b6e0Skxie@chelsio.com cxgbi_sock_enqueue_wr(csk, skb); 7687b36b6e0Skxie@chelsio.com 7697b36b6e0Skxie@chelsio.com log_debug(1 << CXGBI_DBG_PDU_TX, 7707b36b6e0Skxie@chelsio.com "csk 0x%p, skb %u/%u, wr %d, left %u, unack %u.\n", 7717b36b6e0Skxie@chelsio.com csk, skb->len, skb->data_len, credits_needed, 7727b36b6e0Skxie@chelsio.com csk->wr_cred, csk->wr_una_cred); 7737b36b6e0Skxie@chelsio.com 7747b36b6e0Skxie@chelsio.com if (likely(cxgbi_skcb_test_flag(skb, SKCBF_TX_NEED_HDR))) { 7757b36b6e0Skxie@chelsio.com len += cxgbi_ulp_extra_len(cxgbi_skcb_ulp_mode(skb)); 7767b36b6e0Skxie@chelsio.com make_tx_data_wr(csk, skb, dlen, len, credits_needed, 7777b36b6e0Skxie@chelsio.com req_completion); 7787b36b6e0Skxie@chelsio.com csk->snd_nxt += len; 7797b36b6e0Skxie@chelsio.com cxgbi_skcb_clear_flag(skb, SKCBF_TX_NEED_HDR); 780fe9b34bfSVarun Prakash } else if (cxgbi_skcb_test_flag(skb, SKCBF_TX_FLAG_COMPL) && 781fe9b34bfSVarun Prakash (csk->wr_una_cred >= (csk->wr_max_cred / 2))) { 782fe9b34bfSVarun Prakash struct cpl_close_con_req *req = 783fe9b34bfSVarun Prakash (struct cpl_close_con_req *)skb->data; 784fe9b34bfSVarun Prakash req->wr.wr_hi |= htonl(FW_WR_COMPL_F); 7857b36b6e0Skxie@chelsio.com } 7867b36b6e0Skxie@chelsio.com total_size += skb->truesize; 7877b36b6e0Skxie@chelsio.com t4_set_arp_err_handler(skb, csk, arp_failure_skb_discard); 7887b36b6e0Skxie@chelsio.com 7897b36b6e0Skxie@chelsio.com log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_PDU_TX, 7907b36b6e0Skxie@chelsio.com "csk 0x%p,%u,0x%lx,%u, skb 0x%p, %u.\n", 7917b36b6e0Skxie@chelsio.com csk, csk->state, csk->flags, csk->tid, skb, len); 7927b36b6e0Skxie@chelsio.com 7937b36b6e0Skxie@chelsio.com cxgb4_l2t_send(csk->cdev->ports[csk->port_id], skb, csk->l2t); 7947b36b6e0Skxie@chelsio.com } 7957b36b6e0Skxie@chelsio.com return total_size; 7967b36b6e0Skxie@chelsio.com } 7977b36b6e0Skxie@chelsio.com 7987b36b6e0Skxie@chelsio.com static inline void free_atid(struct cxgbi_sock *csk) 7997b36b6e0Skxie@chelsio.com { 8007b36b6e0Skxie@chelsio.com struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(csk->cdev); 8017b36b6e0Skxie@chelsio.com 8027b36b6e0Skxie@chelsio.com if (cxgbi_sock_flag(csk, CTPF_HAS_ATID)) { 8037b36b6e0Skxie@chelsio.com cxgb4_free_atid(lldi->tids, csk->atid); 8047b36b6e0Skxie@chelsio.com cxgbi_sock_clear_flag(csk, CTPF_HAS_ATID); 8057b36b6e0Skxie@chelsio.com cxgbi_sock_put(csk); 8067b36b6e0Skxie@chelsio.com } 8077b36b6e0Skxie@chelsio.com } 8087b36b6e0Skxie@chelsio.com 8097b36b6e0Skxie@chelsio.com static void do_act_establish(struct cxgbi_device *cdev, struct sk_buff *skb) 8107b36b6e0Skxie@chelsio.com { 8117b36b6e0Skxie@chelsio.com struct cxgbi_sock *csk; 8127b36b6e0Skxie@chelsio.com struct cpl_act_establish *req = (struct cpl_act_establish *)skb->data; 8137b36b6e0Skxie@chelsio.com unsigned short tcp_opt = ntohs(req->tcp_opt); 8147b36b6e0Skxie@chelsio.com unsigned int tid = GET_TID(req); 8156c53e938SHariprasad Shenai unsigned int atid = TID_TID_G(ntohl(req->tos_atid)); 8167b36b6e0Skxie@chelsio.com struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(cdev); 8177b36b6e0Skxie@chelsio.com struct tid_info *t = lldi->tids; 8187b36b6e0Skxie@chelsio.com u32 rcv_isn = be32_to_cpu(req->rcv_isn); 8197b36b6e0Skxie@chelsio.com 8207b36b6e0Skxie@chelsio.com csk = lookup_atid(t, atid); 8217b36b6e0Skxie@chelsio.com if (unlikely(!csk)) { 8227b36b6e0Skxie@chelsio.com pr_err("NO conn. for atid %u, cdev 0x%p.\n", atid, cdev); 8237b36b6e0Skxie@chelsio.com goto rel_skb; 8247b36b6e0Skxie@chelsio.com } 8257b36b6e0Skxie@chelsio.com 826e27d6169Skxie@chelsio.com if (csk->atid != atid) { 827e27d6169Skxie@chelsio.com pr_err("bad conn atid %u, csk 0x%p,%u,0x%lx,tid %u, atid %u.\n", 828e27d6169Skxie@chelsio.com atid, csk, csk->state, csk->flags, csk->tid, csk->atid); 829e27d6169Skxie@chelsio.com goto rel_skb; 830e27d6169Skxie@chelsio.com } 831e27d6169Skxie@chelsio.com 832759a0cc5SAnish Bhatt pr_info_ipaddr("atid 0x%x, tid 0x%x, csk 0x%p,%u,0x%lx, isn %u.\n", 833759a0cc5SAnish Bhatt (&csk->saddr), (&csk->daddr), 834759a0cc5SAnish Bhatt atid, tid, csk, csk->state, csk->flags, rcv_isn); 835759a0cc5SAnish Bhatt 8361fe1fdb0SVarun Prakash module_put(cdev->owner); 8377b36b6e0Skxie@chelsio.com 8387b36b6e0Skxie@chelsio.com cxgbi_sock_get(csk); 8397b36b6e0Skxie@chelsio.com csk->tid = tid; 8401dec4cecSGanesh Goudar cxgb4_insert_tid(lldi->tids, csk, tid, csk->csk_family); 8417b36b6e0Skxie@chelsio.com cxgbi_sock_set_flag(csk, CTPF_HAS_TID); 8427b36b6e0Skxie@chelsio.com 8437b36b6e0Skxie@chelsio.com free_atid(csk); 8447b36b6e0Skxie@chelsio.com 8457b36b6e0Skxie@chelsio.com spin_lock_bh(&csk->lock); 8467b36b6e0Skxie@chelsio.com if (unlikely(csk->state != CTP_ACTIVE_OPEN)) 8477b36b6e0Skxie@chelsio.com pr_info("csk 0x%p,%u,0x%lx,%u, got EST.\n", 8487b36b6e0Skxie@chelsio.com csk, csk->state, csk->flags, csk->tid); 8497b36b6e0Skxie@chelsio.com 8507b36b6e0Skxie@chelsio.com if (csk->retry_timer.function) { 8517b36b6e0Skxie@chelsio.com del_timer(&csk->retry_timer); 8527b36b6e0Skxie@chelsio.com csk->retry_timer.function = NULL; 8537b36b6e0Skxie@chelsio.com } 8547b36b6e0Skxie@chelsio.com 8557b36b6e0Skxie@chelsio.com csk->copied_seq = csk->rcv_wup = csk->rcv_nxt = rcv_isn; 8567b36b6e0Skxie@chelsio.com /* 8577b36b6e0Skxie@chelsio.com * Causes the first RX_DATA_ACK to supply any Rx credits we couldn't 8587b36b6e0Skxie@chelsio.com * pass through opt0. 8597b36b6e0Skxie@chelsio.com */ 86081daf10cSKaren Xie if (csk->rcv_win > (RCV_BUFSIZ_MASK << 10)) 86181daf10cSKaren Xie csk->rcv_wup -= csk->rcv_win - (RCV_BUFSIZ_MASK << 10); 8627b36b6e0Skxie@chelsio.com 8636c53e938SHariprasad Shenai csk->advmss = lldi->mtus[TCPOPT_MSS_G(tcp_opt)] - 40; 8646c53e938SHariprasad Shenai if (TCPOPT_TSTAMP_G(tcp_opt)) 8657b36b6e0Skxie@chelsio.com csk->advmss -= 12; 8667b36b6e0Skxie@chelsio.com if (csk->advmss < 128) 8677b36b6e0Skxie@chelsio.com csk->advmss = 128; 8687b36b6e0Skxie@chelsio.com 8697b36b6e0Skxie@chelsio.com log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK, 8707b36b6e0Skxie@chelsio.com "csk 0x%p, mss_idx %u, advmss %u.\n", 8716c53e938SHariprasad Shenai csk, TCPOPT_MSS_G(tcp_opt), csk->advmss); 8727b36b6e0Skxie@chelsio.com 8737b36b6e0Skxie@chelsio.com cxgbi_sock_established(csk, ntohl(req->snd_isn), ntohs(req->tcp_opt)); 8747b36b6e0Skxie@chelsio.com 8757b36b6e0Skxie@chelsio.com if (unlikely(cxgbi_sock_flag(csk, CTPF_ACTIVE_CLOSE_NEEDED))) 8767b36b6e0Skxie@chelsio.com send_abort_req(csk); 8777b36b6e0Skxie@chelsio.com else { 8787b36b6e0Skxie@chelsio.com if (skb_queue_len(&csk->write_queue)) 8797b36b6e0Skxie@chelsio.com push_tx_frames(csk, 0); 8807b36b6e0Skxie@chelsio.com cxgbi_conn_tx_open(csk); 8817b36b6e0Skxie@chelsio.com } 8827b36b6e0Skxie@chelsio.com spin_unlock_bh(&csk->lock); 8837b36b6e0Skxie@chelsio.com 8847b36b6e0Skxie@chelsio.com rel_skb: 8857b36b6e0Skxie@chelsio.com __kfree_skb(skb); 8867b36b6e0Skxie@chelsio.com } 8877b36b6e0Skxie@chelsio.com 8887b36b6e0Skxie@chelsio.com static int act_open_rpl_status_to_errno(int status) 8897b36b6e0Skxie@chelsio.com { 8907b36b6e0Skxie@chelsio.com switch (status) { 8917b36b6e0Skxie@chelsio.com case CPL_ERR_CONN_RESET: 8927b36b6e0Skxie@chelsio.com return -ECONNREFUSED; 8937b36b6e0Skxie@chelsio.com case CPL_ERR_ARP_MISS: 8947b36b6e0Skxie@chelsio.com return -EHOSTUNREACH; 8957b36b6e0Skxie@chelsio.com case CPL_ERR_CONN_TIMEDOUT: 8967b36b6e0Skxie@chelsio.com return -ETIMEDOUT; 8977b36b6e0Skxie@chelsio.com case CPL_ERR_TCAM_FULL: 8987b36b6e0Skxie@chelsio.com return -ENOMEM; 8997b36b6e0Skxie@chelsio.com case CPL_ERR_CONN_EXIST: 9007b36b6e0Skxie@chelsio.com return -EADDRINUSE; 9017b36b6e0Skxie@chelsio.com default: 9027b36b6e0Skxie@chelsio.com return -EIO; 9037b36b6e0Skxie@chelsio.com } 9047b36b6e0Skxie@chelsio.com } 9057b36b6e0Skxie@chelsio.com 906cd07f958SKees Cook static void csk_act_open_retry_timer(struct timer_list *t) 9077b36b6e0Skxie@chelsio.com { 908001586a7SAnish Bhatt struct sk_buff *skb = NULL; 909cd07f958SKees Cook struct cxgbi_sock *csk = from_timer(csk, t, retry_timer); 9103bd3e8bfSKaren Xie struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(csk->cdev); 911759a0cc5SAnish Bhatt void (*send_act_open_func)(struct cxgbi_sock *, struct sk_buff *, 912759a0cc5SAnish Bhatt struct l2t_entry *); 913759a0cc5SAnish Bhatt int t4 = is_t4(lldi->adapter_type), size, size6; 9147b36b6e0Skxie@chelsio.com 9157b36b6e0Skxie@chelsio.com log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK, 9167b36b6e0Skxie@chelsio.com "csk 0x%p,%u,0x%lx,%u.\n", 9177b36b6e0Skxie@chelsio.com csk, csk->state, csk->flags, csk->tid); 9187b36b6e0Skxie@chelsio.com 9197b36b6e0Skxie@chelsio.com cxgbi_sock_get(csk); 9207b36b6e0Skxie@chelsio.com spin_lock_bh(&csk->lock); 921759a0cc5SAnish Bhatt 922759a0cc5SAnish Bhatt if (t4) { 923759a0cc5SAnish Bhatt size = sizeof(struct cpl_act_open_req); 924759a0cc5SAnish Bhatt size6 = sizeof(struct cpl_act_open_req6); 925759a0cc5SAnish Bhatt } else { 926759a0cc5SAnish Bhatt size = sizeof(struct cpl_t5_act_open_req); 927759a0cc5SAnish Bhatt size6 = sizeof(struct cpl_t5_act_open_req6); 928759a0cc5SAnish Bhatt } 929759a0cc5SAnish Bhatt 930759a0cc5SAnish Bhatt if (csk->csk_family == AF_INET) { 931759a0cc5SAnish Bhatt send_act_open_func = send_act_open_req; 932759a0cc5SAnish Bhatt skb = alloc_wr(size, 0, GFP_ATOMIC); 933f42bb57cSAnish Bhatt #if IS_ENABLED(CONFIG_IPV6) 934759a0cc5SAnish Bhatt } else { 935759a0cc5SAnish Bhatt send_act_open_func = send_act_open_req6; 936759a0cc5SAnish Bhatt skb = alloc_wr(size6, 0, GFP_ATOMIC); 937f42bb57cSAnish Bhatt #endif 938759a0cc5SAnish Bhatt } 939759a0cc5SAnish Bhatt 9407b36b6e0Skxie@chelsio.com if (!skb) 9417b36b6e0Skxie@chelsio.com cxgbi_sock_fail_act_open(csk, -ENOMEM); 9427b36b6e0Skxie@chelsio.com else { 9437b36b6e0Skxie@chelsio.com skb->sk = (struct sock *)csk; 9447b36b6e0Skxie@chelsio.com t4_set_arp_err_handler(skb, csk, 9457b36b6e0Skxie@chelsio.com cxgbi_sock_act_open_req_arp_failure); 946759a0cc5SAnish Bhatt send_act_open_func(csk, skb, csk->l2t); 9477b36b6e0Skxie@chelsio.com } 948759a0cc5SAnish Bhatt 9497b36b6e0Skxie@chelsio.com spin_unlock_bh(&csk->lock); 9507b36b6e0Skxie@chelsio.com cxgbi_sock_put(csk); 951759a0cc5SAnish Bhatt 9527b36b6e0Skxie@chelsio.com } 9537b36b6e0Skxie@chelsio.com 954928567adSKaren Xie static inline bool is_neg_adv(unsigned int status) 955928567adSKaren Xie { 956928567adSKaren Xie return status == CPL_ERR_RTX_NEG_ADVICE || 957928567adSKaren Xie status == CPL_ERR_KEEPALV_NEG_ADVICE || 958928567adSKaren Xie status == CPL_ERR_PERSIST_NEG_ADVICE; 959928567adSKaren Xie } 960928567adSKaren Xie 9617b36b6e0Skxie@chelsio.com static void do_act_open_rpl(struct cxgbi_device *cdev, struct sk_buff *skb) 9627b36b6e0Skxie@chelsio.com { 9637b36b6e0Skxie@chelsio.com struct cxgbi_sock *csk; 9647b36b6e0Skxie@chelsio.com struct cpl_act_open_rpl *rpl = (struct cpl_act_open_rpl *)skb->data; 9657b36b6e0Skxie@chelsio.com unsigned int tid = GET_TID(rpl); 9667b36b6e0Skxie@chelsio.com unsigned int atid = 9676c53e938SHariprasad Shenai TID_TID_G(AOPEN_ATID_G(be32_to_cpu(rpl->atid_status))); 9686c53e938SHariprasad Shenai unsigned int status = AOPEN_STATUS_G(be32_to_cpu(rpl->atid_status)); 9697b36b6e0Skxie@chelsio.com struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(cdev); 9707b36b6e0Skxie@chelsio.com struct tid_info *t = lldi->tids; 9717b36b6e0Skxie@chelsio.com 9727b36b6e0Skxie@chelsio.com csk = lookup_atid(t, atid); 9737b36b6e0Skxie@chelsio.com if (unlikely(!csk)) { 9747b36b6e0Skxie@chelsio.com pr_err("NO matching conn. atid %u, tid %u.\n", atid, tid); 9757b36b6e0Skxie@chelsio.com goto rel_skb; 9767b36b6e0Skxie@chelsio.com } 9777b36b6e0Skxie@chelsio.com 978759a0cc5SAnish Bhatt pr_info_ipaddr("tid %u/%u, status %u.\n" 979759a0cc5SAnish Bhatt "csk 0x%p,%u,0x%lx. ", (&csk->saddr), (&csk->daddr), 980e27d6169Skxie@chelsio.com atid, tid, status, csk, csk->state, csk->flags); 9817b36b6e0Skxie@chelsio.com 982928567adSKaren Xie if (is_neg_adv(status)) 983150cca7cSKaren Xie goto rel_skb; 984150cca7cSKaren Xie 9851fe1fdb0SVarun Prakash module_put(cdev->owner); 986ee7255adSAnish Bhatt 9877b36b6e0Skxie@chelsio.com if (status && status != CPL_ERR_TCAM_FULL && 9887b36b6e0Skxie@chelsio.com status != CPL_ERR_CONN_EXIST && 9897b36b6e0Skxie@chelsio.com status != CPL_ERR_ARP_MISS) 9901dec4cecSGanesh Goudar cxgb4_remove_tid(lldi->tids, csk->port_id, GET_TID(rpl), 9911dec4cecSGanesh Goudar csk->csk_family); 9927b36b6e0Skxie@chelsio.com 9937b36b6e0Skxie@chelsio.com cxgbi_sock_get(csk); 9947b36b6e0Skxie@chelsio.com spin_lock_bh(&csk->lock); 9957b36b6e0Skxie@chelsio.com 9967b36b6e0Skxie@chelsio.com if (status == CPL_ERR_CONN_EXIST && 997841b86f3SKees Cook csk->retry_timer.function != csk_act_open_retry_timer) { 998841b86f3SKees Cook csk->retry_timer.function = csk_act_open_retry_timer; 9997b36b6e0Skxie@chelsio.com mod_timer(&csk->retry_timer, jiffies + HZ / 2); 10007b36b6e0Skxie@chelsio.com } else 10017b36b6e0Skxie@chelsio.com cxgbi_sock_fail_act_open(csk, 10027b36b6e0Skxie@chelsio.com act_open_rpl_status_to_errno(status)); 10037b36b6e0Skxie@chelsio.com 10047b36b6e0Skxie@chelsio.com spin_unlock_bh(&csk->lock); 10057b36b6e0Skxie@chelsio.com cxgbi_sock_put(csk); 10067b36b6e0Skxie@chelsio.com rel_skb: 10077b36b6e0Skxie@chelsio.com __kfree_skb(skb); 10087b36b6e0Skxie@chelsio.com } 10097b36b6e0Skxie@chelsio.com 10107b36b6e0Skxie@chelsio.com static void do_peer_close(struct cxgbi_device *cdev, struct sk_buff *skb) 10117b36b6e0Skxie@chelsio.com { 10127b36b6e0Skxie@chelsio.com struct cxgbi_sock *csk; 10137b36b6e0Skxie@chelsio.com struct cpl_peer_close *req = (struct cpl_peer_close *)skb->data; 10147b36b6e0Skxie@chelsio.com unsigned int tid = GET_TID(req); 10157b36b6e0Skxie@chelsio.com struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(cdev); 10167b36b6e0Skxie@chelsio.com struct tid_info *t = lldi->tids; 10177b36b6e0Skxie@chelsio.com 10187b36b6e0Skxie@chelsio.com csk = lookup_tid(t, tid); 10197b36b6e0Skxie@chelsio.com if (unlikely(!csk)) { 10207b36b6e0Skxie@chelsio.com pr_err("can't find connection for tid %u.\n", tid); 10217b36b6e0Skxie@chelsio.com goto rel_skb; 10227b36b6e0Skxie@chelsio.com } 1023759a0cc5SAnish Bhatt pr_info_ipaddr("csk 0x%p,%u,0x%lx,%u.\n", 1024759a0cc5SAnish Bhatt (&csk->saddr), (&csk->daddr), 10257b36b6e0Skxie@chelsio.com csk, csk->state, csk->flags, csk->tid); 10267b36b6e0Skxie@chelsio.com cxgbi_sock_rcv_peer_close(csk); 10277b36b6e0Skxie@chelsio.com rel_skb: 10287b36b6e0Skxie@chelsio.com __kfree_skb(skb); 10297b36b6e0Skxie@chelsio.com } 10307b36b6e0Skxie@chelsio.com 10317b36b6e0Skxie@chelsio.com static void do_close_con_rpl(struct cxgbi_device *cdev, struct sk_buff *skb) 10327b36b6e0Skxie@chelsio.com { 10337b36b6e0Skxie@chelsio.com struct cxgbi_sock *csk; 10347b36b6e0Skxie@chelsio.com struct cpl_close_con_rpl *rpl = (struct cpl_close_con_rpl *)skb->data; 10357b36b6e0Skxie@chelsio.com unsigned int tid = GET_TID(rpl); 10367b36b6e0Skxie@chelsio.com struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(cdev); 10377b36b6e0Skxie@chelsio.com struct tid_info *t = lldi->tids; 10387b36b6e0Skxie@chelsio.com 10397b36b6e0Skxie@chelsio.com csk = lookup_tid(t, tid); 10407b36b6e0Skxie@chelsio.com if (unlikely(!csk)) { 10417b36b6e0Skxie@chelsio.com pr_err("can't find connection for tid %u.\n", tid); 10427b36b6e0Skxie@chelsio.com goto rel_skb; 10437b36b6e0Skxie@chelsio.com } 1044759a0cc5SAnish Bhatt pr_info_ipaddr("csk 0x%p,%u,0x%lx,%u.\n", 1045759a0cc5SAnish Bhatt (&csk->saddr), (&csk->daddr), 10467b36b6e0Skxie@chelsio.com csk, csk->state, csk->flags, csk->tid); 10477b36b6e0Skxie@chelsio.com cxgbi_sock_rcv_close_conn_rpl(csk, ntohl(rpl->snd_nxt)); 10487b36b6e0Skxie@chelsio.com rel_skb: 10497b36b6e0Skxie@chelsio.com __kfree_skb(skb); 10507b36b6e0Skxie@chelsio.com } 10517b36b6e0Skxie@chelsio.com 10527b36b6e0Skxie@chelsio.com static int abort_status_to_errno(struct cxgbi_sock *csk, int abort_reason, 10537b36b6e0Skxie@chelsio.com int *need_rst) 10547b36b6e0Skxie@chelsio.com { 10557b36b6e0Skxie@chelsio.com switch (abort_reason) { 10567b36b6e0Skxie@chelsio.com case CPL_ERR_BAD_SYN: /* fall through */ 10577b36b6e0Skxie@chelsio.com case CPL_ERR_CONN_RESET: 10587b36b6e0Skxie@chelsio.com return csk->state > CTP_ESTABLISHED ? 10597b36b6e0Skxie@chelsio.com -EPIPE : -ECONNRESET; 10607b36b6e0Skxie@chelsio.com case CPL_ERR_XMIT_TIMEDOUT: 10617b36b6e0Skxie@chelsio.com case CPL_ERR_PERSIST_TIMEDOUT: 10627b36b6e0Skxie@chelsio.com case CPL_ERR_FINWAIT2_TIMEDOUT: 10637b36b6e0Skxie@chelsio.com case CPL_ERR_KEEPALIVE_TIMEDOUT: 10647b36b6e0Skxie@chelsio.com return -ETIMEDOUT; 10657b36b6e0Skxie@chelsio.com default: 10667b36b6e0Skxie@chelsio.com return -EIO; 10677b36b6e0Skxie@chelsio.com } 10687b36b6e0Skxie@chelsio.com } 10697b36b6e0Skxie@chelsio.com 10707b36b6e0Skxie@chelsio.com static void do_abort_req_rss(struct cxgbi_device *cdev, struct sk_buff *skb) 10717b36b6e0Skxie@chelsio.com { 10727b36b6e0Skxie@chelsio.com struct cxgbi_sock *csk; 10737b36b6e0Skxie@chelsio.com struct cpl_abort_req_rss *req = (struct cpl_abort_req_rss *)skb->data; 10747b36b6e0Skxie@chelsio.com unsigned int tid = GET_TID(req); 10757b36b6e0Skxie@chelsio.com struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(cdev); 10767b36b6e0Skxie@chelsio.com struct tid_info *t = lldi->tids; 10777b36b6e0Skxie@chelsio.com int rst_status = CPL_ABORT_NO_RST; 10787b36b6e0Skxie@chelsio.com 10797b36b6e0Skxie@chelsio.com csk = lookup_tid(t, tid); 10807b36b6e0Skxie@chelsio.com if (unlikely(!csk)) { 10817b36b6e0Skxie@chelsio.com pr_err("can't find connection for tid %u.\n", tid); 10827b36b6e0Skxie@chelsio.com goto rel_skb; 10837b36b6e0Skxie@chelsio.com } 10847b36b6e0Skxie@chelsio.com 1085759a0cc5SAnish Bhatt pr_info_ipaddr("csk 0x%p,%u,0x%lx,%u, status %u.\n", 1086759a0cc5SAnish Bhatt (&csk->saddr), (&csk->daddr), 10877b36b6e0Skxie@chelsio.com csk, csk->state, csk->flags, csk->tid, req->status); 10887b36b6e0Skxie@chelsio.com 1089928567adSKaren Xie if (is_neg_adv(req->status)) 10907b36b6e0Skxie@chelsio.com goto rel_skb; 10917b36b6e0Skxie@chelsio.com 10927b36b6e0Skxie@chelsio.com cxgbi_sock_get(csk); 10937b36b6e0Skxie@chelsio.com spin_lock_bh(&csk->lock); 10947b36b6e0Skxie@chelsio.com 10957b07bf24SAnish Bhatt cxgbi_sock_clear_flag(csk, CTPF_ABORT_REQ_RCVD); 10967b07bf24SAnish Bhatt 10977b07bf24SAnish Bhatt if (!cxgbi_sock_flag(csk, CTPF_TX_DATA_SENT)) { 10987b07bf24SAnish Bhatt send_tx_flowc_wr(csk); 10997b07bf24SAnish Bhatt cxgbi_sock_set_flag(csk, CTPF_TX_DATA_SENT); 11007b36b6e0Skxie@chelsio.com } 11017b36b6e0Skxie@chelsio.com 11027b07bf24SAnish Bhatt cxgbi_sock_set_flag(csk, CTPF_ABORT_REQ_RCVD); 11037b07bf24SAnish Bhatt cxgbi_sock_set_state(csk, CTP_ABORTING); 11047b07bf24SAnish Bhatt 11057b36b6e0Skxie@chelsio.com send_abort_rpl(csk, rst_status); 11067b36b6e0Skxie@chelsio.com 11077b36b6e0Skxie@chelsio.com if (!cxgbi_sock_flag(csk, CTPF_ABORT_RPL_PENDING)) { 11087b36b6e0Skxie@chelsio.com csk->err = abort_status_to_errno(csk, req->status, &rst_status); 11097b36b6e0Skxie@chelsio.com cxgbi_sock_closed(csk); 11107b36b6e0Skxie@chelsio.com } 11117b07bf24SAnish Bhatt 11127b36b6e0Skxie@chelsio.com spin_unlock_bh(&csk->lock); 11137b36b6e0Skxie@chelsio.com cxgbi_sock_put(csk); 11147b36b6e0Skxie@chelsio.com rel_skb: 11157b36b6e0Skxie@chelsio.com __kfree_skb(skb); 11167b36b6e0Skxie@chelsio.com } 11177b36b6e0Skxie@chelsio.com 11187b36b6e0Skxie@chelsio.com static void do_abort_rpl_rss(struct cxgbi_device *cdev, struct sk_buff *skb) 11197b36b6e0Skxie@chelsio.com { 11207b36b6e0Skxie@chelsio.com struct cxgbi_sock *csk; 11217b36b6e0Skxie@chelsio.com struct cpl_abort_rpl_rss *rpl = (struct cpl_abort_rpl_rss *)skb->data; 11227b36b6e0Skxie@chelsio.com unsigned int tid = GET_TID(rpl); 11237b36b6e0Skxie@chelsio.com struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(cdev); 11247b36b6e0Skxie@chelsio.com struct tid_info *t = lldi->tids; 11257b36b6e0Skxie@chelsio.com 11267b36b6e0Skxie@chelsio.com csk = lookup_tid(t, tid); 11277b36b6e0Skxie@chelsio.com if (!csk) 11287b36b6e0Skxie@chelsio.com goto rel_skb; 11297b36b6e0Skxie@chelsio.com 1130759a0cc5SAnish Bhatt if (csk) 1131759a0cc5SAnish Bhatt pr_info_ipaddr("csk 0x%p,%u,0x%lx,%u, status %u.\n", 1132759a0cc5SAnish Bhatt (&csk->saddr), (&csk->daddr), csk, 1133759a0cc5SAnish Bhatt csk->state, csk->flags, csk->tid, rpl->status); 11347b36b6e0Skxie@chelsio.com 11357b36b6e0Skxie@chelsio.com if (rpl->status == CPL_ERR_ABORT_FAILED) 11367b36b6e0Skxie@chelsio.com goto rel_skb; 11377b36b6e0Skxie@chelsio.com 11387b36b6e0Skxie@chelsio.com cxgbi_sock_rcv_abort_rpl(csk); 11397b36b6e0Skxie@chelsio.com rel_skb: 11407b36b6e0Skxie@chelsio.com __kfree_skb(skb); 11417b36b6e0Skxie@chelsio.com } 11427b36b6e0Skxie@chelsio.com 1143f7bcd2e1SKaren Xie static void do_rx_data(struct cxgbi_device *cdev, struct sk_buff *skb) 1144f7bcd2e1SKaren Xie { 1145f7bcd2e1SKaren Xie struct cxgbi_sock *csk; 1146f7bcd2e1SKaren Xie struct cpl_rx_data *cpl = (struct cpl_rx_data *)skb->data; 1147f7bcd2e1SKaren Xie unsigned int tid = GET_TID(cpl); 1148f7bcd2e1SKaren Xie struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(cdev); 1149f7bcd2e1SKaren Xie struct tid_info *t = lldi->tids; 1150f7bcd2e1SKaren Xie 1151f7bcd2e1SKaren Xie csk = lookup_tid(t, tid); 1152f7bcd2e1SKaren Xie if (!csk) { 1153f7bcd2e1SKaren Xie pr_err("can't find connection for tid %u.\n", tid); 1154f7bcd2e1SKaren Xie } else { 1155f7bcd2e1SKaren Xie /* not expecting this, reset the connection. */ 1156f7bcd2e1SKaren Xie pr_err("csk 0x%p, tid %u, rcv cpl_rx_data.\n", csk, tid); 1157f7bcd2e1SKaren Xie spin_lock_bh(&csk->lock); 1158f7bcd2e1SKaren Xie send_abort_req(csk); 1159f7bcd2e1SKaren Xie spin_unlock_bh(&csk->lock); 1160f7bcd2e1SKaren Xie } 1161f7bcd2e1SKaren Xie __kfree_skb(skb); 1162f7bcd2e1SKaren Xie } 1163f7bcd2e1SKaren Xie 11647b36b6e0Skxie@chelsio.com static void do_rx_iscsi_hdr(struct cxgbi_device *cdev, struct sk_buff *skb) 11657b36b6e0Skxie@chelsio.com { 11667b36b6e0Skxie@chelsio.com struct cxgbi_sock *csk; 11677b36b6e0Skxie@chelsio.com struct cpl_iscsi_hdr *cpl = (struct cpl_iscsi_hdr *)skb->data; 11687b36b6e0Skxie@chelsio.com unsigned short pdu_len_ddp = be16_to_cpu(cpl->pdu_len_ddp); 11697b36b6e0Skxie@chelsio.com unsigned int tid = GET_TID(cpl); 11707b36b6e0Skxie@chelsio.com struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(cdev); 11717b36b6e0Skxie@chelsio.com struct tid_info *t = lldi->tids; 11727b36b6e0Skxie@chelsio.com 11737b36b6e0Skxie@chelsio.com csk = lookup_tid(t, tid); 11747b36b6e0Skxie@chelsio.com if (unlikely(!csk)) { 11757b36b6e0Skxie@chelsio.com pr_err("can't find conn. for tid %u.\n", tid); 11767b36b6e0Skxie@chelsio.com goto rel_skb; 11777b36b6e0Skxie@chelsio.com } 11787b36b6e0Skxie@chelsio.com 11797b36b6e0Skxie@chelsio.com log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_PDU_RX, 11807b36b6e0Skxie@chelsio.com "csk 0x%p,%u,0x%lx, tid %u, skb 0x%p,%u, 0x%x.\n", 11817b36b6e0Skxie@chelsio.com csk, csk->state, csk->flags, csk->tid, skb, skb->len, 11827b36b6e0Skxie@chelsio.com pdu_len_ddp); 11837b36b6e0Skxie@chelsio.com 11847b36b6e0Skxie@chelsio.com spin_lock_bh(&csk->lock); 11857b36b6e0Skxie@chelsio.com 11867b36b6e0Skxie@chelsio.com if (unlikely(csk->state >= CTP_PASSIVE_CLOSE)) { 11877b36b6e0Skxie@chelsio.com log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK, 11887b36b6e0Skxie@chelsio.com "csk 0x%p,%u,0x%lx,%u, bad state.\n", 11897b36b6e0Skxie@chelsio.com csk, csk->state, csk->flags, csk->tid); 11907b36b6e0Skxie@chelsio.com if (csk->state != CTP_ABORTING) 11917b36b6e0Skxie@chelsio.com goto abort_conn; 11927b36b6e0Skxie@chelsio.com else 11937b36b6e0Skxie@chelsio.com goto discard; 11947b36b6e0Skxie@chelsio.com } 11957b36b6e0Skxie@chelsio.com 11967b36b6e0Skxie@chelsio.com cxgbi_skcb_tcp_seq(skb) = ntohl(cpl->seq); 1197e27d6169Skxie@chelsio.com cxgbi_skcb_flags(skb) = 0; 1198e27d6169Skxie@chelsio.com 11997b36b6e0Skxie@chelsio.com skb_reset_transport_header(skb); 12007b36b6e0Skxie@chelsio.com __skb_pull(skb, sizeof(*cpl)); 12017b36b6e0Skxie@chelsio.com __pskb_trim(skb, ntohs(cpl->len)); 12027b36b6e0Skxie@chelsio.com 12037b36b6e0Skxie@chelsio.com if (!csk->skb_ulp_lhdr) { 12047b36b6e0Skxie@chelsio.com unsigned char *bhs; 12053bd3e8bfSKaren Xie unsigned int hlen, dlen, plen; 12067b36b6e0Skxie@chelsio.com 12077b36b6e0Skxie@chelsio.com log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_PDU_RX, 12087b36b6e0Skxie@chelsio.com "csk 0x%p,%u,0x%lx, tid %u, skb 0x%p header.\n", 12097b36b6e0Skxie@chelsio.com csk, csk->state, csk->flags, csk->tid, skb); 12107b36b6e0Skxie@chelsio.com csk->skb_ulp_lhdr = skb; 1211e27d6169Skxie@chelsio.com cxgbi_skcb_set_flag(skb, SKCBF_RX_HDR); 12127b36b6e0Skxie@chelsio.com 121326af1a36SVarun Prakash if ((CHELSIO_CHIP_VERSION(lldi->adapter_type) <= CHELSIO_T5) && 121426af1a36SVarun Prakash (cxgbi_skcb_tcp_seq(skb) != csk->rcv_nxt)) { 12157b36b6e0Skxie@chelsio.com pr_info("tid %u, CPL_ISCSI_HDR, bad seq, 0x%x/0x%x.\n", 1216e27d6169Skxie@chelsio.com csk->tid, cxgbi_skcb_tcp_seq(skb), 12177b36b6e0Skxie@chelsio.com csk->rcv_nxt); 12187b36b6e0Skxie@chelsio.com goto abort_conn; 12197b36b6e0Skxie@chelsio.com } 12207b36b6e0Skxie@chelsio.com 1221e27d6169Skxie@chelsio.com bhs = skb->data; 12227b36b6e0Skxie@chelsio.com hlen = ntohs(cpl->len); 12237b36b6e0Skxie@chelsio.com dlen = ntohl(*(unsigned int *)(bhs + 4)) & 0xFFFFFF; 12247b36b6e0Skxie@chelsio.com 1225bdc590b9SHariprasad Shenai plen = ISCSI_PDU_LEN_G(pdu_len_ddp); 12263bd3e8bfSKaren Xie if (is_t4(lldi->adapter_type)) 12273bd3e8bfSKaren Xie plen -= 40; 12283bd3e8bfSKaren Xie 12293bd3e8bfSKaren Xie if ((hlen + dlen) != plen) { 12307b36b6e0Skxie@chelsio.com pr_info("tid 0x%x, CPL_ISCSI_HDR, pdu len " 12317b36b6e0Skxie@chelsio.com "mismatch %u != %u + %u, seq 0x%x.\n", 12323bd3e8bfSKaren Xie csk->tid, plen, hlen, dlen, 12333bd3e8bfSKaren Xie cxgbi_skcb_tcp_seq(skb)); 12347b36b6e0Skxie@chelsio.com goto abort_conn; 12357b36b6e0Skxie@chelsio.com } 12367b36b6e0Skxie@chelsio.com 12377b36b6e0Skxie@chelsio.com cxgbi_skcb_rx_pdulen(skb) = (hlen + dlen + 3) & (~0x3); 12387b36b6e0Skxie@chelsio.com if (dlen) 12397b36b6e0Skxie@chelsio.com cxgbi_skcb_rx_pdulen(skb) += csk->dcrc_len; 12407b36b6e0Skxie@chelsio.com csk->rcv_nxt += cxgbi_skcb_rx_pdulen(skb); 12417b36b6e0Skxie@chelsio.com 12427b36b6e0Skxie@chelsio.com log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_PDU_RX, 12437b36b6e0Skxie@chelsio.com "csk 0x%p, skb 0x%p, 0x%x,%u+%u,0x%x,0x%x.\n", 12447b36b6e0Skxie@chelsio.com csk, skb, *bhs, hlen, dlen, 12457b36b6e0Skxie@chelsio.com ntohl(*((unsigned int *)(bhs + 16))), 12467b36b6e0Skxie@chelsio.com ntohl(*((unsigned int *)(bhs + 24)))); 12477b36b6e0Skxie@chelsio.com 12487b36b6e0Skxie@chelsio.com } else { 1249e27d6169Skxie@chelsio.com struct sk_buff *lskb = csk->skb_ulp_lhdr; 12507b36b6e0Skxie@chelsio.com 1251e27d6169Skxie@chelsio.com cxgbi_skcb_set_flag(lskb, SKCBF_RX_DATA); 12527b36b6e0Skxie@chelsio.com log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_PDU_RX, 12537b36b6e0Skxie@chelsio.com "csk 0x%p,%u,0x%lx, skb 0x%p data, 0x%p.\n", 12547b36b6e0Skxie@chelsio.com csk, csk->state, csk->flags, skb, lskb); 12557b36b6e0Skxie@chelsio.com } 12567b36b6e0Skxie@chelsio.com 12577b36b6e0Skxie@chelsio.com __skb_queue_tail(&csk->receive_queue, skb); 12587b36b6e0Skxie@chelsio.com spin_unlock_bh(&csk->lock); 12597b36b6e0Skxie@chelsio.com return; 12607b36b6e0Skxie@chelsio.com 12617b36b6e0Skxie@chelsio.com abort_conn: 12627b36b6e0Skxie@chelsio.com send_abort_req(csk); 12637b36b6e0Skxie@chelsio.com discard: 12647b36b6e0Skxie@chelsio.com spin_unlock_bh(&csk->lock); 12657b36b6e0Skxie@chelsio.com rel_skb: 12667b36b6e0Skxie@chelsio.com __kfree_skb(skb); 12677b36b6e0Skxie@chelsio.com } 12687b36b6e0Skxie@chelsio.com 126944830d8fSVarun Prakash static void do_rx_iscsi_data(struct cxgbi_device *cdev, struct sk_buff *skb) 127044830d8fSVarun Prakash { 127144830d8fSVarun Prakash struct cxgbi_sock *csk; 127244830d8fSVarun Prakash struct cpl_iscsi_hdr *cpl = (struct cpl_iscsi_hdr *)skb->data; 127344830d8fSVarun Prakash struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(cdev); 127444830d8fSVarun Prakash struct tid_info *t = lldi->tids; 127544830d8fSVarun Prakash struct sk_buff *lskb; 127644830d8fSVarun Prakash u32 tid = GET_TID(cpl); 127744830d8fSVarun Prakash u16 pdu_len_ddp = be16_to_cpu(cpl->pdu_len_ddp); 127844830d8fSVarun Prakash 127944830d8fSVarun Prakash csk = lookup_tid(t, tid); 128044830d8fSVarun Prakash if (unlikely(!csk)) { 128144830d8fSVarun Prakash pr_err("can't find conn. for tid %u.\n", tid); 128244830d8fSVarun Prakash goto rel_skb; 128344830d8fSVarun Prakash } 128444830d8fSVarun Prakash 128544830d8fSVarun Prakash log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_PDU_RX, 128644830d8fSVarun Prakash "csk 0x%p,%u,0x%lx, tid %u, skb 0x%p,%u, 0x%x.\n", 128744830d8fSVarun Prakash csk, csk->state, csk->flags, csk->tid, skb, 128844830d8fSVarun Prakash skb->len, pdu_len_ddp); 128944830d8fSVarun Prakash 129044830d8fSVarun Prakash spin_lock_bh(&csk->lock); 129144830d8fSVarun Prakash 129244830d8fSVarun Prakash if (unlikely(csk->state >= CTP_PASSIVE_CLOSE)) { 129344830d8fSVarun Prakash log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK, 129444830d8fSVarun Prakash "csk 0x%p,%u,0x%lx,%u, bad state.\n", 129544830d8fSVarun Prakash csk, csk->state, csk->flags, csk->tid); 129644830d8fSVarun Prakash 129744830d8fSVarun Prakash if (csk->state != CTP_ABORTING) 129844830d8fSVarun Prakash goto abort_conn; 129944830d8fSVarun Prakash else 130044830d8fSVarun Prakash goto discard; 130144830d8fSVarun Prakash } 130244830d8fSVarun Prakash 130344830d8fSVarun Prakash cxgbi_skcb_tcp_seq(skb) = be32_to_cpu(cpl->seq); 130444830d8fSVarun Prakash cxgbi_skcb_flags(skb) = 0; 130544830d8fSVarun Prakash 130644830d8fSVarun Prakash skb_reset_transport_header(skb); 130744830d8fSVarun Prakash __skb_pull(skb, sizeof(*cpl)); 130844830d8fSVarun Prakash __pskb_trim(skb, ntohs(cpl->len)); 130944830d8fSVarun Prakash 131044830d8fSVarun Prakash if (!csk->skb_ulp_lhdr) 131144830d8fSVarun Prakash csk->skb_ulp_lhdr = skb; 131244830d8fSVarun Prakash 131344830d8fSVarun Prakash lskb = csk->skb_ulp_lhdr; 131444830d8fSVarun Prakash cxgbi_skcb_set_flag(lskb, SKCBF_RX_DATA); 131544830d8fSVarun Prakash 131644830d8fSVarun Prakash log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_PDU_RX, 131744830d8fSVarun Prakash "csk 0x%p,%u,0x%lx, skb 0x%p data, 0x%p.\n", 131844830d8fSVarun Prakash csk, csk->state, csk->flags, skb, lskb); 131944830d8fSVarun Prakash 132044830d8fSVarun Prakash __skb_queue_tail(&csk->receive_queue, skb); 132144830d8fSVarun Prakash spin_unlock_bh(&csk->lock); 132244830d8fSVarun Prakash return; 132344830d8fSVarun Prakash 132444830d8fSVarun Prakash abort_conn: 132544830d8fSVarun Prakash send_abort_req(csk); 132644830d8fSVarun Prakash discard: 132744830d8fSVarun Prakash spin_unlock_bh(&csk->lock); 132844830d8fSVarun Prakash rel_skb: 132944830d8fSVarun Prakash __kfree_skb(skb); 133044830d8fSVarun Prakash } 133144830d8fSVarun Prakash 133244830d8fSVarun Prakash static void 133344830d8fSVarun Prakash cxgb4i_process_ddpvld(struct cxgbi_sock *csk, 133444830d8fSVarun Prakash struct sk_buff *skb, u32 ddpvld) 133544830d8fSVarun Prakash { 133644830d8fSVarun Prakash if (ddpvld & (1 << CPL_RX_DDP_STATUS_HCRC_SHIFT)) { 133744830d8fSVarun Prakash pr_info("csk 0x%p, lhdr 0x%p, status 0x%x, hcrc bad 0x%lx.\n", 133844830d8fSVarun Prakash csk, skb, ddpvld, cxgbi_skcb_flags(skb)); 133944830d8fSVarun Prakash cxgbi_skcb_set_flag(skb, SKCBF_RX_HCRC_ERR); 134044830d8fSVarun Prakash } 134144830d8fSVarun Prakash 134244830d8fSVarun Prakash if (ddpvld & (1 << CPL_RX_DDP_STATUS_DCRC_SHIFT)) { 134344830d8fSVarun Prakash pr_info("csk 0x%p, lhdr 0x%p, status 0x%x, dcrc bad 0x%lx.\n", 134444830d8fSVarun Prakash csk, skb, ddpvld, cxgbi_skcb_flags(skb)); 134544830d8fSVarun Prakash cxgbi_skcb_set_flag(skb, SKCBF_RX_DCRC_ERR); 134644830d8fSVarun Prakash } 134744830d8fSVarun Prakash 134844830d8fSVarun Prakash if (ddpvld & (1 << CPL_RX_DDP_STATUS_PAD_SHIFT)) { 134944830d8fSVarun Prakash log_debug(1 << CXGBI_DBG_PDU_RX, 135044830d8fSVarun Prakash "csk 0x%p, lhdr 0x%p, status 0x%x, pad bad.\n", 135144830d8fSVarun Prakash csk, skb, ddpvld); 135244830d8fSVarun Prakash cxgbi_skcb_set_flag(skb, SKCBF_RX_PAD_ERR); 135344830d8fSVarun Prakash } 135444830d8fSVarun Prakash 135544830d8fSVarun Prakash if ((ddpvld & (1 << CPL_RX_DDP_STATUS_DDP_SHIFT)) && 135644830d8fSVarun Prakash !cxgbi_skcb_test_flag(skb, SKCBF_RX_DATA)) { 135744830d8fSVarun Prakash log_debug(1 << CXGBI_DBG_PDU_RX, 135844830d8fSVarun Prakash "csk 0x%p, lhdr 0x%p, 0x%x, data ddp'ed.\n", 135944830d8fSVarun Prakash csk, skb, ddpvld); 136044830d8fSVarun Prakash cxgbi_skcb_set_flag(skb, SKCBF_RX_DATA_DDPD); 136144830d8fSVarun Prakash } 136244830d8fSVarun Prakash } 136344830d8fSVarun Prakash 13647b36b6e0Skxie@chelsio.com static void do_rx_data_ddp(struct cxgbi_device *cdev, 13657b36b6e0Skxie@chelsio.com struct sk_buff *skb) 13667b36b6e0Skxie@chelsio.com { 13677b36b6e0Skxie@chelsio.com struct cxgbi_sock *csk; 13687b36b6e0Skxie@chelsio.com struct sk_buff *lskb; 13697b36b6e0Skxie@chelsio.com struct cpl_rx_data_ddp *rpl = (struct cpl_rx_data_ddp *)skb->data; 13707b36b6e0Skxie@chelsio.com unsigned int tid = GET_TID(rpl); 13717b36b6e0Skxie@chelsio.com struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(cdev); 13727b36b6e0Skxie@chelsio.com struct tid_info *t = lldi->tids; 137344830d8fSVarun Prakash u32 ddpvld = be32_to_cpu(rpl->ddpvld); 13747b36b6e0Skxie@chelsio.com 13757b36b6e0Skxie@chelsio.com csk = lookup_tid(t, tid); 13767b36b6e0Skxie@chelsio.com if (unlikely(!csk)) { 13777b36b6e0Skxie@chelsio.com pr_err("can't find connection for tid %u.\n", tid); 13787b36b6e0Skxie@chelsio.com goto rel_skb; 13797b36b6e0Skxie@chelsio.com } 13807b36b6e0Skxie@chelsio.com 13817b36b6e0Skxie@chelsio.com log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_PDU_RX, 13827b36b6e0Skxie@chelsio.com "csk 0x%p,%u,0x%lx, skb 0x%p,0x%x, lhdr 0x%p.\n", 138344830d8fSVarun Prakash csk, csk->state, csk->flags, skb, ddpvld, csk->skb_ulp_lhdr); 13847b36b6e0Skxie@chelsio.com 13857b36b6e0Skxie@chelsio.com spin_lock_bh(&csk->lock); 13867b36b6e0Skxie@chelsio.com 13877b36b6e0Skxie@chelsio.com if (unlikely(csk->state >= CTP_PASSIVE_CLOSE)) { 13887b36b6e0Skxie@chelsio.com log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK, 13897b36b6e0Skxie@chelsio.com "csk 0x%p,%u,0x%lx,%u, bad state.\n", 13907b36b6e0Skxie@chelsio.com csk, csk->state, csk->flags, csk->tid); 13917b36b6e0Skxie@chelsio.com if (csk->state != CTP_ABORTING) 13927b36b6e0Skxie@chelsio.com goto abort_conn; 13937b36b6e0Skxie@chelsio.com else 13947b36b6e0Skxie@chelsio.com goto discard; 13957b36b6e0Skxie@chelsio.com } 13967b36b6e0Skxie@chelsio.com 13977b36b6e0Skxie@chelsio.com if (!csk->skb_ulp_lhdr) { 13987b36b6e0Skxie@chelsio.com pr_err("tid 0x%x, rcv RX_DATA_DDP w/o pdu bhs.\n", csk->tid); 13997b36b6e0Skxie@chelsio.com goto abort_conn; 14007b36b6e0Skxie@chelsio.com } 14017b36b6e0Skxie@chelsio.com 14027b36b6e0Skxie@chelsio.com lskb = csk->skb_ulp_lhdr; 14037b36b6e0Skxie@chelsio.com csk->skb_ulp_lhdr = NULL; 14047b36b6e0Skxie@chelsio.com 14057b36b6e0Skxie@chelsio.com cxgbi_skcb_rx_ddigest(lskb) = ntohl(rpl->ulp_crc); 14067b36b6e0Skxie@chelsio.com 14077b36b6e0Skxie@chelsio.com if (ntohs(rpl->len) != cxgbi_skcb_rx_pdulen(lskb)) 14087b36b6e0Skxie@chelsio.com pr_info("tid 0x%x, RX_DATA_DDP pdulen %u != %u.\n", 14097b36b6e0Skxie@chelsio.com csk->tid, ntohs(rpl->len), cxgbi_skcb_rx_pdulen(lskb)); 14107b36b6e0Skxie@chelsio.com 141144830d8fSVarun Prakash cxgb4i_process_ddpvld(csk, lskb, ddpvld); 141244830d8fSVarun Prakash 14137b36b6e0Skxie@chelsio.com log_debug(1 << CXGBI_DBG_PDU_RX, 14147b36b6e0Skxie@chelsio.com "csk 0x%p, lskb 0x%p, f 0x%lx.\n", 14157b36b6e0Skxie@chelsio.com csk, lskb, cxgbi_skcb_flags(lskb)); 14167b36b6e0Skxie@chelsio.com 1417e27d6169Skxie@chelsio.com cxgbi_skcb_set_flag(lskb, SKCBF_RX_STATUS); 14187b36b6e0Skxie@chelsio.com cxgbi_conn_pdu_ready(csk); 14197b36b6e0Skxie@chelsio.com spin_unlock_bh(&csk->lock); 14207b36b6e0Skxie@chelsio.com goto rel_skb; 14217b36b6e0Skxie@chelsio.com 14227b36b6e0Skxie@chelsio.com abort_conn: 14237b36b6e0Skxie@chelsio.com send_abort_req(csk); 14247b36b6e0Skxie@chelsio.com discard: 14257b36b6e0Skxie@chelsio.com spin_unlock_bh(&csk->lock); 14267b36b6e0Skxie@chelsio.com rel_skb: 14277b36b6e0Skxie@chelsio.com __kfree_skb(skb); 14287b36b6e0Skxie@chelsio.com } 14297b36b6e0Skxie@chelsio.com 143044830d8fSVarun Prakash static void 143144830d8fSVarun Prakash do_rx_iscsi_cmp(struct cxgbi_device *cdev, struct sk_buff *skb) 143244830d8fSVarun Prakash { 143344830d8fSVarun Prakash struct cxgbi_sock *csk; 143444830d8fSVarun Prakash struct cpl_rx_iscsi_cmp *rpl = (struct cpl_rx_iscsi_cmp *)skb->data; 143544830d8fSVarun Prakash struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(cdev); 143644830d8fSVarun Prakash struct tid_info *t = lldi->tids; 143744830d8fSVarun Prakash struct sk_buff *data_skb = NULL; 143844830d8fSVarun Prakash u32 tid = GET_TID(rpl); 143944830d8fSVarun Prakash u32 ddpvld = be32_to_cpu(rpl->ddpvld); 144044830d8fSVarun Prakash u32 seq = be32_to_cpu(rpl->seq); 144144830d8fSVarun Prakash u16 pdu_len_ddp = be16_to_cpu(rpl->pdu_len_ddp); 144244830d8fSVarun Prakash 144344830d8fSVarun Prakash csk = lookup_tid(t, tid); 144444830d8fSVarun Prakash if (unlikely(!csk)) { 144544830d8fSVarun Prakash pr_err("can't find connection for tid %u.\n", tid); 144644830d8fSVarun Prakash goto rel_skb; 144744830d8fSVarun Prakash } 144844830d8fSVarun Prakash 144944830d8fSVarun Prakash log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_PDU_RX, 145044830d8fSVarun Prakash "csk 0x%p,%u,0x%lx, skb 0x%p,0x%x, lhdr 0x%p, len %u, " 145144830d8fSVarun Prakash "pdu_len_ddp %u, status %u.\n", 145244830d8fSVarun Prakash csk, csk->state, csk->flags, skb, ddpvld, csk->skb_ulp_lhdr, 145344830d8fSVarun Prakash ntohs(rpl->len), pdu_len_ddp, rpl->status); 145444830d8fSVarun Prakash 145544830d8fSVarun Prakash spin_lock_bh(&csk->lock); 145644830d8fSVarun Prakash 145744830d8fSVarun Prakash if (unlikely(csk->state >= CTP_PASSIVE_CLOSE)) { 145844830d8fSVarun Prakash log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK, 145944830d8fSVarun Prakash "csk 0x%p,%u,0x%lx,%u, bad state.\n", 146044830d8fSVarun Prakash csk, csk->state, csk->flags, csk->tid); 146144830d8fSVarun Prakash 146244830d8fSVarun Prakash if (csk->state != CTP_ABORTING) 146344830d8fSVarun Prakash goto abort_conn; 146444830d8fSVarun Prakash else 146544830d8fSVarun Prakash goto discard; 146644830d8fSVarun Prakash } 146744830d8fSVarun Prakash 146844830d8fSVarun Prakash cxgbi_skcb_tcp_seq(skb) = seq; 146944830d8fSVarun Prakash cxgbi_skcb_flags(skb) = 0; 147044830d8fSVarun Prakash cxgbi_skcb_rx_pdulen(skb) = 0; 147144830d8fSVarun Prakash 147244830d8fSVarun Prakash skb_reset_transport_header(skb); 147344830d8fSVarun Prakash __skb_pull(skb, sizeof(*rpl)); 147444830d8fSVarun Prakash __pskb_trim(skb, be16_to_cpu(rpl->len)); 147544830d8fSVarun Prakash 147644830d8fSVarun Prakash csk->rcv_nxt = seq + pdu_len_ddp; 147744830d8fSVarun Prakash 147844830d8fSVarun Prakash if (csk->skb_ulp_lhdr) { 147944830d8fSVarun Prakash data_skb = skb_peek(&csk->receive_queue); 148044830d8fSVarun Prakash if (!data_skb || 148144830d8fSVarun Prakash !cxgbi_skcb_test_flag(data_skb, SKCBF_RX_DATA)) { 148244830d8fSVarun Prakash pr_err("Error! freelist data not found 0x%p, tid %u\n", 148344830d8fSVarun Prakash data_skb, tid); 148444830d8fSVarun Prakash 148544830d8fSVarun Prakash goto abort_conn; 148644830d8fSVarun Prakash } 148744830d8fSVarun Prakash __skb_unlink(data_skb, &csk->receive_queue); 148844830d8fSVarun Prakash 148944830d8fSVarun Prakash cxgbi_skcb_set_flag(skb, SKCBF_RX_DATA); 149044830d8fSVarun Prakash 149144830d8fSVarun Prakash __skb_queue_tail(&csk->receive_queue, skb); 149244830d8fSVarun Prakash __skb_queue_tail(&csk->receive_queue, data_skb); 149344830d8fSVarun Prakash } else { 149444830d8fSVarun Prakash __skb_queue_tail(&csk->receive_queue, skb); 149544830d8fSVarun Prakash } 149644830d8fSVarun Prakash 149744830d8fSVarun Prakash csk->skb_ulp_lhdr = NULL; 149844830d8fSVarun Prakash 149944830d8fSVarun Prakash cxgbi_skcb_set_flag(skb, SKCBF_RX_HDR); 150044830d8fSVarun Prakash cxgbi_skcb_set_flag(skb, SKCBF_RX_STATUS); 150144830d8fSVarun Prakash cxgbi_skcb_set_flag(skb, SKCBF_RX_ISCSI_COMPL); 150244830d8fSVarun Prakash cxgbi_skcb_rx_ddigest(skb) = be32_to_cpu(rpl->ulp_crc); 150344830d8fSVarun Prakash 150444830d8fSVarun Prakash cxgb4i_process_ddpvld(csk, skb, ddpvld); 150544830d8fSVarun Prakash 150644830d8fSVarun Prakash log_debug(1 << CXGBI_DBG_PDU_RX, "csk 0x%p, skb 0x%p, f 0x%lx.\n", 150744830d8fSVarun Prakash csk, skb, cxgbi_skcb_flags(skb)); 150844830d8fSVarun Prakash 150944830d8fSVarun Prakash cxgbi_conn_pdu_ready(csk); 151044830d8fSVarun Prakash spin_unlock_bh(&csk->lock); 151144830d8fSVarun Prakash 151244830d8fSVarun Prakash return; 151344830d8fSVarun Prakash 151444830d8fSVarun Prakash abort_conn: 151544830d8fSVarun Prakash send_abort_req(csk); 151644830d8fSVarun Prakash discard: 151744830d8fSVarun Prakash spin_unlock_bh(&csk->lock); 151844830d8fSVarun Prakash rel_skb: 151944830d8fSVarun Prakash __kfree_skb(skb); 152044830d8fSVarun Prakash } 152144830d8fSVarun Prakash 15227b36b6e0Skxie@chelsio.com static void do_fw4_ack(struct cxgbi_device *cdev, struct sk_buff *skb) 15237b36b6e0Skxie@chelsio.com { 15247b36b6e0Skxie@chelsio.com struct cxgbi_sock *csk; 15257b36b6e0Skxie@chelsio.com struct cpl_fw4_ack *rpl = (struct cpl_fw4_ack *)skb->data; 15267b36b6e0Skxie@chelsio.com unsigned int tid = GET_TID(rpl); 15277b36b6e0Skxie@chelsio.com struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(cdev); 15287b36b6e0Skxie@chelsio.com struct tid_info *t = lldi->tids; 15297b36b6e0Skxie@chelsio.com 15307b36b6e0Skxie@chelsio.com csk = lookup_tid(t, tid); 15317b36b6e0Skxie@chelsio.com if (unlikely(!csk)) 15327b36b6e0Skxie@chelsio.com pr_err("can't find connection for tid %u.\n", tid); 15337b36b6e0Skxie@chelsio.com else { 15347b36b6e0Skxie@chelsio.com log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK, 15357b36b6e0Skxie@chelsio.com "csk 0x%p,%u,0x%lx,%u.\n", 15367b36b6e0Skxie@chelsio.com csk, csk->state, csk->flags, csk->tid); 15377b36b6e0Skxie@chelsio.com cxgbi_sock_rcv_wr_ack(csk, rpl->credits, ntohl(rpl->snd_una), 15387b36b6e0Skxie@chelsio.com rpl->seq_vld); 15397b36b6e0Skxie@chelsio.com } 15407b36b6e0Skxie@chelsio.com __kfree_skb(skb); 15417b36b6e0Skxie@chelsio.com } 15427b36b6e0Skxie@chelsio.com 15437b36b6e0Skxie@chelsio.com static void do_set_tcb_rpl(struct cxgbi_device *cdev, struct sk_buff *skb) 15447b36b6e0Skxie@chelsio.com { 15457b36b6e0Skxie@chelsio.com struct cpl_set_tcb_rpl *rpl = (struct cpl_set_tcb_rpl *)skb->data; 15467b36b6e0Skxie@chelsio.com unsigned int tid = GET_TID(rpl); 15477b36b6e0Skxie@chelsio.com struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(cdev); 15487b36b6e0Skxie@chelsio.com struct tid_info *t = lldi->tids; 15497b36b6e0Skxie@chelsio.com struct cxgbi_sock *csk; 15507b36b6e0Skxie@chelsio.com 15517b36b6e0Skxie@chelsio.com csk = lookup_tid(t, tid); 15529e8f1c79SVarun Prakash if (!csk) { 15537b36b6e0Skxie@chelsio.com pr_err("can't find conn. for tid %u.\n", tid); 15549e8f1c79SVarun Prakash return; 15559e8f1c79SVarun Prakash } 15567b36b6e0Skxie@chelsio.com 15577b36b6e0Skxie@chelsio.com log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK, 15587b36b6e0Skxie@chelsio.com "csk 0x%p,%u,%lx,%u, status 0x%x.\n", 15597b36b6e0Skxie@chelsio.com csk, csk->state, csk->flags, csk->tid, rpl->status); 15607b36b6e0Skxie@chelsio.com 15619e8f1c79SVarun Prakash if (rpl->status != CPL_ERR_NONE) { 15627b36b6e0Skxie@chelsio.com pr_err("csk 0x%p,%u, SET_TCB_RPL status %u.\n", 15637b36b6e0Skxie@chelsio.com csk, tid, rpl->status); 15649e8f1c79SVarun Prakash csk->err = -EINVAL; 15659e8f1c79SVarun Prakash } 15669e8f1c79SVarun Prakash 15679e8f1c79SVarun Prakash complete(&csk->cmpl); 15687b36b6e0Skxie@chelsio.com 15697b36b6e0Skxie@chelsio.com __kfree_skb(skb); 15707b36b6e0Skxie@chelsio.com } 15717b36b6e0Skxie@chelsio.com 15727b36b6e0Skxie@chelsio.com static int alloc_cpls(struct cxgbi_sock *csk) 15737b36b6e0Skxie@chelsio.com { 157424d3f95aSkxie@chelsio.com csk->cpl_close = alloc_wr(sizeof(struct cpl_close_con_req), 157524d3f95aSkxie@chelsio.com 0, GFP_KERNEL); 15767b36b6e0Skxie@chelsio.com if (!csk->cpl_close) 15777b36b6e0Skxie@chelsio.com return -ENOMEM; 15787b36b6e0Skxie@chelsio.com 157924d3f95aSkxie@chelsio.com csk->cpl_abort_req = alloc_wr(sizeof(struct cpl_abort_req), 158024d3f95aSkxie@chelsio.com 0, GFP_KERNEL); 15817b36b6e0Skxie@chelsio.com if (!csk->cpl_abort_req) 15827b36b6e0Skxie@chelsio.com goto free_cpls; 15837b36b6e0Skxie@chelsio.com 158424d3f95aSkxie@chelsio.com csk->cpl_abort_rpl = alloc_wr(sizeof(struct cpl_abort_rpl), 158524d3f95aSkxie@chelsio.com 0, GFP_KERNEL); 15867b36b6e0Skxie@chelsio.com if (!csk->cpl_abort_rpl) 15877b36b6e0Skxie@chelsio.com goto free_cpls; 15887b36b6e0Skxie@chelsio.com return 0; 15897b36b6e0Skxie@chelsio.com 15907b36b6e0Skxie@chelsio.com free_cpls: 15917b36b6e0Skxie@chelsio.com cxgbi_sock_free_cpl_skbs(csk); 15927b36b6e0Skxie@chelsio.com return -ENOMEM; 15937b36b6e0Skxie@chelsio.com } 15947b36b6e0Skxie@chelsio.com 15957b36b6e0Skxie@chelsio.com static inline void l2t_put(struct cxgbi_sock *csk) 15967b36b6e0Skxie@chelsio.com { 15977b36b6e0Skxie@chelsio.com if (csk->l2t) { 15987b36b6e0Skxie@chelsio.com cxgb4_l2t_release(csk->l2t); 15997b36b6e0Skxie@chelsio.com csk->l2t = NULL; 16007b36b6e0Skxie@chelsio.com cxgbi_sock_put(csk); 16017b36b6e0Skxie@chelsio.com } 16027b36b6e0Skxie@chelsio.com } 16037b36b6e0Skxie@chelsio.com 16047b36b6e0Skxie@chelsio.com static void release_offload_resources(struct cxgbi_sock *csk) 16057b36b6e0Skxie@chelsio.com { 16067b36b6e0Skxie@chelsio.com struct cxgb4_lld_info *lldi; 1607211a84e3SAnish Bhatt #if IS_ENABLED(CONFIG_IPV6) 1608211a84e3SAnish Bhatt struct net_device *ndev = csk->cdev->ports[csk->port_id]; 1609211a84e3SAnish Bhatt #endif 16107b36b6e0Skxie@chelsio.com 16117b36b6e0Skxie@chelsio.com log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK, 16127b36b6e0Skxie@chelsio.com "csk 0x%p,%u,0x%lx,%u.\n", 16137b36b6e0Skxie@chelsio.com csk, csk->state, csk->flags, csk->tid); 16147b36b6e0Skxie@chelsio.com 16157b36b6e0Skxie@chelsio.com cxgbi_sock_free_cpl_skbs(csk); 16169b3a081fSVarun Prakash cxgbi_sock_purge_write_queue(csk); 16177b36b6e0Skxie@chelsio.com if (csk->wr_cred != csk->wr_max_cred) { 16187b36b6e0Skxie@chelsio.com cxgbi_sock_purge_wr_queue(csk); 16197b36b6e0Skxie@chelsio.com cxgbi_sock_reset_wr_list(csk); 16207b36b6e0Skxie@chelsio.com } 16217b36b6e0Skxie@chelsio.com 16227b36b6e0Skxie@chelsio.com l2t_put(csk); 1623211a84e3SAnish Bhatt #if IS_ENABLED(CONFIG_IPV6) 1624211a84e3SAnish Bhatt if (csk->csk_family == AF_INET6) 1625211a84e3SAnish Bhatt cxgb4_clip_release(ndev, 1626211a84e3SAnish Bhatt (const u32 *)&csk->saddr6.sin6_addr, 1); 1627211a84e3SAnish Bhatt #endif 1628211a84e3SAnish Bhatt 16297b36b6e0Skxie@chelsio.com if (cxgbi_sock_flag(csk, CTPF_HAS_ATID)) 16307b36b6e0Skxie@chelsio.com free_atid(csk); 16317b36b6e0Skxie@chelsio.com else if (cxgbi_sock_flag(csk, CTPF_HAS_TID)) { 16327b36b6e0Skxie@chelsio.com lldi = cxgbi_cdev_priv(csk->cdev); 16331dec4cecSGanesh Goudar cxgb4_remove_tid(lldi->tids, 0, csk->tid, 16341dec4cecSGanesh Goudar csk->csk_family); 16357b36b6e0Skxie@chelsio.com cxgbi_sock_clear_flag(csk, CTPF_HAS_TID); 16367b36b6e0Skxie@chelsio.com cxgbi_sock_put(csk); 16377b36b6e0Skxie@chelsio.com } 16387b36b6e0Skxie@chelsio.com csk->dst = NULL; 16397b36b6e0Skxie@chelsio.com } 16407b36b6e0Skxie@chelsio.com 1641b5a5fe4eSVarun Prakash #ifdef CONFIG_CHELSIO_T4_DCB 1642b5a5fe4eSVarun Prakash static inline u8 get_iscsi_dcb_state(struct net_device *ndev) 1643b5a5fe4eSVarun Prakash { 1644b5a5fe4eSVarun Prakash return ndev->dcbnl_ops->getstate(ndev); 1645b5a5fe4eSVarun Prakash } 1646b5a5fe4eSVarun Prakash 1647b5a5fe4eSVarun Prakash static int select_priority(int pri_mask) 1648b5a5fe4eSVarun Prakash { 1649b5a5fe4eSVarun Prakash if (!pri_mask) 1650b5a5fe4eSVarun Prakash return 0; 1651b5a5fe4eSVarun Prakash return (ffs(pri_mask) - 1); 1652b5a5fe4eSVarun Prakash } 1653b5a5fe4eSVarun Prakash 1654b5a5fe4eSVarun Prakash static u8 get_iscsi_dcb_priority(struct net_device *ndev) 1655b5a5fe4eSVarun Prakash { 1656b5a5fe4eSVarun Prakash int rv; 1657b5a5fe4eSVarun Prakash u8 caps; 1658b5a5fe4eSVarun Prakash 1659b5a5fe4eSVarun Prakash struct dcb_app iscsi_dcb_app = { 1660b5a5fe4eSVarun Prakash .protocol = 3260 1661b5a5fe4eSVarun Prakash }; 1662b5a5fe4eSVarun Prakash 1663b5a5fe4eSVarun Prakash rv = (int)ndev->dcbnl_ops->getcap(ndev, DCB_CAP_ATTR_DCBX, &caps); 1664b5a5fe4eSVarun Prakash if (rv) 1665b5a5fe4eSVarun Prakash return 0; 1666b5a5fe4eSVarun Prakash 1667b5a5fe4eSVarun Prakash if (caps & DCB_CAP_DCBX_VER_IEEE) { 1668b5a5fe4eSVarun Prakash iscsi_dcb_app.selector = IEEE_8021QAZ_APP_SEL_ANY; 1669b5a5fe4eSVarun Prakash rv = dcb_ieee_getapp_mask(ndev, &iscsi_dcb_app); 1670b5a5fe4eSVarun Prakash } else if (caps & DCB_CAP_DCBX_VER_CEE) { 1671b5a5fe4eSVarun Prakash iscsi_dcb_app.selector = DCB_APP_IDTYPE_PORTNUM; 1672b5a5fe4eSVarun Prakash rv = dcb_getapp(ndev, &iscsi_dcb_app); 1673b5a5fe4eSVarun Prakash } 1674b5a5fe4eSVarun Prakash 1675b5a5fe4eSVarun Prakash log_debug(1 << CXGBI_DBG_ISCSI, 1676b5a5fe4eSVarun Prakash "iSCSI priority is set to %u\n", select_priority(rv)); 1677b5a5fe4eSVarun Prakash return select_priority(rv); 1678b5a5fe4eSVarun Prakash } 1679b5a5fe4eSVarun Prakash #endif 1680b5a5fe4eSVarun Prakash 16817b36b6e0Skxie@chelsio.com static int init_act_open(struct cxgbi_sock *csk) 16827b36b6e0Skxie@chelsio.com { 16837b36b6e0Skxie@chelsio.com struct cxgbi_device *cdev = csk->cdev; 16847b36b6e0Skxie@chelsio.com struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(cdev); 16857b36b6e0Skxie@chelsio.com struct net_device *ndev = cdev->ports[csk->port_id]; 16867b36b6e0Skxie@chelsio.com struct sk_buff *skb = NULL; 1687759a0cc5SAnish Bhatt struct neighbour *n = NULL; 1688759a0cc5SAnish Bhatt void *daddr; 16897b36b6e0Skxie@chelsio.com unsigned int step; 16906c9e2770SVarun Prakash unsigned int rxq_idx; 1691759a0cc5SAnish Bhatt unsigned int size, size6; 169281daf10cSKaren Xie unsigned int linkspeed; 169381daf10cSKaren Xie unsigned int rcv_winf, snd_winf; 1694b5a5fe4eSVarun Prakash #ifdef CONFIG_CHELSIO_T4_DCB 1695b5a5fe4eSVarun Prakash u8 priority = 0; 1696b5a5fe4eSVarun Prakash #endif 16977b36b6e0Skxie@chelsio.com log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK, 16987b36b6e0Skxie@chelsio.com "csk 0x%p,%u,0x%lx,%u.\n", 16997b36b6e0Skxie@chelsio.com csk, csk->state, csk->flags, csk->tid); 17007b36b6e0Skxie@chelsio.com 1701759a0cc5SAnish Bhatt if (csk->csk_family == AF_INET) 1702759a0cc5SAnish Bhatt daddr = &csk->daddr.sin_addr.s_addr; 1703e81fbf6cSAnish Bhatt #if IS_ENABLED(CONFIG_IPV6) 1704e81fbf6cSAnish Bhatt else if (csk->csk_family == AF_INET6) 1705759a0cc5SAnish Bhatt daddr = &csk->daddr6.sin6_addr; 1706e81fbf6cSAnish Bhatt #endif 1707e81fbf6cSAnish Bhatt else { 1708e81fbf6cSAnish Bhatt pr_err("address family 0x%x not supported\n", csk->csk_family); 1709e81fbf6cSAnish Bhatt goto rel_resource; 1710e81fbf6cSAnish Bhatt } 1711759a0cc5SAnish Bhatt 1712759a0cc5SAnish Bhatt n = dst_neigh_lookup(csk->dst, daddr); 1713759a0cc5SAnish Bhatt 1714759a0cc5SAnish Bhatt if (!n) { 1715759a0cc5SAnish Bhatt pr_err("%s, can't get neighbour of csk->dst.\n", ndev->name); 1716759a0cc5SAnish Bhatt goto rel_resource; 1717759a0cc5SAnish Bhatt } 1718759a0cc5SAnish Bhatt 171971eb2ac5SVarun Prakash if (!(n->nud_state & NUD_VALID)) 172071eb2ac5SVarun Prakash neigh_event_send(n, NULL); 172171eb2ac5SVarun Prakash 17227b36b6e0Skxie@chelsio.com csk->atid = cxgb4_alloc_atid(lldi->tids, csk); 17237b36b6e0Skxie@chelsio.com if (csk->atid < 0) { 17247b36b6e0Skxie@chelsio.com pr_err("%s, NO atid available.\n", ndev->name); 1725338be072SQuentin Lambert goto rel_resource_without_clip; 17267b36b6e0Skxie@chelsio.com } 17277b36b6e0Skxie@chelsio.com cxgbi_sock_set_flag(csk, CTPF_HAS_ATID); 17287b36b6e0Skxie@chelsio.com cxgbi_sock_get(csk); 17297b36b6e0Skxie@chelsio.com 1730b5a5fe4eSVarun Prakash #ifdef CONFIG_CHELSIO_T4_DCB 1731b5a5fe4eSVarun Prakash if (get_iscsi_dcb_state(ndev)) 1732b5a5fe4eSVarun Prakash priority = get_iscsi_dcb_priority(ndev); 1733b5a5fe4eSVarun Prakash 1734b5a5fe4eSVarun Prakash csk->dcb_priority = priority; 1735b5a5fe4eSVarun Prakash csk->l2t = cxgb4_l2t_get(lldi->l2t, n, ndev, priority); 1736b5a5fe4eSVarun Prakash #else 173751e059bdSDavid Miller csk->l2t = cxgb4_l2t_get(lldi->l2t, n, ndev, 0); 1738b5a5fe4eSVarun Prakash #endif 17397b36b6e0Skxie@chelsio.com if (!csk->l2t) { 17407b36b6e0Skxie@chelsio.com pr_err("%s, cannot alloc l2t.\n", ndev->name); 1741211a84e3SAnish Bhatt goto rel_resource_without_clip; 17427b36b6e0Skxie@chelsio.com } 17437b36b6e0Skxie@chelsio.com cxgbi_sock_get(csk); 17447b36b6e0Skxie@chelsio.com 1745211a84e3SAnish Bhatt #if IS_ENABLED(CONFIG_IPV6) 1746211a84e3SAnish Bhatt if (csk->csk_family == AF_INET6) 1747211a84e3SAnish Bhatt cxgb4_clip_get(ndev, (const u32 *)&csk->saddr6.sin6_addr, 1); 1748211a84e3SAnish Bhatt #endif 1749211a84e3SAnish Bhatt 1750586be7cbSVarun Prakash if (is_t4(lldi->adapter_type)) { 1751759a0cc5SAnish Bhatt size = sizeof(struct cpl_act_open_req); 1752759a0cc5SAnish Bhatt size6 = sizeof(struct cpl_act_open_req6); 1753586be7cbSVarun Prakash } else if (is_t5(lldi->adapter_type)) { 1754759a0cc5SAnish Bhatt size = sizeof(struct cpl_t5_act_open_req); 1755759a0cc5SAnish Bhatt size6 = sizeof(struct cpl_t5_act_open_req6); 1756586be7cbSVarun Prakash } else { 1757586be7cbSVarun Prakash size = sizeof(struct cpl_t6_act_open_req); 1758586be7cbSVarun Prakash size6 = sizeof(struct cpl_t6_act_open_req6); 1759759a0cc5SAnish Bhatt } 1760759a0cc5SAnish Bhatt 1761759a0cc5SAnish Bhatt if (csk->csk_family == AF_INET) 1762759a0cc5SAnish Bhatt skb = alloc_wr(size, 0, GFP_NOIO); 1763f42bb57cSAnish Bhatt #if IS_ENABLED(CONFIG_IPV6) 1764759a0cc5SAnish Bhatt else 1765759a0cc5SAnish Bhatt skb = alloc_wr(size6, 0, GFP_NOIO); 1766f42bb57cSAnish Bhatt #endif 1767759a0cc5SAnish Bhatt 17687b36b6e0Skxie@chelsio.com if (!skb) 17697b36b6e0Skxie@chelsio.com goto rel_resource; 17707b36b6e0Skxie@chelsio.com skb->sk = (struct sock *)csk; 17717b36b6e0Skxie@chelsio.com t4_set_arp_err_handler(skb, csk, cxgbi_sock_act_open_req_arp_failure); 17727b36b6e0Skxie@chelsio.com 17737b36b6e0Skxie@chelsio.com if (!csk->mtu) 17747b36b6e0Skxie@chelsio.com csk->mtu = dst_mtu(csk->dst); 17757b36b6e0Skxie@chelsio.com cxgb4_best_mtu(lldi->mtus, csk->mtu, &csk->mss_idx); 17767b36b6e0Skxie@chelsio.com csk->tx_chan = cxgb4_port_chan(ndev); 177702d805dcSSantosh Rastapur csk->smac_idx = ((struct port_info *)netdev_priv(ndev))->smt_idx; 17787b36b6e0Skxie@chelsio.com step = lldi->ntxq / lldi->nchan; 17797b36b6e0Skxie@chelsio.com csk->txq_idx = cxgb4_port_idx(ndev) * step; 17807b36b6e0Skxie@chelsio.com step = lldi->nrxq / lldi->nchan; 17816c9e2770SVarun Prakash rxq_idx = (cxgb4_port_idx(ndev) * step) + (cdev->rxq_idx_cntr % step); 17826c9e2770SVarun Prakash cdev->rxq_idx_cntr++; 17836c9e2770SVarun Prakash csk->rss_qid = lldi->rxq_ids[rxq_idx]; 178481daf10cSKaren Xie linkspeed = ((struct port_info *)netdev_priv(ndev))->link_cfg.speed; 178581daf10cSKaren Xie csk->snd_win = cxgb4i_snd_win; 178681daf10cSKaren Xie csk->rcv_win = cxgb4i_rcv_win; 178781daf10cSKaren Xie if (cxgb4i_rcv_win <= 0) { 178881daf10cSKaren Xie csk->rcv_win = CXGB4I_DEFAULT_10G_RCV_WIN; 178981daf10cSKaren Xie rcv_winf = linkspeed / SPEED_10000; 179081daf10cSKaren Xie if (rcv_winf) 179181daf10cSKaren Xie csk->rcv_win *= rcv_winf; 179281daf10cSKaren Xie } 179381daf10cSKaren Xie if (cxgb4i_snd_win <= 0) { 179481daf10cSKaren Xie csk->snd_win = CXGB4I_DEFAULT_10G_SND_WIN; 179581daf10cSKaren Xie snd_winf = linkspeed / SPEED_10000; 179681daf10cSKaren Xie if (snd_winf) 179781daf10cSKaren Xie csk->snd_win *= snd_winf; 179881daf10cSKaren Xie } 1799759a0cc5SAnish Bhatt csk->wr_cred = lldi->wr_cred - 1800759a0cc5SAnish Bhatt DIV_ROUND_UP(sizeof(struct cpl_abort_req), 16); 1801759a0cc5SAnish Bhatt csk->wr_max_cred = csk->wr_cred; 18027b36b6e0Skxie@chelsio.com csk->wr_una_cred = 0; 18037b36b6e0Skxie@chelsio.com cxgbi_sock_reset_wr_list(csk); 18047b36b6e0Skxie@chelsio.com csk->err = 0; 18057b36b6e0Skxie@chelsio.com 1806759a0cc5SAnish Bhatt pr_info_ipaddr("csk 0x%p,%u,0x%lx,%u,%u,%u, mtu %u,%u, smac %u.\n", 1807759a0cc5SAnish Bhatt (&csk->saddr), (&csk->daddr), csk, csk->state, 1808759a0cc5SAnish Bhatt csk->flags, csk->tx_chan, csk->txq_idx, csk->rss_qid, 1809759a0cc5SAnish Bhatt csk->mtu, csk->mss_idx, csk->smac_idx); 1810759a0cc5SAnish Bhatt 1811759a0cc5SAnish Bhatt /* must wait for either a act_open_rpl or act_open_establish */ 18121fe1fdb0SVarun Prakash if (!try_module_get(cdev->owner)) { 18131fe1fdb0SVarun Prakash pr_err("%s, try_module_get failed.\n", ndev->name); 18141fe1fdb0SVarun Prakash goto rel_resource; 18151fe1fdb0SVarun Prakash } 18161fe1fdb0SVarun Prakash 18177b36b6e0Skxie@chelsio.com cxgbi_sock_set_state(csk, CTP_ACTIVE_OPEN); 1818759a0cc5SAnish Bhatt if (csk->csk_family == AF_INET) 18197b36b6e0Skxie@chelsio.com send_act_open_req(csk, skb, csk->l2t); 1820f42bb57cSAnish Bhatt #if IS_ENABLED(CONFIG_IPV6) 1821759a0cc5SAnish Bhatt else 1822759a0cc5SAnish Bhatt send_act_open_req6(csk, skb, csk->l2t); 1823f42bb57cSAnish Bhatt #endif 1824c4737377SDavid S. Miller neigh_release(n); 1825759a0cc5SAnish Bhatt 18267b36b6e0Skxie@chelsio.com return 0; 18277b36b6e0Skxie@chelsio.com 18287b36b6e0Skxie@chelsio.com rel_resource: 1829211a84e3SAnish Bhatt #if IS_ENABLED(CONFIG_IPV6) 1830211a84e3SAnish Bhatt if (csk->csk_family == AF_INET6) 1831211a84e3SAnish Bhatt cxgb4_clip_release(ndev, 1832211a84e3SAnish Bhatt (const u32 *)&csk->saddr6.sin6_addr, 1); 1833211a84e3SAnish Bhatt #endif 1834211a84e3SAnish Bhatt rel_resource_without_clip: 1835c4737377SDavid S. Miller if (n) 1836c4737377SDavid S. Miller neigh_release(n); 18377b36b6e0Skxie@chelsio.com if (skb) 18387b36b6e0Skxie@chelsio.com __kfree_skb(skb); 18397b36b6e0Skxie@chelsio.com return -EINVAL; 18407b36b6e0Skxie@chelsio.com } 18417b36b6e0Skxie@chelsio.com 18424665bdd5SVarun Prakash static cxgb4i_cplhandler_func cxgb4i_cplhandlers[NUM_CPL_CMDS] = { 18437b36b6e0Skxie@chelsio.com [CPL_ACT_ESTABLISH] = do_act_establish, 18447b36b6e0Skxie@chelsio.com [CPL_ACT_OPEN_RPL] = do_act_open_rpl, 18457b36b6e0Skxie@chelsio.com [CPL_PEER_CLOSE] = do_peer_close, 18467b36b6e0Skxie@chelsio.com [CPL_ABORT_REQ_RSS] = do_abort_req_rss, 18477b36b6e0Skxie@chelsio.com [CPL_ABORT_RPL_RSS] = do_abort_rpl_rss, 18487b36b6e0Skxie@chelsio.com [CPL_CLOSE_CON_RPL] = do_close_con_rpl, 18497b36b6e0Skxie@chelsio.com [CPL_FW4_ACK] = do_fw4_ack, 18507b36b6e0Skxie@chelsio.com [CPL_ISCSI_HDR] = do_rx_iscsi_hdr, 185144830d8fSVarun Prakash [CPL_ISCSI_DATA] = do_rx_iscsi_data, 18527b36b6e0Skxie@chelsio.com [CPL_SET_TCB_RPL] = do_set_tcb_rpl, 18537b36b6e0Skxie@chelsio.com [CPL_RX_DATA_DDP] = do_rx_data_ddp, 18543bd3e8bfSKaren Xie [CPL_RX_ISCSI_DDP] = do_rx_data_ddp, 185544830d8fSVarun Prakash [CPL_RX_ISCSI_CMP] = do_rx_iscsi_cmp, 1856f7bcd2e1SKaren Xie [CPL_RX_DATA] = do_rx_data, 18577b36b6e0Skxie@chelsio.com }; 18587b36b6e0Skxie@chelsio.com 18594665bdd5SVarun Prakash static int cxgb4i_ofld_init(struct cxgbi_device *cdev) 18607b36b6e0Skxie@chelsio.com { 18617b36b6e0Skxie@chelsio.com int rc; 18627b36b6e0Skxie@chelsio.com 18637b36b6e0Skxie@chelsio.com if (cxgb4i_max_connect > CXGB4I_MAX_CONN) 18647b36b6e0Skxie@chelsio.com cxgb4i_max_connect = CXGB4I_MAX_CONN; 18657b36b6e0Skxie@chelsio.com 18667b36b6e0Skxie@chelsio.com rc = cxgbi_device_portmap_create(cdev, cxgb4i_sport_base, 18677b36b6e0Skxie@chelsio.com cxgb4i_max_connect); 18687b36b6e0Skxie@chelsio.com if (rc < 0) 18697b36b6e0Skxie@chelsio.com return rc; 18707b36b6e0Skxie@chelsio.com 18717b36b6e0Skxie@chelsio.com cdev->csk_release_offload_resources = release_offload_resources; 18727b36b6e0Skxie@chelsio.com cdev->csk_push_tx_frames = push_tx_frames; 18737b36b6e0Skxie@chelsio.com cdev->csk_send_abort_req = send_abort_req; 18747b36b6e0Skxie@chelsio.com cdev->csk_send_close_req = send_close_req; 18757b36b6e0Skxie@chelsio.com cdev->csk_send_rx_credits = send_rx_credits; 18767b36b6e0Skxie@chelsio.com cdev->csk_alloc_cpls = alloc_cpls; 18777b36b6e0Skxie@chelsio.com cdev->csk_init_act_open = init_act_open; 18787b36b6e0Skxie@chelsio.com 18797b36b6e0Skxie@chelsio.com pr_info("cdev 0x%p, offload up, added.\n", cdev); 18807b36b6e0Skxie@chelsio.com return 0; 18817b36b6e0Skxie@chelsio.com } 18827b36b6e0Skxie@chelsio.com 188371f7a00bSVarun Prakash static inline void 188471f7a00bSVarun Prakash ulp_mem_io_set_hdr(struct cxgbi_device *cdev, 188571f7a00bSVarun Prakash struct ulp_mem_io *req, 188671f7a00bSVarun Prakash unsigned int wr_len, unsigned int dlen, 188771f7a00bSVarun Prakash unsigned int pm_addr, 188871f7a00bSVarun Prakash int tid) 188971f7a00bSVarun Prakash { 189071f7a00bSVarun Prakash struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(cdev); 189171f7a00bSVarun Prakash struct ulptx_idata *idata = (struct ulptx_idata *)(req + 1); 189271f7a00bSVarun Prakash 189371f7a00bSVarun Prakash INIT_ULPTX_WR(req, wr_len, 0, tid); 189471f7a00bSVarun Prakash req->wr.wr_hi = htonl(FW_WR_OP_V(FW_ULPTX_WR) | 189571f7a00bSVarun Prakash FW_WR_ATOMIC_V(0)); 189671f7a00bSVarun Prakash req->cmd = htonl(ULPTX_CMD_V(ULP_TX_MEM_WRITE) | 189771f7a00bSVarun Prakash ULP_MEMIO_ORDER_V(is_t4(lldi->adapter_type)) | 189871f7a00bSVarun Prakash T5_ULP_MEMIO_IMM_V(!is_t4(lldi->adapter_type))); 189971f7a00bSVarun Prakash req->dlen = htonl(ULP_MEMIO_DATA_LEN_V(dlen >> 5)); 190071f7a00bSVarun Prakash req->lock_addr = htonl(ULP_MEMIO_ADDR_V(pm_addr >> 5)); 190171f7a00bSVarun Prakash req->len16 = htonl(DIV_ROUND_UP(wr_len - sizeof(req->wr), 16)); 190271f7a00bSVarun Prakash 190371f7a00bSVarun Prakash idata->cmd_more = htonl(ULPTX_CMD_V(ULP_TX_SC_IMM)); 190471f7a00bSVarun Prakash idata->len = htonl(dlen); 190571f7a00bSVarun Prakash } 190671f7a00bSVarun Prakash 190771f7a00bSVarun Prakash static struct sk_buff * 190871f7a00bSVarun Prakash ddp_ppod_init_idata(struct cxgbi_device *cdev, 190971f7a00bSVarun Prakash struct cxgbi_ppm *ppm, 191071f7a00bSVarun Prakash unsigned int idx, unsigned int npods, 191171f7a00bSVarun Prakash unsigned int tid) 191271f7a00bSVarun Prakash { 191371f7a00bSVarun Prakash unsigned int pm_addr = (idx << PPOD_SIZE_SHIFT) + ppm->llimit; 191471f7a00bSVarun Prakash unsigned int dlen = npods << PPOD_SIZE_SHIFT; 191571f7a00bSVarun Prakash unsigned int wr_len = roundup(sizeof(struct ulp_mem_io) + 191671f7a00bSVarun Prakash sizeof(struct ulptx_idata) + dlen, 16); 191771f7a00bSVarun Prakash struct sk_buff *skb = alloc_wr(wr_len, 0, GFP_ATOMIC); 191871f7a00bSVarun Prakash 191971f7a00bSVarun Prakash if (!skb) { 192071f7a00bSVarun Prakash pr_err("%s: %s idx %u, npods %u, OOM.\n", 192171f7a00bSVarun Prakash __func__, ppm->ndev->name, idx, npods); 192271f7a00bSVarun Prakash return NULL; 192371f7a00bSVarun Prakash } 192471f7a00bSVarun Prakash 192571f7a00bSVarun Prakash ulp_mem_io_set_hdr(cdev, (struct ulp_mem_io *)skb->head, wr_len, dlen, 192671f7a00bSVarun Prakash pm_addr, tid); 192771f7a00bSVarun Prakash 192871f7a00bSVarun Prakash return skb; 192971f7a00bSVarun Prakash } 193071f7a00bSVarun Prakash 193171f7a00bSVarun Prakash static int ddp_ppod_write_idata(struct cxgbi_ppm *ppm, struct cxgbi_sock *csk, 193271f7a00bSVarun Prakash struct cxgbi_task_tag_info *ttinfo, 193371f7a00bSVarun Prakash unsigned int idx, unsigned int npods, 193471f7a00bSVarun Prakash struct scatterlist **sg_pp, 193571f7a00bSVarun Prakash unsigned int *sg_off) 193671f7a00bSVarun Prakash { 193771f7a00bSVarun Prakash struct cxgbi_device *cdev = csk->cdev; 193871f7a00bSVarun Prakash struct sk_buff *skb = ddp_ppod_init_idata(cdev, ppm, idx, npods, 193971f7a00bSVarun Prakash csk->tid); 194071f7a00bSVarun Prakash struct ulp_mem_io *req; 194171f7a00bSVarun Prakash struct ulptx_idata *idata; 194271f7a00bSVarun Prakash struct cxgbi_pagepod *ppod; 194371f7a00bSVarun Prakash int i; 194471f7a00bSVarun Prakash 194571f7a00bSVarun Prakash if (!skb) 194671f7a00bSVarun Prakash return -ENOMEM; 194771f7a00bSVarun Prakash 194871f7a00bSVarun Prakash req = (struct ulp_mem_io *)skb->head; 194971f7a00bSVarun Prakash idata = (struct ulptx_idata *)(req + 1); 195071f7a00bSVarun Prakash ppod = (struct cxgbi_pagepod *)(idata + 1); 195171f7a00bSVarun Prakash 195271f7a00bSVarun Prakash for (i = 0; i < npods; i++, ppod++) 195371f7a00bSVarun Prakash cxgbi_ddp_set_one_ppod(ppod, ttinfo, sg_pp, sg_off); 195471f7a00bSVarun Prakash 195571f7a00bSVarun Prakash cxgbi_skcb_set_flag(skb, SKCBF_TX_MEM_WRITE); 195671f7a00bSVarun Prakash cxgbi_skcb_set_flag(skb, SKCBF_TX_FLAG_COMPL); 195771f7a00bSVarun Prakash set_wr_txq(skb, CPL_PRIORITY_DATA, csk->port_id); 195871f7a00bSVarun Prakash 195971f7a00bSVarun Prakash spin_lock_bh(&csk->lock); 196071f7a00bSVarun Prakash cxgbi_sock_skb_entail(csk, skb); 196171f7a00bSVarun Prakash spin_unlock_bh(&csk->lock); 196271f7a00bSVarun Prakash 196371f7a00bSVarun Prakash return 0; 196471f7a00bSVarun Prakash } 196571f7a00bSVarun Prakash 196671f7a00bSVarun Prakash static int ddp_set_map(struct cxgbi_ppm *ppm, struct cxgbi_sock *csk, 196771f7a00bSVarun Prakash struct cxgbi_task_tag_info *ttinfo) 196871f7a00bSVarun Prakash { 196971f7a00bSVarun Prakash unsigned int pidx = ttinfo->idx; 197071f7a00bSVarun Prakash unsigned int npods = ttinfo->npods; 197171f7a00bSVarun Prakash unsigned int i, cnt; 197271f7a00bSVarun Prakash int err = 0; 197371f7a00bSVarun Prakash struct scatterlist *sg = ttinfo->sgl; 197471f7a00bSVarun Prakash unsigned int offset = 0; 197571f7a00bSVarun Prakash 197671f7a00bSVarun Prakash ttinfo->cid = csk->port_id; 197771f7a00bSVarun Prakash 197871f7a00bSVarun Prakash for (i = 0; i < npods; i += cnt, pidx += cnt) { 197971f7a00bSVarun Prakash cnt = npods - i; 198071f7a00bSVarun Prakash 198171f7a00bSVarun Prakash if (cnt > ULPMEM_IDATA_MAX_NPPODS) 198271f7a00bSVarun Prakash cnt = ULPMEM_IDATA_MAX_NPPODS; 198371f7a00bSVarun Prakash err = ddp_ppod_write_idata(ppm, csk, ttinfo, pidx, cnt, 198471f7a00bSVarun Prakash &sg, &offset); 198571f7a00bSVarun Prakash if (err < 0) 198671f7a00bSVarun Prakash break; 198771f7a00bSVarun Prakash } 198871f7a00bSVarun Prakash 198971f7a00bSVarun Prakash return err; 199071f7a00bSVarun Prakash } 199171f7a00bSVarun Prakash 19927b36b6e0Skxie@chelsio.com static int ddp_setup_conn_pgidx(struct cxgbi_sock *csk, unsigned int tid, 19939e8f1c79SVarun Prakash int pg_idx) 19947b36b6e0Skxie@chelsio.com { 19957b36b6e0Skxie@chelsio.com struct sk_buff *skb; 19967b36b6e0Skxie@chelsio.com struct cpl_set_tcb_field *req; 19977b36b6e0Skxie@chelsio.com 1998e27d6169Skxie@chelsio.com if (!pg_idx || pg_idx >= DDP_PGIDX_MAX) 19997b36b6e0Skxie@chelsio.com return 0; 20007b36b6e0Skxie@chelsio.com 200124d3f95aSkxie@chelsio.com skb = alloc_wr(sizeof(*req), 0, GFP_KERNEL); 20027b36b6e0Skxie@chelsio.com if (!skb) 20037b36b6e0Skxie@chelsio.com return -ENOMEM; 20047b36b6e0Skxie@chelsio.com 2005e27d6169Skxie@chelsio.com /* set up ulp page size */ 20067b36b6e0Skxie@chelsio.com req = (struct cpl_set_tcb_field *)skb->head; 20077b36b6e0Skxie@chelsio.com INIT_TP_WR(req, csk->tid); 20087b36b6e0Skxie@chelsio.com OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_SET_TCB_FIELD, csk->tid)); 20099e8f1c79SVarun Prakash req->reply_ctrl = htons(NO_REPLY_V(0) | QUEUENO_V(csk->rss_qid)); 2010e27d6169Skxie@chelsio.com req->word_cookie = htons(0); 2011e27d6169Skxie@chelsio.com req->mask = cpu_to_be64(0x3 << 8); 2012e27d6169Skxie@chelsio.com req->val = cpu_to_be64(pg_idx << 8); 20137b36b6e0Skxie@chelsio.com set_wr_txq(skb, CPL_PRIORITY_CONTROL, csk->port_id); 20147b36b6e0Skxie@chelsio.com 20157b36b6e0Skxie@chelsio.com log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK, 20167b36b6e0Skxie@chelsio.com "csk 0x%p, tid 0x%x, pg_idx %u.\n", csk, csk->tid, pg_idx); 20177b36b6e0Skxie@chelsio.com 20189e8f1c79SVarun Prakash reinit_completion(&csk->cmpl); 20197b36b6e0Skxie@chelsio.com cxgb4_ofld_send(csk->cdev->ports[csk->port_id], skb); 20209e8f1c79SVarun Prakash wait_for_completion(&csk->cmpl); 20219e8f1c79SVarun Prakash 20229e8f1c79SVarun Prakash return csk->err; 20237b36b6e0Skxie@chelsio.com } 20247b36b6e0Skxie@chelsio.com 20257b36b6e0Skxie@chelsio.com static int ddp_setup_conn_digest(struct cxgbi_sock *csk, unsigned int tid, 20269e8f1c79SVarun Prakash int hcrc, int dcrc) 20277b36b6e0Skxie@chelsio.com { 20287b36b6e0Skxie@chelsio.com struct sk_buff *skb; 20297b36b6e0Skxie@chelsio.com struct cpl_set_tcb_field *req; 20307b36b6e0Skxie@chelsio.com 2031e27d6169Skxie@chelsio.com if (!hcrc && !dcrc) 2032e27d6169Skxie@chelsio.com return 0; 20337b36b6e0Skxie@chelsio.com 203424d3f95aSkxie@chelsio.com skb = alloc_wr(sizeof(*req), 0, GFP_KERNEL); 20357b36b6e0Skxie@chelsio.com if (!skb) 20367b36b6e0Skxie@chelsio.com return -ENOMEM; 20377b36b6e0Skxie@chelsio.com 20387b36b6e0Skxie@chelsio.com csk->hcrc_len = (hcrc ? 4 : 0); 20397b36b6e0Skxie@chelsio.com csk->dcrc_len = (dcrc ? 4 : 0); 2040e27d6169Skxie@chelsio.com /* set up ulp submode */ 20417b36b6e0Skxie@chelsio.com req = (struct cpl_set_tcb_field *)skb->head; 20427b36b6e0Skxie@chelsio.com INIT_TP_WR(req, tid); 20437b36b6e0Skxie@chelsio.com OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_SET_TCB_FIELD, tid)); 20449e8f1c79SVarun Prakash req->reply_ctrl = htons(NO_REPLY_V(0) | QUEUENO_V(csk->rss_qid)); 2045e27d6169Skxie@chelsio.com req->word_cookie = htons(0); 2046e27d6169Skxie@chelsio.com req->mask = cpu_to_be64(0x3 << 4); 2047e27d6169Skxie@chelsio.com req->val = cpu_to_be64(((hcrc ? ULP_CRC_HEADER : 0) | 2048e27d6169Skxie@chelsio.com (dcrc ? ULP_CRC_DATA : 0)) << 4); 20497b36b6e0Skxie@chelsio.com set_wr_txq(skb, CPL_PRIORITY_CONTROL, csk->port_id); 20507b36b6e0Skxie@chelsio.com 20517b36b6e0Skxie@chelsio.com log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK, 20527b36b6e0Skxie@chelsio.com "csk 0x%p, tid 0x%x, crc %d,%d.\n", csk, csk->tid, hcrc, dcrc); 20537b36b6e0Skxie@chelsio.com 20549e8f1c79SVarun Prakash reinit_completion(&csk->cmpl); 20557b36b6e0Skxie@chelsio.com cxgb4_ofld_send(csk->cdev->ports[csk->port_id], skb); 20569e8f1c79SVarun Prakash wait_for_completion(&csk->cmpl); 20579e8f1c79SVarun Prakash 20589e8f1c79SVarun Prakash return csk->err; 20597b36b6e0Skxie@chelsio.com } 20607b36b6e0Skxie@chelsio.com 206171f7a00bSVarun Prakash static struct cxgbi_ppm *cdev2ppm(struct cxgbi_device *cdev) 206271f7a00bSVarun Prakash { 206371f7a00bSVarun Prakash return (struct cxgbi_ppm *)(*((struct cxgb4_lld_info *) 206471f7a00bSVarun Prakash (cxgbi_cdev_priv(cdev)))->iscsi_ppm); 206571f7a00bSVarun Prakash } 206671f7a00bSVarun Prakash 20677b36b6e0Skxie@chelsio.com static int cxgb4i_ddp_init(struct cxgbi_device *cdev) 20687b36b6e0Skxie@chelsio.com { 206971f7a00bSVarun Prakash struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(cdev); 207071f7a00bSVarun Prakash struct net_device *ndev = cdev->ports[0]; 207171f7a00bSVarun Prakash struct cxgbi_tag_format tformat; 207271f7a00bSVarun Prakash unsigned int ppmax; 207371f7a00bSVarun Prakash int i; 207471f7a00bSVarun Prakash 207571f7a00bSVarun Prakash if (!lldi->vr->iscsi.size) { 207671f7a00bSVarun Prakash pr_warn("%s, iscsi NOT enabled, check config!\n", ndev->name); 207771f7a00bSVarun Prakash return -EACCES; 207871f7a00bSVarun Prakash } 207971f7a00bSVarun Prakash 208071f7a00bSVarun Prakash cdev->flags |= CXGBI_FLAG_USE_PPOD_OFLDQ; 208171f7a00bSVarun Prakash ppmax = lldi->vr->iscsi.size >> PPOD_SIZE_SHIFT; 208271f7a00bSVarun Prakash 208371f7a00bSVarun Prakash memset(&tformat, 0, sizeof(struct cxgbi_tag_format)); 208471f7a00bSVarun Prakash for (i = 0; i < 4; i++) 208571f7a00bSVarun Prakash tformat.pgsz_order[i] = (lldi->iscsi_pgsz_order >> (i << 3)) 208671f7a00bSVarun Prakash & 0xF; 208771f7a00bSVarun Prakash cxgbi_tagmask_check(lldi->iscsi_tagmask, &tformat); 208871f7a00bSVarun Prakash 208971f7a00bSVarun Prakash cxgbi_ddp_ppm_setup(lldi->iscsi_ppm, cdev, &tformat, ppmax, 209071f7a00bSVarun Prakash lldi->iscsi_llimit, lldi->vr->iscsi.start, 2); 209171f7a00bSVarun Prakash 20927b36b6e0Skxie@chelsio.com cdev->csk_ddp_setup_digest = ddp_setup_conn_digest; 20937b36b6e0Skxie@chelsio.com cdev->csk_ddp_setup_pgidx = ddp_setup_conn_pgidx; 209471f7a00bSVarun Prakash cdev->csk_ddp_set_map = ddp_set_map; 209571f7a00bSVarun Prakash cdev->tx_max_size = min_t(unsigned int, ULP2_MAX_PDU_PAYLOAD, 209671f7a00bSVarun Prakash lldi->iscsi_iolen - ISCSI_PDU_NONPAYLOAD_LEN); 209771f7a00bSVarun Prakash cdev->rx_max_size = min_t(unsigned int, ULP2_MAX_PDU_PAYLOAD, 209871f7a00bSVarun Prakash lldi->iscsi_iolen - ISCSI_PDU_NONPAYLOAD_LEN); 209971f7a00bSVarun Prakash cdev->cdev2ppm = cdev2ppm; 210071f7a00bSVarun Prakash 21017b36b6e0Skxie@chelsio.com return 0; 21027b36b6e0Skxie@chelsio.com } 21037b36b6e0Skxie@chelsio.com 21047b36b6e0Skxie@chelsio.com static void *t4_uld_add(const struct cxgb4_lld_info *lldi) 21057b36b6e0Skxie@chelsio.com { 21067b36b6e0Skxie@chelsio.com struct cxgbi_device *cdev; 21077b36b6e0Skxie@chelsio.com struct port_info *pi; 21087b36b6e0Skxie@chelsio.com int i, rc; 21097b36b6e0Skxie@chelsio.com 21107b36b6e0Skxie@chelsio.com cdev = cxgbi_device_register(sizeof(*lldi), lldi->nports); 21117b36b6e0Skxie@chelsio.com if (!cdev) { 21127b36b6e0Skxie@chelsio.com pr_info("t4 device 0x%p, register failed.\n", lldi); 21137b36b6e0Skxie@chelsio.com return NULL; 21147b36b6e0Skxie@chelsio.com } 21157b36b6e0Skxie@chelsio.com pr_info("0x%p,0x%x, ports %u,%s, chan %u, q %u,%u, wr %u.\n", 21167b36b6e0Skxie@chelsio.com cdev, lldi->adapter_type, lldi->nports, 21177b36b6e0Skxie@chelsio.com lldi->ports[0]->name, lldi->nchan, lldi->ntxq, 21187b36b6e0Skxie@chelsio.com lldi->nrxq, lldi->wr_cred); 21197b36b6e0Skxie@chelsio.com for (i = 0; i < lldi->nrxq; i++) 21207b36b6e0Skxie@chelsio.com log_debug(1 << CXGBI_DBG_DEV, 21217b36b6e0Skxie@chelsio.com "t4 0x%p, rxq id #%d: %u.\n", 21227b36b6e0Skxie@chelsio.com cdev, i, lldi->rxq_ids[i]); 21237b36b6e0Skxie@chelsio.com 21247b36b6e0Skxie@chelsio.com memcpy(cxgbi_cdev_priv(cdev), lldi, sizeof(*lldi)); 21257b36b6e0Skxie@chelsio.com cdev->flags = CXGBI_FLAG_DEV_T4; 21267b36b6e0Skxie@chelsio.com cdev->pdev = lldi->pdev; 21277b36b6e0Skxie@chelsio.com cdev->ports = lldi->ports; 21287b36b6e0Skxie@chelsio.com cdev->nports = lldi->nports; 21297b36b6e0Skxie@chelsio.com cdev->mtus = lldi->mtus; 21307b36b6e0Skxie@chelsio.com cdev->nmtus = NMTUS; 2131586be7cbSVarun Prakash cdev->rx_credit_thres = (CHELSIO_CHIP_VERSION(lldi->adapter_type) <= 2132586be7cbSVarun Prakash CHELSIO_T5) ? cxgb4i_rx_credit_thres : 0; 21337b36b6e0Skxie@chelsio.com cdev->skb_tx_rsvd = CXGB4I_TX_HEADER_LEN; 21347b36b6e0Skxie@chelsio.com cdev->skb_rx_extra = sizeof(struct cpl_iscsi_hdr); 21357b36b6e0Skxie@chelsio.com cdev->itp = &cxgb4i_iscsi_transport; 21361fe1fdb0SVarun Prakash cdev->owner = THIS_MODULE; 21377b36b6e0Skxie@chelsio.com 2138b184487cSVarun Prakash cdev->pfvf = FW_PFVF_CMD_PFN_V(lldi->pf); 2139e27d6169Skxie@chelsio.com pr_info("cdev 0x%p,%s, pfvf %u.\n", 2140e27d6169Skxie@chelsio.com cdev, lldi->ports[0]->name, cdev->pfvf); 2141e27d6169Skxie@chelsio.com 21427b36b6e0Skxie@chelsio.com rc = cxgb4i_ddp_init(cdev); 21437b36b6e0Skxie@chelsio.com if (rc) { 21447b36b6e0Skxie@chelsio.com pr_info("t4 0x%p ddp init failed.\n", cdev); 21457b36b6e0Skxie@chelsio.com goto err_out; 21467b36b6e0Skxie@chelsio.com } 21477b36b6e0Skxie@chelsio.com rc = cxgb4i_ofld_init(cdev); 21487b36b6e0Skxie@chelsio.com if (rc) { 21497b36b6e0Skxie@chelsio.com pr_info("t4 0x%p ofld init failed.\n", cdev); 21507b36b6e0Skxie@chelsio.com goto err_out; 21517b36b6e0Skxie@chelsio.com } 21527b36b6e0Skxie@chelsio.com 21537b36b6e0Skxie@chelsio.com rc = cxgbi_hbas_add(cdev, CXGB4I_MAX_LUN, CXGBI_MAX_CONN, 21547b36b6e0Skxie@chelsio.com &cxgb4i_host_template, cxgb4i_stt); 21557b36b6e0Skxie@chelsio.com if (rc) 21567b36b6e0Skxie@chelsio.com goto err_out; 21577b36b6e0Skxie@chelsio.com 21587b36b6e0Skxie@chelsio.com for (i = 0; i < cdev->nports; i++) { 21597b36b6e0Skxie@chelsio.com pi = netdev_priv(lldi->ports[i]); 21607b36b6e0Skxie@chelsio.com cdev->hbas[i]->port_id = pi->port_id; 21617b36b6e0Skxie@chelsio.com } 21627b36b6e0Skxie@chelsio.com return cdev; 21637b36b6e0Skxie@chelsio.com 21647b36b6e0Skxie@chelsio.com err_out: 21657b36b6e0Skxie@chelsio.com cxgbi_device_unregister(cdev); 21667b36b6e0Skxie@chelsio.com return ERR_PTR(-ENOMEM); 21677b36b6e0Skxie@chelsio.com } 21687b36b6e0Skxie@chelsio.com 21697b36b6e0Skxie@chelsio.com #define RX_PULL_LEN 128 21707b36b6e0Skxie@chelsio.com static int t4_uld_rx_handler(void *handle, const __be64 *rsp, 21717b36b6e0Skxie@chelsio.com const struct pkt_gl *pgl) 21727b36b6e0Skxie@chelsio.com { 21737b36b6e0Skxie@chelsio.com const struct cpl_act_establish *rpl; 21747b36b6e0Skxie@chelsio.com struct sk_buff *skb; 21757b36b6e0Skxie@chelsio.com unsigned int opc; 21767b36b6e0Skxie@chelsio.com struct cxgbi_device *cdev = handle; 21777b36b6e0Skxie@chelsio.com 21787b36b6e0Skxie@chelsio.com if (pgl == NULL) { 21797b36b6e0Skxie@chelsio.com unsigned int len = 64 - sizeof(struct rsp_ctrl) - 8; 21807b36b6e0Skxie@chelsio.com 218124d3f95aSkxie@chelsio.com skb = alloc_wr(len, 0, GFP_ATOMIC); 21827b36b6e0Skxie@chelsio.com if (!skb) 21837b36b6e0Skxie@chelsio.com goto nomem; 21847b36b6e0Skxie@chelsio.com skb_copy_to_linear_data(skb, &rsp[1], len); 21857b36b6e0Skxie@chelsio.com } else { 21867b36b6e0Skxie@chelsio.com if (unlikely(*(u8 *)rsp != *(u8 *)pgl->va)) { 21877b36b6e0Skxie@chelsio.com pr_info("? FL 0x%p,RSS%#llx,FL %#llx,len %u.\n", 21887b36b6e0Skxie@chelsio.com pgl->va, be64_to_cpu(*rsp), 21897b36b6e0Skxie@chelsio.com be64_to_cpu(*(u64 *)pgl->va), 21907b36b6e0Skxie@chelsio.com pgl->tot_len); 21917b36b6e0Skxie@chelsio.com return 0; 21927b36b6e0Skxie@chelsio.com } 21937b36b6e0Skxie@chelsio.com skb = cxgb4_pktgl_to_skb(pgl, RX_PULL_LEN, RX_PULL_LEN); 21947b36b6e0Skxie@chelsio.com if (unlikely(!skb)) 21957b36b6e0Skxie@chelsio.com goto nomem; 21967b36b6e0Skxie@chelsio.com } 21977b36b6e0Skxie@chelsio.com 21987b36b6e0Skxie@chelsio.com rpl = (struct cpl_act_establish *)skb->data; 21997b36b6e0Skxie@chelsio.com opc = rpl->ot.opcode; 22007b36b6e0Skxie@chelsio.com log_debug(1 << CXGBI_DBG_TOE, 22017b36b6e0Skxie@chelsio.com "cdev %p, opcode 0x%x(0x%x,0x%x), skb %p.\n", 22027b36b6e0Skxie@chelsio.com cdev, opc, rpl->ot.opcode_tid, ntohl(rpl->ot.opcode_tid), skb); 2203ccc495efSDan Carpenter if (opc >= ARRAY_SIZE(cxgb4i_cplhandlers) || !cxgb4i_cplhandlers[opc]) { 22047b36b6e0Skxie@chelsio.com pr_err("No handler for opcode 0x%x.\n", opc); 22057b36b6e0Skxie@chelsio.com __kfree_skb(skb); 2206ccc495efSDan Carpenter } else 2207ccc495efSDan Carpenter cxgb4i_cplhandlers[opc](cdev, skb); 2208ccc495efSDan Carpenter 22097b36b6e0Skxie@chelsio.com return 0; 22107b36b6e0Skxie@chelsio.com nomem: 22117b36b6e0Skxie@chelsio.com log_debug(1 << CXGBI_DBG_TOE, "OOM bailing out.\n"); 22127b36b6e0Skxie@chelsio.com return 1; 22137b36b6e0Skxie@chelsio.com } 22147b36b6e0Skxie@chelsio.com 22157b36b6e0Skxie@chelsio.com static int t4_uld_state_change(void *handle, enum cxgb4_state state) 22167b36b6e0Skxie@chelsio.com { 22177b36b6e0Skxie@chelsio.com struct cxgbi_device *cdev = handle; 22187b36b6e0Skxie@chelsio.com 22197b36b6e0Skxie@chelsio.com switch (state) { 22207b36b6e0Skxie@chelsio.com case CXGB4_STATE_UP: 22217b36b6e0Skxie@chelsio.com pr_info("cdev 0x%p, UP.\n", cdev); 22227b36b6e0Skxie@chelsio.com break; 22237b36b6e0Skxie@chelsio.com case CXGB4_STATE_START_RECOVERY: 22247b36b6e0Skxie@chelsio.com pr_info("cdev 0x%p, RECOVERY.\n", cdev); 22257b36b6e0Skxie@chelsio.com /* close all connections */ 22267b36b6e0Skxie@chelsio.com break; 22277b36b6e0Skxie@chelsio.com case CXGB4_STATE_DOWN: 22287b36b6e0Skxie@chelsio.com pr_info("cdev 0x%p, DOWN.\n", cdev); 22297b36b6e0Skxie@chelsio.com break; 22307b36b6e0Skxie@chelsio.com case CXGB4_STATE_DETACH: 22317b36b6e0Skxie@chelsio.com pr_info("cdev 0x%p, DETACH.\n", cdev); 2232c3b331a3SThadeu Lima de Souza Cascardo cxgbi_device_unregister(cdev); 22337b36b6e0Skxie@chelsio.com break; 22347b36b6e0Skxie@chelsio.com default: 22357b36b6e0Skxie@chelsio.com pr_info("cdev 0x%p, unknown state %d.\n", cdev, state); 22367b36b6e0Skxie@chelsio.com break; 22377b36b6e0Skxie@chelsio.com } 22387b36b6e0Skxie@chelsio.com return 0; 22397b36b6e0Skxie@chelsio.com } 22407b36b6e0Skxie@chelsio.com 2241b5a5fe4eSVarun Prakash #ifdef CONFIG_CHELSIO_T4_DCB 2242b5a5fe4eSVarun Prakash static int 2243b5a5fe4eSVarun Prakash cxgb4_dcb_change_notify(struct notifier_block *self, unsigned long val, 2244b5a5fe4eSVarun Prakash void *data) 2245b5a5fe4eSVarun Prakash { 2246b5a5fe4eSVarun Prakash int i, port = 0xFF; 2247b5a5fe4eSVarun Prakash struct net_device *ndev; 2248b5a5fe4eSVarun Prakash struct cxgbi_device *cdev = NULL; 2249b5a5fe4eSVarun Prakash struct dcb_app_type *iscsi_app = data; 2250b5a5fe4eSVarun Prakash struct cxgbi_ports_map *pmap; 2251b5a5fe4eSVarun Prakash u8 priority; 2252b5a5fe4eSVarun Prakash 2253b5a5fe4eSVarun Prakash if (iscsi_app->dcbx & DCB_CAP_DCBX_VER_IEEE) { 2254b5a5fe4eSVarun Prakash if (iscsi_app->app.selector != IEEE_8021QAZ_APP_SEL_ANY) 2255b5a5fe4eSVarun Prakash return NOTIFY_DONE; 2256b5a5fe4eSVarun Prakash 2257b5a5fe4eSVarun Prakash priority = iscsi_app->app.priority; 2258b5a5fe4eSVarun Prakash } else if (iscsi_app->dcbx & DCB_CAP_DCBX_VER_CEE) { 2259b5a5fe4eSVarun Prakash if (iscsi_app->app.selector != DCB_APP_IDTYPE_PORTNUM) 2260b5a5fe4eSVarun Prakash return NOTIFY_DONE; 2261b5a5fe4eSVarun Prakash 2262b5a5fe4eSVarun Prakash if (!iscsi_app->app.priority) 2263b5a5fe4eSVarun Prakash return NOTIFY_DONE; 2264b5a5fe4eSVarun Prakash 2265b5a5fe4eSVarun Prakash priority = ffs(iscsi_app->app.priority) - 1; 2266b5a5fe4eSVarun Prakash } else { 2267b5a5fe4eSVarun Prakash return NOTIFY_DONE; 2268b5a5fe4eSVarun Prakash } 2269b5a5fe4eSVarun Prakash 2270b5a5fe4eSVarun Prakash if (iscsi_app->app.protocol != 3260) 2271b5a5fe4eSVarun Prakash return NOTIFY_DONE; 2272b5a5fe4eSVarun Prakash 2273b5a5fe4eSVarun Prakash log_debug(1 << CXGBI_DBG_ISCSI, "iSCSI priority for ifid %d is %u\n", 2274b5a5fe4eSVarun Prakash iscsi_app->ifindex, priority); 2275b5a5fe4eSVarun Prakash 2276b5a5fe4eSVarun Prakash ndev = dev_get_by_index(&init_net, iscsi_app->ifindex); 2277b5a5fe4eSVarun Prakash if (!ndev) 2278b5a5fe4eSVarun Prakash return NOTIFY_DONE; 2279b5a5fe4eSVarun Prakash 2280b5a5fe4eSVarun Prakash cdev = cxgbi_device_find_by_netdev_rcu(ndev, &port); 2281b5a5fe4eSVarun Prakash 2282b5a5fe4eSVarun Prakash dev_put(ndev); 2283b5a5fe4eSVarun Prakash if (!cdev) 2284b5a5fe4eSVarun Prakash return NOTIFY_DONE; 2285b5a5fe4eSVarun Prakash 2286b5a5fe4eSVarun Prakash pmap = &cdev->pmap; 2287b5a5fe4eSVarun Prakash 2288b5a5fe4eSVarun Prakash for (i = 0; i < pmap->used; i++) { 2289b5a5fe4eSVarun Prakash if (pmap->port_csk[i]) { 2290b5a5fe4eSVarun Prakash struct cxgbi_sock *csk = pmap->port_csk[i]; 2291b5a5fe4eSVarun Prakash 2292b5a5fe4eSVarun Prakash if (csk->dcb_priority != priority) { 2293b5a5fe4eSVarun Prakash iscsi_conn_failure(csk->user_data, 2294b5a5fe4eSVarun Prakash ISCSI_ERR_CONN_FAILED); 2295b5a5fe4eSVarun Prakash pr_info("Restarting iSCSI connection %p with " 2296b5a5fe4eSVarun Prakash "priority %u->%u.\n", csk, 2297b5a5fe4eSVarun Prakash csk->dcb_priority, priority); 2298b5a5fe4eSVarun Prakash } 2299b5a5fe4eSVarun Prakash } 2300b5a5fe4eSVarun Prakash } 2301b5a5fe4eSVarun Prakash return NOTIFY_OK; 2302b5a5fe4eSVarun Prakash } 2303b5a5fe4eSVarun Prakash #endif 2304b5a5fe4eSVarun Prakash 23057b36b6e0Skxie@chelsio.com static int __init cxgb4i_init_module(void) 23067b36b6e0Skxie@chelsio.com { 23077b36b6e0Skxie@chelsio.com int rc; 23087b36b6e0Skxie@chelsio.com 23097b36b6e0Skxie@chelsio.com printk(KERN_INFO "%s", version); 23107b36b6e0Skxie@chelsio.com 23117b36b6e0Skxie@chelsio.com rc = cxgbi_iscsi_init(&cxgb4i_iscsi_transport, &cxgb4i_stt); 23127b36b6e0Skxie@chelsio.com if (rc < 0) 23137b36b6e0Skxie@chelsio.com return rc; 23147b36b6e0Skxie@chelsio.com cxgb4_register_uld(CXGB4_ULD_ISCSI, &cxgb4i_uld_info); 2315759a0cc5SAnish Bhatt 2316b5a5fe4eSVarun Prakash #ifdef CONFIG_CHELSIO_T4_DCB 2317b5a5fe4eSVarun Prakash pr_info("%s dcb enabled.\n", DRV_MODULE_NAME); 2318b5a5fe4eSVarun Prakash register_dcbevent_notifier(&cxgb4_dcb_change); 2319b5a5fe4eSVarun Prakash #endif 23207b36b6e0Skxie@chelsio.com return 0; 23217b36b6e0Skxie@chelsio.com } 23227b36b6e0Skxie@chelsio.com 23237b36b6e0Skxie@chelsio.com static void __exit cxgb4i_exit_module(void) 23247b36b6e0Skxie@chelsio.com { 2325b5a5fe4eSVarun Prakash #ifdef CONFIG_CHELSIO_T4_DCB 2326b5a5fe4eSVarun Prakash unregister_dcbevent_notifier(&cxgb4_dcb_change); 2327b5a5fe4eSVarun Prakash #endif 23287b36b6e0Skxie@chelsio.com cxgb4_unregister_uld(CXGB4_ULD_ISCSI); 23297b36b6e0Skxie@chelsio.com cxgbi_device_unregister_all(CXGBI_FLAG_DEV_T4); 23307b36b6e0Skxie@chelsio.com cxgbi_iscsi_cleanup(&cxgb4i_iscsi_transport, &cxgb4i_stt); 23317b36b6e0Skxie@chelsio.com } 23327b36b6e0Skxie@chelsio.com 23337b36b6e0Skxie@chelsio.com module_init(cxgb4i_init_module); 23347b36b6e0Skxie@chelsio.com module_exit(cxgb4i_exit_module); 2335