xref: /openbmc/linux/drivers/scsi/cxgbi/cxgb4i/cxgb4i.c (revision 891e2639)
17b36b6e0Skxie@chelsio.com /*
27b36b6e0Skxie@chelsio.com  * cxgb4i.c: Chelsio T4 iSCSI driver.
37b36b6e0Skxie@chelsio.com  *
41149a5edSKaren Xie  * Copyright (c) 2010-2015 Chelsio Communications, Inc.
57b36b6e0Skxie@chelsio.com  *
67b36b6e0Skxie@chelsio.com  * This program is free software; you can redistribute it and/or modify
77b36b6e0Skxie@chelsio.com  * it under the terms of the GNU General Public License as published by
87b36b6e0Skxie@chelsio.com  * the Free Software Foundation.
97b36b6e0Skxie@chelsio.com  *
107b36b6e0Skxie@chelsio.com  * Written by:	Karen Xie (kxie@chelsio.com)
117b36b6e0Skxie@chelsio.com  *		Rakesh Ranjan (rranjan@chelsio.com)
127b36b6e0Skxie@chelsio.com  */
137b36b6e0Skxie@chelsio.com 
147b36b6e0Skxie@chelsio.com #define pr_fmt(fmt) KBUILD_MODNAME ":%s: " fmt, __func__
157b36b6e0Skxie@chelsio.com 
1628466e0fSNicolas Dichtel #include <linux/kernel.h>
177b36b6e0Skxie@chelsio.com #include <linux/module.h>
187b36b6e0Skxie@chelsio.com #include <linux/moduleparam.h>
197b36b6e0Skxie@chelsio.com #include <scsi/scsi_host.h>
207b36b6e0Skxie@chelsio.com #include <net/tcp.h>
217b36b6e0Skxie@chelsio.com #include <net/dst.h>
227b36b6e0Skxie@chelsio.com #include <linux/netdevice.h>
23759a0cc5SAnish Bhatt #include <net/addrconf.h>
247b36b6e0Skxie@chelsio.com 
253bd3e8bfSKaren Xie #include "t4_regs.h"
267b36b6e0Skxie@chelsio.com #include "t4_msg.h"
277b36b6e0Skxie@chelsio.com #include "cxgb4.h"
287b36b6e0Skxie@chelsio.com #include "cxgb4_uld.h"
297b36b6e0Skxie@chelsio.com #include "t4fw_api.h"
307b36b6e0Skxie@chelsio.com #include "l2t.h"
317b36b6e0Skxie@chelsio.com #include "cxgb4i.h"
32211a84e3SAnish Bhatt #include "clip_tbl.h"
337b36b6e0Skxie@chelsio.com 
347b36b6e0Skxie@chelsio.com static unsigned int dbg_level;
357b36b6e0Skxie@chelsio.com 
367b36b6e0Skxie@chelsio.com #include "../libcxgbi.h"
377b36b6e0Skxie@chelsio.com 
38b5a5fe4eSVarun Prakash #ifdef CONFIG_CHELSIO_T4_DCB
39b5a5fe4eSVarun Prakash #include <net/dcbevent.h>
40b5a5fe4eSVarun Prakash #include "cxgb4_dcb.h"
41b5a5fe4eSVarun Prakash #endif
42b5a5fe4eSVarun Prakash 
437b36b6e0Skxie@chelsio.com #define	DRV_MODULE_NAME		"cxgb4i"
44cb22bdc8SVarun Prakash #define DRV_MODULE_DESC		"Chelsio T4-T6 iSCSI Driver"
450ea5bf3dSKaren Xie #define	DRV_MODULE_VERSION	"0.9.5-ko"
460ea5bf3dSKaren Xie #define DRV_MODULE_RELDATE	"Apr. 2015"
477b36b6e0Skxie@chelsio.com 
487b36b6e0Skxie@chelsio.com static char version[] =
497b36b6e0Skxie@chelsio.com 	DRV_MODULE_DESC " " DRV_MODULE_NAME
500ea5bf3dSKaren Xie 	" v" DRV_MODULE_VERSION " (" DRV_MODULE_RELDATE ")\n";
517b36b6e0Skxie@chelsio.com 
527b36b6e0Skxie@chelsio.com MODULE_AUTHOR("Chelsio Communications, Inc.");
537b36b6e0Skxie@chelsio.com MODULE_DESCRIPTION(DRV_MODULE_DESC);
547b36b6e0Skxie@chelsio.com MODULE_VERSION(DRV_MODULE_VERSION);
557b36b6e0Skxie@chelsio.com MODULE_LICENSE("GPL");
567b36b6e0Skxie@chelsio.com 
577b36b6e0Skxie@chelsio.com module_param(dbg_level, uint, 0644);
587b36b6e0Skxie@chelsio.com MODULE_PARM_DESC(dbg_level, "Debug flag (default=0)");
597b36b6e0Skxie@chelsio.com 
6081daf10cSKaren Xie #define CXGB4I_DEFAULT_10G_RCV_WIN (256 * 1024)
6181daf10cSKaren Xie static int cxgb4i_rcv_win = -1;
627b36b6e0Skxie@chelsio.com module_param(cxgb4i_rcv_win, int, 0644);
6321112e13SVarun Prakash MODULE_PARM_DESC(cxgb4i_rcv_win, "TCP receive window in bytes");
647b36b6e0Skxie@chelsio.com 
6581daf10cSKaren Xie #define CXGB4I_DEFAULT_10G_SND_WIN (128 * 1024)
6681daf10cSKaren Xie static int cxgb4i_snd_win = -1;
677b36b6e0Skxie@chelsio.com module_param(cxgb4i_snd_win, int, 0644);
687b36b6e0Skxie@chelsio.com MODULE_PARM_DESC(cxgb4i_snd_win, "TCP send window in bytes");
697b36b6e0Skxie@chelsio.com 
707b36b6e0Skxie@chelsio.com static int cxgb4i_rx_credit_thres = 10 * 1024;
717b36b6e0Skxie@chelsio.com module_param(cxgb4i_rx_credit_thres, int, 0644);
727b36b6e0Skxie@chelsio.com MODULE_PARM_DESC(cxgb4i_rx_credit_thres,
737b36b6e0Skxie@chelsio.com 		"RX credits return threshold in bytes (default=10KB)");
747b36b6e0Skxie@chelsio.com 
757b36b6e0Skxie@chelsio.com static unsigned int cxgb4i_max_connect = (8 * 1024);
767b36b6e0Skxie@chelsio.com module_param(cxgb4i_max_connect, uint, 0644);
777b36b6e0Skxie@chelsio.com MODULE_PARM_DESC(cxgb4i_max_connect, "Maximum number of connections");
787b36b6e0Skxie@chelsio.com 
797b36b6e0Skxie@chelsio.com static unsigned short cxgb4i_sport_base = 20000;
807b36b6e0Skxie@chelsio.com module_param(cxgb4i_sport_base, ushort, 0644);
817b36b6e0Skxie@chelsio.com MODULE_PARM_DESC(cxgb4i_sport_base, "Starting port number (default 20000)");
827b36b6e0Skxie@chelsio.com 
837b36b6e0Skxie@chelsio.com typedef void (*cxgb4i_cplhandler_func)(struct cxgbi_device *, struct sk_buff *);
847b36b6e0Skxie@chelsio.com 
857b36b6e0Skxie@chelsio.com static void *t4_uld_add(const struct cxgb4_lld_info *);
867b36b6e0Skxie@chelsio.com static int t4_uld_rx_handler(void *, const __be64 *, const struct pkt_gl *);
877b36b6e0Skxie@chelsio.com static int t4_uld_state_change(void *, enum cxgb4_state state);
8864bfead8SKaren Xie static inline int send_tx_flowc_wr(struct cxgbi_sock *);
897b36b6e0Skxie@chelsio.com 
907b36b6e0Skxie@chelsio.com static const struct cxgb4_uld_info cxgb4i_uld_info = {
917b36b6e0Skxie@chelsio.com 	.name = DRV_MODULE_NAME,
920fbc81b3SHariprasad Shenai 	.nrxq = MAX_ULD_QSETS,
93ab677ff4SHariprasad Shenai 	.ntxq = MAX_ULD_QSETS,
940fbc81b3SHariprasad Shenai 	.rxq_size = 1024,
950fbc81b3SHariprasad Shenai 	.lro = false,
967b36b6e0Skxie@chelsio.com 	.add = t4_uld_add,
977b36b6e0Skxie@chelsio.com 	.rx_handler = t4_uld_rx_handler,
987b36b6e0Skxie@chelsio.com 	.state_change = t4_uld_state_change,
997b36b6e0Skxie@chelsio.com };
1007b36b6e0Skxie@chelsio.com 
1017b36b6e0Skxie@chelsio.com static struct scsi_host_template cxgb4i_host_template = {
1027b36b6e0Skxie@chelsio.com 	.module		= THIS_MODULE,
1037b36b6e0Skxie@chelsio.com 	.name		= DRV_MODULE_NAME,
1047b36b6e0Skxie@chelsio.com 	.proc_name	= DRV_MODULE_NAME,
1057b36b6e0Skxie@chelsio.com 	.can_queue	= CXGB4I_SCSI_HOST_QDEPTH,
1067b36b6e0Skxie@chelsio.com 	.queuecommand	= iscsi_queuecommand,
107db5ed4dfSChristoph Hellwig 	.change_queue_depth = scsi_change_queue_depth,
1087b36b6e0Skxie@chelsio.com 	.sg_tablesize	= SG_ALL,
1097b36b6e0Skxie@chelsio.com 	.max_sectors	= 0xFFFF,
1107b36b6e0Skxie@chelsio.com 	.cmd_per_lun	= ISCSI_DEF_CMD_PER_LUN,
111b6a05c82SChristoph Hellwig 	.eh_timed_out	= iscsi_eh_cmd_timed_out,
1127b36b6e0Skxie@chelsio.com 	.eh_abort_handler = iscsi_eh_abort,
1137b36b6e0Skxie@chelsio.com 	.eh_device_reset_handler = iscsi_eh_device_reset,
1147b36b6e0Skxie@chelsio.com 	.eh_target_reset_handler = iscsi_eh_recover_target,
1157b36b6e0Skxie@chelsio.com 	.target_alloc	= iscsi_target_alloc,
1164af14d11SChristoph Hellwig 	.dma_boundary	= PAGE_SIZE - 1,
1177b36b6e0Skxie@chelsio.com 	.this_id	= -1,
118c40ecc12SChristoph Hellwig 	.track_queue_depth = 1,
1197b36b6e0Skxie@chelsio.com };
1207b36b6e0Skxie@chelsio.com 
1217b36b6e0Skxie@chelsio.com static struct iscsi_transport cxgb4i_iscsi_transport = {
1227b36b6e0Skxie@chelsio.com 	.owner		= THIS_MODULE,
1237b36b6e0Skxie@chelsio.com 	.name		= DRV_MODULE_NAME,
1247b36b6e0Skxie@chelsio.com 	.caps		= CAP_RECOVERY_L0 | CAP_MULTI_R2T | CAP_HDRDGST |
1257b36b6e0Skxie@chelsio.com 				CAP_DATADGST | CAP_DIGEST_OFFLOAD |
126fdafd4dfSMike Christie 				CAP_PADDING_OFFLOAD | CAP_TEXT_NEGO,
1273128c6c7SMike Christie 	.attr_is_visible	= cxgbi_attr_is_visible,
1287b36b6e0Skxie@chelsio.com 	.get_host_param	= cxgbi_get_host_param,
1297b36b6e0Skxie@chelsio.com 	.set_host_param	= cxgbi_set_host_param,
1307b36b6e0Skxie@chelsio.com 	/* session management */
1317b36b6e0Skxie@chelsio.com 	.create_session	= cxgbi_create_session,
1327b36b6e0Skxie@chelsio.com 	.destroy_session	= cxgbi_destroy_session,
1337b36b6e0Skxie@chelsio.com 	.get_session_param = iscsi_session_get_param,
1347b36b6e0Skxie@chelsio.com 	/* connection management */
1357b36b6e0Skxie@chelsio.com 	.create_conn	= cxgbi_create_conn,
1367b36b6e0Skxie@chelsio.com 	.bind_conn		= cxgbi_bind_conn,
137*891e2639SMike Christie 	.unbind_conn	= iscsi_conn_unbind,
1387b36b6e0Skxie@chelsio.com 	.destroy_conn	= iscsi_tcp_conn_teardown,
1397b36b6e0Skxie@chelsio.com 	.start_conn		= iscsi_conn_start,
1407b36b6e0Skxie@chelsio.com 	.stop_conn		= iscsi_conn_stop,
141c71b9b66SMike Christie 	.get_conn_param	= iscsi_conn_get_param,
1427b36b6e0Skxie@chelsio.com 	.set_param	= cxgbi_set_conn_param,
1437b36b6e0Skxie@chelsio.com 	.get_stats	= cxgbi_get_conn_stats,
1447b36b6e0Skxie@chelsio.com 	/* pdu xmit req from user space */
1457b36b6e0Skxie@chelsio.com 	.send_pdu	= iscsi_conn_send_pdu,
1467b36b6e0Skxie@chelsio.com 	/* task */
1477b36b6e0Skxie@chelsio.com 	.init_task	= iscsi_tcp_task_init,
1487b36b6e0Skxie@chelsio.com 	.xmit_task	= iscsi_tcp_task_xmit,
1497b36b6e0Skxie@chelsio.com 	.cleanup_task	= cxgbi_cleanup_task,
1507b36b6e0Skxie@chelsio.com 	/* pdu */
1517b36b6e0Skxie@chelsio.com 	.alloc_pdu	= cxgbi_conn_alloc_pdu,
1527b36b6e0Skxie@chelsio.com 	.init_pdu	= cxgbi_conn_init_pdu,
1537b36b6e0Skxie@chelsio.com 	.xmit_pdu	= cxgbi_conn_xmit_pdu,
1547b36b6e0Skxie@chelsio.com 	.parse_pdu_itt	= cxgbi_parse_pdu_itt,
1557b36b6e0Skxie@chelsio.com 	/* TCP connect/disconnect */
156c71b9b66SMike Christie 	.get_ep_param	= cxgbi_get_ep_param,
1577b36b6e0Skxie@chelsio.com 	.ep_connect	= cxgbi_ep_connect,
1587b36b6e0Skxie@chelsio.com 	.ep_poll	= cxgbi_ep_poll,
1597b36b6e0Skxie@chelsio.com 	.ep_disconnect	= cxgbi_ep_disconnect,
1607b36b6e0Skxie@chelsio.com 	/* Error recovery timeout call */
1617b36b6e0Skxie@chelsio.com 	.session_recovery_timedout = iscsi_session_recovery_timedout,
1627b36b6e0Skxie@chelsio.com };
1637b36b6e0Skxie@chelsio.com 
164b5a5fe4eSVarun Prakash #ifdef CONFIG_CHELSIO_T4_DCB
165b5a5fe4eSVarun Prakash static int
166b5a5fe4eSVarun Prakash cxgb4_dcb_change_notify(struct notifier_block *, unsigned long, void *);
167b5a5fe4eSVarun Prakash 
168b5a5fe4eSVarun Prakash static struct notifier_block cxgb4_dcb_change = {
169b5a5fe4eSVarun Prakash 	.notifier_call = cxgb4_dcb_change_notify,
170b5a5fe4eSVarun Prakash };
171b5a5fe4eSVarun Prakash #endif
172b5a5fe4eSVarun Prakash 
1737b36b6e0Skxie@chelsio.com static struct scsi_transport_template *cxgb4i_stt;
1747b36b6e0Skxie@chelsio.com 
1757b36b6e0Skxie@chelsio.com /*
1767b36b6e0Skxie@chelsio.com  * CPL (Chelsio Protocol Language) defines a message passing interface between
1777b36b6e0Skxie@chelsio.com  * the host driver and Chelsio asic.
1787b36b6e0Skxie@chelsio.com  * The section below implments CPLs that related to iscsi tcp connection
1797b36b6e0Skxie@chelsio.com  * open/close/abort and data send/receive.
1807b36b6e0Skxie@chelsio.com  */
181759a0cc5SAnish Bhatt 
1827b36b6e0Skxie@chelsio.com #define RCV_BUFSIZ_MASK		0x3FFU
183d3074cceSKaren Xie #define MAX_IMM_TX_PKT_LEN	256
1847b36b6e0Skxie@chelsio.com 
1857b36b6e0Skxie@chelsio.com static int push_tx_frames(struct cxgbi_sock *, int);
1867b36b6e0Skxie@chelsio.com 
1877b36b6e0Skxie@chelsio.com /*
1887b36b6e0Skxie@chelsio.com  * is_ofld_imm - check whether a packet can be sent as immediate data
1897b36b6e0Skxie@chelsio.com  * @skb: the packet
1907b36b6e0Skxie@chelsio.com  *
1917b36b6e0Skxie@chelsio.com  * Returns true if a packet can be sent as an offload WR with immediate
1927b36b6e0Skxie@chelsio.com  * data.  We currently use the same limit as for Ethernet packets.
1937b36b6e0Skxie@chelsio.com  */
19484944d8cSKaren Xie static inline bool is_ofld_imm(const struct sk_buff *skb)
1957b36b6e0Skxie@chelsio.com {
19684944d8cSKaren Xie 	int len = skb->len;
19784944d8cSKaren Xie 
19884944d8cSKaren Xie 	if (likely(cxgbi_skcb_test_flag(skb, SKCBF_TX_NEED_HDR)))
19984944d8cSKaren Xie 		len += sizeof(struct fw_ofld_tx_data_wr);
20084944d8cSKaren Xie 
201e33c2482SVarun Prakash 	if  (likely(cxgbi_skcb_test_flag((struct sk_buff *)skb, SKCBF_TX_ISO)))
202e33c2482SVarun Prakash 		len += sizeof(struct cpl_tx_data_iso);
203e33c2482SVarun Prakash 
204e33c2482SVarun Prakash 	return (len <= MAX_IMM_OFLD_TX_DATA_WR_LEN);
2057b36b6e0Skxie@chelsio.com }
2067b36b6e0Skxie@chelsio.com 
2077b36b6e0Skxie@chelsio.com static void send_act_open_req(struct cxgbi_sock *csk, struct sk_buff *skb,
2087b36b6e0Skxie@chelsio.com 				struct l2t_entry *e)
2097b36b6e0Skxie@chelsio.com {
2103bd3e8bfSKaren Xie 	struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(csk->cdev);
2117b36b6e0Skxie@chelsio.com 	int wscale = cxgbi_sock_compute_wscale(csk->mss_idx);
2127b36b6e0Skxie@chelsio.com 	unsigned long long opt0;
2137b36b6e0Skxie@chelsio.com 	unsigned int opt2;
2147b36b6e0Skxie@chelsio.com 	unsigned int qid_atid = ((unsigned int)csk->atid) |
2157b36b6e0Skxie@chelsio.com 				 (((unsigned int)csk->rss_qid) << 14);
2167b36b6e0Skxie@chelsio.com 
217d7990b0cSAnish Bhatt 	opt0 = KEEP_ALIVE_F |
218d7990b0cSAnish Bhatt 		WND_SCALE_V(wscale) |
219d7990b0cSAnish Bhatt 		MSS_IDX_V(csk->mss_idx) |
220d7990b0cSAnish Bhatt 		L2T_IDX_V(((struct l2t_entry *)csk->l2t)->idx) |
221d7990b0cSAnish Bhatt 		TX_CHAN_V(csk->tx_chan) |
222d7990b0cSAnish Bhatt 		SMAC_SEL_V(csk->smac_idx) |
223d7990b0cSAnish Bhatt 		ULP_MODE_V(ULP_MODE_ISCSI) |
22481daf10cSKaren Xie 		RCV_BUFSIZ_V(csk->rcv_win >> 10);
2251eb88a5dSKaren Xie 
226d7990b0cSAnish Bhatt 	opt2 = RX_CHANNEL_V(0) |
227d7990b0cSAnish Bhatt 		RSS_QUEUE_VALID_F |
228d7990b0cSAnish Bhatt 		RSS_QUEUE_V(csk->rss_qid);
2297b36b6e0Skxie@chelsio.com 
2303bd3e8bfSKaren Xie 	if (is_t4(lldi->adapter_type)) {
2313bd3e8bfSKaren Xie 		struct cpl_act_open_req *req =
2323bd3e8bfSKaren Xie 				(struct cpl_act_open_req *)skb->head;
2333bd3e8bfSKaren Xie 
2347b36b6e0Skxie@chelsio.com 		INIT_TP_WR(req, 0);
2357b36b6e0Skxie@chelsio.com 		OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_ACT_OPEN_REQ,
2367b36b6e0Skxie@chelsio.com 					qid_atid));
2377b36b6e0Skxie@chelsio.com 		req->local_port = csk->saddr.sin_port;
2387b36b6e0Skxie@chelsio.com 		req->peer_port = csk->daddr.sin_port;
2397b36b6e0Skxie@chelsio.com 		req->local_ip = csk->saddr.sin_addr.s_addr;
2407b36b6e0Skxie@chelsio.com 		req->peer_ip = csk->daddr.sin_addr.s_addr;
2417b36b6e0Skxie@chelsio.com 		req->opt0 = cpu_to_be64(opt0);
242ac0245ffSKaren Xie 		req->params = cpu_to_be32(cxgb4_select_ntuple(
243ac0245ffSKaren Xie 					csk->cdev->ports[csk->port_id],
244ac0245ffSKaren Xie 					csk->l2t));
245d7990b0cSAnish Bhatt 		opt2 |= RX_FC_VALID_F;
2467b36b6e0Skxie@chelsio.com 		req->opt2 = cpu_to_be32(opt2);
2477b36b6e0Skxie@chelsio.com 
2487b36b6e0Skxie@chelsio.com 		log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
2493bd3e8bfSKaren Xie 			"csk t4 0x%p, %pI4:%u-%pI4:%u, atid %d, qid %u.\n",
2507b36b6e0Skxie@chelsio.com 			csk, &req->local_ip, ntohs(req->local_port),
2517b36b6e0Skxie@chelsio.com 			&req->peer_ip, ntohs(req->peer_port),
2527b36b6e0Skxie@chelsio.com 			csk->atid, csk->rss_qid);
253586be7cbSVarun Prakash 	} else if (is_t5(lldi->adapter_type)) {
2543bd3e8bfSKaren Xie 		struct cpl_t5_act_open_req *req =
2553bd3e8bfSKaren Xie 				(struct cpl_t5_act_open_req *)skb->head;
2561eb88a5dSKaren Xie 		u32 isn = (prandom_u32() & ~7UL) - 1;
2577b36b6e0Skxie@chelsio.com 
2583bd3e8bfSKaren Xie 		INIT_TP_WR(req, 0);
2593bd3e8bfSKaren Xie 		OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_ACT_OPEN_REQ,
2603bd3e8bfSKaren Xie 					qid_atid));
2613bd3e8bfSKaren Xie 		req->local_port = csk->saddr.sin_port;
2623bd3e8bfSKaren Xie 		req->peer_port = csk->daddr.sin_port;
2633bd3e8bfSKaren Xie 		req->local_ip = csk->saddr.sin_addr.s_addr;
2643bd3e8bfSKaren Xie 		req->peer_ip = csk->daddr.sin_addr.s_addr;
2653bd3e8bfSKaren Xie 		req->opt0 = cpu_to_be64(opt0);
266d7990b0cSAnish Bhatt 		req->params = cpu_to_be64(FILTER_TUPLE_V(
267ac0245ffSKaren Xie 				cxgb4_select_ntuple(
268ac0245ffSKaren Xie 					csk->cdev->ports[csk->port_id],
269ac0245ffSKaren Xie 					csk->l2t)));
2701eb88a5dSKaren Xie 		req->rsvd = cpu_to_be32(isn);
2711eb88a5dSKaren Xie 		opt2 |= T5_ISS_VALID;
2721eb88a5dSKaren Xie 		opt2 |= T5_OPT_2_VALID_F;
2731eb88a5dSKaren Xie 
2743bd3e8bfSKaren Xie 		req->opt2 = cpu_to_be32(opt2);
2753bd3e8bfSKaren Xie 
2763bd3e8bfSKaren Xie 		log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
2773bd3e8bfSKaren Xie 			"csk t5 0x%p, %pI4:%u-%pI4:%u, atid %d, qid %u.\n",
2783bd3e8bfSKaren Xie 			csk, &req->local_ip, ntohs(req->local_port),
2793bd3e8bfSKaren Xie 			&req->peer_ip, ntohs(req->peer_port),
2803bd3e8bfSKaren Xie 			csk->atid, csk->rss_qid);
281586be7cbSVarun Prakash 	} else {
282586be7cbSVarun Prakash 		struct cpl_t6_act_open_req *req =
283586be7cbSVarun Prakash 				(struct cpl_t6_act_open_req *)skb->head;
284586be7cbSVarun Prakash 		u32 isn = (prandom_u32() & ~7UL) - 1;
285586be7cbSVarun Prakash 
286586be7cbSVarun Prakash 		INIT_TP_WR(req, 0);
287586be7cbSVarun Prakash 		OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_ACT_OPEN_REQ,
288586be7cbSVarun Prakash 							    qid_atid));
289586be7cbSVarun Prakash 		req->local_port = csk->saddr.sin_port;
290586be7cbSVarun Prakash 		req->peer_port = csk->daddr.sin_port;
291586be7cbSVarun Prakash 		req->local_ip = csk->saddr.sin_addr.s_addr;
292586be7cbSVarun Prakash 		req->peer_ip = csk->daddr.sin_addr.s_addr;
293586be7cbSVarun Prakash 		req->opt0 = cpu_to_be64(opt0);
294586be7cbSVarun Prakash 		req->params = cpu_to_be64(FILTER_TUPLE_V(
295586be7cbSVarun Prakash 				cxgb4_select_ntuple(
296586be7cbSVarun Prakash 					csk->cdev->ports[csk->port_id],
297586be7cbSVarun Prakash 					csk->l2t)));
298586be7cbSVarun Prakash 		req->rsvd = cpu_to_be32(isn);
299586be7cbSVarun Prakash 
300586be7cbSVarun Prakash 		opt2 |= T5_ISS_VALID;
301586be7cbSVarun Prakash 		opt2 |= RX_FC_DISABLE_F;
302586be7cbSVarun Prakash 		opt2 |= T5_OPT_2_VALID_F;
303586be7cbSVarun Prakash 
304586be7cbSVarun Prakash 		req->opt2 = cpu_to_be32(opt2);
305586be7cbSVarun Prakash 		req->rsvd2 = cpu_to_be32(0);
306586be7cbSVarun Prakash 		req->opt3 = cpu_to_be32(0);
307586be7cbSVarun Prakash 
308586be7cbSVarun Prakash 		log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
309586be7cbSVarun Prakash 			  "csk t6 0x%p, %pI4:%u-%pI4:%u, atid %d, qid %u.\n",
310586be7cbSVarun Prakash 			  csk, &req->local_ip, ntohs(req->local_port),
311586be7cbSVarun Prakash 			  &req->peer_ip, ntohs(req->peer_port),
312586be7cbSVarun Prakash 			  csk->atid, csk->rss_qid);
3133bd3e8bfSKaren Xie 	}
3143bd3e8bfSKaren Xie 
3153bd3e8bfSKaren Xie 	set_wr_txq(skb, CPL_PRIORITY_SETUP, csk->port_id);
316759a0cc5SAnish Bhatt 
317759a0cc5SAnish Bhatt 	pr_info_ipaddr("t%d csk 0x%p,%u,0x%lx,%u, rss_qid %u.\n",
318586be7cbSVarun Prakash 		       (&csk->saddr), (&csk->daddr),
319586be7cbSVarun Prakash 		       CHELSIO_CHIP_VERSION(lldi->adapter_type), csk,
320759a0cc5SAnish Bhatt 		       csk->state, csk->flags, csk->atid, csk->rss_qid);
321759a0cc5SAnish Bhatt 
322759a0cc5SAnish Bhatt 	cxgb4_l2t_send(csk->cdev->ports[csk->port_id], skb, csk->l2t);
323759a0cc5SAnish Bhatt }
324759a0cc5SAnish Bhatt 
325f42bb57cSAnish Bhatt #if IS_ENABLED(CONFIG_IPV6)
326759a0cc5SAnish Bhatt static void send_act_open_req6(struct cxgbi_sock *csk, struct sk_buff *skb,
327759a0cc5SAnish Bhatt 			       struct l2t_entry *e)
328759a0cc5SAnish Bhatt {
329759a0cc5SAnish Bhatt 	struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(csk->cdev);
330759a0cc5SAnish Bhatt 	int wscale = cxgbi_sock_compute_wscale(csk->mss_idx);
331759a0cc5SAnish Bhatt 	unsigned long long opt0;
332759a0cc5SAnish Bhatt 	unsigned int opt2;
333759a0cc5SAnish Bhatt 	unsigned int qid_atid = ((unsigned int)csk->atid) |
334759a0cc5SAnish Bhatt 				 (((unsigned int)csk->rss_qid) << 14);
335759a0cc5SAnish Bhatt 
336d7990b0cSAnish Bhatt 	opt0 = KEEP_ALIVE_F |
337d7990b0cSAnish Bhatt 		WND_SCALE_V(wscale) |
338d7990b0cSAnish Bhatt 		MSS_IDX_V(csk->mss_idx) |
339d7990b0cSAnish Bhatt 		L2T_IDX_V(((struct l2t_entry *)csk->l2t)->idx) |
340d7990b0cSAnish Bhatt 		TX_CHAN_V(csk->tx_chan) |
341d7990b0cSAnish Bhatt 		SMAC_SEL_V(csk->smac_idx) |
342d7990b0cSAnish Bhatt 		ULP_MODE_V(ULP_MODE_ISCSI) |
34381daf10cSKaren Xie 		RCV_BUFSIZ_V(csk->rcv_win >> 10);
344759a0cc5SAnish Bhatt 
345d7990b0cSAnish Bhatt 	opt2 = RX_CHANNEL_V(0) |
346d7990b0cSAnish Bhatt 		RSS_QUEUE_VALID_F |
347d7990b0cSAnish Bhatt 		RSS_QUEUE_V(csk->rss_qid);
348759a0cc5SAnish Bhatt 
349586be7cbSVarun Prakash 	if (is_t4(lldi->adapter_type)) {
350759a0cc5SAnish Bhatt 		struct cpl_act_open_req6 *req =
351759a0cc5SAnish Bhatt 			    (struct cpl_act_open_req6 *)skb->head;
352759a0cc5SAnish Bhatt 
353759a0cc5SAnish Bhatt 		INIT_TP_WR(req, 0);
354759a0cc5SAnish Bhatt 		OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_ACT_OPEN_REQ6,
355759a0cc5SAnish Bhatt 							    qid_atid));
356759a0cc5SAnish Bhatt 		req->local_port = csk->saddr6.sin6_port;
357759a0cc5SAnish Bhatt 		req->peer_port = csk->daddr6.sin6_port;
358759a0cc5SAnish Bhatt 
359759a0cc5SAnish Bhatt 		req->local_ip_hi = *(__be64 *)(csk->saddr6.sin6_addr.s6_addr);
360759a0cc5SAnish Bhatt 		req->local_ip_lo = *(__be64 *)(csk->saddr6.sin6_addr.s6_addr +
361759a0cc5SAnish Bhatt 								    8);
362759a0cc5SAnish Bhatt 		req->peer_ip_hi = *(__be64 *)(csk->daddr6.sin6_addr.s6_addr);
363759a0cc5SAnish Bhatt 		req->peer_ip_lo = *(__be64 *)(csk->daddr6.sin6_addr.s6_addr +
364759a0cc5SAnish Bhatt 								    8);
365759a0cc5SAnish Bhatt 
366759a0cc5SAnish Bhatt 		req->opt0 = cpu_to_be64(opt0);
367759a0cc5SAnish Bhatt 
368d7990b0cSAnish Bhatt 		opt2 |= RX_FC_VALID_F;
369759a0cc5SAnish Bhatt 		req->opt2 = cpu_to_be32(opt2);
370759a0cc5SAnish Bhatt 
371759a0cc5SAnish Bhatt 		req->params = cpu_to_be32(cxgb4_select_ntuple(
372759a0cc5SAnish Bhatt 					  csk->cdev->ports[csk->port_id],
373759a0cc5SAnish Bhatt 					  csk->l2t));
374586be7cbSVarun Prakash 	} else if (is_t5(lldi->adapter_type)) {
375759a0cc5SAnish Bhatt 		struct cpl_t5_act_open_req6 *req =
376759a0cc5SAnish Bhatt 				(struct cpl_t5_act_open_req6 *)skb->head;
377759a0cc5SAnish Bhatt 
378759a0cc5SAnish Bhatt 		INIT_TP_WR(req, 0);
379759a0cc5SAnish Bhatt 		OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_ACT_OPEN_REQ6,
380759a0cc5SAnish Bhatt 							    qid_atid));
381759a0cc5SAnish Bhatt 		req->local_port = csk->saddr6.sin6_port;
382759a0cc5SAnish Bhatt 		req->peer_port = csk->daddr6.sin6_port;
383759a0cc5SAnish Bhatt 		req->local_ip_hi = *(__be64 *)(csk->saddr6.sin6_addr.s6_addr);
384759a0cc5SAnish Bhatt 		req->local_ip_lo = *(__be64 *)(csk->saddr6.sin6_addr.s6_addr +
385759a0cc5SAnish Bhatt 									8);
386759a0cc5SAnish Bhatt 		req->peer_ip_hi = *(__be64 *)(csk->daddr6.sin6_addr.s6_addr);
387759a0cc5SAnish Bhatt 		req->peer_ip_lo = *(__be64 *)(csk->daddr6.sin6_addr.s6_addr +
388759a0cc5SAnish Bhatt 									8);
389759a0cc5SAnish Bhatt 		req->opt0 = cpu_to_be64(opt0);
390759a0cc5SAnish Bhatt 
391d7990b0cSAnish Bhatt 		opt2 |= T5_OPT_2_VALID_F;
392759a0cc5SAnish Bhatt 		req->opt2 = cpu_to_be32(opt2);
393759a0cc5SAnish Bhatt 
394d7990b0cSAnish Bhatt 		req->params = cpu_to_be64(FILTER_TUPLE_V(cxgb4_select_ntuple(
395759a0cc5SAnish Bhatt 					  csk->cdev->ports[csk->port_id],
396759a0cc5SAnish Bhatt 					  csk->l2t)));
397586be7cbSVarun Prakash 	} else {
398586be7cbSVarun Prakash 		struct cpl_t6_act_open_req6 *req =
399586be7cbSVarun Prakash 				(struct cpl_t6_act_open_req6 *)skb->head;
400586be7cbSVarun Prakash 
401586be7cbSVarun Prakash 		INIT_TP_WR(req, 0);
402586be7cbSVarun Prakash 		OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_ACT_OPEN_REQ6,
403586be7cbSVarun Prakash 							    qid_atid));
404586be7cbSVarun Prakash 		req->local_port = csk->saddr6.sin6_port;
405586be7cbSVarun Prakash 		req->peer_port = csk->daddr6.sin6_port;
406586be7cbSVarun Prakash 		req->local_ip_hi = *(__be64 *)(csk->saddr6.sin6_addr.s6_addr);
407586be7cbSVarun Prakash 		req->local_ip_lo = *(__be64 *)(csk->saddr6.sin6_addr.s6_addr +
408586be7cbSVarun Prakash 									8);
409586be7cbSVarun Prakash 		req->peer_ip_hi = *(__be64 *)(csk->daddr6.sin6_addr.s6_addr);
410586be7cbSVarun Prakash 		req->peer_ip_lo = *(__be64 *)(csk->daddr6.sin6_addr.s6_addr +
411586be7cbSVarun Prakash 									8);
412586be7cbSVarun Prakash 		req->opt0 = cpu_to_be64(opt0);
413586be7cbSVarun Prakash 
414586be7cbSVarun Prakash 		opt2 |= RX_FC_DISABLE_F;
415586be7cbSVarun Prakash 		opt2 |= T5_OPT_2_VALID_F;
416586be7cbSVarun Prakash 
417586be7cbSVarun Prakash 		req->opt2 = cpu_to_be32(opt2);
418586be7cbSVarun Prakash 
419586be7cbSVarun Prakash 		req->params = cpu_to_be64(FILTER_TUPLE_V(cxgb4_select_ntuple(
420586be7cbSVarun Prakash 					  csk->cdev->ports[csk->port_id],
421586be7cbSVarun Prakash 					  csk->l2t)));
422586be7cbSVarun Prakash 
423586be7cbSVarun Prakash 		req->rsvd2 = cpu_to_be32(0);
424586be7cbSVarun Prakash 		req->opt3 = cpu_to_be32(0);
425759a0cc5SAnish Bhatt 	}
426759a0cc5SAnish Bhatt 
427759a0cc5SAnish Bhatt 	set_wr_txq(skb, CPL_PRIORITY_SETUP, csk->port_id);
428759a0cc5SAnish Bhatt 
429759a0cc5SAnish Bhatt 	pr_info("t%d csk 0x%p,%u,0x%lx,%u, [%pI6]:%u-[%pI6]:%u, rss_qid %u.\n",
430586be7cbSVarun Prakash 		CHELSIO_CHIP_VERSION(lldi->adapter_type), csk, csk->state,
431586be7cbSVarun Prakash 		csk->flags, csk->atid,
432759a0cc5SAnish Bhatt 		&csk->saddr6.sin6_addr, ntohs(csk->saddr.sin_port),
433759a0cc5SAnish Bhatt 		&csk->daddr6.sin6_addr, ntohs(csk->daddr.sin_port),
434759a0cc5SAnish Bhatt 		csk->rss_qid);
435759a0cc5SAnish Bhatt 
4367b36b6e0Skxie@chelsio.com 	cxgb4_l2t_send(csk->cdev->ports[csk->port_id], skb, csk->l2t);
4377b36b6e0Skxie@chelsio.com }
438f42bb57cSAnish Bhatt #endif
4397b36b6e0Skxie@chelsio.com 
4407b36b6e0Skxie@chelsio.com static void send_close_req(struct cxgbi_sock *csk)
4417b36b6e0Skxie@chelsio.com {
4427b36b6e0Skxie@chelsio.com 	struct sk_buff *skb = csk->cpl_close;
4437b36b6e0Skxie@chelsio.com 	struct cpl_close_con_req *req = (struct cpl_close_con_req *)skb->head;
4447b36b6e0Skxie@chelsio.com 	unsigned int tid = csk->tid;
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.\n",
4487b36b6e0Skxie@chelsio.com 		csk, csk->state, csk->flags, csk->tid);
4497b36b6e0Skxie@chelsio.com 	csk->cpl_close = NULL;
4507b36b6e0Skxie@chelsio.com 	set_wr_txq(skb, CPL_PRIORITY_DATA, csk->port_id);
4517b36b6e0Skxie@chelsio.com 	INIT_TP_WR(req, tid);
4527b36b6e0Skxie@chelsio.com 	OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_CLOSE_CON_REQ, tid));
4537b36b6e0Skxie@chelsio.com 	req->rsvd = 0;
4547b36b6e0Skxie@chelsio.com 
4557b36b6e0Skxie@chelsio.com 	cxgbi_sock_skb_entail(csk, skb);
4567b36b6e0Skxie@chelsio.com 	if (csk->state >= CTP_ESTABLISHED)
4577b36b6e0Skxie@chelsio.com 		push_tx_frames(csk, 1);
4587b36b6e0Skxie@chelsio.com }
4597b36b6e0Skxie@chelsio.com 
4607b36b6e0Skxie@chelsio.com static void abort_arp_failure(void *handle, struct sk_buff *skb)
4617b36b6e0Skxie@chelsio.com {
4627b36b6e0Skxie@chelsio.com 	struct cxgbi_sock *csk = (struct cxgbi_sock *)handle;
4637b36b6e0Skxie@chelsio.com 	struct cpl_abort_req *req;
4647b36b6e0Skxie@chelsio.com 
4657b36b6e0Skxie@chelsio.com 	log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
4667b36b6e0Skxie@chelsio.com 		"csk 0x%p,%u,0x%lx, tid %u, abort.\n",
4677b36b6e0Skxie@chelsio.com 		csk, csk->state, csk->flags, csk->tid);
4687b36b6e0Skxie@chelsio.com 	req = (struct cpl_abort_req *)skb->data;
4697b36b6e0Skxie@chelsio.com 	req->cmd = CPL_ABORT_NO_RST;
4707b36b6e0Skxie@chelsio.com 	cxgb4_ofld_send(csk->cdev->ports[csk->port_id], skb);
4717b36b6e0Skxie@chelsio.com }
4727b36b6e0Skxie@chelsio.com 
4737b36b6e0Skxie@chelsio.com static void send_abort_req(struct cxgbi_sock *csk)
4747b36b6e0Skxie@chelsio.com {
4757b36b6e0Skxie@chelsio.com 	struct cpl_abort_req *req;
4767b36b6e0Skxie@chelsio.com 	struct sk_buff *skb = csk->cpl_abort_req;
4777b36b6e0Skxie@chelsio.com 
4787b36b6e0Skxie@chelsio.com 	if (unlikely(csk->state == CTP_ABORTING) || !skb || !csk->cdev)
4797b36b6e0Skxie@chelsio.com 		return;
48064bfead8SKaren Xie 
48164bfead8SKaren Xie 	if (!cxgbi_sock_flag(csk, CTPF_TX_DATA_SENT)) {
48264bfead8SKaren Xie 		send_tx_flowc_wr(csk);
48364bfead8SKaren Xie 		cxgbi_sock_set_flag(csk, CTPF_TX_DATA_SENT);
48464bfead8SKaren Xie 	}
48564bfead8SKaren Xie 
4867b36b6e0Skxie@chelsio.com 	cxgbi_sock_set_state(csk, CTP_ABORTING);
4877b36b6e0Skxie@chelsio.com 	cxgbi_sock_set_flag(csk, CTPF_ABORT_RPL_PENDING);
4887b36b6e0Skxie@chelsio.com 	cxgbi_sock_purge_write_queue(csk);
4897b36b6e0Skxie@chelsio.com 
4907b36b6e0Skxie@chelsio.com 	csk->cpl_abort_req = NULL;
4917b36b6e0Skxie@chelsio.com 	req = (struct cpl_abort_req *)skb->head;
4922126bc5eSKaren Xie 	set_wr_txq(skb, CPL_PRIORITY_DATA, csk->port_id);
4937b36b6e0Skxie@chelsio.com 	req->cmd = CPL_ABORT_SEND_RST;
4947b36b6e0Skxie@chelsio.com 	t4_set_arp_err_handler(skb, csk, abort_arp_failure);
4957b36b6e0Skxie@chelsio.com 	INIT_TP_WR(req, csk->tid);
4967b36b6e0Skxie@chelsio.com 	OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_ABORT_REQ, csk->tid));
4977b36b6e0Skxie@chelsio.com 	req->rsvd0 = htonl(csk->snd_nxt);
4987b36b6e0Skxie@chelsio.com 	req->rsvd1 = !cxgbi_sock_flag(csk, CTPF_TX_DATA_SENT);
4997b36b6e0Skxie@chelsio.com 
5007b36b6e0Skxie@chelsio.com 	log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
5017b36b6e0Skxie@chelsio.com 		"csk 0x%p,%u,0x%lx,%u, snd_nxt %u, 0x%x.\n",
5027b36b6e0Skxie@chelsio.com 		csk, csk->state, csk->flags, csk->tid, csk->snd_nxt,
5037b36b6e0Skxie@chelsio.com 		req->rsvd1);
5047b36b6e0Skxie@chelsio.com 
5057b36b6e0Skxie@chelsio.com 	cxgb4_l2t_send(csk->cdev->ports[csk->port_id], skb, csk->l2t);
5067b36b6e0Skxie@chelsio.com }
5077b36b6e0Skxie@chelsio.com 
5087b36b6e0Skxie@chelsio.com static void send_abort_rpl(struct cxgbi_sock *csk, int rst_status)
5097b36b6e0Skxie@chelsio.com {
5107b36b6e0Skxie@chelsio.com 	struct sk_buff *skb = csk->cpl_abort_rpl;
5117b36b6e0Skxie@chelsio.com 	struct cpl_abort_rpl *rpl = (struct cpl_abort_rpl *)skb->head;
5127b36b6e0Skxie@chelsio.com 
5137b36b6e0Skxie@chelsio.com 	log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
5147b36b6e0Skxie@chelsio.com 		"csk 0x%p,%u,0x%lx,%u, status %d.\n",
5157b36b6e0Skxie@chelsio.com 		csk, csk->state, csk->flags, csk->tid, rst_status);
5167b36b6e0Skxie@chelsio.com 
5177b36b6e0Skxie@chelsio.com 	csk->cpl_abort_rpl = NULL;
5182126bc5eSKaren Xie 	set_wr_txq(skb, CPL_PRIORITY_DATA, csk->port_id);
5197b36b6e0Skxie@chelsio.com 	INIT_TP_WR(rpl, csk->tid);
5207b36b6e0Skxie@chelsio.com 	OPCODE_TID(rpl) = cpu_to_be32(MK_OPCODE_TID(CPL_ABORT_RPL, csk->tid));
5217b36b6e0Skxie@chelsio.com 	rpl->cmd = rst_status;
5227b36b6e0Skxie@chelsio.com 	cxgb4_ofld_send(csk->cdev->ports[csk->port_id], skb);
5237b36b6e0Skxie@chelsio.com }
5247b36b6e0Skxie@chelsio.com 
5257b36b6e0Skxie@chelsio.com /*
5267b36b6e0Skxie@chelsio.com  * CPL connection rx data ack: host ->
5277b36b6e0Skxie@chelsio.com  * Send RX credits through an RX_DATA_ACK CPL message. Returns the number of
5287b36b6e0Skxie@chelsio.com  * credits sent.
5297b36b6e0Skxie@chelsio.com  */
5307b36b6e0Skxie@chelsio.com static u32 send_rx_credits(struct cxgbi_sock *csk, u32 credits)
5317b36b6e0Skxie@chelsio.com {
5327b36b6e0Skxie@chelsio.com 	struct sk_buff *skb;
5337b36b6e0Skxie@chelsio.com 	struct cpl_rx_data_ack *req;
5347b36b6e0Skxie@chelsio.com 
5357b36b6e0Skxie@chelsio.com 	log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_PDU_RX,
5367b36b6e0Skxie@chelsio.com 		"csk 0x%p,%u,0x%lx,%u, credit %u.\n",
5377b36b6e0Skxie@chelsio.com 		csk, csk->state, csk->flags, csk->tid, credits);
5387b36b6e0Skxie@chelsio.com 
53924d3f95aSkxie@chelsio.com 	skb = alloc_wr(sizeof(*req), 0, GFP_ATOMIC);
5407b36b6e0Skxie@chelsio.com 	if (!skb) {
5417b36b6e0Skxie@chelsio.com 		pr_info("csk 0x%p, credit %u, OOM.\n", csk, credits);
5427b36b6e0Skxie@chelsio.com 		return 0;
5437b36b6e0Skxie@chelsio.com 	}
5447b36b6e0Skxie@chelsio.com 	req = (struct cpl_rx_data_ack *)skb->head;
5457b36b6e0Skxie@chelsio.com 
5467b36b6e0Skxie@chelsio.com 	set_wr_txq(skb, CPL_PRIORITY_ACK, csk->port_id);
5477b36b6e0Skxie@chelsio.com 	INIT_TP_WR(req, csk->tid);
5487b36b6e0Skxie@chelsio.com 	OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_RX_DATA_ACK,
5497b36b6e0Skxie@chelsio.com 				      csk->tid));
550d7990b0cSAnish Bhatt 	req->credit_dack = cpu_to_be32(RX_CREDITS_V(credits)
551d7990b0cSAnish Bhatt 				       | RX_FORCE_ACK_F);
5527b36b6e0Skxie@chelsio.com 	cxgb4_ofld_send(csk->cdev->ports[csk->port_id], skb);
5537b36b6e0Skxie@chelsio.com 	return credits;
5547b36b6e0Skxie@chelsio.com }
5557b36b6e0Skxie@chelsio.com 
5567b36b6e0Skxie@chelsio.com /*
5577b36b6e0Skxie@chelsio.com  * sgl_len - calculates the size of an SGL of the given capacity
5587b36b6e0Skxie@chelsio.com  * @n: the number of SGL entries
5597b36b6e0Skxie@chelsio.com  * Calculates the number of flits needed for a scatter/gather list that
5607b36b6e0Skxie@chelsio.com  * can hold the given number of entries.
5617b36b6e0Skxie@chelsio.com  */
5627b36b6e0Skxie@chelsio.com static inline unsigned int sgl_len(unsigned int n)
5637b36b6e0Skxie@chelsio.com {
5647b36b6e0Skxie@chelsio.com 	n--;
5657b36b6e0Skxie@chelsio.com 	return (3 * n) / 2 + (n & 1) + 2;
5667b36b6e0Skxie@chelsio.com }
5677b36b6e0Skxie@chelsio.com 
5687b36b6e0Skxie@chelsio.com /*
5697b36b6e0Skxie@chelsio.com  * calc_tx_flits_ofld - calculate # of flits for an offload packet
5707b36b6e0Skxie@chelsio.com  * @skb: the packet
5717b36b6e0Skxie@chelsio.com  *
5727b36b6e0Skxie@chelsio.com  * Returns the number of flits needed for the given offload packet.
5737b36b6e0Skxie@chelsio.com  * These packets are already fully constructed and no additional headers
5747b36b6e0Skxie@chelsio.com  * will be added.
5757b36b6e0Skxie@chelsio.com  */
5767b36b6e0Skxie@chelsio.com static inline unsigned int calc_tx_flits_ofld(const struct sk_buff *skb)
5777b36b6e0Skxie@chelsio.com {
5787b36b6e0Skxie@chelsio.com 	unsigned int flits, cnt;
5797b36b6e0Skxie@chelsio.com 
5807b36b6e0Skxie@chelsio.com 	if (is_ofld_imm(skb))
5817b36b6e0Skxie@chelsio.com 		return DIV_ROUND_UP(skb->len, 8);
5827b36b6e0Skxie@chelsio.com 	flits = skb_transport_offset(skb) / 8;
5837b36b6e0Skxie@chelsio.com 	cnt = skb_shinfo(skb)->nr_frags;
584499e2e6fSIsaku Yamahata 	if (skb_tail_pointer(skb) != skb_transport_header(skb))
5857b36b6e0Skxie@chelsio.com 		cnt++;
5867b36b6e0Skxie@chelsio.com 	return flits + sgl_len(cnt);
5877b36b6e0Skxie@chelsio.com }
5887b36b6e0Skxie@chelsio.com 
58964bfead8SKaren Xie #define FLOWC_WR_NPARAMS_MIN	9
59064bfead8SKaren Xie static inline int tx_flowc_wr_credits(int *nparamsp, int *flowclenp)
59164bfead8SKaren Xie {
59264bfead8SKaren Xie 	int nparams, flowclen16, flowclen;
59364bfead8SKaren Xie 
59464bfead8SKaren Xie 	nparams = FLOWC_WR_NPARAMS_MIN;
595b5a5fe4eSVarun Prakash #ifdef CONFIG_CHELSIO_T4_DCB
596b5a5fe4eSVarun Prakash 	nparams++;
597b5a5fe4eSVarun Prakash #endif
59864bfead8SKaren Xie 	flowclen = offsetof(struct fw_flowc_wr, mnemval[nparams]);
59964bfead8SKaren Xie 	flowclen16 = DIV_ROUND_UP(flowclen, 16);
60064bfead8SKaren Xie 	flowclen = flowclen16 * 16;
60164bfead8SKaren Xie 	/*
60264bfead8SKaren Xie 	 * Return the number of 16-byte credits used by the FlowC request.
60364bfead8SKaren Xie 	 * Pass back the nparams and actual FlowC length if requested.
60464bfead8SKaren Xie 	 */
60564bfead8SKaren Xie 	if (nparamsp)
60664bfead8SKaren Xie 		*nparamsp = nparams;
60764bfead8SKaren Xie 	if (flowclenp)
60864bfead8SKaren Xie 		*flowclenp = flowclen;
60964bfead8SKaren Xie 
61064bfead8SKaren Xie 	return flowclen16;
61164bfead8SKaren Xie }
61264bfead8SKaren Xie 
61364bfead8SKaren Xie static inline int send_tx_flowc_wr(struct cxgbi_sock *csk)
6147b36b6e0Skxie@chelsio.com {
6157b36b6e0Skxie@chelsio.com 	struct sk_buff *skb;
6167b36b6e0Skxie@chelsio.com 	struct fw_flowc_wr *flowc;
61764bfead8SKaren Xie 	int nparams, flowclen16, flowclen;
6187b36b6e0Skxie@chelsio.com 
619b5a5fe4eSVarun Prakash #ifdef CONFIG_CHELSIO_T4_DCB
620b5a5fe4eSVarun Prakash 	u16 vlan = ((struct l2t_entry *)csk->l2t)->vlan;
621b5a5fe4eSVarun Prakash #endif
62264bfead8SKaren Xie 	flowclen16 = tx_flowc_wr_credits(&nparams, &flowclen);
62324d3f95aSkxie@chelsio.com 	skb = alloc_wr(flowclen, 0, GFP_ATOMIC);
6247b36b6e0Skxie@chelsio.com 	flowc = (struct fw_flowc_wr *)skb->head;
6257b36b6e0Skxie@chelsio.com 	flowc->op_to_nparams =
62664bfead8SKaren Xie 		htonl(FW_WR_OP_V(FW_FLOWC_WR) | FW_FLOWC_WR_NPARAMS_V(nparams));
6277b36b6e0Skxie@chelsio.com 	flowc->flowid_len16 =
62864bfead8SKaren Xie 		htonl(FW_WR_LEN16_V(flowclen16) | FW_WR_FLOWID_V(csk->tid));
6297b36b6e0Skxie@chelsio.com 	flowc->mnemval[0].mnemonic = FW_FLOWC_MNEM_PFNVFN;
630e27d6169Skxie@chelsio.com 	flowc->mnemval[0].val = htonl(csk->cdev->pfvf);
6317b36b6e0Skxie@chelsio.com 	flowc->mnemval[1].mnemonic = FW_FLOWC_MNEM_CH;
6327b36b6e0Skxie@chelsio.com 	flowc->mnemval[1].val = htonl(csk->tx_chan);
6337b36b6e0Skxie@chelsio.com 	flowc->mnemval[2].mnemonic = FW_FLOWC_MNEM_PORT;
6347b36b6e0Skxie@chelsio.com 	flowc->mnemval[2].val = htonl(csk->tx_chan);
6357b36b6e0Skxie@chelsio.com 	flowc->mnemval[3].mnemonic = FW_FLOWC_MNEM_IQID;
6367b36b6e0Skxie@chelsio.com 	flowc->mnemval[3].val = htonl(csk->rss_qid);
6377b36b6e0Skxie@chelsio.com 	flowc->mnemval[4].mnemonic = FW_FLOWC_MNEM_SNDNXT;
6387b36b6e0Skxie@chelsio.com 	flowc->mnemval[4].val = htonl(csk->snd_nxt);
6397b36b6e0Skxie@chelsio.com 	flowc->mnemval[5].mnemonic = FW_FLOWC_MNEM_RCVNXT;
6407b36b6e0Skxie@chelsio.com 	flowc->mnemval[5].val = htonl(csk->rcv_nxt);
6417b36b6e0Skxie@chelsio.com 	flowc->mnemval[6].mnemonic = FW_FLOWC_MNEM_SNDBUF;
64281daf10cSKaren Xie 	flowc->mnemval[6].val = htonl(csk->snd_win);
6437b36b6e0Skxie@chelsio.com 	flowc->mnemval[7].mnemonic = FW_FLOWC_MNEM_MSS;
6447b36b6e0Skxie@chelsio.com 	flowc->mnemval[7].val = htonl(csk->advmss);
6457b36b6e0Skxie@chelsio.com 	flowc->mnemval[8].mnemonic = 0;
6467b36b6e0Skxie@chelsio.com 	flowc->mnemval[8].val = 0;
64764bfead8SKaren Xie 	flowc->mnemval[8].mnemonic = FW_FLOWC_MNEM_TXDATAPLEN_MAX;
648e33c2482SVarun Prakash 	if (csk->cdev->skb_iso_txhdr)
649e33c2482SVarun Prakash 		flowc->mnemval[8].val = cpu_to_be32(CXGBI_MAX_ISO_DATA_IN_SKB);
650e33c2482SVarun Prakash 	else
651e33c2482SVarun Prakash 		flowc->mnemval[8].val = cpu_to_be32(16128);
652b5a5fe4eSVarun Prakash #ifdef CONFIG_CHELSIO_T4_DCB
653b5a5fe4eSVarun Prakash 	flowc->mnemval[9].mnemonic = FW_FLOWC_MNEM_DCBPRIO;
654b5a5fe4eSVarun Prakash 	if (vlan == CPL_L2T_VLAN_NONE) {
655b5a5fe4eSVarun Prakash 		pr_warn_ratelimited("csk %u without VLAN Tag on DCB Link\n",
656b5a5fe4eSVarun Prakash 				    csk->tid);
657b5a5fe4eSVarun Prakash 		flowc->mnemval[9].val = cpu_to_be32(0);
658b5a5fe4eSVarun Prakash 	} else {
659b5a5fe4eSVarun Prakash 		flowc->mnemval[9].val = cpu_to_be32((vlan & VLAN_PRIO_MASK) >>
660b5a5fe4eSVarun Prakash 					VLAN_PRIO_SHIFT);
661b5a5fe4eSVarun Prakash 	}
662b5a5fe4eSVarun Prakash #endif
66364bfead8SKaren Xie 
6642126bc5eSKaren Xie 	set_wr_txq(skb, CPL_PRIORITY_DATA, csk->port_id);
6657b36b6e0Skxie@chelsio.com 
6667b36b6e0Skxie@chelsio.com 	log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
6677b36b6e0Skxie@chelsio.com 		"csk 0x%p, tid 0x%x, %u,%u,%u,%u,%u,%u,%u.\n",
6687b36b6e0Skxie@chelsio.com 		csk, csk->tid, 0, csk->tx_chan, csk->rss_qid,
66981daf10cSKaren Xie 		csk->snd_nxt, csk->rcv_nxt, csk->snd_win,
6707b36b6e0Skxie@chelsio.com 		csk->advmss);
6717b36b6e0Skxie@chelsio.com 
6727b36b6e0Skxie@chelsio.com 	cxgb4_ofld_send(csk->cdev->ports[csk->port_id], skb);
67364bfead8SKaren Xie 
67464bfead8SKaren Xie 	return flowclen16;
6757b36b6e0Skxie@chelsio.com }
6767b36b6e0Skxie@chelsio.com 
677e33c2482SVarun Prakash static void
678e33c2482SVarun Prakash cxgb4i_make_tx_iso_cpl(struct sk_buff *skb, struct cpl_tx_data_iso *cpl)
6797b36b6e0Skxie@chelsio.com {
680e33c2482SVarun Prakash 	struct cxgbi_iso_info *info = (struct cxgbi_iso_info *)skb->head;
681e33c2482SVarun Prakash 	u32 imm_en = !!(info->flags & CXGBI_ISO_INFO_IMM_ENABLE);
682e33c2482SVarun Prakash 	u32 fslice = !!(info->flags & CXGBI_ISO_INFO_FSLICE);
683e33c2482SVarun Prakash 	u32 lslice = !!(info->flags & CXGBI_ISO_INFO_LSLICE);
684e33c2482SVarun Prakash 	u32 pdu_type = (info->op == ISCSI_OP_SCSI_CMD) ? 0 : 1;
685e33c2482SVarun Prakash 	u32 submode = cxgbi_skcb_tx_ulp_mode(skb) & 0x3;
6867b36b6e0Skxie@chelsio.com 
687e33c2482SVarun Prakash 	cpl->op_to_scsi = cpu_to_be32(CPL_TX_DATA_ISO_OP_V(CPL_TX_DATA_ISO) |
688e33c2482SVarun Prakash 				CPL_TX_DATA_ISO_FIRST_V(fslice) |
689e33c2482SVarun Prakash 				CPL_TX_DATA_ISO_LAST_V(lslice) |
690e33c2482SVarun Prakash 				CPL_TX_DATA_ISO_CPLHDRLEN_V(0) |
691e33c2482SVarun Prakash 				CPL_TX_DATA_ISO_HDRCRC_V(submode & 1) |
692e33c2482SVarun Prakash 				CPL_TX_DATA_ISO_PLDCRC_V(((submode >> 1) & 1)) |
693e33c2482SVarun Prakash 				CPL_TX_DATA_ISO_IMMEDIATE_V(imm_en) |
694e33c2482SVarun Prakash 				CPL_TX_DATA_ISO_SCSI_V(pdu_type));
6957b36b6e0Skxie@chelsio.com 
696e33c2482SVarun Prakash 	cpl->ahs_len = info->ahs;
697e33c2482SVarun Prakash 	cpl->mpdu = cpu_to_be16(DIV_ROUND_UP(info->mpdu, 4));
698e33c2482SVarun Prakash 	cpl->burst_size = cpu_to_be32(info->burst_size);
699e33c2482SVarun Prakash 	cpl->len = cpu_to_be32(info->len);
700e33c2482SVarun Prakash 	cpl->reserved2_seglen_offset =
701e33c2482SVarun Prakash 	     cpu_to_be32(CPL_TX_DATA_ISO_SEGLEN_OFFSET_V(info->segment_offset));
702e33c2482SVarun Prakash 	cpl->datasn_offset = cpu_to_be32(info->datasn_offset);
703e33c2482SVarun Prakash 	cpl->buffer_offset = cpu_to_be32(info->buffer_offset);
704e33c2482SVarun Prakash 	cpl->reserved3 = cpu_to_be32(0);
705e33c2482SVarun Prakash 	log_debug(1 << CXGBI_DBG_ISCSI | 1 << CXGBI_DBG_PDU_TX,
706e33c2482SVarun Prakash 		  "iso: flags 0x%x, op %u, ahs %u, num_pdu %u, mpdu %u, "
707e33c2482SVarun Prakash 		  "burst_size %u, iso_len %u\n",
708e33c2482SVarun Prakash 		  info->flags, info->op, info->ahs, info->num_pdu,
709e33c2482SVarun Prakash 		  info->mpdu, info->burst_size << 2, info->len);
7107b36b6e0Skxie@chelsio.com }
711e33c2482SVarun Prakash 
712e33c2482SVarun Prakash static void
713e33c2482SVarun Prakash cxgb4i_make_tx_data_wr(struct cxgbi_sock *csk, struct sk_buff *skb, int dlen,
714e33c2482SVarun Prakash 		       int len, u32 credits, int compl)
715e33c2482SVarun Prakash {
716e33c2482SVarun Prakash 	struct cxgbi_device *cdev = csk->cdev;
717e33c2482SVarun Prakash 	struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(cdev);
718e33c2482SVarun Prakash 	struct fw_ofld_tx_data_wr *req;
719e33c2482SVarun Prakash 	struct cpl_tx_data_iso *cpl;
720e33c2482SVarun Prakash 	u32 submode = cxgbi_skcb_tx_ulp_mode(skb) & 0x3;
721e33c2482SVarun Prakash 	u32 wr_ulp_mode = 0;
722e33c2482SVarun Prakash 	u32 hdr_size = sizeof(*req);
723e33c2482SVarun Prakash 	u32 opcode = FW_OFLD_TX_DATA_WR;
724e33c2482SVarun Prakash 	u32 immlen = 0;
725e33c2482SVarun Prakash 	u32 force = is_t5(lldi->adapter_type) ? TX_FORCE_V(!submode) :
726e33c2482SVarun Prakash 						T6_TX_FORCE_F;
727e33c2482SVarun Prakash 
728e33c2482SVarun Prakash 	if (cxgbi_skcb_test_flag(skb, SKCBF_TX_ISO)) {
729e33c2482SVarun Prakash 		hdr_size += sizeof(struct cpl_tx_data_iso);
730e33c2482SVarun Prakash 		opcode = FW_ISCSI_TX_DATA_WR;
731e33c2482SVarun Prakash 		immlen += sizeof(struct cpl_tx_data_iso);
732e33c2482SVarun Prakash 		submode |= 8;
733e33c2482SVarun Prakash 	}
734e33c2482SVarun Prakash 
735e33c2482SVarun Prakash 	if (is_ofld_imm(skb))
736e33c2482SVarun Prakash 		immlen += dlen;
737e33c2482SVarun Prakash 
738e33c2482SVarun Prakash 	req = (struct fw_ofld_tx_data_wr *)__skb_push(skb, hdr_size);
739e33c2482SVarun Prakash 	req->op_to_immdlen = cpu_to_be32(FW_WR_OP_V(opcode) |
740e33c2482SVarun Prakash 					 FW_WR_COMPL_V(compl) |
741e33c2482SVarun Prakash 					 FW_WR_IMMDLEN_V(immlen));
742e33c2482SVarun Prakash 	req->flowid_len16 = cpu_to_be32(FW_WR_FLOWID_V(csk->tid) |
743e33c2482SVarun Prakash 					FW_WR_LEN16_V(credits));
744e33c2482SVarun Prakash 	req->plen = cpu_to_be32(len);
745e33c2482SVarun Prakash 	cpl =  (struct cpl_tx_data_iso *)(req + 1);
746e33c2482SVarun Prakash 
747e33c2482SVarun Prakash 	if (likely(cxgbi_skcb_test_flag(skb, SKCBF_TX_ISO)))
748e33c2482SVarun Prakash 		cxgb4i_make_tx_iso_cpl(skb, cpl);
749e33c2482SVarun Prakash 
7507b36b6e0Skxie@chelsio.com 	if (submode)
751e2ac9628SHariprasad Shenai 		wr_ulp_mode = FW_OFLD_TX_DATA_WR_ULPMODE_V(ULP2_MODE_ISCSI) |
752e2ac9628SHariprasad Shenai 			      FW_OFLD_TX_DATA_WR_ULPSUBMODE_V(submode);
753e33c2482SVarun Prakash 
754e33c2482SVarun Prakash 	req->tunnel_to_proxy = cpu_to_be32(wr_ulp_mode | force |
755e33c2482SVarun Prakash 					   FW_OFLD_TX_DATA_WR_SHOVE_V(1U));
756e33c2482SVarun Prakash 
7577b36b6e0Skxie@chelsio.com 	if (!cxgbi_sock_flag(csk, CTPF_TX_DATA_SENT))
7587b36b6e0Skxie@chelsio.com 		cxgbi_sock_set_flag(csk, CTPF_TX_DATA_SENT);
7597b36b6e0Skxie@chelsio.com }
7607b36b6e0Skxie@chelsio.com 
7617b36b6e0Skxie@chelsio.com static void arp_failure_skb_discard(void *handle, struct sk_buff *skb)
7627b36b6e0Skxie@chelsio.com {
7637b36b6e0Skxie@chelsio.com 	kfree_skb(skb);
7647b36b6e0Skxie@chelsio.com }
7657b36b6e0Skxie@chelsio.com 
7667b36b6e0Skxie@chelsio.com static int push_tx_frames(struct cxgbi_sock *csk, int req_completion)
7677b36b6e0Skxie@chelsio.com {
7687b36b6e0Skxie@chelsio.com 	int total_size = 0;
7697b36b6e0Skxie@chelsio.com 	struct sk_buff *skb;
7707b36b6e0Skxie@chelsio.com 
7717b36b6e0Skxie@chelsio.com 	if (unlikely(csk->state < CTP_ESTABLISHED ||
7727b36b6e0Skxie@chelsio.com 		csk->state == CTP_CLOSE_WAIT_1 || csk->state >= CTP_ABORTING)) {
7737b36b6e0Skxie@chelsio.com 		log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK |
7747b36b6e0Skxie@chelsio.com 			  1 << CXGBI_DBG_PDU_TX,
7757b36b6e0Skxie@chelsio.com 			  "csk 0x%p,%u,0x%lx,%u, in closing state.\n",
7767b36b6e0Skxie@chelsio.com 			  csk, csk->state, csk->flags, csk->tid);
7777b36b6e0Skxie@chelsio.com 		return 0;
7787b36b6e0Skxie@chelsio.com 	}
7797b36b6e0Skxie@chelsio.com 
780e33c2482SVarun Prakash 	while (csk->wr_cred && ((skb = skb_peek(&csk->write_queue)) != NULL)) {
781e33c2482SVarun Prakash 		struct cxgbi_iso_info *iso_cpl;
782e33c2482SVarun Prakash 		u32 dlen = skb->len;
783e33c2482SVarun Prakash 		u32 len = skb->len;
784e33c2482SVarun Prakash 		u32 iso_cpl_len = 0;
785e33c2482SVarun Prakash 		u32 flowclen16 = 0;
786e33c2482SVarun Prakash 		u32 credits_needed;
787e33c2482SVarun Prakash 		u32 num_pdu = 1, hdr_len;
7887b36b6e0Skxie@chelsio.com 
789e33c2482SVarun Prakash 		if (cxgbi_skcb_test_flag(skb, SKCBF_TX_ISO))
790e33c2482SVarun Prakash 			iso_cpl_len = sizeof(struct cpl_tx_data_iso);
791e33c2482SVarun Prakash 
7927b36b6e0Skxie@chelsio.com 		if (is_ofld_imm(skb))
793e33c2482SVarun Prakash 			credits_needed = DIV_ROUND_UP(dlen + iso_cpl_len, 16);
7947b36b6e0Skxie@chelsio.com 		else
795e33c2482SVarun Prakash 			credits_needed =
796e33c2482SVarun Prakash 				DIV_ROUND_UP((8 * calc_tx_flits_ofld(skb)) +
797e33c2482SVarun Prakash 					     iso_cpl_len, 16);
79884944d8cSKaren Xie 
79984944d8cSKaren Xie 		if (likely(cxgbi_skcb_test_flag(skb, SKCBF_TX_NEED_HDR)))
800e33c2482SVarun Prakash 			credits_needed +=
801e33c2482SVarun Prakash 			   DIV_ROUND_UP(sizeof(struct fw_ofld_tx_data_wr), 16);
8027b36b6e0Skxie@chelsio.com 
80364bfead8SKaren Xie 		/*
80464bfead8SKaren Xie 		 * Assumes the initial credits is large enough to support
80564bfead8SKaren Xie 		 * fw_flowc_wr plus largest possible first payload
80664bfead8SKaren Xie 		 */
80764bfead8SKaren Xie 		if (!cxgbi_sock_flag(csk, CTPF_TX_DATA_SENT)) {
80864bfead8SKaren Xie 			flowclen16 = send_tx_flowc_wr(csk);
80964bfead8SKaren Xie 			csk->wr_cred -= flowclen16;
81064bfead8SKaren Xie 			csk->wr_una_cred += flowclen16;
81164bfead8SKaren Xie 			cxgbi_sock_set_flag(csk, CTPF_TX_DATA_SENT);
81264bfead8SKaren Xie 		}
81364bfead8SKaren Xie 
8147b36b6e0Skxie@chelsio.com 		if (csk->wr_cred < credits_needed) {
8157b36b6e0Skxie@chelsio.com 			log_debug(1 << CXGBI_DBG_PDU_TX,
8167b36b6e0Skxie@chelsio.com 				  "csk 0x%p, skb %u/%u, wr %d < %u.\n",
8177b36b6e0Skxie@chelsio.com 				  csk, skb->len, skb->data_len,
8187b36b6e0Skxie@chelsio.com 				  credits_needed, csk->wr_cred);
819e33c2482SVarun Prakash 
820e33c2482SVarun Prakash 			csk->no_tx_credits++;
8217b36b6e0Skxie@chelsio.com 			break;
8227b36b6e0Skxie@chelsio.com 		}
823e33c2482SVarun Prakash 
824e33c2482SVarun Prakash 		csk->no_tx_credits = 0;
825e33c2482SVarun Prakash 
8267b36b6e0Skxie@chelsio.com 		__skb_unlink(skb, &csk->write_queue);
8272126bc5eSKaren Xie 		set_wr_txq(skb, CPL_PRIORITY_DATA, csk->port_id);
828e33c2482SVarun Prakash 		skb->csum = (__force __wsum)(credits_needed + flowclen16);
8297b36b6e0Skxie@chelsio.com 		csk->wr_cred -= credits_needed;
8307b36b6e0Skxie@chelsio.com 		csk->wr_una_cred += credits_needed;
8317b36b6e0Skxie@chelsio.com 		cxgbi_sock_enqueue_wr(csk, skb);
8327b36b6e0Skxie@chelsio.com 
8337b36b6e0Skxie@chelsio.com 		log_debug(1 << CXGBI_DBG_PDU_TX,
8347b36b6e0Skxie@chelsio.com 			"csk 0x%p, skb %u/%u, wr %d, left %u, unack %u.\n",
8357b36b6e0Skxie@chelsio.com 			csk, skb->len, skb->data_len, credits_needed,
8367b36b6e0Skxie@chelsio.com 			csk->wr_cred, csk->wr_una_cred);
8377b36b6e0Skxie@chelsio.com 
838e33c2482SVarun Prakash 		if (!req_completion &&
839e33c2482SVarun Prakash 		    ((csk->wr_una_cred >= (csk->wr_max_cred / 2)) ||
840e33c2482SVarun Prakash 		     after(csk->write_seq, (csk->snd_una + csk->snd_win / 2))))
841e33c2482SVarun Prakash 			req_completion = 1;
842e33c2482SVarun Prakash 
8437b36b6e0Skxie@chelsio.com 		if (likely(cxgbi_skcb_test_flag(skb, SKCBF_TX_NEED_HDR))) {
844e33c2482SVarun Prakash 			u32 ulp_mode = cxgbi_skcb_tx_ulp_mode(skb);
845e33c2482SVarun Prakash 
846e33c2482SVarun Prakash 			if (cxgbi_skcb_test_flag(skb, SKCBF_TX_ISO)) {
847e33c2482SVarun Prakash 				iso_cpl = (struct cxgbi_iso_info *)skb->head;
848e33c2482SVarun Prakash 				num_pdu = iso_cpl->num_pdu;
849e33c2482SVarun Prakash 				hdr_len = cxgbi_skcb_tx_iscsi_hdrlen(skb);
850e33c2482SVarun Prakash 				len += (cxgbi_ulp_extra_len(ulp_mode) * num_pdu) +
851e33c2482SVarun Prakash 				       (hdr_len * (num_pdu - 1));
852e33c2482SVarun Prakash 			} else {
853e33c2482SVarun Prakash 				len += cxgbi_ulp_extra_len(ulp_mode);
854e33c2482SVarun Prakash 			}
855e33c2482SVarun Prakash 
856e33c2482SVarun Prakash 			cxgb4i_make_tx_data_wr(csk, skb, dlen, len,
857e33c2482SVarun Prakash 					       credits_needed, req_completion);
8587b36b6e0Skxie@chelsio.com 			csk->snd_nxt += len;
8597b36b6e0Skxie@chelsio.com 			cxgbi_skcb_clear_flag(skb, SKCBF_TX_NEED_HDR);
860fe9b34bfSVarun Prakash 		} else if (cxgbi_skcb_test_flag(skb, SKCBF_TX_FLAG_COMPL) &&
861fe9b34bfSVarun Prakash 			   (csk->wr_una_cred >= (csk->wr_max_cred / 2))) {
862fe9b34bfSVarun Prakash 			struct cpl_close_con_req *req =
863fe9b34bfSVarun Prakash 				(struct cpl_close_con_req *)skb->data;
864e33c2482SVarun Prakash 
865e33c2482SVarun Prakash 			req->wr.wr_hi |= cpu_to_be32(FW_WR_COMPL_F);
8667b36b6e0Skxie@chelsio.com 		}
867e33c2482SVarun Prakash 
8687b36b6e0Skxie@chelsio.com 		total_size += skb->truesize;
8697b36b6e0Skxie@chelsio.com 		t4_set_arp_err_handler(skb, csk, arp_failure_skb_discard);
8707b36b6e0Skxie@chelsio.com 
8717b36b6e0Skxie@chelsio.com 		log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_PDU_TX,
8727b36b6e0Skxie@chelsio.com 			  "csk 0x%p,%u,0x%lx,%u, skb 0x%p, %u.\n",
8737b36b6e0Skxie@chelsio.com 			  csk, csk->state, csk->flags, csk->tid, skb, len);
8747b36b6e0Skxie@chelsio.com 		cxgb4_l2t_send(csk->cdev->ports[csk->port_id], skb, csk->l2t);
8757b36b6e0Skxie@chelsio.com 	}
8767b36b6e0Skxie@chelsio.com 	return total_size;
8777b36b6e0Skxie@chelsio.com }
8787b36b6e0Skxie@chelsio.com 
8797b36b6e0Skxie@chelsio.com static inline void free_atid(struct cxgbi_sock *csk)
8807b36b6e0Skxie@chelsio.com {
8817b36b6e0Skxie@chelsio.com 	struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(csk->cdev);
8827b36b6e0Skxie@chelsio.com 
8837b36b6e0Skxie@chelsio.com 	if (cxgbi_sock_flag(csk, CTPF_HAS_ATID)) {
8847b36b6e0Skxie@chelsio.com 		cxgb4_free_atid(lldi->tids, csk->atid);
8857b36b6e0Skxie@chelsio.com 		cxgbi_sock_clear_flag(csk, CTPF_HAS_ATID);
8867b36b6e0Skxie@chelsio.com 		cxgbi_sock_put(csk);
8877b36b6e0Skxie@chelsio.com 	}
8887b36b6e0Skxie@chelsio.com }
8897b36b6e0Skxie@chelsio.com 
8907b36b6e0Skxie@chelsio.com static void do_act_establish(struct cxgbi_device *cdev, struct sk_buff *skb)
8917b36b6e0Skxie@chelsio.com {
8927b36b6e0Skxie@chelsio.com 	struct cxgbi_sock *csk;
8937b36b6e0Skxie@chelsio.com 	struct cpl_act_establish *req = (struct cpl_act_establish *)skb->data;
8947b36b6e0Skxie@chelsio.com 	unsigned short tcp_opt = ntohs(req->tcp_opt);
8957b36b6e0Skxie@chelsio.com 	unsigned int tid = GET_TID(req);
8966c53e938SHariprasad Shenai 	unsigned int atid = TID_TID_G(ntohl(req->tos_atid));
8977b36b6e0Skxie@chelsio.com 	struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(cdev);
8987b36b6e0Skxie@chelsio.com 	struct tid_info *t = lldi->tids;
8997b36b6e0Skxie@chelsio.com 	u32 rcv_isn = be32_to_cpu(req->rcv_isn);
9007b36b6e0Skxie@chelsio.com 
9017b36b6e0Skxie@chelsio.com 	csk = lookup_atid(t, atid);
9027b36b6e0Skxie@chelsio.com 	if (unlikely(!csk)) {
9037b36b6e0Skxie@chelsio.com 		pr_err("NO conn. for atid %u, cdev 0x%p.\n", atid, cdev);
9047b36b6e0Skxie@chelsio.com 		goto rel_skb;
9057b36b6e0Skxie@chelsio.com 	}
9067b36b6e0Skxie@chelsio.com 
907e27d6169Skxie@chelsio.com 	if (csk->atid != atid) {
908e27d6169Skxie@chelsio.com 		pr_err("bad conn atid %u, csk 0x%p,%u,0x%lx,tid %u, atid %u.\n",
909e27d6169Skxie@chelsio.com 			atid, csk, csk->state, csk->flags, csk->tid, csk->atid);
910e27d6169Skxie@chelsio.com 		goto rel_skb;
911e27d6169Skxie@chelsio.com 	}
912e27d6169Skxie@chelsio.com 
913759a0cc5SAnish Bhatt 	pr_info_ipaddr("atid 0x%x, tid 0x%x, csk 0x%p,%u,0x%lx, isn %u.\n",
914759a0cc5SAnish Bhatt 		       (&csk->saddr), (&csk->daddr),
915759a0cc5SAnish Bhatt 		       atid, tid, csk, csk->state, csk->flags, rcv_isn);
916759a0cc5SAnish Bhatt 
9171fe1fdb0SVarun Prakash 	module_put(cdev->owner);
9187b36b6e0Skxie@chelsio.com 
9197b36b6e0Skxie@chelsio.com 	cxgbi_sock_get(csk);
9207b36b6e0Skxie@chelsio.com 	csk->tid = tid;
9211dec4cecSGanesh Goudar 	cxgb4_insert_tid(lldi->tids, csk, tid, csk->csk_family);
9227b36b6e0Skxie@chelsio.com 	cxgbi_sock_set_flag(csk, CTPF_HAS_TID);
9237b36b6e0Skxie@chelsio.com 
9247b36b6e0Skxie@chelsio.com 	free_atid(csk);
9257b36b6e0Skxie@chelsio.com 
9267b36b6e0Skxie@chelsio.com 	spin_lock_bh(&csk->lock);
9277b36b6e0Skxie@chelsio.com 	if (unlikely(csk->state != CTP_ACTIVE_OPEN))
9287b36b6e0Skxie@chelsio.com 		pr_info("csk 0x%p,%u,0x%lx,%u, got EST.\n",
9297b36b6e0Skxie@chelsio.com 			csk, csk->state, csk->flags, csk->tid);
9307b36b6e0Skxie@chelsio.com 
9317b36b6e0Skxie@chelsio.com 	if (csk->retry_timer.function) {
9327b36b6e0Skxie@chelsio.com 		del_timer(&csk->retry_timer);
9337b36b6e0Skxie@chelsio.com 		csk->retry_timer.function = NULL;
9347b36b6e0Skxie@chelsio.com 	}
9357b36b6e0Skxie@chelsio.com 
9367b36b6e0Skxie@chelsio.com 	csk->copied_seq = csk->rcv_wup = csk->rcv_nxt = rcv_isn;
9377b36b6e0Skxie@chelsio.com 	/*
9387b36b6e0Skxie@chelsio.com 	 * Causes the first RX_DATA_ACK to supply any Rx credits we couldn't
9397b36b6e0Skxie@chelsio.com 	 * pass through opt0.
9407b36b6e0Skxie@chelsio.com 	 */
94181daf10cSKaren Xie 	if (csk->rcv_win > (RCV_BUFSIZ_MASK << 10))
94281daf10cSKaren Xie 		csk->rcv_wup -= csk->rcv_win - (RCV_BUFSIZ_MASK << 10);
9437b36b6e0Skxie@chelsio.com 
9446c53e938SHariprasad Shenai 	csk->advmss = lldi->mtus[TCPOPT_MSS_G(tcp_opt)] - 40;
9456c53e938SHariprasad Shenai 	if (TCPOPT_TSTAMP_G(tcp_opt))
9467b36b6e0Skxie@chelsio.com 		csk->advmss -= 12;
9477b36b6e0Skxie@chelsio.com 	if (csk->advmss < 128)
9487b36b6e0Skxie@chelsio.com 		csk->advmss = 128;
9497b36b6e0Skxie@chelsio.com 
9507b36b6e0Skxie@chelsio.com 	log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
9517b36b6e0Skxie@chelsio.com 		"csk 0x%p, mss_idx %u, advmss %u.\n",
9526c53e938SHariprasad Shenai 			csk, TCPOPT_MSS_G(tcp_opt), csk->advmss);
9537b36b6e0Skxie@chelsio.com 
9547b36b6e0Skxie@chelsio.com 	cxgbi_sock_established(csk, ntohl(req->snd_isn), ntohs(req->tcp_opt));
9557b36b6e0Skxie@chelsio.com 
9567b36b6e0Skxie@chelsio.com 	if (unlikely(cxgbi_sock_flag(csk, CTPF_ACTIVE_CLOSE_NEEDED)))
9577b36b6e0Skxie@chelsio.com 		send_abort_req(csk);
9587b36b6e0Skxie@chelsio.com 	else {
9597b36b6e0Skxie@chelsio.com 		if (skb_queue_len(&csk->write_queue))
9607b36b6e0Skxie@chelsio.com 			push_tx_frames(csk, 0);
9617b36b6e0Skxie@chelsio.com 		cxgbi_conn_tx_open(csk);
9627b36b6e0Skxie@chelsio.com 	}
9637b36b6e0Skxie@chelsio.com 	spin_unlock_bh(&csk->lock);
9647b36b6e0Skxie@chelsio.com 
9657b36b6e0Skxie@chelsio.com rel_skb:
9667b36b6e0Skxie@chelsio.com 	__kfree_skb(skb);
9677b36b6e0Skxie@chelsio.com }
9687b36b6e0Skxie@chelsio.com 
9697b36b6e0Skxie@chelsio.com static int act_open_rpl_status_to_errno(int status)
9707b36b6e0Skxie@chelsio.com {
9717b36b6e0Skxie@chelsio.com 	switch (status) {
9727b36b6e0Skxie@chelsio.com 	case CPL_ERR_CONN_RESET:
9737b36b6e0Skxie@chelsio.com 		return -ECONNREFUSED;
9747b36b6e0Skxie@chelsio.com 	case CPL_ERR_ARP_MISS:
9757b36b6e0Skxie@chelsio.com 		return -EHOSTUNREACH;
9767b36b6e0Skxie@chelsio.com 	case CPL_ERR_CONN_TIMEDOUT:
9777b36b6e0Skxie@chelsio.com 		return -ETIMEDOUT;
9787b36b6e0Skxie@chelsio.com 	case CPL_ERR_TCAM_FULL:
9797b36b6e0Skxie@chelsio.com 		return -ENOMEM;
9807b36b6e0Skxie@chelsio.com 	case CPL_ERR_CONN_EXIST:
9817b36b6e0Skxie@chelsio.com 		return -EADDRINUSE;
9827b36b6e0Skxie@chelsio.com 	default:
9837b36b6e0Skxie@chelsio.com 		return -EIO;
9847b36b6e0Skxie@chelsio.com 	}
9857b36b6e0Skxie@chelsio.com }
9867b36b6e0Skxie@chelsio.com 
987cd07f958SKees Cook static void csk_act_open_retry_timer(struct timer_list *t)
9887b36b6e0Skxie@chelsio.com {
989001586a7SAnish Bhatt 	struct sk_buff *skb = NULL;
990cd07f958SKees Cook 	struct cxgbi_sock *csk = from_timer(csk, t, retry_timer);
9913bd3e8bfSKaren Xie 	struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(csk->cdev);
992759a0cc5SAnish Bhatt 	void (*send_act_open_func)(struct cxgbi_sock *, struct sk_buff *,
993759a0cc5SAnish Bhatt 				   struct l2t_entry *);
994759a0cc5SAnish Bhatt 	int t4 = is_t4(lldi->adapter_type), size, size6;
9957b36b6e0Skxie@chelsio.com 
9967b36b6e0Skxie@chelsio.com 	log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
9977b36b6e0Skxie@chelsio.com 		"csk 0x%p,%u,0x%lx,%u.\n",
9987b36b6e0Skxie@chelsio.com 		csk, csk->state, csk->flags, csk->tid);
9997b36b6e0Skxie@chelsio.com 
10007b36b6e0Skxie@chelsio.com 	cxgbi_sock_get(csk);
10017b36b6e0Skxie@chelsio.com 	spin_lock_bh(&csk->lock);
1002759a0cc5SAnish Bhatt 
1003759a0cc5SAnish Bhatt 	if (t4) {
1004759a0cc5SAnish Bhatt 		size = sizeof(struct cpl_act_open_req);
1005759a0cc5SAnish Bhatt 		size6 = sizeof(struct cpl_act_open_req6);
1006759a0cc5SAnish Bhatt 	} else {
1007759a0cc5SAnish Bhatt 		size = sizeof(struct cpl_t5_act_open_req);
1008759a0cc5SAnish Bhatt 		size6 = sizeof(struct cpl_t5_act_open_req6);
1009759a0cc5SAnish Bhatt 	}
1010759a0cc5SAnish Bhatt 
1011759a0cc5SAnish Bhatt 	if (csk->csk_family == AF_INET) {
1012759a0cc5SAnish Bhatt 		send_act_open_func = send_act_open_req;
1013759a0cc5SAnish Bhatt 		skb = alloc_wr(size, 0, GFP_ATOMIC);
1014f42bb57cSAnish Bhatt #if IS_ENABLED(CONFIG_IPV6)
1015759a0cc5SAnish Bhatt 	} else {
1016759a0cc5SAnish Bhatt 		send_act_open_func = send_act_open_req6;
1017759a0cc5SAnish Bhatt 		skb = alloc_wr(size6, 0, GFP_ATOMIC);
1018f42bb57cSAnish Bhatt #endif
1019759a0cc5SAnish Bhatt 	}
1020759a0cc5SAnish Bhatt 
10217b36b6e0Skxie@chelsio.com 	if (!skb)
10227b36b6e0Skxie@chelsio.com 		cxgbi_sock_fail_act_open(csk, -ENOMEM);
10237b36b6e0Skxie@chelsio.com 	else {
10247b36b6e0Skxie@chelsio.com 		skb->sk = (struct sock *)csk;
10257b36b6e0Skxie@chelsio.com 		t4_set_arp_err_handler(skb, csk,
10267b36b6e0Skxie@chelsio.com 				       cxgbi_sock_act_open_req_arp_failure);
1027759a0cc5SAnish Bhatt 		send_act_open_func(csk, skb, csk->l2t);
10287b36b6e0Skxie@chelsio.com 	}
1029759a0cc5SAnish Bhatt 
10307b36b6e0Skxie@chelsio.com 	spin_unlock_bh(&csk->lock);
10317b36b6e0Skxie@chelsio.com 	cxgbi_sock_put(csk);
1032759a0cc5SAnish Bhatt 
10337b36b6e0Skxie@chelsio.com }
10347b36b6e0Skxie@chelsio.com 
1035928567adSKaren Xie static inline bool is_neg_adv(unsigned int status)
1036928567adSKaren Xie {
1037928567adSKaren Xie 	return status == CPL_ERR_RTX_NEG_ADVICE ||
1038928567adSKaren Xie 		status == CPL_ERR_KEEPALV_NEG_ADVICE ||
1039928567adSKaren Xie 		status == CPL_ERR_PERSIST_NEG_ADVICE;
1040928567adSKaren Xie }
1041928567adSKaren Xie 
10427b36b6e0Skxie@chelsio.com static void do_act_open_rpl(struct cxgbi_device *cdev, struct sk_buff *skb)
10437b36b6e0Skxie@chelsio.com {
10447b36b6e0Skxie@chelsio.com 	struct cxgbi_sock *csk;
10457b36b6e0Skxie@chelsio.com 	struct cpl_act_open_rpl *rpl = (struct cpl_act_open_rpl *)skb->data;
10467b36b6e0Skxie@chelsio.com 	unsigned int tid = GET_TID(rpl);
10477b36b6e0Skxie@chelsio.com 	unsigned int atid =
10486c53e938SHariprasad Shenai 		TID_TID_G(AOPEN_ATID_G(be32_to_cpu(rpl->atid_status)));
10496c53e938SHariprasad Shenai 	unsigned int status = AOPEN_STATUS_G(be32_to_cpu(rpl->atid_status));
10507b36b6e0Skxie@chelsio.com 	struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(cdev);
10517b36b6e0Skxie@chelsio.com 	struct tid_info *t = lldi->tids;
10527b36b6e0Skxie@chelsio.com 
10537b36b6e0Skxie@chelsio.com 	csk = lookup_atid(t, atid);
10547b36b6e0Skxie@chelsio.com 	if (unlikely(!csk)) {
10557b36b6e0Skxie@chelsio.com 		pr_err("NO matching conn. atid %u, tid %u.\n", atid, tid);
10567b36b6e0Skxie@chelsio.com 		goto rel_skb;
10577b36b6e0Skxie@chelsio.com 	}
10587b36b6e0Skxie@chelsio.com 
1059759a0cc5SAnish Bhatt 	pr_info_ipaddr("tid %u/%u, status %u.\n"
1060759a0cc5SAnish Bhatt 		       "csk 0x%p,%u,0x%lx. ", (&csk->saddr), (&csk->daddr),
1061e27d6169Skxie@chelsio.com 		       atid, tid, status, csk, csk->state, csk->flags);
10627b36b6e0Skxie@chelsio.com 
1063928567adSKaren Xie 	if (is_neg_adv(status))
1064150cca7cSKaren Xie 		goto rel_skb;
1065150cca7cSKaren Xie 
10661fe1fdb0SVarun Prakash 	module_put(cdev->owner);
1067ee7255adSAnish Bhatt 
10687b36b6e0Skxie@chelsio.com 	if (status && status != CPL_ERR_TCAM_FULL &&
10697b36b6e0Skxie@chelsio.com 	    status != CPL_ERR_CONN_EXIST &&
10707b36b6e0Skxie@chelsio.com 	    status != CPL_ERR_ARP_MISS)
10711dec4cecSGanesh Goudar 		cxgb4_remove_tid(lldi->tids, csk->port_id, GET_TID(rpl),
10721dec4cecSGanesh Goudar 				 csk->csk_family);
10737b36b6e0Skxie@chelsio.com 
10747b36b6e0Skxie@chelsio.com 	cxgbi_sock_get(csk);
10757b36b6e0Skxie@chelsio.com 	spin_lock_bh(&csk->lock);
10767b36b6e0Skxie@chelsio.com 
10777b36b6e0Skxie@chelsio.com 	if (status == CPL_ERR_CONN_EXIST &&
1078841b86f3SKees Cook 	    csk->retry_timer.function != csk_act_open_retry_timer) {
1079841b86f3SKees Cook 		csk->retry_timer.function = csk_act_open_retry_timer;
10807b36b6e0Skxie@chelsio.com 		mod_timer(&csk->retry_timer, jiffies + HZ / 2);
10817b36b6e0Skxie@chelsio.com 	} else
10827b36b6e0Skxie@chelsio.com 		cxgbi_sock_fail_act_open(csk,
10837b36b6e0Skxie@chelsio.com 					act_open_rpl_status_to_errno(status));
10847b36b6e0Skxie@chelsio.com 
10857b36b6e0Skxie@chelsio.com 	spin_unlock_bh(&csk->lock);
10867b36b6e0Skxie@chelsio.com 	cxgbi_sock_put(csk);
10877b36b6e0Skxie@chelsio.com rel_skb:
10887b36b6e0Skxie@chelsio.com 	__kfree_skb(skb);
10897b36b6e0Skxie@chelsio.com }
10907b36b6e0Skxie@chelsio.com 
10917b36b6e0Skxie@chelsio.com static void do_peer_close(struct cxgbi_device *cdev, struct sk_buff *skb)
10927b36b6e0Skxie@chelsio.com {
10937b36b6e0Skxie@chelsio.com 	struct cxgbi_sock *csk;
10947b36b6e0Skxie@chelsio.com 	struct cpl_peer_close *req = (struct cpl_peer_close *)skb->data;
10957b36b6e0Skxie@chelsio.com 	unsigned int tid = GET_TID(req);
10967b36b6e0Skxie@chelsio.com 	struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(cdev);
10977b36b6e0Skxie@chelsio.com 	struct tid_info *t = lldi->tids;
10987b36b6e0Skxie@chelsio.com 
10997b36b6e0Skxie@chelsio.com 	csk = lookup_tid(t, tid);
11007b36b6e0Skxie@chelsio.com 	if (unlikely(!csk)) {
11017b36b6e0Skxie@chelsio.com 		pr_err("can't find connection for tid %u.\n", tid);
11027b36b6e0Skxie@chelsio.com 		goto rel_skb;
11037b36b6e0Skxie@chelsio.com 	}
1104759a0cc5SAnish Bhatt 	pr_info_ipaddr("csk 0x%p,%u,0x%lx,%u.\n",
1105759a0cc5SAnish Bhatt 		       (&csk->saddr), (&csk->daddr),
11067b36b6e0Skxie@chelsio.com 		       csk, csk->state, csk->flags, csk->tid);
11077b36b6e0Skxie@chelsio.com 	cxgbi_sock_rcv_peer_close(csk);
11087b36b6e0Skxie@chelsio.com rel_skb:
11097b36b6e0Skxie@chelsio.com 	__kfree_skb(skb);
11107b36b6e0Skxie@chelsio.com }
11117b36b6e0Skxie@chelsio.com 
11127b36b6e0Skxie@chelsio.com static void do_close_con_rpl(struct cxgbi_device *cdev, struct sk_buff *skb)
11137b36b6e0Skxie@chelsio.com {
11147b36b6e0Skxie@chelsio.com 	struct cxgbi_sock *csk;
11157b36b6e0Skxie@chelsio.com 	struct cpl_close_con_rpl *rpl = (struct cpl_close_con_rpl *)skb->data;
11167b36b6e0Skxie@chelsio.com 	unsigned int tid = GET_TID(rpl);
11177b36b6e0Skxie@chelsio.com 	struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(cdev);
11187b36b6e0Skxie@chelsio.com 	struct tid_info *t = lldi->tids;
11197b36b6e0Skxie@chelsio.com 
11207b36b6e0Skxie@chelsio.com 	csk = lookup_tid(t, tid);
11217b36b6e0Skxie@chelsio.com 	if (unlikely(!csk)) {
11227b36b6e0Skxie@chelsio.com 		pr_err("can't find connection for tid %u.\n", tid);
11237b36b6e0Skxie@chelsio.com 		goto rel_skb;
11247b36b6e0Skxie@chelsio.com 	}
1125759a0cc5SAnish Bhatt 	pr_info_ipaddr("csk 0x%p,%u,0x%lx,%u.\n",
1126759a0cc5SAnish Bhatt 		       (&csk->saddr), (&csk->daddr),
11277b36b6e0Skxie@chelsio.com 		       csk, csk->state, csk->flags, csk->tid);
11287b36b6e0Skxie@chelsio.com 	cxgbi_sock_rcv_close_conn_rpl(csk, ntohl(rpl->snd_nxt));
11297b36b6e0Skxie@chelsio.com rel_skb:
11307b36b6e0Skxie@chelsio.com 	__kfree_skb(skb);
11317b36b6e0Skxie@chelsio.com }
11327b36b6e0Skxie@chelsio.com 
11337b36b6e0Skxie@chelsio.com static int abort_status_to_errno(struct cxgbi_sock *csk, int abort_reason,
11347b36b6e0Skxie@chelsio.com 								int *need_rst)
11357b36b6e0Skxie@chelsio.com {
11367b36b6e0Skxie@chelsio.com 	switch (abort_reason) {
1137df561f66SGustavo A. R. Silva 	case CPL_ERR_BAD_SYN:
11387b36b6e0Skxie@chelsio.com 	case CPL_ERR_CONN_RESET:
11397b36b6e0Skxie@chelsio.com 		return csk->state > CTP_ESTABLISHED ?
11407b36b6e0Skxie@chelsio.com 			-EPIPE : -ECONNRESET;
11417b36b6e0Skxie@chelsio.com 	case CPL_ERR_XMIT_TIMEDOUT:
11427b36b6e0Skxie@chelsio.com 	case CPL_ERR_PERSIST_TIMEDOUT:
11437b36b6e0Skxie@chelsio.com 	case CPL_ERR_FINWAIT2_TIMEDOUT:
11447b36b6e0Skxie@chelsio.com 	case CPL_ERR_KEEPALIVE_TIMEDOUT:
11457b36b6e0Skxie@chelsio.com 		return -ETIMEDOUT;
11467b36b6e0Skxie@chelsio.com 	default:
11477b36b6e0Skxie@chelsio.com 		return -EIO;
11487b36b6e0Skxie@chelsio.com 	}
11497b36b6e0Skxie@chelsio.com }
11507b36b6e0Skxie@chelsio.com 
11517b36b6e0Skxie@chelsio.com static void do_abort_req_rss(struct cxgbi_device *cdev, struct sk_buff *skb)
11527b36b6e0Skxie@chelsio.com {
11537b36b6e0Skxie@chelsio.com 	struct cxgbi_sock *csk;
11547b36b6e0Skxie@chelsio.com 	struct cpl_abort_req_rss *req = (struct cpl_abort_req_rss *)skb->data;
11557b36b6e0Skxie@chelsio.com 	unsigned int tid = GET_TID(req);
11567b36b6e0Skxie@chelsio.com 	struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(cdev);
11577b36b6e0Skxie@chelsio.com 	struct tid_info *t = lldi->tids;
11587b36b6e0Skxie@chelsio.com 	int rst_status = CPL_ABORT_NO_RST;
11597b36b6e0Skxie@chelsio.com 
11607b36b6e0Skxie@chelsio.com 	csk = lookup_tid(t, tid);
11617b36b6e0Skxie@chelsio.com 	if (unlikely(!csk)) {
11627b36b6e0Skxie@chelsio.com 		pr_err("can't find connection for tid %u.\n", tid);
11637b36b6e0Skxie@chelsio.com 		goto rel_skb;
11647b36b6e0Skxie@chelsio.com 	}
11657b36b6e0Skxie@chelsio.com 
1166759a0cc5SAnish Bhatt 	pr_info_ipaddr("csk 0x%p,%u,0x%lx,%u, status %u.\n",
1167759a0cc5SAnish Bhatt 		       (&csk->saddr), (&csk->daddr),
11687b36b6e0Skxie@chelsio.com 		       csk, csk->state, csk->flags, csk->tid, req->status);
11697b36b6e0Skxie@chelsio.com 
1170928567adSKaren Xie 	if (is_neg_adv(req->status))
11717b36b6e0Skxie@chelsio.com 		goto rel_skb;
11727b36b6e0Skxie@chelsio.com 
11737b36b6e0Skxie@chelsio.com 	cxgbi_sock_get(csk);
11747b36b6e0Skxie@chelsio.com 	spin_lock_bh(&csk->lock);
11757b36b6e0Skxie@chelsio.com 
11767b07bf24SAnish Bhatt 	cxgbi_sock_clear_flag(csk, CTPF_ABORT_REQ_RCVD);
11777b07bf24SAnish Bhatt 
11787b07bf24SAnish Bhatt 	if (!cxgbi_sock_flag(csk, CTPF_TX_DATA_SENT)) {
11797b07bf24SAnish Bhatt 		send_tx_flowc_wr(csk);
11807b07bf24SAnish Bhatt 		cxgbi_sock_set_flag(csk, CTPF_TX_DATA_SENT);
11817b36b6e0Skxie@chelsio.com 	}
11827b36b6e0Skxie@chelsio.com 
11837b07bf24SAnish Bhatt 	cxgbi_sock_set_flag(csk, CTPF_ABORT_REQ_RCVD);
11847b07bf24SAnish Bhatt 	cxgbi_sock_set_state(csk, CTP_ABORTING);
11857b07bf24SAnish Bhatt 
11867b36b6e0Skxie@chelsio.com 	send_abort_rpl(csk, rst_status);
11877b36b6e0Skxie@chelsio.com 
11887b36b6e0Skxie@chelsio.com 	if (!cxgbi_sock_flag(csk, CTPF_ABORT_RPL_PENDING)) {
11897b36b6e0Skxie@chelsio.com 		csk->err = abort_status_to_errno(csk, req->status, &rst_status);
11907b36b6e0Skxie@chelsio.com 		cxgbi_sock_closed(csk);
11917b36b6e0Skxie@chelsio.com 	}
11927b07bf24SAnish Bhatt 
11937b36b6e0Skxie@chelsio.com 	spin_unlock_bh(&csk->lock);
11947b36b6e0Skxie@chelsio.com 	cxgbi_sock_put(csk);
11957b36b6e0Skxie@chelsio.com rel_skb:
11967b36b6e0Skxie@chelsio.com 	__kfree_skb(skb);
11977b36b6e0Skxie@chelsio.com }
11987b36b6e0Skxie@chelsio.com 
11997b36b6e0Skxie@chelsio.com static void do_abort_rpl_rss(struct cxgbi_device *cdev, struct sk_buff *skb)
12007b36b6e0Skxie@chelsio.com {
12017b36b6e0Skxie@chelsio.com 	struct cxgbi_sock *csk;
12027b36b6e0Skxie@chelsio.com 	struct cpl_abort_rpl_rss *rpl = (struct cpl_abort_rpl_rss *)skb->data;
12037b36b6e0Skxie@chelsio.com 	unsigned int tid = GET_TID(rpl);
12047b36b6e0Skxie@chelsio.com 	struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(cdev);
12057b36b6e0Skxie@chelsio.com 	struct tid_info *t = lldi->tids;
12067b36b6e0Skxie@chelsio.com 
12077b36b6e0Skxie@chelsio.com 	csk = lookup_tid(t, tid);
12087b36b6e0Skxie@chelsio.com 	if (!csk)
12097b36b6e0Skxie@chelsio.com 		goto rel_skb;
12107b36b6e0Skxie@chelsio.com 
1211759a0cc5SAnish Bhatt 	pr_info_ipaddr("csk 0x%p,%u,0x%lx,%u, status %u.\n",
1212759a0cc5SAnish Bhatt 		       (&csk->saddr), (&csk->daddr), csk,
1213759a0cc5SAnish Bhatt 		       csk->state, csk->flags, csk->tid, rpl->status);
12147b36b6e0Skxie@chelsio.com 
12157b36b6e0Skxie@chelsio.com 	if (rpl->status == CPL_ERR_ABORT_FAILED)
12167b36b6e0Skxie@chelsio.com 		goto rel_skb;
12177b36b6e0Skxie@chelsio.com 
12187b36b6e0Skxie@chelsio.com 	cxgbi_sock_rcv_abort_rpl(csk);
12197b36b6e0Skxie@chelsio.com rel_skb:
12207b36b6e0Skxie@chelsio.com 	__kfree_skb(skb);
12217b36b6e0Skxie@chelsio.com }
12227b36b6e0Skxie@chelsio.com 
1223f7bcd2e1SKaren Xie static void do_rx_data(struct cxgbi_device *cdev, struct sk_buff *skb)
1224f7bcd2e1SKaren Xie {
1225f7bcd2e1SKaren Xie 	struct cxgbi_sock *csk;
1226f7bcd2e1SKaren Xie 	struct cpl_rx_data *cpl = (struct cpl_rx_data *)skb->data;
1227f7bcd2e1SKaren Xie 	unsigned int tid = GET_TID(cpl);
1228f7bcd2e1SKaren Xie 	struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(cdev);
1229f7bcd2e1SKaren Xie 	struct tid_info *t = lldi->tids;
1230f7bcd2e1SKaren Xie 
1231f7bcd2e1SKaren Xie 	csk = lookup_tid(t, tid);
1232f7bcd2e1SKaren Xie 	if (!csk) {
1233f7bcd2e1SKaren Xie 		pr_err("can't find connection for tid %u.\n", tid);
1234f7bcd2e1SKaren Xie 	} else {
1235f7bcd2e1SKaren Xie 		/* not expecting this, reset the connection. */
1236f7bcd2e1SKaren Xie 		pr_err("csk 0x%p, tid %u, rcv cpl_rx_data.\n", csk, tid);
1237f7bcd2e1SKaren Xie 		spin_lock_bh(&csk->lock);
1238f7bcd2e1SKaren Xie 		send_abort_req(csk);
1239f7bcd2e1SKaren Xie 		spin_unlock_bh(&csk->lock);
1240f7bcd2e1SKaren Xie 	}
1241f7bcd2e1SKaren Xie 	__kfree_skb(skb);
1242f7bcd2e1SKaren Xie }
1243f7bcd2e1SKaren Xie 
12447b36b6e0Skxie@chelsio.com static void do_rx_iscsi_hdr(struct cxgbi_device *cdev, struct sk_buff *skb)
12457b36b6e0Skxie@chelsio.com {
12467b36b6e0Skxie@chelsio.com 	struct cxgbi_sock *csk;
12477b36b6e0Skxie@chelsio.com 	struct cpl_iscsi_hdr *cpl = (struct cpl_iscsi_hdr *)skb->data;
12487b36b6e0Skxie@chelsio.com 	unsigned short pdu_len_ddp = be16_to_cpu(cpl->pdu_len_ddp);
12497b36b6e0Skxie@chelsio.com 	unsigned int tid = GET_TID(cpl);
12507b36b6e0Skxie@chelsio.com 	struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(cdev);
12517b36b6e0Skxie@chelsio.com 	struct tid_info *t = lldi->tids;
12527b36b6e0Skxie@chelsio.com 
12537b36b6e0Skxie@chelsio.com 	csk = lookup_tid(t, tid);
12547b36b6e0Skxie@chelsio.com 	if (unlikely(!csk)) {
12557b36b6e0Skxie@chelsio.com 		pr_err("can't find conn. for tid %u.\n", tid);
12567b36b6e0Skxie@chelsio.com 		goto rel_skb;
12577b36b6e0Skxie@chelsio.com 	}
12587b36b6e0Skxie@chelsio.com 
12597b36b6e0Skxie@chelsio.com 	log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_PDU_RX,
12607b36b6e0Skxie@chelsio.com 		"csk 0x%p,%u,0x%lx, tid %u, skb 0x%p,%u, 0x%x.\n",
12617b36b6e0Skxie@chelsio.com 		csk, csk->state, csk->flags, csk->tid, skb, skb->len,
12627b36b6e0Skxie@chelsio.com 		pdu_len_ddp);
12637b36b6e0Skxie@chelsio.com 
12647b36b6e0Skxie@chelsio.com 	spin_lock_bh(&csk->lock);
12657b36b6e0Skxie@chelsio.com 
12667b36b6e0Skxie@chelsio.com 	if (unlikely(csk->state >= CTP_PASSIVE_CLOSE)) {
12677b36b6e0Skxie@chelsio.com 		log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
12687b36b6e0Skxie@chelsio.com 			"csk 0x%p,%u,0x%lx,%u, bad state.\n",
12697b36b6e0Skxie@chelsio.com 			csk, csk->state, csk->flags, csk->tid);
12707b36b6e0Skxie@chelsio.com 		if (csk->state != CTP_ABORTING)
12717b36b6e0Skxie@chelsio.com 			goto abort_conn;
12727b36b6e0Skxie@chelsio.com 		else
12737b36b6e0Skxie@chelsio.com 			goto discard;
12747b36b6e0Skxie@chelsio.com 	}
12757b36b6e0Skxie@chelsio.com 
12767b36b6e0Skxie@chelsio.com 	cxgbi_skcb_tcp_seq(skb) = ntohl(cpl->seq);
1277e27d6169Skxie@chelsio.com 	cxgbi_skcb_flags(skb) = 0;
1278e27d6169Skxie@chelsio.com 
12797b36b6e0Skxie@chelsio.com 	skb_reset_transport_header(skb);
12807b36b6e0Skxie@chelsio.com 	__skb_pull(skb, sizeof(*cpl));
12817b36b6e0Skxie@chelsio.com 	__pskb_trim(skb, ntohs(cpl->len));
12827b36b6e0Skxie@chelsio.com 
12837b36b6e0Skxie@chelsio.com 	if (!csk->skb_ulp_lhdr) {
12847b36b6e0Skxie@chelsio.com 		unsigned char *bhs;
12853bd3e8bfSKaren Xie 		unsigned int hlen, dlen, plen;
12867b36b6e0Skxie@chelsio.com 
12877b36b6e0Skxie@chelsio.com 		log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_PDU_RX,
12887b36b6e0Skxie@chelsio.com 			"csk 0x%p,%u,0x%lx, tid %u, skb 0x%p header.\n",
12897b36b6e0Skxie@chelsio.com 			csk, csk->state, csk->flags, csk->tid, skb);
12907b36b6e0Skxie@chelsio.com 		csk->skb_ulp_lhdr = skb;
1291e27d6169Skxie@chelsio.com 		cxgbi_skcb_set_flag(skb, SKCBF_RX_HDR);
12927b36b6e0Skxie@chelsio.com 
129326af1a36SVarun Prakash 		if ((CHELSIO_CHIP_VERSION(lldi->adapter_type) <= CHELSIO_T5) &&
129426af1a36SVarun Prakash 		    (cxgbi_skcb_tcp_seq(skb) != csk->rcv_nxt)) {
12957b36b6e0Skxie@chelsio.com 			pr_info("tid %u, CPL_ISCSI_HDR, bad seq, 0x%x/0x%x.\n",
1296e27d6169Skxie@chelsio.com 				csk->tid, cxgbi_skcb_tcp_seq(skb),
12977b36b6e0Skxie@chelsio.com 				csk->rcv_nxt);
12987b36b6e0Skxie@chelsio.com 			goto abort_conn;
12997b36b6e0Skxie@chelsio.com 		}
13007b36b6e0Skxie@chelsio.com 
1301e27d6169Skxie@chelsio.com 		bhs = skb->data;
13027b36b6e0Skxie@chelsio.com 		hlen = ntohs(cpl->len);
13037b36b6e0Skxie@chelsio.com 		dlen = ntohl(*(unsigned int *)(bhs + 4)) & 0xFFFFFF;
13047b36b6e0Skxie@chelsio.com 
1305bdc590b9SHariprasad Shenai 		plen = ISCSI_PDU_LEN_G(pdu_len_ddp);
13063bd3e8bfSKaren Xie 		if (is_t4(lldi->adapter_type))
13073bd3e8bfSKaren Xie 			plen -= 40;
13083bd3e8bfSKaren Xie 
13093bd3e8bfSKaren Xie 		if ((hlen + dlen) != plen) {
13107b36b6e0Skxie@chelsio.com 			pr_info("tid 0x%x, CPL_ISCSI_HDR, pdu len "
13117b36b6e0Skxie@chelsio.com 				"mismatch %u != %u + %u, seq 0x%x.\n",
13123bd3e8bfSKaren Xie 				csk->tid, plen, hlen, dlen,
13133bd3e8bfSKaren Xie 				cxgbi_skcb_tcp_seq(skb));
13147b36b6e0Skxie@chelsio.com 			goto abort_conn;
13157b36b6e0Skxie@chelsio.com 		}
13167b36b6e0Skxie@chelsio.com 
13177b36b6e0Skxie@chelsio.com 		cxgbi_skcb_rx_pdulen(skb) = (hlen + dlen + 3) & (~0x3);
13187b36b6e0Skxie@chelsio.com 		if (dlen)
13197b36b6e0Skxie@chelsio.com 			cxgbi_skcb_rx_pdulen(skb) += csk->dcrc_len;
13207b36b6e0Skxie@chelsio.com 		csk->rcv_nxt += cxgbi_skcb_rx_pdulen(skb);
13217b36b6e0Skxie@chelsio.com 
13227b36b6e0Skxie@chelsio.com 		log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_PDU_RX,
13237b36b6e0Skxie@chelsio.com 			"csk 0x%p, skb 0x%p, 0x%x,%u+%u,0x%x,0x%x.\n",
13247b36b6e0Skxie@chelsio.com 			csk, skb, *bhs, hlen, dlen,
13257b36b6e0Skxie@chelsio.com 			ntohl(*((unsigned int *)(bhs + 16))),
13267b36b6e0Skxie@chelsio.com 			ntohl(*((unsigned int *)(bhs + 24))));
13277b36b6e0Skxie@chelsio.com 
13287b36b6e0Skxie@chelsio.com 	} else {
1329e27d6169Skxie@chelsio.com 		struct sk_buff *lskb = csk->skb_ulp_lhdr;
13307b36b6e0Skxie@chelsio.com 
1331e27d6169Skxie@chelsio.com 		cxgbi_skcb_set_flag(lskb, SKCBF_RX_DATA);
13327b36b6e0Skxie@chelsio.com 		log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_PDU_RX,
13337b36b6e0Skxie@chelsio.com 			"csk 0x%p,%u,0x%lx, skb 0x%p data, 0x%p.\n",
13347b36b6e0Skxie@chelsio.com 			csk, csk->state, csk->flags, skb, lskb);
13357b36b6e0Skxie@chelsio.com 	}
13367b36b6e0Skxie@chelsio.com 
13377b36b6e0Skxie@chelsio.com 	__skb_queue_tail(&csk->receive_queue, skb);
13387b36b6e0Skxie@chelsio.com 	spin_unlock_bh(&csk->lock);
13397b36b6e0Skxie@chelsio.com 	return;
13407b36b6e0Skxie@chelsio.com 
13417b36b6e0Skxie@chelsio.com abort_conn:
13427b36b6e0Skxie@chelsio.com 	send_abort_req(csk);
13437b36b6e0Skxie@chelsio.com discard:
13447b36b6e0Skxie@chelsio.com 	spin_unlock_bh(&csk->lock);
13457b36b6e0Skxie@chelsio.com rel_skb:
13467b36b6e0Skxie@chelsio.com 	__kfree_skb(skb);
13477b36b6e0Skxie@chelsio.com }
13487b36b6e0Skxie@chelsio.com 
134944830d8fSVarun Prakash static void do_rx_iscsi_data(struct cxgbi_device *cdev, struct sk_buff *skb)
135044830d8fSVarun Prakash {
135144830d8fSVarun Prakash 	struct cxgbi_sock *csk;
135244830d8fSVarun Prakash 	struct cpl_iscsi_hdr *cpl = (struct cpl_iscsi_hdr *)skb->data;
135344830d8fSVarun Prakash 	struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(cdev);
135444830d8fSVarun Prakash 	struct tid_info *t = lldi->tids;
135544830d8fSVarun Prakash 	struct sk_buff *lskb;
135644830d8fSVarun Prakash 	u32 tid = GET_TID(cpl);
135744830d8fSVarun Prakash 	u16 pdu_len_ddp = be16_to_cpu(cpl->pdu_len_ddp);
135844830d8fSVarun Prakash 
135944830d8fSVarun Prakash 	csk = lookup_tid(t, tid);
136044830d8fSVarun Prakash 	if (unlikely(!csk)) {
136144830d8fSVarun Prakash 		pr_err("can't find conn. for tid %u.\n", tid);
136244830d8fSVarun Prakash 		goto rel_skb;
136344830d8fSVarun Prakash 	}
136444830d8fSVarun Prakash 
136544830d8fSVarun Prakash 	log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_PDU_RX,
136644830d8fSVarun Prakash 		  "csk 0x%p,%u,0x%lx, tid %u, skb 0x%p,%u, 0x%x.\n",
136744830d8fSVarun Prakash 		  csk, csk->state, csk->flags, csk->tid, skb,
136844830d8fSVarun Prakash 		  skb->len, pdu_len_ddp);
136944830d8fSVarun Prakash 
137044830d8fSVarun Prakash 	spin_lock_bh(&csk->lock);
137144830d8fSVarun Prakash 
137244830d8fSVarun Prakash 	if (unlikely(csk->state >= CTP_PASSIVE_CLOSE)) {
137344830d8fSVarun Prakash 		log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
137444830d8fSVarun Prakash 			  "csk 0x%p,%u,0x%lx,%u, bad state.\n",
137544830d8fSVarun Prakash 			  csk, csk->state, csk->flags, csk->tid);
137644830d8fSVarun Prakash 
137744830d8fSVarun Prakash 		if (csk->state != CTP_ABORTING)
137844830d8fSVarun Prakash 			goto abort_conn;
137944830d8fSVarun Prakash 		else
138044830d8fSVarun Prakash 			goto discard;
138144830d8fSVarun Prakash 	}
138244830d8fSVarun Prakash 
138344830d8fSVarun Prakash 	cxgbi_skcb_tcp_seq(skb) = be32_to_cpu(cpl->seq);
138444830d8fSVarun Prakash 	cxgbi_skcb_flags(skb) = 0;
138544830d8fSVarun Prakash 
138644830d8fSVarun Prakash 	skb_reset_transport_header(skb);
138744830d8fSVarun Prakash 	__skb_pull(skb, sizeof(*cpl));
138844830d8fSVarun Prakash 	__pskb_trim(skb, ntohs(cpl->len));
138944830d8fSVarun Prakash 
139044830d8fSVarun Prakash 	if (!csk->skb_ulp_lhdr)
139144830d8fSVarun Prakash 		csk->skb_ulp_lhdr = skb;
139244830d8fSVarun Prakash 
139344830d8fSVarun Prakash 	lskb = csk->skb_ulp_lhdr;
139444830d8fSVarun Prakash 	cxgbi_skcb_set_flag(lskb, SKCBF_RX_DATA);
139544830d8fSVarun Prakash 
139644830d8fSVarun Prakash 	log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_PDU_RX,
139744830d8fSVarun Prakash 		  "csk 0x%p,%u,0x%lx, skb 0x%p data, 0x%p.\n",
139844830d8fSVarun Prakash 		  csk, csk->state, csk->flags, skb, lskb);
139944830d8fSVarun Prakash 
140044830d8fSVarun Prakash 	__skb_queue_tail(&csk->receive_queue, skb);
140144830d8fSVarun Prakash 	spin_unlock_bh(&csk->lock);
140244830d8fSVarun Prakash 	return;
140344830d8fSVarun Prakash 
140444830d8fSVarun Prakash abort_conn:
140544830d8fSVarun Prakash 	send_abort_req(csk);
140644830d8fSVarun Prakash discard:
140744830d8fSVarun Prakash 	spin_unlock_bh(&csk->lock);
140844830d8fSVarun Prakash rel_skb:
140944830d8fSVarun Prakash 	__kfree_skb(skb);
141044830d8fSVarun Prakash }
141144830d8fSVarun Prakash 
141244830d8fSVarun Prakash static void
141344830d8fSVarun Prakash cxgb4i_process_ddpvld(struct cxgbi_sock *csk,
141444830d8fSVarun Prakash 		      struct sk_buff *skb, u32 ddpvld)
141544830d8fSVarun Prakash {
141644830d8fSVarun Prakash 	if (ddpvld & (1 << CPL_RX_DDP_STATUS_HCRC_SHIFT)) {
141744830d8fSVarun Prakash 		pr_info("csk 0x%p, lhdr 0x%p, status 0x%x, hcrc bad 0x%lx.\n",
141844830d8fSVarun Prakash 			csk, skb, ddpvld, cxgbi_skcb_flags(skb));
141944830d8fSVarun Prakash 		cxgbi_skcb_set_flag(skb, SKCBF_RX_HCRC_ERR);
142044830d8fSVarun Prakash 	}
142144830d8fSVarun Prakash 
142244830d8fSVarun Prakash 	if (ddpvld & (1 << CPL_RX_DDP_STATUS_DCRC_SHIFT)) {
142344830d8fSVarun Prakash 		pr_info("csk 0x%p, lhdr 0x%p, status 0x%x, dcrc bad 0x%lx.\n",
142444830d8fSVarun Prakash 			csk, skb, ddpvld, cxgbi_skcb_flags(skb));
142544830d8fSVarun Prakash 		cxgbi_skcb_set_flag(skb, SKCBF_RX_DCRC_ERR);
142644830d8fSVarun Prakash 	}
142744830d8fSVarun Prakash 
142844830d8fSVarun Prakash 	if (ddpvld & (1 << CPL_RX_DDP_STATUS_PAD_SHIFT)) {
142944830d8fSVarun Prakash 		log_debug(1 << CXGBI_DBG_PDU_RX,
143044830d8fSVarun Prakash 			  "csk 0x%p, lhdr 0x%p, status 0x%x, pad bad.\n",
143144830d8fSVarun Prakash 			  csk, skb, ddpvld);
143244830d8fSVarun Prakash 		cxgbi_skcb_set_flag(skb, SKCBF_RX_PAD_ERR);
143344830d8fSVarun Prakash 	}
143444830d8fSVarun Prakash 
143544830d8fSVarun Prakash 	if ((ddpvld & (1 << CPL_RX_DDP_STATUS_DDP_SHIFT)) &&
143644830d8fSVarun Prakash 	    !cxgbi_skcb_test_flag(skb, SKCBF_RX_DATA)) {
143744830d8fSVarun Prakash 		log_debug(1 << CXGBI_DBG_PDU_RX,
143844830d8fSVarun Prakash 			  "csk 0x%p, lhdr 0x%p, 0x%x, data ddp'ed.\n",
143944830d8fSVarun Prakash 			  csk, skb, ddpvld);
144044830d8fSVarun Prakash 		cxgbi_skcb_set_flag(skb, SKCBF_RX_DATA_DDPD);
144144830d8fSVarun Prakash 	}
144244830d8fSVarun Prakash }
144344830d8fSVarun Prakash 
14447b36b6e0Skxie@chelsio.com static void do_rx_data_ddp(struct cxgbi_device *cdev,
14457b36b6e0Skxie@chelsio.com 				  struct sk_buff *skb)
14467b36b6e0Skxie@chelsio.com {
14477b36b6e0Skxie@chelsio.com 	struct cxgbi_sock *csk;
14487b36b6e0Skxie@chelsio.com 	struct sk_buff *lskb;
14497b36b6e0Skxie@chelsio.com 	struct cpl_rx_data_ddp *rpl = (struct cpl_rx_data_ddp *)skb->data;
14507b36b6e0Skxie@chelsio.com 	unsigned int tid = GET_TID(rpl);
14517b36b6e0Skxie@chelsio.com 	struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(cdev);
14527b36b6e0Skxie@chelsio.com 	struct tid_info *t = lldi->tids;
145344830d8fSVarun Prakash 	u32 ddpvld = be32_to_cpu(rpl->ddpvld);
14547b36b6e0Skxie@chelsio.com 
14557b36b6e0Skxie@chelsio.com 	csk = lookup_tid(t, tid);
14567b36b6e0Skxie@chelsio.com 	if (unlikely(!csk)) {
14577b36b6e0Skxie@chelsio.com 		pr_err("can't find connection for tid %u.\n", tid);
14587b36b6e0Skxie@chelsio.com 		goto rel_skb;
14597b36b6e0Skxie@chelsio.com 	}
14607b36b6e0Skxie@chelsio.com 
14617b36b6e0Skxie@chelsio.com 	log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_PDU_RX,
14627b36b6e0Skxie@chelsio.com 		"csk 0x%p,%u,0x%lx, skb 0x%p,0x%x, lhdr 0x%p.\n",
146344830d8fSVarun Prakash 		csk, csk->state, csk->flags, skb, ddpvld, csk->skb_ulp_lhdr);
14647b36b6e0Skxie@chelsio.com 
14657b36b6e0Skxie@chelsio.com 	spin_lock_bh(&csk->lock);
14667b36b6e0Skxie@chelsio.com 
14677b36b6e0Skxie@chelsio.com 	if (unlikely(csk->state >= CTP_PASSIVE_CLOSE)) {
14687b36b6e0Skxie@chelsio.com 		log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
14697b36b6e0Skxie@chelsio.com 			"csk 0x%p,%u,0x%lx,%u, bad state.\n",
14707b36b6e0Skxie@chelsio.com 			csk, csk->state, csk->flags, csk->tid);
14717b36b6e0Skxie@chelsio.com 		if (csk->state != CTP_ABORTING)
14727b36b6e0Skxie@chelsio.com 			goto abort_conn;
14737b36b6e0Skxie@chelsio.com 		else
14747b36b6e0Skxie@chelsio.com 			goto discard;
14757b36b6e0Skxie@chelsio.com 	}
14767b36b6e0Skxie@chelsio.com 
14777b36b6e0Skxie@chelsio.com 	if (!csk->skb_ulp_lhdr) {
14787b36b6e0Skxie@chelsio.com 		pr_err("tid 0x%x, rcv RX_DATA_DDP w/o pdu bhs.\n", csk->tid);
14797b36b6e0Skxie@chelsio.com 		goto abort_conn;
14807b36b6e0Skxie@chelsio.com 	}
14817b36b6e0Skxie@chelsio.com 
14827b36b6e0Skxie@chelsio.com 	lskb = csk->skb_ulp_lhdr;
14837b36b6e0Skxie@chelsio.com 	csk->skb_ulp_lhdr = NULL;
14847b36b6e0Skxie@chelsio.com 
14857b36b6e0Skxie@chelsio.com 	cxgbi_skcb_rx_ddigest(lskb) = ntohl(rpl->ulp_crc);
14867b36b6e0Skxie@chelsio.com 
14877b36b6e0Skxie@chelsio.com 	if (ntohs(rpl->len) != cxgbi_skcb_rx_pdulen(lskb))
14887b36b6e0Skxie@chelsio.com 		pr_info("tid 0x%x, RX_DATA_DDP pdulen %u != %u.\n",
14897b36b6e0Skxie@chelsio.com 			csk->tid, ntohs(rpl->len), cxgbi_skcb_rx_pdulen(lskb));
14907b36b6e0Skxie@chelsio.com 
149144830d8fSVarun Prakash 	cxgb4i_process_ddpvld(csk, lskb, ddpvld);
149244830d8fSVarun Prakash 
14937b36b6e0Skxie@chelsio.com 	log_debug(1 << CXGBI_DBG_PDU_RX,
14947b36b6e0Skxie@chelsio.com 		"csk 0x%p, lskb 0x%p, f 0x%lx.\n",
14957b36b6e0Skxie@chelsio.com 		csk, lskb, cxgbi_skcb_flags(lskb));
14967b36b6e0Skxie@chelsio.com 
1497e27d6169Skxie@chelsio.com 	cxgbi_skcb_set_flag(lskb, SKCBF_RX_STATUS);
14987b36b6e0Skxie@chelsio.com 	cxgbi_conn_pdu_ready(csk);
14997b36b6e0Skxie@chelsio.com 	spin_unlock_bh(&csk->lock);
15007b36b6e0Skxie@chelsio.com 	goto rel_skb;
15017b36b6e0Skxie@chelsio.com 
15027b36b6e0Skxie@chelsio.com abort_conn:
15037b36b6e0Skxie@chelsio.com 	send_abort_req(csk);
15047b36b6e0Skxie@chelsio.com discard:
15057b36b6e0Skxie@chelsio.com 	spin_unlock_bh(&csk->lock);
15067b36b6e0Skxie@chelsio.com rel_skb:
15077b36b6e0Skxie@chelsio.com 	__kfree_skb(skb);
15087b36b6e0Skxie@chelsio.com }
15097b36b6e0Skxie@chelsio.com 
151044830d8fSVarun Prakash static void
151144830d8fSVarun Prakash do_rx_iscsi_cmp(struct cxgbi_device *cdev, struct sk_buff *skb)
151244830d8fSVarun Prakash {
151344830d8fSVarun Prakash 	struct cxgbi_sock *csk;
151444830d8fSVarun Prakash 	struct cpl_rx_iscsi_cmp *rpl = (struct cpl_rx_iscsi_cmp *)skb->data;
151544830d8fSVarun Prakash 	struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(cdev);
151644830d8fSVarun Prakash 	struct tid_info *t = lldi->tids;
151744830d8fSVarun Prakash 	struct sk_buff *data_skb = NULL;
151844830d8fSVarun Prakash 	u32 tid = GET_TID(rpl);
151944830d8fSVarun Prakash 	u32 ddpvld = be32_to_cpu(rpl->ddpvld);
152044830d8fSVarun Prakash 	u32 seq = be32_to_cpu(rpl->seq);
152144830d8fSVarun Prakash 	u16 pdu_len_ddp = be16_to_cpu(rpl->pdu_len_ddp);
152244830d8fSVarun Prakash 
152344830d8fSVarun Prakash 	csk = lookup_tid(t, tid);
152444830d8fSVarun Prakash 	if (unlikely(!csk)) {
152544830d8fSVarun Prakash 		pr_err("can't find connection for tid %u.\n", tid);
152644830d8fSVarun Prakash 		goto rel_skb;
152744830d8fSVarun Prakash 	}
152844830d8fSVarun Prakash 
152944830d8fSVarun Prakash 	log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_PDU_RX,
153044830d8fSVarun Prakash 		  "csk 0x%p,%u,0x%lx, skb 0x%p,0x%x, lhdr 0x%p, len %u, "
153144830d8fSVarun Prakash 		  "pdu_len_ddp %u, status %u.\n",
153244830d8fSVarun Prakash 		  csk, csk->state, csk->flags, skb, ddpvld, csk->skb_ulp_lhdr,
153344830d8fSVarun Prakash 		  ntohs(rpl->len), pdu_len_ddp,  rpl->status);
153444830d8fSVarun Prakash 
153544830d8fSVarun Prakash 	spin_lock_bh(&csk->lock);
153644830d8fSVarun Prakash 
153744830d8fSVarun Prakash 	if (unlikely(csk->state >= CTP_PASSIVE_CLOSE)) {
153844830d8fSVarun Prakash 		log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
153944830d8fSVarun Prakash 			  "csk 0x%p,%u,0x%lx,%u, bad state.\n",
154044830d8fSVarun Prakash 			  csk, csk->state, csk->flags, csk->tid);
154144830d8fSVarun Prakash 
154244830d8fSVarun Prakash 		if (csk->state != CTP_ABORTING)
154344830d8fSVarun Prakash 			goto abort_conn;
154444830d8fSVarun Prakash 		else
154544830d8fSVarun Prakash 			goto discard;
154644830d8fSVarun Prakash 	}
154744830d8fSVarun Prakash 
154844830d8fSVarun Prakash 	cxgbi_skcb_tcp_seq(skb) = seq;
154944830d8fSVarun Prakash 	cxgbi_skcb_flags(skb) = 0;
155044830d8fSVarun Prakash 	cxgbi_skcb_rx_pdulen(skb) = 0;
155144830d8fSVarun Prakash 
155244830d8fSVarun Prakash 	skb_reset_transport_header(skb);
155344830d8fSVarun Prakash 	__skb_pull(skb, sizeof(*rpl));
155444830d8fSVarun Prakash 	__pskb_trim(skb, be16_to_cpu(rpl->len));
155544830d8fSVarun Prakash 
155644830d8fSVarun Prakash 	csk->rcv_nxt = seq + pdu_len_ddp;
155744830d8fSVarun Prakash 
155844830d8fSVarun Prakash 	if (csk->skb_ulp_lhdr) {
155944830d8fSVarun Prakash 		data_skb = skb_peek(&csk->receive_queue);
156044830d8fSVarun Prakash 		if (!data_skb ||
156144830d8fSVarun Prakash 		    !cxgbi_skcb_test_flag(data_skb, SKCBF_RX_DATA)) {
156244830d8fSVarun Prakash 			pr_err("Error! freelist data not found 0x%p, tid %u\n",
156344830d8fSVarun Prakash 			       data_skb, tid);
156444830d8fSVarun Prakash 
156544830d8fSVarun Prakash 			goto abort_conn;
156644830d8fSVarun Prakash 		}
156744830d8fSVarun Prakash 		__skb_unlink(data_skb, &csk->receive_queue);
156844830d8fSVarun Prakash 
156944830d8fSVarun Prakash 		cxgbi_skcb_set_flag(skb, SKCBF_RX_DATA);
157044830d8fSVarun Prakash 
157144830d8fSVarun Prakash 		__skb_queue_tail(&csk->receive_queue, skb);
157244830d8fSVarun Prakash 		__skb_queue_tail(&csk->receive_queue, data_skb);
157344830d8fSVarun Prakash 	} else {
157444830d8fSVarun Prakash 		 __skb_queue_tail(&csk->receive_queue, skb);
157544830d8fSVarun Prakash 	}
157644830d8fSVarun Prakash 
157744830d8fSVarun Prakash 	csk->skb_ulp_lhdr = NULL;
157844830d8fSVarun Prakash 
157944830d8fSVarun Prakash 	cxgbi_skcb_set_flag(skb, SKCBF_RX_HDR);
158044830d8fSVarun Prakash 	cxgbi_skcb_set_flag(skb, SKCBF_RX_STATUS);
158144830d8fSVarun Prakash 	cxgbi_skcb_set_flag(skb, SKCBF_RX_ISCSI_COMPL);
158244830d8fSVarun Prakash 	cxgbi_skcb_rx_ddigest(skb) = be32_to_cpu(rpl->ulp_crc);
158344830d8fSVarun Prakash 
158444830d8fSVarun Prakash 	cxgb4i_process_ddpvld(csk, skb, ddpvld);
158544830d8fSVarun Prakash 
158644830d8fSVarun Prakash 	log_debug(1 << CXGBI_DBG_PDU_RX, "csk 0x%p, skb 0x%p, f 0x%lx.\n",
158744830d8fSVarun Prakash 		  csk, skb, cxgbi_skcb_flags(skb));
158844830d8fSVarun Prakash 
158944830d8fSVarun Prakash 	cxgbi_conn_pdu_ready(csk);
159044830d8fSVarun Prakash 	spin_unlock_bh(&csk->lock);
159144830d8fSVarun Prakash 
159244830d8fSVarun Prakash 	return;
159344830d8fSVarun Prakash 
159444830d8fSVarun Prakash abort_conn:
159544830d8fSVarun Prakash 	send_abort_req(csk);
159644830d8fSVarun Prakash discard:
159744830d8fSVarun Prakash 	spin_unlock_bh(&csk->lock);
159844830d8fSVarun Prakash rel_skb:
159944830d8fSVarun Prakash 	__kfree_skb(skb);
160044830d8fSVarun Prakash }
160144830d8fSVarun Prakash 
16027b36b6e0Skxie@chelsio.com static void do_fw4_ack(struct cxgbi_device *cdev, struct sk_buff *skb)
16037b36b6e0Skxie@chelsio.com {
16047b36b6e0Skxie@chelsio.com 	struct cxgbi_sock *csk;
16057b36b6e0Skxie@chelsio.com 	struct cpl_fw4_ack *rpl = (struct cpl_fw4_ack *)skb->data;
16067b36b6e0Skxie@chelsio.com 	unsigned int tid = GET_TID(rpl);
16077b36b6e0Skxie@chelsio.com 	struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(cdev);
16087b36b6e0Skxie@chelsio.com 	struct tid_info *t = lldi->tids;
16097b36b6e0Skxie@chelsio.com 
16107b36b6e0Skxie@chelsio.com 	csk = lookup_tid(t, tid);
16117b36b6e0Skxie@chelsio.com 	if (unlikely(!csk))
16127b36b6e0Skxie@chelsio.com 		pr_err("can't find connection for tid %u.\n", tid);
16137b36b6e0Skxie@chelsio.com 	else {
16147b36b6e0Skxie@chelsio.com 		log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
16157b36b6e0Skxie@chelsio.com 			"csk 0x%p,%u,0x%lx,%u.\n",
16167b36b6e0Skxie@chelsio.com 			csk, csk->state, csk->flags, csk->tid);
16177b36b6e0Skxie@chelsio.com 		cxgbi_sock_rcv_wr_ack(csk, rpl->credits, ntohl(rpl->snd_una),
16187b36b6e0Skxie@chelsio.com 					rpl->seq_vld);
16197b36b6e0Skxie@chelsio.com 	}
16207b36b6e0Skxie@chelsio.com 	__kfree_skb(skb);
16217b36b6e0Skxie@chelsio.com }
16227b36b6e0Skxie@chelsio.com 
16237b36b6e0Skxie@chelsio.com static void do_set_tcb_rpl(struct cxgbi_device *cdev, struct sk_buff *skb)
16247b36b6e0Skxie@chelsio.com {
16257b36b6e0Skxie@chelsio.com 	struct cpl_set_tcb_rpl *rpl = (struct cpl_set_tcb_rpl *)skb->data;
16267b36b6e0Skxie@chelsio.com 	unsigned int tid = GET_TID(rpl);
16277b36b6e0Skxie@chelsio.com 	struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(cdev);
16287b36b6e0Skxie@chelsio.com 	struct tid_info *t = lldi->tids;
16297b36b6e0Skxie@chelsio.com 	struct cxgbi_sock *csk;
16307b36b6e0Skxie@chelsio.com 
16317b36b6e0Skxie@chelsio.com 	csk = lookup_tid(t, tid);
16329e8f1c79SVarun Prakash 	if (!csk) {
16337b36b6e0Skxie@chelsio.com 		pr_err("can't find conn. for tid %u.\n", tid);
16349e8f1c79SVarun Prakash 		return;
16359e8f1c79SVarun Prakash 	}
16367b36b6e0Skxie@chelsio.com 
16377b36b6e0Skxie@chelsio.com 	log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
16387b36b6e0Skxie@chelsio.com 		"csk 0x%p,%u,%lx,%u, status 0x%x.\n",
16397b36b6e0Skxie@chelsio.com 		csk, csk->state, csk->flags, csk->tid, rpl->status);
16407b36b6e0Skxie@chelsio.com 
16419e8f1c79SVarun Prakash 	if (rpl->status != CPL_ERR_NONE) {
16427b36b6e0Skxie@chelsio.com 		pr_err("csk 0x%p,%u, SET_TCB_RPL status %u.\n",
16437b36b6e0Skxie@chelsio.com 			csk, tid, rpl->status);
16449e8f1c79SVarun Prakash 		csk->err = -EINVAL;
16459e8f1c79SVarun Prakash 	}
16469e8f1c79SVarun Prakash 
16479e8f1c79SVarun Prakash 	complete(&csk->cmpl);
16487b36b6e0Skxie@chelsio.com 
16497b36b6e0Skxie@chelsio.com 	__kfree_skb(skb);
16507b36b6e0Skxie@chelsio.com }
16517b36b6e0Skxie@chelsio.com 
16527b36b6e0Skxie@chelsio.com static int alloc_cpls(struct cxgbi_sock *csk)
16537b36b6e0Skxie@chelsio.com {
165424d3f95aSkxie@chelsio.com 	csk->cpl_close = alloc_wr(sizeof(struct cpl_close_con_req),
165524d3f95aSkxie@chelsio.com 					0, GFP_KERNEL);
16567b36b6e0Skxie@chelsio.com 	if (!csk->cpl_close)
16577b36b6e0Skxie@chelsio.com 		return -ENOMEM;
16587b36b6e0Skxie@chelsio.com 
165924d3f95aSkxie@chelsio.com 	csk->cpl_abort_req = alloc_wr(sizeof(struct cpl_abort_req),
166024d3f95aSkxie@chelsio.com 					0, GFP_KERNEL);
16617b36b6e0Skxie@chelsio.com 	if (!csk->cpl_abort_req)
16627b36b6e0Skxie@chelsio.com 		goto free_cpls;
16637b36b6e0Skxie@chelsio.com 
166424d3f95aSkxie@chelsio.com 	csk->cpl_abort_rpl = alloc_wr(sizeof(struct cpl_abort_rpl),
166524d3f95aSkxie@chelsio.com 					0, GFP_KERNEL);
16667b36b6e0Skxie@chelsio.com 	if (!csk->cpl_abort_rpl)
16677b36b6e0Skxie@chelsio.com 		goto free_cpls;
16687b36b6e0Skxie@chelsio.com 	return 0;
16697b36b6e0Skxie@chelsio.com 
16707b36b6e0Skxie@chelsio.com free_cpls:
16717b36b6e0Skxie@chelsio.com 	cxgbi_sock_free_cpl_skbs(csk);
16727b36b6e0Skxie@chelsio.com 	return -ENOMEM;
16737b36b6e0Skxie@chelsio.com }
16747b36b6e0Skxie@chelsio.com 
16757b36b6e0Skxie@chelsio.com static inline void l2t_put(struct cxgbi_sock *csk)
16767b36b6e0Skxie@chelsio.com {
16777b36b6e0Skxie@chelsio.com 	if (csk->l2t) {
16787b36b6e0Skxie@chelsio.com 		cxgb4_l2t_release(csk->l2t);
16797b36b6e0Skxie@chelsio.com 		csk->l2t = NULL;
16807b36b6e0Skxie@chelsio.com 		cxgbi_sock_put(csk);
16817b36b6e0Skxie@chelsio.com 	}
16827b36b6e0Skxie@chelsio.com }
16837b36b6e0Skxie@chelsio.com 
16847b36b6e0Skxie@chelsio.com static void release_offload_resources(struct cxgbi_sock *csk)
16857b36b6e0Skxie@chelsio.com {
16867b36b6e0Skxie@chelsio.com 	struct cxgb4_lld_info *lldi;
1687211a84e3SAnish Bhatt #if IS_ENABLED(CONFIG_IPV6)
1688211a84e3SAnish Bhatt 	struct net_device *ndev = csk->cdev->ports[csk->port_id];
1689211a84e3SAnish Bhatt #endif
16907b36b6e0Skxie@chelsio.com 
16917b36b6e0Skxie@chelsio.com 	log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
16927b36b6e0Skxie@chelsio.com 		"csk 0x%p,%u,0x%lx,%u.\n",
16937b36b6e0Skxie@chelsio.com 		csk, csk->state, csk->flags, csk->tid);
16947b36b6e0Skxie@chelsio.com 
16957b36b6e0Skxie@chelsio.com 	cxgbi_sock_free_cpl_skbs(csk);
16969b3a081fSVarun Prakash 	cxgbi_sock_purge_write_queue(csk);
16977b36b6e0Skxie@chelsio.com 	if (csk->wr_cred != csk->wr_max_cred) {
16987b36b6e0Skxie@chelsio.com 		cxgbi_sock_purge_wr_queue(csk);
16997b36b6e0Skxie@chelsio.com 		cxgbi_sock_reset_wr_list(csk);
17007b36b6e0Skxie@chelsio.com 	}
17017b36b6e0Skxie@chelsio.com 
17027b36b6e0Skxie@chelsio.com 	l2t_put(csk);
1703211a84e3SAnish Bhatt #if IS_ENABLED(CONFIG_IPV6)
1704211a84e3SAnish Bhatt 	if (csk->csk_family == AF_INET6)
1705211a84e3SAnish Bhatt 		cxgb4_clip_release(ndev,
1706211a84e3SAnish Bhatt 				   (const u32 *)&csk->saddr6.sin6_addr, 1);
1707211a84e3SAnish Bhatt #endif
1708211a84e3SAnish Bhatt 
17097b36b6e0Skxie@chelsio.com 	if (cxgbi_sock_flag(csk, CTPF_HAS_ATID))
17107b36b6e0Skxie@chelsio.com 		free_atid(csk);
17117b36b6e0Skxie@chelsio.com 	else if (cxgbi_sock_flag(csk, CTPF_HAS_TID)) {
17127b36b6e0Skxie@chelsio.com 		lldi = cxgbi_cdev_priv(csk->cdev);
17131dec4cecSGanesh Goudar 		cxgb4_remove_tid(lldi->tids, 0, csk->tid,
17141dec4cecSGanesh Goudar 				 csk->csk_family);
17157b36b6e0Skxie@chelsio.com 		cxgbi_sock_clear_flag(csk, CTPF_HAS_TID);
17167b36b6e0Skxie@chelsio.com 		cxgbi_sock_put(csk);
17177b36b6e0Skxie@chelsio.com 	}
17187b36b6e0Skxie@chelsio.com 	csk->dst = NULL;
17197b36b6e0Skxie@chelsio.com }
17207b36b6e0Skxie@chelsio.com 
1721b5a5fe4eSVarun Prakash #ifdef CONFIG_CHELSIO_T4_DCB
1722b5a5fe4eSVarun Prakash static inline u8 get_iscsi_dcb_state(struct net_device *ndev)
1723b5a5fe4eSVarun Prakash {
1724b5a5fe4eSVarun Prakash 	return ndev->dcbnl_ops->getstate(ndev);
1725b5a5fe4eSVarun Prakash }
1726b5a5fe4eSVarun Prakash 
1727b5a5fe4eSVarun Prakash static int select_priority(int pri_mask)
1728b5a5fe4eSVarun Prakash {
1729b5a5fe4eSVarun Prakash 	if (!pri_mask)
1730b5a5fe4eSVarun Prakash 		return 0;
1731b5a5fe4eSVarun Prakash 	return (ffs(pri_mask) - 1);
1732b5a5fe4eSVarun Prakash }
1733b5a5fe4eSVarun Prakash 
1734b5a5fe4eSVarun Prakash static u8 get_iscsi_dcb_priority(struct net_device *ndev)
1735b5a5fe4eSVarun Prakash {
1736b5a5fe4eSVarun Prakash 	int rv;
1737b5a5fe4eSVarun Prakash 	u8 caps;
1738b5a5fe4eSVarun Prakash 
1739b5a5fe4eSVarun Prakash 	struct dcb_app iscsi_dcb_app = {
1740b5a5fe4eSVarun Prakash 		.protocol = 3260
1741b5a5fe4eSVarun Prakash 	};
1742b5a5fe4eSVarun Prakash 
1743b5a5fe4eSVarun Prakash 	rv = (int)ndev->dcbnl_ops->getcap(ndev, DCB_CAP_ATTR_DCBX, &caps);
1744b5a5fe4eSVarun Prakash 	if (rv)
1745b5a5fe4eSVarun Prakash 		return 0;
1746b5a5fe4eSVarun Prakash 
1747b5a5fe4eSVarun Prakash 	if (caps & DCB_CAP_DCBX_VER_IEEE) {
1748152e30fcSVarun Prakash 		iscsi_dcb_app.selector = IEEE_8021QAZ_APP_SEL_STREAM;
1749152e30fcSVarun Prakash 		rv = dcb_ieee_getapp_mask(ndev, &iscsi_dcb_app);
1750152e30fcSVarun Prakash 		if (!rv) {
1751b5a5fe4eSVarun Prakash 			iscsi_dcb_app.selector = IEEE_8021QAZ_APP_SEL_ANY;
1752b5a5fe4eSVarun Prakash 			rv = dcb_ieee_getapp_mask(ndev, &iscsi_dcb_app);
1753152e30fcSVarun Prakash 		}
1754b5a5fe4eSVarun Prakash 	} else if (caps & DCB_CAP_DCBX_VER_CEE) {
1755b5a5fe4eSVarun Prakash 		iscsi_dcb_app.selector = DCB_APP_IDTYPE_PORTNUM;
1756b5a5fe4eSVarun Prakash 		rv = dcb_getapp(ndev, &iscsi_dcb_app);
1757b5a5fe4eSVarun Prakash 	}
1758b5a5fe4eSVarun Prakash 
1759b5a5fe4eSVarun Prakash 	log_debug(1 << CXGBI_DBG_ISCSI,
1760b5a5fe4eSVarun Prakash 		  "iSCSI priority is set to %u\n", select_priority(rv));
1761b5a5fe4eSVarun Prakash 	return select_priority(rv);
1762b5a5fe4eSVarun Prakash }
1763b5a5fe4eSVarun Prakash #endif
1764b5a5fe4eSVarun Prakash 
17657b36b6e0Skxie@chelsio.com static int init_act_open(struct cxgbi_sock *csk)
17667b36b6e0Skxie@chelsio.com {
17677b36b6e0Skxie@chelsio.com 	struct cxgbi_device *cdev = csk->cdev;
17687b36b6e0Skxie@chelsio.com 	struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(cdev);
17697b36b6e0Skxie@chelsio.com 	struct net_device *ndev = cdev->ports[csk->port_id];
17707b36b6e0Skxie@chelsio.com 	struct sk_buff *skb = NULL;
1771759a0cc5SAnish Bhatt 	struct neighbour *n = NULL;
1772759a0cc5SAnish Bhatt 	void *daddr;
17737b36b6e0Skxie@chelsio.com 	unsigned int step;
17746c9e2770SVarun Prakash 	unsigned int rxq_idx;
1775759a0cc5SAnish Bhatt 	unsigned int size, size6;
177681daf10cSKaren Xie 	unsigned int linkspeed;
177781daf10cSKaren Xie 	unsigned int rcv_winf, snd_winf;
1778b5a5fe4eSVarun Prakash #ifdef CONFIG_CHELSIO_T4_DCB
1779b5a5fe4eSVarun Prakash 	u8 priority = 0;
1780b5a5fe4eSVarun Prakash #endif
17817b36b6e0Skxie@chelsio.com 	log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
17827b36b6e0Skxie@chelsio.com 		"csk 0x%p,%u,0x%lx,%u.\n",
17837b36b6e0Skxie@chelsio.com 		csk, csk->state, csk->flags, csk->tid);
17847b36b6e0Skxie@chelsio.com 
1785759a0cc5SAnish Bhatt 	if (csk->csk_family == AF_INET)
1786759a0cc5SAnish Bhatt 		daddr = &csk->daddr.sin_addr.s_addr;
1787e81fbf6cSAnish Bhatt #if IS_ENABLED(CONFIG_IPV6)
1788e81fbf6cSAnish Bhatt 	else if (csk->csk_family == AF_INET6)
1789759a0cc5SAnish Bhatt 		daddr = &csk->daddr6.sin6_addr;
1790e81fbf6cSAnish Bhatt #endif
1791e81fbf6cSAnish Bhatt 	else {
1792e81fbf6cSAnish Bhatt 		pr_err("address family 0x%x not supported\n", csk->csk_family);
1793e81fbf6cSAnish Bhatt 		goto rel_resource;
1794e81fbf6cSAnish Bhatt 	}
1795759a0cc5SAnish Bhatt 
1796759a0cc5SAnish Bhatt 	n = dst_neigh_lookup(csk->dst, daddr);
1797759a0cc5SAnish Bhatt 
1798759a0cc5SAnish Bhatt 	if (!n) {
1799759a0cc5SAnish Bhatt 		pr_err("%s, can't get neighbour of csk->dst.\n", ndev->name);
1800759a0cc5SAnish Bhatt 		goto rel_resource;
1801759a0cc5SAnish Bhatt 	}
1802759a0cc5SAnish Bhatt 
180371eb2ac5SVarun Prakash 	if (!(n->nud_state & NUD_VALID))
180471eb2ac5SVarun Prakash 		neigh_event_send(n, NULL);
180571eb2ac5SVarun Prakash 
18067b36b6e0Skxie@chelsio.com 	csk->atid = cxgb4_alloc_atid(lldi->tids, csk);
18077b36b6e0Skxie@chelsio.com 	if (csk->atid < 0) {
18087b36b6e0Skxie@chelsio.com 		pr_err("%s, NO atid available.\n", ndev->name);
1809338be072SQuentin Lambert 		goto rel_resource_without_clip;
18107b36b6e0Skxie@chelsio.com 	}
18117b36b6e0Skxie@chelsio.com 	cxgbi_sock_set_flag(csk, CTPF_HAS_ATID);
18127b36b6e0Skxie@chelsio.com 	cxgbi_sock_get(csk);
18137b36b6e0Skxie@chelsio.com 
1814b5a5fe4eSVarun Prakash #ifdef CONFIG_CHELSIO_T4_DCB
1815b5a5fe4eSVarun Prakash 	if (get_iscsi_dcb_state(ndev))
1816b5a5fe4eSVarun Prakash 		priority = get_iscsi_dcb_priority(ndev);
1817b5a5fe4eSVarun Prakash 
1818b5a5fe4eSVarun Prakash 	csk->dcb_priority = priority;
1819b5a5fe4eSVarun Prakash 	csk->l2t = cxgb4_l2t_get(lldi->l2t, n, ndev, priority);
1820b5a5fe4eSVarun Prakash #else
182151e059bdSDavid Miller 	csk->l2t = cxgb4_l2t_get(lldi->l2t, n, ndev, 0);
1822b5a5fe4eSVarun Prakash #endif
18237b36b6e0Skxie@chelsio.com 	if (!csk->l2t) {
18247b36b6e0Skxie@chelsio.com 		pr_err("%s, cannot alloc l2t.\n", ndev->name);
1825211a84e3SAnish Bhatt 		goto rel_resource_without_clip;
18267b36b6e0Skxie@chelsio.com 	}
18277b36b6e0Skxie@chelsio.com 	cxgbi_sock_get(csk);
18287b36b6e0Skxie@chelsio.com 
1829211a84e3SAnish Bhatt #if IS_ENABLED(CONFIG_IPV6)
1830211a84e3SAnish Bhatt 	if (csk->csk_family == AF_INET6)
1831211a84e3SAnish Bhatt 		cxgb4_clip_get(ndev, (const u32 *)&csk->saddr6.sin6_addr, 1);
1832211a84e3SAnish Bhatt #endif
1833211a84e3SAnish Bhatt 
1834586be7cbSVarun Prakash 	if (is_t4(lldi->adapter_type)) {
1835759a0cc5SAnish Bhatt 		size = sizeof(struct cpl_act_open_req);
1836759a0cc5SAnish Bhatt 		size6 = sizeof(struct cpl_act_open_req6);
1837586be7cbSVarun Prakash 	} else if (is_t5(lldi->adapter_type)) {
1838759a0cc5SAnish Bhatt 		size = sizeof(struct cpl_t5_act_open_req);
1839759a0cc5SAnish Bhatt 		size6 = sizeof(struct cpl_t5_act_open_req6);
1840586be7cbSVarun Prakash 	} else {
1841586be7cbSVarun Prakash 		size = sizeof(struct cpl_t6_act_open_req);
1842586be7cbSVarun Prakash 		size6 = sizeof(struct cpl_t6_act_open_req6);
1843759a0cc5SAnish Bhatt 	}
1844759a0cc5SAnish Bhatt 
1845759a0cc5SAnish Bhatt 	if (csk->csk_family == AF_INET)
1846759a0cc5SAnish Bhatt 		skb = alloc_wr(size, 0, GFP_NOIO);
1847f42bb57cSAnish Bhatt #if IS_ENABLED(CONFIG_IPV6)
1848759a0cc5SAnish Bhatt 	else
1849759a0cc5SAnish Bhatt 		skb = alloc_wr(size6, 0, GFP_NOIO);
1850f42bb57cSAnish Bhatt #endif
1851759a0cc5SAnish Bhatt 
18527b36b6e0Skxie@chelsio.com 	if (!skb)
18537b36b6e0Skxie@chelsio.com 		goto rel_resource;
18547b36b6e0Skxie@chelsio.com 	skb->sk = (struct sock *)csk;
18557b36b6e0Skxie@chelsio.com 	t4_set_arp_err_handler(skb, csk, cxgbi_sock_act_open_req_arp_failure);
18567b36b6e0Skxie@chelsio.com 
18577b36b6e0Skxie@chelsio.com 	if (!csk->mtu)
18587b36b6e0Skxie@chelsio.com 		csk->mtu = dst_mtu(csk->dst);
18597b36b6e0Skxie@chelsio.com 	cxgb4_best_mtu(lldi->mtus, csk->mtu, &csk->mss_idx);
18607b36b6e0Skxie@chelsio.com 	csk->tx_chan = cxgb4_port_chan(ndev);
186102d805dcSSantosh Rastapur 	csk->smac_idx = ((struct port_info *)netdev_priv(ndev))->smt_idx;
18627b36b6e0Skxie@chelsio.com 	step = lldi->ntxq / lldi->nchan;
18637b36b6e0Skxie@chelsio.com 	csk->txq_idx = cxgb4_port_idx(ndev) * step;
18647b36b6e0Skxie@chelsio.com 	step = lldi->nrxq / lldi->nchan;
18656c9e2770SVarun Prakash 	rxq_idx = (cxgb4_port_idx(ndev) * step) + (cdev->rxq_idx_cntr % step);
18666c9e2770SVarun Prakash 	cdev->rxq_idx_cntr++;
18676c9e2770SVarun Prakash 	csk->rss_qid = lldi->rxq_ids[rxq_idx];
186881daf10cSKaren Xie 	linkspeed = ((struct port_info *)netdev_priv(ndev))->link_cfg.speed;
186981daf10cSKaren Xie 	csk->snd_win = cxgb4i_snd_win;
187081daf10cSKaren Xie 	csk->rcv_win = cxgb4i_rcv_win;
187181daf10cSKaren Xie 	if (cxgb4i_rcv_win <= 0) {
187281daf10cSKaren Xie 		csk->rcv_win = CXGB4I_DEFAULT_10G_RCV_WIN;
187381daf10cSKaren Xie 		rcv_winf = linkspeed / SPEED_10000;
187481daf10cSKaren Xie 		if (rcv_winf)
187581daf10cSKaren Xie 			csk->rcv_win *= rcv_winf;
187681daf10cSKaren Xie 	}
187781daf10cSKaren Xie 	if (cxgb4i_snd_win <= 0) {
187881daf10cSKaren Xie 		csk->snd_win = CXGB4I_DEFAULT_10G_SND_WIN;
187981daf10cSKaren Xie 		snd_winf = linkspeed / SPEED_10000;
188081daf10cSKaren Xie 		if (snd_winf)
188181daf10cSKaren Xie 			csk->snd_win *= snd_winf;
188281daf10cSKaren Xie 	}
1883759a0cc5SAnish Bhatt 	csk->wr_cred = lldi->wr_cred -
1884759a0cc5SAnish Bhatt 		       DIV_ROUND_UP(sizeof(struct cpl_abort_req), 16);
1885759a0cc5SAnish Bhatt 	csk->wr_max_cred = csk->wr_cred;
18867b36b6e0Skxie@chelsio.com 	csk->wr_una_cred = 0;
18877b36b6e0Skxie@chelsio.com 	cxgbi_sock_reset_wr_list(csk);
18887b36b6e0Skxie@chelsio.com 	csk->err = 0;
18897b36b6e0Skxie@chelsio.com 
1890759a0cc5SAnish Bhatt 	pr_info_ipaddr("csk 0x%p,%u,0x%lx,%u,%u,%u, mtu %u,%u, smac %u.\n",
1891759a0cc5SAnish Bhatt 		       (&csk->saddr), (&csk->daddr), csk, csk->state,
1892759a0cc5SAnish Bhatt 		       csk->flags, csk->tx_chan, csk->txq_idx, csk->rss_qid,
1893759a0cc5SAnish Bhatt 		       csk->mtu, csk->mss_idx, csk->smac_idx);
1894759a0cc5SAnish Bhatt 
1895759a0cc5SAnish Bhatt 	/* must wait for either a act_open_rpl or act_open_establish */
18961fe1fdb0SVarun Prakash 	if (!try_module_get(cdev->owner)) {
18971fe1fdb0SVarun Prakash 		pr_err("%s, try_module_get failed.\n", ndev->name);
18981fe1fdb0SVarun Prakash 		goto rel_resource;
18991fe1fdb0SVarun Prakash 	}
19001fe1fdb0SVarun Prakash 
19017b36b6e0Skxie@chelsio.com 	cxgbi_sock_set_state(csk, CTP_ACTIVE_OPEN);
1902759a0cc5SAnish Bhatt 	if (csk->csk_family == AF_INET)
19037b36b6e0Skxie@chelsio.com 		send_act_open_req(csk, skb, csk->l2t);
1904f42bb57cSAnish Bhatt #if IS_ENABLED(CONFIG_IPV6)
1905759a0cc5SAnish Bhatt 	else
1906759a0cc5SAnish Bhatt 		send_act_open_req6(csk, skb, csk->l2t);
1907f42bb57cSAnish Bhatt #endif
1908c4737377SDavid S. Miller 	neigh_release(n);
1909759a0cc5SAnish Bhatt 
19107b36b6e0Skxie@chelsio.com 	return 0;
19117b36b6e0Skxie@chelsio.com 
19127b36b6e0Skxie@chelsio.com rel_resource:
1913211a84e3SAnish Bhatt #if IS_ENABLED(CONFIG_IPV6)
1914211a84e3SAnish Bhatt 	if (csk->csk_family == AF_INET6)
1915211a84e3SAnish Bhatt 		cxgb4_clip_release(ndev,
1916211a84e3SAnish Bhatt 				   (const u32 *)&csk->saddr6.sin6_addr, 1);
1917211a84e3SAnish Bhatt #endif
1918211a84e3SAnish Bhatt rel_resource_without_clip:
1919c4737377SDavid S. Miller 	if (n)
1920c4737377SDavid S. Miller 		neigh_release(n);
19217b36b6e0Skxie@chelsio.com 	if (skb)
19227b36b6e0Skxie@chelsio.com 		__kfree_skb(skb);
19237b36b6e0Skxie@chelsio.com 	return -EINVAL;
19247b36b6e0Skxie@chelsio.com }
19257b36b6e0Skxie@chelsio.com 
19264665bdd5SVarun Prakash static cxgb4i_cplhandler_func cxgb4i_cplhandlers[NUM_CPL_CMDS] = {
19277b36b6e0Skxie@chelsio.com 	[CPL_ACT_ESTABLISH] = do_act_establish,
19287b36b6e0Skxie@chelsio.com 	[CPL_ACT_OPEN_RPL] = do_act_open_rpl,
19297b36b6e0Skxie@chelsio.com 	[CPL_PEER_CLOSE] = do_peer_close,
19307b36b6e0Skxie@chelsio.com 	[CPL_ABORT_REQ_RSS] = do_abort_req_rss,
19317b36b6e0Skxie@chelsio.com 	[CPL_ABORT_RPL_RSS] = do_abort_rpl_rss,
19327b36b6e0Skxie@chelsio.com 	[CPL_CLOSE_CON_RPL] = do_close_con_rpl,
19337b36b6e0Skxie@chelsio.com 	[CPL_FW4_ACK] = do_fw4_ack,
19347b36b6e0Skxie@chelsio.com 	[CPL_ISCSI_HDR] = do_rx_iscsi_hdr,
193544830d8fSVarun Prakash 	[CPL_ISCSI_DATA] = do_rx_iscsi_data,
19367b36b6e0Skxie@chelsio.com 	[CPL_SET_TCB_RPL] = do_set_tcb_rpl,
19377b36b6e0Skxie@chelsio.com 	[CPL_RX_DATA_DDP] = do_rx_data_ddp,
19383bd3e8bfSKaren Xie 	[CPL_RX_ISCSI_DDP] = do_rx_data_ddp,
193944830d8fSVarun Prakash 	[CPL_RX_ISCSI_CMP] = do_rx_iscsi_cmp,
1940f7bcd2e1SKaren Xie 	[CPL_RX_DATA] = do_rx_data,
19417b36b6e0Skxie@chelsio.com };
19427b36b6e0Skxie@chelsio.com 
19434665bdd5SVarun Prakash static int cxgb4i_ofld_init(struct cxgbi_device *cdev)
19447b36b6e0Skxie@chelsio.com {
19457b36b6e0Skxie@chelsio.com 	int rc;
19467b36b6e0Skxie@chelsio.com 
19477b36b6e0Skxie@chelsio.com 	if (cxgb4i_max_connect > CXGB4I_MAX_CONN)
19487b36b6e0Skxie@chelsio.com 		cxgb4i_max_connect = CXGB4I_MAX_CONN;
19497b36b6e0Skxie@chelsio.com 
19507b36b6e0Skxie@chelsio.com 	rc = cxgbi_device_portmap_create(cdev, cxgb4i_sport_base,
19517b36b6e0Skxie@chelsio.com 					cxgb4i_max_connect);
19527b36b6e0Skxie@chelsio.com 	if (rc < 0)
19537b36b6e0Skxie@chelsio.com 		return rc;
19547b36b6e0Skxie@chelsio.com 
19557b36b6e0Skxie@chelsio.com 	cdev->csk_release_offload_resources = release_offload_resources;
19567b36b6e0Skxie@chelsio.com 	cdev->csk_push_tx_frames = push_tx_frames;
19577b36b6e0Skxie@chelsio.com 	cdev->csk_send_abort_req = send_abort_req;
19587b36b6e0Skxie@chelsio.com 	cdev->csk_send_close_req = send_close_req;
19597b36b6e0Skxie@chelsio.com 	cdev->csk_send_rx_credits = send_rx_credits;
19607b36b6e0Skxie@chelsio.com 	cdev->csk_alloc_cpls = alloc_cpls;
19617b36b6e0Skxie@chelsio.com 	cdev->csk_init_act_open = init_act_open;
19627b36b6e0Skxie@chelsio.com 
19637b36b6e0Skxie@chelsio.com 	pr_info("cdev 0x%p, offload up, added.\n", cdev);
19647b36b6e0Skxie@chelsio.com 	return 0;
19657b36b6e0Skxie@chelsio.com }
19667b36b6e0Skxie@chelsio.com 
196771f7a00bSVarun Prakash static inline void
196871f7a00bSVarun Prakash ulp_mem_io_set_hdr(struct cxgbi_device *cdev,
196971f7a00bSVarun Prakash 		   struct ulp_mem_io *req,
197071f7a00bSVarun Prakash 		   unsigned int wr_len, unsigned int dlen,
197171f7a00bSVarun Prakash 		   unsigned int pm_addr,
197271f7a00bSVarun Prakash 		   int tid)
197371f7a00bSVarun Prakash {
197471f7a00bSVarun Prakash 	struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(cdev);
197571f7a00bSVarun Prakash 	struct ulptx_idata *idata = (struct ulptx_idata *)(req + 1);
197671f7a00bSVarun Prakash 
197771f7a00bSVarun Prakash 	INIT_ULPTX_WR(req, wr_len, 0, tid);
197871f7a00bSVarun Prakash 	req->wr.wr_hi = htonl(FW_WR_OP_V(FW_ULPTX_WR) |
197971f7a00bSVarun Prakash 		FW_WR_ATOMIC_V(0));
198071f7a00bSVarun Prakash 	req->cmd = htonl(ULPTX_CMD_V(ULP_TX_MEM_WRITE) |
198171f7a00bSVarun Prakash 		ULP_MEMIO_ORDER_V(is_t4(lldi->adapter_type)) |
198271f7a00bSVarun Prakash 		T5_ULP_MEMIO_IMM_V(!is_t4(lldi->adapter_type)));
198371f7a00bSVarun Prakash 	req->dlen = htonl(ULP_MEMIO_DATA_LEN_V(dlen >> 5));
198471f7a00bSVarun Prakash 	req->lock_addr = htonl(ULP_MEMIO_ADDR_V(pm_addr >> 5));
198571f7a00bSVarun Prakash 	req->len16 = htonl(DIV_ROUND_UP(wr_len - sizeof(req->wr), 16));
198671f7a00bSVarun Prakash 
198771f7a00bSVarun Prakash 	idata->cmd_more = htonl(ULPTX_CMD_V(ULP_TX_SC_IMM));
198871f7a00bSVarun Prakash 	idata->len = htonl(dlen);
198971f7a00bSVarun Prakash }
199071f7a00bSVarun Prakash 
199171f7a00bSVarun Prakash static struct sk_buff *
199271f7a00bSVarun Prakash ddp_ppod_init_idata(struct cxgbi_device *cdev,
199371f7a00bSVarun Prakash 		    struct cxgbi_ppm *ppm,
199471f7a00bSVarun Prakash 		    unsigned int idx, unsigned int npods,
199571f7a00bSVarun Prakash 		    unsigned int tid)
199671f7a00bSVarun Prakash {
199771f7a00bSVarun Prakash 	unsigned int pm_addr = (idx << PPOD_SIZE_SHIFT) + ppm->llimit;
199871f7a00bSVarun Prakash 	unsigned int dlen = npods << PPOD_SIZE_SHIFT;
199971f7a00bSVarun Prakash 	unsigned int wr_len = roundup(sizeof(struct ulp_mem_io) +
200071f7a00bSVarun Prakash 				sizeof(struct ulptx_idata) + dlen, 16);
200171f7a00bSVarun Prakash 	struct sk_buff *skb = alloc_wr(wr_len, 0, GFP_ATOMIC);
200271f7a00bSVarun Prakash 
200371f7a00bSVarun Prakash 	if (!skb) {
200471f7a00bSVarun Prakash 		pr_err("%s: %s idx %u, npods %u, OOM.\n",
200571f7a00bSVarun Prakash 		       __func__, ppm->ndev->name, idx, npods);
200671f7a00bSVarun Prakash 		return NULL;
200771f7a00bSVarun Prakash 	}
200871f7a00bSVarun Prakash 
200971f7a00bSVarun Prakash 	ulp_mem_io_set_hdr(cdev, (struct ulp_mem_io *)skb->head, wr_len, dlen,
201071f7a00bSVarun Prakash 			   pm_addr, tid);
201171f7a00bSVarun Prakash 
201271f7a00bSVarun Prakash 	return skb;
201371f7a00bSVarun Prakash }
201471f7a00bSVarun Prakash 
201571f7a00bSVarun Prakash static int ddp_ppod_write_idata(struct cxgbi_ppm *ppm, struct cxgbi_sock *csk,
201671f7a00bSVarun Prakash 				struct cxgbi_task_tag_info *ttinfo,
201771f7a00bSVarun Prakash 				unsigned int idx, unsigned int npods,
201871f7a00bSVarun Prakash 				struct scatterlist **sg_pp,
201971f7a00bSVarun Prakash 				unsigned int *sg_off)
202071f7a00bSVarun Prakash {
202171f7a00bSVarun Prakash 	struct cxgbi_device *cdev = csk->cdev;
202271f7a00bSVarun Prakash 	struct sk_buff *skb = ddp_ppod_init_idata(cdev, ppm, idx, npods,
202371f7a00bSVarun Prakash 						  csk->tid);
202471f7a00bSVarun Prakash 	struct ulp_mem_io *req;
202571f7a00bSVarun Prakash 	struct ulptx_idata *idata;
202671f7a00bSVarun Prakash 	struct cxgbi_pagepod *ppod;
202771f7a00bSVarun Prakash 	int i;
202871f7a00bSVarun Prakash 
202971f7a00bSVarun Prakash 	if (!skb)
203071f7a00bSVarun Prakash 		return -ENOMEM;
203171f7a00bSVarun Prakash 
203271f7a00bSVarun Prakash 	req = (struct ulp_mem_io *)skb->head;
203371f7a00bSVarun Prakash 	idata = (struct ulptx_idata *)(req + 1);
203471f7a00bSVarun Prakash 	ppod = (struct cxgbi_pagepod *)(idata + 1);
203571f7a00bSVarun Prakash 
203671f7a00bSVarun Prakash 	for (i = 0; i < npods; i++, ppod++)
203771f7a00bSVarun Prakash 		cxgbi_ddp_set_one_ppod(ppod, ttinfo, sg_pp, sg_off);
203871f7a00bSVarun Prakash 
203971f7a00bSVarun Prakash 	cxgbi_skcb_set_flag(skb, SKCBF_TX_MEM_WRITE);
204071f7a00bSVarun Prakash 	cxgbi_skcb_set_flag(skb, SKCBF_TX_FLAG_COMPL);
204171f7a00bSVarun Prakash 	set_wr_txq(skb, CPL_PRIORITY_DATA, csk->port_id);
204271f7a00bSVarun Prakash 
204371f7a00bSVarun Prakash 	spin_lock_bh(&csk->lock);
204471f7a00bSVarun Prakash 	cxgbi_sock_skb_entail(csk, skb);
204571f7a00bSVarun Prakash 	spin_unlock_bh(&csk->lock);
204671f7a00bSVarun Prakash 
204771f7a00bSVarun Prakash 	return 0;
204871f7a00bSVarun Prakash }
204971f7a00bSVarun Prakash 
205071f7a00bSVarun Prakash static int ddp_set_map(struct cxgbi_ppm *ppm, struct cxgbi_sock *csk,
205171f7a00bSVarun Prakash 		       struct cxgbi_task_tag_info *ttinfo)
205271f7a00bSVarun Prakash {
205371f7a00bSVarun Prakash 	unsigned int pidx = ttinfo->idx;
205471f7a00bSVarun Prakash 	unsigned int npods = ttinfo->npods;
205571f7a00bSVarun Prakash 	unsigned int i, cnt;
205671f7a00bSVarun Prakash 	int err = 0;
205771f7a00bSVarun Prakash 	struct scatterlist *sg = ttinfo->sgl;
205871f7a00bSVarun Prakash 	unsigned int offset = 0;
205971f7a00bSVarun Prakash 
206071f7a00bSVarun Prakash 	ttinfo->cid = csk->port_id;
206171f7a00bSVarun Prakash 
206271f7a00bSVarun Prakash 	for (i = 0; i < npods; i += cnt, pidx += cnt) {
206371f7a00bSVarun Prakash 		cnt = npods - i;
206471f7a00bSVarun Prakash 
206571f7a00bSVarun Prakash 		if (cnt > ULPMEM_IDATA_MAX_NPPODS)
206671f7a00bSVarun Prakash 			cnt = ULPMEM_IDATA_MAX_NPPODS;
206771f7a00bSVarun Prakash 		err = ddp_ppod_write_idata(ppm, csk, ttinfo, pidx, cnt,
206871f7a00bSVarun Prakash 					   &sg, &offset);
206971f7a00bSVarun Prakash 		if (err < 0)
207071f7a00bSVarun Prakash 			break;
207171f7a00bSVarun Prakash 	}
207271f7a00bSVarun Prakash 
207371f7a00bSVarun Prakash 	return err;
207471f7a00bSVarun Prakash }
207571f7a00bSVarun Prakash 
20767b36b6e0Skxie@chelsio.com static int ddp_setup_conn_pgidx(struct cxgbi_sock *csk, unsigned int tid,
20779e8f1c79SVarun Prakash 				int pg_idx)
20787b36b6e0Skxie@chelsio.com {
20797b36b6e0Skxie@chelsio.com 	struct sk_buff *skb;
20807b36b6e0Skxie@chelsio.com 	struct cpl_set_tcb_field *req;
20817b36b6e0Skxie@chelsio.com 
2082e27d6169Skxie@chelsio.com 	if (!pg_idx || pg_idx >= DDP_PGIDX_MAX)
20837b36b6e0Skxie@chelsio.com 		return 0;
20847b36b6e0Skxie@chelsio.com 
208524d3f95aSkxie@chelsio.com 	skb = alloc_wr(sizeof(*req), 0, GFP_KERNEL);
20867b36b6e0Skxie@chelsio.com 	if (!skb)
20877b36b6e0Skxie@chelsio.com 		return -ENOMEM;
20887b36b6e0Skxie@chelsio.com 
2089e27d6169Skxie@chelsio.com 	/*  set up ulp page size */
20907b36b6e0Skxie@chelsio.com 	req = (struct cpl_set_tcb_field *)skb->head;
20917b36b6e0Skxie@chelsio.com 	INIT_TP_WR(req, csk->tid);
20927b36b6e0Skxie@chelsio.com 	OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_SET_TCB_FIELD, csk->tid));
20939e8f1c79SVarun Prakash 	req->reply_ctrl = htons(NO_REPLY_V(0) | QUEUENO_V(csk->rss_qid));
2094e27d6169Skxie@chelsio.com 	req->word_cookie = htons(0);
2095e27d6169Skxie@chelsio.com 	req->mask = cpu_to_be64(0x3 << 8);
2096e27d6169Skxie@chelsio.com 	req->val = cpu_to_be64(pg_idx << 8);
20977b36b6e0Skxie@chelsio.com 	set_wr_txq(skb, CPL_PRIORITY_CONTROL, csk->port_id);
20987b36b6e0Skxie@chelsio.com 
20997b36b6e0Skxie@chelsio.com 	log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
21007b36b6e0Skxie@chelsio.com 		"csk 0x%p, tid 0x%x, pg_idx %u.\n", csk, csk->tid, pg_idx);
21017b36b6e0Skxie@chelsio.com 
21029e8f1c79SVarun Prakash 	reinit_completion(&csk->cmpl);
21037b36b6e0Skxie@chelsio.com 	cxgb4_ofld_send(csk->cdev->ports[csk->port_id], skb);
21049e8f1c79SVarun Prakash 	wait_for_completion(&csk->cmpl);
21059e8f1c79SVarun Prakash 
21069e8f1c79SVarun Prakash 	return csk->err;
21077b36b6e0Skxie@chelsio.com }
21087b36b6e0Skxie@chelsio.com 
21097b36b6e0Skxie@chelsio.com static int ddp_setup_conn_digest(struct cxgbi_sock *csk, unsigned int tid,
21109e8f1c79SVarun Prakash 				 int hcrc, int dcrc)
21117b36b6e0Skxie@chelsio.com {
21127b36b6e0Skxie@chelsio.com 	struct sk_buff *skb;
21137b36b6e0Skxie@chelsio.com 	struct cpl_set_tcb_field *req;
21147b36b6e0Skxie@chelsio.com 
2115e27d6169Skxie@chelsio.com 	if (!hcrc && !dcrc)
2116e27d6169Skxie@chelsio.com 		return 0;
21177b36b6e0Skxie@chelsio.com 
211824d3f95aSkxie@chelsio.com 	skb = alloc_wr(sizeof(*req), 0, GFP_KERNEL);
21197b36b6e0Skxie@chelsio.com 	if (!skb)
21207b36b6e0Skxie@chelsio.com 		return -ENOMEM;
21217b36b6e0Skxie@chelsio.com 
21227b36b6e0Skxie@chelsio.com 	csk->hcrc_len = (hcrc ? 4 : 0);
21237b36b6e0Skxie@chelsio.com 	csk->dcrc_len = (dcrc ? 4 : 0);
2124e27d6169Skxie@chelsio.com 	/*  set up ulp submode */
21257b36b6e0Skxie@chelsio.com 	req = (struct cpl_set_tcb_field *)skb->head;
21267b36b6e0Skxie@chelsio.com 	INIT_TP_WR(req, tid);
21277b36b6e0Skxie@chelsio.com 	OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_SET_TCB_FIELD, tid));
21289e8f1c79SVarun Prakash 	req->reply_ctrl = htons(NO_REPLY_V(0) | QUEUENO_V(csk->rss_qid));
2129e27d6169Skxie@chelsio.com 	req->word_cookie = htons(0);
2130e27d6169Skxie@chelsio.com 	req->mask = cpu_to_be64(0x3 << 4);
2131e27d6169Skxie@chelsio.com 	req->val = cpu_to_be64(((hcrc ? ULP_CRC_HEADER : 0) |
2132e27d6169Skxie@chelsio.com 				(dcrc ? ULP_CRC_DATA : 0)) << 4);
21337b36b6e0Skxie@chelsio.com 	set_wr_txq(skb, CPL_PRIORITY_CONTROL, csk->port_id);
21347b36b6e0Skxie@chelsio.com 
21357b36b6e0Skxie@chelsio.com 	log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
21367b36b6e0Skxie@chelsio.com 		"csk 0x%p, tid 0x%x, crc %d,%d.\n", csk, csk->tid, hcrc, dcrc);
21377b36b6e0Skxie@chelsio.com 
21389e8f1c79SVarun Prakash 	reinit_completion(&csk->cmpl);
21397b36b6e0Skxie@chelsio.com 	cxgb4_ofld_send(csk->cdev->ports[csk->port_id], skb);
21409e8f1c79SVarun Prakash 	wait_for_completion(&csk->cmpl);
21419e8f1c79SVarun Prakash 
21429e8f1c79SVarun Prakash 	return csk->err;
21437b36b6e0Skxie@chelsio.com }
21447b36b6e0Skxie@chelsio.com 
214571f7a00bSVarun Prakash static struct cxgbi_ppm *cdev2ppm(struct cxgbi_device *cdev)
214671f7a00bSVarun Prakash {
214771f7a00bSVarun Prakash 	return (struct cxgbi_ppm *)(*((struct cxgb4_lld_info *)
214871f7a00bSVarun Prakash 				       (cxgbi_cdev_priv(cdev)))->iscsi_ppm);
214971f7a00bSVarun Prakash }
215071f7a00bSVarun Prakash 
21517b36b6e0Skxie@chelsio.com static int cxgb4i_ddp_init(struct cxgbi_device *cdev)
21527b36b6e0Skxie@chelsio.com {
215371f7a00bSVarun Prakash 	struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(cdev);
215471f7a00bSVarun Prakash 	struct net_device *ndev = cdev->ports[0];
215571f7a00bSVarun Prakash 	struct cxgbi_tag_format tformat;
2156a248384eSVarun Prakash 	int i, err;
215771f7a00bSVarun Prakash 
215871f7a00bSVarun Prakash 	if (!lldi->vr->iscsi.size) {
215971f7a00bSVarun Prakash 		pr_warn("%s, iscsi NOT enabled, check config!\n", ndev->name);
216071f7a00bSVarun Prakash 		return -EACCES;
216171f7a00bSVarun Prakash 	}
216271f7a00bSVarun Prakash 
216371f7a00bSVarun Prakash 	cdev->flags |= CXGBI_FLAG_USE_PPOD_OFLDQ;
216471f7a00bSVarun Prakash 
216571f7a00bSVarun Prakash 	memset(&tformat, 0, sizeof(struct cxgbi_tag_format));
216671f7a00bSVarun Prakash 	for (i = 0; i < 4; i++)
216771f7a00bSVarun Prakash 		tformat.pgsz_order[i] = (lldi->iscsi_pgsz_order >> (i << 3))
216871f7a00bSVarun Prakash 					 & 0xF;
216971f7a00bSVarun Prakash 	cxgbi_tagmask_check(lldi->iscsi_tagmask, &tformat);
217071f7a00bSVarun Prakash 
2171a248384eSVarun Prakash 	pr_info("iscsi_edram.start 0x%x iscsi_edram.size 0x%x",
2172a248384eSVarun Prakash 		lldi->vr->ppod_edram.start, lldi->vr->ppod_edram.size);
2173a248384eSVarun Prakash 
2174a248384eSVarun Prakash 	err = cxgbi_ddp_ppm_setup(lldi->iscsi_ppm, cdev, &tformat,
2175a248384eSVarun Prakash 				  lldi->vr->iscsi.size, lldi->iscsi_llimit,
2176a248384eSVarun Prakash 				  lldi->vr->iscsi.start, 2,
2177a248384eSVarun Prakash 				  lldi->vr->ppod_edram.start,
2178a248384eSVarun Prakash 				  lldi->vr->ppod_edram.size);
2179a248384eSVarun Prakash 
2180a248384eSVarun Prakash 	if (err < 0)
2181a248384eSVarun Prakash 		return err;
218271f7a00bSVarun Prakash 
21837b36b6e0Skxie@chelsio.com 	cdev->csk_ddp_setup_digest = ddp_setup_conn_digest;
21847b36b6e0Skxie@chelsio.com 	cdev->csk_ddp_setup_pgidx = ddp_setup_conn_pgidx;
218571f7a00bSVarun Prakash 	cdev->csk_ddp_set_map = ddp_set_map;
218671f7a00bSVarun Prakash 	cdev->tx_max_size = min_t(unsigned int, ULP2_MAX_PDU_PAYLOAD,
218771f7a00bSVarun Prakash 				  lldi->iscsi_iolen - ISCSI_PDU_NONPAYLOAD_LEN);
218871f7a00bSVarun Prakash 	cdev->rx_max_size = min_t(unsigned int, ULP2_MAX_PDU_PAYLOAD,
218971f7a00bSVarun Prakash 				  lldi->iscsi_iolen - ISCSI_PDU_NONPAYLOAD_LEN);
219071f7a00bSVarun Prakash 	cdev->cdev2ppm = cdev2ppm;
219171f7a00bSVarun Prakash 
21927b36b6e0Skxie@chelsio.com 	return 0;
21937b36b6e0Skxie@chelsio.com }
21947b36b6e0Skxie@chelsio.com 
2195e33c2482SVarun Prakash static bool is_memfree(struct adapter *adap)
2196e33c2482SVarun Prakash {
2197e33c2482SVarun Prakash 	u32 io;
2198e33c2482SVarun Prakash 
2199e33c2482SVarun Prakash 	io = t4_read_reg(adap, MA_TARGET_MEM_ENABLE_A);
2200e33c2482SVarun Prakash 	if (is_t5(adap->params.chip)) {
2201e33c2482SVarun Prakash 		if ((io & EXT_MEM0_ENABLE_F) || (io & EXT_MEM1_ENABLE_F))
2202e33c2482SVarun Prakash 			return false;
2203e33c2482SVarun Prakash 	} else if (io & EXT_MEM_ENABLE_F) {
2204e33c2482SVarun Prakash 		return false;
2205e33c2482SVarun Prakash 	}
2206e33c2482SVarun Prakash 
2207e33c2482SVarun Prakash 	return true;
2208e33c2482SVarun Prakash }
2209e33c2482SVarun Prakash 
22107b36b6e0Skxie@chelsio.com static void *t4_uld_add(const struct cxgb4_lld_info *lldi)
22117b36b6e0Skxie@chelsio.com {
22127b36b6e0Skxie@chelsio.com 	struct cxgbi_device *cdev;
22137b36b6e0Skxie@chelsio.com 	struct port_info *pi;
2214e33c2482SVarun Prakash 	struct net_device *ndev;
2215e33c2482SVarun Prakash 	struct adapter *adap;
2216e33c2482SVarun Prakash 	struct tid_info *t;
2217e33c2482SVarun Prakash 	u32 max_cmds = CXGB4I_SCSI_HOST_QDEPTH;
2218e33c2482SVarun Prakash 	u32 max_conn = CXGBI_MAX_CONN;
22197b36b6e0Skxie@chelsio.com 	int i, rc;
22207b36b6e0Skxie@chelsio.com 
22217b36b6e0Skxie@chelsio.com 	cdev = cxgbi_device_register(sizeof(*lldi), lldi->nports);
22227b36b6e0Skxie@chelsio.com 	if (!cdev) {
22237b36b6e0Skxie@chelsio.com 		pr_info("t4 device 0x%p, register failed.\n", lldi);
22247b36b6e0Skxie@chelsio.com 		return NULL;
22257b36b6e0Skxie@chelsio.com 	}
22267b36b6e0Skxie@chelsio.com 	pr_info("0x%p,0x%x, ports %u,%s, chan %u, q %u,%u, wr %u.\n",
22277b36b6e0Skxie@chelsio.com 		cdev, lldi->adapter_type, lldi->nports,
22287b36b6e0Skxie@chelsio.com 		lldi->ports[0]->name, lldi->nchan, lldi->ntxq,
22297b36b6e0Skxie@chelsio.com 		lldi->nrxq, lldi->wr_cred);
22307b36b6e0Skxie@chelsio.com 	for (i = 0; i < lldi->nrxq; i++)
22317b36b6e0Skxie@chelsio.com 		log_debug(1 << CXGBI_DBG_DEV,
22327b36b6e0Skxie@chelsio.com 			"t4 0x%p, rxq id #%d: %u.\n",
22337b36b6e0Skxie@chelsio.com 			cdev, i, lldi->rxq_ids[i]);
22347b36b6e0Skxie@chelsio.com 
22357b36b6e0Skxie@chelsio.com 	memcpy(cxgbi_cdev_priv(cdev), lldi, sizeof(*lldi));
22367b36b6e0Skxie@chelsio.com 	cdev->flags = CXGBI_FLAG_DEV_T4;
22377b36b6e0Skxie@chelsio.com 	cdev->pdev = lldi->pdev;
22387b36b6e0Skxie@chelsio.com 	cdev->ports = lldi->ports;
22397b36b6e0Skxie@chelsio.com 	cdev->nports = lldi->nports;
22407b36b6e0Skxie@chelsio.com 	cdev->mtus = lldi->mtus;
22417b36b6e0Skxie@chelsio.com 	cdev->nmtus = NMTUS;
2242586be7cbSVarun Prakash 	cdev->rx_credit_thres = (CHELSIO_CHIP_VERSION(lldi->adapter_type) <=
2243586be7cbSVarun Prakash 				 CHELSIO_T5) ? cxgb4i_rx_credit_thres : 0;
22447b36b6e0Skxie@chelsio.com 	cdev->skb_tx_rsvd = CXGB4I_TX_HEADER_LEN;
22457b36b6e0Skxie@chelsio.com 	cdev->skb_rx_extra = sizeof(struct cpl_iscsi_hdr);
22467b36b6e0Skxie@chelsio.com 	cdev->itp = &cxgb4i_iscsi_transport;
22471fe1fdb0SVarun Prakash 	cdev->owner = THIS_MODULE;
22487b36b6e0Skxie@chelsio.com 
2249b184487cSVarun Prakash 	cdev->pfvf = FW_PFVF_CMD_PFN_V(lldi->pf);
2250e27d6169Skxie@chelsio.com 	pr_info("cdev 0x%p,%s, pfvf %u.\n",
2251e27d6169Skxie@chelsio.com 		cdev, lldi->ports[0]->name, cdev->pfvf);
2252e27d6169Skxie@chelsio.com 
22537b36b6e0Skxie@chelsio.com 	rc = cxgb4i_ddp_init(cdev);
22547b36b6e0Skxie@chelsio.com 	if (rc) {
2255a248384eSVarun Prakash 		pr_info("t4 0x%p ddp init failed %d.\n", cdev, rc);
22567b36b6e0Skxie@chelsio.com 		goto err_out;
22577b36b6e0Skxie@chelsio.com 	}
2258e33c2482SVarun Prakash 
2259e33c2482SVarun Prakash 	ndev = cdev->ports[0];
2260e33c2482SVarun Prakash 	adap = netdev2adap(ndev);
2261e33c2482SVarun Prakash 	if (adap) {
2262e33c2482SVarun Prakash 		t = &adap->tids;
2263e33c2482SVarun Prakash 		if (t->ntids <= CXGBI_MAX_CONN)
2264e33c2482SVarun Prakash 			max_conn = t->ntids;
2265e33c2482SVarun Prakash 
2266e33c2482SVarun Prakash 		if (is_memfree(adap)) {
2267e33c2482SVarun Prakash 			cdev->flags |=	CXGBI_FLAG_DEV_ISO_OFF;
2268e33c2482SVarun Prakash 			max_cmds = CXGB4I_SCSI_HOST_QDEPTH >> 2;
2269e33c2482SVarun Prakash 
2270e33c2482SVarun Prakash 			pr_info("%s: 0x%p, tid %u, SO adapter.\n",
2271e33c2482SVarun Prakash 				ndev->name, cdev, t->ntids);
2272e33c2482SVarun Prakash 		}
2273e33c2482SVarun Prakash 	} else {
2274e33c2482SVarun Prakash 		pr_info("%s, 0x%p, NO adapter struct.\n", ndev->name, cdev);
2275e33c2482SVarun Prakash 	}
2276e33c2482SVarun Prakash 
2277e33c2482SVarun Prakash 	/* ISO is enabled in T5/T6 firmware version >= 1.13.43.0 */
2278e33c2482SVarun Prakash 	if (!is_t4(lldi->adapter_type) &&
2279e33c2482SVarun Prakash 	    (lldi->fw_vers >= 0x10d2b00) &&
2280e33c2482SVarun Prakash 	    !(cdev->flags & CXGBI_FLAG_DEV_ISO_OFF))
2281e33c2482SVarun Prakash 		cdev->skb_iso_txhdr = sizeof(struct cpl_tx_data_iso);
2282e33c2482SVarun Prakash 
22837b36b6e0Skxie@chelsio.com 	rc = cxgb4i_ofld_init(cdev);
22847b36b6e0Skxie@chelsio.com 	if (rc) {
22857b36b6e0Skxie@chelsio.com 		pr_info("t4 0x%p ofld init failed.\n", cdev);
22867b36b6e0Skxie@chelsio.com 		goto err_out;
22877b36b6e0Skxie@chelsio.com 	}
22887b36b6e0Skxie@chelsio.com 
2289e33c2482SVarun Prakash 	cxgb4i_host_template.can_queue = max_cmds;
2290e33c2482SVarun Prakash 	rc = cxgbi_hbas_add(cdev, CXGB4I_MAX_LUN, max_conn,
22917b36b6e0Skxie@chelsio.com 			    &cxgb4i_host_template, cxgb4i_stt);
22927b36b6e0Skxie@chelsio.com 	if (rc)
22937b36b6e0Skxie@chelsio.com 		goto err_out;
22947b36b6e0Skxie@chelsio.com 
22957b36b6e0Skxie@chelsio.com 	for (i = 0; i < cdev->nports; i++) {
22967b36b6e0Skxie@chelsio.com 		pi = netdev_priv(lldi->ports[i]);
22977b36b6e0Skxie@chelsio.com 		cdev->hbas[i]->port_id = pi->port_id;
22987b36b6e0Skxie@chelsio.com 	}
22997b36b6e0Skxie@chelsio.com 	return cdev;
23007b36b6e0Skxie@chelsio.com 
23017b36b6e0Skxie@chelsio.com err_out:
23027b36b6e0Skxie@chelsio.com 	cxgbi_device_unregister(cdev);
23037b36b6e0Skxie@chelsio.com 	return ERR_PTR(-ENOMEM);
23047b36b6e0Skxie@chelsio.com }
23057b36b6e0Skxie@chelsio.com 
23067b36b6e0Skxie@chelsio.com #define RX_PULL_LEN	128
23077b36b6e0Skxie@chelsio.com static int t4_uld_rx_handler(void *handle, const __be64 *rsp,
23087b36b6e0Skxie@chelsio.com 				const struct pkt_gl *pgl)
23097b36b6e0Skxie@chelsio.com {
23107b36b6e0Skxie@chelsio.com 	const struct cpl_act_establish *rpl;
23117b36b6e0Skxie@chelsio.com 	struct sk_buff *skb;
23127b36b6e0Skxie@chelsio.com 	unsigned int opc;
23137b36b6e0Skxie@chelsio.com 	struct cxgbi_device *cdev = handle;
23147b36b6e0Skxie@chelsio.com 
23157b36b6e0Skxie@chelsio.com 	if (pgl == NULL) {
23167b36b6e0Skxie@chelsio.com 		unsigned int len = 64 - sizeof(struct rsp_ctrl) - 8;
23177b36b6e0Skxie@chelsio.com 
231824d3f95aSkxie@chelsio.com 		skb = alloc_wr(len, 0, GFP_ATOMIC);
23197b36b6e0Skxie@chelsio.com 		if (!skb)
23207b36b6e0Skxie@chelsio.com 			goto nomem;
23217b36b6e0Skxie@chelsio.com 		skb_copy_to_linear_data(skb, &rsp[1], len);
23227b36b6e0Skxie@chelsio.com 	} else {
23237b36b6e0Skxie@chelsio.com 		if (unlikely(*(u8 *)rsp != *(u8 *)pgl->va)) {
23247b36b6e0Skxie@chelsio.com 			pr_info("? FL 0x%p,RSS%#llx,FL %#llx,len %u.\n",
23257b36b6e0Skxie@chelsio.com 				pgl->va, be64_to_cpu(*rsp),
23267b36b6e0Skxie@chelsio.com 				be64_to_cpu(*(u64 *)pgl->va),
23277b36b6e0Skxie@chelsio.com 				pgl->tot_len);
23287b36b6e0Skxie@chelsio.com 			return 0;
23297b36b6e0Skxie@chelsio.com 		}
23307b36b6e0Skxie@chelsio.com 		skb = cxgb4_pktgl_to_skb(pgl, RX_PULL_LEN, RX_PULL_LEN);
23317b36b6e0Skxie@chelsio.com 		if (unlikely(!skb))
23327b36b6e0Skxie@chelsio.com 			goto nomem;
23337b36b6e0Skxie@chelsio.com 	}
23347b36b6e0Skxie@chelsio.com 
23357b36b6e0Skxie@chelsio.com 	rpl = (struct cpl_act_establish *)skb->data;
23367b36b6e0Skxie@chelsio.com 	opc = rpl->ot.opcode;
23377b36b6e0Skxie@chelsio.com 	log_debug(1 << CXGBI_DBG_TOE,
23387b36b6e0Skxie@chelsio.com 		"cdev %p, opcode 0x%x(0x%x,0x%x), skb %p.\n",
23397b36b6e0Skxie@chelsio.com 		 cdev, opc, rpl->ot.opcode_tid, ntohl(rpl->ot.opcode_tid), skb);
2340ccc495efSDan Carpenter 	if (opc >= ARRAY_SIZE(cxgb4i_cplhandlers) || !cxgb4i_cplhandlers[opc]) {
23417b36b6e0Skxie@chelsio.com 		pr_err("No handler for opcode 0x%x.\n", opc);
23427b36b6e0Skxie@chelsio.com 		__kfree_skb(skb);
2343ccc495efSDan Carpenter 	} else
2344ccc495efSDan Carpenter 		cxgb4i_cplhandlers[opc](cdev, skb);
2345ccc495efSDan Carpenter 
23467b36b6e0Skxie@chelsio.com 	return 0;
23477b36b6e0Skxie@chelsio.com nomem:
23487b36b6e0Skxie@chelsio.com 	log_debug(1 << CXGBI_DBG_TOE, "OOM bailing out.\n");
23497b36b6e0Skxie@chelsio.com 	return 1;
23507b36b6e0Skxie@chelsio.com }
23517b36b6e0Skxie@chelsio.com 
23527b36b6e0Skxie@chelsio.com static int t4_uld_state_change(void *handle, enum cxgb4_state state)
23537b36b6e0Skxie@chelsio.com {
23547b36b6e0Skxie@chelsio.com 	struct cxgbi_device *cdev = handle;
23557b36b6e0Skxie@chelsio.com 
23567b36b6e0Skxie@chelsio.com 	switch (state) {
23577b36b6e0Skxie@chelsio.com 	case CXGB4_STATE_UP:
23587b36b6e0Skxie@chelsio.com 		pr_info("cdev 0x%p, UP.\n", cdev);
23597b36b6e0Skxie@chelsio.com 		break;
23607b36b6e0Skxie@chelsio.com 	case CXGB4_STATE_START_RECOVERY:
23617b36b6e0Skxie@chelsio.com 		pr_info("cdev 0x%p, RECOVERY.\n", cdev);
23627b36b6e0Skxie@chelsio.com 		/* close all connections */
23637b36b6e0Skxie@chelsio.com 		break;
23647b36b6e0Skxie@chelsio.com 	case CXGB4_STATE_DOWN:
23657b36b6e0Skxie@chelsio.com 		pr_info("cdev 0x%p, DOWN.\n", cdev);
23667b36b6e0Skxie@chelsio.com 		break;
23677b36b6e0Skxie@chelsio.com 	case CXGB4_STATE_DETACH:
23687b36b6e0Skxie@chelsio.com 		pr_info("cdev 0x%p, DETACH.\n", cdev);
2369c3b331a3SThadeu Lima de Souza Cascardo 		cxgbi_device_unregister(cdev);
23707b36b6e0Skxie@chelsio.com 		break;
23717b36b6e0Skxie@chelsio.com 	default:
23727b36b6e0Skxie@chelsio.com 		pr_info("cdev 0x%p, unknown state %d.\n", cdev, state);
23737b36b6e0Skxie@chelsio.com 		break;
23747b36b6e0Skxie@chelsio.com 	}
23757b36b6e0Skxie@chelsio.com 	return 0;
23767b36b6e0Skxie@chelsio.com }
23777b36b6e0Skxie@chelsio.com 
2378b5a5fe4eSVarun Prakash #ifdef CONFIG_CHELSIO_T4_DCB
2379b5a5fe4eSVarun Prakash static int
2380b5a5fe4eSVarun Prakash cxgb4_dcb_change_notify(struct notifier_block *self, unsigned long val,
2381b5a5fe4eSVarun Prakash 			void *data)
2382b5a5fe4eSVarun Prakash {
2383b5a5fe4eSVarun Prakash 	int i, port = 0xFF;
2384b5a5fe4eSVarun Prakash 	struct net_device *ndev;
2385b5a5fe4eSVarun Prakash 	struct cxgbi_device *cdev = NULL;
2386b5a5fe4eSVarun Prakash 	struct dcb_app_type *iscsi_app = data;
2387b5a5fe4eSVarun Prakash 	struct cxgbi_ports_map *pmap;
2388b5a5fe4eSVarun Prakash 	u8 priority;
2389b5a5fe4eSVarun Prakash 
2390b5a5fe4eSVarun Prakash 	if (iscsi_app->dcbx & DCB_CAP_DCBX_VER_IEEE) {
2391152e30fcSVarun Prakash 		if ((iscsi_app->app.selector != IEEE_8021QAZ_APP_SEL_STREAM) &&
2392152e30fcSVarun Prakash 		    (iscsi_app->app.selector != IEEE_8021QAZ_APP_SEL_ANY))
2393b5a5fe4eSVarun Prakash 			return NOTIFY_DONE;
2394b5a5fe4eSVarun Prakash 
2395b5a5fe4eSVarun Prakash 		priority = iscsi_app->app.priority;
2396b5a5fe4eSVarun Prakash 	} else if (iscsi_app->dcbx & DCB_CAP_DCBX_VER_CEE) {
2397b5a5fe4eSVarun Prakash 		if (iscsi_app->app.selector != DCB_APP_IDTYPE_PORTNUM)
2398b5a5fe4eSVarun Prakash 			return NOTIFY_DONE;
2399b5a5fe4eSVarun Prakash 
2400b5a5fe4eSVarun Prakash 		if (!iscsi_app->app.priority)
2401b5a5fe4eSVarun Prakash 			return NOTIFY_DONE;
2402b5a5fe4eSVarun Prakash 
2403b5a5fe4eSVarun Prakash 		priority = ffs(iscsi_app->app.priority) - 1;
2404b5a5fe4eSVarun Prakash 	} else {
2405b5a5fe4eSVarun Prakash 		return NOTIFY_DONE;
2406b5a5fe4eSVarun Prakash 	}
2407b5a5fe4eSVarun Prakash 
2408b5a5fe4eSVarun Prakash 	if (iscsi_app->app.protocol != 3260)
2409b5a5fe4eSVarun Prakash 		return NOTIFY_DONE;
2410b5a5fe4eSVarun Prakash 
2411b5a5fe4eSVarun Prakash 	log_debug(1 << CXGBI_DBG_ISCSI, "iSCSI priority for ifid %d is %u\n",
2412b5a5fe4eSVarun Prakash 		  iscsi_app->ifindex, priority);
2413b5a5fe4eSVarun Prakash 
2414b5a5fe4eSVarun Prakash 	ndev = dev_get_by_index(&init_net, iscsi_app->ifindex);
2415b5a5fe4eSVarun Prakash 	if (!ndev)
2416b5a5fe4eSVarun Prakash 		return NOTIFY_DONE;
2417b5a5fe4eSVarun Prakash 
2418b5a5fe4eSVarun Prakash 	cdev = cxgbi_device_find_by_netdev_rcu(ndev, &port);
2419b5a5fe4eSVarun Prakash 
2420b5a5fe4eSVarun Prakash 	dev_put(ndev);
2421b5a5fe4eSVarun Prakash 	if (!cdev)
2422b5a5fe4eSVarun Prakash 		return NOTIFY_DONE;
2423b5a5fe4eSVarun Prakash 
2424b5a5fe4eSVarun Prakash 	pmap = &cdev->pmap;
2425b5a5fe4eSVarun Prakash 
2426b5a5fe4eSVarun Prakash 	for (i = 0; i < pmap->used; i++) {
2427b5a5fe4eSVarun Prakash 		if (pmap->port_csk[i]) {
2428b5a5fe4eSVarun Prakash 			struct cxgbi_sock *csk = pmap->port_csk[i];
2429b5a5fe4eSVarun Prakash 
2430b5a5fe4eSVarun Prakash 			if (csk->dcb_priority != priority) {
2431b5a5fe4eSVarun Prakash 				iscsi_conn_failure(csk->user_data,
2432b5a5fe4eSVarun Prakash 						   ISCSI_ERR_CONN_FAILED);
2433b5a5fe4eSVarun Prakash 				pr_info("Restarting iSCSI connection %p with "
2434b5a5fe4eSVarun Prakash 					"priority %u->%u.\n", csk,
2435b5a5fe4eSVarun Prakash 					csk->dcb_priority, priority);
2436b5a5fe4eSVarun Prakash 			}
2437b5a5fe4eSVarun Prakash 		}
2438b5a5fe4eSVarun Prakash 	}
2439b5a5fe4eSVarun Prakash 	return NOTIFY_OK;
2440b5a5fe4eSVarun Prakash }
2441b5a5fe4eSVarun Prakash #endif
2442b5a5fe4eSVarun Prakash 
24437b36b6e0Skxie@chelsio.com static int __init cxgb4i_init_module(void)
24447b36b6e0Skxie@chelsio.com {
24457b36b6e0Skxie@chelsio.com 	int rc;
24467b36b6e0Skxie@chelsio.com 
24477b36b6e0Skxie@chelsio.com 	printk(KERN_INFO "%s", version);
24487b36b6e0Skxie@chelsio.com 
24497b36b6e0Skxie@chelsio.com 	rc = cxgbi_iscsi_init(&cxgb4i_iscsi_transport, &cxgb4i_stt);
24507b36b6e0Skxie@chelsio.com 	if (rc < 0)
24517b36b6e0Skxie@chelsio.com 		return rc;
24527b36b6e0Skxie@chelsio.com 	cxgb4_register_uld(CXGB4_ULD_ISCSI, &cxgb4i_uld_info);
2453759a0cc5SAnish Bhatt 
2454b5a5fe4eSVarun Prakash #ifdef CONFIG_CHELSIO_T4_DCB
2455b5a5fe4eSVarun Prakash 	pr_info("%s dcb enabled.\n", DRV_MODULE_NAME);
2456b5a5fe4eSVarun Prakash 	register_dcbevent_notifier(&cxgb4_dcb_change);
2457b5a5fe4eSVarun Prakash #endif
24587b36b6e0Skxie@chelsio.com 	return 0;
24597b36b6e0Skxie@chelsio.com }
24607b36b6e0Skxie@chelsio.com 
24617b36b6e0Skxie@chelsio.com static void __exit cxgb4i_exit_module(void)
24627b36b6e0Skxie@chelsio.com {
2463b5a5fe4eSVarun Prakash #ifdef CONFIG_CHELSIO_T4_DCB
2464b5a5fe4eSVarun Prakash 	unregister_dcbevent_notifier(&cxgb4_dcb_change);
2465b5a5fe4eSVarun Prakash #endif
24667b36b6e0Skxie@chelsio.com 	cxgb4_unregister_uld(CXGB4_ULD_ISCSI);
24677b36b6e0Skxie@chelsio.com 	cxgbi_device_unregister_all(CXGBI_FLAG_DEV_T4);
24687b36b6e0Skxie@chelsio.com 	cxgbi_iscsi_cleanup(&cxgb4i_iscsi_transport, &cxgb4i_stt);
24697b36b6e0Skxie@chelsio.com }
24707b36b6e0Skxie@chelsio.com 
24717b36b6e0Skxie@chelsio.com module_init(cxgb4i_init_module);
24727b36b6e0Skxie@chelsio.com module_exit(cxgb4i_exit_module);
2473