xref: /openbmc/linux/drivers/scsi/cxgbi/cxgb4i/cxgb4i.c (revision 1fe1fdb0)
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 
387b36b6e0Skxie@chelsio.com #define	DRV_MODULE_NAME		"cxgb4i"
393bd3e8bfSKaren Xie #define DRV_MODULE_DESC		"Chelsio T4/T5 iSCSI Driver"
400ea5bf3dSKaren Xie #define	DRV_MODULE_VERSION	"0.9.5-ko"
410ea5bf3dSKaren Xie #define DRV_MODULE_RELDATE	"Apr. 2015"
427b36b6e0Skxie@chelsio.com 
437b36b6e0Skxie@chelsio.com static char version[] =
447b36b6e0Skxie@chelsio.com 	DRV_MODULE_DESC " " DRV_MODULE_NAME
450ea5bf3dSKaren Xie 	" v" DRV_MODULE_VERSION " (" DRV_MODULE_RELDATE ")\n";
467b36b6e0Skxie@chelsio.com 
477b36b6e0Skxie@chelsio.com MODULE_AUTHOR("Chelsio Communications, Inc.");
487b36b6e0Skxie@chelsio.com MODULE_DESCRIPTION(DRV_MODULE_DESC);
497b36b6e0Skxie@chelsio.com MODULE_VERSION(DRV_MODULE_VERSION);
507b36b6e0Skxie@chelsio.com MODULE_LICENSE("GPL");
517b36b6e0Skxie@chelsio.com 
527b36b6e0Skxie@chelsio.com module_param(dbg_level, uint, 0644);
537b36b6e0Skxie@chelsio.com MODULE_PARM_DESC(dbg_level, "Debug flag (default=0)");
547b36b6e0Skxie@chelsio.com 
5581daf10cSKaren Xie #define CXGB4I_DEFAULT_10G_RCV_WIN (256 * 1024)
5681daf10cSKaren Xie static int cxgb4i_rcv_win = -1;
577b36b6e0Skxie@chelsio.com module_param(cxgb4i_rcv_win, int, 0644);
587b36b6e0Skxie@chelsio.com MODULE_PARM_DESC(cxgb4i_rcv_win, "TCP reveive window in bytes");
597b36b6e0Skxie@chelsio.com 
6081daf10cSKaren Xie #define CXGB4I_DEFAULT_10G_SND_WIN (128 * 1024)
6181daf10cSKaren Xie static int cxgb4i_snd_win = -1;
627b36b6e0Skxie@chelsio.com module_param(cxgb4i_snd_win, int, 0644);
637b36b6e0Skxie@chelsio.com MODULE_PARM_DESC(cxgb4i_snd_win, "TCP send window in bytes");
647b36b6e0Skxie@chelsio.com 
657b36b6e0Skxie@chelsio.com static int cxgb4i_rx_credit_thres = 10 * 1024;
667b36b6e0Skxie@chelsio.com module_param(cxgb4i_rx_credit_thres, int, 0644);
677b36b6e0Skxie@chelsio.com MODULE_PARM_DESC(cxgb4i_rx_credit_thres,
687b36b6e0Skxie@chelsio.com 		"RX credits return threshold in bytes (default=10KB)");
697b36b6e0Skxie@chelsio.com 
707b36b6e0Skxie@chelsio.com static unsigned int cxgb4i_max_connect = (8 * 1024);
717b36b6e0Skxie@chelsio.com module_param(cxgb4i_max_connect, uint, 0644);
727b36b6e0Skxie@chelsio.com MODULE_PARM_DESC(cxgb4i_max_connect, "Maximum number of connections");
737b36b6e0Skxie@chelsio.com 
747b36b6e0Skxie@chelsio.com static unsigned short cxgb4i_sport_base = 20000;
757b36b6e0Skxie@chelsio.com module_param(cxgb4i_sport_base, ushort, 0644);
767b36b6e0Skxie@chelsio.com MODULE_PARM_DESC(cxgb4i_sport_base, "Starting port number (default 20000)");
777b36b6e0Skxie@chelsio.com 
787b36b6e0Skxie@chelsio.com typedef void (*cxgb4i_cplhandler_func)(struct cxgbi_device *, struct sk_buff *);
797b36b6e0Skxie@chelsio.com 
807b36b6e0Skxie@chelsio.com static void *t4_uld_add(const struct cxgb4_lld_info *);
817b36b6e0Skxie@chelsio.com static int t4_uld_rx_handler(void *, const __be64 *, const struct pkt_gl *);
827b36b6e0Skxie@chelsio.com static int t4_uld_state_change(void *, enum cxgb4_state state);
8364bfead8SKaren Xie static inline int send_tx_flowc_wr(struct cxgbi_sock *);
847b36b6e0Skxie@chelsio.com 
857b36b6e0Skxie@chelsio.com static const struct cxgb4_uld_info cxgb4i_uld_info = {
867b36b6e0Skxie@chelsio.com 	.name = DRV_MODULE_NAME,
870fbc81b3SHariprasad Shenai 	.nrxq = MAX_ULD_QSETS,
88ab677ff4SHariprasad Shenai 	.ntxq = MAX_ULD_QSETS,
890fbc81b3SHariprasad Shenai 	.rxq_size = 1024,
900fbc81b3SHariprasad Shenai 	.lro = false,
917b36b6e0Skxie@chelsio.com 	.add = t4_uld_add,
927b36b6e0Skxie@chelsio.com 	.rx_handler = t4_uld_rx_handler,
937b36b6e0Skxie@chelsio.com 	.state_change = t4_uld_state_change,
947b36b6e0Skxie@chelsio.com };
957b36b6e0Skxie@chelsio.com 
967b36b6e0Skxie@chelsio.com static struct scsi_host_template cxgb4i_host_template = {
977b36b6e0Skxie@chelsio.com 	.module		= THIS_MODULE,
987b36b6e0Skxie@chelsio.com 	.name		= DRV_MODULE_NAME,
997b36b6e0Skxie@chelsio.com 	.proc_name	= DRV_MODULE_NAME,
1007b36b6e0Skxie@chelsio.com 	.can_queue	= CXGB4I_SCSI_HOST_QDEPTH,
1017b36b6e0Skxie@chelsio.com 	.queuecommand	= iscsi_queuecommand,
102db5ed4dfSChristoph Hellwig 	.change_queue_depth = scsi_change_queue_depth,
1037b36b6e0Skxie@chelsio.com 	.sg_tablesize	= SG_ALL,
1047b36b6e0Skxie@chelsio.com 	.max_sectors	= 0xFFFF,
1057b36b6e0Skxie@chelsio.com 	.cmd_per_lun	= ISCSI_DEF_CMD_PER_LUN,
1067b36b6e0Skxie@chelsio.com 	.eh_abort_handler = iscsi_eh_abort,
1077b36b6e0Skxie@chelsio.com 	.eh_device_reset_handler = iscsi_eh_device_reset,
1087b36b6e0Skxie@chelsio.com 	.eh_target_reset_handler = iscsi_eh_recover_target,
1097b36b6e0Skxie@chelsio.com 	.target_alloc	= iscsi_target_alloc,
1107b36b6e0Skxie@chelsio.com 	.use_clustering	= DISABLE_CLUSTERING,
1117b36b6e0Skxie@chelsio.com 	.this_id	= -1,
112c40ecc12SChristoph Hellwig 	.track_queue_depth = 1,
1137b36b6e0Skxie@chelsio.com };
1147b36b6e0Skxie@chelsio.com 
1157b36b6e0Skxie@chelsio.com static struct iscsi_transport cxgb4i_iscsi_transport = {
1167b36b6e0Skxie@chelsio.com 	.owner		= THIS_MODULE,
1177b36b6e0Skxie@chelsio.com 	.name		= DRV_MODULE_NAME,
1187b36b6e0Skxie@chelsio.com 	.caps		= CAP_RECOVERY_L0 | CAP_MULTI_R2T | CAP_HDRDGST |
1197b36b6e0Skxie@chelsio.com 				CAP_DATADGST | CAP_DIGEST_OFFLOAD |
120fdafd4dfSMike Christie 				CAP_PADDING_OFFLOAD | CAP_TEXT_NEGO,
1213128c6c7SMike Christie 	.attr_is_visible	= cxgbi_attr_is_visible,
1227b36b6e0Skxie@chelsio.com 	.get_host_param	= cxgbi_get_host_param,
1237b36b6e0Skxie@chelsio.com 	.set_host_param	= cxgbi_set_host_param,
1247b36b6e0Skxie@chelsio.com 	/* session management */
1257b36b6e0Skxie@chelsio.com 	.create_session	= cxgbi_create_session,
1267b36b6e0Skxie@chelsio.com 	.destroy_session	= cxgbi_destroy_session,
1277b36b6e0Skxie@chelsio.com 	.get_session_param = iscsi_session_get_param,
1287b36b6e0Skxie@chelsio.com 	/* connection management */
1297b36b6e0Skxie@chelsio.com 	.create_conn	= cxgbi_create_conn,
1307b36b6e0Skxie@chelsio.com 	.bind_conn		= cxgbi_bind_conn,
1317b36b6e0Skxie@chelsio.com 	.destroy_conn	= iscsi_tcp_conn_teardown,
1327b36b6e0Skxie@chelsio.com 	.start_conn		= iscsi_conn_start,
1337b36b6e0Skxie@chelsio.com 	.stop_conn		= iscsi_conn_stop,
134c71b9b66SMike Christie 	.get_conn_param	= iscsi_conn_get_param,
1357b36b6e0Skxie@chelsio.com 	.set_param	= cxgbi_set_conn_param,
1367b36b6e0Skxie@chelsio.com 	.get_stats	= cxgbi_get_conn_stats,
1377b36b6e0Skxie@chelsio.com 	/* pdu xmit req from user space */
1387b36b6e0Skxie@chelsio.com 	.send_pdu	= iscsi_conn_send_pdu,
1397b36b6e0Skxie@chelsio.com 	/* task */
1407b36b6e0Skxie@chelsio.com 	.init_task	= iscsi_tcp_task_init,
1417b36b6e0Skxie@chelsio.com 	.xmit_task	= iscsi_tcp_task_xmit,
1427b36b6e0Skxie@chelsio.com 	.cleanup_task	= cxgbi_cleanup_task,
1437b36b6e0Skxie@chelsio.com 	/* pdu */
1447b36b6e0Skxie@chelsio.com 	.alloc_pdu	= cxgbi_conn_alloc_pdu,
1457b36b6e0Skxie@chelsio.com 	.init_pdu	= cxgbi_conn_init_pdu,
1467b36b6e0Skxie@chelsio.com 	.xmit_pdu	= cxgbi_conn_xmit_pdu,
1477b36b6e0Skxie@chelsio.com 	.parse_pdu_itt	= cxgbi_parse_pdu_itt,
1487b36b6e0Skxie@chelsio.com 	/* TCP connect/disconnect */
149c71b9b66SMike Christie 	.get_ep_param	= cxgbi_get_ep_param,
1507b36b6e0Skxie@chelsio.com 	.ep_connect	= cxgbi_ep_connect,
1517b36b6e0Skxie@chelsio.com 	.ep_poll	= cxgbi_ep_poll,
1527b36b6e0Skxie@chelsio.com 	.ep_disconnect	= cxgbi_ep_disconnect,
1537b36b6e0Skxie@chelsio.com 	/* Error recovery timeout call */
1547b36b6e0Skxie@chelsio.com 	.session_recovery_timedout = iscsi_session_recovery_timedout,
1557b36b6e0Skxie@chelsio.com };
1567b36b6e0Skxie@chelsio.com 
1577b36b6e0Skxie@chelsio.com static struct scsi_transport_template *cxgb4i_stt;
1587b36b6e0Skxie@chelsio.com 
1597b36b6e0Skxie@chelsio.com /*
1607b36b6e0Skxie@chelsio.com  * CPL (Chelsio Protocol Language) defines a message passing interface between
1617b36b6e0Skxie@chelsio.com  * the host driver and Chelsio asic.
1627b36b6e0Skxie@chelsio.com  * The section below implments CPLs that related to iscsi tcp connection
1637b36b6e0Skxie@chelsio.com  * open/close/abort and data send/receive.
1647b36b6e0Skxie@chelsio.com  */
165759a0cc5SAnish Bhatt 
1667b36b6e0Skxie@chelsio.com #define RCV_BUFSIZ_MASK		0x3FFU
167d3074cceSKaren Xie #define MAX_IMM_TX_PKT_LEN	256
1687b36b6e0Skxie@chelsio.com 
1697b36b6e0Skxie@chelsio.com static int push_tx_frames(struct cxgbi_sock *, int);
1707b36b6e0Skxie@chelsio.com 
1717b36b6e0Skxie@chelsio.com /*
1727b36b6e0Skxie@chelsio.com  * is_ofld_imm - check whether a packet can be sent as immediate data
1737b36b6e0Skxie@chelsio.com  * @skb: the packet
1747b36b6e0Skxie@chelsio.com  *
1757b36b6e0Skxie@chelsio.com  * Returns true if a packet can be sent as an offload WR with immediate
1767b36b6e0Skxie@chelsio.com  * data.  We currently use the same limit as for Ethernet packets.
1777b36b6e0Skxie@chelsio.com  */
17884944d8cSKaren Xie static inline bool is_ofld_imm(const struct sk_buff *skb)
1797b36b6e0Skxie@chelsio.com {
18084944d8cSKaren Xie 	int len = skb->len;
18184944d8cSKaren Xie 
18284944d8cSKaren Xie 	if (likely(cxgbi_skcb_test_flag(skb, SKCBF_TX_NEED_HDR)))
18384944d8cSKaren Xie 		len += sizeof(struct fw_ofld_tx_data_wr);
18484944d8cSKaren Xie 
18584944d8cSKaren Xie 	return len <= MAX_IMM_TX_PKT_LEN;
1867b36b6e0Skxie@chelsio.com }
1877b36b6e0Skxie@chelsio.com 
1887b36b6e0Skxie@chelsio.com static void send_act_open_req(struct cxgbi_sock *csk, struct sk_buff *skb,
1897b36b6e0Skxie@chelsio.com 				struct l2t_entry *e)
1907b36b6e0Skxie@chelsio.com {
1913bd3e8bfSKaren Xie 	struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(csk->cdev);
1927b36b6e0Skxie@chelsio.com 	int wscale = cxgbi_sock_compute_wscale(csk->mss_idx);
1937b36b6e0Skxie@chelsio.com 	unsigned long long opt0;
1947b36b6e0Skxie@chelsio.com 	unsigned int opt2;
1957b36b6e0Skxie@chelsio.com 	unsigned int qid_atid = ((unsigned int)csk->atid) |
1967b36b6e0Skxie@chelsio.com 				 (((unsigned int)csk->rss_qid) << 14);
1977b36b6e0Skxie@chelsio.com 
198d7990b0cSAnish Bhatt 	opt0 = KEEP_ALIVE_F |
199d7990b0cSAnish Bhatt 		WND_SCALE_V(wscale) |
200d7990b0cSAnish Bhatt 		MSS_IDX_V(csk->mss_idx) |
201d7990b0cSAnish Bhatt 		L2T_IDX_V(((struct l2t_entry *)csk->l2t)->idx) |
202d7990b0cSAnish Bhatt 		TX_CHAN_V(csk->tx_chan) |
203d7990b0cSAnish Bhatt 		SMAC_SEL_V(csk->smac_idx) |
204d7990b0cSAnish Bhatt 		ULP_MODE_V(ULP_MODE_ISCSI) |
20581daf10cSKaren Xie 		RCV_BUFSIZ_V(csk->rcv_win >> 10);
2061eb88a5dSKaren Xie 
207d7990b0cSAnish Bhatt 	opt2 = RX_CHANNEL_V(0) |
208d7990b0cSAnish Bhatt 		RSS_QUEUE_VALID_F |
209d7990b0cSAnish Bhatt 		RSS_QUEUE_V(csk->rss_qid);
2107b36b6e0Skxie@chelsio.com 
2113bd3e8bfSKaren Xie 	if (is_t4(lldi->adapter_type)) {
2123bd3e8bfSKaren Xie 		struct cpl_act_open_req *req =
2133bd3e8bfSKaren Xie 				(struct cpl_act_open_req *)skb->head;
2143bd3e8bfSKaren Xie 
2157b36b6e0Skxie@chelsio.com 		INIT_TP_WR(req, 0);
2167b36b6e0Skxie@chelsio.com 		OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_ACT_OPEN_REQ,
2177b36b6e0Skxie@chelsio.com 					qid_atid));
2187b36b6e0Skxie@chelsio.com 		req->local_port = csk->saddr.sin_port;
2197b36b6e0Skxie@chelsio.com 		req->peer_port = csk->daddr.sin_port;
2207b36b6e0Skxie@chelsio.com 		req->local_ip = csk->saddr.sin_addr.s_addr;
2217b36b6e0Skxie@chelsio.com 		req->peer_ip = csk->daddr.sin_addr.s_addr;
2227b36b6e0Skxie@chelsio.com 		req->opt0 = cpu_to_be64(opt0);
223ac0245ffSKaren Xie 		req->params = cpu_to_be32(cxgb4_select_ntuple(
224ac0245ffSKaren Xie 					csk->cdev->ports[csk->port_id],
225ac0245ffSKaren Xie 					csk->l2t));
226d7990b0cSAnish Bhatt 		opt2 |= RX_FC_VALID_F;
2277b36b6e0Skxie@chelsio.com 		req->opt2 = cpu_to_be32(opt2);
2287b36b6e0Skxie@chelsio.com 
2297b36b6e0Skxie@chelsio.com 		log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
2303bd3e8bfSKaren Xie 			"csk t4 0x%p, %pI4:%u-%pI4:%u, atid %d, qid %u.\n",
2317b36b6e0Skxie@chelsio.com 			csk, &req->local_ip, ntohs(req->local_port),
2327b36b6e0Skxie@chelsio.com 			&req->peer_ip, ntohs(req->peer_port),
2337b36b6e0Skxie@chelsio.com 			csk->atid, csk->rss_qid);
234586be7cbSVarun Prakash 	} else if (is_t5(lldi->adapter_type)) {
2353bd3e8bfSKaren Xie 		struct cpl_t5_act_open_req *req =
2363bd3e8bfSKaren Xie 				(struct cpl_t5_act_open_req *)skb->head;
2371eb88a5dSKaren Xie 		u32 isn = (prandom_u32() & ~7UL) - 1;
2387b36b6e0Skxie@chelsio.com 
2393bd3e8bfSKaren Xie 		INIT_TP_WR(req, 0);
2403bd3e8bfSKaren Xie 		OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_ACT_OPEN_REQ,
2413bd3e8bfSKaren Xie 					qid_atid));
2423bd3e8bfSKaren Xie 		req->local_port = csk->saddr.sin_port;
2433bd3e8bfSKaren Xie 		req->peer_port = csk->daddr.sin_port;
2443bd3e8bfSKaren Xie 		req->local_ip = csk->saddr.sin_addr.s_addr;
2453bd3e8bfSKaren Xie 		req->peer_ip = csk->daddr.sin_addr.s_addr;
2463bd3e8bfSKaren Xie 		req->opt0 = cpu_to_be64(opt0);
247d7990b0cSAnish Bhatt 		req->params = cpu_to_be64(FILTER_TUPLE_V(
248ac0245ffSKaren Xie 				cxgb4_select_ntuple(
249ac0245ffSKaren Xie 					csk->cdev->ports[csk->port_id],
250ac0245ffSKaren Xie 					csk->l2t)));
2511eb88a5dSKaren Xie 		req->rsvd = cpu_to_be32(isn);
2521eb88a5dSKaren Xie 		opt2 |= T5_ISS_VALID;
2531eb88a5dSKaren Xie 		opt2 |= T5_OPT_2_VALID_F;
2541eb88a5dSKaren Xie 
2553bd3e8bfSKaren Xie 		req->opt2 = cpu_to_be32(opt2);
2563bd3e8bfSKaren Xie 
2573bd3e8bfSKaren Xie 		log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
2583bd3e8bfSKaren Xie 			"csk t5 0x%p, %pI4:%u-%pI4:%u, atid %d, qid %u.\n",
2593bd3e8bfSKaren Xie 			csk, &req->local_ip, ntohs(req->local_port),
2603bd3e8bfSKaren Xie 			&req->peer_ip, ntohs(req->peer_port),
2613bd3e8bfSKaren Xie 			csk->atid, csk->rss_qid);
262586be7cbSVarun Prakash 	} else {
263586be7cbSVarun Prakash 		struct cpl_t6_act_open_req *req =
264586be7cbSVarun Prakash 				(struct cpl_t6_act_open_req *)skb->head;
265586be7cbSVarun Prakash 		u32 isn = (prandom_u32() & ~7UL) - 1;
266586be7cbSVarun Prakash 
267586be7cbSVarun Prakash 		INIT_TP_WR(req, 0);
268586be7cbSVarun Prakash 		OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_ACT_OPEN_REQ,
269586be7cbSVarun Prakash 							    qid_atid));
270586be7cbSVarun Prakash 		req->local_port = csk->saddr.sin_port;
271586be7cbSVarun Prakash 		req->peer_port = csk->daddr.sin_port;
272586be7cbSVarun Prakash 		req->local_ip = csk->saddr.sin_addr.s_addr;
273586be7cbSVarun Prakash 		req->peer_ip = csk->daddr.sin_addr.s_addr;
274586be7cbSVarun Prakash 		req->opt0 = cpu_to_be64(opt0);
275586be7cbSVarun Prakash 		req->params = cpu_to_be64(FILTER_TUPLE_V(
276586be7cbSVarun Prakash 				cxgb4_select_ntuple(
277586be7cbSVarun Prakash 					csk->cdev->ports[csk->port_id],
278586be7cbSVarun Prakash 					csk->l2t)));
279586be7cbSVarun Prakash 		req->rsvd = cpu_to_be32(isn);
280586be7cbSVarun Prakash 
281586be7cbSVarun Prakash 		opt2 |= T5_ISS_VALID;
282586be7cbSVarun Prakash 		opt2 |= RX_FC_DISABLE_F;
283586be7cbSVarun Prakash 		opt2 |= T5_OPT_2_VALID_F;
284586be7cbSVarun Prakash 
285586be7cbSVarun Prakash 		req->opt2 = cpu_to_be32(opt2);
286586be7cbSVarun Prakash 		req->rsvd2 = cpu_to_be32(0);
287586be7cbSVarun Prakash 		req->opt3 = cpu_to_be32(0);
288586be7cbSVarun Prakash 
289586be7cbSVarun Prakash 		log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
290586be7cbSVarun Prakash 			  "csk t6 0x%p, %pI4:%u-%pI4:%u, atid %d, qid %u.\n",
291586be7cbSVarun Prakash 			  csk, &req->local_ip, ntohs(req->local_port),
292586be7cbSVarun Prakash 			  &req->peer_ip, ntohs(req->peer_port),
293586be7cbSVarun Prakash 			  csk->atid, csk->rss_qid);
2943bd3e8bfSKaren Xie 	}
2953bd3e8bfSKaren Xie 
2963bd3e8bfSKaren Xie 	set_wr_txq(skb, CPL_PRIORITY_SETUP, csk->port_id);
297759a0cc5SAnish Bhatt 
298759a0cc5SAnish Bhatt 	pr_info_ipaddr("t%d csk 0x%p,%u,0x%lx,%u, rss_qid %u.\n",
299586be7cbSVarun Prakash 		       (&csk->saddr), (&csk->daddr),
300586be7cbSVarun Prakash 		       CHELSIO_CHIP_VERSION(lldi->adapter_type), csk,
301759a0cc5SAnish Bhatt 		       csk->state, csk->flags, csk->atid, csk->rss_qid);
302759a0cc5SAnish Bhatt 
303759a0cc5SAnish Bhatt 	cxgb4_l2t_send(csk->cdev->ports[csk->port_id], skb, csk->l2t);
304759a0cc5SAnish Bhatt }
305759a0cc5SAnish Bhatt 
306f42bb57cSAnish Bhatt #if IS_ENABLED(CONFIG_IPV6)
307759a0cc5SAnish Bhatt static void send_act_open_req6(struct cxgbi_sock *csk, struct sk_buff *skb,
308759a0cc5SAnish Bhatt 			       struct l2t_entry *e)
309759a0cc5SAnish Bhatt {
310759a0cc5SAnish Bhatt 	struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(csk->cdev);
311759a0cc5SAnish Bhatt 	int wscale = cxgbi_sock_compute_wscale(csk->mss_idx);
312759a0cc5SAnish Bhatt 	unsigned long long opt0;
313759a0cc5SAnish Bhatt 	unsigned int opt2;
314759a0cc5SAnish Bhatt 	unsigned int qid_atid = ((unsigned int)csk->atid) |
315759a0cc5SAnish Bhatt 				 (((unsigned int)csk->rss_qid) << 14);
316759a0cc5SAnish Bhatt 
317d7990b0cSAnish Bhatt 	opt0 = KEEP_ALIVE_F |
318d7990b0cSAnish Bhatt 		WND_SCALE_V(wscale) |
319d7990b0cSAnish Bhatt 		MSS_IDX_V(csk->mss_idx) |
320d7990b0cSAnish Bhatt 		L2T_IDX_V(((struct l2t_entry *)csk->l2t)->idx) |
321d7990b0cSAnish Bhatt 		TX_CHAN_V(csk->tx_chan) |
322d7990b0cSAnish Bhatt 		SMAC_SEL_V(csk->smac_idx) |
323d7990b0cSAnish Bhatt 		ULP_MODE_V(ULP_MODE_ISCSI) |
32481daf10cSKaren Xie 		RCV_BUFSIZ_V(csk->rcv_win >> 10);
325759a0cc5SAnish Bhatt 
326d7990b0cSAnish Bhatt 	opt2 = RX_CHANNEL_V(0) |
327d7990b0cSAnish Bhatt 		RSS_QUEUE_VALID_F |
328d7990b0cSAnish Bhatt 		RSS_QUEUE_V(csk->rss_qid);
329759a0cc5SAnish Bhatt 
330586be7cbSVarun Prakash 	if (is_t4(lldi->adapter_type)) {
331759a0cc5SAnish Bhatt 		struct cpl_act_open_req6 *req =
332759a0cc5SAnish Bhatt 			    (struct cpl_act_open_req6 *)skb->head;
333759a0cc5SAnish Bhatt 
334759a0cc5SAnish Bhatt 		INIT_TP_WR(req, 0);
335759a0cc5SAnish Bhatt 		OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_ACT_OPEN_REQ6,
336759a0cc5SAnish Bhatt 							    qid_atid));
337759a0cc5SAnish Bhatt 		req->local_port = csk->saddr6.sin6_port;
338759a0cc5SAnish Bhatt 		req->peer_port = csk->daddr6.sin6_port;
339759a0cc5SAnish Bhatt 
340759a0cc5SAnish Bhatt 		req->local_ip_hi = *(__be64 *)(csk->saddr6.sin6_addr.s6_addr);
341759a0cc5SAnish Bhatt 		req->local_ip_lo = *(__be64 *)(csk->saddr6.sin6_addr.s6_addr +
342759a0cc5SAnish Bhatt 								    8);
343759a0cc5SAnish Bhatt 		req->peer_ip_hi = *(__be64 *)(csk->daddr6.sin6_addr.s6_addr);
344759a0cc5SAnish Bhatt 		req->peer_ip_lo = *(__be64 *)(csk->daddr6.sin6_addr.s6_addr +
345759a0cc5SAnish Bhatt 								    8);
346759a0cc5SAnish Bhatt 
347759a0cc5SAnish Bhatt 		req->opt0 = cpu_to_be64(opt0);
348759a0cc5SAnish Bhatt 
349d7990b0cSAnish Bhatt 		opt2 |= RX_FC_VALID_F;
350759a0cc5SAnish Bhatt 		req->opt2 = cpu_to_be32(opt2);
351759a0cc5SAnish Bhatt 
352759a0cc5SAnish Bhatt 		req->params = cpu_to_be32(cxgb4_select_ntuple(
353759a0cc5SAnish Bhatt 					  csk->cdev->ports[csk->port_id],
354759a0cc5SAnish Bhatt 					  csk->l2t));
355586be7cbSVarun Prakash 	} else if (is_t5(lldi->adapter_type)) {
356759a0cc5SAnish Bhatt 		struct cpl_t5_act_open_req6 *req =
357759a0cc5SAnish Bhatt 				(struct cpl_t5_act_open_req6 *)skb->head;
358759a0cc5SAnish Bhatt 
359759a0cc5SAnish Bhatt 		INIT_TP_WR(req, 0);
360759a0cc5SAnish Bhatt 		OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_ACT_OPEN_REQ6,
361759a0cc5SAnish Bhatt 							    qid_atid));
362759a0cc5SAnish Bhatt 		req->local_port = csk->saddr6.sin6_port;
363759a0cc5SAnish Bhatt 		req->peer_port = csk->daddr6.sin6_port;
364759a0cc5SAnish Bhatt 		req->local_ip_hi = *(__be64 *)(csk->saddr6.sin6_addr.s6_addr);
365759a0cc5SAnish Bhatt 		req->local_ip_lo = *(__be64 *)(csk->saddr6.sin6_addr.s6_addr +
366759a0cc5SAnish Bhatt 									8);
367759a0cc5SAnish Bhatt 		req->peer_ip_hi = *(__be64 *)(csk->daddr6.sin6_addr.s6_addr);
368759a0cc5SAnish Bhatt 		req->peer_ip_lo = *(__be64 *)(csk->daddr6.sin6_addr.s6_addr +
369759a0cc5SAnish Bhatt 									8);
370759a0cc5SAnish Bhatt 		req->opt0 = cpu_to_be64(opt0);
371759a0cc5SAnish Bhatt 
372d7990b0cSAnish Bhatt 		opt2 |= T5_OPT_2_VALID_F;
373759a0cc5SAnish Bhatt 		req->opt2 = cpu_to_be32(opt2);
374759a0cc5SAnish Bhatt 
375d7990b0cSAnish Bhatt 		req->params = cpu_to_be64(FILTER_TUPLE_V(cxgb4_select_ntuple(
376759a0cc5SAnish Bhatt 					  csk->cdev->ports[csk->port_id],
377759a0cc5SAnish Bhatt 					  csk->l2t)));
378586be7cbSVarun Prakash 	} else {
379586be7cbSVarun Prakash 		struct cpl_t6_act_open_req6 *req =
380586be7cbSVarun Prakash 				(struct cpl_t6_act_open_req6 *)skb->head;
381586be7cbSVarun Prakash 
382586be7cbSVarun Prakash 		INIT_TP_WR(req, 0);
383586be7cbSVarun Prakash 		OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_ACT_OPEN_REQ6,
384586be7cbSVarun Prakash 							    qid_atid));
385586be7cbSVarun Prakash 		req->local_port = csk->saddr6.sin6_port;
386586be7cbSVarun Prakash 		req->peer_port = csk->daddr6.sin6_port;
387586be7cbSVarun Prakash 		req->local_ip_hi = *(__be64 *)(csk->saddr6.sin6_addr.s6_addr);
388586be7cbSVarun Prakash 		req->local_ip_lo = *(__be64 *)(csk->saddr6.sin6_addr.s6_addr +
389586be7cbSVarun Prakash 									8);
390586be7cbSVarun Prakash 		req->peer_ip_hi = *(__be64 *)(csk->daddr6.sin6_addr.s6_addr);
391586be7cbSVarun Prakash 		req->peer_ip_lo = *(__be64 *)(csk->daddr6.sin6_addr.s6_addr +
392586be7cbSVarun Prakash 									8);
393586be7cbSVarun Prakash 		req->opt0 = cpu_to_be64(opt0);
394586be7cbSVarun Prakash 
395586be7cbSVarun Prakash 		opt2 |= RX_FC_DISABLE_F;
396586be7cbSVarun Prakash 		opt2 |= T5_OPT_2_VALID_F;
397586be7cbSVarun Prakash 
398586be7cbSVarun Prakash 		req->opt2 = cpu_to_be32(opt2);
399586be7cbSVarun Prakash 
400586be7cbSVarun Prakash 		req->params = cpu_to_be64(FILTER_TUPLE_V(cxgb4_select_ntuple(
401586be7cbSVarun Prakash 					  csk->cdev->ports[csk->port_id],
402586be7cbSVarun Prakash 					  csk->l2t)));
403586be7cbSVarun Prakash 
404586be7cbSVarun Prakash 		req->rsvd2 = cpu_to_be32(0);
405586be7cbSVarun Prakash 		req->opt3 = cpu_to_be32(0);
406759a0cc5SAnish Bhatt 	}
407759a0cc5SAnish Bhatt 
408759a0cc5SAnish Bhatt 	set_wr_txq(skb, CPL_PRIORITY_SETUP, csk->port_id);
409759a0cc5SAnish Bhatt 
410759a0cc5SAnish Bhatt 	pr_info("t%d csk 0x%p,%u,0x%lx,%u, [%pI6]:%u-[%pI6]:%u, rss_qid %u.\n",
411586be7cbSVarun Prakash 		CHELSIO_CHIP_VERSION(lldi->adapter_type), csk, csk->state,
412586be7cbSVarun Prakash 		csk->flags, csk->atid,
413759a0cc5SAnish Bhatt 		&csk->saddr6.sin6_addr, ntohs(csk->saddr.sin_port),
414759a0cc5SAnish Bhatt 		&csk->daddr6.sin6_addr, ntohs(csk->daddr.sin_port),
415759a0cc5SAnish Bhatt 		csk->rss_qid);
416759a0cc5SAnish Bhatt 
4177b36b6e0Skxie@chelsio.com 	cxgb4_l2t_send(csk->cdev->ports[csk->port_id], skb, csk->l2t);
4187b36b6e0Skxie@chelsio.com }
419f42bb57cSAnish Bhatt #endif
4207b36b6e0Skxie@chelsio.com 
4217b36b6e0Skxie@chelsio.com static void send_close_req(struct cxgbi_sock *csk)
4227b36b6e0Skxie@chelsio.com {
4237b36b6e0Skxie@chelsio.com 	struct sk_buff *skb = csk->cpl_close;
4247b36b6e0Skxie@chelsio.com 	struct cpl_close_con_req *req = (struct cpl_close_con_req *)skb->head;
4257b36b6e0Skxie@chelsio.com 	unsigned int tid = csk->tid;
4267b36b6e0Skxie@chelsio.com 
4277b36b6e0Skxie@chelsio.com 	log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
4287b36b6e0Skxie@chelsio.com 		"csk 0x%p,%u,0x%lx, tid %u.\n",
4297b36b6e0Skxie@chelsio.com 		csk, csk->state, csk->flags, csk->tid);
4307b36b6e0Skxie@chelsio.com 	csk->cpl_close = NULL;
4317b36b6e0Skxie@chelsio.com 	set_wr_txq(skb, CPL_PRIORITY_DATA, csk->port_id);
4327b36b6e0Skxie@chelsio.com 	INIT_TP_WR(req, tid);
4337b36b6e0Skxie@chelsio.com 	OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_CLOSE_CON_REQ, tid));
4347b36b6e0Skxie@chelsio.com 	req->rsvd = 0;
4357b36b6e0Skxie@chelsio.com 
4367b36b6e0Skxie@chelsio.com 	cxgbi_sock_skb_entail(csk, skb);
4377b36b6e0Skxie@chelsio.com 	if (csk->state >= CTP_ESTABLISHED)
4387b36b6e0Skxie@chelsio.com 		push_tx_frames(csk, 1);
4397b36b6e0Skxie@chelsio.com }
4407b36b6e0Skxie@chelsio.com 
4417b36b6e0Skxie@chelsio.com static void abort_arp_failure(void *handle, struct sk_buff *skb)
4427b36b6e0Skxie@chelsio.com {
4437b36b6e0Skxie@chelsio.com 	struct cxgbi_sock *csk = (struct cxgbi_sock *)handle;
4447b36b6e0Skxie@chelsio.com 	struct cpl_abort_req *req;
4457b36b6e0Skxie@chelsio.com 
4467b36b6e0Skxie@chelsio.com 	log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
4477b36b6e0Skxie@chelsio.com 		"csk 0x%p,%u,0x%lx, tid %u, abort.\n",
4487b36b6e0Skxie@chelsio.com 		csk, csk->state, csk->flags, csk->tid);
4497b36b6e0Skxie@chelsio.com 	req = (struct cpl_abort_req *)skb->data;
4507b36b6e0Skxie@chelsio.com 	req->cmd = CPL_ABORT_NO_RST;
4517b36b6e0Skxie@chelsio.com 	cxgb4_ofld_send(csk->cdev->ports[csk->port_id], skb);
4527b36b6e0Skxie@chelsio.com }
4537b36b6e0Skxie@chelsio.com 
4547b36b6e0Skxie@chelsio.com static void send_abort_req(struct cxgbi_sock *csk)
4557b36b6e0Skxie@chelsio.com {
4567b36b6e0Skxie@chelsio.com 	struct cpl_abort_req *req;
4577b36b6e0Skxie@chelsio.com 	struct sk_buff *skb = csk->cpl_abort_req;
4587b36b6e0Skxie@chelsio.com 
4597b36b6e0Skxie@chelsio.com 	if (unlikely(csk->state == CTP_ABORTING) || !skb || !csk->cdev)
4607b36b6e0Skxie@chelsio.com 		return;
46164bfead8SKaren Xie 
46264bfead8SKaren Xie 	if (!cxgbi_sock_flag(csk, CTPF_TX_DATA_SENT)) {
46364bfead8SKaren Xie 		send_tx_flowc_wr(csk);
46464bfead8SKaren Xie 		cxgbi_sock_set_flag(csk, CTPF_TX_DATA_SENT);
46564bfead8SKaren Xie 	}
46664bfead8SKaren Xie 
4677b36b6e0Skxie@chelsio.com 	cxgbi_sock_set_state(csk, CTP_ABORTING);
4687b36b6e0Skxie@chelsio.com 	cxgbi_sock_set_flag(csk, CTPF_ABORT_RPL_PENDING);
4697b36b6e0Skxie@chelsio.com 	cxgbi_sock_purge_write_queue(csk);
4707b36b6e0Skxie@chelsio.com 
4717b36b6e0Skxie@chelsio.com 	csk->cpl_abort_req = NULL;
4727b36b6e0Skxie@chelsio.com 	req = (struct cpl_abort_req *)skb->head;
4732126bc5eSKaren Xie 	set_wr_txq(skb, CPL_PRIORITY_DATA, csk->port_id);
4747b36b6e0Skxie@chelsio.com 	req->cmd = CPL_ABORT_SEND_RST;
4757b36b6e0Skxie@chelsio.com 	t4_set_arp_err_handler(skb, csk, abort_arp_failure);
4767b36b6e0Skxie@chelsio.com 	INIT_TP_WR(req, csk->tid);
4777b36b6e0Skxie@chelsio.com 	OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_ABORT_REQ, csk->tid));
4787b36b6e0Skxie@chelsio.com 	req->rsvd0 = htonl(csk->snd_nxt);
4797b36b6e0Skxie@chelsio.com 	req->rsvd1 = !cxgbi_sock_flag(csk, CTPF_TX_DATA_SENT);
4807b36b6e0Skxie@chelsio.com 
4817b36b6e0Skxie@chelsio.com 	log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
4827b36b6e0Skxie@chelsio.com 		"csk 0x%p,%u,0x%lx,%u, snd_nxt %u, 0x%x.\n",
4837b36b6e0Skxie@chelsio.com 		csk, csk->state, csk->flags, csk->tid, csk->snd_nxt,
4847b36b6e0Skxie@chelsio.com 		req->rsvd1);
4857b36b6e0Skxie@chelsio.com 
4867b36b6e0Skxie@chelsio.com 	cxgb4_l2t_send(csk->cdev->ports[csk->port_id], skb, csk->l2t);
4877b36b6e0Skxie@chelsio.com }
4887b36b6e0Skxie@chelsio.com 
4897b36b6e0Skxie@chelsio.com static void send_abort_rpl(struct cxgbi_sock *csk, int rst_status)
4907b36b6e0Skxie@chelsio.com {
4917b36b6e0Skxie@chelsio.com 	struct sk_buff *skb = csk->cpl_abort_rpl;
4927b36b6e0Skxie@chelsio.com 	struct cpl_abort_rpl *rpl = (struct cpl_abort_rpl *)skb->head;
4937b36b6e0Skxie@chelsio.com 
4947b36b6e0Skxie@chelsio.com 	log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
4957b36b6e0Skxie@chelsio.com 		"csk 0x%p,%u,0x%lx,%u, status %d.\n",
4967b36b6e0Skxie@chelsio.com 		csk, csk->state, csk->flags, csk->tid, rst_status);
4977b36b6e0Skxie@chelsio.com 
4987b36b6e0Skxie@chelsio.com 	csk->cpl_abort_rpl = NULL;
4992126bc5eSKaren Xie 	set_wr_txq(skb, CPL_PRIORITY_DATA, csk->port_id);
5007b36b6e0Skxie@chelsio.com 	INIT_TP_WR(rpl, csk->tid);
5017b36b6e0Skxie@chelsio.com 	OPCODE_TID(rpl) = cpu_to_be32(MK_OPCODE_TID(CPL_ABORT_RPL, csk->tid));
5027b36b6e0Skxie@chelsio.com 	rpl->cmd = rst_status;
5037b36b6e0Skxie@chelsio.com 	cxgb4_ofld_send(csk->cdev->ports[csk->port_id], skb);
5047b36b6e0Skxie@chelsio.com }
5057b36b6e0Skxie@chelsio.com 
5067b36b6e0Skxie@chelsio.com /*
5077b36b6e0Skxie@chelsio.com  * CPL connection rx data ack: host ->
5087b36b6e0Skxie@chelsio.com  * Send RX credits through an RX_DATA_ACK CPL message. Returns the number of
5097b36b6e0Skxie@chelsio.com  * credits sent.
5107b36b6e0Skxie@chelsio.com  */
5117b36b6e0Skxie@chelsio.com static u32 send_rx_credits(struct cxgbi_sock *csk, u32 credits)
5127b36b6e0Skxie@chelsio.com {
5137b36b6e0Skxie@chelsio.com 	struct sk_buff *skb;
5147b36b6e0Skxie@chelsio.com 	struct cpl_rx_data_ack *req;
5157b36b6e0Skxie@chelsio.com 
5167b36b6e0Skxie@chelsio.com 	log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_PDU_RX,
5177b36b6e0Skxie@chelsio.com 		"csk 0x%p,%u,0x%lx,%u, credit %u.\n",
5187b36b6e0Skxie@chelsio.com 		csk, csk->state, csk->flags, csk->tid, credits);
5197b36b6e0Skxie@chelsio.com 
52024d3f95aSkxie@chelsio.com 	skb = alloc_wr(sizeof(*req), 0, GFP_ATOMIC);
5217b36b6e0Skxie@chelsio.com 	if (!skb) {
5227b36b6e0Skxie@chelsio.com 		pr_info("csk 0x%p, credit %u, OOM.\n", csk, credits);
5237b36b6e0Skxie@chelsio.com 		return 0;
5247b36b6e0Skxie@chelsio.com 	}
5257b36b6e0Skxie@chelsio.com 	req = (struct cpl_rx_data_ack *)skb->head;
5267b36b6e0Skxie@chelsio.com 
5277b36b6e0Skxie@chelsio.com 	set_wr_txq(skb, CPL_PRIORITY_ACK, csk->port_id);
5287b36b6e0Skxie@chelsio.com 	INIT_TP_WR(req, csk->tid);
5297b36b6e0Skxie@chelsio.com 	OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_RX_DATA_ACK,
5307b36b6e0Skxie@chelsio.com 				      csk->tid));
531d7990b0cSAnish Bhatt 	req->credit_dack = cpu_to_be32(RX_CREDITS_V(credits)
532d7990b0cSAnish Bhatt 				       | RX_FORCE_ACK_F);
5337b36b6e0Skxie@chelsio.com 	cxgb4_ofld_send(csk->cdev->ports[csk->port_id], skb);
5347b36b6e0Skxie@chelsio.com 	return credits;
5357b36b6e0Skxie@chelsio.com }
5367b36b6e0Skxie@chelsio.com 
5377b36b6e0Skxie@chelsio.com /*
5387b36b6e0Skxie@chelsio.com  * sgl_len - calculates the size of an SGL of the given capacity
5397b36b6e0Skxie@chelsio.com  * @n: the number of SGL entries
5407b36b6e0Skxie@chelsio.com  * Calculates the number of flits needed for a scatter/gather list that
5417b36b6e0Skxie@chelsio.com  * can hold the given number of entries.
5427b36b6e0Skxie@chelsio.com  */
5437b36b6e0Skxie@chelsio.com static inline unsigned int sgl_len(unsigned int n)
5447b36b6e0Skxie@chelsio.com {
5457b36b6e0Skxie@chelsio.com 	n--;
5467b36b6e0Skxie@chelsio.com 	return (3 * n) / 2 + (n & 1) + 2;
5477b36b6e0Skxie@chelsio.com }
5487b36b6e0Skxie@chelsio.com 
5497b36b6e0Skxie@chelsio.com /*
5507b36b6e0Skxie@chelsio.com  * calc_tx_flits_ofld - calculate # of flits for an offload packet
5517b36b6e0Skxie@chelsio.com  * @skb: the packet
5527b36b6e0Skxie@chelsio.com  *
5537b36b6e0Skxie@chelsio.com  * Returns the number of flits needed for the given offload packet.
5547b36b6e0Skxie@chelsio.com  * These packets are already fully constructed and no additional headers
5557b36b6e0Skxie@chelsio.com  * will be added.
5567b36b6e0Skxie@chelsio.com  */
5577b36b6e0Skxie@chelsio.com static inline unsigned int calc_tx_flits_ofld(const struct sk_buff *skb)
5587b36b6e0Skxie@chelsio.com {
5597b36b6e0Skxie@chelsio.com 	unsigned int flits, cnt;
5607b36b6e0Skxie@chelsio.com 
5617b36b6e0Skxie@chelsio.com 	if (is_ofld_imm(skb))
5627b36b6e0Skxie@chelsio.com 		return DIV_ROUND_UP(skb->len, 8);
5637b36b6e0Skxie@chelsio.com 	flits = skb_transport_offset(skb) / 8;
5647b36b6e0Skxie@chelsio.com 	cnt = skb_shinfo(skb)->nr_frags;
565499e2e6fSIsaku Yamahata 	if (skb_tail_pointer(skb) != skb_transport_header(skb))
5667b36b6e0Skxie@chelsio.com 		cnt++;
5677b36b6e0Skxie@chelsio.com 	return flits + sgl_len(cnt);
5687b36b6e0Skxie@chelsio.com }
5697b36b6e0Skxie@chelsio.com 
57064bfead8SKaren Xie #define FLOWC_WR_NPARAMS_MIN	9
57164bfead8SKaren Xie static inline int tx_flowc_wr_credits(int *nparamsp, int *flowclenp)
57264bfead8SKaren Xie {
57364bfead8SKaren Xie 	int nparams, flowclen16, flowclen;
57464bfead8SKaren Xie 
57564bfead8SKaren Xie 	nparams = FLOWC_WR_NPARAMS_MIN;
57664bfead8SKaren Xie 	flowclen = offsetof(struct fw_flowc_wr, mnemval[nparams]);
57764bfead8SKaren Xie 	flowclen16 = DIV_ROUND_UP(flowclen, 16);
57864bfead8SKaren Xie 	flowclen = flowclen16 * 16;
57964bfead8SKaren Xie 	/*
58064bfead8SKaren Xie 	 * Return the number of 16-byte credits used by the FlowC request.
58164bfead8SKaren Xie 	 * Pass back the nparams and actual FlowC length if requested.
58264bfead8SKaren Xie 	 */
58364bfead8SKaren Xie 	if (nparamsp)
58464bfead8SKaren Xie 		*nparamsp = nparams;
58564bfead8SKaren Xie 	if (flowclenp)
58664bfead8SKaren Xie 		*flowclenp = flowclen;
58764bfead8SKaren Xie 
58864bfead8SKaren Xie 	return flowclen16;
58964bfead8SKaren Xie }
59064bfead8SKaren Xie 
59164bfead8SKaren Xie static inline int send_tx_flowc_wr(struct cxgbi_sock *csk)
5927b36b6e0Skxie@chelsio.com {
5937b36b6e0Skxie@chelsio.com 	struct sk_buff *skb;
5947b36b6e0Skxie@chelsio.com 	struct fw_flowc_wr *flowc;
59564bfead8SKaren Xie 	int nparams, flowclen16, flowclen;
5967b36b6e0Skxie@chelsio.com 
59764bfead8SKaren Xie 	flowclen16 = tx_flowc_wr_credits(&nparams, &flowclen);
59824d3f95aSkxie@chelsio.com 	skb = alloc_wr(flowclen, 0, GFP_ATOMIC);
5997b36b6e0Skxie@chelsio.com 	flowc = (struct fw_flowc_wr *)skb->head;
6007b36b6e0Skxie@chelsio.com 	flowc->op_to_nparams =
60164bfead8SKaren Xie 		htonl(FW_WR_OP_V(FW_FLOWC_WR) | FW_FLOWC_WR_NPARAMS_V(nparams));
6027b36b6e0Skxie@chelsio.com 	flowc->flowid_len16 =
60364bfead8SKaren Xie 		htonl(FW_WR_LEN16_V(flowclen16) | FW_WR_FLOWID_V(csk->tid));
6047b36b6e0Skxie@chelsio.com 	flowc->mnemval[0].mnemonic = FW_FLOWC_MNEM_PFNVFN;
605e27d6169Skxie@chelsio.com 	flowc->mnemval[0].val = htonl(csk->cdev->pfvf);
6067b36b6e0Skxie@chelsio.com 	flowc->mnemval[1].mnemonic = FW_FLOWC_MNEM_CH;
6077b36b6e0Skxie@chelsio.com 	flowc->mnemval[1].val = htonl(csk->tx_chan);
6087b36b6e0Skxie@chelsio.com 	flowc->mnemval[2].mnemonic = FW_FLOWC_MNEM_PORT;
6097b36b6e0Skxie@chelsio.com 	flowc->mnemval[2].val = htonl(csk->tx_chan);
6107b36b6e0Skxie@chelsio.com 	flowc->mnemval[3].mnemonic = FW_FLOWC_MNEM_IQID;
6117b36b6e0Skxie@chelsio.com 	flowc->mnemval[3].val = htonl(csk->rss_qid);
6127b36b6e0Skxie@chelsio.com 	flowc->mnemval[4].mnemonic = FW_FLOWC_MNEM_SNDNXT;
6137b36b6e0Skxie@chelsio.com 	flowc->mnemval[4].val = htonl(csk->snd_nxt);
6147b36b6e0Skxie@chelsio.com 	flowc->mnemval[5].mnemonic = FW_FLOWC_MNEM_RCVNXT;
6157b36b6e0Skxie@chelsio.com 	flowc->mnemval[5].val = htonl(csk->rcv_nxt);
6167b36b6e0Skxie@chelsio.com 	flowc->mnemval[6].mnemonic = FW_FLOWC_MNEM_SNDBUF;
61781daf10cSKaren Xie 	flowc->mnemval[6].val = htonl(csk->snd_win);
6187b36b6e0Skxie@chelsio.com 	flowc->mnemval[7].mnemonic = FW_FLOWC_MNEM_MSS;
6197b36b6e0Skxie@chelsio.com 	flowc->mnemval[7].val = htonl(csk->advmss);
6207b36b6e0Skxie@chelsio.com 	flowc->mnemval[8].mnemonic = 0;
6217b36b6e0Skxie@chelsio.com 	flowc->mnemval[8].val = 0;
62264bfead8SKaren Xie 	flowc->mnemval[8].mnemonic = FW_FLOWC_MNEM_TXDATAPLEN_MAX;
62364bfead8SKaren Xie 	flowc->mnemval[8].val = 16384;
62464bfead8SKaren Xie 
6252126bc5eSKaren Xie 	set_wr_txq(skb, CPL_PRIORITY_DATA, csk->port_id);
6267b36b6e0Skxie@chelsio.com 
6277b36b6e0Skxie@chelsio.com 	log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
6287b36b6e0Skxie@chelsio.com 		"csk 0x%p, tid 0x%x, %u,%u,%u,%u,%u,%u,%u.\n",
6297b36b6e0Skxie@chelsio.com 		csk, csk->tid, 0, csk->tx_chan, csk->rss_qid,
63081daf10cSKaren Xie 		csk->snd_nxt, csk->rcv_nxt, csk->snd_win,
6317b36b6e0Skxie@chelsio.com 		csk->advmss);
6327b36b6e0Skxie@chelsio.com 
6337b36b6e0Skxie@chelsio.com 	cxgb4_ofld_send(csk->cdev->ports[csk->port_id], skb);
63464bfead8SKaren Xie 
63564bfead8SKaren Xie 	return flowclen16;
6367b36b6e0Skxie@chelsio.com }
6377b36b6e0Skxie@chelsio.com 
6387b36b6e0Skxie@chelsio.com static inline void make_tx_data_wr(struct cxgbi_sock *csk, struct sk_buff *skb,
6397b36b6e0Skxie@chelsio.com 				   int dlen, int len, u32 credits, int compl)
6407b36b6e0Skxie@chelsio.com {
6417b36b6e0Skxie@chelsio.com 	struct fw_ofld_tx_data_wr *req;
6427b36b6e0Skxie@chelsio.com 	unsigned int submode = cxgbi_skcb_ulp_mode(skb) & 3;
643e2ac9628SHariprasad Shenai 	unsigned int wr_ulp_mode = 0, val;
6447857c62aSKaren Xie 	bool imm = is_ofld_imm(skb);
6457b36b6e0Skxie@chelsio.com 
6467b36b6e0Skxie@chelsio.com 	req = (struct fw_ofld_tx_data_wr *)__skb_push(skb, sizeof(*req));
6477b36b6e0Skxie@chelsio.com 
6487857c62aSKaren Xie 	if (imm) {
649e2ac9628SHariprasad Shenai 		req->op_to_immdlen = htonl(FW_WR_OP_V(FW_OFLD_TX_DATA_WR) |
650e2ac9628SHariprasad Shenai 					FW_WR_COMPL_F |
651e2ac9628SHariprasad Shenai 					FW_WR_IMMDLEN_V(dlen));
652e2ac9628SHariprasad Shenai 		req->flowid_len16 = htonl(FW_WR_FLOWID_V(csk->tid) |
653e2ac9628SHariprasad Shenai 						FW_WR_LEN16_V(credits));
6547b36b6e0Skxie@chelsio.com 	} else {
6557b36b6e0Skxie@chelsio.com 		req->op_to_immdlen =
656e2ac9628SHariprasad Shenai 			cpu_to_be32(FW_WR_OP_V(FW_OFLD_TX_DATA_WR) |
657e2ac9628SHariprasad Shenai 					FW_WR_COMPL_F |
658e2ac9628SHariprasad Shenai 					FW_WR_IMMDLEN_V(0));
6597b36b6e0Skxie@chelsio.com 		req->flowid_len16 =
660e2ac9628SHariprasad Shenai 			cpu_to_be32(FW_WR_FLOWID_V(csk->tid) |
661e2ac9628SHariprasad Shenai 					FW_WR_LEN16_V(credits));
6627b36b6e0Skxie@chelsio.com 	}
6637b36b6e0Skxie@chelsio.com 	if (submode)
664e2ac9628SHariprasad Shenai 		wr_ulp_mode = FW_OFLD_TX_DATA_WR_ULPMODE_V(ULP2_MODE_ISCSI) |
665e2ac9628SHariprasad Shenai 				FW_OFLD_TX_DATA_WR_ULPSUBMODE_V(submode);
666e2ac9628SHariprasad Shenai 	val = skb_peek(&csk->write_queue) ? 0 : 1;
6676aca4112SKaren Xie 	req->tunnel_to_proxy = htonl(wr_ulp_mode |
668e2ac9628SHariprasad Shenai 				     FW_OFLD_TX_DATA_WR_SHOVE_V(val));
6697b36b6e0Skxie@chelsio.com 	req->plen = htonl(len);
6707b36b6e0Skxie@chelsio.com 	if (!cxgbi_sock_flag(csk, CTPF_TX_DATA_SENT))
6717b36b6e0Skxie@chelsio.com 		cxgbi_sock_set_flag(csk, CTPF_TX_DATA_SENT);
6727b36b6e0Skxie@chelsio.com }
6737b36b6e0Skxie@chelsio.com 
6747b36b6e0Skxie@chelsio.com static void arp_failure_skb_discard(void *handle, struct sk_buff *skb)
6757b36b6e0Skxie@chelsio.com {
6767b36b6e0Skxie@chelsio.com 	kfree_skb(skb);
6777b36b6e0Skxie@chelsio.com }
6787b36b6e0Skxie@chelsio.com 
6797b36b6e0Skxie@chelsio.com static int push_tx_frames(struct cxgbi_sock *csk, int req_completion)
6807b36b6e0Skxie@chelsio.com {
6817b36b6e0Skxie@chelsio.com 	int total_size = 0;
6827b36b6e0Skxie@chelsio.com 	struct sk_buff *skb;
6837b36b6e0Skxie@chelsio.com 
6847b36b6e0Skxie@chelsio.com 	if (unlikely(csk->state < CTP_ESTABLISHED ||
6857b36b6e0Skxie@chelsio.com 		csk->state == CTP_CLOSE_WAIT_1 || csk->state >= CTP_ABORTING)) {
6867b36b6e0Skxie@chelsio.com 		log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK |
6877b36b6e0Skxie@chelsio.com 			 1 << CXGBI_DBG_PDU_TX,
6887b36b6e0Skxie@chelsio.com 			"csk 0x%p,%u,0x%lx,%u, in closing state.\n",
6897b36b6e0Skxie@chelsio.com 			csk, csk->state, csk->flags, csk->tid);
6907b36b6e0Skxie@chelsio.com 		return 0;
6917b36b6e0Skxie@chelsio.com 	}
6927b36b6e0Skxie@chelsio.com 
6937b36b6e0Skxie@chelsio.com 	while (csk->wr_cred && (skb = skb_peek(&csk->write_queue)) != NULL) {
6947b36b6e0Skxie@chelsio.com 		int dlen = skb->len;
6957b36b6e0Skxie@chelsio.com 		int len = skb->len;
6967b36b6e0Skxie@chelsio.com 		unsigned int credits_needed;
69764bfead8SKaren Xie 		int flowclen16 = 0;
6987b36b6e0Skxie@chelsio.com 
6997b36b6e0Skxie@chelsio.com 		skb_reset_transport_header(skb);
7007b36b6e0Skxie@chelsio.com 		if (is_ofld_imm(skb))
70184944d8cSKaren Xie 			credits_needed = DIV_ROUND_UP(dlen, 16);
7027b36b6e0Skxie@chelsio.com 		else
70384944d8cSKaren Xie 			credits_needed = DIV_ROUND_UP(
70484944d8cSKaren Xie 						8 * calc_tx_flits_ofld(skb),
70584944d8cSKaren Xie 						16);
70684944d8cSKaren Xie 
70784944d8cSKaren Xie 		if (likely(cxgbi_skcb_test_flag(skb, SKCBF_TX_NEED_HDR)))
70884944d8cSKaren Xie 			credits_needed += DIV_ROUND_UP(
70984944d8cSKaren Xie 					sizeof(struct fw_ofld_tx_data_wr),
7107b36b6e0Skxie@chelsio.com 					16);
7117b36b6e0Skxie@chelsio.com 
71264bfead8SKaren Xie 		/*
71364bfead8SKaren Xie 		 * Assumes the initial credits is large enough to support
71464bfead8SKaren Xie 		 * fw_flowc_wr plus largest possible first payload
71564bfead8SKaren Xie 		 */
71664bfead8SKaren Xie 		if (!cxgbi_sock_flag(csk, CTPF_TX_DATA_SENT)) {
71764bfead8SKaren Xie 			flowclen16 = send_tx_flowc_wr(csk);
71864bfead8SKaren Xie 			csk->wr_cred -= flowclen16;
71964bfead8SKaren Xie 			csk->wr_una_cred += flowclen16;
72064bfead8SKaren Xie 			cxgbi_sock_set_flag(csk, CTPF_TX_DATA_SENT);
72164bfead8SKaren Xie 		}
72264bfead8SKaren Xie 
7237b36b6e0Skxie@chelsio.com 		if (csk->wr_cred < credits_needed) {
7247b36b6e0Skxie@chelsio.com 			log_debug(1 << CXGBI_DBG_PDU_TX,
7257b36b6e0Skxie@chelsio.com 				"csk 0x%p, skb %u/%u, wr %d < %u.\n",
7267b36b6e0Skxie@chelsio.com 				csk, skb->len, skb->data_len,
7277b36b6e0Skxie@chelsio.com 				credits_needed, csk->wr_cred);
7287b36b6e0Skxie@chelsio.com 			break;
7297b36b6e0Skxie@chelsio.com 		}
7307b36b6e0Skxie@chelsio.com 		__skb_unlink(skb, &csk->write_queue);
7312126bc5eSKaren Xie 		set_wr_txq(skb, CPL_PRIORITY_DATA, csk->port_id);
73264bfead8SKaren Xie 		skb->csum = credits_needed + flowclen16;
7337b36b6e0Skxie@chelsio.com 		csk->wr_cred -= credits_needed;
7347b36b6e0Skxie@chelsio.com 		csk->wr_una_cred += credits_needed;
7357b36b6e0Skxie@chelsio.com 		cxgbi_sock_enqueue_wr(csk, skb);
7367b36b6e0Skxie@chelsio.com 
7377b36b6e0Skxie@chelsio.com 		log_debug(1 << CXGBI_DBG_PDU_TX,
7387b36b6e0Skxie@chelsio.com 			"csk 0x%p, skb %u/%u, wr %d, left %u, unack %u.\n",
7397b36b6e0Skxie@chelsio.com 			csk, skb->len, skb->data_len, credits_needed,
7407b36b6e0Skxie@chelsio.com 			csk->wr_cred, csk->wr_una_cred);
7417b36b6e0Skxie@chelsio.com 
7427b36b6e0Skxie@chelsio.com 		if (likely(cxgbi_skcb_test_flag(skb, SKCBF_TX_NEED_HDR))) {
7437b36b6e0Skxie@chelsio.com 			len += cxgbi_ulp_extra_len(cxgbi_skcb_ulp_mode(skb));
7447b36b6e0Skxie@chelsio.com 			make_tx_data_wr(csk, skb, dlen, len, credits_needed,
7457b36b6e0Skxie@chelsio.com 					req_completion);
7467b36b6e0Skxie@chelsio.com 			csk->snd_nxt += len;
7477b36b6e0Skxie@chelsio.com 			cxgbi_skcb_clear_flag(skb, SKCBF_TX_NEED_HDR);
748fe9b34bfSVarun Prakash 		} else if (cxgbi_skcb_test_flag(skb, SKCBF_TX_FLAG_COMPL) &&
749fe9b34bfSVarun Prakash 			   (csk->wr_una_cred >= (csk->wr_max_cred / 2))) {
750fe9b34bfSVarun Prakash 			struct cpl_close_con_req *req =
751fe9b34bfSVarun Prakash 				(struct cpl_close_con_req *)skb->data;
752fe9b34bfSVarun Prakash 			req->wr.wr_hi |= htonl(FW_WR_COMPL_F);
7537b36b6e0Skxie@chelsio.com 		}
7547b36b6e0Skxie@chelsio.com 		total_size += skb->truesize;
7557b36b6e0Skxie@chelsio.com 		t4_set_arp_err_handler(skb, csk, arp_failure_skb_discard);
7567b36b6e0Skxie@chelsio.com 
7577b36b6e0Skxie@chelsio.com 		log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_PDU_TX,
7587b36b6e0Skxie@chelsio.com 			"csk 0x%p,%u,0x%lx,%u, skb 0x%p, %u.\n",
7597b36b6e0Skxie@chelsio.com 			csk, csk->state, csk->flags, csk->tid, skb, len);
7607b36b6e0Skxie@chelsio.com 
7617b36b6e0Skxie@chelsio.com 		cxgb4_l2t_send(csk->cdev->ports[csk->port_id], skb, csk->l2t);
7627b36b6e0Skxie@chelsio.com 	}
7637b36b6e0Skxie@chelsio.com 	return total_size;
7647b36b6e0Skxie@chelsio.com }
7657b36b6e0Skxie@chelsio.com 
7667b36b6e0Skxie@chelsio.com static inline void free_atid(struct cxgbi_sock *csk)
7677b36b6e0Skxie@chelsio.com {
7687b36b6e0Skxie@chelsio.com 	struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(csk->cdev);
7697b36b6e0Skxie@chelsio.com 
7707b36b6e0Skxie@chelsio.com 	if (cxgbi_sock_flag(csk, CTPF_HAS_ATID)) {
7717b36b6e0Skxie@chelsio.com 		cxgb4_free_atid(lldi->tids, csk->atid);
7727b36b6e0Skxie@chelsio.com 		cxgbi_sock_clear_flag(csk, CTPF_HAS_ATID);
7737b36b6e0Skxie@chelsio.com 		cxgbi_sock_put(csk);
7747b36b6e0Skxie@chelsio.com 	}
7757b36b6e0Skxie@chelsio.com }
7767b36b6e0Skxie@chelsio.com 
7777b36b6e0Skxie@chelsio.com static void do_act_establish(struct cxgbi_device *cdev, struct sk_buff *skb)
7787b36b6e0Skxie@chelsio.com {
7797b36b6e0Skxie@chelsio.com 	struct cxgbi_sock *csk;
7807b36b6e0Skxie@chelsio.com 	struct cpl_act_establish *req = (struct cpl_act_establish *)skb->data;
7817b36b6e0Skxie@chelsio.com 	unsigned short tcp_opt = ntohs(req->tcp_opt);
7827b36b6e0Skxie@chelsio.com 	unsigned int tid = GET_TID(req);
7836c53e938SHariprasad Shenai 	unsigned int atid = TID_TID_G(ntohl(req->tos_atid));
7847b36b6e0Skxie@chelsio.com 	struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(cdev);
7857b36b6e0Skxie@chelsio.com 	struct tid_info *t = lldi->tids;
7867b36b6e0Skxie@chelsio.com 	u32 rcv_isn = be32_to_cpu(req->rcv_isn);
7877b36b6e0Skxie@chelsio.com 
7887b36b6e0Skxie@chelsio.com 	csk = lookup_atid(t, atid);
7897b36b6e0Skxie@chelsio.com 	if (unlikely(!csk)) {
7907b36b6e0Skxie@chelsio.com 		pr_err("NO conn. for atid %u, cdev 0x%p.\n", atid, cdev);
7917b36b6e0Skxie@chelsio.com 		goto rel_skb;
7927b36b6e0Skxie@chelsio.com 	}
7937b36b6e0Skxie@chelsio.com 
794e27d6169Skxie@chelsio.com 	if (csk->atid != atid) {
795e27d6169Skxie@chelsio.com 		pr_err("bad conn atid %u, csk 0x%p,%u,0x%lx,tid %u, atid %u.\n",
796e27d6169Skxie@chelsio.com 			atid, csk, csk->state, csk->flags, csk->tid, csk->atid);
797e27d6169Skxie@chelsio.com 		goto rel_skb;
798e27d6169Skxie@chelsio.com 	}
799e27d6169Skxie@chelsio.com 
800759a0cc5SAnish Bhatt 	pr_info_ipaddr("atid 0x%x, tid 0x%x, csk 0x%p,%u,0x%lx, isn %u.\n",
801759a0cc5SAnish Bhatt 		       (&csk->saddr), (&csk->daddr),
802759a0cc5SAnish Bhatt 		       atid, tid, csk, csk->state, csk->flags, rcv_isn);
803759a0cc5SAnish Bhatt 
8041fe1fdb0SVarun Prakash 	module_put(cdev->owner);
8057b36b6e0Skxie@chelsio.com 
8067b36b6e0Skxie@chelsio.com 	cxgbi_sock_get(csk);
8077b36b6e0Skxie@chelsio.com 	csk->tid = tid;
8087b36b6e0Skxie@chelsio.com 	cxgb4_insert_tid(lldi->tids, csk, tid);
8097b36b6e0Skxie@chelsio.com 	cxgbi_sock_set_flag(csk, CTPF_HAS_TID);
8107b36b6e0Skxie@chelsio.com 
8117b36b6e0Skxie@chelsio.com 	free_atid(csk);
8127b36b6e0Skxie@chelsio.com 
8137b36b6e0Skxie@chelsio.com 	spin_lock_bh(&csk->lock);
8147b36b6e0Skxie@chelsio.com 	if (unlikely(csk->state != CTP_ACTIVE_OPEN))
8157b36b6e0Skxie@chelsio.com 		pr_info("csk 0x%p,%u,0x%lx,%u, got EST.\n",
8167b36b6e0Skxie@chelsio.com 			csk, csk->state, csk->flags, csk->tid);
8177b36b6e0Skxie@chelsio.com 
8187b36b6e0Skxie@chelsio.com 	if (csk->retry_timer.function) {
8197b36b6e0Skxie@chelsio.com 		del_timer(&csk->retry_timer);
8207b36b6e0Skxie@chelsio.com 		csk->retry_timer.function = NULL;
8217b36b6e0Skxie@chelsio.com 	}
8227b36b6e0Skxie@chelsio.com 
8237b36b6e0Skxie@chelsio.com 	csk->copied_seq = csk->rcv_wup = csk->rcv_nxt = rcv_isn;
8247b36b6e0Skxie@chelsio.com 	/*
8257b36b6e0Skxie@chelsio.com 	 * Causes the first RX_DATA_ACK to supply any Rx credits we couldn't
8267b36b6e0Skxie@chelsio.com 	 * pass through opt0.
8277b36b6e0Skxie@chelsio.com 	 */
82881daf10cSKaren Xie 	if (csk->rcv_win > (RCV_BUFSIZ_MASK << 10))
82981daf10cSKaren Xie 		csk->rcv_wup -= csk->rcv_win - (RCV_BUFSIZ_MASK << 10);
8307b36b6e0Skxie@chelsio.com 
8316c53e938SHariprasad Shenai 	csk->advmss = lldi->mtus[TCPOPT_MSS_G(tcp_opt)] - 40;
8326c53e938SHariprasad Shenai 	if (TCPOPT_TSTAMP_G(tcp_opt))
8337b36b6e0Skxie@chelsio.com 		csk->advmss -= 12;
8347b36b6e0Skxie@chelsio.com 	if (csk->advmss < 128)
8357b36b6e0Skxie@chelsio.com 		csk->advmss = 128;
8367b36b6e0Skxie@chelsio.com 
8377b36b6e0Skxie@chelsio.com 	log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
8387b36b6e0Skxie@chelsio.com 		"csk 0x%p, mss_idx %u, advmss %u.\n",
8396c53e938SHariprasad Shenai 			csk, TCPOPT_MSS_G(tcp_opt), csk->advmss);
8407b36b6e0Skxie@chelsio.com 
8417b36b6e0Skxie@chelsio.com 	cxgbi_sock_established(csk, ntohl(req->snd_isn), ntohs(req->tcp_opt));
8427b36b6e0Skxie@chelsio.com 
8437b36b6e0Skxie@chelsio.com 	if (unlikely(cxgbi_sock_flag(csk, CTPF_ACTIVE_CLOSE_NEEDED)))
8447b36b6e0Skxie@chelsio.com 		send_abort_req(csk);
8457b36b6e0Skxie@chelsio.com 	else {
8467b36b6e0Skxie@chelsio.com 		if (skb_queue_len(&csk->write_queue))
8477b36b6e0Skxie@chelsio.com 			push_tx_frames(csk, 0);
8487b36b6e0Skxie@chelsio.com 		cxgbi_conn_tx_open(csk);
8497b36b6e0Skxie@chelsio.com 	}
8507b36b6e0Skxie@chelsio.com 	spin_unlock_bh(&csk->lock);
8517b36b6e0Skxie@chelsio.com 
8527b36b6e0Skxie@chelsio.com rel_skb:
8537b36b6e0Skxie@chelsio.com 	__kfree_skb(skb);
8547b36b6e0Skxie@chelsio.com }
8557b36b6e0Skxie@chelsio.com 
8567b36b6e0Skxie@chelsio.com static int act_open_rpl_status_to_errno(int status)
8577b36b6e0Skxie@chelsio.com {
8587b36b6e0Skxie@chelsio.com 	switch (status) {
8597b36b6e0Skxie@chelsio.com 	case CPL_ERR_CONN_RESET:
8607b36b6e0Skxie@chelsio.com 		return -ECONNREFUSED;
8617b36b6e0Skxie@chelsio.com 	case CPL_ERR_ARP_MISS:
8627b36b6e0Skxie@chelsio.com 		return -EHOSTUNREACH;
8637b36b6e0Skxie@chelsio.com 	case CPL_ERR_CONN_TIMEDOUT:
8647b36b6e0Skxie@chelsio.com 		return -ETIMEDOUT;
8657b36b6e0Skxie@chelsio.com 	case CPL_ERR_TCAM_FULL:
8667b36b6e0Skxie@chelsio.com 		return -ENOMEM;
8677b36b6e0Skxie@chelsio.com 	case CPL_ERR_CONN_EXIST:
8687b36b6e0Skxie@chelsio.com 		return -EADDRINUSE;
8697b36b6e0Skxie@chelsio.com 	default:
8707b36b6e0Skxie@chelsio.com 		return -EIO;
8717b36b6e0Skxie@chelsio.com 	}
8727b36b6e0Skxie@chelsio.com }
8737b36b6e0Skxie@chelsio.com 
8747b36b6e0Skxie@chelsio.com static void csk_act_open_retry_timer(unsigned long data)
8757b36b6e0Skxie@chelsio.com {
876001586a7SAnish Bhatt 	struct sk_buff *skb = NULL;
8777b36b6e0Skxie@chelsio.com 	struct cxgbi_sock *csk = (struct cxgbi_sock *)data;
8783bd3e8bfSKaren Xie 	struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(csk->cdev);
879759a0cc5SAnish Bhatt 	void (*send_act_open_func)(struct cxgbi_sock *, struct sk_buff *,
880759a0cc5SAnish Bhatt 				   struct l2t_entry *);
881759a0cc5SAnish Bhatt 	int t4 = is_t4(lldi->adapter_type), size, size6;
8827b36b6e0Skxie@chelsio.com 
8837b36b6e0Skxie@chelsio.com 	log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
8847b36b6e0Skxie@chelsio.com 		"csk 0x%p,%u,0x%lx,%u.\n",
8857b36b6e0Skxie@chelsio.com 		csk, csk->state, csk->flags, csk->tid);
8867b36b6e0Skxie@chelsio.com 
8877b36b6e0Skxie@chelsio.com 	cxgbi_sock_get(csk);
8887b36b6e0Skxie@chelsio.com 	spin_lock_bh(&csk->lock);
889759a0cc5SAnish Bhatt 
890759a0cc5SAnish Bhatt 	if (t4) {
891759a0cc5SAnish Bhatt 		size = sizeof(struct cpl_act_open_req);
892759a0cc5SAnish Bhatt 		size6 = sizeof(struct cpl_act_open_req6);
893759a0cc5SAnish Bhatt 	} else {
894759a0cc5SAnish Bhatt 		size = sizeof(struct cpl_t5_act_open_req);
895759a0cc5SAnish Bhatt 		size6 = sizeof(struct cpl_t5_act_open_req6);
896759a0cc5SAnish Bhatt 	}
897759a0cc5SAnish Bhatt 
898759a0cc5SAnish Bhatt 	if (csk->csk_family == AF_INET) {
899759a0cc5SAnish Bhatt 		send_act_open_func = send_act_open_req;
900759a0cc5SAnish Bhatt 		skb = alloc_wr(size, 0, GFP_ATOMIC);
901f42bb57cSAnish Bhatt #if IS_ENABLED(CONFIG_IPV6)
902759a0cc5SAnish Bhatt 	} else {
903759a0cc5SAnish Bhatt 		send_act_open_func = send_act_open_req6;
904759a0cc5SAnish Bhatt 		skb = alloc_wr(size6, 0, GFP_ATOMIC);
905f42bb57cSAnish Bhatt #endif
906759a0cc5SAnish Bhatt 	}
907759a0cc5SAnish Bhatt 
9087b36b6e0Skxie@chelsio.com 	if (!skb)
9097b36b6e0Skxie@chelsio.com 		cxgbi_sock_fail_act_open(csk, -ENOMEM);
9107b36b6e0Skxie@chelsio.com 	else {
9117b36b6e0Skxie@chelsio.com 		skb->sk = (struct sock *)csk;
9127b36b6e0Skxie@chelsio.com 		t4_set_arp_err_handler(skb, csk,
9137b36b6e0Skxie@chelsio.com 				       cxgbi_sock_act_open_req_arp_failure);
914759a0cc5SAnish Bhatt 		send_act_open_func(csk, skb, csk->l2t);
9157b36b6e0Skxie@chelsio.com 	}
916759a0cc5SAnish Bhatt 
9177b36b6e0Skxie@chelsio.com 	spin_unlock_bh(&csk->lock);
9187b36b6e0Skxie@chelsio.com 	cxgbi_sock_put(csk);
919759a0cc5SAnish Bhatt 
9207b36b6e0Skxie@chelsio.com }
9217b36b6e0Skxie@chelsio.com 
922928567adSKaren Xie static inline bool is_neg_adv(unsigned int status)
923928567adSKaren Xie {
924928567adSKaren Xie 	return status == CPL_ERR_RTX_NEG_ADVICE ||
925928567adSKaren Xie 		status == CPL_ERR_KEEPALV_NEG_ADVICE ||
926928567adSKaren Xie 		status == CPL_ERR_PERSIST_NEG_ADVICE;
927928567adSKaren Xie }
928928567adSKaren Xie 
9297b36b6e0Skxie@chelsio.com static void do_act_open_rpl(struct cxgbi_device *cdev, struct sk_buff *skb)
9307b36b6e0Skxie@chelsio.com {
9317b36b6e0Skxie@chelsio.com 	struct cxgbi_sock *csk;
9327b36b6e0Skxie@chelsio.com 	struct cpl_act_open_rpl *rpl = (struct cpl_act_open_rpl *)skb->data;
9337b36b6e0Skxie@chelsio.com 	unsigned int tid = GET_TID(rpl);
9347b36b6e0Skxie@chelsio.com 	unsigned int atid =
9356c53e938SHariprasad Shenai 		TID_TID_G(AOPEN_ATID_G(be32_to_cpu(rpl->atid_status)));
9366c53e938SHariprasad Shenai 	unsigned int status = AOPEN_STATUS_G(be32_to_cpu(rpl->atid_status));
9377b36b6e0Skxie@chelsio.com 	struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(cdev);
9387b36b6e0Skxie@chelsio.com 	struct tid_info *t = lldi->tids;
9397b36b6e0Skxie@chelsio.com 
9407b36b6e0Skxie@chelsio.com 	csk = lookup_atid(t, atid);
9417b36b6e0Skxie@chelsio.com 	if (unlikely(!csk)) {
9427b36b6e0Skxie@chelsio.com 		pr_err("NO matching conn. atid %u, tid %u.\n", atid, tid);
9437b36b6e0Skxie@chelsio.com 		goto rel_skb;
9447b36b6e0Skxie@chelsio.com 	}
9457b36b6e0Skxie@chelsio.com 
946759a0cc5SAnish Bhatt 	pr_info_ipaddr("tid %u/%u, status %u.\n"
947759a0cc5SAnish Bhatt 		       "csk 0x%p,%u,0x%lx. ", (&csk->saddr), (&csk->daddr),
948e27d6169Skxie@chelsio.com 		       atid, tid, status, csk, csk->state, csk->flags);
9497b36b6e0Skxie@chelsio.com 
950928567adSKaren Xie 	if (is_neg_adv(status))
951150cca7cSKaren Xie 		goto rel_skb;
952150cca7cSKaren Xie 
9531fe1fdb0SVarun Prakash 	module_put(cdev->owner);
954ee7255adSAnish Bhatt 
9557b36b6e0Skxie@chelsio.com 	if (status && status != CPL_ERR_TCAM_FULL &&
9567b36b6e0Skxie@chelsio.com 	    status != CPL_ERR_CONN_EXIST &&
9577b36b6e0Skxie@chelsio.com 	    status != CPL_ERR_ARP_MISS)
9587b36b6e0Skxie@chelsio.com 		cxgb4_remove_tid(lldi->tids, csk->port_id, GET_TID(rpl));
9597b36b6e0Skxie@chelsio.com 
9607b36b6e0Skxie@chelsio.com 	cxgbi_sock_get(csk);
9617b36b6e0Skxie@chelsio.com 	spin_lock_bh(&csk->lock);
9627b36b6e0Skxie@chelsio.com 
9637b36b6e0Skxie@chelsio.com 	if (status == CPL_ERR_CONN_EXIST &&
9647b36b6e0Skxie@chelsio.com 	    csk->retry_timer.function != csk_act_open_retry_timer) {
9657b36b6e0Skxie@chelsio.com 		csk->retry_timer.function = csk_act_open_retry_timer;
9667b36b6e0Skxie@chelsio.com 		mod_timer(&csk->retry_timer, jiffies + HZ / 2);
9677b36b6e0Skxie@chelsio.com 	} else
9687b36b6e0Skxie@chelsio.com 		cxgbi_sock_fail_act_open(csk,
9697b36b6e0Skxie@chelsio.com 					act_open_rpl_status_to_errno(status));
9707b36b6e0Skxie@chelsio.com 
9717b36b6e0Skxie@chelsio.com 	spin_unlock_bh(&csk->lock);
9727b36b6e0Skxie@chelsio.com 	cxgbi_sock_put(csk);
9737b36b6e0Skxie@chelsio.com rel_skb:
9747b36b6e0Skxie@chelsio.com 	__kfree_skb(skb);
9757b36b6e0Skxie@chelsio.com }
9767b36b6e0Skxie@chelsio.com 
9777b36b6e0Skxie@chelsio.com static void do_peer_close(struct cxgbi_device *cdev, struct sk_buff *skb)
9787b36b6e0Skxie@chelsio.com {
9797b36b6e0Skxie@chelsio.com 	struct cxgbi_sock *csk;
9807b36b6e0Skxie@chelsio.com 	struct cpl_peer_close *req = (struct cpl_peer_close *)skb->data;
9817b36b6e0Skxie@chelsio.com 	unsigned int tid = GET_TID(req);
9827b36b6e0Skxie@chelsio.com 	struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(cdev);
9837b36b6e0Skxie@chelsio.com 	struct tid_info *t = lldi->tids;
9847b36b6e0Skxie@chelsio.com 
9857b36b6e0Skxie@chelsio.com 	csk = lookup_tid(t, tid);
9867b36b6e0Skxie@chelsio.com 	if (unlikely(!csk)) {
9877b36b6e0Skxie@chelsio.com 		pr_err("can't find connection for tid %u.\n", tid);
9887b36b6e0Skxie@chelsio.com 		goto rel_skb;
9897b36b6e0Skxie@chelsio.com 	}
990759a0cc5SAnish Bhatt 	pr_info_ipaddr("csk 0x%p,%u,0x%lx,%u.\n",
991759a0cc5SAnish Bhatt 		       (&csk->saddr), (&csk->daddr),
9927b36b6e0Skxie@chelsio.com 		       csk, csk->state, csk->flags, csk->tid);
9937b36b6e0Skxie@chelsio.com 	cxgbi_sock_rcv_peer_close(csk);
9947b36b6e0Skxie@chelsio.com rel_skb:
9957b36b6e0Skxie@chelsio.com 	__kfree_skb(skb);
9967b36b6e0Skxie@chelsio.com }
9977b36b6e0Skxie@chelsio.com 
9987b36b6e0Skxie@chelsio.com static void do_close_con_rpl(struct cxgbi_device *cdev, struct sk_buff *skb)
9997b36b6e0Skxie@chelsio.com {
10007b36b6e0Skxie@chelsio.com 	struct cxgbi_sock *csk;
10017b36b6e0Skxie@chelsio.com 	struct cpl_close_con_rpl *rpl = (struct cpl_close_con_rpl *)skb->data;
10027b36b6e0Skxie@chelsio.com 	unsigned int tid = GET_TID(rpl);
10037b36b6e0Skxie@chelsio.com 	struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(cdev);
10047b36b6e0Skxie@chelsio.com 	struct tid_info *t = lldi->tids;
10057b36b6e0Skxie@chelsio.com 
10067b36b6e0Skxie@chelsio.com 	csk = lookup_tid(t, tid);
10077b36b6e0Skxie@chelsio.com 	if (unlikely(!csk)) {
10087b36b6e0Skxie@chelsio.com 		pr_err("can't find connection for tid %u.\n", tid);
10097b36b6e0Skxie@chelsio.com 		goto rel_skb;
10107b36b6e0Skxie@chelsio.com 	}
1011759a0cc5SAnish Bhatt 	pr_info_ipaddr("csk 0x%p,%u,0x%lx,%u.\n",
1012759a0cc5SAnish Bhatt 		       (&csk->saddr), (&csk->daddr),
10137b36b6e0Skxie@chelsio.com 		       csk, csk->state, csk->flags, csk->tid);
10147b36b6e0Skxie@chelsio.com 	cxgbi_sock_rcv_close_conn_rpl(csk, ntohl(rpl->snd_nxt));
10157b36b6e0Skxie@chelsio.com rel_skb:
10167b36b6e0Skxie@chelsio.com 	__kfree_skb(skb);
10177b36b6e0Skxie@chelsio.com }
10187b36b6e0Skxie@chelsio.com 
10197b36b6e0Skxie@chelsio.com static int abort_status_to_errno(struct cxgbi_sock *csk, int abort_reason,
10207b36b6e0Skxie@chelsio.com 								int *need_rst)
10217b36b6e0Skxie@chelsio.com {
10227b36b6e0Skxie@chelsio.com 	switch (abort_reason) {
10237b36b6e0Skxie@chelsio.com 	case CPL_ERR_BAD_SYN: /* fall through */
10247b36b6e0Skxie@chelsio.com 	case CPL_ERR_CONN_RESET:
10257b36b6e0Skxie@chelsio.com 		return csk->state > CTP_ESTABLISHED ?
10267b36b6e0Skxie@chelsio.com 			-EPIPE : -ECONNRESET;
10277b36b6e0Skxie@chelsio.com 	case CPL_ERR_XMIT_TIMEDOUT:
10287b36b6e0Skxie@chelsio.com 	case CPL_ERR_PERSIST_TIMEDOUT:
10297b36b6e0Skxie@chelsio.com 	case CPL_ERR_FINWAIT2_TIMEDOUT:
10307b36b6e0Skxie@chelsio.com 	case CPL_ERR_KEEPALIVE_TIMEDOUT:
10317b36b6e0Skxie@chelsio.com 		return -ETIMEDOUT;
10327b36b6e0Skxie@chelsio.com 	default:
10337b36b6e0Skxie@chelsio.com 		return -EIO;
10347b36b6e0Skxie@chelsio.com 	}
10357b36b6e0Skxie@chelsio.com }
10367b36b6e0Skxie@chelsio.com 
10377b36b6e0Skxie@chelsio.com static void do_abort_req_rss(struct cxgbi_device *cdev, struct sk_buff *skb)
10387b36b6e0Skxie@chelsio.com {
10397b36b6e0Skxie@chelsio.com 	struct cxgbi_sock *csk;
10407b36b6e0Skxie@chelsio.com 	struct cpl_abort_req_rss *req = (struct cpl_abort_req_rss *)skb->data;
10417b36b6e0Skxie@chelsio.com 	unsigned int tid = GET_TID(req);
10427b36b6e0Skxie@chelsio.com 	struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(cdev);
10437b36b6e0Skxie@chelsio.com 	struct tid_info *t = lldi->tids;
10447b36b6e0Skxie@chelsio.com 	int rst_status = CPL_ABORT_NO_RST;
10457b36b6e0Skxie@chelsio.com 
10467b36b6e0Skxie@chelsio.com 	csk = lookup_tid(t, tid);
10477b36b6e0Skxie@chelsio.com 	if (unlikely(!csk)) {
10487b36b6e0Skxie@chelsio.com 		pr_err("can't find connection for tid %u.\n", tid);
10497b36b6e0Skxie@chelsio.com 		goto rel_skb;
10507b36b6e0Skxie@chelsio.com 	}
10517b36b6e0Skxie@chelsio.com 
1052759a0cc5SAnish Bhatt 	pr_info_ipaddr("csk 0x%p,%u,0x%lx,%u, status %u.\n",
1053759a0cc5SAnish Bhatt 		       (&csk->saddr), (&csk->daddr),
10547b36b6e0Skxie@chelsio.com 		       csk, csk->state, csk->flags, csk->tid, req->status);
10557b36b6e0Skxie@chelsio.com 
1056928567adSKaren Xie 	if (is_neg_adv(req->status))
10577b36b6e0Skxie@chelsio.com 		goto rel_skb;
10587b36b6e0Skxie@chelsio.com 
10597b36b6e0Skxie@chelsio.com 	cxgbi_sock_get(csk);
10607b36b6e0Skxie@chelsio.com 	spin_lock_bh(&csk->lock);
10617b36b6e0Skxie@chelsio.com 
10627b07bf24SAnish Bhatt 	cxgbi_sock_clear_flag(csk, CTPF_ABORT_REQ_RCVD);
10637b07bf24SAnish Bhatt 
10647b07bf24SAnish Bhatt 	if (!cxgbi_sock_flag(csk, CTPF_TX_DATA_SENT)) {
10657b07bf24SAnish Bhatt 		send_tx_flowc_wr(csk);
10667b07bf24SAnish Bhatt 		cxgbi_sock_set_flag(csk, CTPF_TX_DATA_SENT);
10677b36b6e0Skxie@chelsio.com 	}
10687b36b6e0Skxie@chelsio.com 
10697b07bf24SAnish Bhatt 	cxgbi_sock_set_flag(csk, CTPF_ABORT_REQ_RCVD);
10707b07bf24SAnish Bhatt 	cxgbi_sock_set_state(csk, CTP_ABORTING);
10717b07bf24SAnish Bhatt 
10727b36b6e0Skxie@chelsio.com 	send_abort_rpl(csk, rst_status);
10737b36b6e0Skxie@chelsio.com 
10747b36b6e0Skxie@chelsio.com 	if (!cxgbi_sock_flag(csk, CTPF_ABORT_RPL_PENDING)) {
10757b36b6e0Skxie@chelsio.com 		csk->err = abort_status_to_errno(csk, req->status, &rst_status);
10767b36b6e0Skxie@chelsio.com 		cxgbi_sock_closed(csk);
10777b36b6e0Skxie@chelsio.com 	}
10787b07bf24SAnish Bhatt 
10797b36b6e0Skxie@chelsio.com 	spin_unlock_bh(&csk->lock);
10807b36b6e0Skxie@chelsio.com 	cxgbi_sock_put(csk);
10817b36b6e0Skxie@chelsio.com rel_skb:
10827b36b6e0Skxie@chelsio.com 	__kfree_skb(skb);
10837b36b6e0Skxie@chelsio.com }
10847b36b6e0Skxie@chelsio.com 
10857b36b6e0Skxie@chelsio.com static void do_abort_rpl_rss(struct cxgbi_device *cdev, struct sk_buff *skb)
10867b36b6e0Skxie@chelsio.com {
10877b36b6e0Skxie@chelsio.com 	struct cxgbi_sock *csk;
10887b36b6e0Skxie@chelsio.com 	struct cpl_abort_rpl_rss *rpl = (struct cpl_abort_rpl_rss *)skb->data;
10897b36b6e0Skxie@chelsio.com 	unsigned int tid = GET_TID(rpl);
10907b36b6e0Skxie@chelsio.com 	struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(cdev);
10917b36b6e0Skxie@chelsio.com 	struct tid_info *t = lldi->tids;
10927b36b6e0Skxie@chelsio.com 
10937b36b6e0Skxie@chelsio.com 	csk = lookup_tid(t, tid);
10947b36b6e0Skxie@chelsio.com 	if (!csk)
10957b36b6e0Skxie@chelsio.com 		goto rel_skb;
10967b36b6e0Skxie@chelsio.com 
1097759a0cc5SAnish Bhatt 	if (csk)
1098759a0cc5SAnish Bhatt 		pr_info_ipaddr("csk 0x%p,%u,0x%lx,%u, status %u.\n",
1099759a0cc5SAnish Bhatt 			       (&csk->saddr), (&csk->daddr), csk,
1100759a0cc5SAnish Bhatt 			       csk->state, csk->flags, csk->tid, rpl->status);
11017b36b6e0Skxie@chelsio.com 
11027b36b6e0Skxie@chelsio.com 	if (rpl->status == CPL_ERR_ABORT_FAILED)
11037b36b6e0Skxie@chelsio.com 		goto rel_skb;
11047b36b6e0Skxie@chelsio.com 
11057b36b6e0Skxie@chelsio.com 	cxgbi_sock_rcv_abort_rpl(csk);
11067b36b6e0Skxie@chelsio.com rel_skb:
11077b36b6e0Skxie@chelsio.com 	__kfree_skb(skb);
11087b36b6e0Skxie@chelsio.com }
11097b36b6e0Skxie@chelsio.com 
1110f7bcd2e1SKaren Xie static void do_rx_data(struct cxgbi_device *cdev, struct sk_buff *skb)
1111f7bcd2e1SKaren Xie {
1112f7bcd2e1SKaren Xie 	struct cxgbi_sock *csk;
1113f7bcd2e1SKaren Xie 	struct cpl_rx_data *cpl = (struct cpl_rx_data *)skb->data;
1114f7bcd2e1SKaren Xie 	unsigned int tid = GET_TID(cpl);
1115f7bcd2e1SKaren Xie 	struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(cdev);
1116f7bcd2e1SKaren Xie 	struct tid_info *t = lldi->tids;
1117f7bcd2e1SKaren Xie 
1118f7bcd2e1SKaren Xie 	csk = lookup_tid(t, tid);
1119f7bcd2e1SKaren Xie 	if (!csk) {
1120f7bcd2e1SKaren Xie 		pr_err("can't find connection for tid %u.\n", tid);
1121f7bcd2e1SKaren Xie 	} else {
1122f7bcd2e1SKaren Xie 		/* not expecting this, reset the connection. */
1123f7bcd2e1SKaren Xie 		pr_err("csk 0x%p, tid %u, rcv cpl_rx_data.\n", csk, tid);
1124f7bcd2e1SKaren Xie 		spin_lock_bh(&csk->lock);
1125f7bcd2e1SKaren Xie 		send_abort_req(csk);
1126f7bcd2e1SKaren Xie 		spin_unlock_bh(&csk->lock);
1127f7bcd2e1SKaren Xie 	}
1128f7bcd2e1SKaren Xie 	__kfree_skb(skb);
1129f7bcd2e1SKaren Xie }
1130f7bcd2e1SKaren Xie 
11317b36b6e0Skxie@chelsio.com static void do_rx_iscsi_hdr(struct cxgbi_device *cdev, struct sk_buff *skb)
11327b36b6e0Skxie@chelsio.com {
11337b36b6e0Skxie@chelsio.com 	struct cxgbi_sock *csk;
11347b36b6e0Skxie@chelsio.com 	struct cpl_iscsi_hdr *cpl = (struct cpl_iscsi_hdr *)skb->data;
11357b36b6e0Skxie@chelsio.com 	unsigned short pdu_len_ddp = be16_to_cpu(cpl->pdu_len_ddp);
11367b36b6e0Skxie@chelsio.com 	unsigned int tid = GET_TID(cpl);
11377b36b6e0Skxie@chelsio.com 	struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(cdev);
11387b36b6e0Skxie@chelsio.com 	struct tid_info *t = lldi->tids;
11397b36b6e0Skxie@chelsio.com 
11407b36b6e0Skxie@chelsio.com 	csk = lookup_tid(t, tid);
11417b36b6e0Skxie@chelsio.com 	if (unlikely(!csk)) {
11427b36b6e0Skxie@chelsio.com 		pr_err("can't find conn. for tid %u.\n", tid);
11437b36b6e0Skxie@chelsio.com 		goto rel_skb;
11447b36b6e0Skxie@chelsio.com 	}
11457b36b6e0Skxie@chelsio.com 
11467b36b6e0Skxie@chelsio.com 	log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_PDU_RX,
11477b36b6e0Skxie@chelsio.com 		"csk 0x%p,%u,0x%lx, tid %u, skb 0x%p,%u, 0x%x.\n",
11487b36b6e0Skxie@chelsio.com 		csk, csk->state, csk->flags, csk->tid, skb, skb->len,
11497b36b6e0Skxie@chelsio.com 		pdu_len_ddp);
11507b36b6e0Skxie@chelsio.com 
11517b36b6e0Skxie@chelsio.com 	spin_lock_bh(&csk->lock);
11527b36b6e0Skxie@chelsio.com 
11537b36b6e0Skxie@chelsio.com 	if (unlikely(csk->state >= CTP_PASSIVE_CLOSE)) {
11547b36b6e0Skxie@chelsio.com 		log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
11557b36b6e0Skxie@chelsio.com 			"csk 0x%p,%u,0x%lx,%u, bad state.\n",
11567b36b6e0Skxie@chelsio.com 			csk, csk->state, csk->flags, csk->tid);
11577b36b6e0Skxie@chelsio.com 		if (csk->state != CTP_ABORTING)
11587b36b6e0Skxie@chelsio.com 			goto abort_conn;
11597b36b6e0Skxie@chelsio.com 		else
11607b36b6e0Skxie@chelsio.com 			goto discard;
11617b36b6e0Skxie@chelsio.com 	}
11627b36b6e0Skxie@chelsio.com 
11637b36b6e0Skxie@chelsio.com 	cxgbi_skcb_tcp_seq(skb) = ntohl(cpl->seq);
1164e27d6169Skxie@chelsio.com 	cxgbi_skcb_flags(skb) = 0;
1165e27d6169Skxie@chelsio.com 
11667b36b6e0Skxie@chelsio.com 	skb_reset_transport_header(skb);
11677b36b6e0Skxie@chelsio.com 	__skb_pull(skb, sizeof(*cpl));
11687b36b6e0Skxie@chelsio.com 	__pskb_trim(skb, ntohs(cpl->len));
11697b36b6e0Skxie@chelsio.com 
11707b36b6e0Skxie@chelsio.com 	if (!csk->skb_ulp_lhdr) {
11717b36b6e0Skxie@chelsio.com 		unsigned char *bhs;
11723bd3e8bfSKaren Xie 		unsigned int hlen, dlen, plen;
11737b36b6e0Skxie@chelsio.com 
11747b36b6e0Skxie@chelsio.com 		log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_PDU_RX,
11757b36b6e0Skxie@chelsio.com 			"csk 0x%p,%u,0x%lx, tid %u, skb 0x%p header.\n",
11767b36b6e0Skxie@chelsio.com 			csk, csk->state, csk->flags, csk->tid, skb);
11777b36b6e0Skxie@chelsio.com 		csk->skb_ulp_lhdr = skb;
1178e27d6169Skxie@chelsio.com 		cxgbi_skcb_set_flag(skb, SKCBF_RX_HDR);
11797b36b6e0Skxie@chelsio.com 
1180e27d6169Skxie@chelsio.com 		if (cxgbi_skcb_tcp_seq(skb) != csk->rcv_nxt) {
11817b36b6e0Skxie@chelsio.com 			pr_info("tid %u, CPL_ISCSI_HDR, bad seq, 0x%x/0x%x.\n",
1182e27d6169Skxie@chelsio.com 				csk->tid, cxgbi_skcb_tcp_seq(skb),
11837b36b6e0Skxie@chelsio.com 				csk->rcv_nxt);
11847b36b6e0Skxie@chelsio.com 			goto abort_conn;
11857b36b6e0Skxie@chelsio.com 		}
11867b36b6e0Skxie@chelsio.com 
1187e27d6169Skxie@chelsio.com 		bhs = skb->data;
11887b36b6e0Skxie@chelsio.com 		hlen = ntohs(cpl->len);
11897b36b6e0Skxie@chelsio.com 		dlen = ntohl(*(unsigned int *)(bhs + 4)) & 0xFFFFFF;
11907b36b6e0Skxie@chelsio.com 
1191bdc590b9SHariprasad Shenai 		plen = ISCSI_PDU_LEN_G(pdu_len_ddp);
11923bd3e8bfSKaren Xie 		if (is_t4(lldi->adapter_type))
11933bd3e8bfSKaren Xie 			plen -= 40;
11943bd3e8bfSKaren Xie 
11953bd3e8bfSKaren Xie 		if ((hlen + dlen) != plen) {
11967b36b6e0Skxie@chelsio.com 			pr_info("tid 0x%x, CPL_ISCSI_HDR, pdu len "
11977b36b6e0Skxie@chelsio.com 				"mismatch %u != %u + %u, seq 0x%x.\n",
11983bd3e8bfSKaren Xie 				csk->tid, plen, hlen, dlen,
11993bd3e8bfSKaren Xie 				cxgbi_skcb_tcp_seq(skb));
12007b36b6e0Skxie@chelsio.com 			goto abort_conn;
12017b36b6e0Skxie@chelsio.com 		}
12027b36b6e0Skxie@chelsio.com 
12037b36b6e0Skxie@chelsio.com 		cxgbi_skcb_rx_pdulen(skb) = (hlen + dlen + 3) & (~0x3);
12047b36b6e0Skxie@chelsio.com 		if (dlen)
12057b36b6e0Skxie@chelsio.com 			cxgbi_skcb_rx_pdulen(skb) += csk->dcrc_len;
12067b36b6e0Skxie@chelsio.com 		csk->rcv_nxt += cxgbi_skcb_rx_pdulen(skb);
12077b36b6e0Skxie@chelsio.com 
12087b36b6e0Skxie@chelsio.com 		log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_PDU_RX,
12097b36b6e0Skxie@chelsio.com 			"csk 0x%p, skb 0x%p, 0x%x,%u+%u,0x%x,0x%x.\n",
12107b36b6e0Skxie@chelsio.com 			csk, skb, *bhs, hlen, dlen,
12117b36b6e0Skxie@chelsio.com 			ntohl(*((unsigned int *)(bhs + 16))),
12127b36b6e0Skxie@chelsio.com 			ntohl(*((unsigned int *)(bhs + 24))));
12137b36b6e0Skxie@chelsio.com 
12147b36b6e0Skxie@chelsio.com 	} else {
1215e27d6169Skxie@chelsio.com 		struct sk_buff *lskb = csk->skb_ulp_lhdr;
12167b36b6e0Skxie@chelsio.com 
1217e27d6169Skxie@chelsio.com 		cxgbi_skcb_set_flag(lskb, SKCBF_RX_DATA);
12187b36b6e0Skxie@chelsio.com 		log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_PDU_RX,
12197b36b6e0Skxie@chelsio.com 			"csk 0x%p,%u,0x%lx, skb 0x%p data, 0x%p.\n",
12207b36b6e0Skxie@chelsio.com 			csk, csk->state, csk->flags, skb, lskb);
12217b36b6e0Skxie@chelsio.com 	}
12227b36b6e0Skxie@chelsio.com 
12237b36b6e0Skxie@chelsio.com 	__skb_queue_tail(&csk->receive_queue, skb);
12247b36b6e0Skxie@chelsio.com 	spin_unlock_bh(&csk->lock);
12257b36b6e0Skxie@chelsio.com 	return;
12267b36b6e0Skxie@chelsio.com 
12277b36b6e0Skxie@chelsio.com abort_conn:
12287b36b6e0Skxie@chelsio.com 	send_abort_req(csk);
12297b36b6e0Skxie@chelsio.com discard:
12307b36b6e0Skxie@chelsio.com 	spin_unlock_bh(&csk->lock);
12317b36b6e0Skxie@chelsio.com rel_skb:
12327b36b6e0Skxie@chelsio.com 	__kfree_skb(skb);
12337b36b6e0Skxie@chelsio.com }
12347b36b6e0Skxie@chelsio.com 
123544830d8fSVarun Prakash static void do_rx_iscsi_data(struct cxgbi_device *cdev, struct sk_buff *skb)
123644830d8fSVarun Prakash {
123744830d8fSVarun Prakash 	struct cxgbi_sock *csk;
123844830d8fSVarun Prakash 	struct cpl_iscsi_hdr *cpl = (struct cpl_iscsi_hdr *)skb->data;
123944830d8fSVarun Prakash 	struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(cdev);
124044830d8fSVarun Prakash 	struct tid_info *t = lldi->tids;
124144830d8fSVarun Prakash 	struct sk_buff *lskb;
124244830d8fSVarun Prakash 	u32 tid = GET_TID(cpl);
124344830d8fSVarun Prakash 	u16 pdu_len_ddp = be16_to_cpu(cpl->pdu_len_ddp);
124444830d8fSVarun Prakash 
124544830d8fSVarun Prakash 	csk = lookup_tid(t, tid);
124644830d8fSVarun Prakash 	if (unlikely(!csk)) {
124744830d8fSVarun Prakash 		pr_err("can't find conn. for tid %u.\n", tid);
124844830d8fSVarun Prakash 		goto rel_skb;
124944830d8fSVarun Prakash 	}
125044830d8fSVarun Prakash 
125144830d8fSVarun Prakash 	log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_PDU_RX,
125244830d8fSVarun Prakash 		  "csk 0x%p,%u,0x%lx, tid %u, skb 0x%p,%u, 0x%x.\n",
125344830d8fSVarun Prakash 		  csk, csk->state, csk->flags, csk->tid, skb,
125444830d8fSVarun Prakash 		  skb->len, pdu_len_ddp);
125544830d8fSVarun Prakash 
125644830d8fSVarun Prakash 	spin_lock_bh(&csk->lock);
125744830d8fSVarun Prakash 
125844830d8fSVarun Prakash 	if (unlikely(csk->state >= CTP_PASSIVE_CLOSE)) {
125944830d8fSVarun Prakash 		log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
126044830d8fSVarun Prakash 			  "csk 0x%p,%u,0x%lx,%u, bad state.\n",
126144830d8fSVarun Prakash 			  csk, csk->state, csk->flags, csk->tid);
126244830d8fSVarun Prakash 
126344830d8fSVarun Prakash 		if (csk->state != CTP_ABORTING)
126444830d8fSVarun Prakash 			goto abort_conn;
126544830d8fSVarun Prakash 		else
126644830d8fSVarun Prakash 			goto discard;
126744830d8fSVarun Prakash 	}
126844830d8fSVarun Prakash 
126944830d8fSVarun Prakash 	cxgbi_skcb_tcp_seq(skb) = be32_to_cpu(cpl->seq);
127044830d8fSVarun Prakash 	cxgbi_skcb_flags(skb) = 0;
127144830d8fSVarun Prakash 
127244830d8fSVarun Prakash 	skb_reset_transport_header(skb);
127344830d8fSVarun Prakash 	__skb_pull(skb, sizeof(*cpl));
127444830d8fSVarun Prakash 	__pskb_trim(skb, ntohs(cpl->len));
127544830d8fSVarun Prakash 
127644830d8fSVarun Prakash 	if (!csk->skb_ulp_lhdr)
127744830d8fSVarun Prakash 		csk->skb_ulp_lhdr = skb;
127844830d8fSVarun Prakash 
127944830d8fSVarun Prakash 	lskb = csk->skb_ulp_lhdr;
128044830d8fSVarun Prakash 	cxgbi_skcb_set_flag(lskb, SKCBF_RX_DATA);
128144830d8fSVarun Prakash 
128244830d8fSVarun Prakash 	log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_PDU_RX,
128344830d8fSVarun Prakash 		  "csk 0x%p,%u,0x%lx, skb 0x%p data, 0x%p.\n",
128444830d8fSVarun Prakash 		  csk, csk->state, csk->flags, skb, lskb);
128544830d8fSVarun Prakash 
128644830d8fSVarun Prakash 	__skb_queue_tail(&csk->receive_queue, skb);
128744830d8fSVarun Prakash 	spin_unlock_bh(&csk->lock);
128844830d8fSVarun Prakash 	return;
128944830d8fSVarun Prakash 
129044830d8fSVarun Prakash abort_conn:
129144830d8fSVarun Prakash 	send_abort_req(csk);
129244830d8fSVarun Prakash discard:
129344830d8fSVarun Prakash 	spin_unlock_bh(&csk->lock);
129444830d8fSVarun Prakash rel_skb:
129544830d8fSVarun Prakash 	__kfree_skb(skb);
129644830d8fSVarun Prakash }
129744830d8fSVarun Prakash 
129844830d8fSVarun Prakash static void
129944830d8fSVarun Prakash cxgb4i_process_ddpvld(struct cxgbi_sock *csk,
130044830d8fSVarun Prakash 		      struct sk_buff *skb, u32 ddpvld)
130144830d8fSVarun Prakash {
130244830d8fSVarun Prakash 	if (ddpvld & (1 << CPL_RX_DDP_STATUS_HCRC_SHIFT)) {
130344830d8fSVarun Prakash 		pr_info("csk 0x%p, lhdr 0x%p, status 0x%x, hcrc bad 0x%lx.\n",
130444830d8fSVarun Prakash 			csk, skb, ddpvld, cxgbi_skcb_flags(skb));
130544830d8fSVarun Prakash 		cxgbi_skcb_set_flag(skb, SKCBF_RX_HCRC_ERR);
130644830d8fSVarun Prakash 	}
130744830d8fSVarun Prakash 
130844830d8fSVarun Prakash 	if (ddpvld & (1 << CPL_RX_DDP_STATUS_DCRC_SHIFT)) {
130944830d8fSVarun Prakash 		pr_info("csk 0x%p, lhdr 0x%p, status 0x%x, dcrc bad 0x%lx.\n",
131044830d8fSVarun Prakash 			csk, skb, ddpvld, cxgbi_skcb_flags(skb));
131144830d8fSVarun Prakash 		cxgbi_skcb_set_flag(skb, SKCBF_RX_DCRC_ERR);
131244830d8fSVarun Prakash 	}
131344830d8fSVarun Prakash 
131444830d8fSVarun Prakash 	if (ddpvld & (1 << CPL_RX_DDP_STATUS_PAD_SHIFT)) {
131544830d8fSVarun Prakash 		log_debug(1 << CXGBI_DBG_PDU_RX,
131644830d8fSVarun Prakash 			  "csk 0x%p, lhdr 0x%p, status 0x%x, pad bad.\n",
131744830d8fSVarun Prakash 			  csk, skb, ddpvld);
131844830d8fSVarun Prakash 		cxgbi_skcb_set_flag(skb, SKCBF_RX_PAD_ERR);
131944830d8fSVarun Prakash 	}
132044830d8fSVarun Prakash 
132144830d8fSVarun Prakash 	if ((ddpvld & (1 << CPL_RX_DDP_STATUS_DDP_SHIFT)) &&
132244830d8fSVarun Prakash 	    !cxgbi_skcb_test_flag(skb, SKCBF_RX_DATA)) {
132344830d8fSVarun Prakash 		log_debug(1 << CXGBI_DBG_PDU_RX,
132444830d8fSVarun Prakash 			  "csk 0x%p, lhdr 0x%p, 0x%x, data ddp'ed.\n",
132544830d8fSVarun Prakash 			  csk, skb, ddpvld);
132644830d8fSVarun Prakash 		cxgbi_skcb_set_flag(skb, SKCBF_RX_DATA_DDPD);
132744830d8fSVarun Prakash 	}
132844830d8fSVarun Prakash }
132944830d8fSVarun Prakash 
13307b36b6e0Skxie@chelsio.com static void do_rx_data_ddp(struct cxgbi_device *cdev,
13317b36b6e0Skxie@chelsio.com 				  struct sk_buff *skb)
13327b36b6e0Skxie@chelsio.com {
13337b36b6e0Skxie@chelsio.com 	struct cxgbi_sock *csk;
13347b36b6e0Skxie@chelsio.com 	struct sk_buff *lskb;
13357b36b6e0Skxie@chelsio.com 	struct cpl_rx_data_ddp *rpl = (struct cpl_rx_data_ddp *)skb->data;
13367b36b6e0Skxie@chelsio.com 	unsigned int tid = GET_TID(rpl);
13377b36b6e0Skxie@chelsio.com 	struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(cdev);
13387b36b6e0Skxie@chelsio.com 	struct tid_info *t = lldi->tids;
133944830d8fSVarun Prakash 	u32 ddpvld = be32_to_cpu(rpl->ddpvld);
13407b36b6e0Skxie@chelsio.com 
13417b36b6e0Skxie@chelsio.com 	csk = lookup_tid(t, tid);
13427b36b6e0Skxie@chelsio.com 	if (unlikely(!csk)) {
13437b36b6e0Skxie@chelsio.com 		pr_err("can't find connection for tid %u.\n", tid);
13447b36b6e0Skxie@chelsio.com 		goto rel_skb;
13457b36b6e0Skxie@chelsio.com 	}
13467b36b6e0Skxie@chelsio.com 
13477b36b6e0Skxie@chelsio.com 	log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_PDU_RX,
13487b36b6e0Skxie@chelsio.com 		"csk 0x%p,%u,0x%lx, skb 0x%p,0x%x, lhdr 0x%p.\n",
134944830d8fSVarun Prakash 		csk, csk->state, csk->flags, skb, ddpvld, csk->skb_ulp_lhdr);
13507b36b6e0Skxie@chelsio.com 
13517b36b6e0Skxie@chelsio.com 	spin_lock_bh(&csk->lock);
13527b36b6e0Skxie@chelsio.com 
13537b36b6e0Skxie@chelsio.com 	if (unlikely(csk->state >= CTP_PASSIVE_CLOSE)) {
13547b36b6e0Skxie@chelsio.com 		log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
13557b36b6e0Skxie@chelsio.com 			"csk 0x%p,%u,0x%lx,%u, bad state.\n",
13567b36b6e0Skxie@chelsio.com 			csk, csk->state, csk->flags, csk->tid);
13577b36b6e0Skxie@chelsio.com 		if (csk->state != CTP_ABORTING)
13587b36b6e0Skxie@chelsio.com 			goto abort_conn;
13597b36b6e0Skxie@chelsio.com 		else
13607b36b6e0Skxie@chelsio.com 			goto discard;
13617b36b6e0Skxie@chelsio.com 	}
13627b36b6e0Skxie@chelsio.com 
13637b36b6e0Skxie@chelsio.com 	if (!csk->skb_ulp_lhdr) {
13647b36b6e0Skxie@chelsio.com 		pr_err("tid 0x%x, rcv RX_DATA_DDP w/o pdu bhs.\n", csk->tid);
13657b36b6e0Skxie@chelsio.com 		goto abort_conn;
13667b36b6e0Skxie@chelsio.com 	}
13677b36b6e0Skxie@chelsio.com 
13687b36b6e0Skxie@chelsio.com 	lskb = csk->skb_ulp_lhdr;
13697b36b6e0Skxie@chelsio.com 	csk->skb_ulp_lhdr = NULL;
13707b36b6e0Skxie@chelsio.com 
13717b36b6e0Skxie@chelsio.com 	cxgbi_skcb_rx_ddigest(lskb) = ntohl(rpl->ulp_crc);
13727b36b6e0Skxie@chelsio.com 
13737b36b6e0Skxie@chelsio.com 	if (ntohs(rpl->len) != cxgbi_skcb_rx_pdulen(lskb))
13747b36b6e0Skxie@chelsio.com 		pr_info("tid 0x%x, RX_DATA_DDP pdulen %u != %u.\n",
13757b36b6e0Skxie@chelsio.com 			csk->tid, ntohs(rpl->len), cxgbi_skcb_rx_pdulen(lskb));
13767b36b6e0Skxie@chelsio.com 
137744830d8fSVarun Prakash 	cxgb4i_process_ddpvld(csk, lskb, ddpvld);
137844830d8fSVarun Prakash 
13797b36b6e0Skxie@chelsio.com 	log_debug(1 << CXGBI_DBG_PDU_RX,
13807b36b6e0Skxie@chelsio.com 		"csk 0x%p, lskb 0x%p, f 0x%lx.\n",
13817b36b6e0Skxie@chelsio.com 		csk, lskb, cxgbi_skcb_flags(lskb));
13827b36b6e0Skxie@chelsio.com 
1383e27d6169Skxie@chelsio.com 	cxgbi_skcb_set_flag(lskb, SKCBF_RX_STATUS);
13847b36b6e0Skxie@chelsio.com 	cxgbi_conn_pdu_ready(csk);
13857b36b6e0Skxie@chelsio.com 	spin_unlock_bh(&csk->lock);
13867b36b6e0Skxie@chelsio.com 	goto rel_skb;
13877b36b6e0Skxie@chelsio.com 
13887b36b6e0Skxie@chelsio.com abort_conn:
13897b36b6e0Skxie@chelsio.com 	send_abort_req(csk);
13907b36b6e0Skxie@chelsio.com discard:
13917b36b6e0Skxie@chelsio.com 	spin_unlock_bh(&csk->lock);
13927b36b6e0Skxie@chelsio.com rel_skb:
13937b36b6e0Skxie@chelsio.com 	__kfree_skb(skb);
13947b36b6e0Skxie@chelsio.com }
13957b36b6e0Skxie@chelsio.com 
139644830d8fSVarun Prakash static void
139744830d8fSVarun Prakash do_rx_iscsi_cmp(struct cxgbi_device *cdev, struct sk_buff *skb)
139844830d8fSVarun Prakash {
139944830d8fSVarun Prakash 	struct cxgbi_sock *csk;
140044830d8fSVarun Prakash 	struct cpl_rx_iscsi_cmp *rpl = (struct cpl_rx_iscsi_cmp *)skb->data;
140144830d8fSVarun Prakash 	struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(cdev);
140244830d8fSVarun Prakash 	struct tid_info *t = lldi->tids;
140344830d8fSVarun Prakash 	struct sk_buff *data_skb = NULL;
140444830d8fSVarun Prakash 	u32 tid = GET_TID(rpl);
140544830d8fSVarun Prakash 	u32 ddpvld = be32_to_cpu(rpl->ddpvld);
140644830d8fSVarun Prakash 	u32 seq = be32_to_cpu(rpl->seq);
140744830d8fSVarun Prakash 	u16 pdu_len_ddp = be16_to_cpu(rpl->pdu_len_ddp);
140844830d8fSVarun Prakash 
140944830d8fSVarun Prakash 	csk = lookup_tid(t, tid);
141044830d8fSVarun Prakash 	if (unlikely(!csk)) {
141144830d8fSVarun Prakash 		pr_err("can't find connection for tid %u.\n", tid);
141244830d8fSVarun Prakash 		goto rel_skb;
141344830d8fSVarun Prakash 	}
141444830d8fSVarun Prakash 
141544830d8fSVarun Prakash 	log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_PDU_RX,
141644830d8fSVarun Prakash 		  "csk 0x%p,%u,0x%lx, skb 0x%p,0x%x, lhdr 0x%p, len %u, "
141744830d8fSVarun Prakash 		  "pdu_len_ddp %u, status %u.\n",
141844830d8fSVarun Prakash 		  csk, csk->state, csk->flags, skb, ddpvld, csk->skb_ulp_lhdr,
141944830d8fSVarun Prakash 		  ntohs(rpl->len), pdu_len_ddp,  rpl->status);
142044830d8fSVarun Prakash 
142144830d8fSVarun Prakash 	spin_lock_bh(&csk->lock);
142244830d8fSVarun Prakash 
142344830d8fSVarun Prakash 	if (unlikely(csk->state >= CTP_PASSIVE_CLOSE)) {
142444830d8fSVarun Prakash 		log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
142544830d8fSVarun Prakash 			  "csk 0x%p,%u,0x%lx,%u, bad state.\n",
142644830d8fSVarun Prakash 			  csk, csk->state, csk->flags, csk->tid);
142744830d8fSVarun Prakash 
142844830d8fSVarun Prakash 		if (csk->state != CTP_ABORTING)
142944830d8fSVarun Prakash 			goto abort_conn;
143044830d8fSVarun Prakash 		else
143144830d8fSVarun Prakash 			goto discard;
143244830d8fSVarun Prakash 	}
143344830d8fSVarun Prakash 
143444830d8fSVarun Prakash 	cxgbi_skcb_tcp_seq(skb) = seq;
143544830d8fSVarun Prakash 	cxgbi_skcb_flags(skb) = 0;
143644830d8fSVarun Prakash 	cxgbi_skcb_rx_pdulen(skb) = 0;
143744830d8fSVarun Prakash 
143844830d8fSVarun Prakash 	skb_reset_transport_header(skb);
143944830d8fSVarun Prakash 	__skb_pull(skb, sizeof(*rpl));
144044830d8fSVarun Prakash 	__pskb_trim(skb, be16_to_cpu(rpl->len));
144144830d8fSVarun Prakash 
144244830d8fSVarun Prakash 	csk->rcv_nxt = seq + pdu_len_ddp;
144344830d8fSVarun Prakash 
144444830d8fSVarun Prakash 	if (csk->skb_ulp_lhdr) {
144544830d8fSVarun Prakash 		data_skb = skb_peek(&csk->receive_queue);
144644830d8fSVarun Prakash 		if (!data_skb ||
144744830d8fSVarun Prakash 		    !cxgbi_skcb_test_flag(data_skb, SKCBF_RX_DATA)) {
144844830d8fSVarun Prakash 			pr_err("Error! freelist data not found 0x%p, tid %u\n",
144944830d8fSVarun Prakash 			       data_skb, tid);
145044830d8fSVarun Prakash 
145144830d8fSVarun Prakash 			goto abort_conn;
145244830d8fSVarun Prakash 		}
145344830d8fSVarun Prakash 		__skb_unlink(data_skb, &csk->receive_queue);
145444830d8fSVarun Prakash 
145544830d8fSVarun Prakash 		cxgbi_skcb_set_flag(skb, SKCBF_RX_DATA);
145644830d8fSVarun Prakash 
145744830d8fSVarun Prakash 		__skb_queue_tail(&csk->receive_queue, skb);
145844830d8fSVarun Prakash 		__skb_queue_tail(&csk->receive_queue, data_skb);
145944830d8fSVarun Prakash 	} else {
146044830d8fSVarun Prakash 		 __skb_queue_tail(&csk->receive_queue, skb);
146144830d8fSVarun Prakash 	}
146244830d8fSVarun Prakash 
146344830d8fSVarun Prakash 	csk->skb_ulp_lhdr = NULL;
146444830d8fSVarun Prakash 
146544830d8fSVarun Prakash 	cxgbi_skcb_set_flag(skb, SKCBF_RX_HDR);
146644830d8fSVarun Prakash 	cxgbi_skcb_set_flag(skb, SKCBF_RX_STATUS);
146744830d8fSVarun Prakash 	cxgbi_skcb_set_flag(skb, SKCBF_RX_ISCSI_COMPL);
146844830d8fSVarun Prakash 	cxgbi_skcb_rx_ddigest(skb) = be32_to_cpu(rpl->ulp_crc);
146944830d8fSVarun Prakash 
147044830d8fSVarun Prakash 	cxgb4i_process_ddpvld(csk, skb, ddpvld);
147144830d8fSVarun Prakash 
147244830d8fSVarun Prakash 	log_debug(1 << CXGBI_DBG_PDU_RX, "csk 0x%p, skb 0x%p, f 0x%lx.\n",
147344830d8fSVarun Prakash 		  csk, skb, cxgbi_skcb_flags(skb));
147444830d8fSVarun Prakash 
147544830d8fSVarun Prakash 	cxgbi_conn_pdu_ready(csk);
147644830d8fSVarun Prakash 	spin_unlock_bh(&csk->lock);
147744830d8fSVarun Prakash 
147844830d8fSVarun Prakash 	return;
147944830d8fSVarun Prakash 
148044830d8fSVarun Prakash abort_conn:
148144830d8fSVarun Prakash 	send_abort_req(csk);
148244830d8fSVarun Prakash discard:
148344830d8fSVarun Prakash 	spin_unlock_bh(&csk->lock);
148444830d8fSVarun Prakash rel_skb:
148544830d8fSVarun Prakash 	__kfree_skb(skb);
148644830d8fSVarun Prakash }
148744830d8fSVarun Prakash 
14887b36b6e0Skxie@chelsio.com static void do_fw4_ack(struct cxgbi_device *cdev, struct sk_buff *skb)
14897b36b6e0Skxie@chelsio.com {
14907b36b6e0Skxie@chelsio.com 	struct cxgbi_sock *csk;
14917b36b6e0Skxie@chelsio.com 	struct cpl_fw4_ack *rpl = (struct cpl_fw4_ack *)skb->data;
14927b36b6e0Skxie@chelsio.com 	unsigned int tid = GET_TID(rpl);
14937b36b6e0Skxie@chelsio.com 	struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(cdev);
14947b36b6e0Skxie@chelsio.com 	struct tid_info *t = lldi->tids;
14957b36b6e0Skxie@chelsio.com 
14967b36b6e0Skxie@chelsio.com 	csk = lookup_tid(t, tid);
14977b36b6e0Skxie@chelsio.com 	if (unlikely(!csk))
14987b36b6e0Skxie@chelsio.com 		pr_err("can't find connection for tid %u.\n", tid);
14997b36b6e0Skxie@chelsio.com 	else {
15007b36b6e0Skxie@chelsio.com 		log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
15017b36b6e0Skxie@chelsio.com 			"csk 0x%p,%u,0x%lx,%u.\n",
15027b36b6e0Skxie@chelsio.com 			csk, csk->state, csk->flags, csk->tid);
15037b36b6e0Skxie@chelsio.com 		cxgbi_sock_rcv_wr_ack(csk, rpl->credits, ntohl(rpl->snd_una),
15047b36b6e0Skxie@chelsio.com 					rpl->seq_vld);
15057b36b6e0Skxie@chelsio.com 	}
15067b36b6e0Skxie@chelsio.com 	__kfree_skb(skb);
15077b36b6e0Skxie@chelsio.com }
15087b36b6e0Skxie@chelsio.com 
15097b36b6e0Skxie@chelsio.com static void do_set_tcb_rpl(struct cxgbi_device *cdev, struct sk_buff *skb)
15107b36b6e0Skxie@chelsio.com {
15117b36b6e0Skxie@chelsio.com 	struct cpl_set_tcb_rpl *rpl = (struct cpl_set_tcb_rpl *)skb->data;
15127b36b6e0Skxie@chelsio.com 	unsigned int tid = GET_TID(rpl);
15137b36b6e0Skxie@chelsio.com 	struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(cdev);
15147b36b6e0Skxie@chelsio.com 	struct tid_info *t = lldi->tids;
15157b36b6e0Skxie@chelsio.com 	struct cxgbi_sock *csk;
15167b36b6e0Skxie@chelsio.com 
15177b36b6e0Skxie@chelsio.com 	csk = lookup_tid(t, tid);
15187b36b6e0Skxie@chelsio.com 	if (!csk)
15197b36b6e0Skxie@chelsio.com 		pr_err("can't find conn. for tid %u.\n", tid);
15207b36b6e0Skxie@chelsio.com 
15217b36b6e0Skxie@chelsio.com 	log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
15227b36b6e0Skxie@chelsio.com 		"csk 0x%p,%u,%lx,%u, status 0x%x.\n",
15237b36b6e0Skxie@chelsio.com 		csk, csk->state, csk->flags, csk->tid, rpl->status);
15247b36b6e0Skxie@chelsio.com 
15257b36b6e0Skxie@chelsio.com 	if (rpl->status != CPL_ERR_NONE)
15267b36b6e0Skxie@chelsio.com 		pr_err("csk 0x%p,%u, SET_TCB_RPL status %u.\n",
15277b36b6e0Skxie@chelsio.com 			csk, tid, rpl->status);
15287b36b6e0Skxie@chelsio.com 
15297b36b6e0Skxie@chelsio.com 	__kfree_skb(skb);
15307b36b6e0Skxie@chelsio.com }
15317b36b6e0Skxie@chelsio.com 
15327b36b6e0Skxie@chelsio.com static int alloc_cpls(struct cxgbi_sock *csk)
15337b36b6e0Skxie@chelsio.com {
153424d3f95aSkxie@chelsio.com 	csk->cpl_close = alloc_wr(sizeof(struct cpl_close_con_req),
153524d3f95aSkxie@chelsio.com 					0, GFP_KERNEL);
15367b36b6e0Skxie@chelsio.com 	if (!csk->cpl_close)
15377b36b6e0Skxie@chelsio.com 		return -ENOMEM;
15387b36b6e0Skxie@chelsio.com 
153924d3f95aSkxie@chelsio.com 	csk->cpl_abort_req = alloc_wr(sizeof(struct cpl_abort_req),
154024d3f95aSkxie@chelsio.com 					0, GFP_KERNEL);
15417b36b6e0Skxie@chelsio.com 	if (!csk->cpl_abort_req)
15427b36b6e0Skxie@chelsio.com 		goto free_cpls;
15437b36b6e0Skxie@chelsio.com 
154424d3f95aSkxie@chelsio.com 	csk->cpl_abort_rpl = alloc_wr(sizeof(struct cpl_abort_rpl),
154524d3f95aSkxie@chelsio.com 					0, GFP_KERNEL);
15467b36b6e0Skxie@chelsio.com 	if (!csk->cpl_abort_rpl)
15477b36b6e0Skxie@chelsio.com 		goto free_cpls;
15487b36b6e0Skxie@chelsio.com 	return 0;
15497b36b6e0Skxie@chelsio.com 
15507b36b6e0Skxie@chelsio.com free_cpls:
15517b36b6e0Skxie@chelsio.com 	cxgbi_sock_free_cpl_skbs(csk);
15527b36b6e0Skxie@chelsio.com 	return -ENOMEM;
15537b36b6e0Skxie@chelsio.com }
15547b36b6e0Skxie@chelsio.com 
15557b36b6e0Skxie@chelsio.com static inline void l2t_put(struct cxgbi_sock *csk)
15567b36b6e0Skxie@chelsio.com {
15577b36b6e0Skxie@chelsio.com 	if (csk->l2t) {
15587b36b6e0Skxie@chelsio.com 		cxgb4_l2t_release(csk->l2t);
15597b36b6e0Skxie@chelsio.com 		csk->l2t = NULL;
15607b36b6e0Skxie@chelsio.com 		cxgbi_sock_put(csk);
15617b36b6e0Skxie@chelsio.com 	}
15627b36b6e0Skxie@chelsio.com }
15637b36b6e0Skxie@chelsio.com 
15647b36b6e0Skxie@chelsio.com static void release_offload_resources(struct cxgbi_sock *csk)
15657b36b6e0Skxie@chelsio.com {
15667b36b6e0Skxie@chelsio.com 	struct cxgb4_lld_info *lldi;
1567211a84e3SAnish Bhatt #if IS_ENABLED(CONFIG_IPV6)
1568211a84e3SAnish Bhatt 	struct net_device *ndev = csk->cdev->ports[csk->port_id];
1569211a84e3SAnish Bhatt #endif
15707b36b6e0Skxie@chelsio.com 
15717b36b6e0Skxie@chelsio.com 	log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
15727b36b6e0Skxie@chelsio.com 		"csk 0x%p,%u,0x%lx,%u.\n",
15737b36b6e0Skxie@chelsio.com 		csk, csk->state, csk->flags, csk->tid);
15747b36b6e0Skxie@chelsio.com 
15757b36b6e0Skxie@chelsio.com 	cxgbi_sock_free_cpl_skbs(csk);
15767b36b6e0Skxie@chelsio.com 	if (csk->wr_cred != csk->wr_max_cred) {
15777b36b6e0Skxie@chelsio.com 		cxgbi_sock_purge_wr_queue(csk);
15787b36b6e0Skxie@chelsio.com 		cxgbi_sock_reset_wr_list(csk);
15797b36b6e0Skxie@chelsio.com 	}
15807b36b6e0Skxie@chelsio.com 
15817b36b6e0Skxie@chelsio.com 	l2t_put(csk);
1582211a84e3SAnish Bhatt #if IS_ENABLED(CONFIG_IPV6)
1583211a84e3SAnish Bhatt 	if (csk->csk_family == AF_INET6)
1584211a84e3SAnish Bhatt 		cxgb4_clip_release(ndev,
1585211a84e3SAnish Bhatt 				   (const u32 *)&csk->saddr6.sin6_addr, 1);
1586211a84e3SAnish Bhatt #endif
1587211a84e3SAnish Bhatt 
15887b36b6e0Skxie@chelsio.com 	if (cxgbi_sock_flag(csk, CTPF_HAS_ATID))
15897b36b6e0Skxie@chelsio.com 		free_atid(csk);
15907b36b6e0Skxie@chelsio.com 	else if (cxgbi_sock_flag(csk, CTPF_HAS_TID)) {
15917b36b6e0Skxie@chelsio.com 		lldi = cxgbi_cdev_priv(csk->cdev);
15927b36b6e0Skxie@chelsio.com 		cxgb4_remove_tid(lldi->tids, 0, csk->tid);
15937b36b6e0Skxie@chelsio.com 		cxgbi_sock_clear_flag(csk, CTPF_HAS_TID);
15947b36b6e0Skxie@chelsio.com 		cxgbi_sock_put(csk);
15957b36b6e0Skxie@chelsio.com 	}
15967b36b6e0Skxie@chelsio.com 	csk->dst = NULL;
15977b36b6e0Skxie@chelsio.com 	csk->cdev = NULL;
15987b36b6e0Skxie@chelsio.com }
15997b36b6e0Skxie@chelsio.com 
16007b36b6e0Skxie@chelsio.com static int init_act_open(struct cxgbi_sock *csk)
16017b36b6e0Skxie@chelsio.com {
16027b36b6e0Skxie@chelsio.com 	struct cxgbi_device *cdev = csk->cdev;
16037b36b6e0Skxie@chelsio.com 	struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(cdev);
16047b36b6e0Skxie@chelsio.com 	struct net_device *ndev = cdev->ports[csk->port_id];
16057b36b6e0Skxie@chelsio.com 	struct sk_buff *skb = NULL;
1606759a0cc5SAnish Bhatt 	struct neighbour *n = NULL;
1607759a0cc5SAnish Bhatt 	void *daddr;
16087b36b6e0Skxie@chelsio.com 	unsigned int step;
1609759a0cc5SAnish Bhatt 	unsigned int size, size6;
161081daf10cSKaren Xie 	unsigned int linkspeed;
161181daf10cSKaren Xie 	unsigned int rcv_winf, snd_winf;
16127b36b6e0Skxie@chelsio.com 
16137b36b6e0Skxie@chelsio.com 	log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
16147b36b6e0Skxie@chelsio.com 		"csk 0x%p,%u,0x%lx,%u.\n",
16157b36b6e0Skxie@chelsio.com 		csk, csk->state, csk->flags, csk->tid);
16167b36b6e0Skxie@chelsio.com 
1617759a0cc5SAnish Bhatt 	if (csk->csk_family == AF_INET)
1618759a0cc5SAnish Bhatt 		daddr = &csk->daddr.sin_addr.s_addr;
1619e81fbf6cSAnish Bhatt #if IS_ENABLED(CONFIG_IPV6)
1620e81fbf6cSAnish Bhatt 	else if (csk->csk_family == AF_INET6)
1621759a0cc5SAnish Bhatt 		daddr = &csk->daddr6.sin6_addr;
1622e81fbf6cSAnish Bhatt #endif
1623e81fbf6cSAnish Bhatt 	else {
1624e81fbf6cSAnish Bhatt 		pr_err("address family 0x%x not supported\n", csk->csk_family);
1625e81fbf6cSAnish Bhatt 		goto rel_resource;
1626e81fbf6cSAnish Bhatt 	}
1627759a0cc5SAnish Bhatt 
1628759a0cc5SAnish Bhatt 	n = dst_neigh_lookup(csk->dst, daddr);
1629759a0cc5SAnish Bhatt 
1630759a0cc5SAnish Bhatt 	if (!n) {
1631759a0cc5SAnish Bhatt 		pr_err("%s, can't get neighbour of csk->dst.\n", ndev->name);
1632759a0cc5SAnish Bhatt 		goto rel_resource;
1633759a0cc5SAnish Bhatt 	}
1634759a0cc5SAnish Bhatt 
16357b36b6e0Skxie@chelsio.com 	csk->atid = cxgb4_alloc_atid(lldi->tids, csk);
16367b36b6e0Skxie@chelsio.com 	if (csk->atid < 0) {
16377b36b6e0Skxie@chelsio.com 		pr_err("%s, NO atid available.\n", ndev->name);
1638338be072SQuentin Lambert 		goto rel_resource_without_clip;
16397b36b6e0Skxie@chelsio.com 	}
16407b36b6e0Skxie@chelsio.com 	cxgbi_sock_set_flag(csk, CTPF_HAS_ATID);
16417b36b6e0Skxie@chelsio.com 	cxgbi_sock_get(csk);
16427b36b6e0Skxie@chelsio.com 
164351e059bdSDavid Miller 	csk->l2t = cxgb4_l2t_get(lldi->l2t, n, ndev, 0);
16447b36b6e0Skxie@chelsio.com 	if (!csk->l2t) {
16457b36b6e0Skxie@chelsio.com 		pr_err("%s, cannot alloc l2t.\n", ndev->name);
1646211a84e3SAnish Bhatt 		goto rel_resource_without_clip;
16477b36b6e0Skxie@chelsio.com 	}
16487b36b6e0Skxie@chelsio.com 	cxgbi_sock_get(csk);
16497b36b6e0Skxie@chelsio.com 
1650211a84e3SAnish Bhatt #if IS_ENABLED(CONFIG_IPV6)
1651211a84e3SAnish Bhatt 	if (csk->csk_family == AF_INET6)
1652211a84e3SAnish Bhatt 		cxgb4_clip_get(ndev, (const u32 *)&csk->saddr6.sin6_addr, 1);
1653211a84e3SAnish Bhatt #endif
1654211a84e3SAnish Bhatt 
1655586be7cbSVarun Prakash 	if (is_t4(lldi->adapter_type)) {
1656759a0cc5SAnish Bhatt 		size = sizeof(struct cpl_act_open_req);
1657759a0cc5SAnish Bhatt 		size6 = sizeof(struct cpl_act_open_req6);
1658586be7cbSVarun Prakash 	} else if (is_t5(lldi->adapter_type)) {
1659759a0cc5SAnish Bhatt 		size = sizeof(struct cpl_t5_act_open_req);
1660759a0cc5SAnish Bhatt 		size6 = sizeof(struct cpl_t5_act_open_req6);
1661586be7cbSVarun Prakash 	} else {
1662586be7cbSVarun Prakash 		size = sizeof(struct cpl_t6_act_open_req);
1663586be7cbSVarun Prakash 		size6 = sizeof(struct cpl_t6_act_open_req6);
1664759a0cc5SAnish Bhatt 	}
1665759a0cc5SAnish Bhatt 
1666759a0cc5SAnish Bhatt 	if (csk->csk_family == AF_INET)
1667759a0cc5SAnish Bhatt 		skb = alloc_wr(size, 0, GFP_NOIO);
1668f42bb57cSAnish Bhatt #if IS_ENABLED(CONFIG_IPV6)
1669759a0cc5SAnish Bhatt 	else
1670759a0cc5SAnish Bhatt 		skb = alloc_wr(size6, 0, GFP_NOIO);
1671f42bb57cSAnish Bhatt #endif
1672759a0cc5SAnish Bhatt 
16737b36b6e0Skxie@chelsio.com 	if (!skb)
16747b36b6e0Skxie@chelsio.com 		goto rel_resource;
16757b36b6e0Skxie@chelsio.com 	skb->sk = (struct sock *)csk;
16767b36b6e0Skxie@chelsio.com 	t4_set_arp_err_handler(skb, csk, cxgbi_sock_act_open_req_arp_failure);
16777b36b6e0Skxie@chelsio.com 
16787b36b6e0Skxie@chelsio.com 	if (!csk->mtu)
16797b36b6e0Skxie@chelsio.com 		csk->mtu = dst_mtu(csk->dst);
16807b36b6e0Skxie@chelsio.com 	cxgb4_best_mtu(lldi->mtus, csk->mtu, &csk->mss_idx);
16817b36b6e0Skxie@chelsio.com 	csk->tx_chan = cxgb4_port_chan(ndev);
1682e0eed8abSVarun Prakash 	csk->smac_idx = cxgb4_tp_smt_idx(lldi->adapter_type,
1683e0eed8abSVarun Prakash 					 cxgb4_port_viid(ndev));
16847b36b6e0Skxie@chelsio.com 	step = lldi->ntxq / lldi->nchan;
16857b36b6e0Skxie@chelsio.com 	csk->txq_idx = cxgb4_port_idx(ndev) * step;
16867b36b6e0Skxie@chelsio.com 	step = lldi->nrxq / lldi->nchan;
16877b36b6e0Skxie@chelsio.com 	csk->rss_qid = lldi->rxq_ids[cxgb4_port_idx(ndev) * step];
168881daf10cSKaren Xie 	linkspeed = ((struct port_info *)netdev_priv(ndev))->link_cfg.speed;
168981daf10cSKaren Xie 	csk->snd_win = cxgb4i_snd_win;
169081daf10cSKaren Xie 	csk->rcv_win = cxgb4i_rcv_win;
169181daf10cSKaren Xie 	if (cxgb4i_rcv_win <= 0) {
169281daf10cSKaren Xie 		csk->rcv_win = CXGB4I_DEFAULT_10G_RCV_WIN;
169381daf10cSKaren Xie 		rcv_winf = linkspeed / SPEED_10000;
169481daf10cSKaren Xie 		if (rcv_winf)
169581daf10cSKaren Xie 			csk->rcv_win *= rcv_winf;
169681daf10cSKaren Xie 	}
169781daf10cSKaren Xie 	if (cxgb4i_snd_win <= 0) {
169881daf10cSKaren Xie 		csk->snd_win = CXGB4I_DEFAULT_10G_SND_WIN;
169981daf10cSKaren Xie 		snd_winf = linkspeed / SPEED_10000;
170081daf10cSKaren Xie 		if (snd_winf)
170181daf10cSKaren Xie 			csk->snd_win *= snd_winf;
170281daf10cSKaren Xie 	}
1703759a0cc5SAnish Bhatt 	csk->wr_cred = lldi->wr_cred -
1704759a0cc5SAnish Bhatt 		       DIV_ROUND_UP(sizeof(struct cpl_abort_req), 16);
1705759a0cc5SAnish Bhatt 	csk->wr_max_cred = csk->wr_cred;
17067b36b6e0Skxie@chelsio.com 	csk->wr_una_cred = 0;
17077b36b6e0Skxie@chelsio.com 	cxgbi_sock_reset_wr_list(csk);
17087b36b6e0Skxie@chelsio.com 	csk->err = 0;
17097b36b6e0Skxie@chelsio.com 
1710759a0cc5SAnish Bhatt 	pr_info_ipaddr("csk 0x%p,%u,0x%lx,%u,%u,%u, mtu %u,%u, smac %u.\n",
1711759a0cc5SAnish Bhatt 		       (&csk->saddr), (&csk->daddr), csk, csk->state,
1712759a0cc5SAnish Bhatt 		       csk->flags, csk->tx_chan, csk->txq_idx, csk->rss_qid,
1713759a0cc5SAnish Bhatt 		       csk->mtu, csk->mss_idx, csk->smac_idx);
1714759a0cc5SAnish Bhatt 
1715759a0cc5SAnish Bhatt 	/* must wait for either a act_open_rpl or act_open_establish */
17161fe1fdb0SVarun Prakash 	if (!try_module_get(cdev->owner)) {
17171fe1fdb0SVarun Prakash 		pr_err("%s, try_module_get failed.\n", ndev->name);
17181fe1fdb0SVarun Prakash 		goto rel_resource;
17191fe1fdb0SVarun Prakash 	}
17201fe1fdb0SVarun Prakash 
17217b36b6e0Skxie@chelsio.com 	cxgbi_sock_set_state(csk, CTP_ACTIVE_OPEN);
1722759a0cc5SAnish Bhatt 	if (csk->csk_family == AF_INET)
17237b36b6e0Skxie@chelsio.com 		send_act_open_req(csk, skb, csk->l2t);
1724f42bb57cSAnish Bhatt #if IS_ENABLED(CONFIG_IPV6)
1725759a0cc5SAnish Bhatt 	else
1726759a0cc5SAnish Bhatt 		send_act_open_req6(csk, skb, csk->l2t);
1727f42bb57cSAnish Bhatt #endif
1728c4737377SDavid S. Miller 	neigh_release(n);
1729759a0cc5SAnish Bhatt 
17307b36b6e0Skxie@chelsio.com 	return 0;
17317b36b6e0Skxie@chelsio.com 
17327b36b6e0Skxie@chelsio.com rel_resource:
1733211a84e3SAnish Bhatt #if IS_ENABLED(CONFIG_IPV6)
1734211a84e3SAnish Bhatt 	if (csk->csk_family == AF_INET6)
1735211a84e3SAnish Bhatt 		cxgb4_clip_release(ndev,
1736211a84e3SAnish Bhatt 				   (const u32 *)&csk->saddr6.sin6_addr, 1);
1737211a84e3SAnish Bhatt #endif
1738211a84e3SAnish Bhatt rel_resource_without_clip:
1739c4737377SDavid S. Miller 	if (n)
1740c4737377SDavid S. Miller 		neigh_release(n);
17417b36b6e0Skxie@chelsio.com 	if (skb)
17427b36b6e0Skxie@chelsio.com 		__kfree_skb(skb);
17437b36b6e0Skxie@chelsio.com 	return -EINVAL;
17447b36b6e0Skxie@chelsio.com }
17457b36b6e0Skxie@chelsio.com 
17464665bdd5SVarun Prakash static cxgb4i_cplhandler_func cxgb4i_cplhandlers[NUM_CPL_CMDS] = {
17477b36b6e0Skxie@chelsio.com 	[CPL_ACT_ESTABLISH] = do_act_establish,
17487b36b6e0Skxie@chelsio.com 	[CPL_ACT_OPEN_RPL] = do_act_open_rpl,
17497b36b6e0Skxie@chelsio.com 	[CPL_PEER_CLOSE] = do_peer_close,
17507b36b6e0Skxie@chelsio.com 	[CPL_ABORT_REQ_RSS] = do_abort_req_rss,
17517b36b6e0Skxie@chelsio.com 	[CPL_ABORT_RPL_RSS] = do_abort_rpl_rss,
17527b36b6e0Skxie@chelsio.com 	[CPL_CLOSE_CON_RPL] = do_close_con_rpl,
17537b36b6e0Skxie@chelsio.com 	[CPL_FW4_ACK] = do_fw4_ack,
17547b36b6e0Skxie@chelsio.com 	[CPL_ISCSI_HDR] = do_rx_iscsi_hdr,
175544830d8fSVarun Prakash 	[CPL_ISCSI_DATA] = do_rx_iscsi_data,
17567b36b6e0Skxie@chelsio.com 	[CPL_SET_TCB_RPL] = do_set_tcb_rpl,
17577b36b6e0Skxie@chelsio.com 	[CPL_RX_DATA_DDP] = do_rx_data_ddp,
17583bd3e8bfSKaren Xie 	[CPL_RX_ISCSI_DDP] = do_rx_data_ddp,
175944830d8fSVarun Prakash 	[CPL_RX_ISCSI_CMP] = do_rx_iscsi_cmp,
1760f7bcd2e1SKaren Xie 	[CPL_RX_DATA] = do_rx_data,
17617b36b6e0Skxie@chelsio.com };
17627b36b6e0Skxie@chelsio.com 
17634665bdd5SVarun Prakash static int cxgb4i_ofld_init(struct cxgbi_device *cdev)
17647b36b6e0Skxie@chelsio.com {
17657b36b6e0Skxie@chelsio.com 	int rc;
17667b36b6e0Skxie@chelsio.com 
17677b36b6e0Skxie@chelsio.com 	if (cxgb4i_max_connect > CXGB4I_MAX_CONN)
17687b36b6e0Skxie@chelsio.com 		cxgb4i_max_connect = CXGB4I_MAX_CONN;
17697b36b6e0Skxie@chelsio.com 
17707b36b6e0Skxie@chelsio.com 	rc = cxgbi_device_portmap_create(cdev, cxgb4i_sport_base,
17717b36b6e0Skxie@chelsio.com 					cxgb4i_max_connect);
17727b36b6e0Skxie@chelsio.com 	if (rc < 0)
17737b36b6e0Skxie@chelsio.com 		return rc;
17747b36b6e0Skxie@chelsio.com 
17757b36b6e0Skxie@chelsio.com 	cdev->csk_release_offload_resources = release_offload_resources;
17767b36b6e0Skxie@chelsio.com 	cdev->csk_push_tx_frames = push_tx_frames;
17777b36b6e0Skxie@chelsio.com 	cdev->csk_send_abort_req = send_abort_req;
17787b36b6e0Skxie@chelsio.com 	cdev->csk_send_close_req = send_close_req;
17797b36b6e0Skxie@chelsio.com 	cdev->csk_send_rx_credits = send_rx_credits;
17807b36b6e0Skxie@chelsio.com 	cdev->csk_alloc_cpls = alloc_cpls;
17817b36b6e0Skxie@chelsio.com 	cdev->csk_init_act_open = init_act_open;
17827b36b6e0Skxie@chelsio.com 
17837b36b6e0Skxie@chelsio.com 	pr_info("cdev 0x%p, offload up, added.\n", cdev);
17847b36b6e0Skxie@chelsio.com 	return 0;
17857b36b6e0Skxie@chelsio.com }
17867b36b6e0Skxie@chelsio.com 
178771f7a00bSVarun Prakash static inline void
178871f7a00bSVarun Prakash ulp_mem_io_set_hdr(struct cxgbi_device *cdev,
178971f7a00bSVarun Prakash 		   struct ulp_mem_io *req,
179071f7a00bSVarun Prakash 		   unsigned int wr_len, unsigned int dlen,
179171f7a00bSVarun Prakash 		   unsigned int pm_addr,
179271f7a00bSVarun Prakash 		   int tid)
179371f7a00bSVarun Prakash {
179471f7a00bSVarun Prakash 	struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(cdev);
179571f7a00bSVarun Prakash 	struct ulptx_idata *idata = (struct ulptx_idata *)(req + 1);
179671f7a00bSVarun Prakash 
179771f7a00bSVarun Prakash 	INIT_ULPTX_WR(req, wr_len, 0, tid);
179871f7a00bSVarun Prakash 	req->wr.wr_hi = htonl(FW_WR_OP_V(FW_ULPTX_WR) |
179971f7a00bSVarun Prakash 		FW_WR_ATOMIC_V(0));
180071f7a00bSVarun Prakash 	req->cmd = htonl(ULPTX_CMD_V(ULP_TX_MEM_WRITE) |
180171f7a00bSVarun Prakash 		ULP_MEMIO_ORDER_V(is_t4(lldi->adapter_type)) |
180271f7a00bSVarun Prakash 		T5_ULP_MEMIO_IMM_V(!is_t4(lldi->adapter_type)));
180371f7a00bSVarun Prakash 	req->dlen = htonl(ULP_MEMIO_DATA_LEN_V(dlen >> 5));
180471f7a00bSVarun Prakash 	req->lock_addr = htonl(ULP_MEMIO_ADDR_V(pm_addr >> 5));
180571f7a00bSVarun Prakash 	req->len16 = htonl(DIV_ROUND_UP(wr_len - sizeof(req->wr), 16));
180671f7a00bSVarun Prakash 
180771f7a00bSVarun Prakash 	idata->cmd_more = htonl(ULPTX_CMD_V(ULP_TX_SC_IMM));
180871f7a00bSVarun Prakash 	idata->len = htonl(dlen);
180971f7a00bSVarun Prakash }
181071f7a00bSVarun Prakash 
181171f7a00bSVarun Prakash static struct sk_buff *
181271f7a00bSVarun Prakash ddp_ppod_init_idata(struct cxgbi_device *cdev,
181371f7a00bSVarun Prakash 		    struct cxgbi_ppm *ppm,
181471f7a00bSVarun Prakash 		    unsigned int idx, unsigned int npods,
181571f7a00bSVarun Prakash 		    unsigned int tid)
181671f7a00bSVarun Prakash {
181771f7a00bSVarun Prakash 	unsigned int pm_addr = (idx << PPOD_SIZE_SHIFT) + ppm->llimit;
181871f7a00bSVarun Prakash 	unsigned int dlen = npods << PPOD_SIZE_SHIFT;
181971f7a00bSVarun Prakash 	unsigned int wr_len = roundup(sizeof(struct ulp_mem_io) +
182071f7a00bSVarun Prakash 				sizeof(struct ulptx_idata) + dlen, 16);
182171f7a00bSVarun Prakash 	struct sk_buff *skb = alloc_wr(wr_len, 0, GFP_ATOMIC);
182271f7a00bSVarun Prakash 
182371f7a00bSVarun Prakash 	if (!skb) {
182471f7a00bSVarun Prakash 		pr_err("%s: %s idx %u, npods %u, OOM.\n",
182571f7a00bSVarun Prakash 		       __func__, ppm->ndev->name, idx, npods);
182671f7a00bSVarun Prakash 		return NULL;
182771f7a00bSVarun Prakash 	}
182871f7a00bSVarun Prakash 
182971f7a00bSVarun Prakash 	ulp_mem_io_set_hdr(cdev, (struct ulp_mem_io *)skb->head, wr_len, dlen,
183071f7a00bSVarun Prakash 			   pm_addr, tid);
183171f7a00bSVarun Prakash 
183271f7a00bSVarun Prakash 	return skb;
183371f7a00bSVarun Prakash }
183471f7a00bSVarun Prakash 
183571f7a00bSVarun Prakash static int ddp_ppod_write_idata(struct cxgbi_ppm *ppm, struct cxgbi_sock *csk,
183671f7a00bSVarun Prakash 				struct cxgbi_task_tag_info *ttinfo,
183771f7a00bSVarun Prakash 				unsigned int idx, unsigned int npods,
183871f7a00bSVarun Prakash 				struct scatterlist **sg_pp,
183971f7a00bSVarun Prakash 				unsigned int *sg_off)
184071f7a00bSVarun Prakash {
184171f7a00bSVarun Prakash 	struct cxgbi_device *cdev = csk->cdev;
184271f7a00bSVarun Prakash 	struct sk_buff *skb = ddp_ppod_init_idata(cdev, ppm, idx, npods,
184371f7a00bSVarun Prakash 						  csk->tid);
184471f7a00bSVarun Prakash 	struct ulp_mem_io *req;
184571f7a00bSVarun Prakash 	struct ulptx_idata *idata;
184671f7a00bSVarun Prakash 	struct cxgbi_pagepod *ppod;
184771f7a00bSVarun Prakash 	int i;
184871f7a00bSVarun Prakash 
184971f7a00bSVarun Prakash 	if (!skb)
185071f7a00bSVarun Prakash 		return -ENOMEM;
185171f7a00bSVarun Prakash 
185271f7a00bSVarun Prakash 	req = (struct ulp_mem_io *)skb->head;
185371f7a00bSVarun Prakash 	idata = (struct ulptx_idata *)(req + 1);
185471f7a00bSVarun Prakash 	ppod = (struct cxgbi_pagepod *)(idata + 1);
185571f7a00bSVarun Prakash 
185671f7a00bSVarun Prakash 	for (i = 0; i < npods; i++, ppod++)
185771f7a00bSVarun Prakash 		cxgbi_ddp_set_one_ppod(ppod, ttinfo, sg_pp, sg_off);
185871f7a00bSVarun Prakash 
185971f7a00bSVarun Prakash 	cxgbi_skcb_set_flag(skb, SKCBF_TX_MEM_WRITE);
186071f7a00bSVarun Prakash 	cxgbi_skcb_set_flag(skb, SKCBF_TX_FLAG_COMPL);
186171f7a00bSVarun Prakash 	set_wr_txq(skb, CPL_PRIORITY_DATA, csk->port_id);
186271f7a00bSVarun Prakash 
186371f7a00bSVarun Prakash 	spin_lock_bh(&csk->lock);
186471f7a00bSVarun Prakash 	cxgbi_sock_skb_entail(csk, skb);
186571f7a00bSVarun Prakash 	spin_unlock_bh(&csk->lock);
186671f7a00bSVarun Prakash 
186771f7a00bSVarun Prakash 	return 0;
186871f7a00bSVarun Prakash }
186971f7a00bSVarun Prakash 
187071f7a00bSVarun Prakash static int ddp_set_map(struct cxgbi_ppm *ppm, struct cxgbi_sock *csk,
187171f7a00bSVarun Prakash 		       struct cxgbi_task_tag_info *ttinfo)
187271f7a00bSVarun Prakash {
187371f7a00bSVarun Prakash 	unsigned int pidx = ttinfo->idx;
187471f7a00bSVarun Prakash 	unsigned int npods = ttinfo->npods;
187571f7a00bSVarun Prakash 	unsigned int i, cnt;
187671f7a00bSVarun Prakash 	int err = 0;
187771f7a00bSVarun Prakash 	struct scatterlist *sg = ttinfo->sgl;
187871f7a00bSVarun Prakash 	unsigned int offset = 0;
187971f7a00bSVarun Prakash 
188071f7a00bSVarun Prakash 	ttinfo->cid = csk->port_id;
188171f7a00bSVarun Prakash 
188271f7a00bSVarun Prakash 	for (i = 0; i < npods; i += cnt, pidx += cnt) {
188371f7a00bSVarun Prakash 		cnt = npods - i;
188471f7a00bSVarun Prakash 
188571f7a00bSVarun Prakash 		if (cnt > ULPMEM_IDATA_MAX_NPPODS)
188671f7a00bSVarun Prakash 			cnt = ULPMEM_IDATA_MAX_NPPODS;
188771f7a00bSVarun Prakash 		err = ddp_ppod_write_idata(ppm, csk, ttinfo, pidx, cnt,
188871f7a00bSVarun Prakash 					   &sg, &offset);
188971f7a00bSVarun Prakash 		if (err < 0)
189071f7a00bSVarun Prakash 			break;
189171f7a00bSVarun Prakash 	}
189271f7a00bSVarun Prakash 
189371f7a00bSVarun Prakash 	return err;
189471f7a00bSVarun Prakash }
189571f7a00bSVarun Prakash 
18967b36b6e0Skxie@chelsio.com static int ddp_setup_conn_pgidx(struct cxgbi_sock *csk, unsigned int tid,
18977b36b6e0Skxie@chelsio.com 				int pg_idx, bool reply)
18987b36b6e0Skxie@chelsio.com {
18997b36b6e0Skxie@chelsio.com 	struct sk_buff *skb;
19007b36b6e0Skxie@chelsio.com 	struct cpl_set_tcb_field *req;
19017b36b6e0Skxie@chelsio.com 
1902e27d6169Skxie@chelsio.com 	if (!pg_idx || pg_idx >= DDP_PGIDX_MAX)
19037b36b6e0Skxie@chelsio.com 		return 0;
19047b36b6e0Skxie@chelsio.com 
190524d3f95aSkxie@chelsio.com 	skb = alloc_wr(sizeof(*req), 0, GFP_KERNEL);
19067b36b6e0Skxie@chelsio.com 	if (!skb)
19077b36b6e0Skxie@chelsio.com 		return -ENOMEM;
19087b36b6e0Skxie@chelsio.com 
1909e27d6169Skxie@chelsio.com 	/*  set up ulp page size */
19107b36b6e0Skxie@chelsio.com 	req = (struct cpl_set_tcb_field *)skb->head;
19117b36b6e0Skxie@chelsio.com 	INIT_TP_WR(req, csk->tid);
19127b36b6e0Skxie@chelsio.com 	OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_SET_TCB_FIELD, csk->tid));
1913bdc590b9SHariprasad Shenai 	req->reply_ctrl = htons(NO_REPLY_V(reply) | QUEUENO_V(csk->rss_qid));
1914e27d6169Skxie@chelsio.com 	req->word_cookie = htons(0);
1915e27d6169Skxie@chelsio.com 	req->mask = cpu_to_be64(0x3 << 8);
1916e27d6169Skxie@chelsio.com 	req->val = cpu_to_be64(pg_idx << 8);
19177b36b6e0Skxie@chelsio.com 	set_wr_txq(skb, CPL_PRIORITY_CONTROL, csk->port_id);
19187b36b6e0Skxie@chelsio.com 
19197b36b6e0Skxie@chelsio.com 	log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
19207b36b6e0Skxie@chelsio.com 		"csk 0x%p, tid 0x%x, pg_idx %u.\n", csk, csk->tid, pg_idx);
19217b36b6e0Skxie@chelsio.com 
19227b36b6e0Skxie@chelsio.com 	cxgb4_ofld_send(csk->cdev->ports[csk->port_id], skb);
19237b36b6e0Skxie@chelsio.com 	return 0;
19247b36b6e0Skxie@chelsio.com }
19257b36b6e0Skxie@chelsio.com 
19267b36b6e0Skxie@chelsio.com static int ddp_setup_conn_digest(struct cxgbi_sock *csk, unsigned int tid,
19277b36b6e0Skxie@chelsio.com 				 int hcrc, int dcrc, int reply)
19287b36b6e0Skxie@chelsio.com {
19297b36b6e0Skxie@chelsio.com 	struct sk_buff *skb;
19307b36b6e0Skxie@chelsio.com 	struct cpl_set_tcb_field *req;
19317b36b6e0Skxie@chelsio.com 
1932e27d6169Skxie@chelsio.com 	if (!hcrc && !dcrc)
1933e27d6169Skxie@chelsio.com 		return 0;
19347b36b6e0Skxie@chelsio.com 
193524d3f95aSkxie@chelsio.com 	skb = alloc_wr(sizeof(*req), 0, GFP_KERNEL);
19367b36b6e0Skxie@chelsio.com 	if (!skb)
19377b36b6e0Skxie@chelsio.com 		return -ENOMEM;
19387b36b6e0Skxie@chelsio.com 
19397b36b6e0Skxie@chelsio.com 	csk->hcrc_len = (hcrc ? 4 : 0);
19407b36b6e0Skxie@chelsio.com 	csk->dcrc_len = (dcrc ? 4 : 0);
1941e27d6169Skxie@chelsio.com 	/*  set up ulp submode */
19427b36b6e0Skxie@chelsio.com 	req = (struct cpl_set_tcb_field *)skb->head;
19437b36b6e0Skxie@chelsio.com 	INIT_TP_WR(req, tid);
19447b36b6e0Skxie@chelsio.com 	OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_SET_TCB_FIELD, tid));
1945bdc590b9SHariprasad Shenai 	req->reply_ctrl = htons(NO_REPLY_V(reply) | QUEUENO_V(csk->rss_qid));
1946e27d6169Skxie@chelsio.com 	req->word_cookie = htons(0);
1947e27d6169Skxie@chelsio.com 	req->mask = cpu_to_be64(0x3 << 4);
1948e27d6169Skxie@chelsio.com 	req->val = cpu_to_be64(((hcrc ? ULP_CRC_HEADER : 0) |
1949e27d6169Skxie@chelsio.com 				(dcrc ? ULP_CRC_DATA : 0)) << 4);
19507b36b6e0Skxie@chelsio.com 	set_wr_txq(skb, CPL_PRIORITY_CONTROL, csk->port_id);
19517b36b6e0Skxie@chelsio.com 
19527b36b6e0Skxie@chelsio.com 	log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
19537b36b6e0Skxie@chelsio.com 		"csk 0x%p, tid 0x%x, crc %d,%d.\n", csk, csk->tid, hcrc, dcrc);
19547b36b6e0Skxie@chelsio.com 
19557b36b6e0Skxie@chelsio.com 	cxgb4_ofld_send(csk->cdev->ports[csk->port_id], skb);
19567b36b6e0Skxie@chelsio.com 	return 0;
19577b36b6e0Skxie@chelsio.com }
19587b36b6e0Skxie@chelsio.com 
195971f7a00bSVarun Prakash static struct cxgbi_ppm *cdev2ppm(struct cxgbi_device *cdev)
196071f7a00bSVarun Prakash {
196171f7a00bSVarun Prakash 	return (struct cxgbi_ppm *)(*((struct cxgb4_lld_info *)
196271f7a00bSVarun Prakash 				       (cxgbi_cdev_priv(cdev)))->iscsi_ppm);
196371f7a00bSVarun Prakash }
196471f7a00bSVarun Prakash 
19657b36b6e0Skxie@chelsio.com static int cxgb4i_ddp_init(struct cxgbi_device *cdev)
19667b36b6e0Skxie@chelsio.com {
196771f7a00bSVarun Prakash 	struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(cdev);
196871f7a00bSVarun Prakash 	struct net_device *ndev = cdev->ports[0];
196971f7a00bSVarun Prakash 	struct cxgbi_tag_format tformat;
197071f7a00bSVarun Prakash 	unsigned int ppmax;
197171f7a00bSVarun Prakash 	int i;
197271f7a00bSVarun Prakash 
197371f7a00bSVarun Prakash 	if (!lldi->vr->iscsi.size) {
197471f7a00bSVarun Prakash 		pr_warn("%s, iscsi NOT enabled, check config!\n", ndev->name);
197571f7a00bSVarun Prakash 		return -EACCES;
197671f7a00bSVarun Prakash 	}
197771f7a00bSVarun Prakash 
197871f7a00bSVarun Prakash 	cdev->flags |= CXGBI_FLAG_USE_PPOD_OFLDQ;
197971f7a00bSVarun Prakash 	ppmax = lldi->vr->iscsi.size >> PPOD_SIZE_SHIFT;
198071f7a00bSVarun Prakash 
198171f7a00bSVarun Prakash 	memset(&tformat, 0, sizeof(struct cxgbi_tag_format));
198271f7a00bSVarun Prakash 	for (i = 0; i < 4; i++)
198371f7a00bSVarun Prakash 		tformat.pgsz_order[i] = (lldi->iscsi_pgsz_order >> (i << 3))
198471f7a00bSVarun Prakash 					 & 0xF;
198571f7a00bSVarun Prakash 	cxgbi_tagmask_check(lldi->iscsi_tagmask, &tformat);
198671f7a00bSVarun Prakash 
198771f7a00bSVarun Prakash 	cxgbi_ddp_ppm_setup(lldi->iscsi_ppm, cdev, &tformat, ppmax,
198871f7a00bSVarun Prakash 			    lldi->iscsi_llimit, lldi->vr->iscsi.start, 2);
198971f7a00bSVarun Prakash 
19907b36b6e0Skxie@chelsio.com 	cdev->csk_ddp_setup_digest = ddp_setup_conn_digest;
19917b36b6e0Skxie@chelsio.com 	cdev->csk_ddp_setup_pgidx = ddp_setup_conn_pgidx;
199271f7a00bSVarun Prakash 	cdev->csk_ddp_set_map = ddp_set_map;
199371f7a00bSVarun Prakash 	cdev->tx_max_size = min_t(unsigned int, ULP2_MAX_PDU_PAYLOAD,
199471f7a00bSVarun Prakash 				  lldi->iscsi_iolen - ISCSI_PDU_NONPAYLOAD_LEN);
199571f7a00bSVarun Prakash 	cdev->rx_max_size = min_t(unsigned int, ULP2_MAX_PDU_PAYLOAD,
199671f7a00bSVarun Prakash 				  lldi->iscsi_iolen - ISCSI_PDU_NONPAYLOAD_LEN);
199771f7a00bSVarun Prakash 	cdev->cdev2ppm = cdev2ppm;
199871f7a00bSVarun Prakash 
19997b36b6e0Skxie@chelsio.com 	return 0;
20007b36b6e0Skxie@chelsio.com }
20017b36b6e0Skxie@chelsio.com 
20027b36b6e0Skxie@chelsio.com static void *t4_uld_add(const struct cxgb4_lld_info *lldi)
20037b36b6e0Skxie@chelsio.com {
20047b36b6e0Skxie@chelsio.com 	struct cxgbi_device *cdev;
20057b36b6e0Skxie@chelsio.com 	struct port_info *pi;
20067b36b6e0Skxie@chelsio.com 	int i, rc;
20077b36b6e0Skxie@chelsio.com 
20087b36b6e0Skxie@chelsio.com 	cdev = cxgbi_device_register(sizeof(*lldi), lldi->nports);
20097b36b6e0Skxie@chelsio.com 	if (!cdev) {
20107b36b6e0Skxie@chelsio.com 		pr_info("t4 device 0x%p, register failed.\n", lldi);
20117b36b6e0Skxie@chelsio.com 		return NULL;
20127b36b6e0Skxie@chelsio.com 	}
20137b36b6e0Skxie@chelsio.com 	pr_info("0x%p,0x%x, ports %u,%s, chan %u, q %u,%u, wr %u.\n",
20147b36b6e0Skxie@chelsio.com 		cdev, lldi->adapter_type, lldi->nports,
20157b36b6e0Skxie@chelsio.com 		lldi->ports[0]->name, lldi->nchan, lldi->ntxq,
20167b36b6e0Skxie@chelsio.com 		lldi->nrxq, lldi->wr_cred);
20177b36b6e0Skxie@chelsio.com 	for (i = 0; i < lldi->nrxq; i++)
20187b36b6e0Skxie@chelsio.com 		log_debug(1 << CXGBI_DBG_DEV,
20197b36b6e0Skxie@chelsio.com 			"t4 0x%p, rxq id #%d: %u.\n",
20207b36b6e0Skxie@chelsio.com 			cdev, i, lldi->rxq_ids[i]);
20217b36b6e0Skxie@chelsio.com 
20227b36b6e0Skxie@chelsio.com 	memcpy(cxgbi_cdev_priv(cdev), lldi, sizeof(*lldi));
20237b36b6e0Skxie@chelsio.com 	cdev->flags = CXGBI_FLAG_DEV_T4;
20247b36b6e0Skxie@chelsio.com 	cdev->pdev = lldi->pdev;
20257b36b6e0Skxie@chelsio.com 	cdev->ports = lldi->ports;
20267b36b6e0Skxie@chelsio.com 	cdev->nports = lldi->nports;
20277b36b6e0Skxie@chelsio.com 	cdev->mtus = lldi->mtus;
20287b36b6e0Skxie@chelsio.com 	cdev->nmtus = NMTUS;
2029586be7cbSVarun Prakash 	cdev->rx_credit_thres = (CHELSIO_CHIP_VERSION(lldi->adapter_type) <=
2030586be7cbSVarun Prakash 				 CHELSIO_T5) ? cxgb4i_rx_credit_thres : 0;
20317b36b6e0Skxie@chelsio.com 	cdev->skb_tx_rsvd = CXGB4I_TX_HEADER_LEN;
20327b36b6e0Skxie@chelsio.com 	cdev->skb_rx_extra = sizeof(struct cpl_iscsi_hdr);
20337b36b6e0Skxie@chelsio.com 	cdev->itp = &cxgb4i_iscsi_transport;
20341fe1fdb0SVarun Prakash 	cdev->owner = THIS_MODULE;
20357b36b6e0Skxie@chelsio.com 
2036d7990b0cSAnish Bhatt 	cdev->pfvf = FW_VIID_PFN_G(cxgb4_port_viid(lldi->ports[0]))
2037d7990b0cSAnish Bhatt 			<< FW_VIID_PFN_S;
2038e27d6169Skxie@chelsio.com 	pr_info("cdev 0x%p,%s, pfvf %u.\n",
2039e27d6169Skxie@chelsio.com 		cdev, lldi->ports[0]->name, cdev->pfvf);
2040e27d6169Skxie@chelsio.com 
20417b36b6e0Skxie@chelsio.com 	rc = cxgb4i_ddp_init(cdev);
20427b36b6e0Skxie@chelsio.com 	if (rc) {
20437b36b6e0Skxie@chelsio.com 		pr_info("t4 0x%p ddp init failed.\n", cdev);
20447b36b6e0Skxie@chelsio.com 		goto err_out;
20457b36b6e0Skxie@chelsio.com 	}
20467b36b6e0Skxie@chelsio.com 	rc = cxgb4i_ofld_init(cdev);
20477b36b6e0Skxie@chelsio.com 	if (rc) {
20487b36b6e0Skxie@chelsio.com 		pr_info("t4 0x%p ofld init failed.\n", cdev);
20497b36b6e0Skxie@chelsio.com 		goto err_out;
20507b36b6e0Skxie@chelsio.com 	}
20517b36b6e0Skxie@chelsio.com 
20527b36b6e0Skxie@chelsio.com 	rc = cxgbi_hbas_add(cdev, CXGB4I_MAX_LUN, CXGBI_MAX_CONN,
20537b36b6e0Skxie@chelsio.com 				&cxgb4i_host_template, cxgb4i_stt);
20547b36b6e0Skxie@chelsio.com 	if (rc)
20557b36b6e0Skxie@chelsio.com 		goto err_out;
20567b36b6e0Skxie@chelsio.com 
20577b36b6e0Skxie@chelsio.com 	for (i = 0; i < cdev->nports; i++) {
20587b36b6e0Skxie@chelsio.com 		pi = netdev_priv(lldi->ports[i]);
20597b36b6e0Skxie@chelsio.com 		cdev->hbas[i]->port_id = pi->port_id;
20607b36b6e0Skxie@chelsio.com 	}
20617b36b6e0Skxie@chelsio.com 	return cdev;
20627b36b6e0Skxie@chelsio.com 
20637b36b6e0Skxie@chelsio.com err_out:
20647b36b6e0Skxie@chelsio.com 	cxgbi_device_unregister(cdev);
20657b36b6e0Skxie@chelsio.com 	return ERR_PTR(-ENOMEM);
20667b36b6e0Skxie@chelsio.com }
20677b36b6e0Skxie@chelsio.com 
20687b36b6e0Skxie@chelsio.com #define RX_PULL_LEN	128
20697b36b6e0Skxie@chelsio.com static int t4_uld_rx_handler(void *handle, const __be64 *rsp,
20707b36b6e0Skxie@chelsio.com 				const struct pkt_gl *pgl)
20717b36b6e0Skxie@chelsio.com {
20727b36b6e0Skxie@chelsio.com 	const struct cpl_act_establish *rpl;
20737b36b6e0Skxie@chelsio.com 	struct sk_buff *skb;
20747b36b6e0Skxie@chelsio.com 	unsigned int opc;
20757b36b6e0Skxie@chelsio.com 	struct cxgbi_device *cdev = handle;
20767b36b6e0Skxie@chelsio.com 
20777b36b6e0Skxie@chelsio.com 	if (pgl == NULL) {
20787b36b6e0Skxie@chelsio.com 		unsigned int len = 64 - sizeof(struct rsp_ctrl) - 8;
20797b36b6e0Skxie@chelsio.com 
208024d3f95aSkxie@chelsio.com 		skb = alloc_wr(len, 0, GFP_ATOMIC);
20817b36b6e0Skxie@chelsio.com 		if (!skb)
20827b36b6e0Skxie@chelsio.com 			goto nomem;
20837b36b6e0Skxie@chelsio.com 		skb_copy_to_linear_data(skb, &rsp[1], len);
20847b36b6e0Skxie@chelsio.com 	} else {
20857b36b6e0Skxie@chelsio.com 		if (unlikely(*(u8 *)rsp != *(u8 *)pgl->va)) {
20867b36b6e0Skxie@chelsio.com 			pr_info("? FL 0x%p,RSS%#llx,FL %#llx,len %u.\n",
20877b36b6e0Skxie@chelsio.com 				pgl->va, be64_to_cpu(*rsp),
20887b36b6e0Skxie@chelsio.com 				be64_to_cpu(*(u64 *)pgl->va),
20897b36b6e0Skxie@chelsio.com 				pgl->tot_len);
20907b36b6e0Skxie@chelsio.com 			return 0;
20917b36b6e0Skxie@chelsio.com 		}
20927b36b6e0Skxie@chelsio.com 		skb = cxgb4_pktgl_to_skb(pgl, RX_PULL_LEN, RX_PULL_LEN);
20937b36b6e0Skxie@chelsio.com 		if (unlikely(!skb))
20947b36b6e0Skxie@chelsio.com 			goto nomem;
20957b36b6e0Skxie@chelsio.com 	}
20967b36b6e0Skxie@chelsio.com 
20977b36b6e0Skxie@chelsio.com 	rpl = (struct cpl_act_establish *)skb->data;
20987b36b6e0Skxie@chelsio.com 	opc = rpl->ot.opcode;
20997b36b6e0Skxie@chelsio.com 	log_debug(1 << CXGBI_DBG_TOE,
21007b36b6e0Skxie@chelsio.com 		"cdev %p, opcode 0x%x(0x%x,0x%x), skb %p.\n",
21017b36b6e0Skxie@chelsio.com 		 cdev, opc, rpl->ot.opcode_tid, ntohl(rpl->ot.opcode_tid), skb);
21027b36b6e0Skxie@chelsio.com 	if (cxgb4i_cplhandlers[opc])
21037b36b6e0Skxie@chelsio.com 		cxgb4i_cplhandlers[opc](cdev, skb);
21047b36b6e0Skxie@chelsio.com 	else {
21057b36b6e0Skxie@chelsio.com 		pr_err("No handler for opcode 0x%x.\n", opc);
21067b36b6e0Skxie@chelsio.com 		__kfree_skb(skb);
21077b36b6e0Skxie@chelsio.com 	}
21087b36b6e0Skxie@chelsio.com 	return 0;
21097b36b6e0Skxie@chelsio.com nomem:
21107b36b6e0Skxie@chelsio.com 	log_debug(1 << CXGBI_DBG_TOE, "OOM bailing out.\n");
21117b36b6e0Skxie@chelsio.com 	return 1;
21127b36b6e0Skxie@chelsio.com }
21137b36b6e0Skxie@chelsio.com 
21147b36b6e0Skxie@chelsio.com static int t4_uld_state_change(void *handle, enum cxgb4_state state)
21157b36b6e0Skxie@chelsio.com {
21167b36b6e0Skxie@chelsio.com 	struct cxgbi_device *cdev = handle;
21177b36b6e0Skxie@chelsio.com 
21187b36b6e0Skxie@chelsio.com 	switch (state) {
21197b36b6e0Skxie@chelsio.com 	case CXGB4_STATE_UP:
21207b36b6e0Skxie@chelsio.com 		pr_info("cdev 0x%p, UP.\n", cdev);
21217b36b6e0Skxie@chelsio.com 		break;
21227b36b6e0Skxie@chelsio.com 	case CXGB4_STATE_START_RECOVERY:
21237b36b6e0Skxie@chelsio.com 		pr_info("cdev 0x%p, RECOVERY.\n", cdev);
21247b36b6e0Skxie@chelsio.com 		/* close all connections */
21257b36b6e0Skxie@chelsio.com 		break;
21267b36b6e0Skxie@chelsio.com 	case CXGB4_STATE_DOWN:
21277b36b6e0Skxie@chelsio.com 		pr_info("cdev 0x%p, DOWN.\n", cdev);
21287b36b6e0Skxie@chelsio.com 		break;
21297b36b6e0Skxie@chelsio.com 	case CXGB4_STATE_DETACH:
21307b36b6e0Skxie@chelsio.com 		pr_info("cdev 0x%p, DETACH.\n", cdev);
2131c3b331a3SThadeu Lima de Souza Cascardo 		cxgbi_device_unregister(cdev);
21327b36b6e0Skxie@chelsio.com 		break;
21337b36b6e0Skxie@chelsio.com 	default:
21347b36b6e0Skxie@chelsio.com 		pr_info("cdev 0x%p, unknown state %d.\n", cdev, state);
21357b36b6e0Skxie@chelsio.com 		break;
21367b36b6e0Skxie@chelsio.com 	}
21377b36b6e0Skxie@chelsio.com 	return 0;
21387b36b6e0Skxie@chelsio.com }
21397b36b6e0Skxie@chelsio.com 
21407b36b6e0Skxie@chelsio.com static int __init cxgb4i_init_module(void)
21417b36b6e0Skxie@chelsio.com {
21427b36b6e0Skxie@chelsio.com 	int rc;
21437b36b6e0Skxie@chelsio.com 
21447b36b6e0Skxie@chelsio.com 	printk(KERN_INFO "%s", version);
21457b36b6e0Skxie@chelsio.com 
21467b36b6e0Skxie@chelsio.com 	rc = cxgbi_iscsi_init(&cxgb4i_iscsi_transport, &cxgb4i_stt);
21477b36b6e0Skxie@chelsio.com 	if (rc < 0)
21487b36b6e0Skxie@chelsio.com 		return rc;
21497b36b6e0Skxie@chelsio.com 	cxgb4_register_uld(CXGB4_ULD_ISCSI, &cxgb4i_uld_info);
2150759a0cc5SAnish Bhatt 
21517b36b6e0Skxie@chelsio.com 	return 0;
21527b36b6e0Skxie@chelsio.com }
21537b36b6e0Skxie@chelsio.com 
21547b36b6e0Skxie@chelsio.com static void __exit cxgb4i_exit_module(void)
21557b36b6e0Skxie@chelsio.com {
21567b36b6e0Skxie@chelsio.com 	cxgb4_unregister_uld(CXGB4_ULD_ISCSI);
21577b36b6e0Skxie@chelsio.com 	cxgbi_device_unregister_all(CXGBI_FLAG_DEV_T4);
21587b36b6e0Skxie@chelsio.com 	cxgbi_iscsi_cleanup(&cxgb4i_iscsi_transport, &cxgb4i_stt);
21597b36b6e0Skxie@chelsio.com }
21607b36b6e0Skxie@chelsio.com 
21617b36b6e0Skxie@chelsio.com module_init(cxgb4i_init_module);
21627b36b6e0Skxie@chelsio.com module_exit(cxgb4i_exit_module);
2163