xref: /openbmc/linux/drivers/scsi/cxgbi/cxgb4i/cxgb4i.c (revision e33c2482)
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,
1377b36b6e0Skxie@chelsio.com 	.destroy_conn	= iscsi_tcp_conn_teardown,
1387b36b6e0Skxie@chelsio.com 	.start_conn		= iscsi_conn_start,
1397b36b6e0Skxie@chelsio.com 	.stop_conn		= iscsi_conn_stop,
140c71b9b66SMike Christie 	.get_conn_param	= iscsi_conn_get_param,
1417b36b6e0Skxie@chelsio.com 	.set_param	= cxgbi_set_conn_param,
1427b36b6e0Skxie@chelsio.com 	.get_stats	= cxgbi_get_conn_stats,
1437b36b6e0Skxie@chelsio.com 	/* pdu xmit req from user space */
1447b36b6e0Skxie@chelsio.com 	.send_pdu	= iscsi_conn_send_pdu,
1457b36b6e0Skxie@chelsio.com 	/* task */
1467b36b6e0Skxie@chelsio.com 	.init_task	= iscsi_tcp_task_init,
1477b36b6e0Skxie@chelsio.com 	.xmit_task	= iscsi_tcp_task_xmit,
1487b36b6e0Skxie@chelsio.com 	.cleanup_task	= cxgbi_cleanup_task,
1497b36b6e0Skxie@chelsio.com 	/* pdu */
1507b36b6e0Skxie@chelsio.com 	.alloc_pdu	= cxgbi_conn_alloc_pdu,
1517b36b6e0Skxie@chelsio.com 	.init_pdu	= cxgbi_conn_init_pdu,
1527b36b6e0Skxie@chelsio.com 	.xmit_pdu	= cxgbi_conn_xmit_pdu,
1537b36b6e0Skxie@chelsio.com 	.parse_pdu_itt	= cxgbi_parse_pdu_itt,
1547b36b6e0Skxie@chelsio.com 	/* TCP connect/disconnect */
155c71b9b66SMike Christie 	.get_ep_param	= cxgbi_get_ep_param,
1567b36b6e0Skxie@chelsio.com 	.ep_connect	= cxgbi_ep_connect,
1577b36b6e0Skxie@chelsio.com 	.ep_poll	= cxgbi_ep_poll,
1587b36b6e0Skxie@chelsio.com 	.ep_disconnect	= cxgbi_ep_disconnect,
1597b36b6e0Skxie@chelsio.com 	/* Error recovery timeout call */
1607b36b6e0Skxie@chelsio.com 	.session_recovery_timedout = iscsi_session_recovery_timedout,
1617b36b6e0Skxie@chelsio.com };
1627b36b6e0Skxie@chelsio.com 
163b5a5fe4eSVarun Prakash #ifdef CONFIG_CHELSIO_T4_DCB
164b5a5fe4eSVarun Prakash static int
165b5a5fe4eSVarun Prakash cxgb4_dcb_change_notify(struct notifier_block *, unsigned long, void *);
166b5a5fe4eSVarun Prakash 
167b5a5fe4eSVarun Prakash static struct notifier_block cxgb4_dcb_change = {
168b5a5fe4eSVarun Prakash 	.notifier_call = cxgb4_dcb_change_notify,
169b5a5fe4eSVarun Prakash };
170b5a5fe4eSVarun Prakash #endif
171b5a5fe4eSVarun Prakash 
1727b36b6e0Skxie@chelsio.com static struct scsi_transport_template *cxgb4i_stt;
1737b36b6e0Skxie@chelsio.com 
1747b36b6e0Skxie@chelsio.com /*
1757b36b6e0Skxie@chelsio.com  * CPL (Chelsio Protocol Language) defines a message passing interface between
1767b36b6e0Skxie@chelsio.com  * the host driver and Chelsio asic.
1777b36b6e0Skxie@chelsio.com  * The section below implments CPLs that related to iscsi tcp connection
1787b36b6e0Skxie@chelsio.com  * open/close/abort and data send/receive.
1797b36b6e0Skxie@chelsio.com  */
180759a0cc5SAnish Bhatt 
1817b36b6e0Skxie@chelsio.com #define RCV_BUFSIZ_MASK		0x3FFU
182d3074cceSKaren Xie #define MAX_IMM_TX_PKT_LEN	256
1837b36b6e0Skxie@chelsio.com 
1847b36b6e0Skxie@chelsio.com static int push_tx_frames(struct cxgbi_sock *, int);
1857b36b6e0Skxie@chelsio.com 
1867b36b6e0Skxie@chelsio.com /*
1877b36b6e0Skxie@chelsio.com  * is_ofld_imm - check whether a packet can be sent as immediate data
1887b36b6e0Skxie@chelsio.com  * @skb: the packet
1897b36b6e0Skxie@chelsio.com  *
1907b36b6e0Skxie@chelsio.com  * Returns true if a packet can be sent as an offload WR with immediate
1917b36b6e0Skxie@chelsio.com  * data.  We currently use the same limit as for Ethernet packets.
1927b36b6e0Skxie@chelsio.com  */
19384944d8cSKaren Xie static inline bool is_ofld_imm(const struct sk_buff *skb)
1947b36b6e0Skxie@chelsio.com {
19584944d8cSKaren Xie 	int len = skb->len;
19684944d8cSKaren Xie 
19784944d8cSKaren Xie 	if (likely(cxgbi_skcb_test_flag(skb, SKCBF_TX_NEED_HDR)))
19884944d8cSKaren Xie 		len += sizeof(struct fw_ofld_tx_data_wr);
19984944d8cSKaren Xie 
200e33c2482SVarun Prakash 	if  (likely(cxgbi_skcb_test_flag((struct sk_buff *)skb, SKCBF_TX_ISO)))
201e33c2482SVarun Prakash 		len += sizeof(struct cpl_tx_data_iso);
202e33c2482SVarun Prakash 
203e33c2482SVarun Prakash 	return (len <= MAX_IMM_OFLD_TX_DATA_WR_LEN);
2047b36b6e0Skxie@chelsio.com }
2057b36b6e0Skxie@chelsio.com 
2067b36b6e0Skxie@chelsio.com static void send_act_open_req(struct cxgbi_sock *csk, struct sk_buff *skb,
2077b36b6e0Skxie@chelsio.com 				struct l2t_entry *e)
2087b36b6e0Skxie@chelsio.com {
2093bd3e8bfSKaren Xie 	struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(csk->cdev);
2107b36b6e0Skxie@chelsio.com 	int wscale = cxgbi_sock_compute_wscale(csk->mss_idx);
2117b36b6e0Skxie@chelsio.com 	unsigned long long opt0;
2127b36b6e0Skxie@chelsio.com 	unsigned int opt2;
2137b36b6e0Skxie@chelsio.com 	unsigned int qid_atid = ((unsigned int)csk->atid) |
2147b36b6e0Skxie@chelsio.com 				 (((unsigned int)csk->rss_qid) << 14);
2157b36b6e0Skxie@chelsio.com 
216d7990b0cSAnish Bhatt 	opt0 = KEEP_ALIVE_F |
217d7990b0cSAnish Bhatt 		WND_SCALE_V(wscale) |
218d7990b0cSAnish Bhatt 		MSS_IDX_V(csk->mss_idx) |
219d7990b0cSAnish Bhatt 		L2T_IDX_V(((struct l2t_entry *)csk->l2t)->idx) |
220d7990b0cSAnish Bhatt 		TX_CHAN_V(csk->tx_chan) |
221d7990b0cSAnish Bhatt 		SMAC_SEL_V(csk->smac_idx) |
222d7990b0cSAnish Bhatt 		ULP_MODE_V(ULP_MODE_ISCSI) |
22381daf10cSKaren Xie 		RCV_BUFSIZ_V(csk->rcv_win >> 10);
2241eb88a5dSKaren Xie 
225d7990b0cSAnish Bhatt 	opt2 = RX_CHANNEL_V(0) |
226d7990b0cSAnish Bhatt 		RSS_QUEUE_VALID_F |
227d7990b0cSAnish Bhatt 		RSS_QUEUE_V(csk->rss_qid);
2287b36b6e0Skxie@chelsio.com 
2293bd3e8bfSKaren Xie 	if (is_t4(lldi->adapter_type)) {
2303bd3e8bfSKaren Xie 		struct cpl_act_open_req *req =
2313bd3e8bfSKaren Xie 				(struct cpl_act_open_req *)skb->head;
2323bd3e8bfSKaren Xie 
2337b36b6e0Skxie@chelsio.com 		INIT_TP_WR(req, 0);
2347b36b6e0Skxie@chelsio.com 		OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_ACT_OPEN_REQ,
2357b36b6e0Skxie@chelsio.com 					qid_atid));
2367b36b6e0Skxie@chelsio.com 		req->local_port = csk->saddr.sin_port;
2377b36b6e0Skxie@chelsio.com 		req->peer_port = csk->daddr.sin_port;
2387b36b6e0Skxie@chelsio.com 		req->local_ip = csk->saddr.sin_addr.s_addr;
2397b36b6e0Skxie@chelsio.com 		req->peer_ip = csk->daddr.sin_addr.s_addr;
2407b36b6e0Skxie@chelsio.com 		req->opt0 = cpu_to_be64(opt0);
241ac0245ffSKaren Xie 		req->params = cpu_to_be32(cxgb4_select_ntuple(
242ac0245ffSKaren Xie 					csk->cdev->ports[csk->port_id],
243ac0245ffSKaren Xie 					csk->l2t));
244d7990b0cSAnish Bhatt 		opt2 |= RX_FC_VALID_F;
2457b36b6e0Skxie@chelsio.com 		req->opt2 = cpu_to_be32(opt2);
2467b36b6e0Skxie@chelsio.com 
2477b36b6e0Skxie@chelsio.com 		log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
2483bd3e8bfSKaren Xie 			"csk t4 0x%p, %pI4:%u-%pI4:%u, atid %d, qid %u.\n",
2497b36b6e0Skxie@chelsio.com 			csk, &req->local_ip, ntohs(req->local_port),
2507b36b6e0Skxie@chelsio.com 			&req->peer_ip, ntohs(req->peer_port),
2517b36b6e0Skxie@chelsio.com 			csk->atid, csk->rss_qid);
252586be7cbSVarun Prakash 	} else if (is_t5(lldi->adapter_type)) {
2533bd3e8bfSKaren Xie 		struct cpl_t5_act_open_req *req =
2543bd3e8bfSKaren Xie 				(struct cpl_t5_act_open_req *)skb->head;
2551eb88a5dSKaren Xie 		u32 isn = (prandom_u32() & ~7UL) - 1;
2567b36b6e0Skxie@chelsio.com 
2573bd3e8bfSKaren Xie 		INIT_TP_WR(req, 0);
2583bd3e8bfSKaren Xie 		OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_ACT_OPEN_REQ,
2593bd3e8bfSKaren Xie 					qid_atid));
2603bd3e8bfSKaren Xie 		req->local_port = csk->saddr.sin_port;
2613bd3e8bfSKaren Xie 		req->peer_port = csk->daddr.sin_port;
2623bd3e8bfSKaren Xie 		req->local_ip = csk->saddr.sin_addr.s_addr;
2633bd3e8bfSKaren Xie 		req->peer_ip = csk->daddr.sin_addr.s_addr;
2643bd3e8bfSKaren Xie 		req->opt0 = cpu_to_be64(opt0);
265d7990b0cSAnish Bhatt 		req->params = cpu_to_be64(FILTER_TUPLE_V(
266ac0245ffSKaren Xie 				cxgb4_select_ntuple(
267ac0245ffSKaren Xie 					csk->cdev->ports[csk->port_id],
268ac0245ffSKaren Xie 					csk->l2t)));
2691eb88a5dSKaren Xie 		req->rsvd = cpu_to_be32(isn);
2701eb88a5dSKaren Xie 		opt2 |= T5_ISS_VALID;
2711eb88a5dSKaren Xie 		opt2 |= T5_OPT_2_VALID_F;
2721eb88a5dSKaren Xie 
2733bd3e8bfSKaren Xie 		req->opt2 = cpu_to_be32(opt2);
2743bd3e8bfSKaren Xie 
2753bd3e8bfSKaren Xie 		log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
2763bd3e8bfSKaren Xie 			"csk t5 0x%p, %pI4:%u-%pI4:%u, atid %d, qid %u.\n",
2773bd3e8bfSKaren Xie 			csk, &req->local_ip, ntohs(req->local_port),
2783bd3e8bfSKaren Xie 			&req->peer_ip, ntohs(req->peer_port),
2793bd3e8bfSKaren Xie 			csk->atid, csk->rss_qid);
280586be7cbSVarun Prakash 	} else {
281586be7cbSVarun Prakash 		struct cpl_t6_act_open_req *req =
282586be7cbSVarun Prakash 				(struct cpl_t6_act_open_req *)skb->head;
283586be7cbSVarun Prakash 		u32 isn = (prandom_u32() & ~7UL) - 1;
284586be7cbSVarun Prakash 
285586be7cbSVarun Prakash 		INIT_TP_WR(req, 0);
286586be7cbSVarun Prakash 		OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_ACT_OPEN_REQ,
287586be7cbSVarun Prakash 							    qid_atid));
288586be7cbSVarun Prakash 		req->local_port = csk->saddr.sin_port;
289586be7cbSVarun Prakash 		req->peer_port = csk->daddr.sin_port;
290586be7cbSVarun Prakash 		req->local_ip = csk->saddr.sin_addr.s_addr;
291586be7cbSVarun Prakash 		req->peer_ip = csk->daddr.sin_addr.s_addr;
292586be7cbSVarun Prakash 		req->opt0 = cpu_to_be64(opt0);
293586be7cbSVarun Prakash 		req->params = cpu_to_be64(FILTER_TUPLE_V(
294586be7cbSVarun Prakash 				cxgb4_select_ntuple(
295586be7cbSVarun Prakash 					csk->cdev->ports[csk->port_id],
296586be7cbSVarun Prakash 					csk->l2t)));
297586be7cbSVarun Prakash 		req->rsvd = cpu_to_be32(isn);
298586be7cbSVarun Prakash 
299586be7cbSVarun Prakash 		opt2 |= T5_ISS_VALID;
300586be7cbSVarun Prakash 		opt2 |= RX_FC_DISABLE_F;
301586be7cbSVarun Prakash 		opt2 |= T5_OPT_2_VALID_F;
302586be7cbSVarun Prakash 
303586be7cbSVarun Prakash 		req->opt2 = cpu_to_be32(opt2);
304586be7cbSVarun Prakash 		req->rsvd2 = cpu_to_be32(0);
305586be7cbSVarun Prakash 		req->opt3 = cpu_to_be32(0);
306586be7cbSVarun Prakash 
307586be7cbSVarun Prakash 		log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
308586be7cbSVarun Prakash 			  "csk t6 0x%p, %pI4:%u-%pI4:%u, atid %d, qid %u.\n",
309586be7cbSVarun Prakash 			  csk, &req->local_ip, ntohs(req->local_port),
310586be7cbSVarun Prakash 			  &req->peer_ip, ntohs(req->peer_port),
311586be7cbSVarun Prakash 			  csk->atid, csk->rss_qid);
3123bd3e8bfSKaren Xie 	}
3133bd3e8bfSKaren Xie 
3143bd3e8bfSKaren Xie 	set_wr_txq(skb, CPL_PRIORITY_SETUP, csk->port_id);
315759a0cc5SAnish Bhatt 
316759a0cc5SAnish Bhatt 	pr_info_ipaddr("t%d csk 0x%p,%u,0x%lx,%u, rss_qid %u.\n",
317586be7cbSVarun Prakash 		       (&csk->saddr), (&csk->daddr),
318586be7cbSVarun Prakash 		       CHELSIO_CHIP_VERSION(lldi->adapter_type), csk,
319759a0cc5SAnish Bhatt 		       csk->state, csk->flags, csk->atid, csk->rss_qid);
320759a0cc5SAnish Bhatt 
321759a0cc5SAnish Bhatt 	cxgb4_l2t_send(csk->cdev->ports[csk->port_id], skb, csk->l2t);
322759a0cc5SAnish Bhatt }
323759a0cc5SAnish Bhatt 
324f42bb57cSAnish Bhatt #if IS_ENABLED(CONFIG_IPV6)
325759a0cc5SAnish Bhatt static void send_act_open_req6(struct cxgbi_sock *csk, struct sk_buff *skb,
326759a0cc5SAnish Bhatt 			       struct l2t_entry *e)
327759a0cc5SAnish Bhatt {
328759a0cc5SAnish Bhatt 	struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(csk->cdev);
329759a0cc5SAnish Bhatt 	int wscale = cxgbi_sock_compute_wscale(csk->mss_idx);
330759a0cc5SAnish Bhatt 	unsigned long long opt0;
331759a0cc5SAnish Bhatt 	unsigned int opt2;
332759a0cc5SAnish Bhatt 	unsigned int qid_atid = ((unsigned int)csk->atid) |
333759a0cc5SAnish Bhatt 				 (((unsigned int)csk->rss_qid) << 14);
334759a0cc5SAnish Bhatt 
335d7990b0cSAnish Bhatt 	opt0 = KEEP_ALIVE_F |
336d7990b0cSAnish Bhatt 		WND_SCALE_V(wscale) |
337d7990b0cSAnish Bhatt 		MSS_IDX_V(csk->mss_idx) |
338d7990b0cSAnish Bhatt 		L2T_IDX_V(((struct l2t_entry *)csk->l2t)->idx) |
339d7990b0cSAnish Bhatt 		TX_CHAN_V(csk->tx_chan) |
340d7990b0cSAnish Bhatt 		SMAC_SEL_V(csk->smac_idx) |
341d7990b0cSAnish Bhatt 		ULP_MODE_V(ULP_MODE_ISCSI) |
34281daf10cSKaren Xie 		RCV_BUFSIZ_V(csk->rcv_win >> 10);
343759a0cc5SAnish Bhatt 
344d7990b0cSAnish Bhatt 	opt2 = RX_CHANNEL_V(0) |
345d7990b0cSAnish Bhatt 		RSS_QUEUE_VALID_F |
346d7990b0cSAnish Bhatt 		RSS_QUEUE_V(csk->rss_qid);
347759a0cc5SAnish Bhatt 
348586be7cbSVarun Prakash 	if (is_t4(lldi->adapter_type)) {
349759a0cc5SAnish Bhatt 		struct cpl_act_open_req6 *req =
350759a0cc5SAnish Bhatt 			    (struct cpl_act_open_req6 *)skb->head;
351759a0cc5SAnish Bhatt 
352759a0cc5SAnish Bhatt 		INIT_TP_WR(req, 0);
353759a0cc5SAnish Bhatt 		OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_ACT_OPEN_REQ6,
354759a0cc5SAnish Bhatt 							    qid_atid));
355759a0cc5SAnish Bhatt 		req->local_port = csk->saddr6.sin6_port;
356759a0cc5SAnish Bhatt 		req->peer_port = csk->daddr6.sin6_port;
357759a0cc5SAnish Bhatt 
358759a0cc5SAnish Bhatt 		req->local_ip_hi = *(__be64 *)(csk->saddr6.sin6_addr.s6_addr);
359759a0cc5SAnish Bhatt 		req->local_ip_lo = *(__be64 *)(csk->saddr6.sin6_addr.s6_addr +
360759a0cc5SAnish Bhatt 								    8);
361759a0cc5SAnish Bhatt 		req->peer_ip_hi = *(__be64 *)(csk->daddr6.sin6_addr.s6_addr);
362759a0cc5SAnish Bhatt 		req->peer_ip_lo = *(__be64 *)(csk->daddr6.sin6_addr.s6_addr +
363759a0cc5SAnish Bhatt 								    8);
364759a0cc5SAnish Bhatt 
365759a0cc5SAnish Bhatt 		req->opt0 = cpu_to_be64(opt0);
366759a0cc5SAnish Bhatt 
367d7990b0cSAnish Bhatt 		opt2 |= RX_FC_VALID_F;
368759a0cc5SAnish Bhatt 		req->opt2 = cpu_to_be32(opt2);
369759a0cc5SAnish Bhatt 
370759a0cc5SAnish Bhatt 		req->params = cpu_to_be32(cxgb4_select_ntuple(
371759a0cc5SAnish Bhatt 					  csk->cdev->ports[csk->port_id],
372759a0cc5SAnish Bhatt 					  csk->l2t));
373586be7cbSVarun Prakash 	} else if (is_t5(lldi->adapter_type)) {
374759a0cc5SAnish Bhatt 		struct cpl_t5_act_open_req6 *req =
375759a0cc5SAnish Bhatt 				(struct cpl_t5_act_open_req6 *)skb->head;
376759a0cc5SAnish Bhatt 
377759a0cc5SAnish Bhatt 		INIT_TP_WR(req, 0);
378759a0cc5SAnish Bhatt 		OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_ACT_OPEN_REQ6,
379759a0cc5SAnish Bhatt 							    qid_atid));
380759a0cc5SAnish Bhatt 		req->local_port = csk->saddr6.sin6_port;
381759a0cc5SAnish Bhatt 		req->peer_port = csk->daddr6.sin6_port;
382759a0cc5SAnish Bhatt 		req->local_ip_hi = *(__be64 *)(csk->saddr6.sin6_addr.s6_addr);
383759a0cc5SAnish Bhatt 		req->local_ip_lo = *(__be64 *)(csk->saddr6.sin6_addr.s6_addr +
384759a0cc5SAnish Bhatt 									8);
385759a0cc5SAnish Bhatt 		req->peer_ip_hi = *(__be64 *)(csk->daddr6.sin6_addr.s6_addr);
386759a0cc5SAnish Bhatt 		req->peer_ip_lo = *(__be64 *)(csk->daddr6.sin6_addr.s6_addr +
387759a0cc5SAnish Bhatt 									8);
388759a0cc5SAnish Bhatt 		req->opt0 = cpu_to_be64(opt0);
389759a0cc5SAnish Bhatt 
390d7990b0cSAnish Bhatt 		opt2 |= T5_OPT_2_VALID_F;
391759a0cc5SAnish Bhatt 		req->opt2 = cpu_to_be32(opt2);
392759a0cc5SAnish Bhatt 
393d7990b0cSAnish Bhatt 		req->params = cpu_to_be64(FILTER_TUPLE_V(cxgb4_select_ntuple(
394759a0cc5SAnish Bhatt 					  csk->cdev->ports[csk->port_id],
395759a0cc5SAnish Bhatt 					  csk->l2t)));
396586be7cbSVarun Prakash 	} else {
397586be7cbSVarun Prakash 		struct cpl_t6_act_open_req6 *req =
398586be7cbSVarun Prakash 				(struct cpl_t6_act_open_req6 *)skb->head;
399586be7cbSVarun Prakash 
400586be7cbSVarun Prakash 		INIT_TP_WR(req, 0);
401586be7cbSVarun Prakash 		OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_ACT_OPEN_REQ6,
402586be7cbSVarun Prakash 							    qid_atid));
403586be7cbSVarun Prakash 		req->local_port = csk->saddr6.sin6_port;
404586be7cbSVarun Prakash 		req->peer_port = csk->daddr6.sin6_port;
405586be7cbSVarun Prakash 		req->local_ip_hi = *(__be64 *)(csk->saddr6.sin6_addr.s6_addr);
406586be7cbSVarun Prakash 		req->local_ip_lo = *(__be64 *)(csk->saddr6.sin6_addr.s6_addr +
407586be7cbSVarun Prakash 									8);
408586be7cbSVarun Prakash 		req->peer_ip_hi = *(__be64 *)(csk->daddr6.sin6_addr.s6_addr);
409586be7cbSVarun Prakash 		req->peer_ip_lo = *(__be64 *)(csk->daddr6.sin6_addr.s6_addr +
410586be7cbSVarun Prakash 									8);
411586be7cbSVarun Prakash 		req->opt0 = cpu_to_be64(opt0);
412586be7cbSVarun Prakash 
413586be7cbSVarun Prakash 		opt2 |= RX_FC_DISABLE_F;
414586be7cbSVarun Prakash 		opt2 |= T5_OPT_2_VALID_F;
415586be7cbSVarun Prakash 
416586be7cbSVarun Prakash 		req->opt2 = cpu_to_be32(opt2);
417586be7cbSVarun Prakash 
418586be7cbSVarun Prakash 		req->params = cpu_to_be64(FILTER_TUPLE_V(cxgb4_select_ntuple(
419586be7cbSVarun Prakash 					  csk->cdev->ports[csk->port_id],
420586be7cbSVarun Prakash 					  csk->l2t)));
421586be7cbSVarun Prakash 
422586be7cbSVarun Prakash 		req->rsvd2 = cpu_to_be32(0);
423586be7cbSVarun Prakash 		req->opt3 = cpu_to_be32(0);
424759a0cc5SAnish Bhatt 	}
425759a0cc5SAnish Bhatt 
426759a0cc5SAnish Bhatt 	set_wr_txq(skb, CPL_PRIORITY_SETUP, csk->port_id);
427759a0cc5SAnish Bhatt 
428759a0cc5SAnish Bhatt 	pr_info("t%d csk 0x%p,%u,0x%lx,%u, [%pI6]:%u-[%pI6]:%u, rss_qid %u.\n",
429586be7cbSVarun Prakash 		CHELSIO_CHIP_VERSION(lldi->adapter_type), csk, csk->state,
430586be7cbSVarun Prakash 		csk->flags, csk->atid,
431759a0cc5SAnish Bhatt 		&csk->saddr6.sin6_addr, ntohs(csk->saddr.sin_port),
432759a0cc5SAnish Bhatt 		&csk->daddr6.sin6_addr, ntohs(csk->daddr.sin_port),
433759a0cc5SAnish Bhatt 		csk->rss_qid);
434759a0cc5SAnish Bhatt 
4357b36b6e0Skxie@chelsio.com 	cxgb4_l2t_send(csk->cdev->ports[csk->port_id], skb, csk->l2t);
4367b36b6e0Skxie@chelsio.com }
437f42bb57cSAnish Bhatt #endif
4387b36b6e0Skxie@chelsio.com 
4397b36b6e0Skxie@chelsio.com static void send_close_req(struct cxgbi_sock *csk)
4407b36b6e0Skxie@chelsio.com {
4417b36b6e0Skxie@chelsio.com 	struct sk_buff *skb = csk->cpl_close;
4427b36b6e0Skxie@chelsio.com 	struct cpl_close_con_req *req = (struct cpl_close_con_req *)skb->head;
4437b36b6e0Skxie@chelsio.com 	unsigned int tid = csk->tid;
4447b36b6e0Skxie@chelsio.com 
4457b36b6e0Skxie@chelsio.com 	log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
4467b36b6e0Skxie@chelsio.com 		"csk 0x%p,%u,0x%lx, tid %u.\n",
4477b36b6e0Skxie@chelsio.com 		csk, csk->state, csk->flags, csk->tid);
4487b36b6e0Skxie@chelsio.com 	csk->cpl_close = NULL;
4497b36b6e0Skxie@chelsio.com 	set_wr_txq(skb, CPL_PRIORITY_DATA, csk->port_id);
4507b36b6e0Skxie@chelsio.com 	INIT_TP_WR(req, tid);
4517b36b6e0Skxie@chelsio.com 	OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_CLOSE_CON_REQ, tid));
4527b36b6e0Skxie@chelsio.com 	req->rsvd = 0;
4537b36b6e0Skxie@chelsio.com 
4547b36b6e0Skxie@chelsio.com 	cxgbi_sock_skb_entail(csk, skb);
4557b36b6e0Skxie@chelsio.com 	if (csk->state >= CTP_ESTABLISHED)
4567b36b6e0Skxie@chelsio.com 		push_tx_frames(csk, 1);
4577b36b6e0Skxie@chelsio.com }
4587b36b6e0Skxie@chelsio.com 
4597b36b6e0Skxie@chelsio.com static void abort_arp_failure(void *handle, struct sk_buff *skb)
4607b36b6e0Skxie@chelsio.com {
4617b36b6e0Skxie@chelsio.com 	struct cxgbi_sock *csk = (struct cxgbi_sock *)handle;
4627b36b6e0Skxie@chelsio.com 	struct cpl_abort_req *req;
4637b36b6e0Skxie@chelsio.com 
4647b36b6e0Skxie@chelsio.com 	log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
4657b36b6e0Skxie@chelsio.com 		"csk 0x%p,%u,0x%lx, tid %u, abort.\n",
4667b36b6e0Skxie@chelsio.com 		csk, csk->state, csk->flags, csk->tid);
4677b36b6e0Skxie@chelsio.com 	req = (struct cpl_abort_req *)skb->data;
4687b36b6e0Skxie@chelsio.com 	req->cmd = CPL_ABORT_NO_RST;
4697b36b6e0Skxie@chelsio.com 	cxgb4_ofld_send(csk->cdev->ports[csk->port_id], skb);
4707b36b6e0Skxie@chelsio.com }
4717b36b6e0Skxie@chelsio.com 
4727b36b6e0Skxie@chelsio.com static void send_abort_req(struct cxgbi_sock *csk)
4737b36b6e0Skxie@chelsio.com {
4747b36b6e0Skxie@chelsio.com 	struct cpl_abort_req *req;
4757b36b6e0Skxie@chelsio.com 	struct sk_buff *skb = csk->cpl_abort_req;
4767b36b6e0Skxie@chelsio.com 
4777b36b6e0Skxie@chelsio.com 	if (unlikely(csk->state == CTP_ABORTING) || !skb || !csk->cdev)
4787b36b6e0Skxie@chelsio.com 		return;
47964bfead8SKaren Xie 
48064bfead8SKaren Xie 	if (!cxgbi_sock_flag(csk, CTPF_TX_DATA_SENT)) {
48164bfead8SKaren Xie 		send_tx_flowc_wr(csk);
48264bfead8SKaren Xie 		cxgbi_sock_set_flag(csk, CTPF_TX_DATA_SENT);
48364bfead8SKaren Xie 	}
48464bfead8SKaren Xie 
4857b36b6e0Skxie@chelsio.com 	cxgbi_sock_set_state(csk, CTP_ABORTING);
4867b36b6e0Skxie@chelsio.com 	cxgbi_sock_set_flag(csk, CTPF_ABORT_RPL_PENDING);
4877b36b6e0Skxie@chelsio.com 	cxgbi_sock_purge_write_queue(csk);
4887b36b6e0Skxie@chelsio.com 
4897b36b6e0Skxie@chelsio.com 	csk->cpl_abort_req = NULL;
4907b36b6e0Skxie@chelsio.com 	req = (struct cpl_abort_req *)skb->head;
4912126bc5eSKaren Xie 	set_wr_txq(skb, CPL_PRIORITY_DATA, csk->port_id);
4927b36b6e0Skxie@chelsio.com 	req->cmd = CPL_ABORT_SEND_RST;
4937b36b6e0Skxie@chelsio.com 	t4_set_arp_err_handler(skb, csk, abort_arp_failure);
4947b36b6e0Skxie@chelsio.com 	INIT_TP_WR(req, csk->tid);
4957b36b6e0Skxie@chelsio.com 	OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_ABORT_REQ, csk->tid));
4967b36b6e0Skxie@chelsio.com 	req->rsvd0 = htonl(csk->snd_nxt);
4977b36b6e0Skxie@chelsio.com 	req->rsvd1 = !cxgbi_sock_flag(csk, CTPF_TX_DATA_SENT);
4987b36b6e0Skxie@chelsio.com 
4997b36b6e0Skxie@chelsio.com 	log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
5007b36b6e0Skxie@chelsio.com 		"csk 0x%p,%u,0x%lx,%u, snd_nxt %u, 0x%x.\n",
5017b36b6e0Skxie@chelsio.com 		csk, csk->state, csk->flags, csk->tid, csk->snd_nxt,
5027b36b6e0Skxie@chelsio.com 		req->rsvd1);
5037b36b6e0Skxie@chelsio.com 
5047b36b6e0Skxie@chelsio.com 	cxgb4_l2t_send(csk->cdev->ports[csk->port_id], skb, csk->l2t);
5057b36b6e0Skxie@chelsio.com }
5067b36b6e0Skxie@chelsio.com 
5077b36b6e0Skxie@chelsio.com static void send_abort_rpl(struct cxgbi_sock *csk, int rst_status)
5087b36b6e0Skxie@chelsio.com {
5097b36b6e0Skxie@chelsio.com 	struct sk_buff *skb = csk->cpl_abort_rpl;
5107b36b6e0Skxie@chelsio.com 	struct cpl_abort_rpl *rpl = (struct cpl_abort_rpl *)skb->head;
5117b36b6e0Skxie@chelsio.com 
5127b36b6e0Skxie@chelsio.com 	log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
5137b36b6e0Skxie@chelsio.com 		"csk 0x%p,%u,0x%lx,%u, status %d.\n",
5147b36b6e0Skxie@chelsio.com 		csk, csk->state, csk->flags, csk->tid, rst_status);
5157b36b6e0Skxie@chelsio.com 
5167b36b6e0Skxie@chelsio.com 	csk->cpl_abort_rpl = NULL;
5172126bc5eSKaren Xie 	set_wr_txq(skb, CPL_PRIORITY_DATA, csk->port_id);
5187b36b6e0Skxie@chelsio.com 	INIT_TP_WR(rpl, csk->tid);
5197b36b6e0Skxie@chelsio.com 	OPCODE_TID(rpl) = cpu_to_be32(MK_OPCODE_TID(CPL_ABORT_RPL, csk->tid));
5207b36b6e0Skxie@chelsio.com 	rpl->cmd = rst_status;
5217b36b6e0Skxie@chelsio.com 	cxgb4_ofld_send(csk->cdev->ports[csk->port_id], skb);
5227b36b6e0Skxie@chelsio.com }
5237b36b6e0Skxie@chelsio.com 
5247b36b6e0Skxie@chelsio.com /*
5257b36b6e0Skxie@chelsio.com  * CPL connection rx data ack: host ->
5267b36b6e0Skxie@chelsio.com  * Send RX credits through an RX_DATA_ACK CPL message. Returns the number of
5277b36b6e0Skxie@chelsio.com  * credits sent.
5287b36b6e0Skxie@chelsio.com  */
5297b36b6e0Skxie@chelsio.com static u32 send_rx_credits(struct cxgbi_sock *csk, u32 credits)
5307b36b6e0Skxie@chelsio.com {
5317b36b6e0Skxie@chelsio.com 	struct sk_buff *skb;
5327b36b6e0Skxie@chelsio.com 	struct cpl_rx_data_ack *req;
5337b36b6e0Skxie@chelsio.com 
5347b36b6e0Skxie@chelsio.com 	log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_PDU_RX,
5357b36b6e0Skxie@chelsio.com 		"csk 0x%p,%u,0x%lx,%u, credit %u.\n",
5367b36b6e0Skxie@chelsio.com 		csk, csk->state, csk->flags, csk->tid, credits);
5377b36b6e0Skxie@chelsio.com 
53824d3f95aSkxie@chelsio.com 	skb = alloc_wr(sizeof(*req), 0, GFP_ATOMIC);
5397b36b6e0Skxie@chelsio.com 	if (!skb) {
5407b36b6e0Skxie@chelsio.com 		pr_info("csk 0x%p, credit %u, OOM.\n", csk, credits);
5417b36b6e0Skxie@chelsio.com 		return 0;
5427b36b6e0Skxie@chelsio.com 	}
5437b36b6e0Skxie@chelsio.com 	req = (struct cpl_rx_data_ack *)skb->head;
5447b36b6e0Skxie@chelsio.com 
5457b36b6e0Skxie@chelsio.com 	set_wr_txq(skb, CPL_PRIORITY_ACK, csk->port_id);
5467b36b6e0Skxie@chelsio.com 	INIT_TP_WR(req, csk->tid);
5477b36b6e0Skxie@chelsio.com 	OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_RX_DATA_ACK,
5487b36b6e0Skxie@chelsio.com 				      csk->tid));
549d7990b0cSAnish Bhatt 	req->credit_dack = cpu_to_be32(RX_CREDITS_V(credits)
550d7990b0cSAnish Bhatt 				       | RX_FORCE_ACK_F);
5517b36b6e0Skxie@chelsio.com 	cxgb4_ofld_send(csk->cdev->ports[csk->port_id], skb);
5527b36b6e0Skxie@chelsio.com 	return credits;
5537b36b6e0Skxie@chelsio.com }
5547b36b6e0Skxie@chelsio.com 
5557b36b6e0Skxie@chelsio.com /*
5567b36b6e0Skxie@chelsio.com  * sgl_len - calculates the size of an SGL of the given capacity
5577b36b6e0Skxie@chelsio.com  * @n: the number of SGL entries
5587b36b6e0Skxie@chelsio.com  * Calculates the number of flits needed for a scatter/gather list that
5597b36b6e0Skxie@chelsio.com  * can hold the given number of entries.
5607b36b6e0Skxie@chelsio.com  */
5617b36b6e0Skxie@chelsio.com static inline unsigned int sgl_len(unsigned int n)
5627b36b6e0Skxie@chelsio.com {
5637b36b6e0Skxie@chelsio.com 	n--;
5647b36b6e0Skxie@chelsio.com 	return (3 * n) / 2 + (n & 1) + 2;
5657b36b6e0Skxie@chelsio.com }
5667b36b6e0Skxie@chelsio.com 
5677b36b6e0Skxie@chelsio.com /*
5687b36b6e0Skxie@chelsio.com  * calc_tx_flits_ofld - calculate # of flits for an offload packet
5697b36b6e0Skxie@chelsio.com  * @skb: the packet
5707b36b6e0Skxie@chelsio.com  *
5717b36b6e0Skxie@chelsio.com  * Returns the number of flits needed for the given offload packet.
5727b36b6e0Skxie@chelsio.com  * These packets are already fully constructed and no additional headers
5737b36b6e0Skxie@chelsio.com  * will be added.
5747b36b6e0Skxie@chelsio.com  */
5757b36b6e0Skxie@chelsio.com static inline unsigned int calc_tx_flits_ofld(const struct sk_buff *skb)
5767b36b6e0Skxie@chelsio.com {
5777b36b6e0Skxie@chelsio.com 	unsigned int flits, cnt;
5787b36b6e0Skxie@chelsio.com 
5797b36b6e0Skxie@chelsio.com 	if (is_ofld_imm(skb))
5807b36b6e0Skxie@chelsio.com 		return DIV_ROUND_UP(skb->len, 8);
5817b36b6e0Skxie@chelsio.com 	flits = skb_transport_offset(skb) / 8;
5827b36b6e0Skxie@chelsio.com 	cnt = skb_shinfo(skb)->nr_frags;
583499e2e6fSIsaku Yamahata 	if (skb_tail_pointer(skb) != skb_transport_header(skb))
5847b36b6e0Skxie@chelsio.com 		cnt++;
5857b36b6e0Skxie@chelsio.com 	return flits + sgl_len(cnt);
5867b36b6e0Skxie@chelsio.com }
5877b36b6e0Skxie@chelsio.com 
58864bfead8SKaren Xie #define FLOWC_WR_NPARAMS_MIN	9
58964bfead8SKaren Xie static inline int tx_flowc_wr_credits(int *nparamsp, int *flowclenp)
59064bfead8SKaren Xie {
59164bfead8SKaren Xie 	int nparams, flowclen16, flowclen;
59264bfead8SKaren Xie 
59364bfead8SKaren Xie 	nparams = FLOWC_WR_NPARAMS_MIN;
594b5a5fe4eSVarun Prakash #ifdef CONFIG_CHELSIO_T4_DCB
595b5a5fe4eSVarun Prakash 	nparams++;
596b5a5fe4eSVarun Prakash #endif
59764bfead8SKaren Xie 	flowclen = offsetof(struct fw_flowc_wr, mnemval[nparams]);
59864bfead8SKaren Xie 	flowclen16 = DIV_ROUND_UP(flowclen, 16);
59964bfead8SKaren Xie 	flowclen = flowclen16 * 16;
60064bfead8SKaren Xie 	/*
60164bfead8SKaren Xie 	 * Return the number of 16-byte credits used by the FlowC request.
60264bfead8SKaren Xie 	 * Pass back the nparams and actual FlowC length if requested.
60364bfead8SKaren Xie 	 */
60464bfead8SKaren Xie 	if (nparamsp)
60564bfead8SKaren Xie 		*nparamsp = nparams;
60664bfead8SKaren Xie 	if (flowclenp)
60764bfead8SKaren Xie 		*flowclenp = flowclen;
60864bfead8SKaren Xie 
60964bfead8SKaren Xie 	return flowclen16;
61064bfead8SKaren Xie }
61164bfead8SKaren Xie 
61264bfead8SKaren Xie static inline int send_tx_flowc_wr(struct cxgbi_sock *csk)
6137b36b6e0Skxie@chelsio.com {
6147b36b6e0Skxie@chelsio.com 	struct sk_buff *skb;
6157b36b6e0Skxie@chelsio.com 	struct fw_flowc_wr *flowc;
61664bfead8SKaren Xie 	int nparams, flowclen16, flowclen;
6177b36b6e0Skxie@chelsio.com 
618b5a5fe4eSVarun Prakash #ifdef CONFIG_CHELSIO_T4_DCB
619b5a5fe4eSVarun Prakash 	u16 vlan = ((struct l2t_entry *)csk->l2t)->vlan;
620b5a5fe4eSVarun Prakash #endif
62164bfead8SKaren Xie 	flowclen16 = tx_flowc_wr_credits(&nparams, &flowclen);
62224d3f95aSkxie@chelsio.com 	skb = alloc_wr(flowclen, 0, GFP_ATOMIC);
6237b36b6e0Skxie@chelsio.com 	flowc = (struct fw_flowc_wr *)skb->head;
6247b36b6e0Skxie@chelsio.com 	flowc->op_to_nparams =
62564bfead8SKaren Xie 		htonl(FW_WR_OP_V(FW_FLOWC_WR) | FW_FLOWC_WR_NPARAMS_V(nparams));
6267b36b6e0Skxie@chelsio.com 	flowc->flowid_len16 =
62764bfead8SKaren Xie 		htonl(FW_WR_LEN16_V(flowclen16) | FW_WR_FLOWID_V(csk->tid));
6287b36b6e0Skxie@chelsio.com 	flowc->mnemval[0].mnemonic = FW_FLOWC_MNEM_PFNVFN;
629e27d6169Skxie@chelsio.com 	flowc->mnemval[0].val = htonl(csk->cdev->pfvf);
6307b36b6e0Skxie@chelsio.com 	flowc->mnemval[1].mnemonic = FW_FLOWC_MNEM_CH;
6317b36b6e0Skxie@chelsio.com 	flowc->mnemval[1].val = htonl(csk->tx_chan);
6327b36b6e0Skxie@chelsio.com 	flowc->mnemval[2].mnemonic = FW_FLOWC_MNEM_PORT;
6337b36b6e0Skxie@chelsio.com 	flowc->mnemval[2].val = htonl(csk->tx_chan);
6347b36b6e0Skxie@chelsio.com 	flowc->mnemval[3].mnemonic = FW_FLOWC_MNEM_IQID;
6357b36b6e0Skxie@chelsio.com 	flowc->mnemval[3].val = htonl(csk->rss_qid);
6367b36b6e0Skxie@chelsio.com 	flowc->mnemval[4].mnemonic = FW_FLOWC_MNEM_SNDNXT;
6377b36b6e0Skxie@chelsio.com 	flowc->mnemval[4].val = htonl(csk->snd_nxt);
6387b36b6e0Skxie@chelsio.com 	flowc->mnemval[5].mnemonic = FW_FLOWC_MNEM_RCVNXT;
6397b36b6e0Skxie@chelsio.com 	flowc->mnemval[5].val = htonl(csk->rcv_nxt);
6407b36b6e0Skxie@chelsio.com 	flowc->mnemval[6].mnemonic = FW_FLOWC_MNEM_SNDBUF;
64181daf10cSKaren Xie 	flowc->mnemval[6].val = htonl(csk->snd_win);
6427b36b6e0Skxie@chelsio.com 	flowc->mnemval[7].mnemonic = FW_FLOWC_MNEM_MSS;
6437b36b6e0Skxie@chelsio.com 	flowc->mnemval[7].val = htonl(csk->advmss);
6447b36b6e0Skxie@chelsio.com 	flowc->mnemval[8].mnemonic = 0;
6457b36b6e0Skxie@chelsio.com 	flowc->mnemval[8].val = 0;
64664bfead8SKaren Xie 	flowc->mnemval[8].mnemonic = FW_FLOWC_MNEM_TXDATAPLEN_MAX;
647e33c2482SVarun Prakash 	if (csk->cdev->skb_iso_txhdr)
648e33c2482SVarun Prakash 		flowc->mnemval[8].val = cpu_to_be32(CXGBI_MAX_ISO_DATA_IN_SKB);
649e33c2482SVarun Prakash 	else
650e33c2482SVarun Prakash 		flowc->mnemval[8].val = cpu_to_be32(16128);
651b5a5fe4eSVarun Prakash #ifdef CONFIG_CHELSIO_T4_DCB
652b5a5fe4eSVarun Prakash 	flowc->mnemval[9].mnemonic = FW_FLOWC_MNEM_DCBPRIO;
653b5a5fe4eSVarun Prakash 	if (vlan == CPL_L2T_VLAN_NONE) {
654b5a5fe4eSVarun Prakash 		pr_warn_ratelimited("csk %u without VLAN Tag on DCB Link\n",
655b5a5fe4eSVarun Prakash 				    csk->tid);
656b5a5fe4eSVarun Prakash 		flowc->mnemval[9].val = cpu_to_be32(0);
657b5a5fe4eSVarun Prakash 	} else {
658b5a5fe4eSVarun Prakash 		flowc->mnemval[9].val = cpu_to_be32((vlan & VLAN_PRIO_MASK) >>
659b5a5fe4eSVarun Prakash 					VLAN_PRIO_SHIFT);
660b5a5fe4eSVarun Prakash 	}
661b5a5fe4eSVarun Prakash #endif
66264bfead8SKaren Xie 
6632126bc5eSKaren Xie 	set_wr_txq(skb, CPL_PRIORITY_DATA, csk->port_id);
6647b36b6e0Skxie@chelsio.com 
6657b36b6e0Skxie@chelsio.com 	log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
6667b36b6e0Skxie@chelsio.com 		"csk 0x%p, tid 0x%x, %u,%u,%u,%u,%u,%u,%u.\n",
6677b36b6e0Skxie@chelsio.com 		csk, csk->tid, 0, csk->tx_chan, csk->rss_qid,
66881daf10cSKaren Xie 		csk->snd_nxt, csk->rcv_nxt, csk->snd_win,
6697b36b6e0Skxie@chelsio.com 		csk->advmss);
6707b36b6e0Skxie@chelsio.com 
6717b36b6e0Skxie@chelsio.com 	cxgb4_ofld_send(csk->cdev->ports[csk->port_id], skb);
67264bfead8SKaren Xie 
67364bfead8SKaren Xie 	return flowclen16;
6747b36b6e0Skxie@chelsio.com }
6757b36b6e0Skxie@chelsio.com 
676e33c2482SVarun Prakash static void
677e33c2482SVarun Prakash cxgb4i_make_tx_iso_cpl(struct sk_buff *skb, struct cpl_tx_data_iso *cpl)
6787b36b6e0Skxie@chelsio.com {
679e33c2482SVarun Prakash 	struct cxgbi_iso_info *info = (struct cxgbi_iso_info *)skb->head;
680e33c2482SVarun Prakash 	u32 imm_en = !!(info->flags & CXGBI_ISO_INFO_IMM_ENABLE);
681e33c2482SVarun Prakash 	u32 fslice = !!(info->flags & CXGBI_ISO_INFO_FSLICE);
682e33c2482SVarun Prakash 	u32 lslice = !!(info->flags & CXGBI_ISO_INFO_LSLICE);
683e33c2482SVarun Prakash 	u32 pdu_type = (info->op == ISCSI_OP_SCSI_CMD) ? 0 : 1;
684e33c2482SVarun Prakash 	u32 submode = cxgbi_skcb_tx_ulp_mode(skb) & 0x3;
6857b36b6e0Skxie@chelsio.com 
686e33c2482SVarun Prakash 	cpl->op_to_scsi = cpu_to_be32(CPL_TX_DATA_ISO_OP_V(CPL_TX_DATA_ISO) |
687e33c2482SVarun Prakash 				CPL_TX_DATA_ISO_FIRST_V(fslice) |
688e33c2482SVarun Prakash 				CPL_TX_DATA_ISO_LAST_V(lslice) |
689e33c2482SVarun Prakash 				CPL_TX_DATA_ISO_CPLHDRLEN_V(0) |
690e33c2482SVarun Prakash 				CPL_TX_DATA_ISO_HDRCRC_V(submode & 1) |
691e33c2482SVarun Prakash 				CPL_TX_DATA_ISO_PLDCRC_V(((submode >> 1) & 1)) |
692e33c2482SVarun Prakash 				CPL_TX_DATA_ISO_IMMEDIATE_V(imm_en) |
693e33c2482SVarun Prakash 				CPL_TX_DATA_ISO_SCSI_V(pdu_type));
6947b36b6e0Skxie@chelsio.com 
695e33c2482SVarun Prakash 	cpl->ahs_len = info->ahs;
696e33c2482SVarun Prakash 	cpl->mpdu = cpu_to_be16(DIV_ROUND_UP(info->mpdu, 4));
697e33c2482SVarun Prakash 	cpl->burst_size = cpu_to_be32(info->burst_size);
698e33c2482SVarun Prakash 	cpl->len = cpu_to_be32(info->len);
699e33c2482SVarun Prakash 	cpl->reserved2_seglen_offset =
700e33c2482SVarun Prakash 	     cpu_to_be32(CPL_TX_DATA_ISO_SEGLEN_OFFSET_V(info->segment_offset));
701e33c2482SVarun Prakash 	cpl->datasn_offset = cpu_to_be32(info->datasn_offset);
702e33c2482SVarun Prakash 	cpl->buffer_offset = cpu_to_be32(info->buffer_offset);
703e33c2482SVarun Prakash 	cpl->reserved3 = cpu_to_be32(0);
704e33c2482SVarun Prakash 	log_debug(1 << CXGBI_DBG_ISCSI | 1 << CXGBI_DBG_PDU_TX,
705e33c2482SVarun Prakash 		  "iso: flags 0x%x, op %u, ahs %u, num_pdu %u, mpdu %u, "
706e33c2482SVarun Prakash 		  "burst_size %u, iso_len %u\n",
707e33c2482SVarun Prakash 		  info->flags, info->op, info->ahs, info->num_pdu,
708e33c2482SVarun Prakash 		  info->mpdu, info->burst_size << 2, info->len);
7097b36b6e0Skxie@chelsio.com }
710e33c2482SVarun Prakash 
711e33c2482SVarun Prakash static void
712e33c2482SVarun Prakash cxgb4i_make_tx_data_wr(struct cxgbi_sock *csk, struct sk_buff *skb, int dlen,
713e33c2482SVarun Prakash 		       int len, u32 credits, int compl)
714e33c2482SVarun Prakash {
715e33c2482SVarun Prakash 	struct cxgbi_device *cdev = csk->cdev;
716e33c2482SVarun Prakash 	struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(cdev);
717e33c2482SVarun Prakash 	struct fw_ofld_tx_data_wr *req;
718e33c2482SVarun Prakash 	struct cpl_tx_data_iso *cpl;
719e33c2482SVarun Prakash 	u32 submode = cxgbi_skcb_tx_ulp_mode(skb) & 0x3;
720e33c2482SVarun Prakash 	u32 wr_ulp_mode = 0;
721e33c2482SVarun Prakash 	u32 hdr_size = sizeof(*req);
722e33c2482SVarun Prakash 	u32 opcode = FW_OFLD_TX_DATA_WR;
723e33c2482SVarun Prakash 	u32 immlen = 0;
724e33c2482SVarun Prakash 	u32 force = is_t5(lldi->adapter_type) ? TX_FORCE_V(!submode) :
725e33c2482SVarun Prakash 						T6_TX_FORCE_F;
726e33c2482SVarun Prakash 
727e33c2482SVarun Prakash 	if (cxgbi_skcb_test_flag(skb, SKCBF_TX_ISO)) {
728e33c2482SVarun Prakash 		hdr_size += sizeof(struct cpl_tx_data_iso);
729e33c2482SVarun Prakash 		opcode = FW_ISCSI_TX_DATA_WR;
730e33c2482SVarun Prakash 		immlen += sizeof(struct cpl_tx_data_iso);
731e33c2482SVarun Prakash 		submode |= 8;
732e33c2482SVarun Prakash 	}
733e33c2482SVarun Prakash 
734e33c2482SVarun Prakash 	if (is_ofld_imm(skb))
735e33c2482SVarun Prakash 		immlen += dlen;
736e33c2482SVarun Prakash 
737e33c2482SVarun Prakash 	req = (struct fw_ofld_tx_data_wr *)__skb_push(skb, hdr_size);
738e33c2482SVarun Prakash 	req->op_to_immdlen = cpu_to_be32(FW_WR_OP_V(opcode) |
739e33c2482SVarun Prakash 					 FW_WR_COMPL_V(compl) |
740e33c2482SVarun Prakash 					 FW_WR_IMMDLEN_V(immlen));
741e33c2482SVarun Prakash 	req->flowid_len16 = cpu_to_be32(FW_WR_FLOWID_V(csk->tid) |
742e33c2482SVarun Prakash 					FW_WR_LEN16_V(credits));
743e33c2482SVarun Prakash 	req->plen = cpu_to_be32(len);
744e33c2482SVarun Prakash 	cpl =  (struct cpl_tx_data_iso *)(req + 1);
745e33c2482SVarun Prakash 
746e33c2482SVarun Prakash 	if (likely(cxgbi_skcb_test_flag(skb, SKCBF_TX_ISO)))
747e33c2482SVarun Prakash 		cxgb4i_make_tx_iso_cpl(skb, cpl);
748e33c2482SVarun Prakash 
7497b36b6e0Skxie@chelsio.com 	if (submode)
750e2ac9628SHariprasad Shenai 		wr_ulp_mode = FW_OFLD_TX_DATA_WR_ULPMODE_V(ULP2_MODE_ISCSI) |
751e2ac9628SHariprasad Shenai 			      FW_OFLD_TX_DATA_WR_ULPSUBMODE_V(submode);
752e33c2482SVarun Prakash 
753e33c2482SVarun Prakash 	req->tunnel_to_proxy = cpu_to_be32(wr_ulp_mode | force |
754e33c2482SVarun Prakash 					   FW_OFLD_TX_DATA_WR_SHOVE_V(1U));
755e33c2482SVarun Prakash 
7567b36b6e0Skxie@chelsio.com 	if (!cxgbi_sock_flag(csk, CTPF_TX_DATA_SENT))
7577b36b6e0Skxie@chelsio.com 		cxgbi_sock_set_flag(csk, CTPF_TX_DATA_SENT);
7587b36b6e0Skxie@chelsio.com }
7597b36b6e0Skxie@chelsio.com 
7607b36b6e0Skxie@chelsio.com static void arp_failure_skb_discard(void *handle, struct sk_buff *skb)
7617b36b6e0Skxie@chelsio.com {
7627b36b6e0Skxie@chelsio.com 	kfree_skb(skb);
7637b36b6e0Skxie@chelsio.com }
7647b36b6e0Skxie@chelsio.com 
7657b36b6e0Skxie@chelsio.com static int push_tx_frames(struct cxgbi_sock *csk, int req_completion)
7667b36b6e0Skxie@chelsio.com {
7677b36b6e0Skxie@chelsio.com 	int total_size = 0;
7687b36b6e0Skxie@chelsio.com 	struct sk_buff *skb;
7697b36b6e0Skxie@chelsio.com 
7707b36b6e0Skxie@chelsio.com 	if (unlikely(csk->state < CTP_ESTABLISHED ||
7717b36b6e0Skxie@chelsio.com 		csk->state == CTP_CLOSE_WAIT_1 || csk->state >= CTP_ABORTING)) {
7727b36b6e0Skxie@chelsio.com 		log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK |
7737b36b6e0Skxie@chelsio.com 			  1 << CXGBI_DBG_PDU_TX,
7747b36b6e0Skxie@chelsio.com 			  "csk 0x%p,%u,0x%lx,%u, in closing state.\n",
7757b36b6e0Skxie@chelsio.com 			  csk, csk->state, csk->flags, csk->tid);
7767b36b6e0Skxie@chelsio.com 		return 0;
7777b36b6e0Skxie@chelsio.com 	}
7787b36b6e0Skxie@chelsio.com 
779e33c2482SVarun Prakash 	while (csk->wr_cred && ((skb = skb_peek(&csk->write_queue)) != NULL)) {
780e33c2482SVarun Prakash 		struct cxgbi_iso_info *iso_cpl;
781e33c2482SVarun Prakash 		u32 dlen = skb->len;
782e33c2482SVarun Prakash 		u32 len = skb->len;
783e33c2482SVarun Prakash 		u32 iso_cpl_len = 0;
784e33c2482SVarun Prakash 		u32 flowclen16 = 0;
785e33c2482SVarun Prakash 		u32 credits_needed;
786e33c2482SVarun Prakash 		u32 num_pdu = 1, hdr_len;
7877b36b6e0Skxie@chelsio.com 
788e33c2482SVarun Prakash 		if (cxgbi_skcb_test_flag(skb, SKCBF_TX_ISO))
789e33c2482SVarun Prakash 			iso_cpl_len = sizeof(struct cpl_tx_data_iso);
790e33c2482SVarun Prakash 
7917b36b6e0Skxie@chelsio.com 		if (is_ofld_imm(skb))
792e33c2482SVarun Prakash 			credits_needed = DIV_ROUND_UP(dlen + iso_cpl_len, 16);
7937b36b6e0Skxie@chelsio.com 		else
794e33c2482SVarun Prakash 			credits_needed =
795e33c2482SVarun Prakash 				DIV_ROUND_UP((8 * calc_tx_flits_ofld(skb)) +
796e33c2482SVarun Prakash 					     iso_cpl_len, 16);
79784944d8cSKaren Xie 
79884944d8cSKaren Xie 		if (likely(cxgbi_skcb_test_flag(skb, SKCBF_TX_NEED_HDR)))
799e33c2482SVarun Prakash 			credits_needed +=
800e33c2482SVarun Prakash 			   DIV_ROUND_UP(sizeof(struct fw_ofld_tx_data_wr), 16);
8017b36b6e0Skxie@chelsio.com 
80264bfead8SKaren Xie 		/*
80364bfead8SKaren Xie 		 * Assumes the initial credits is large enough to support
80464bfead8SKaren Xie 		 * fw_flowc_wr plus largest possible first payload
80564bfead8SKaren Xie 		 */
80664bfead8SKaren Xie 		if (!cxgbi_sock_flag(csk, CTPF_TX_DATA_SENT)) {
80764bfead8SKaren Xie 			flowclen16 = send_tx_flowc_wr(csk);
80864bfead8SKaren Xie 			csk->wr_cred -= flowclen16;
80964bfead8SKaren Xie 			csk->wr_una_cred += flowclen16;
81064bfead8SKaren Xie 			cxgbi_sock_set_flag(csk, CTPF_TX_DATA_SENT);
81164bfead8SKaren Xie 		}
81264bfead8SKaren Xie 
8137b36b6e0Skxie@chelsio.com 		if (csk->wr_cred < credits_needed) {
8147b36b6e0Skxie@chelsio.com 			log_debug(1 << CXGBI_DBG_PDU_TX,
8157b36b6e0Skxie@chelsio.com 				  "csk 0x%p, skb %u/%u, wr %d < %u.\n",
8167b36b6e0Skxie@chelsio.com 				  csk, skb->len, skb->data_len,
8177b36b6e0Skxie@chelsio.com 				  credits_needed, csk->wr_cred);
818e33c2482SVarun Prakash 
819e33c2482SVarun Prakash 			csk->no_tx_credits++;
8207b36b6e0Skxie@chelsio.com 			break;
8217b36b6e0Skxie@chelsio.com 		}
822e33c2482SVarun Prakash 
823e33c2482SVarun Prakash 		csk->no_tx_credits = 0;
824e33c2482SVarun Prakash 
8257b36b6e0Skxie@chelsio.com 		__skb_unlink(skb, &csk->write_queue);
8262126bc5eSKaren Xie 		set_wr_txq(skb, CPL_PRIORITY_DATA, csk->port_id);
827e33c2482SVarun Prakash 		skb->csum = (__force __wsum)(credits_needed + flowclen16);
8287b36b6e0Skxie@chelsio.com 		csk->wr_cred -= credits_needed;
8297b36b6e0Skxie@chelsio.com 		csk->wr_una_cred += credits_needed;
8307b36b6e0Skxie@chelsio.com 		cxgbi_sock_enqueue_wr(csk, skb);
8317b36b6e0Skxie@chelsio.com 
8327b36b6e0Skxie@chelsio.com 		log_debug(1 << CXGBI_DBG_PDU_TX,
8337b36b6e0Skxie@chelsio.com 			"csk 0x%p, skb %u/%u, wr %d, left %u, unack %u.\n",
8347b36b6e0Skxie@chelsio.com 			csk, skb->len, skb->data_len, credits_needed,
8357b36b6e0Skxie@chelsio.com 			csk->wr_cred, csk->wr_una_cred);
8367b36b6e0Skxie@chelsio.com 
837e33c2482SVarun Prakash 		if (!req_completion &&
838e33c2482SVarun Prakash 		    ((csk->wr_una_cred >= (csk->wr_max_cred / 2)) ||
839e33c2482SVarun Prakash 		     after(csk->write_seq, (csk->snd_una + csk->snd_win / 2))))
840e33c2482SVarun Prakash 			req_completion = 1;
841e33c2482SVarun Prakash 
8427b36b6e0Skxie@chelsio.com 		if (likely(cxgbi_skcb_test_flag(skb, SKCBF_TX_NEED_HDR))) {
843e33c2482SVarun Prakash 			u32 ulp_mode = cxgbi_skcb_tx_ulp_mode(skb);
844e33c2482SVarun Prakash 
845e33c2482SVarun Prakash 			if (cxgbi_skcb_test_flag(skb, SKCBF_TX_ISO)) {
846e33c2482SVarun Prakash 				iso_cpl = (struct cxgbi_iso_info *)skb->head;
847e33c2482SVarun Prakash 				num_pdu = iso_cpl->num_pdu;
848e33c2482SVarun Prakash 				hdr_len = cxgbi_skcb_tx_iscsi_hdrlen(skb);
849e33c2482SVarun Prakash 				len += (cxgbi_ulp_extra_len(ulp_mode) * num_pdu) +
850e33c2482SVarun Prakash 				       (hdr_len * (num_pdu - 1));
851e33c2482SVarun Prakash 			} else {
852e33c2482SVarun Prakash 				len += cxgbi_ulp_extra_len(ulp_mode);
853e33c2482SVarun Prakash 			}
854e33c2482SVarun Prakash 
855e33c2482SVarun Prakash 			cxgb4i_make_tx_data_wr(csk, skb, dlen, len,
856e33c2482SVarun Prakash 					       credits_needed, req_completion);
8577b36b6e0Skxie@chelsio.com 			csk->snd_nxt += len;
8587b36b6e0Skxie@chelsio.com 			cxgbi_skcb_clear_flag(skb, SKCBF_TX_NEED_HDR);
859fe9b34bfSVarun Prakash 		} else if (cxgbi_skcb_test_flag(skb, SKCBF_TX_FLAG_COMPL) &&
860fe9b34bfSVarun Prakash 			   (csk->wr_una_cred >= (csk->wr_max_cred / 2))) {
861fe9b34bfSVarun Prakash 			struct cpl_close_con_req *req =
862fe9b34bfSVarun Prakash 				(struct cpl_close_con_req *)skb->data;
863e33c2482SVarun Prakash 
864e33c2482SVarun Prakash 			req->wr.wr_hi |= cpu_to_be32(FW_WR_COMPL_F);
8657b36b6e0Skxie@chelsio.com 		}
866e33c2482SVarun Prakash 
8677b36b6e0Skxie@chelsio.com 		total_size += skb->truesize;
8687b36b6e0Skxie@chelsio.com 		t4_set_arp_err_handler(skb, csk, arp_failure_skb_discard);
8697b36b6e0Skxie@chelsio.com 
8707b36b6e0Skxie@chelsio.com 		log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_PDU_TX,
8717b36b6e0Skxie@chelsio.com 			  "csk 0x%p,%u,0x%lx,%u, skb 0x%p, %u.\n",
8727b36b6e0Skxie@chelsio.com 			  csk, csk->state, csk->flags, csk->tid, skb, len);
8737b36b6e0Skxie@chelsio.com 		cxgb4_l2t_send(csk->cdev->ports[csk->port_id], skb, csk->l2t);
8747b36b6e0Skxie@chelsio.com 	}
8757b36b6e0Skxie@chelsio.com 	return total_size;
8767b36b6e0Skxie@chelsio.com }
8777b36b6e0Skxie@chelsio.com 
8787b36b6e0Skxie@chelsio.com static inline void free_atid(struct cxgbi_sock *csk)
8797b36b6e0Skxie@chelsio.com {
8807b36b6e0Skxie@chelsio.com 	struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(csk->cdev);
8817b36b6e0Skxie@chelsio.com 
8827b36b6e0Skxie@chelsio.com 	if (cxgbi_sock_flag(csk, CTPF_HAS_ATID)) {
8837b36b6e0Skxie@chelsio.com 		cxgb4_free_atid(lldi->tids, csk->atid);
8847b36b6e0Skxie@chelsio.com 		cxgbi_sock_clear_flag(csk, CTPF_HAS_ATID);
8857b36b6e0Skxie@chelsio.com 		cxgbi_sock_put(csk);
8867b36b6e0Skxie@chelsio.com 	}
8877b36b6e0Skxie@chelsio.com }
8887b36b6e0Skxie@chelsio.com 
8897b36b6e0Skxie@chelsio.com static void do_act_establish(struct cxgbi_device *cdev, struct sk_buff *skb)
8907b36b6e0Skxie@chelsio.com {
8917b36b6e0Skxie@chelsio.com 	struct cxgbi_sock *csk;
8927b36b6e0Skxie@chelsio.com 	struct cpl_act_establish *req = (struct cpl_act_establish *)skb->data;
8937b36b6e0Skxie@chelsio.com 	unsigned short tcp_opt = ntohs(req->tcp_opt);
8947b36b6e0Skxie@chelsio.com 	unsigned int tid = GET_TID(req);
8956c53e938SHariprasad Shenai 	unsigned int atid = TID_TID_G(ntohl(req->tos_atid));
8967b36b6e0Skxie@chelsio.com 	struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(cdev);
8977b36b6e0Skxie@chelsio.com 	struct tid_info *t = lldi->tids;
8987b36b6e0Skxie@chelsio.com 	u32 rcv_isn = be32_to_cpu(req->rcv_isn);
8997b36b6e0Skxie@chelsio.com 
9007b36b6e0Skxie@chelsio.com 	csk = lookup_atid(t, atid);
9017b36b6e0Skxie@chelsio.com 	if (unlikely(!csk)) {
9027b36b6e0Skxie@chelsio.com 		pr_err("NO conn. for atid %u, cdev 0x%p.\n", atid, cdev);
9037b36b6e0Skxie@chelsio.com 		goto rel_skb;
9047b36b6e0Skxie@chelsio.com 	}
9057b36b6e0Skxie@chelsio.com 
906e27d6169Skxie@chelsio.com 	if (csk->atid != atid) {
907e27d6169Skxie@chelsio.com 		pr_err("bad conn atid %u, csk 0x%p,%u,0x%lx,tid %u, atid %u.\n",
908e27d6169Skxie@chelsio.com 			atid, csk, csk->state, csk->flags, csk->tid, csk->atid);
909e27d6169Skxie@chelsio.com 		goto rel_skb;
910e27d6169Skxie@chelsio.com 	}
911e27d6169Skxie@chelsio.com 
912759a0cc5SAnish Bhatt 	pr_info_ipaddr("atid 0x%x, tid 0x%x, csk 0x%p,%u,0x%lx, isn %u.\n",
913759a0cc5SAnish Bhatt 		       (&csk->saddr), (&csk->daddr),
914759a0cc5SAnish Bhatt 		       atid, tid, csk, csk->state, csk->flags, rcv_isn);
915759a0cc5SAnish Bhatt 
9161fe1fdb0SVarun Prakash 	module_put(cdev->owner);
9177b36b6e0Skxie@chelsio.com 
9187b36b6e0Skxie@chelsio.com 	cxgbi_sock_get(csk);
9197b36b6e0Skxie@chelsio.com 	csk->tid = tid;
9201dec4cecSGanesh Goudar 	cxgb4_insert_tid(lldi->tids, csk, tid, csk->csk_family);
9217b36b6e0Skxie@chelsio.com 	cxgbi_sock_set_flag(csk, CTPF_HAS_TID);
9227b36b6e0Skxie@chelsio.com 
9237b36b6e0Skxie@chelsio.com 	free_atid(csk);
9247b36b6e0Skxie@chelsio.com 
9257b36b6e0Skxie@chelsio.com 	spin_lock_bh(&csk->lock);
9267b36b6e0Skxie@chelsio.com 	if (unlikely(csk->state != CTP_ACTIVE_OPEN))
9277b36b6e0Skxie@chelsio.com 		pr_info("csk 0x%p,%u,0x%lx,%u, got EST.\n",
9287b36b6e0Skxie@chelsio.com 			csk, csk->state, csk->flags, csk->tid);
9297b36b6e0Skxie@chelsio.com 
9307b36b6e0Skxie@chelsio.com 	if (csk->retry_timer.function) {
9317b36b6e0Skxie@chelsio.com 		del_timer(&csk->retry_timer);
9327b36b6e0Skxie@chelsio.com 		csk->retry_timer.function = NULL;
9337b36b6e0Skxie@chelsio.com 	}
9347b36b6e0Skxie@chelsio.com 
9357b36b6e0Skxie@chelsio.com 	csk->copied_seq = csk->rcv_wup = csk->rcv_nxt = rcv_isn;
9367b36b6e0Skxie@chelsio.com 	/*
9377b36b6e0Skxie@chelsio.com 	 * Causes the first RX_DATA_ACK to supply any Rx credits we couldn't
9387b36b6e0Skxie@chelsio.com 	 * pass through opt0.
9397b36b6e0Skxie@chelsio.com 	 */
94081daf10cSKaren Xie 	if (csk->rcv_win > (RCV_BUFSIZ_MASK << 10))
94181daf10cSKaren Xie 		csk->rcv_wup -= csk->rcv_win - (RCV_BUFSIZ_MASK << 10);
9427b36b6e0Skxie@chelsio.com 
9436c53e938SHariprasad Shenai 	csk->advmss = lldi->mtus[TCPOPT_MSS_G(tcp_opt)] - 40;
9446c53e938SHariprasad Shenai 	if (TCPOPT_TSTAMP_G(tcp_opt))
9457b36b6e0Skxie@chelsio.com 		csk->advmss -= 12;
9467b36b6e0Skxie@chelsio.com 	if (csk->advmss < 128)
9477b36b6e0Skxie@chelsio.com 		csk->advmss = 128;
9487b36b6e0Skxie@chelsio.com 
9497b36b6e0Skxie@chelsio.com 	log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
9507b36b6e0Skxie@chelsio.com 		"csk 0x%p, mss_idx %u, advmss %u.\n",
9516c53e938SHariprasad Shenai 			csk, TCPOPT_MSS_G(tcp_opt), csk->advmss);
9527b36b6e0Skxie@chelsio.com 
9537b36b6e0Skxie@chelsio.com 	cxgbi_sock_established(csk, ntohl(req->snd_isn), ntohs(req->tcp_opt));
9547b36b6e0Skxie@chelsio.com 
9557b36b6e0Skxie@chelsio.com 	if (unlikely(cxgbi_sock_flag(csk, CTPF_ACTIVE_CLOSE_NEEDED)))
9567b36b6e0Skxie@chelsio.com 		send_abort_req(csk);
9577b36b6e0Skxie@chelsio.com 	else {
9587b36b6e0Skxie@chelsio.com 		if (skb_queue_len(&csk->write_queue))
9597b36b6e0Skxie@chelsio.com 			push_tx_frames(csk, 0);
9607b36b6e0Skxie@chelsio.com 		cxgbi_conn_tx_open(csk);
9617b36b6e0Skxie@chelsio.com 	}
9627b36b6e0Skxie@chelsio.com 	spin_unlock_bh(&csk->lock);
9637b36b6e0Skxie@chelsio.com 
9647b36b6e0Skxie@chelsio.com rel_skb:
9657b36b6e0Skxie@chelsio.com 	__kfree_skb(skb);
9667b36b6e0Skxie@chelsio.com }
9677b36b6e0Skxie@chelsio.com 
9687b36b6e0Skxie@chelsio.com static int act_open_rpl_status_to_errno(int status)
9697b36b6e0Skxie@chelsio.com {
9707b36b6e0Skxie@chelsio.com 	switch (status) {
9717b36b6e0Skxie@chelsio.com 	case CPL_ERR_CONN_RESET:
9727b36b6e0Skxie@chelsio.com 		return -ECONNREFUSED;
9737b36b6e0Skxie@chelsio.com 	case CPL_ERR_ARP_MISS:
9747b36b6e0Skxie@chelsio.com 		return -EHOSTUNREACH;
9757b36b6e0Skxie@chelsio.com 	case CPL_ERR_CONN_TIMEDOUT:
9767b36b6e0Skxie@chelsio.com 		return -ETIMEDOUT;
9777b36b6e0Skxie@chelsio.com 	case CPL_ERR_TCAM_FULL:
9787b36b6e0Skxie@chelsio.com 		return -ENOMEM;
9797b36b6e0Skxie@chelsio.com 	case CPL_ERR_CONN_EXIST:
9807b36b6e0Skxie@chelsio.com 		return -EADDRINUSE;
9817b36b6e0Skxie@chelsio.com 	default:
9827b36b6e0Skxie@chelsio.com 		return -EIO;
9837b36b6e0Skxie@chelsio.com 	}
9847b36b6e0Skxie@chelsio.com }
9857b36b6e0Skxie@chelsio.com 
986cd07f958SKees Cook static void csk_act_open_retry_timer(struct timer_list *t)
9877b36b6e0Skxie@chelsio.com {
988001586a7SAnish Bhatt 	struct sk_buff *skb = NULL;
989cd07f958SKees Cook 	struct cxgbi_sock *csk = from_timer(csk, t, retry_timer);
9903bd3e8bfSKaren Xie 	struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(csk->cdev);
991759a0cc5SAnish Bhatt 	void (*send_act_open_func)(struct cxgbi_sock *, struct sk_buff *,
992759a0cc5SAnish Bhatt 				   struct l2t_entry *);
993759a0cc5SAnish Bhatt 	int t4 = is_t4(lldi->adapter_type), size, size6;
9947b36b6e0Skxie@chelsio.com 
9957b36b6e0Skxie@chelsio.com 	log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
9967b36b6e0Skxie@chelsio.com 		"csk 0x%p,%u,0x%lx,%u.\n",
9977b36b6e0Skxie@chelsio.com 		csk, csk->state, csk->flags, csk->tid);
9987b36b6e0Skxie@chelsio.com 
9997b36b6e0Skxie@chelsio.com 	cxgbi_sock_get(csk);
10007b36b6e0Skxie@chelsio.com 	spin_lock_bh(&csk->lock);
1001759a0cc5SAnish Bhatt 
1002759a0cc5SAnish Bhatt 	if (t4) {
1003759a0cc5SAnish Bhatt 		size = sizeof(struct cpl_act_open_req);
1004759a0cc5SAnish Bhatt 		size6 = sizeof(struct cpl_act_open_req6);
1005759a0cc5SAnish Bhatt 	} else {
1006759a0cc5SAnish Bhatt 		size = sizeof(struct cpl_t5_act_open_req);
1007759a0cc5SAnish Bhatt 		size6 = sizeof(struct cpl_t5_act_open_req6);
1008759a0cc5SAnish Bhatt 	}
1009759a0cc5SAnish Bhatt 
1010759a0cc5SAnish Bhatt 	if (csk->csk_family == AF_INET) {
1011759a0cc5SAnish Bhatt 		send_act_open_func = send_act_open_req;
1012759a0cc5SAnish Bhatt 		skb = alloc_wr(size, 0, GFP_ATOMIC);
1013f42bb57cSAnish Bhatt #if IS_ENABLED(CONFIG_IPV6)
1014759a0cc5SAnish Bhatt 	} else {
1015759a0cc5SAnish Bhatt 		send_act_open_func = send_act_open_req6;
1016759a0cc5SAnish Bhatt 		skb = alloc_wr(size6, 0, GFP_ATOMIC);
1017f42bb57cSAnish Bhatt #endif
1018759a0cc5SAnish Bhatt 	}
1019759a0cc5SAnish Bhatt 
10207b36b6e0Skxie@chelsio.com 	if (!skb)
10217b36b6e0Skxie@chelsio.com 		cxgbi_sock_fail_act_open(csk, -ENOMEM);
10227b36b6e0Skxie@chelsio.com 	else {
10237b36b6e0Skxie@chelsio.com 		skb->sk = (struct sock *)csk;
10247b36b6e0Skxie@chelsio.com 		t4_set_arp_err_handler(skb, csk,
10257b36b6e0Skxie@chelsio.com 				       cxgbi_sock_act_open_req_arp_failure);
1026759a0cc5SAnish Bhatt 		send_act_open_func(csk, skb, csk->l2t);
10277b36b6e0Skxie@chelsio.com 	}
1028759a0cc5SAnish Bhatt 
10297b36b6e0Skxie@chelsio.com 	spin_unlock_bh(&csk->lock);
10307b36b6e0Skxie@chelsio.com 	cxgbi_sock_put(csk);
1031759a0cc5SAnish Bhatt 
10327b36b6e0Skxie@chelsio.com }
10337b36b6e0Skxie@chelsio.com 
1034928567adSKaren Xie static inline bool is_neg_adv(unsigned int status)
1035928567adSKaren Xie {
1036928567adSKaren Xie 	return status == CPL_ERR_RTX_NEG_ADVICE ||
1037928567adSKaren Xie 		status == CPL_ERR_KEEPALV_NEG_ADVICE ||
1038928567adSKaren Xie 		status == CPL_ERR_PERSIST_NEG_ADVICE;
1039928567adSKaren Xie }
1040928567adSKaren Xie 
10417b36b6e0Skxie@chelsio.com static void do_act_open_rpl(struct cxgbi_device *cdev, struct sk_buff *skb)
10427b36b6e0Skxie@chelsio.com {
10437b36b6e0Skxie@chelsio.com 	struct cxgbi_sock *csk;
10447b36b6e0Skxie@chelsio.com 	struct cpl_act_open_rpl *rpl = (struct cpl_act_open_rpl *)skb->data;
10457b36b6e0Skxie@chelsio.com 	unsigned int tid = GET_TID(rpl);
10467b36b6e0Skxie@chelsio.com 	unsigned int atid =
10476c53e938SHariprasad Shenai 		TID_TID_G(AOPEN_ATID_G(be32_to_cpu(rpl->atid_status)));
10486c53e938SHariprasad Shenai 	unsigned int status = AOPEN_STATUS_G(be32_to_cpu(rpl->atid_status));
10497b36b6e0Skxie@chelsio.com 	struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(cdev);
10507b36b6e0Skxie@chelsio.com 	struct tid_info *t = lldi->tids;
10517b36b6e0Skxie@chelsio.com 
10527b36b6e0Skxie@chelsio.com 	csk = lookup_atid(t, atid);
10537b36b6e0Skxie@chelsio.com 	if (unlikely(!csk)) {
10547b36b6e0Skxie@chelsio.com 		pr_err("NO matching conn. atid %u, tid %u.\n", atid, tid);
10557b36b6e0Skxie@chelsio.com 		goto rel_skb;
10567b36b6e0Skxie@chelsio.com 	}
10577b36b6e0Skxie@chelsio.com 
1058759a0cc5SAnish Bhatt 	pr_info_ipaddr("tid %u/%u, status %u.\n"
1059759a0cc5SAnish Bhatt 		       "csk 0x%p,%u,0x%lx. ", (&csk->saddr), (&csk->daddr),
1060e27d6169Skxie@chelsio.com 		       atid, tid, status, csk, csk->state, csk->flags);
10617b36b6e0Skxie@chelsio.com 
1062928567adSKaren Xie 	if (is_neg_adv(status))
1063150cca7cSKaren Xie 		goto rel_skb;
1064150cca7cSKaren Xie 
10651fe1fdb0SVarun Prakash 	module_put(cdev->owner);
1066ee7255adSAnish Bhatt 
10677b36b6e0Skxie@chelsio.com 	if (status && status != CPL_ERR_TCAM_FULL &&
10687b36b6e0Skxie@chelsio.com 	    status != CPL_ERR_CONN_EXIST &&
10697b36b6e0Skxie@chelsio.com 	    status != CPL_ERR_ARP_MISS)
10701dec4cecSGanesh Goudar 		cxgb4_remove_tid(lldi->tids, csk->port_id, GET_TID(rpl),
10711dec4cecSGanesh Goudar 				 csk->csk_family);
10727b36b6e0Skxie@chelsio.com 
10737b36b6e0Skxie@chelsio.com 	cxgbi_sock_get(csk);
10747b36b6e0Skxie@chelsio.com 	spin_lock_bh(&csk->lock);
10757b36b6e0Skxie@chelsio.com 
10767b36b6e0Skxie@chelsio.com 	if (status == CPL_ERR_CONN_EXIST &&
1077841b86f3SKees Cook 	    csk->retry_timer.function != csk_act_open_retry_timer) {
1078841b86f3SKees Cook 		csk->retry_timer.function = csk_act_open_retry_timer;
10797b36b6e0Skxie@chelsio.com 		mod_timer(&csk->retry_timer, jiffies + HZ / 2);
10807b36b6e0Skxie@chelsio.com 	} else
10817b36b6e0Skxie@chelsio.com 		cxgbi_sock_fail_act_open(csk,
10827b36b6e0Skxie@chelsio.com 					act_open_rpl_status_to_errno(status));
10837b36b6e0Skxie@chelsio.com 
10847b36b6e0Skxie@chelsio.com 	spin_unlock_bh(&csk->lock);
10857b36b6e0Skxie@chelsio.com 	cxgbi_sock_put(csk);
10867b36b6e0Skxie@chelsio.com rel_skb:
10877b36b6e0Skxie@chelsio.com 	__kfree_skb(skb);
10887b36b6e0Skxie@chelsio.com }
10897b36b6e0Skxie@chelsio.com 
10907b36b6e0Skxie@chelsio.com static void do_peer_close(struct cxgbi_device *cdev, struct sk_buff *skb)
10917b36b6e0Skxie@chelsio.com {
10927b36b6e0Skxie@chelsio.com 	struct cxgbi_sock *csk;
10937b36b6e0Skxie@chelsio.com 	struct cpl_peer_close *req = (struct cpl_peer_close *)skb->data;
10947b36b6e0Skxie@chelsio.com 	unsigned int tid = GET_TID(req);
10957b36b6e0Skxie@chelsio.com 	struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(cdev);
10967b36b6e0Skxie@chelsio.com 	struct tid_info *t = lldi->tids;
10977b36b6e0Skxie@chelsio.com 
10987b36b6e0Skxie@chelsio.com 	csk = lookup_tid(t, tid);
10997b36b6e0Skxie@chelsio.com 	if (unlikely(!csk)) {
11007b36b6e0Skxie@chelsio.com 		pr_err("can't find connection for tid %u.\n", tid);
11017b36b6e0Skxie@chelsio.com 		goto rel_skb;
11027b36b6e0Skxie@chelsio.com 	}
1103759a0cc5SAnish Bhatt 	pr_info_ipaddr("csk 0x%p,%u,0x%lx,%u.\n",
1104759a0cc5SAnish Bhatt 		       (&csk->saddr), (&csk->daddr),
11057b36b6e0Skxie@chelsio.com 		       csk, csk->state, csk->flags, csk->tid);
11067b36b6e0Skxie@chelsio.com 	cxgbi_sock_rcv_peer_close(csk);
11077b36b6e0Skxie@chelsio.com rel_skb:
11087b36b6e0Skxie@chelsio.com 	__kfree_skb(skb);
11097b36b6e0Skxie@chelsio.com }
11107b36b6e0Skxie@chelsio.com 
11117b36b6e0Skxie@chelsio.com static void do_close_con_rpl(struct cxgbi_device *cdev, struct sk_buff *skb)
11127b36b6e0Skxie@chelsio.com {
11137b36b6e0Skxie@chelsio.com 	struct cxgbi_sock *csk;
11147b36b6e0Skxie@chelsio.com 	struct cpl_close_con_rpl *rpl = (struct cpl_close_con_rpl *)skb->data;
11157b36b6e0Skxie@chelsio.com 	unsigned int tid = GET_TID(rpl);
11167b36b6e0Skxie@chelsio.com 	struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(cdev);
11177b36b6e0Skxie@chelsio.com 	struct tid_info *t = lldi->tids;
11187b36b6e0Skxie@chelsio.com 
11197b36b6e0Skxie@chelsio.com 	csk = lookup_tid(t, tid);
11207b36b6e0Skxie@chelsio.com 	if (unlikely(!csk)) {
11217b36b6e0Skxie@chelsio.com 		pr_err("can't find connection for tid %u.\n", tid);
11227b36b6e0Skxie@chelsio.com 		goto rel_skb;
11237b36b6e0Skxie@chelsio.com 	}
1124759a0cc5SAnish Bhatt 	pr_info_ipaddr("csk 0x%p,%u,0x%lx,%u.\n",
1125759a0cc5SAnish Bhatt 		       (&csk->saddr), (&csk->daddr),
11267b36b6e0Skxie@chelsio.com 		       csk, csk->state, csk->flags, csk->tid);
11277b36b6e0Skxie@chelsio.com 	cxgbi_sock_rcv_close_conn_rpl(csk, ntohl(rpl->snd_nxt));
11287b36b6e0Skxie@chelsio.com rel_skb:
11297b36b6e0Skxie@chelsio.com 	__kfree_skb(skb);
11307b36b6e0Skxie@chelsio.com }
11317b36b6e0Skxie@chelsio.com 
11327b36b6e0Skxie@chelsio.com static int abort_status_to_errno(struct cxgbi_sock *csk, int abort_reason,
11337b36b6e0Skxie@chelsio.com 								int *need_rst)
11347b36b6e0Skxie@chelsio.com {
11357b36b6e0Skxie@chelsio.com 	switch (abort_reason) {
11367b36b6e0Skxie@chelsio.com 	case CPL_ERR_BAD_SYN: /* fall through */
11377b36b6e0Skxie@chelsio.com 	case CPL_ERR_CONN_RESET:
11387b36b6e0Skxie@chelsio.com 		return csk->state > CTP_ESTABLISHED ?
11397b36b6e0Skxie@chelsio.com 			-EPIPE : -ECONNRESET;
11407b36b6e0Skxie@chelsio.com 	case CPL_ERR_XMIT_TIMEDOUT:
11417b36b6e0Skxie@chelsio.com 	case CPL_ERR_PERSIST_TIMEDOUT:
11427b36b6e0Skxie@chelsio.com 	case CPL_ERR_FINWAIT2_TIMEDOUT:
11437b36b6e0Skxie@chelsio.com 	case CPL_ERR_KEEPALIVE_TIMEDOUT:
11447b36b6e0Skxie@chelsio.com 		return -ETIMEDOUT;
11457b36b6e0Skxie@chelsio.com 	default:
11467b36b6e0Skxie@chelsio.com 		return -EIO;
11477b36b6e0Skxie@chelsio.com 	}
11487b36b6e0Skxie@chelsio.com }
11497b36b6e0Skxie@chelsio.com 
11507b36b6e0Skxie@chelsio.com static void do_abort_req_rss(struct cxgbi_device *cdev, struct sk_buff *skb)
11517b36b6e0Skxie@chelsio.com {
11527b36b6e0Skxie@chelsio.com 	struct cxgbi_sock *csk;
11537b36b6e0Skxie@chelsio.com 	struct cpl_abort_req_rss *req = (struct cpl_abort_req_rss *)skb->data;
11547b36b6e0Skxie@chelsio.com 	unsigned int tid = GET_TID(req);
11557b36b6e0Skxie@chelsio.com 	struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(cdev);
11567b36b6e0Skxie@chelsio.com 	struct tid_info *t = lldi->tids;
11577b36b6e0Skxie@chelsio.com 	int rst_status = CPL_ABORT_NO_RST;
11587b36b6e0Skxie@chelsio.com 
11597b36b6e0Skxie@chelsio.com 	csk = lookup_tid(t, tid);
11607b36b6e0Skxie@chelsio.com 	if (unlikely(!csk)) {
11617b36b6e0Skxie@chelsio.com 		pr_err("can't find connection for tid %u.\n", tid);
11627b36b6e0Skxie@chelsio.com 		goto rel_skb;
11637b36b6e0Skxie@chelsio.com 	}
11647b36b6e0Skxie@chelsio.com 
1165759a0cc5SAnish Bhatt 	pr_info_ipaddr("csk 0x%p,%u,0x%lx,%u, status %u.\n",
1166759a0cc5SAnish Bhatt 		       (&csk->saddr), (&csk->daddr),
11677b36b6e0Skxie@chelsio.com 		       csk, csk->state, csk->flags, csk->tid, req->status);
11687b36b6e0Skxie@chelsio.com 
1169928567adSKaren Xie 	if (is_neg_adv(req->status))
11707b36b6e0Skxie@chelsio.com 		goto rel_skb;
11717b36b6e0Skxie@chelsio.com 
11727b36b6e0Skxie@chelsio.com 	cxgbi_sock_get(csk);
11737b36b6e0Skxie@chelsio.com 	spin_lock_bh(&csk->lock);
11747b36b6e0Skxie@chelsio.com 
11757b07bf24SAnish Bhatt 	cxgbi_sock_clear_flag(csk, CTPF_ABORT_REQ_RCVD);
11767b07bf24SAnish Bhatt 
11777b07bf24SAnish Bhatt 	if (!cxgbi_sock_flag(csk, CTPF_TX_DATA_SENT)) {
11787b07bf24SAnish Bhatt 		send_tx_flowc_wr(csk);
11797b07bf24SAnish Bhatt 		cxgbi_sock_set_flag(csk, CTPF_TX_DATA_SENT);
11807b36b6e0Skxie@chelsio.com 	}
11817b36b6e0Skxie@chelsio.com 
11827b07bf24SAnish Bhatt 	cxgbi_sock_set_flag(csk, CTPF_ABORT_REQ_RCVD);
11837b07bf24SAnish Bhatt 	cxgbi_sock_set_state(csk, CTP_ABORTING);
11847b07bf24SAnish Bhatt 
11857b36b6e0Skxie@chelsio.com 	send_abort_rpl(csk, rst_status);
11867b36b6e0Skxie@chelsio.com 
11877b36b6e0Skxie@chelsio.com 	if (!cxgbi_sock_flag(csk, CTPF_ABORT_RPL_PENDING)) {
11887b36b6e0Skxie@chelsio.com 		csk->err = abort_status_to_errno(csk, req->status, &rst_status);
11897b36b6e0Skxie@chelsio.com 		cxgbi_sock_closed(csk);
11907b36b6e0Skxie@chelsio.com 	}
11917b07bf24SAnish Bhatt 
11927b36b6e0Skxie@chelsio.com 	spin_unlock_bh(&csk->lock);
11937b36b6e0Skxie@chelsio.com 	cxgbi_sock_put(csk);
11947b36b6e0Skxie@chelsio.com rel_skb:
11957b36b6e0Skxie@chelsio.com 	__kfree_skb(skb);
11967b36b6e0Skxie@chelsio.com }
11977b36b6e0Skxie@chelsio.com 
11987b36b6e0Skxie@chelsio.com static void do_abort_rpl_rss(struct cxgbi_device *cdev, struct sk_buff *skb)
11997b36b6e0Skxie@chelsio.com {
12007b36b6e0Skxie@chelsio.com 	struct cxgbi_sock *csk;
12017b36b6e0Skxie@chelsio.com 	struct cpl_abort_rpl_rss *rpl = (struct cpl_abort_rpl_rss *)skb->data;
12027b36b6e0Skxie@chelsio.com 	unsigned int tid = GET_TID(rpl);
12037b36b6e0Skxie@chelsio.com 	struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(cdev);
12047b36b6e0Skxie@chelsio.com 	struct tid_info *t = lldi->tids;
12057b36b6e0Skxie@chelsio.com 
12067b36b6e0Skxie@chelsio.com 	csk = lookup_tid(t, tid);
12077b36b6e0Skxie@chelsio.com 	if (!csk)
12087b36b6e0Skxie@chelsio.com 		goto rel_skb;
12097b36b6e0Skxie@chelsio.com 
1210759a0cc5SAnish Bhatt 	pr_info_ipaddr("csk 0x%p,%u,0x%lx,%u, status %u.\n",
1211759a0cc5SAnish Bhatt 		       (&csk->saddr), (&csk->daddr), csk,
1212759a0cc5SAnish Bhatt 		       csk->state, csk->flags, csk->tid, rpl->status);
12137b36b6e0Skxie@chelsio.com 
12147b36b6e0Skxie@chelsio.com 	if (rpl->status == CPL_ERR_ABORT_FAILED)
12157b36b6e0Skxie@chelsio.com 		goto rel_skb;
12167b36b6e0Skxie@chelsio.com 
12177b36b6e0Skxie@chelsio.com 	cxgbi_sock_rcv_abort_rpl(csk);
12187b36b6e0Skxie@chelsio.com rel_skb:
12197b36b6e0Skxie@chelsio.com 	__kfree_skb(skb);
12207b36b6e0Skxie@chelsio.com }
12217b36b6e0Skxie@chelsio.com 
1222f7bcd2e1SKaren Xie static void do_rx_data(struct cxgbi_device *cdev, struct sk_buff *skb)
1223f7bcd2e1SKaren Xie {
1224f7bcd2e1SKaren Xie 	struct cxgbi_sock *csk;
1225f7bcd2e1SKaren Xie 	struct cpl_rx_data *cpl = (struct cpl_rx_data *)skb->data;
1226f7bcd2e1SKaren Xie 	unsigned int tid = GET_TID(cpl);
1227f7bcd2e1SKaren Xie 	struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(cdev);
1228f7bcd2e1SKaren Xie 	struct tid_info *t = lldi->tids;
1229f7bcd2e1SKaren Xie 
1230f7bcd2e1SKaren Xie 	csk = lookup_tid(t, tid);
1231f7bcd2e1SKaren Xie 	if (!csk) {
1232f7bcd2e1SKaren Xie 		pr_err("can't find connection for tid %u.\n", tid);
1233f7bcd2e1SKaren Xie 	} else {
1234f7bcd2e1SKaren Xie 		/* not expecting this, reset the connection. */
1235f7bcd2e1SKaren Xie 		pr_err("csk 0x%p, tid %u, rcv cpl_rx_data.\n", csk, tid);
1236f7bcd2e1SKaren Xie 		spin_lock_bh(&csk->lock);
1237f7bcd2e1SKaren Xie 		send_abort_req(csk);
1238f7bcd2e1SKaren Xie 		spin_unlock_bh(&csk->lock);
1239f7bcd2e1SKaren Xie 	}
1240f7bcd2e1SKaren Xie 	__kfree_skb(skb);
1241f7bcd2e1SKaren Xie }
1242f7bcd2e1SKaren Xie 
12437b36b6e0Skxie@chelsio.com static void do_rx_iscsi_hdr(struct cxgbi_device *cdev, struct sk_buff *skb)
12447b36b6e0Skxie@chelsio.com {
12457b36b6e0Skxie@chelsio.com 	struct cxgbi_sock *csk;
12467b36b6e0Skxie@chelsio.com 	struct cpl_iscsi_hdr *cpl = (struct cpl_iscsi_hdr *)skb->data;
12477b36b6e0Skxie@chelsio.com 	unsigned short pdu_len_ddp = be16_to_cpu(cpl->pdu_len_ddp);
12487b36b6e0Skxie@chelsio.com 	unsigned int tid = GET_TID(cpl);
12497b36b6e0Skxie@chelsio.com 	struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(cdev);
12507b36b6e0Skxie@chelsio.com 	struct tid_info *t = lldi->tids;
12517b36b6e0Skxie@chelsio.com 
12527b36b6e0Skxie@chelsio.com 	csk = lookup_tid(t, tid);
12537b36b6e0Skxie@chelsio.com 	if (unlikely(!csk)) {
12547b36b6e0Skxie@chelsio.com 		pr_err("can't find conn. for tid %u.\n", tid);
12557b36b6e0Skxie@chelsio.com 		goto rel_skb;
12567b36b6e0Skxie@chelsio.com 	}
12577b36b6e0Skxie@chelsio.com 
12587b36b6e0Skxie@chelsio.com 	log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_PDU_RX,
12597b36b6e0Skxie@chelsio.com 		"csk 0x%p,%u,0x%lx, tid %u, skb 0x%p,%u, 0x%x.\n",
12607b36b6e0Skxie@chelsio.com 		csk, csk->state, csk->flags, csk->tid, skb, skb->len,
12617b36b6e0Skxie@chelsio.com 		pdu_len_ddp);
12627b36b6e0Skxie@chelsio.com 
12637b36b6e0Skxie@chelsio.com 	spin_lock_bh(&csk->lock);
12647b36b6e0Skxie@chelsio.com 
12657b36b6e0Skxie@chelsio.com 	if (unlikely(csk->state >= CTP_PASSIVE_CLOSE)) {
12667b36b6e0Skxie@chelsio.com 		log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
12677b36b6e0Skxie@chelsio.com 			"csk 0x%p,%u,0x%lx,%u, bad state.\n",
12687b36b6e0Skxie@chelsio.com 			csk, csk->state, csk->flags, csk->tid);
12697b36b6e0Skxie@chelsio.com 		if (csk->state != CTP_ABORTING)
12707b36b6e0Skxie@chelsio.com 			goto abort_conn;
12717b36b6e0Skxie@chelsio.com 		else
12727b36b6e0Skxie@chelsio.com 			goto discard;
12737b36b6e0Skxie@chelsio.com 	}
12747b36b6e0Skxie@chelsio.com 
12757b36b6e0Skxie@chelsio.com 	cxgbi_skcb_tcp_seq(skb) = ntohl(cpl->seq);
1276e27d6169Skxie@chelsio.com 	cxgbi_skcb_flags(skb) = 0;
1277e27d6169Skxie@chelsio.com 
12787b36b6e0Skxie@chelsio.com 	skb_reset_transport_header(skb);
12797b36b6e0Skxie@chelsio.com 	__skb_pull(skb, sizeof(*cpl));
12807b36b6e0Skxie@chelsio.com 	__pskb_trim(skb, ntohs(cpl->len));
12817b36b6e0Skxie@chelsio.com 
12827b36b6e0Skxie@chelsio.com 	if (!csk->skb_ulp_lhdr) {
12837b36b6e0Skxie@chelsio.com 		unsigned char *bhs;
12843bd3e8bfSKaren Xie 		unsigned int hlen, dlen, plen;
12857b36b6e0Skxie@chelsio.com 
12867b36b6e0Skxie@chelsio.com 		log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_PDU_RX,
12877b36b6e0Skxie@chelsio.com 			"csk 0x%p,%u,0x%lx, tid %u, skb 0x%p header.\n",
12887b36b6e0Skxie@chelsio.com 			csk, csk->state, csk->flags, csk->tid, skb);
12897b36b6e0Skxie@chelsio.com 		csk->skb_ulp_lhdr = skb;
1290e27d6169Skxie@chelsio.com 		cxgbi_skcb_set_flag(skb, SKCBF_RX_HDR);
12917b36b6e0Skxie@chelsio.com 
129226af1a36SVarun Prakash 		if ((CHELSIO_CHIP_VERSION(lldi->adapter_type) <= CHELSIO_T5) &&
129326af1a36SVarun Prakash 		    (cxgbi_skcb_tcp_seq(skb) != csk->rcv_nxt)) {
12947b36b6e0Skxie@chelsio.com 			pr_info("tid %u, CPL_ISCSI_HDR, bad seq, 0x%x/0x%x.\n",
1295e27d6169Skxie@chelsio.com 				csk->tid, cxgbi_skcb_tcp_seq(skb),
12967b36b6e0Skxie@chelsio.com 				csk->rcv_nxt);
12977b36b6e0Skxie@chelsio.com 			goto abort_conn;
12987b36b6e0Skxie@chelsio.com 		}
12997b36b6e0Skxie@chelsio.com 
1300e27d6169Skxie@chelsio.com 		bhs = skb->data;
13017b36b6e0Skxie@chelsio.com 		hlen = ntohs(cpl->len);
13027b36b6e0Skxie@chelsio.com 		dlen = ntohl(*(unsigned int *)(bhs + 4)) & 0xFFFFFF;
13037b36b6e0Skxie@chelsio.com 
1304bdc590b9SHariprasad Shenai 		plen = ISCSI_PDU_LEN_G(pdu_len_ddp);
13053bd3e8bfSKaren Xie 		if (is_t4(lldi->adapter_type))
13063bd3e8bfSKaren Xie 			plen -= 40;
13073bd3e8bfSKaren Xie 
13083bd3e8bfSKaren Xie 		if ((hlen + dlen) != plen) {
13097b36b6e0Skxie@chelsio.com 			pr_info("tid 0x%x, CPL_ISCSI_HDR, pdu len "
13107b36b6e0Skxie@chelsio.com 				"mismatch %u != %u + %u, seq 0x%x.\n",
13113bd3e8bfSKaren Xie 				csk->tid, plen, hlen, dlen,
13123bd3e8bfSKaren Xie 				cxgbi_skcb_tcp_seq(skb));
13137b36b6e0Skxie@chelsio.com 			goto abort_conn;
13147b36b6e0Skxie@chelsio.com 		}
13157b36b6e0Skxie@chelsio.com 
13167b36b6e0Skxie@chelsio.com 		cxgbi_skcb_rx_pdulen(skb) = (hlen + dlen + 3) & (~0x3);
13177b36b6e0Skxie@chelsio.com 		if (dlen)
13187b36b6e0Skxie@chelsio.com 			cxgbi_skcb_rx_pdulen(skb) += csk->dcrc_len;
13197b36b6e0Skxie@chelsio.com 		csk->rcv_nxt += cxgbi_skcb_rx_pdulen(skb);
13207b36b6e0Skxie@chelsio.com 
13217b36b6e0Skxie@chelsio.com 		log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_PDU_RX,
13227b36b6e0Skxie@chelsio.com 			"csk 0x%p, skb 0x%p, 0x%x,%u+%u,0x%x,0x%x.\n",
13237b36b6e0Skxie@chelsio.com 			csk, skb, *bhs, hlen, dlen,
13247b36b6e0Skxie@chelsio.com 			ntohl(*((unsigned int *)(bhs + 16))),
13257b36b6e0Skxie@chelsio.com 			ntohl(*((unsigned int *)(bhs + 24))));
13267b36b6e0Skxie@chelsio.com 
13277b36b6e0Skxie@chelsio.com 	} else {
1328e27d6169Skxie@chelsio.com 		struct sk_buff *lskb = csk->skb_ulp_lhdr;
13297b36b6e0Skxie@chelsio.com 
1330e27d6169Skxie@chelsio.com 		cxgbi_skcb_set_flag(lskb, SKCBF_RX_DATA);
13317b36b6e0Skxie@chelsio.com 		log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_PDU_RX,
13327b36b6e0Skxie@chelsio.com 			"csk 0x%p,%u,0x%lx, skb 0x%p data, 0x%p.\n",
13337b36b6e0Skxie@chelsio.com 			csk, csk->state, csk->flags, skb, lskb);
13347b36b6e0Skxie@chelsio.com 	}
13357b36b6e0Skxie@chelsio.com 
13367b36b6e0Skxie@chelsio.com 	__skb_queue_tail(&csk->receive_queue, skb);
13377b36b6e0Skxie@chelsio.com 	spin_unlock_bh(&csk->lock);
13387b36b6e0Skxie@chelsio.com 	return;
13397b36b6e0Skxie@chelsio.com 
13407b36b6e0Skxie@chelsio.com abort_conn:
13417b36b6e0Skxie@chelsio.com 	send_abort_req(csk);
13427b36b6e0Skxie@chelsio.com discard:
13437b36b6e0Skxie@chelsio.com 	spin_unlock_bh(&csk->lock);
13447b36b6e0Skxie@chelsio.com rel_skb:
13457b36b6e0Skxie@chelsio.com 	__kfree_skb(skb);
13467b36b6e0Skxie@chelsio.com }
13477b36b6e0Skxie@chelsio.com 
134844830d8fSVarun Prakash static void do_rx_iscsi_data(struct cxgbi_device *cdev, struct sk_buff *skb)
134944830d8fSVarun Prakash {
135044830d8fSVarun Prakash 	struct cxgbi_sock *csk;
135144830d8fSVarun Prakash 	struct cpl_iscsi_hdr *cpl = (struct cpl_iscsi_hdr *)skb->data;
135244830d8fSVarun Prakash 	struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(cdev);
135344830d8fSVarun Prakash 	struct tid_info *t = lldi->tids;
135444830d8fSVarun Prakash 	struct sk_buff *lskb;
135544830d8fSVarun Prakash 	u32 tid = GET_TID(cpl);
135644830d8fSVarun Prakash 	u16 pdu_len_ddp = be16_to_cpu(cpl->pdu_len_ddp);
135744830d8fSVarun Prakash 
135844830d8fSVarun Prakash 	csk = lookup_tid(t, tid);
135944830d8fSVarun Prakash 	if (unlikely(!csk)) {
136044830d8fSVarun Prakash 		pr_err("can't find conn. for tid %u.\n", tid);
136144830d8fSVarun Prakash 		goto rel_skb;
136244830d8fSVarun Prakash 	}
136344830d8fSVarun Prakash 
136444830d8fSVarun Prakash 	log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_PDU_RX,
136544830d8fSVarun Prakash 		  "csk 0x%p,%u,0x%lx, tid %u, skb 0x%p,%u, 0x%x.\n",
136644830d8fSVarun Prakash 		  csk, csk->state, csk->flags, csk->tid, skb,
136744830d8fSVarun Prakash 		  skb->len, pdu_len_ddp);
136844830d8fSVarun Prakash 
136944830d8fSVarun Prakash 	spin_lock_bh(&csk->lock);
137044830d8fSVarun Prakash 
137144830d8fSVarun Prakash 	if (unlikely(csk->state >= CTP_PASSIVE_CLOSE)) {
137244830d8fSVarun Prakash 		log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
137344830d8fSVarun Prakash 			  "csk 0x%p,%u,0x%lx,%u, bad state.\n",
137444830d8fSVarun Prakash 			  csk, csk->state, csk->flags, csk->tid);
137544830d8fSVarun Prakash 
137644830d8fSVarun Prakash 		if (csk->state != CTP_ABORTING)
137744830d8fSVarun Prakash 			goto abort_conn;
137844830d8fSVarun Prakash 		else
137944830d8fSVarun Prakash 			goto discard;
138044830d8fSVarun Prakash 	}
138144830d8fSVarun Prakash 
138244830d8fSVarun Prakash 	cxgbi_skcb_tcp_seq(skb) = be32_to_cpu(cpl->seq);
138344830d8fSVarun Prakash 	cxgbi_skcb_flags(skb) = 0;
138444830d8fSVarun Prakash 
138544830d8fSVarun Prakash 	skb_reset_transport_header(skb);
138644830d8fSVarun Prakash 	__skb_pull(skb, sizeof(*cpl));
138744830d8fSVarun Prakash 	__pskb_trim(skb, ntohs(cpl->len));
138844830d8fSVarun Prakash 
138944830d8fSVarun Prakash 	if (!csk->skb_ulp_lhdr)
139044830d8fSVarun Prakash 		csk->skb_ulp_lhdr = skb;
139144830d8fSVarun Prakash 
139244830d8fSVarun Prakash 	lskb = csk->skb_ulp_lhdr;
139344830d8fSVarun Prakash 	cxgbi_skcb_set_flag(lskb, SKCBF_RX_DATA);
139444830d8fSVarun Prakash 
139544830d8fSVarun Prakash 	log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_PDU_RX,
139644830d8fSVarun Prakash 		  "csk 0x%p,%u,0x%lx, skb 0x%p data, 0x%p.\n",
139744830d8fSVarun Prakash 		  csk, csk->state, csk->flags, skb, lskb);
139844830d8fSVarun Prakash 
139944830d8fSVarun Prakash 	__skb_queue_tail(&csk->receive_queue, skb);
140044830d8fSVarun Prakash 	spin_unlock_bh(&csk->lock);
140144830d8fSVarun Prakash 	return;
140244830d8fSVarun Prakash 
140344830d8fSVarun Prakash abort_conn:
140444830d8fSVarun Prakash 	send_abort_req(csk);
140544830d8fSVarun Prakash discard:
140644830d8fSVarun Prakash 	spin_unlock_bh(&csk->lock);
140744830d8fSVarun Prakash rel_skb:
140844830d8fSVarun Prakash 	__kfree_skb(skb);
140944830d8fSVarun Prakash }
141044830d8fSVarun Prakash 
141144830d8fSVarun Prakash static void
141244830d8fSVarun Prakash cxgb4i_process_ddpvld(struct cxgbi_sock *csk,
141344830d8fSVarun Prakash 		      struct sk_buff *skb, u32 ddpvld)
141444830d8fSVarun Prakash {
141544830d8fSVarun Prakash 	if (ddpvld & (1 << CPL_RX_DDP_STATUS_HCRC_SHIFT)) {
141644830d8fSVarun Prakash 		pr_info("csk 0x%p, lhdr 0x%p, status 0x%x, hcrc bad 0x%lx.\n",
141744830d8fSVarun Prakash 			csk, skb, ddpvld, cxgbi_skcb_flags(skb));
141844830d8fSVarun Prakash 		cxgbi_skcb_set_flag(skb, SKCBF_RX_HCRC_ERR);
141944830d8fSVarun Prakash 	}
142044830d8fSVarun Prakash 
142144830d8fSVarun Prakash 	if (ddpvld & (1 << CPL_RX_DDP_STATUS_DCRC_SHIFT)) {
142244830d8fSVarun Prakash 		pr_info("csk 0x%p, lhdr 0x%p, status 0x%x, dcrc bad 0x%lx.\n",
142344830d8fSVarun Prakash 			csk, skb, ddpvld, cxgbi_skcb_flags(skb));
142444830d8fSVarun Prakash 		cxgbi_skcb_set_flag(skb, SKCBF_RX_DCRC_ERR);
142544830d8fSVarun Prakash 	}
142644830d8fSVarun Prakash 
142744830d8fSVarun Prakash 	if (ddpvld & (1 << CPL_RX_DDP_STATUS_PAD_SHIFT)) {
142844830d8fSVarun Prakash 		log_debug(1 << CXGBI_DBG_PDU_RX,
142944830d8fSVarun Prakash 			  "csk 0x%p, lhdr 0x%p, status 0x%x, pad bad.\n",
143044830d8fSVarun Prakash 			  csk, skb, ddpvld);
143144830d8fSVarun Prakash 		cxgbi_skcb_set_flag(skb, SKCBF_RX_PAD_ERR);
143244830d8fSVarun Prakash 	}
143344830d8fSVarun Prakash 
143444830d8fSVarun Prakash 	if ((ddpvld & (1 << CPL_RX_DDP_STATUS_DDP_SHIFT)) &&
143544830d8fSVarun Prakash 	    !cxgbi_skcb_test_flag(skb, SKCBF_RX_DATA)) {
143644830d8fSVarun Prakash 		log_debug(1 << CXGBI_DBG_PDU_RX,
143744830d8fSVarun Prakash 			  "csk 0x%p, lhdr 0x%p, 0x%x, data ddp'ed.\n",
143844830d8fSVarun Prakash 			  csk, skb, ddpvld);
143944830d8fSVarun Prakash 		cxgbi_skcb_set_flag(skb, SKCBF_RX_DATA_DDPD);
144044830d8fSVarun Prakash 	}
144144830d8fSVarun Prakash }
144244830d8fSVarun Prakash 
14437b36b6e0Skxie@chelsio.com static void do_rx_data_ddp(struct cxgbi_device *cdev,
14447b36b6e0Skxie@chelsio.com 				  struct sk_buff *skb)
14457b36b6e0Skxie@chelsio.com {
14467b36b6e0Skxie@chelsio.com 	struct cxgbi_sock *csk;
14477b36b6e0Skxie@chelsio.com 	struct sk_buff *lskb;
14487b36b6e0Skxie@chelsio.com 	struct cpl_rx_data_ddp *rpl = (struct cpl_rx_data_ddp *)skb->data;
14497b36b6e0Skxie@chelsio.com 	unsigned int tid = GET_TID(rpl);
14507b36b6e0Skxie@chelsio.com 	struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(cdev);
14517b36b6e0Skxie@chelsio.com 	struct tid_info *t = lldi->tids;
145244830d8fSVarun Prakash 	u32 ddpvld = be32_to_cpu(rpl->ddpvld);
14537b36b6e0Skxie@chelsio.com 
14547b36b6e0Skxie@chelsio.com 	csk = lookup_tid(t, tid);
14557b36b6e0Skxie@chelsio.com 	if (unlikely(!csk)) {
14567b36b6e0Skxie@chelsio.com 		pr_err("can't find connection for tid %u.\n", tid);
14577b36b6e0Skxie@chelsio.com 		goto rel_skb;
14587b36b6e0Skxie@chelsio.com 	}
14597b36b6e0Skxie@chelsio.com 
14607b36b6e0Skxie@chelsio.com 	log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_PDU_RX,
14617b36b6e0Skxie@chelsio.com 		"csk 0x%p,%u,0x%lx, skb 0x%p,0x%x, lhdr 0x%p.\n",
146244830d8fSVarun Prakash 		csk, csk->state, csk->flags, skb, ddpvld, csk->skb_ulp_lhdr);
14637b36b6e0Skxie@chelsio.com 
14647b36b6e0Skxie@chelsio.com 	spin_lock_bh(&csk->lock);
14657b36b6e0Skxie@chelsio.com 
14667b36b6e0Skxie@chelsio.com 	if (unlikely(csk->state >= CTP_PASSIVE_CLOSE)) {
14677b36b6e0Skxie@chelsio.com 		log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
14687b36b6e0Skxie@chelsio.com 			"csk 0x%p,%u,0x%lx,%u, bad state.\n",
14697b36b6e0Skxie@chelsio.com 			csk, csk->state, csk->flags, csk->tid);
14707b36b6e0Skxie@chelsio.com 		if (csk->state != CTP_ABORTING)
14717b36b6e0Skxie@chelsio.com 			goto abort_conn;
14727b36b6e0Skxie@chelsio.com 		else
14737b36b6e0Skxie@chelsio.com 			goto discard;
14747b36b6e0Skxie@chelsio.com 	}
14757b36b6e0Skxie@chelsio.com 
14767b36b6e0Skxie@chelsio.com 	if (!csk->skb_ulp_lhdr) {
14777b36b6e0Skxie@chelsio.com 		pr_err("tid 0x%x, rcv RX_DATA_DDP w/o pdu bhs.\n", csk->tid);
14787b36b6e0Skxie@chelsio.com 		goto abort_conn;
14797b36b6e0Skxie@chelsio.com 	}
14807b36b6e0Skxie@chelsio.com 
14817b36b6e0Skxie@chelsio.com 	lskb = csk->skb_ulp_lhdr;
14827b36b6e0Skxie@chelsio.com 	csk->skb_ulp_lhdr = NULL;
14837b36b6e0Skxie@chelsio.com 
14847b36b6e0Skxie@chelsio.com 	cxgbi_skcb_rx_ddigest(lskb) = ntohl(rpl->ulp_crc);
14857b36b6e0Skxie@chelsio.com 
14867b36b6e0Skxie@chelsio.com 	if (ntohs(rpl->len) != cxgbi_skcb_rx_pdulen(lskb))
14877b36b6e0Skxie@chelsio.com 		pr_info("tid 0x%x, RX_DATA_DDP pdulen %u != %u.\n",
14887b36b6e0Skxie@chelsio.com 			csk->tid, ntohs(rpl->len), cxgbi_skcb_rx_pdulen(lskb));
14897b36b6e0Skxie@chelsio.com 
149044830d8fSVarun Prakash 	cxgb4i_process_ddpvld(csk, lskb, ddpvld);
149144830d8fSVarun Prakash 
14927b36b6e0Skxie@chelsio.com 	log_debug(1 << CXGBI_DBG_PDU_RX,
14937b36b6e0Skxie@chelsio.com 		"csk 0x%p, lskb 0x%p, f 0x%lx.\n",
14947b36b6e0Skxie@chelsio.com 		csk, lskb, cxgbi_skcb_flags(lskb));
14957b36b6e0Skxie@chelsio.com 
1496e27d6169Skxie@chelsio.com 	cxgbi_skcb_set_flag(lskb, SKCBF_RX_STATUS);
14977b36b6e0Skxie@chelsio.com 	cxgbi_conn_pdu_ready(csk);
14987b36b6e0Skxie@chelsio.com 	spin_unlock_bh(&csk->lock);
14997b36b6e0Skxie@chelsio.com 	goto rel_skb;
15007b36b6e0Skxie@chelsio.com 
15017b36b6e0Skxie@chelsio.com abort_conn:
15027b36b6e0Skxie@chelsio.com 	send_abort_req(csk);
15037b36b6e0Skxie@chelsio.com discard:
15047b36b6e0Skxie@chelsio.com 	spin_unlock_bh(&csk->lock);
15057b36b6e0Skxie@chelsio.com rel_skb:
15067b36b6e0Skxie@chelsio.com 	__kfree_skb(skb);
15077b36b6e0Skxie@chelsio.com }
15087b36b6e0Skxie@chelsio.com 
150944830d8fSVarun Prakash static void
151044830d8fSVarun Prakash do_rx_iscsi_cmp(struct cxgbi_device *cdev, struct sk_buff *skb)
151144830d8fSVarun Prakash {
151244830d8fSVarun Prakash 	struct cxgbi_sock *csk;
151344830d8fSVarun Prakash 	struct cpl_rx_iscsi_cmp *rpl = (struct cpl_rx_iscsi_cmp *)skb->data;
151444830d8fSVarun Prakash 	struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(cdev);
151544830d8fSVarun Prakash 	struct tid_info *t = lldi->tids;
151644830d8fSVarun Prakash 	struct sk_buff *data_skb = NULL;
151744830d8fSVarun Prakash 	u32 tid = GET_TID(rpl);
151844830d8fSVarun Prakash 	u32 ddpvld = be32_to_cpu(rpl->ddpvld);
151944830d8fSVarun Prakash 	u32 seq = be32_to_cpu(rpl->seq);
152044830d8fSVarun Prakash 	u16 pdu_len_ddp = be16_to_cpu(rpl->pdu_len_ddp);
152144830d8fSVarun Prakash 
152244830d8fSVarun Prakash 	csk = lookup_tid(t, tid);
152344830d8fSVarun Prakash 	if (unlikely(!csk)) {
152444830d8fSVarun Prakash 		pr_err("can't find connection for tid %u.\n", tid);
152544830d8fSVarun Prakash 		goto rel_skb;
152644830d8fSVarun Prakash 	}
152744830d8fSVarun Prakash 
152844830d8fSVarun Prakash 	log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_PDU_RX,
152944830d8fSVarun Prakash 		  "csk 0x%p,%u,0x%lx, skb 0x%p,0x%x, lhdr 0x%p, len %u, "
153044830d8fSVarun Prakash 		  "pdu_len_ddp %u, status %u.\n",
153144830d8fSVarun Prakash 		  csk, csk->state, csk->flags, skb, ddpvld, csk->skb_ulp_lhdr,
153244830d8fSVarun Prakash 		  ntohs(rpl->len), pdu_len_ddp,  rpl->status);
153344830d8fSVarun Prakash 
153444830d8fSVarun Prakash 	spin_lock_bh(&csk->lock);
153544830d8fSVarun Prakash 
153644830d8fSVarun Prakash 	if (unlikely(csk->state >= CTP_PASSIVE_CLOSE)) {
153744830d8fSVarun Prakash 		log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
153844830d8fSVarun Prakash 			  "csk 0x%p,%u,0x%lx,%u, bad state.\n",
153944830d8fSVarun Prakash 			  csk, csk->state, csk->flags, csk->tid);
154044830d8fSVarun Prakash 
154144830d8fSVarun Prakash 		if (csk->state != CTP_ABORTING)
154244830d8fSVarun Prakash 			goto abort_conn;
154344830d8fSVarun Prakash 		else
154444830d8fSVarun Prakash 			goto discard;
154544830d8fSVarun Prakash 	}
154644830d8fSVarun Prakash 
154744830d8fSVarun Prakash 	cxgbi_skcb_tcp_seq(skb) = seq;
154844830d8fSVarun Prakash 	cxgbi_skcb_flags(skb) = 0;
154944830d8fSVarun Prakash 	cxgbi_skcb_rx_pdulen(skb) = 0;
155044830d8fSVarun Prakash 
155144830d8fSVarun Prakash 	skb_reset_transport_header(skb);
155244830d8fSVarun Prakash 	__skb_pull(skb, sizeof(*rpl));
155344830d8fSVarun Prakash 	__pskb_trim(skb, be16_to_cpu(rpl->len));
155444830d8fSVarun Prakash 
155544830d8fSVarun Prakash 	csk->rcv_nxt = seq + pdu_len_ddp;
155644830d8fSVarun Prakash 
155744830d8fSVarun Prakash 	if (csk->skb_ulp_lhdr) {
155844830d8fSVarun Prakash 		data_skb = skb_peek(&csk->receive_queue);
155944830d8fSVarun Prakash 		if (!data_skb ||
156044830d8fSVarun Prakash 		    !cxgbi_skcb_test_flag(data_skb, SKCBF_RX_DATA)) {
156144830d8fSVarun Prakash 			pr_err("Error! freelist data not found 0x%p, tid %u\n",
156244830d8fSVarun Prakash 			       data_skb, tid);
156344830d8fSVarun Prakash 
156444830d8fSVarun Prakash 			goto abort_conn;
156544830d8fSVarun Prakash 		}
156644830d8fSVarun Prakash 		__skb_unlink(data_skb, &csk->receive_queue);
156744830d8fSVarun Prakash 
156844830d8fSVarun Prakash 		cxgbi_skcb_set_flag(skb, SKCBF_RX_DATA);
156944830d8fSVarun Prakash 
157044830d8fSVarun Prakash 		__skb_queue_tail(&csk->receive_queue, skb);
157144830d8fSVarun Prakash 		__skb_queue_tail(&csk->receive_queue, data_skb);
157244830d8fSVarun Prakash 	} else {
157344830d8fSVarun Prakash 		 __skb_queue_tail(&csk->receive_queue, skb);
157444830d8fSVarun Prakash 	}
157544830d8fSVarun Prakash 
157644830d8fSVarun Prakash 	csk->skb_ulp_lhdr = NULL;
157744830d8fSVarun Prakash 
157844830d8fSVarun Prakash 	cxgbi_skcb_set_flag(skb, SKCBF_RX_HDR);
157944830d8fSVarun Prakash 	cxgbi_skcb_set_flag(skb, SKCBF_RX_STATUS);
158044830d8fSVarun Prakash 	cxgbi_skcb_set_flag(skb, SKCBF_RX_ISCSI_COMPL);
158144830d8fSVarun Prakash 	cxgbi_skcb_rx_ddigest(skb) = be32_to_cpu(rpl->ulp_crc);
158244830d8fSVarun Prakash 
158344830d8fSVarun Prakash 	cxgb4i_process_ddpvld(csk, skb, ddpvld);
158444830d8fSVarun Prakash 
158544830d8fSVarun Prakash 	log_debug(1 << CXGBI_DBG_PDU_RX, "csk 0x%p, skb 0x%p, f 0x%lx.\n",
158644830d8fSVarun Prakash 		  csk, skb, cxgbi_skcb_flags(skb));
158744830d8fSVarun Prakash 
158844830d8fSVarun Prakash 	cxgbi_conn_pdu_ready(csk);
158944830d8fSVarun Prakash 	spin_unlock_bh(&csk->lock);
159044830d8fSVarun Prakash 
159144830d8fSVarun Prakash 	return;
159244830d8fSVarun Prakash 
159344830d8fSVarun Prakash abort_conn:
159444830d8fSVarun Prakash 	send_abort_req(csk);
159544830d8fSVarun Prakash discard:
159644830d8fSVarun Prakash 	spin_unlock_bh(&csk->lock);
159744830d8fSVarun Prakash rel_skb:
159844830d8fSVarun Prakash 	__kfree_skb(skb);
159944830d8fSVarun Prakash }
160044830d8fSVarun Prakash 
16017b36b6e0Skxie@chelsio.com static void do_fw4_ack(struct cxgbi_device *cdev, struct sk_buff *skb)
16027b36b6e0Skxie@chelsio.com {
16037b36b6e0Skxie@chelsio.com 	struct cxgbi_sock *csk;
16047b36b6e0Skxie@chelsio.com 	struct cpl_fw4_ack *rpl = (struct cpl_fw4_ack *)skb->data;
16057b36b6e0Skxie@chelsio.com 	unsigned int tid = GET_TID(rpl);
16067b36b6e0Skxie@chelsio.com 	struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(cdev);
16077b36b6e0Skxie@chelsio.com 	struct tid_info *t = lldi->tids;
16087b36b6e0Skxie@chelsio.com 
16097b36b6e0Skxie@chelsio.com 	csk = lookup_tid(t, tid);
16107b36b6e0Skxie@chelsio.com 	if (unlikely(!csk))
16117b36b6e0Skxie@chelsio.com 		pr_err("can't find connection for tid %u.\n", tid);
16127b36b6e0Skxie@chelsio.com 	else {
16137b36b6e0Skxie@chelsio.com 		log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
16147b36b6e0Skxie@chelsio.com 			"csk 0x%p,%u,0x%lx,%u.\n",
16157b36b6e0Skxie@chelsio.com 			csk, csk->state, csk->flags, csk->tid);
16167b36b6e0Skxie@chelsio.com 		cxgbi_sock_rcv_wr_ack(csk, rpl->credits, ntohl(rpl->snd_una),
16177b36b6e0Skxie@chelsio.com 					rpl->seq_vld);
16187b36b6e0Skxie@chelsio.com 	}
16197b36b6e0Skxie@chelsio.com 	__kfree_skb(skb);
16207b36b6e0Skxie@chelsio.com }
16217b36b6e0Skxie@chelsio.com 
16227b36b6e0Skxie@chelsio.com static void do_set_tcb_rpl(struct cxgbi_device *cdev, struct sk_buff *skb)
16237b36b6e0Skxie@chelsio.com {
16247b36b6e0Skxie@chelsio.com 	struct cpl_set_tcb_rpl *rpl = (struct cpl_set_tcb_rpl *)skb->data;
16257b36b6e0Skxie@chelsio.com 	unsigned int tid = GET_TID(rpl);
16267b36b6e0Skxie@chelsio.com 	struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(cdev);
16277b36b6e0Skxie@chelsio.com 	struct tid_info *t = lldi->tids;
16287b36b6e0Skxie@chelsio.com 	struct cxgbi_sock *csk;
16297b36b6e0Skxie@chelsio.com 
16307b36b6e0Skxie@chelsio.com 	csk = lookup_tid(t, tid);
16319e8f1c79SVarun Prakash 	if (!csk) {
16327b36b6e0Skxie@chelsio.com 		pr_err("can't find conn. for tid %u.\n", tid);
16339e8f1c79SVarun Prakash 		return;
16349e8f1c79SVarun Prakash 	}
16357b36b6e0Skxie@chelsio.com 
16367b36b6e0Skxie@chelsio.com 	log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
16377b36b6e0Skxie@chelsio.com 		"csk 0x%p,%u,%lx,%u, status 0x%x.\n",
16387b36b6e0Skxie@chelsio.com 		csk, csk->state, csk->flags, csk->tid, rpl->status);
16397b36b6e0Skxie@chelsio.com 
16409e8f1c79SVarun Prakash 	if (rpl->status != CPL_ERR_NONE) {
16417b36b6e0Skxie@chelsio.com 		pr_err("csk 0x%p,%u, SET_TCB_RPL status %u.\n",
16427b36b6e0Skxie@chelsio.com 			csk, tid, rpl->status);
16439e8f1c79SVarun Prakash 		csk->err = -EINVAL;
16449e8f1c79SVarun Prakash 	}
16459e8f1c79SVarun Prakash 
16469e8f1c79SVarun Prakash 	complete(&csk->cmpl);
16477b36b6e0Skxie@chelsio.com 
16487b36b6e0Skxie@chelsio.com 	__kfree_skb(skb);
16497b36b6e0Skxie@chelsio.com }
16507b36b6e0Skxie@chelsio.com 
16517b36b6e0Skxie@chelsio.com static int alloc_cpls(struct cxgbi_sock *csk)
16527b36b6e0Skxie@chelsio.com {
165324d3f95aSkxie@chelsio.com 	csk->cpl_close = alloc_wr(sizeof(struct cpl_close_con_req),
165424d3f95aSkxie@chelsio.com 					0, GFP_KERNEL);
16557b36b6e0Skxie@chelsio.com 	if (!csk->cpl_close)
16567b36b6e0Skxie@chelsio.com 		return -ENOMEM;
16577b36b6e0Skxie@chelsio.com 
165824d3f95aSkxie@chelsio.com 	csk->cpl_abort_req = alloc_wr(sizeof(struct cpl_abort_req),
165924d3f95aSkxie@chelsio.com 					0, GFP_KERNEL);
16607b36b6e0Skxie@chelsio.com 	if (!csk->cpl_abort_req)
16617b36b6e0Skxie@chelsio.com 		goto free_cpls;
16627b36b6e0Skxie@chelsio.com 
166324d3f95aSkxie@chelsio.com 	csk->cpl_abort_rpl = alloc_wr(sizeof(struct cpl_abort_rpl),
166424d3f95aSkxie@chelsio.com 					0, GFP_KERNEL);
16657b36b6e0Skxie@chelsio.com 	if (!csk->cpl_abort_rpl)
16667b36b6e0Skxie@chelsio.com 		goto free_cpls;
16677b36b6e0Skxie@chelsio.com 	return 0;
16687b36b6e0Skxie@chelsio.com 
16697b36b6e0Skxie@chelsio.com free_cpls:
16707b36b6e0Skxie@chelsio.com 	cxgbi_sock_free_cpl_skbs(csk);
16717b36b6e0Skxie@chelsio.com 	return -ENOMEM;
16727b36b6e0Skxie@chelsio.com }
16737b36b6e0Skxie@chelsio.com 
16747b36b6e0Skxie@chelsio.com static inline void l2t_put(struct cxgbi_sock *csk)
16757b36b6e0Skxie@chelsio.com {
16767b36b6e0Skxie@chelsio.com 	if (csk->l2t) {
16777b36b6e0Skxie@chelsio.com 		cxgb4_l2t_release(csk->l2t);
16787b36b6e0Skxie@chelsio.com 		csk->l2t = NULL;
16797b36b6e0Skxie@chelsio.com 		cxgbi_sock_put(csk);
16807b36b6e0Skxie@chelsio.com 	}
16817b36b6e0Skxie@chelsio.com }
16827b36b6e0Skxie@chelsio.com 
16837b36b6e0Skxie@chelsio.com static void release_offload_resources(struct cxgbi_sock *csk)
16847b36b6e0Skxie@chelsio.com {
16857b36b6e0Skxie@chelsio.com 	struct cxgb4_lld_info *lldi;
1686211a84e3SAnish Bhatt #if IS_ENABLED(CONFIG_IPV6)
1687211a84e3SAnish Bhatt 	struct net_device *ndev = csk->cdev->ports[csk->port_id];
1688211a84e3SAnish Bhatt #endif
16897b36b6e0Skxie@chelsio.com 
16907b36b6e0Skxie@chelsio.com 	log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
16917b36b6e0Skxie@chelsio.com 		"csk 0x%p,%u,0x%lx,%u.\n",
16927b36b6e0Skxie@chelsio.com 		csk, csk->state, csk->flags, csk->tid);
16937b36b6e0Skxie@chelsio.com 
16947b36b6e0Skxie@chelsio.com 	cxgbi_sock_free_cpl_skbs(csk);
16959b3a081fSVarun Prakash 	cxgbi_sock_purge_write_queue(csk);
16967b36b6e0Skxie@chelsio.com 	if (csk->wr_cred != csk->wr_max_cred) {
16977b36b6e0Skxie@chelsio.com 		cxgbi_sock_purge_wr_queue(csk);
16987b36b6e0Skxie@chelsio.com 		cxgbi_sock_reset_wr_list(csk);
16997b36b6e0Skxie@chelsio.com 	}
17007b36b6e0Skxie@chelsio.com 
17017b36b6e0Skxie@chelsio.com 	l2t_put(csk);
1702211a84e3SAnish Bhatt #if IS_ENABLED(CONFIG_IPV6)
1703211a84e3SAnish Bhatt 	if (csk->csk_family == AF_INET6)
1704211a84e3SAnish Bhatt 		cxgb4_clip_release(ndev,
1705211a84e3SAnish Bhatt 				   (const u32 *)&csk->saddr6.sin6_addr, 1);
1706211a84e3SAnish Bhatt #endif
1707211a84e3SAnish Bhatt 
17087b36b6e0Skxie@chelsio.com 	if (cxgbi_sock_flag(csk, CTPF_HAS_ATID))
17097b36b6e0Skxie@chelsio.com 		free_atid(csk);
17107b36b6e0Skxie@chelsio.com 	else if (cxgbi_sock_flag(csk, CTPF_HAS_TID)) {
17117b36b6e0Skxie@chelsio.com 		lldi = cxgbi_cdev_priv(csk->cdev);
17121dec4cecSGanesh Goudar 		cxgb4_remove_tid(lldi->tids, 0, csk->tid,
17131dec4cecSGanesh Goudar 				 csk->csk_family);
17147b36b6e0Skxie@chelsio.com 		cxgbi_sock_clear_flag(csk, CTPF_HAS_TID);
17157b36b6e0Skxie@chelsio.com 		cxgbi_sock_put(csk);
17167b36b6e0Skxie@chelsio.com 	}
17177b36b6e0Skxie@chelsio.com 	csk->dst = NULL;
17187b36b6e0Skxie@chelsio.com }
17197b36b6e0Skxie@chelsio.com 
1720b5a5fe4eSVarun Prakash #ifdef CONFIG_CHELSIO_T4_DCB
1721b5a5fe4eSVarun Prakash static inline u8 get_iscsi_dcb_state(struct net_device *ndev)
1722b5a5fe4eSVarun Prakash {
1723b5a5fe4eSVarun Prakash 	return ndev->dcbnl_ops->getstate(ndev);
1724b5a5fe4eSVarun Prakash }
1725b5a5fe4eSVarun Prakash 
1726b5a5fe4eSVarun Prakash static int select_priority(int pri_mask)
1727b5a5fe4eSVarun Prakash {
1728b5a5fe4eSVarun Prakash 	if (!pri_mask)
1729b5a5fe4eSVarun Prakash 		return 0;
1730b5a5fe4eSVarun Prakash 	return (ffs(pri_mask) - 1);
1731b5a5fe4eSVarun Prakash }
1732b5a5fe4eSVarun Prakash 
1733b5a5fe4eSVarun Prakash static u8 get_iscsi_dcb_priority(struct net_device *ndev)
1734b5a5fe4eSVarun Prakash {
1735b5a5fe4eSVarun Prakash 	int rv;
1736b5a5fe4eSVarun Prakash 	u8 caps;
1737b5a5fe4eSVarun Prakash 
1738b5a5fe4eSVarun Prakash 	struct dcb_app iscsi_dcb_app = {
1739b5a5fe4eSVarun Prakash 		.protocol = 3260
1740b5a5fe4eSVarun Prakash 	};
1741b5a5fe4eSVarun Prakash 
1742b5a5fe4eSVarun Prakash 	rv = (int)ndev->dcbnl_ops->getcap(ndev, DCB_CAP_ATTR_DCBX, &caps);
1743b5a5fe4eSVarun Prakash 	if (rv)
1744b5a5fe4eSVarun Prakash 		return 0;
1745b5a5fe4eSVarun Prakash 
1746b5a5fe4eSVarun Prakash 	if (caps & DCB_CAP_DCBX_VER_IEEE) {
1747152e30fcSVarun Prakash 		iscsi_dcb_app.selector = IEEE_8021QAZ_APP_SEL_STREAM;
1748152e30fcSVarun Prakash 		rv = dcb_ieee_getapp_mask(ndev, &iscsi_dcb_app);
1749152e30fcSVarun Prakash 		if (!rv) {
1750b5a5fe4eSVarun Prakash 			iscsi_dcb_app.selector = IEEE_8021QAZ_APP_SEL_ANY;
1751b5a5fe4eSVarun Prakash 			rv = dcb_ieee_getapp_mask(ndev, &iscsi_dcb_app);
1752152e30fcSVarun Prakash 		}
1753b5a5fe4eSVarun Prakash 	} else if (caps & DCB_CAP_DCBX_VER_CEE) {
1754b5a5fe4eSVarun Prakash 		iscsi_dcb_app.selector = DCB_APP_IDTYPE_PORTNUM;
1755b5a5fe4eSVarun Prakash 		rv = dcb_getapp(ndev, &iscsi_dcb_app);
1756b5a5fe4eSVarun Prakash 	}
1757b5a5fe4eSVarun Prakash 
1758b5a5fe4eSVarun Prakash 	log_debug(1 << CXGBI_DBG_ISCSI,
1759b5a5fe4eSVarun Prakash 		  "iSCSI priority is set to %u\n", select_priority(rv));
1760b5a5fe4eSVarun Prakash 	return select_priority(rv);
1761b5a5fe4eSVarun Prakash }
1762b5a5fe4eSVarun Prakash #endif
1763b5a5fe4eSVarun Prakash 
17647b36b6e0Skxie@chelsio.com static int init_act_open(struct cxgbi_sock *csk)
17657b36b6e0Skxie@chelsio.com {
17667b36b6e0Skxie@chelsio.com 	struct cxgbi_device *cdev = csk->cdev;
17677b36b6e0Skxie@chelsio.com 	struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(cdev);
17687b36b6e0Skxie@chelsio.com 	struct net_device *ndev = cdev->ports[csk->port_id];
17697b36b6e0Skxie@chelsio.com 	struct sk_buff *skb = NULL;
1770759a0cc5SAnish Bhatt 	struct neighbour *n = NULL;
1771759a0cc5SAnish Bhatt 	void *daddr;
17727b36b6e0Skxie@chelsio.com 	unsigned int step;
17736c9e2770SVarun Prakash 	unsigned int rxq_idx;
1774759a0cc5SAnish Bhatt 	unsigned int size, size6;
177581daf10cSKaren Xie 	unsigned int linkspeed;
177681daf10cSKaren Xie 	unsigned int rcv_winf, snd_winf;
1777b5a5fe4eSVarun Prakash #ifdef CONFIG_CHELSIO_T4_DCB
1778b5a5fe4eSVarun Prakash 	u8 priority = 0;
1779b5a5fe4eSVarun Prakash #endif
17807b36b6e0Skxie@chelsio.com 	log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
17817b36b6e0Skxie@chelsio.com 		"csk 0x%p,%u,0x%lx,%u.\n",
17827b36b6e0Skxie@chelsio.com 		csk, csk->state, csk->flags, csk->tid);
17837b36b6e0Skxie@chelsio.com 
1784759a0cc5SAnish Bhatt 	if (csk->csk_family == AF_INET)
1785759a0cc5SAnish Bhatt 		daddr = &csk->daddr.sin_addr.s_addr;
1786e81fbf6cSAnish Bhatt #if IS_ENABLED(CONFIG_IPV6)
1787e81fbf6cSAnish Bhatt 	else if (csk->csk_family == AF_INET6)
1788759a0cc5SAnish Bhatt 		daddr = &csk->daddr6.sin6_addr;
1789e81fbf6cSAnish Bhatt #endif
1790e81fbf6cSAnish Bhatt 	else {
1791e81fbf6cSAnish Bhatt 		pr_err("address family 0x%x not supported\n", csk->csk_family);
1792e81fbf6cSAnish Bhatt 		goto rel_resource;
1793e81fbf6cSAnish Bhatt 	}
1794759a0cc5SAnish Bhatt 
1795759a0cc5SAnish Bhatt 	n = dst_neigh_lookup(csk->dst, daddr);
1796759a0cc5SAnish Bhatt 
1797759a0cc5SAnish Bhatt 	if (!n) {
1798759a0cc5SAnish Bhatt 		pr_err("%s, can't get neighbour of csk->dst.\n", ndev->name);
1799759a0cc5SAnish Bhatt 		goto rel_resource;
1800759a0cc5SAnish Bhatt 	}
1801759a0cc5SAnish Bhatt 
180271eb2ac5SVarun Prakash 	if (!(n->nud_state & NUD_VALID))
180371eb2ac5SVarun Prakash 		neigh_event_send(n, NULL);
180471eb2ac5SVarun Prakash 
18057b36b6e0Skxie@chelsio.com 	csk->atid = cxgb4_alloc_atid(lldi->tids, csk);
18067b36b6e0Skxie@chelsio.com 	if (csk->atid < 0) {
18077b36b6e0Skxie@chelsio.com 		pr_err("%s, NO atid available.\n", ndev->name);
1808338be072SQuentin Lambert 		goto rel_resource_without_clip;
18097b36b6e0Skxie@chelsio.com 	}
18107b36b6e0Skxie@chelsio.com 	cxgbi_sock_set_flag(csk, CTPF_HAS_ATID);
18117b36b6e0Skxie@chelsio.com 	cxgbi_sock_get(csk);
18127b36b6e0Skxie@chelsio.com 
1813b5a5fe4eSVarun Prakash #ifdef CONFIG_CHELSIO_T4_DCB
1814b5a5fe4eSVarun Prakash 	if (get_iscsi_dcb_state(ndev))
1815b5a5fe4eSVarun Prakash 		priority = get_iscsi_dcb_priority(ndev);
1816b5a5fe4eSVarun Prakash 
1817b5a5fe4eSVarun Prakash 	csk->dcb_priority = priority;
1818b5a5fe4eSVarun Prakash 	csk->l2t = cxgb4_l2t_get(lldi->l2t, n, ndev, priority);
1819b5a5fe4eSVarun Prakash #else
182051e059bdSDavid Miller 	csk->l2t = cxgb4_l2t_get(lldi->l2t, n, ndev, 0);
1821b5a5fe4eSVarun Prakash #endif
18227b36b6e0Skxie@chelsio.com 	if (!csk->l2t) {
18237b36b6e0Skxie@chelsio.com 		pr_err("%s, cannot alloc l2t.\n", ndev->name);
1824211a84e3SAnish Bhatt 		goto rel_resource_without_clip;
18257b36b6e0Skxie@chelsio.com 	}
18267b36b6e0Skxie@chelsio.com 	cxgbi_sock_get(csk);
18277b36b6e0Skxie@chelsio.com 
1828211a84e3SAnish Bhatt #if IS_ENABLED(CONFIG_IPV6)
1829211a84e3SAnish Bhatt 	if (csk->csk_family == AF_INET6)
1830211a84e3SAnish Bhatt 		cxgb4_clip_get(ndev, (const u32 *)&csk->saddr6.sin6_addr, 1);
1831211a84e3SAnish Bhatt #endif
1832211a84e3SAnish Bhatt 
1833586be7cbSVarun Prakash 	if (is_t4(lldi->adapter_type)) {
1834759a0cc5SAnish Bhatt 		size = sizeof(struct cpl_act_open_req);
1835759a0cc5SAnish Bhatt 		size6 = sizeof(struct cpl_act_open_req6);
1836586be7cbSVarun Prakash 	} else if (is_t5(lldi->adapter_type)) {
1837759a0cc5SAnish Bhatt 		size = sizeof(struct cpl_t5_act_open_req);
1838759a0cc5SAnish Bhatt 		size6 = sizeof(struct cpl_t5_act_open_req6);
1839586be7cbSVarun Prakash 	} else {
1840586be7cbSVarun Prakash 		size = sizeof(struct cpl_t6_act_open_req);
1841586be7cbSVarun Prakash 		size6 = sizeof(struct cpl_t6_act_open_req6);
1842759a0cc5SAnish Bhatt 	}
1843759a0cc5SAnish Bhatt 
1844759a0cc5SAnish Bhatt 	if (csk->csk_family == AF_INET)
1845759a0cc5SAnish Bhatt 		skb = alloc_wr(size, 0, GFP_NOIO);
1846f42bb57cSAnish Bhatt #if IS_ENABLED(CONFIG_IPV6)
1847759a0cc5SAnish Bhatt 	else
1848759a0cc5SAnish Bhatt 		skb = alloc_wr(size6, 0, GFP_NOIO);
1849f42bb57cSAnish Bhatt #endif
1850759a0cc5SAnish Bhatt 
18517b36b6e0Skxie@chelsio.com 	if (!skb)
18527b36b6e0Skxie@chelsio.com 		goto rel_resource;
18537b36b6e0Skxie@chelsio.com 	skb->sk = (struct sock *)csk;
18547b36b6e0Skxie@chelsio.com 	t4_set_arp_err_handler(skb, csk, cxgbi_sock_act_open_req_arp_failure);
18557b36b6e0Skxie@chelsio.com 
18567b36b6e0Skxie@chelsio.com 	if (!csk->mtu)
18577b36b6e0Skxie@chelsio.com 		csk->mtu = dst_mtu(csk->dst);
18587b36b6e0Skxie@chelsio.com 	cxgb4_best_mtu(lldi->mtus, csk->mtu, &csk->mss_idx);
18597b36b6e0Skxie@chelsio.com 	csk->tx_chan = cxgb4_port_chan(ndev);
186002d805dcSSantosh Rastapur 	csk->smac_idx = ((struct port_info *)netdev_priv(ndev))->smt_idx;
18617b36b6e0Skxie@chelsio.com 	step = lldi->ntxq / lldi->nchan;
18627b36b6e0Skxie@chelsio.com 	csk->txq_idx = cxgb4_port_idx(ndev) * step;
18637b36b6e0Skxie@chelsio.com 	step = lldi->nrxq / lldi->nchan;
18646c9e2770SVarun Prakash 	rxq_idx = (cxgb4_port_idx(ndev) * step) + (cdev->rxq_idx_cntr % step);
18656c9e2770SVarun Prakash 	cdev->rxq_idx_cntr++;
18666c9e2770SVarun Prakash 	csk->rss_qid = lldi->rxq_ids[rxq_idx];
186781daf10cSKaren Xie 	linkspeed = ((struct port_info *)netdev_priv(ndev))->link_cfg.speed;
186881daf10cSKaren Xie 	csk->snd_win = cxgb4i_snd_win;
186981daf10cSKaren Xie 	csk->rcv_win = cxgb4i_rcv_win;
187081daf10cSKaren Xie 	if (cxgb4i_rcv_win <= 0) {
187181daf10cSKaren Xie 		csk->rcv_win = CXGB4I_DEFAULT_10G_RCV_WIN;
187281daf10cSKaren Xie 		rcv_winf = linkspeed / SPEED_10000;
187381daf10cSKaren Xie 		if (rcv_winf)
187481daf10cSKaren Xie 			csk->rcv_win *= rcv_winf;
187581daf10cSKaren Xie 	}
187681daf10cSKaren Xie 	if (cxgb4i_snd_win <= 0) {
187781daf10cSKaren Xie 		csk->snd_win = CXGB4I_DEFAULT_10G_SND_WIN;
187881daf10cSKaren Xie 		snd_winf = linkspeed / SPEED_10000;
187981daf10cSKaren Xie 		if (snd_winf)
188081daf10cSKaren Xie 			csk->snd_win *= snd_winf;
188181daf10cSKaren Xie 	}
1882759a0cc5SAnish Bhatt 	csk->wr_cred = lldi->wr_cred -
1883759a0cc5SAnish Bhatt 		       DIV_ROUND_UP(sizeof(struct cpl_abort_req), 16);
1884759a0cc5SAnish Bhatt 	csk->wr_max_cred = csk->wr_cred;
18857b36b6e0Skxie@chelsio.com 	csk->wr_una_cred = 0;
18867b36b6e0Skxie@chelsio.com 	cxgbi_sock_reset_wr_list(csk);
18877b36b6e0Skxie@chelsio.com 	csk->err = 0;
18887b36b6e0Skxie@chelsio.com 
1889759a0cc5SAnish Bhatt 	pr_info_ipaddr("csk 0x%p,%u,0x%lx,%u,%u,%u, mtu %u,%u, smac %u.\n",
1890759a0cc5SAnish Bhatt 		       (&csk->saddr), (&csk->daddr), csk, csk->state,
1891759a0cc5SAnish Bhatt 		       csk->flags, csk->tx_chan, csk->txq_idx, csk->rss_qid,
1892759a0cc5SAnish Bhatt 		       csk->mtu, csk->mss_idx, csk->smac_idx);
1893759a0cc5SAnish Bhatt 
1894759a0cc5SAnish Bhatt 	/* must wait for either a act_open_rpl or act_open_establish */
18951fe1fdb0SVarun Prakash 	if (!try_module_get(cdev->owner)) {
18961fe1fdb0SVarun Prakash 		pr_err("%s, try_module_get failed.\n", ndev->name);
18971fe1fdb0SVarun Prakash 		goto rel_resource;
18981fe1fdb0SVarun Prakash 	}
18991fe1fdb0SVarun Prakash 
19007b36b6e0Skxie@chelsio.com 	cxgbi_sock_set_state(csk, CTP_ACTIVE_OPEN);
1901759a0cc5SAnish Bhatt 	if (csk->csk_family == AF_INET)
19027b36b6e0Skxie@chelsio.com 		send_act_open_req(csk, skb, csk->l2t);
1903f42bb57cSAnish Bhatt #if IS_ENABLED(CONFIG_IPV6)
1904759a0cc5SAnish Bhatt 	else
1905759a0cc5SAnish Bhatt 		send_act_open_req6(csk, skb, csk->l2t);
1906f42bb57cSAnish Bhatt #endif
1907c4737377SDavid S. Miller 	neigh_release(n);
1908759a0cc5SAnish Bhatt 
19097b36b6e0Skxie@chelsio.com 	return 0;
19107b36b6e0Skxie@chelsio.com 
19117b36b6e0Skxie@chelsio.com rel_resource:
1912211a84e3SAnish Bhatt #if IS_ENABLED(CONFIG_IPV6)
1913211a84e3SAnish Bhatt 	if (csk->csk_family == AF_INET6)
1914211a84e3SAnish Bhatt 		cxgb4_clip_release(ndev,
1915211a84e3SAnish Bhatt 				   (const u32 *)&csk->saddr6.sin6_addr, 1);
1916211a84e3SAnish Bhatt #endif
1917211a84e3SAnish Bhatt rel_resource_without_clip:
1918c4737377SDavid S. Miller 	if (n)
1919c4737377SDavid S. Miller 		neigh_release(n);
19207b36b6e0Skxie@chelsio.com 	if (skb)
19217b36b6e0Skxie@chelsio.com 		__kfree_skb(skb);
19227b36b6e0Skxie@chelsio.com 	return -EINVAL;
19237b36b6e0Skxie@chelsio.com }
19247b36b6e0Skxie@chelsio.com 
19254665bdd5SVarun Prakash static cxgb4i_cplhandler_func cxgb4i_cplhandlers[NUM_CPL_CMDS] = {
19267b36b6e0Skxie@chelsio.com 	[CPL_ACT_ESTABLISH] = do_act_establish,
19277b36b6e0Skxie@chelsio.com 	[CPL_ACT_OPEN_RPL] = do_act_open_rpl,
19287b36b6e0Skxie@chelsio.com 	[CPL_PEER_CLOSE] = do_peer_close,
19297b36b6e0Skxie@chelsio.com 	[CPL_ABORT_REQ_RSS] = do_abort_req_rss,
19307b36b6e0Skxie@chelsio.com 	[CPL_ABORT_RPL_RSS] = do_abort_rpl_rss,
19317b36b6e0Skxie@chelsio.com 	[CPL_CLOSE_CON_RPL] = do_close_con_rpl,
19327b36b6e0Skxie@chelsio.com 	[CPL_FW4_ACK] = do_fw4_ack,
19337b36b6e0Skxie@chelsio.com 	[CPL_ISCSI_HDR] = do_rx_iscsi_hdr,
193444830d8fSVarun Prakash 	[CPL_ISCSI_DATA] = do_rx_iscsi_data,
19357b36b6e0Skxie@chelsio.com 	[CPL_SET_TCB_RPL] = do_set_tcb_rpl,
19367b36b6e0Skxie@chelsio.com 	[CPL_RX_DATA_DDP] = do_rx_data_ddp,
19373bd3e8bfSKaren Xie 	[CPL_RX_ISCSI_DDP] = do_rx_data_ddp,
193844830d8fSVarun Prakash 	[CPL_RX_ISCSI_CMP] = do_rx_iscsi_cmp,
1939f7bcd2e1SKaren Xie 	[CPL_RX_DATA] = do_rx_data,
19407b36b6e0Skxie@chelsio.com };
19417b36b6e0Skxie@chelsio.com 
19424665bdd5SVarun Prakash static int cxgb4i_ofld_init(struct cxgbi_device *cdev)
19437b36b6e0Skxie@chelsio.com {
19447b36b6e0Skxie@chelsio.com 	int rc;
19457b36b6e0Skxie@chelsio.com 
19467b36b6e0Skxie@chelsio.com 	if (cxgb4i_max_connect > CXGB4I_MAX_CONN)
19477b36b6e0Skxie@chelsio.com 		cxgb4i_max_connect = CXGB4I_MAX_CONN;
19487b36b6e0Skxie@chelsio.com 
19497b36b6e0Skxie@chelsio.com 	rc = cxgbi_device_portmap_create(cdev, cxgb4i_sport_base,
19507b36b6e0Skxie@chelsio.com 					cxgb4i_max_connect);
19517b36b6e0Skxie@chelsio.com 	if (rc < 0)
19527b36b6e0Skxie@chelsio.com 		return rc;
19537b36b6e0Skxie@chelsio.com 
19547b36b6e0Skxie@chelsio.com 	cdev->csk_release_offload_resources = release_offload_resources;
19557b36b6e0Skxie@chelsio.com 	cdev->csk_push_tx_frames = push_tx_frames;
19567b36b6e0Skxie@chelsio.com 	cdev->csk_send_abort_req = send_abort_req;
19577b36b6e0Skxie@chelsio.com 	cdev->csk_send_close_req = send_close_req;
19587b36b6e0Skxie@chelsio.com 	cdev->csk_send_rx_credits = send_rx_credits;
19597b36b6e0Skxie@chelsio.com 	cdev->csk_alloc_cpls = alloc_cpls;
19607b36b6e0Skxie@chelsio.com 	cdev->csk_init_act_open = init_act_open;
19617b36b6e0Skxie@chelsio.com 
19627b36b6e0Skxie@chelsio.com 	pr_info("cdev 0x%p, offload up, added.\n", cdev);
19637b36b6e0Skxie@chelsio.com 	return 0;
19647b36b6e0Skxie@chelsio.com }
19657b36b6e0Skxie@chelsio.com 
196671f7a00bSVarun Prakash static inline void
196771f7a00bSVarun Prakash ulp_mem_io_set_hdr(struct cxgbi_device *cdev,
196871f7a00bSVarun Prakash 		   struct ulp_mem_io *req,
196971f7a00bSVarun Prakash 		   unsigned int wr_len, unsigned int dlen,
197071f7a00bSVarun Prakash 		   unsigned int pm_addr,
197171f7a00bSVarun Prakash 		   int tid)
197271f7a00bSVarun Prakash {
197371f7a00bSVarun Prakash 	struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(cdev);
197471f7a00bSVarun Prakash 	struct ulptx_idata *idata = (struct ulptx_idata *)(req + 1);
197571f7a00bSVarun Prakash 
197671f7a00bSVarun Prakash 	INIT_ULPTX_WR(req, wr_len, 0, tid);
197771f7a00bSVarun Prakash 	req->wr.wr_hi = htonl(FW_WR_OP_V(FW_ULPTX_WR) |
197871f7a00bSVarun Prakash 		FW_WR_ATOMIC_V(0));
197971f7a00bSVarun Prakash 	req->cmd = htonl(ULPTX_CMD_V(ULP_TX_MEM_WRITE) |
198071f7a00bSVarun Prakash 		ULP_MEMIO_ORDER_V(is_t4(lldi->adapter_type)) |
198171f7a00bSVarun Prakash 		T5_ULP_MEMIO_IMM_V(!is_t4(lldi->adapter_type)));
198271f7a00bSVarun Prakash 	req->dlen = htonl(ULP_MEMIO_DATA_LEN_V(dlen >> 5));
198371f7a00bSVarun Prakash 	req->lock_addr = htonl(ULP_MEMIO_ADDR_V(pm_addr >> 5));
198471f7a00bSVarun Prakash 	req->len16 = htonl(DIV_ROUND_UP(wr_len - sizeof(req->wr), 16));
198571f7a00bSVarun Prakash 
198671f7a00bSVarun Prakash 	idata->cmd_more = htonl(ULPTX_CMD_V(ULP_TX_SC_IMM));
198771f7a00bSVarun Prakash 	idata->len = htonl(dlen);
198871f7a00bSVarun Prakash }
198971f7a00bSVarun Prakash 
199071f7a00bSVarun Prakash static struct sk_buff *
199171f7a00bSVarun Prakash ddp_ppod_init_idata(struct cxgbi_device *cdev,
199271f7a00bSVarun Prakash 		    struct cxgbi_ppm *ppm,
199371f7a00bSVarun Prakash 		    unsigned int idx, unsigned int npods,
199471f7a00bSVarun Prakash 		    unsigned int tid)
199571f7a00bSVarun Prakash {
199671f7a00bSVarun Prakash 	unsigned int pm_addr = (idx << PPOD_SIZE_SHIFT) + ppm->llimit;
199771f7a00bSVarun Prakash 	unsigned int dlen = npods << PPOD_SIZE_SHIFT;
199871f7a00bSVarun Prakash 	unsigned int wr_len = roundup(sizeof(struct ulp_mem_io) +
199971f7a00bSVarun Prakash 				sizeof(struct ulptx_idata) + dlen, 16);
200071f7a00bSVarun Prakash 	struct sk_buff *skb = alloc_wr(wr_len, 0, GFP_ATOMIC);
200171f7a00bSVarun Prakash 
200271f7a00bSVarun Prakash 	if (!skb) {
200371f7a00bSVarun Prakash 		pr_err("%s: %s idx %u, npods %u, OOM.\n",
200471f7a00bSVarun Prakash 		       __func__, ppm->ndev->name, idx, npods);
200571f7a00bSVarun Prakash 		return NULL;
200671f7a00bSVarun Prakash 	}
200771f7a00bSVarun Prakash 
200871f7a00bSVarun Prakash 	ulp_mem_io_set_hdr(cdev, (struct ulp_mem_io *)skb->head, wr_len, dlen,
200971f7a00bSVarun Prakash 			   pm_addr, tid);
201071f7a00bSVarun Prakash 
201171f7a00bSVarun Prakash 	return skb;
201271f7a00bSVarun Prakash }
201371f7a00bSVarun Prakash 
201471f7a00bSVarun Prakash static int ddp_ppod_write_idata(struct cxgbi_ppm *ppm, struct cxgbi_sock *csk,
201571f7a00bSVarun Prakash 				struct cxgbi_task_tag_info *ttinfo,
201671f7a00bSVarun Prakash 				unsigned int idx, unsigned int npods,
201771f7a00bSVarun Prakash 				struct scatterlist **sg_pp,
201871f7a00bSVarun Prakash 				unsigned int *sg_off)
201971f7a00bSVarun Prakash {
202071f7a00bSVarun Prakash 	struct cxgbi_device *cdev = csk->cdev;
202171f7a00bSVarun Prakash 	struct sk_buff *skb = ddp_ppod_init_idata(cdev, ppm, idx, npods,
202271f7a00bSVarun Prakash 						  csk->tid);
202371f7a00bSVarun Prakash 	struct ulp_mem_io *req;
202471f7a00bSVarun Prakash 	struct ulptx_idata *idata;
202571f7a00bSVarun Prakash 	struct cxgbi_pagepod *ppod;
202671f7a00bSVarun Prakash 	int i;
202771f7a00bSVarun Prakash 
202871f7a00bSVarun Prakash 	if (!skb)
202971f7a00bSVarun Prakash 		return -ENOMEM;
203071f7a00bSVarun Prakash 
203171f7a00bSVarun Prakash 	req = (struct ulp_mem_io *)skb->head;
203271f7a00bSVarun Prakash 	idata = (struct ulptx_idata *)(req + 1);
203371f7a00bSVarun Prakash 	ppod = (struct cxgbi_pagepod *)(idata + 1);
203471f7a00bSVarun Prakash 
203571f7a00bSVarun Prakash 	for (i = 0; i < npods; i++, ppod++)
203671f7a00bSVarun Prakash 		cxgbi_ddp_set_one_ppod(ppod, ttinfo, sg_pp, sg_off);
203771f7a00bSVarun Prakash 
203871f7a00bSVarun Prakash 	cxgbi_skcb_set_flag(skb, SKCBF_TX_MEM_WRITE);
203971f7a00bSVarun Prakash 	cxgbi_skcb_set_flag(skb, SKCBF_TX_FLAG_COMPL);
204071f7a00bSVarun Prakash 	set_wr_txq(skb, CPL_PRIORITY_DATA, csk->port_id);
204171f7a00bSVarun Prakash 
204271f7a00bSVarun Prakash 	spin_lock_bh(&csk->lock);
204371f7a00bSVarun Prakash 	cxgbi_sock_skb_entail(csk, skb);
204471f7a00bSVarun Prakash 	spin_unlock_bh(&csk->lock);
204571f7a00bSVarun Prakash 
204671f7a00bSVarun Prakash 	return 0;
204771f7a00bSVarun Prakash }
204871f7a00bSVarun Prakash 
204971f7a00bSVarun Prakash static int ddp_set_map(struct cxgbi_ppm *ppm, struct cxgbi_sock *csk,
205071f7a00bSVarun Prakash 		       struct cxgbi_task_tag_info *ttinfo)
205171f7a00bSVarun Prakash {
205271f7a00bSVarun Prakash 	unsigned int pidx = ttinfo->idx;
205371f7a00bSVarun Prakash 	unsigned int npods = ttinfo->npods;
205471f7a00bSVarun Prakash 	unsigned int i, cnt;
205571f7a00bSVarun Prakash 	int err = 0;
205671f7a00bSVarun Prakash 	struct scatterlist *sg = ttinfo->sgl;
205771f7a00bSVarun Prakash 	unsigned int offset = 0;
205871f7a00bSVarun Prakash 
205971f7a00bSVarun Prakash 	ttinfo->cid = csk->port_id;
206071f7a00bSVarun Prakash 
206171f7a00bSVarun Prakash 	for (i = 0; i < npods; i += cnt, pidx += cnt) {
206271f7a00bSVarun Prakash 		cnt = npods - i;
206371f7a00bSVarun Prakash 
206471f7a00bSVarun Prakash 		if (cnt > ULPMEM_IDATA_MAX_NPPODS)
206571f7a00bSVarun Prakash 			cnt = ULPMEM_IDATA_MAX_NPPODS;
206671f7a00bSVarun Prakash 		err = ddp_ppod_write_idata(ppm, csk, ttinfo, pidx, cnt,
206771f7a00bSVarun Prakash 					   &sg, &offset);
206871f7a00bSVarun Prakash 		if (err < 0)
206971f7a00bSVarun Prakash 			break;
207071f7a00bSVarun Prakash 	}
207171f7a00bSVarun Prakash 
207271f7a00bSVarun Prakash 	return err;
207371f7a00bSVarun Prakash }
207471f7a00bSVarun Prakash 
20757b36b6e0Skxie@chelsio.com static int ddp_setup_conn_pgidx(struct cxgbi_sock *csk, unsigned int tid,
20769e8f1c79SVarun Prakash 				int pg_idx)
20777b36b6e0Skxie@chelsio.com {
20787b36b6e0Skxie@chelsio.com 	struct sk_buff *skb;
20797b36b6e0Skxie@chelsio.com 	struct cpl_set_tcb_field *req;
20807b36b6e0Skxie@chelsio.com 
2081e27d6169Skxie@chelsio.com 	if (!pg_idx || pg_idx >= DDP_PGIDX_MAX)
20827b36b6e0Skxie@chelsio.com 		return 0;
20837b36b6e0Skxie@chelsio.com 
208424d3f95aSkxie@chelsio.com 	skb = alloc_wr(sizeof(*req), 0, GFP_KERNEL);
20857b36b6e0Skxie@chelsio.com 	if (!skb)
20867b36b6e0Skxie@chelsio.com 		return -ENOMEM;
20877b36b6e0Skxie@chelsio.com 
2088e27d6169Skxie@chelsio.com 	/*  set up ulp page size */
20897b36b6e0Skxie@chelsio.com 	req = (struct cpl_set_tcb_field *)skb->head;
20907b36b6e0Skxie@chelsio.com 	INIT_TP_WR(req, csk->tid);
20917b36b6e0Skxie@chelsio.com 	OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_SET_TCB_FIELD, csk->tid));
20929e8f1c79SVarun Prakash 	req->reply_ctrl = htons(NO_REPLY_V(0) | QUEUENO_V(csk->rss_qid));
2093e27d6169Skxie@chelsio.com 	req->word_cookie = htons(0);
2094e27d6169Skxie@chelsio.com 	req->mask = cpu_to_be64(0x3 << 8);
2095e27d6169Skxie@chelsio.com 	req->val = cpu_to_be64(pg_idx << 8);
20967b36b6e0Skxie@chelsio.com 	set_wr_txq(skb, CPL_PRIORITY_CONTROL, csk->port_id);
20977b36b6e0Skxie@chelsio.com 
20987b36b6e0Skxie@chelsio.com 	log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
20997b36b6e0Skxie@chelsio.com 		"csk 0x%p, tid 0x%x, pg_idx %u.\n", csk, csk->tid, pg_idx);
21007b36b6e0Skxie@chelsio.com 
21019e8f1c79SVarun Prakash 	reinit_completion(&csk->cmpl);
21027b36b6e0Skxie@chelsio.com 	cxgb4_ofld_send(csk->cdev->ports[csk->port_id], skb);
21039e8f1c79SVarun Prakash 	wait_for_completion(&csk->cmpl);
21049e8f1c79SVarun Prakash 
21059e8f1c79SVarun Prakash 	return csk->err;
21067b36b6e0Skxie@chelsio.com }
21077b36b6e0Skxie@chelsio.com 
21087b36b6e0Skxie@chelsio.com static int ddp_setup_conn_digest(struct cxgbi_sock *csk, unsigned int tid,
21099e8f1c79SVarun Prakash 				 int hcrc, int dcrc)
21107b36b6e0Skxie@chelsio.com {
21117b36b6e0Skxie@chelsio.com 	struct sk_buff *skb;
21127b36b6e0Skxie@chelsio.com 	struct cpl_set_tcb_field *req;
21137b36b6e0Skxie@chelsio.com 
2114e27d6169Skxie@chelsio.com 	if (!hcrc && !dcrc)
2115e27d6169Skxie@chelsio.com 		return 0;
21167b36b6e0Skxie@chelsio.com 
211724d3f95aSkxie@chelsio.com 	skb = alloc_wr(sizeof(*req), 0, GFP_KERNEL);
21187b36b6e0Skxie@chelsio.com 	if (!skb)
21197b36b6e0Skxie@chelsio.com 		return -ENOMEM;
21207b36b6e0Skxie@chelsio.com 
21217b36b6e0Skxie@chelsio.com 	csk->hcrc_len = (hcrc ? 4 : 0);
21227b36b6e0Skxie@chelsio.com 	csk->dcrc_len = (dcrc ? 4 : 0);
2123e27d6169Skxie@chelsio.com 	/*  set up ulp submode */
21247b36b6e0Skxie@chelsio.com 	req = (struct cpl_set_tcb_field *)skb->head;
21257b36b6e0Skxie@chelsio.com 	INIT_TP_WR(req, tid);
21267b36b6e0Skxie@chelsio.com 	OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_SET_TCB_FIELD, tid));
21279e8f1c79SVarun Prakash 	req->reply_ctrl = htons(NO_REPLY_V(0) | QUEUENO_V(csk->rss_qid));
2128e27d6169Skxie@chelsio.com 	req->word_cookie = htons(0);
2129e27d6169Skxie@chelsio.com 	req->mask = cpu_to_be64(0x3 << 4);
2130e27d6169Skxie@chelsio.com 	req->val = cpu_to_be64(((hcrc ? ULP_CRC_HEADER : 0) |
2131e27d6169Skxie@chelsio.com 				(dcrc ? ULP_CRC_DATA : 0)) << 4);
21327b36b6e0Skxie@chelsio.com 	set_wr_txq(skb, CPL_PRIORITY_CONTROL, csk->port_id);
21337b36b6e0Skxie@chelsio.com 
21347b36b6e0Skxie@chelsio.com 	log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
21357b36b6e0Skxie@chelsio.com 		"csk 0x%p, tid 0x%x, crc %d,%d.\n", csk, csk->tid, hcrc, dcrc);
21367b36b6e0Skxie@chelsio.com 
21379e8f1c79SVarun Prakash 	reinit_completion(&csk->cmpl);
21387b36b6e0Skxie@chelsio.com 	cxgb4_ofld_send(csk->cdev->ports[csk->port_id], skb);
21399e8f1c79SVarun Prakash 	wait_for_completion(&csk->cmpl);
21409e8f1c79SVarun Prakash 
21419e8f1c79SVarun Prakash 	return csk->err;
21427b36b6e0Skxie@chelsio.com }
21437b36b6e0Skxie@chelsio.com 
214471f7a00bSVarun Prakash static struct cxgbi_ppm *cdev2ppm(struct cxgbi_device *cdev)
214571f7a00bSVarun Prakash {
214671f7a00bSVarun Prakash 	return (struct cxgbi_ppm *)(*((struct cxgb4_lld_info *)
214771f7a00bSVarun Prakash 				       (cxgbi_cdev_priv(cdev)))->iscsi_ppm);
214871f7a00bSVarun Prakash }
214971f7a00bSVarun Prakash 
21507b36b6e0Skxie@chelsio.com static int cxgb4i_ddp_init(struct cxgbi_device *cdev)
21517b36b6e0Skxie@chelsio.com {
215271f7a00bSVarun Prakash 	struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(cdev);
215371f7a00bSVarun Prakash 	struct net_device *ndev = cdev->ports[0];
215471f7a00bSVarun Prakash 	struct cxgbi_tag_format tformat;
2155a248384eSVarun Prakash 	int i, err;
215671f7a00bSVarun Prakash 
215771f7a00bSVarun Prakash 	if (!lldi->vr->iscsi.size) {
215871f7a00bSVarun Prakash 		pr_warn("%s, iscsi NOT enabled, check config!\n", ndev->name);
215971f7a00bSVarun Prakash 		return -EACCES;
216071f7a00bSVarun Prakash 	}
216171f7a00bSVarun Prakash 
216271f7a00bSVarun Prakash 	cdev->flags |= CXGBI_FLAG_USE_PPOD_OFLDQ;
216371f7a00bSVarun Prakash 
216471f7a00bSVarun Prakash 	memset(&tformat, 0, sizeof(struct cxgbi_tag_format));
216571f7a00bSVarun Prakash 	for (i = 0; i < 4; i++)
216671f7a00bSVarun Prakash 		tformat.pgsz_order[i] = (lldi->iscsi_pgsz_order >> (i << 3))
216771f7a00bSVarun Prakash 					 & 0xF;
216871f7a00bSVarun Prakash 	cxgbi_tagmask_check(lldi->iscsi_tagmask, &tformat);
216971f7a00bSVarun Prakash 
2170a248384eSVarun Prakash 	pr_info("iscsi_edram.start 0x%x iscsi_edram.size 0x%x",
2171a248384eSVarun Prakash 		lldi->vr->ppod_edram.start, lldi->vr->ppod_edram.size);
2172a248384eSVarun Prakash 
2173a248384eSVarun Prakash 	err = cxgbi_ddp_ppm_setup(lldi->iscsi_ppm, cdev, &tformat,
2174a248384eSVarun Prakash 				  lldi->vr->iscsi.size, lldi->iscsi_llimit,
2175a248384eSVarun Prakash 				  lldi->vr->iscsi.start, 2,
2176a248384eSVarun Prakash 				  lldi->vr->ppod_edram.start,
2177a248384eSVarun Prakash 				  lldi->vr->ppod_edram.size);
2178a248384eSVarun Prakash 
2179a248384eSVarun Prakash 	if (err < 0)
2180a248384eSVarun Prakash 		return err;
218171f7a00bSVarun Prakash 
21827b36b6e0Skxie@chelsio.com 	cdev->csk_ddp_setup_digest = ddp_setup_conn_digest;
21837b36b6e0Skxie@chelsio.com 	cdev->csk_ddp_setup_pgidx = ddp_setup_conn_pgidx;
218471f7a00bSVarun Prakash 	cdev->csk_ddp_set_map = ddp_set_map;
218571f7a00bSVarun Prakash 	cdev->tx_max_size = min_t(unsigned int, ULP2_MAX_PDU_PAYLOAD,
218671f7a00bSVarun Prakash 				  lldi->iscsi_iolen - ISCSI_PDU_NONPAYLOAD_LEN);
218771f7a00bSVarun Prakash 	cdev->rx_max_size = min_t(unsigned int, ULP2_MAX_PDU_PAYLOAD,
218871f7a00bSVarun Prakash 				  lldi->iscsi_iolen - ISCSI_PDU_NONPAYLOAD_LEN);
218971f7a00bSVarun Prakash 	cdev->cdev2ppm = cdev2ppm;
219071f7a00bSVarun Prakash 
21917b36b6e0Skxie@chelsio.com 	return 0;
21927b36b6e0Skxie@chelsio.com }
21937b36b6e0Skxie@chelsio.com 
2194e33c2482SVarun Prakash static bool is_memfree(struct adapter *adap)
2195e33c2482SVarun Prakash {
2196e33c2482SVarun Prakash 	u32 io;
2197e33c2482SVarun Prakash 
2198e33c2482SVarun Prakash 	io = t4_read_reg(adap, MA_TARGET_MEM_ENABLE_A);
2199e33c2482SVarun Prakash 	if (is_t5(adap->params.chip)) {
2200e33c2482SVarun Prakash 		if ((io & EXT_MEM0_ENABLE_F) || (io & EXT_MEM1_ENABLE_F))
2201e33c2482SVarun Prakash 			return false;
2202e33c2482SVarun Prakash 	} else if (io & EXT_MEM_ENABLE_F) {
2203e33c2482SVarun Prakash 		return false;
2204e33c2482SVarun Prakash 	}
2205e33c2482SVarun Prakash 
2206e33c2482SVarun Prakash 	return true;
2207e33c2482SVarun Prakash }
2208e33c2482SVarun Prakash 
22097b36b6e0Skxie@chelsio.com static void *t4_uld_add(const struct cxgb4_lld_info *lldi)
22107b36b6e0Skxie@chelsio.com {
22117b36b6e0Skxie@chelsio.com 	struct cxgbi_device *cdev;
22127b36b6e0Skxie@chelsio.com 	struct port_info *pi;
2213e33c2482SVarun Prakash 	struct net_device *ndev;
2214e33c2482SVarun Prakash 	struct adapter *adap;
2215e33c2482SVarun Prakash 	struct tid_info *t;
2216e33c2482SVarun Prakash 	u32 max_cmds = CXGB4I_SCSI_HOST_QDEPTH;
2217e33c2482SVarun Prakash 	u32 max_conn = CXGBI_MAX_CONN;
22187b36b6e0Skxie@chelsio.com 	int i, rc;
22197b36b6e0Skxie@chelsio.com 
22207b36b6e0Skxie@chelsio.com 	cdev = cxgbi_device_register(sizeof(*lldi), lldi->nports);
22217b36b6e0Skxie@chelsio.com 	if (!cdev) {
22227b36b6e0Skxie@chelsio.com 		pr_info("t4 device 0x%p, register failed.\n", lldi);
22237b36b6e0Skxie@chelsio.com 		return NULL;
22247b36b6e0Skxie@chelsio.com 	}
22257b36b6e0Skxie@chelsio.com 	pr_info("0x%p,0x%x, ports %u,%s, chan %u, q %u,%u, wr %u.\n",
22267b36b6e0Skxie@chelsio.com 		cdev, lldi->adapter_type, lldi->nports,
22277b36b6e0Skxie@chelsio.com 		lldi->ports[0]->name, lldi->nchan, lldi->ntxq,
22287b36b6e0Skxie@chelsio.com 		lldi->nrxq, lldi->wr_cred);
22297b36b6e0Skxie@chelsio.com 	for (i = 0; i < lldi->nrxq; i++)
22307b36b6e0Skxie@chelsio.com 		log_debug(1 << CXGBI_DBG_DEV,
22317b36b6e0Skxie@chelsio.com 			"t4 0x%p, rxq id #%d: %u.\n",
22327b36b6e0Skxie@chelsio.com 			cdev, i, lldi->rxq_ids[i]);
22337b36b6e0Skxie@chelsio.com 
22347b36b6e0Skxie@chelsio.com 	memcpy(cxgbi_cdev_priv(cdev), lldi, sizeof(*lldi));
22357b36b6e0Skxie@chelsio.com 	cdev->flags = CXGBI_FLAG_DEV_T4;
22367b36b6e0Skxie@chelsio.com 	cdev->pdev = lldi->pdev;
22377b36b6e0Skxie@chelsio.com 	cdev->ports = lldi->ports;
22387b36b6e0Skxie@chelsio.com 	cdev->nports = lldi->nports;
22397b36b6e0Skxie@chelsio.com 	cdev->mtus = lldi->mtus;
22407b36b6e0Skxie@chelsio.com 	cdev->nmtus = NMTUS;
2241586be7cbSVarun Prakash 	cdev->rx_credit_thres = (CHELSIO_CHIP_VERSION(lldi->adapter_type) <=
2242586be7cbSVarun Prakash 				 CHELSIO_T5) ? cxgb4i_rx_credit_thres : 0;
22437b36b6e0Skxie@chelsio.com 	cdev->skb_tx_rsvd = CXGB4I_TX_HEADER_LEN;
22447b36b6e0Skxie@chelsio.com 	cdev->skb_rx_extra = sizeof(struct cpl_iscsi_hdr);
22457b36b6e0Skxie@chelsio.com 	cdev->itp = &cxgb4i_iscsi_transport;
22461fe1fdb0SVarun Prakash 	cdev->owner = THIS_MODULE;
22477b36b6e0Skxie@chelsio.com 
2248b184487cSVarun Prakash 	cdev->pfvf = FW_PFVF_CMD_PFN_V(lldi->pf);
2249e27d6169Skxie@chelsio.com 	pr_info("cdev 0x%p,%s, pfvf %u.\n",
2250e27d6169Skxie@chelsio.com 		cdev, lldi->ports[0]->name, cdev->pfvf);
2251e27d6169Skxie@chelsio.com 
22527b36b6e0Skxie@chelsio.com 	rc = cxgb4i_ddp_init(cdev);
22537b36b6e0Skxie@chelsio.com 	if (rc) {
2254a248384eSVarun Prakash 		pr_info("t4 0x%p ddp init failed %d.\n", cdev, rc);
22557b36b6e0Skxie@chelsio.com 		goto err_out;
22567b36b6e0Skxie@chelsio.com 	}
2257e33c2482SVarun Prakash 
2258e33c2482SVarun Prakash 	ndev = cdev->ports[0];
2259e33c2482SVarun Prakash 	adap = netdev2adap(ndev);
2260e33c2482SVarun Prakash 	if (adap) {
2261e33c2482SVarun Prakash 		t = &adap->tids;
2262e33c2482SVarun Prakash 		if (t->ntids <= CXGBI_MAX_CONN)
2263e33c2482SVarun Prakash 			max_conn = t->ntids;
2264e33c2482SVarun Prakash 
2265e33c2482SVarun Prakash 		if (is_memfree(adap)) {
2266e33c2482SVarun Prakash 			cdev->flags |=	CXGBI_FLAG_DEV_ISO_OFF;
2267e33c2482SVarun Prakash 			max_cmds = CXGB4I_SCSI_HOST_QDEPTH >> 2;
2268e33c2482SVarun Prakash 
2269e33c2482SVarun Prakash 			pr_info("%s: 0x%p, tid %u, SO adapter.\n",
2270e33c2482SVarun Prakash 				ndev->name, cdev, t->ntids);
2271e33c2482SVarun Prakash 		}
2272e33c2482SVarun Prakash 	} else {
2273e33c2482SVarun Prakash 		pr_info("%s, 0x%p, NO adapter struct.\n", ndev->name, cdev);
2274e33c2482SVarun Prakash 	}
2275e33c2482SVarun Prakash 
2276e33c2482SVarun Prakash 	/* ISO is enabled in T5/T6 firmware version >= 1.13.43.0 */
2277e33c2482SVarun Prakash 	if (!is_t4(lldi->adapter_type) &&
2278e33c2482SVarun Prakash 	    (lldi->fw_vers >= 0x10d2b00) &&
2279e33c2482SVarun Prakash 	    !(cdev->flags & CXGBI_FLAG_DEV_ISO_OFF))
2280e33c2482SVarun Prakash 		cdev->skb_iso_txhdr = sizeof(struct cpl_tx_data_iso);
2281e33c2482SVarun Prakash 
22827b36b6e0Skxie@chelsio.com 	rc = cxgb4i_ofld_init(cdev);
22837b36b6e0Skxie@chelsio.com 	if (rc) {
22847b36b6e0Skxie@chelsio.com 		pr_info("t4 0x%p ofld init failed.\n", cdev);
22857b36b6e0Skxie@chelsio.com 		goto err_out;
22867b36b6e0Skxie@chelsio.com 	}
22877b36b6e0Skxie@chelsio.com 
2288e33c2482SVarun Prakash 	cxgb4i_host_template.can_queue = max_cmds;
2289e33c2482SVarun Prakash 	rc = cxgbi_hbas_add(cdev, CXGB4I_MAX_LUN, max_conn,
22907b36b6e0Skxie@chelsio.com 			    &cxgb4i_host_template, cxgb4i_stt);
22917b36b6e0Skxie@chelsio.com 	if (rc)
22927b36b6e0Skxie@chelsio.com 		goto err_out;
22937b36b6e0Skxie@chelsio.com 
22947b36b6e0Skxie@chelsio.com 	for (i = 0; i < cdev->nports; i++) {
22957b36b6e0Skxie@chelsio.com 		pi = netdev_priv(lldi->ports[i]);
22967b36b6e0Skxie@chelsio.com 		cdev->hbas[i]->port_id = pi->port_id;
22977b36b6e0Skxie@chelsio.com 	}
22987b36b6e0Skxie@chelsio.com 	return cdev;
22997b36b6e0Skxie@chelsio.com 
23007b36b6e0Skxie@chelsio.com err_out:
23017b36b6e0Skxie@chelsio.com 	cxgbi_device_unregister(cdev);
23027b36b6e0Skxie@chelsio.com 	return ERR_PTR(-ENOMEM);
23037b36b6e0Skxie@chelsio.com }
23047b36b6e0Skxie@chelsio.com 
23057b36b6e0Skxie@chelsio.com #define RX_PULL_LEN	128
23067b36b6e0Skxie@chelsio.com static int t4_uld_rx_handler(void *handle, const __be64 *rsp,
23077b36b6e0Skxie@chelsio.com 				const struct pkt_gl *pgl)
23087b36b6e0Skxie@chelsio.com {
23097b36b6e0Skxie@chelsio.com 	const struct cpl_act_establish *rpl;
23107b36b6e0Skxie@chelsio.com 	struct sk_buff *skb;
23117b36b6e0Skxie@chelsio.com 	unsigned int opc;
23127b36b6e0Skxie@chelsio.com 	struct cxgbi_device *cdev = handle;
23137b36b6e0Skxie@chelsio.com 
23147b36b6e0Skxie@chelsio.com 	if (pgl == NULL) {
23157b36b6e0Skxie@chelsio.com 		unsigned int len = 64 - sizeof(struct rsp_ctrl) - 8;
23167b36b6e0Skxie@chelsio.com 
231724d3f95aSkxie@chelsio.com 		skb = alloc_wr(len, 0, GFP_ATOMIC);
23187b36b6e0Skxie@chelsio.com 		if (!skb)
23197b36b6e0Skxie@chelsio.com 			goto nomem;
23207b36b6e0Skxie@chelsio.com 		skb_copy_to_linear_data(skb, &rsp[1], len);
23217b36b6e0Skxie@chelsio.com 	} else {
23227b36b6e0Skxie@chelsio.com 		if (unlikely(*(u8 *)rsp != *(u8 *)pgl->va)) {
23237b36b6e0Skxie@chelsio.com 			pr_info("? FL 0x%p,RSS%#llx,FL %#llx,len %u.\n",
23247b36b6e0Skxie@chelsio.com 				pgl->va, be64_to_cpu(*rsp),
23257b36b6e0Skxie@chelsio.com 				be64_to_cpu(*(u64 *)pgl->va),
23267b36b6e0Skxie@chelsio.com 				pgl->tot_len);
23277b36b6e0Skxie@chelsio.com 			return 0;
23287b36b6e0Skxie@chelsio.com 		}
23297b36b6e0Skxie@chelsio.com 		skb = cxgb4_pktgl_to_skb(pgl, RX_PULL_LEN, RX_PULL_LEN);
23307b36b6e0Skxie@chelsio.com 		if (unlikely(!skb))
23317b36b6e0Skxie@chelsio.com 			goto nomem;
23327b36b6e0Skxie@chelsio.com 	}
23337b36b6e0Skxie@chelsio.com 
23347b36b6e0Skxie@chelsio.com 	rpl = (struct cpl_act_establish *)skb->data;
23357b36b6e0Skxie@chelsio.com 	opc = rpl->ot.opcode;
23367b36b6e0Skxie@chelsio.com 	log_debug(1 << CXGBI_DBG_TOE,
23377b36b6e0Skxie@chelsio.com 		"cdev %p, opcode 0x%x(0x%x,0x%x), skb %p.\n",
23387b36b6e0Skxie@chelsio.com 		 cdev, opc, rpl->ot.opcode_tid, ntohl(rpl->ot.opcode_tid), skb);
2339ccc495efSDan Carpenter 	if (opc >= ARRAY_SIZE(cxgb4i_cplhandlers) || !cxgb4i_cplhandlers[opc]) {
23407b36b6e0Skxie@chelsio.com 		pr_err("No handler for opcode 0x%x.\n", opc);
23417b36b6e0Skxie@chelsio.com 		__kfree_skb(skb);
2342ccc495efSDan Carpenter 	} else
2343ccc495efSDan Carpenter 		cxgb4i_cplhandlers[opc](cdev, skb);
2344ccc495efSDan Carpenter 
23457b36b6e0Skxie@chelsio.com 	return 0;
23467b36b6e0Skxie@chelsio.com nomem:
23477b36b6e0Skxie@chelsio.com 	log_debug(1 << CXGBI_DBG_TOE, "OOM bailing out.\n");
23487b36b6e0Skxie@chelsio.com 	return 1;
23497b36b6e0Skxie@chelsio.com }
23507b36b6e0Skxie@chelsio.com 
23517b36b6e0Skxie@chelsio.com static int t4_uld_state_change(void *handle, enum cxgb4_state state)
23527b36b6e0Skxie@chelsio.com {
23537b36b6e0Skxie@chelsio.com 	struct cxgbi_device *cdev = handle;
23547b36b6e0Skxie@chelsio.com 
23557b36b6e0Skxie@chelsio.com 	switch (state) {
23567b36b6e0Skxie@chelsio.com 	case CXGB4_STATE_UP:
23577b36b6e0Skxie@chelsio.com 		pr_info("cdev 0x%p, UP.\n", cdev);
23587b36b6e0Skxie@chelsio.com 		break;
23597b36b6e0Skxie@chelsio.com 	case CXGB4_STATE_START_RECOVERY:
23607b36b6e0Skxie@chelsio.com 		pr_info("cdev 0x%p, RECOVERY.\n", cdev);
23617b36b6e0Skxie@chelsio.com 		/* close all connections */
23627b36b6e0Skxie@chelsio.com 		break;
23637b36b6e0Skxie@chelsio.com 	case CXGB4_STATE_DOWN:
23647b36b6e0Skxie@chelsio.com 		pr_info("cdev 0x%p, DOWN.\n", cdev);
23657b36b6e0Skxie@chelsio.com 		break;
23667b36b6e0Skxie@chelsio.com 	case CXGB4_STATE_DETACH:
23677b36b6e0Skxie@chelsio.com 		pr_info("cdev 0x%p, DETACH.\n", cdev);
2368c3b331a3SThadeu Lima de Souza Cascardo 		cxgbi_device_unregister(cdev);
23697b36b6e0Skxie@chelsio.com 		break;
23707b36b6e0Skxie@chelsio.com 	default:
23717b36b6e0Skxie@chelsio.com 		pr_info("cdev 0x%p, unknown state %d.\n", cdev, state);
23727b36b6e0Skxie@chelsio.com 		break;
23737b36b6e0Skxie@chelsio.com 	}
23747b36b6e0Skxie@chelsio.com 	return 0;
23757b36b6e0Skxie@chelsio.com }
23767b36b6e0Skxie@chelsio.com 
2377b5a5fe4eSVarun Prakash #ifdef CONFIG_CHELSIO_T4_DCB
2378b5a5fe4eSVarun Prakash static int
2379b5a5fe4eSVarun Prakash cxgb4_dcb_change_notify(struct notifier_block *self, unsigned long val,
2380b5a5fe4eSVarun Prakash 			void *data)
2381b5a5fe4eSVarun Prakash {
2382b5a5fe4eSVarun Prakash 	int i, port = 0xFF;
2383b5a5fe4eSVarun Prakash 	struct net_device *ndev;
2384b5a5fe4eSVarun Prakash 	struct cxgbi_device *cdev = NULL;
2385b5a5fe4eSVarun Prakash 	struct dcb_app_type *iscsi_app = data;
2386b5a5fe4eSVarun Prakash 	struct cxgbi_ports_map *pmap;
2387b5a5fe4eSVarun Prakash 	u8 priority;
2388b5a5fe4eSVarun Prakash 
2389b5a5fe4eSVarun Prakash 	if (iscsi_app->dcbx & DCB_CAP_DCBX_VER_IEEE) {
2390152e30fcSVarun Prakash 		if ((iscsi_app->app.selector != IEEE_8021QAZ_APP_SEL_STREAM) &&
2391152e30fcSVarun Prakash 		    (iscsi_app->app.selector != IEEE_8021QAZ_APP_SEL_ANY))
2392b5a5fe4eSVarun Prakash 			return NOTIFY_DONE;
2393b5a5fe4eSVarun Prakash 
2394b5a5fe4eSVarun Prakash 		priority = iscsi_app->app.priority;
2395b5a5fe4eSVarun Prakash 	} else if (iscsi_app->dcbx & DCB_CAP_DCBX_VER_CEE) {
2396b5a5fe4eSVarun Prakash 		if (iscsi_app->app.selector != DCB_APP_IDTYPE_PORTNUM)
2397b5a5fe4eSVarun Prakash 			return NOTIFY_DONE;
2398b5a5fe4eSVarun Prakash 
2399b5a5fe4eSVarun Prakash 		if (!iscsi_app->app.priority)
2400b5a5fe4eSVarun Prakash 			return NOTIFY_DONE;
2401b5a5fe4eSVarun Prakash 
2402b5a5fe4eSVarun Prakash 		priority = ffs(iscsi_app->app.priority) - 1;
2403b5a5fe4eSVarun Prakash 	} else {
2404b5a5fe4eSVarun Prakash 		return NOTIFY_DONE;
2405b5a5fe4eSVarun Prakash 	}
2406b5a5fe4eSVarun Prakash 
2407b5a5fe4eSVarun Prakash 	if (iscsi_app->app.protocol != 3260)
2408b5a5fe4eSVarun Prakash 		return NOTIFY_DONE;
2409b5a5fe4eSVarun Prakash 
2410b5a5fe4eSVarun Prakash 	log_debug(1 << CXGBI_DBG_ISCSI, "iSCSI priority for ifid %d is %u\n",
2411b5a5fe4eSVarun Prakash 		  iscsi_app->ifindex, priority);
2412b5a5fe4eSVarun Prakash 
2413b5a5fe4eSVarun Prakash 	ndev = dev_get_by_index(&init_net, iscsi_app->ifindex);
2414b5a5fe4eSVarun Prakash 	if (!ndev)
2415b5a5fe4eSVarun Prakash 		return NOTIFY_DONE;
2416b5a5fe4eSVarun Prakash 
2417b5a5fe4eSVarun Prakash 	cdev = cxgbi_device_find_by_netdev_rcu(ndev, &port);
2418b5a5fe4eSVarun Prakash 
2419b5a5fe4eSVarun Prakash 	dev_put(ndev);
2420b5a5fe4eSVarun Prakash 	if (!cdev)
2421b5a5fe4eSVarun Prakash 		return NOTIFY_DONE;
2422b5a5fe4eSVarun Prakash 
2423b5a5fe4eSVarun Prakash 	pmap = &cdev->pmap;
2424b5a5fe4eSVarun Prakash 
2425b5a5fe4eSVarun Prakash 	for (i = 0; i < pmap->used; i++) {
2426b5a5fe4eSVarun Prakash 		if (pmap->port_csk[i]) {
2427b5a5fe4eSVarun Prakash 			struct cxgbi_sock *csk = pmap->port_csk[i];
2428b5a5fe4eSVarun Prakash 
2429b5a5fe4eSVarun Prakash 			if (csk->dcb_priority != priority) {
2430b5a5fe4eSVarun Prakash 				iscsi_conn_failure(csk->user_data,
2431b5a5fe4eSVarun Prakash 						   ISCSI_ERR_CONN_FAILED);
2432b5a5fe4eSVarun Prakash 				pr_info("Restarting iSCSI connection %p with "
2433b5a5fe4eSVarun Prakash 					"priority %u->%u.\n", csk,
2434b5a5fe4eSVarun Prakash 					csk->dcb_priority, priority);
2435b5a5fe4eSVarun Prakash 			}
2436b5a5fe4eSVarun Prakash 		}
2437b5a5fe4eSVarun Prakash 	}
2438b5a5fe4eSVarun Prakash 	return NOTIFY_OK;
2439b5a5fe4eSVarun Prakash }
2440b5a5fe4eSVarun Prakash #endif
2441b5a5fe4eSVarun Prakash 
24427b36b6e0Skxie@chelsio.com static int __init cxgb4i_init_module(void)
24437b36b6e0Skxie@chelsio.com {
24447b36b6e0Skxie@chelsio.com 	int rc;
24457b36b6e0Skxie@chelsio.com 
24467b36b6e0Skxie@chelsio.com 	printk(KERN_INFO "%s", version);
24477b36b6e0Skxie@chelsio.com 
24487b36b6e0Skxie@chelsio.com 	rc = cxgbi_iscsi_init(&cxgb4i_iscsi_transport, &cxgb4i_stt);
24497b36b6e0Skxie@chelsio.com 	if (rc < 0)
24507b36b6e0Skxie@chelsio.com 		return rc;
24517b36b6e0Skxie@chelsio.com 	cxgb4_register_uld(CXGB4_ULD_ISCSI, &cxgb4i_uld_info);
2452759a0cc5SAnish Bhatt 
2453b5a5fe4eSVarun Prakash #ifdef CONFIG_CHELSIO_T4_DCB
2454b5a5fe4eSVarun Prakash 	pr_info("%s dcb enabled.\n", DRV_MODULE_NAME);
2455b5a5fe4eSVarun Prakash 	register_dcbevent_notifier(&cxgb4_dcb_change);
2456b5a5fe4eSVarun Prakash #endif
24577b36b6e0Skxie@chelsio.com 	return 0;
24587b36b6e0Skxie@chelsio.com }
24597b36b6e0Skxie@chelsio.com 
24607b36b6e0Skxie@chelsio.com static void __exit cxgb4i_exit_module(void)
24617b36b6e0Skxie@chelsio.com {
2462b5a5fe4eSVarun Prakash #ifdef CONFIG_CHELSIO_T4_DCB
2463b5a5fe4eSVarun Prakash 	unregister_dcbevent_notifier(&cxgb4_dcb_change);
2464b5a5fe4eSVarun Prakash #endif
24657b36b6e0Skxie@chelsio.com 	cxgb4_unregister_uld(CXGB4_ULD_ISCSI);
24667b36b6e0Skxie@chelsio.com 	cxgbi_device_unregister_all(CXGBI_FLAG_DEV_T4);
24677b36b6e0Skxie@chelsio.com 	cxgbi_iscsi_cleanup(&cxgb4i_iscsi_transport, &cxgb4i_stt);
24687b36b6e0Skxie@chelsio.com }
24697b36b6e0Skxie@chelsio.com 
24707b36b6e0Skxie@chelsio.com module_init(cxgb4i_init_module);
24717b36b6e0Skxie@chelsio.com module_exit(cxgb4i_exit_module);
2472