xref: /openbmc/linux/drivers/scsi/cxgbi/cxgb4i/cxgb4i.c (revision a251c17a)
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,
119db22de3eSBart Van Assche 	.cmd_size	= sizeof(struct iscsi_cmd),
1207b36b6e0Skxie@chelsio.com };
1217b36b6e0Skxie@chelsio.com 
1227b36b6e0Skxie@chelsio.com static struct iscsi_transport cxgb4i_iscsi_transport = {
1237b36b6e0Skxie@chelsio.com 	.owner		= THIS_MODULE,
1247b36b6e0Skxie@chelsio.com 	.name		= DRV_MODULE_NAME,
1257b36b6e0Skxie@chelsio.com 	.caps		= CAP_RECOVERY_L0 | CAP_MULTI_R2T | CAP_HDRDGST |
1267b36b6e0Skxie@chelsio.com 				CAP_DATADGST | CAP_DIGEST_OFFLOAD |
127fdafd4dfSMike Christie 				CAP_PADDING_OFFLOAD | CAP_TEXT_NEGO,
1283128c6c7SMike Christie 	.attr_is_visible	= cxgbi_attr_is_visible,
1297b36b6e0Skxie@chelsio.com 	.get_host_param	= cxgbi_get_host_param,
1307b36b6e0Skxie@chelsio.com 	.set_host_param	= cxgbi_set_host_param,
1317b36b6e0Skxie@chelsio.com 	/* session management */
1327b36b6e0Skxie@chelsio.com 	.create_session	= cxgbi_create_session,
1337b36b6e0Skxie@chelsio.com 	.destroy_session	= cxgbi_destroy_session,
1347b36b6e0Skxie@chelsio.com 	.get_session_param = iscsi_session_get_param,
1357b36b6e0Skxie@chelsio.com 	/* connection management */
1367b36b6e0Skxie@chelsio.com 	.create_conn	= cxgbi_create_conn,
1377b36b6e0Skxie@chelsio.com 	.bind_conn		= cxgbi_bind_conn,
138891e2639SMike Christie 	.unbind_conn	= iscsi_conn_unbind,
1397b36b6e0Skxie@chelsio.com 	.destroy_conn	= iscsi_tcp_conn_teardown,
1407b36b6e0Skxie@chelsio.com 	.start_conn		= iscsi_conn_start,
1417b36b6e0Skxie@chelsio.com 	.stop_conn		= iscsi_conn_stop,
142c71b9b66SMike Christie 	.get_conn_param	= iscsi_conn_get_param,
1437b36b6e0Skxie@chelsio.com 	.set_param	= cxgbi_set_conn_param,
1447b36b6e0Skxie@chelsio.com 	.get_stats	= cxgbi_get_conn_stats,
1457b36b6e0Skxie@chelsio.com 	/* pdu xmit req from user space */
1467b36b6e0Skxie@chelsio.com 	.send_pdu	= iscsi_conn_send_pdu,
1477b36b6e0Skxie@chelsio.com 	/* task */
1487b36b6e0Skxie@chelsio.com 	.init_task	= iscsi_tcp_task_init,
1497b36b6e0Skxie@chelsio.com 	.xmit_task	= iscsi_tcp_task_xmit,
1507b36b6e0Skxie@chelsio.com 	.cleanup_task	= cxgbi_cleanup_task,
1517b36b6e0Skxie@chelsio.com 	/* pdu */
1527b36b6e0Skxie@chelsio.com 	.alloc_pdu	= cxgbi_conn_alloc_pdu,
1537b36b6e0Skxie@chelsio.com 	.init_pdu	= cxgbi_conn_init_pdu,
1547b36b6e0Skxie@chelsio.com 	.xmit_pdu	= cxgbi_conn_xmit_pdu,
1557b36b6e0Skxie@chelsio.com 	.parse_pdu_itt	= cxgbi_parse_pdu_itt,
1567b36b6e0Skxie@chelsio.com 	/* TCP connect/disconnect */
157c71b9b66SMike Christie 	.get_ep_param	= cxgbi_get_ep_param,
1587b36b6e0Skxie@chelsio.com 	.ep_connect	= cxgbi_ep_connect,
1597b36b6e0Skxie@chelsio.com 	.ep_poll	= cxgbi_ep_poll,
1607b36b6e0Skxie@chelsio.com 	.ep_disconnect	= cxgbi_ep_disconnect,
1617b36b6e0Skxie@chelsio.com 	/* Error recovery timeout call */
1627b36b6e0Skxie@chelsio.com 	.session_recovery_timedout = iscsi_session_recovery_timedout,
1637b36b6e0Skxie@chelsio.com };
1647b36b6e0Skxie@chelsio.com 
165b5a5fe4eSVarun Prakash #ifdef CONFIG_CHELSIO_T4_DCB
166b5a5fe4eSVarun Prakash static int
167b5a5fe4eSVarun Prakash cxgb4_dcb_change_notify(struct notifier_block *, unsigned long, void *);
168b5a5fe4eSVarun Prakash 
169b5a5fe4eSVarun Prakash static struct notifier_block cxgb4_dcb_change = {
170b5a5fe4eSVarun Prakash 	.notifier_call = cxgb4_dcb_change_notify,
171b5a5fe4eSVarun Prakash };
172b5a5fe4eSVarun Prakash #endif
173b5a5fe4eSVarun Prakash 
1747b36b6e0Skxie@chelsio.com static struct scsi_transport_template *cxgb4i_stt;
1757b36b6e0Skxie@chelsio.com 
1767b36b6e0Skxie@chelsio.com /*
1777b36b6e0Skxie@chelsio.com  * CPL (Chelsio Protocol Language) defines a message passing interface between
1787b36b6e0Skxie@chelsio.com  * the host driver and Chelsio asic.
1797b36b6e0Skxie@chelsio.com  * The section below implments CPLs that related to iscsi tcp connection
1807b36b6e0Skxie@chelsio.com  * open/close/abort and data send/receive.
1817b36b6e0Skxie@chelsio.com  */
182759a0cc5SAnish Bhatt 
1837b36b6e0Skxie@chelsio.com #define RCV_BUFSIZ_MASK		0x3FFU
184d3074cceSKaren Xie #define MAX_IMM_TX_PKT_LEN	256
1857b36b6e0Skxie@chelsio.com 
1867b36b6e0Skxie@chelsio.com static int push_tx_frames(struct cxgbi_sock *, int);
1877b36b6e0Skxie@chelsio.com 
1887b36b6e0Skxie@chelsio.com /*
1897b36b6e0Skxie@chelsio.com  * is_ofld_imm - check whether a packet can be sent as immediate data
1907b36b6e0Skxie@chelsio.com  * @skb: the packet
1917b36b6e0Skxie@chelsio.com  *
1927b36b6e0Skxie@chelsio.com  * Returns true if a packet can be sent as an offload WR with immediate
1937b36b6e0Skxie@chelsio.com  * data.  We currently use the same limit as for Ethernet packets.
1947b36b6e0Skxie@chelsio.com  */
is_ofld_imm(const struct sk_buff * skb)19584944d8cSKaren Xie static inline bool is_ofld_imm(const struct sk_buff *skb)
1967b36b6e0Skxie@chelsio.com {
19784944d8cSKaren Xie 	int len = skb->len;
19884944d8cSKaren Xie 
19984944d8cSKaren Xie 	if (likely(cxgbi_skcb_test_flag(skb, SKCBF_TX_NEED_HDR)))
20084944d8cSKaren Xie 		len += sizeof(struct fw_ofld_tx_data_wr);
20184944d8cSKaren Xie 
202e33c2482SVarun Prakash 	if  (likely(cxgbi_skcb_test_flag((struct sk_buff *)skb, SKCBF_TX_ISO)))
203e33c2482SVarun Prakash 		len += sizeof(struct cpl_tx_data_iso);
204e33c2482SVarun Prakash 
205e33c2482SVarun Prakash 	return (len <= MAX_IMM_OFLD_TX_DATA_WR_LEN);
2067b36b6e0Skxie@chelsio.com }
2077b36b6e0Skxie@chelsio.com 
send_act_open_req(struct cxgbi_sock * csk,struct sk_buff * skb,struct l2t_entry * e)2087b36b6e0Skxie@chelsio.com static void send_act_open_req(struct cxgbi_sock *csk, struct sk_buff *skb,
2097b36b6e0Skxie@chelsio.com 				struct l2t_entry *e)
2107b36b6e0Skxie@chelsio.com {
2113bd3e8bfSKaren Xie 	struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(csk->cdev);
2127b36b6e0Skxie@chelsio.com 	int wscale = cxgbi_sock_compute_wscale(csk->mss_idx);
2137b36b6e0Skxie@chelsio.com 	unsigned long long opt0;
2147b36b6e0Skxie@chelsio.com 	unsigned int opt2;
2157b36b6e0Skxie@chelsio.com 	unsigned int qid_atid = ((unsigned int)csk->atid) |
2167b36b6e0Skxie@chelsio.com 				 (((unsigned int)csk->rss_qid) << 14);
2177b36b6e0Skxie@chelsio.com 
218d7990b0cSAnish Bhatt 	opt0 = KEEP_ALIVE_F |
219d7990b0cSAnish Bhatt 		WND_SCALE_V(wscale) |
220d7990b0cSAnish Bhatt 		MSS_IDX_V(csk->mss_idx) |
221d7990b0cSAnish Bhatt 		L2T_IDX_V(((struct l2t_entry *)csk->l2t)->idx) |
222d7990b0cSAnish Bhatt 		TX_CHAN_V(csk->tx_chan) |
223d7990b0cSAnish Bhatt 		SMAC_SEL_V(csk->smac_idx) |
224d7990b0cSAnish Bhatt 		ULP_MODE_V(ULP_MODE_ISCSI) |
22581daf10cSKaren Xie 		RCV_BUFSIZ_V(csk->rcv_win >> 10);
2261eb88a5dSKaren Xie 
227d7990b0cSAnish Bhatt 	opt2 = RX_CHANNEL_V(0) |
228d7990b0cSAnish Bhatt 		RSS_QUEUE_VALID_F |
229d7990b0cSAnish Bhatt 		RSS_QUEUE_V(csk->rss_qid);
2307b36b6e0Skxie@chelsio.com 
2313bd3e8bfSKaren Xie 	if (is_t4(lldi->adapter_type)) {
2323bd3e8bfSKaren Xie 		struct cpl_act_open_req *req =
2333bd3e8bfSKaren Xie 				(struct cpl_act_open_req *)skb->head;
2343bd3e8bfSKaren Xie 
2357b36b6e0Skxie@chelsio.com 		INIT_TP_WR(req, 0);
2367b36b6e0Skxie@chelsio.com 		OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_ACT_OPEN_REQ,
2377b36b6e0Skxie@chelsio.com 					qid_atid));
2387b36b6e0Skxie@chelsio.com 		req->local_port = csk->saddr.sin_port;
2397b36b6e0Skxie@chelsio.com 		req->peer_port = csk->daddr.sin_port;
2407b36b6e0Skxie@chelsio.com 		req->local_ip = csk->saddr.sin_addr.s_addr;
2417b36b6e0Skxie@chelsio.com 		req->peer_ip = csk->daddr.sin_addr.s_addr;
2427b36b6e0Skxie@chelsio.com 		req->opt0 = cpu_to_be64(opt0);
243ac0245ffSKaren Xie 		req->params = cpu_to_be32(cxgb4_select_ntuple(
244ac0245ffSKaren Xie 					csk->cdev->ports[csk->port_id],
245ac0245ffSKaren Xie 					csk->l2t));
246d7990b0cSAnish Bhatt 		opt2 |= RX_FC_VALID_F;
2477b36b6e0Skxie@chelsio.com 		req->opt2 = cpu_to_be32(opt2);
2487b36b6e0Skxie@chelsio.com 
2497b36b6e0Skxie@chelsio.com 		log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
2503bd3e8bfSKaren Xie 			"csk t4 0x%p, %pI4:%u-%pI4:%u, atid %d, qid %u.\n",
2517b36b6e0Skxie@chelsio.com 			csk, &req->local_ip, ntohs(req->local_port),
2527b36b6e0Skxie@chelsio.com 			&req->peer_ip, ntohs(req->peer_port),
2537b36b6e0Skxie@chelsio.com 			csk->atid, csk->rss_qid);
254586be7cbSVarun Prakash 	} else if (is_t5(lldi->adapter_type)) {
2553bd3e8bfSKaren Xie 		struct cpl_t5_act_open_req *req =
2563bd3e8bfSKaren Xie 				(struct cpl_t5_act_open_req *)skb->head;
257*a251c17aSJason A. Donenfeld 		u32 isn = (get_random_u32() & ~7UL) - 1;
2587b36b6e0Skxie@chelsio.com 
2593bd3e8bfSKaren Xie 		INIT_TP_WR(req, 0);
2603bd3e8bfSKaren Xie 		OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_ACT_OPEN_REQ,
2613bd3e8bfSKaren Xie 					qid_atid));
2623bd3e8bfSKaren Xie 		req->local_port = csk->saddr.sin_port;
2633bd3e8bfSKaren Xie 		req->peer_port = csk->daddr.sin_port;
2643bd3e8bfSKaren Xie 		req->local_ip = csk->saddr.sin_addr.s_addr;
2653bd3e8bfSKaren Xie 		req->peer_ip = csk->daddr.sin_addr.s_addr;
2663bd3e8bfSKaren Xie 		req->opt0 = cpu_to_be64(opt0);
267d7990b0cSAnish Bhatt 		req->params = cpu_to_be64(FILTER_TUPLE_V(
268ac0245ffSKaren Xie 				cxgb4_select_ntuple(
269ac0245ffSKaren Xie 					csk->cdev->ports[csk->port_id],
270ac0245ffSKaren Xie 					csk->l2t)));
2711eb88a5dSKaren Xie 		req->rsvd = cpu_to_be32(isn);
2721eb88a5dSKaren Xie 		opt2 |= T5_ISS_VALID;
2731eb88a5dSKaren Xie 		opt2 |= T5_OPT_2_VALID_F;
2741eb88a5dSKaren Xie 
2753bd3e8bfSKaren Xie 		req->opt2 = cpu_to_be32(opt2);
2763bd3e8bfSKaren Xie 
2773bd3e8bfSKaren Xie 		log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
2783bd3e8bfSKaren Xie 			"csk t5 0x%p, %pI4:%u-%pI4:%u, atid %d, qid %u.\n",
2793bd3e8bfSKaren Xie 			csk, &req->local_ip, ntohs(req->local_port),
2803bd3e8bfSKaren Xie 			&req->peer_ip, ntohs(req->peer_port),
2813bd3e8bfSKaren Xie 			csk->atid, csk->rss_qid);
282586be7cbSVarun Prakash 	} else {
283586be7cbSVarun Prakash 		struct cpl_t6_act_open_req *req =
284586be7cbSVarun Prakash 				(struct cpl_t6_act_open_req *)skb->head;
285*a251c17aSJason A. Donenfeld 		u32 isn = (get_random_u32() & ~7UL) - 1;
286586be7cbSVarun Prakash 
287586be7cbSVarun Prakash 		INIT_TP_WR(req, 0);
288586be7cbSVarun Prakash 		OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_ACT_OPEN_REQ,
289586be7cbSVarun Prakash 							    qid_atid));
290586be7cbSVarun Prakash 		req->local_port = csk->saddr.sin_port;
291586be7cbSVarun Prakash 		req->peer_port = csk->daddr.sin_port;
292586be7cbSVarun Prakash 		req->local_ip = csk->saddr.sin_addr.s_addr;
293586be7cbSVarun Prakash 		req->peer_ip = csk->daddr.sin_addr.s_addr;
294586be7cbSVarun Prakash 		req->opt0 = cpu_to_be64(opt0);
295586be7cbSVarun Prakash 		req->params = cpu_to_be64(FILTER_TUPLE_V(
296586be7cbSVarun Prakash 				cxgb4_select_ntuple(
297586be7cbSVarun Prakash 					csk->cdev->ports[csk->port_id],
298586be7cbSVarun Prakash 					csk->l2t)));
299586be7cbSVarun Prakash 		req->rsvd = cpu_to_be32(isn);
300586be7cbSVarun Prakash 
301586be7cbSVarun Prakash 		opt2 |= T5_ISS_VALID;
302586be7cbSVarun Prakash 		opt2 |= RX_FC_DISABLE_F;
303586be7cbSVarun Prakash 		opt2 |= T5_OPT_2_VALID_F;
304586be7cbSVarun Prakash 
305586be7cbSVarun Prakash 		req->opt2 = cpu_to_be32(opt2);
306586be7cbSVarun Prakash 		req->rsvd2 = cpu_to_be32(0);
307586be7cbSVarun Prakash 		req->opt3 = cpu_to_be32(0);
308586be7cbSVarun Prakash 
309586be7cbSVarun Prakash 		log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
310586be7cbSVarun Prakash 			  "csk t6 0x%p, %pI4:%u-%pI4:%u, atid %d, qid %u.\n",
311586be7cbSVarun Prakash 			  csk, &req->local_ip, ntohs(req->local_port),
312586be7cbSVarun Prakash 			  &req->peer_ip, ntohs(req->peer_port),
313586be7cbSVarun Prakash 			  csk->atid, csk->rss_qid);
3143bd3e8bfSKaren Xie 	}
3153bd3e8bfSKaren Xie 
3163bd3e8bfSKaren Xie 	set_wr_txq(skb, CPL_PRIORITY_SETUP, csk->port_id);
317759a0cc5SAnish Bhatt 
318759a0cc5SAnish Bhatt 	pr_info_ipaddr("t%d csk 0x%p,%u,0x%lx,%u, rss_qid %u.\n",
319586be7cbSVarun Prakash 		       (&csk->saddr), (&csk->daddr),
320586be7cbSVarun Prakash 		       CHELSIO_CHIP_VERSION(lldi->adapter_type), csk,
321759a0cc5SAnish Bhatt 		       csk->state, csk->flags, csk->atid, csk->rss_qid);
322759a0cc5SAnish Bhatt 
323759a0cc5SAnish Bhatt 	cxgb4_l2t_send(csk->cdev->ports[csk->port_id], skb, csk->l2t);
324759a0cc5SAnish Bhatt }
325759a0cc5SAnish Bhatt 
326f42bb57cSAnish Bhatt #if IS_ENABLED(CONFIG_IPV6)
send_act_open_req6(struct cxgbi_sock * csk,struct sk_buff * skb,struct l2t_entry * e)327759a0cc5SAnish Bhatt static void send_act_open_req6(struct cxgbi_sock *csk, struct sk_buff *skb,
328759a0cc5SAnish Bhatt 			       struct l2t_entry *e)
329759a0cc5SAnish Bhatt {
330759a0cc5SAnish Bhatt 	struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(csk->cdev);
331759a0cc5SAnish Bhatt 	int wscale = cxgbi_sock_compute_wscale(csk->mss_idx);
332759a0cc5SAnish Bhatt 	unsigned long long opt0;
333759a0cc5SAnish Bhatt 	unsigned int opt2;
334759a0cc5SAnish Bhatt 	unsigned int qid_atid = ((unsigned int)csk->atid) |
335759a0cc5SAnish Bhatt 				 (((unsigned int)csk->rss_qid) << 14);
336759a0cc5SAnish Bhatt 
337d7990b0cSAnish Bhatt 	opt0 = KEEP_ALIVE_F |
338d7990b0cSAnish Bhatt 		WND_SCALE_V(wscale) |
339d7990b0cSAnish Bhatt 		MSS_IDX_V(csk->mss_idx) |
340d7990b0cSAnish Bhatt 		L2T_IDX_V(((struct l2t_entry *)csk->l2t)->idx) |
341d7990b0cSAnish Bhatt 		TX_CHAN_V(csk->tx_chan) |
342d7990b0cSAnish Bhatt 		SMAC_SEL_V(csk->smac_idx) |
343d7990b0cSAnish Bhatt 		ULP_MODE_V(ULP_MODE_ISCSI) |
34481daf10cSKaren Xie 		RCV_BUFSIZ_V(csk->rcv_win >> 10);
345759a0cc5SAnish Bhatt 
346d7990b0cSAnish Bhatt 	opt2 = RX_CHANNEL_V(0) |
347d7990b0cSAnish Bhatt 		RSS_QUEUE_VALID_F |
348d7990b0cSAnish Bhatt 		RSS_QUEUE_V(csk->rss_qid);
349759a0cc5SAnish Bhatt 
350586be7cbSVarun Prakash 	if (is_t4(lldi->adapter_type)) {
351759a0cc5SAnish Bhatt 		struct cpl_act_open_req6 *req =
352759a0cc5SAnish Bhatt 			    (struct cpl_act_open_req6 *)skb->head;
353759a0cc5SAnish Bhatt 
354759a0cc5SAnish Bhatt 		INIT_TP_WR(req, 0);
355759a0cc5SAnish Bhatt 		OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_ACT_OPEN_REQ6,
356759a0cc5SAnish Bhatt 							    qid_atid));
357759a0cc5SAnish Bhatt 		req->local_port = csk->saddr6.sin6_port;
358759a0cc5SAnish Bhatt 		req->peer_port = csk->daddr6.sin6_port;
359759a0cc5SAnish Bhatt 
360759a0cc5SAnish Bhatt 		req->local_ip_hi = *(__be64 *)(csk->saddr6.sin6_addr.s6_addr);
361759a0cc5SAnish Bhatt 		req->local_ip_lo = *(__be64 *)(csk->saddr6.sin6_addr.s6_addr +
362759a0cc5SAnish Bhatt 								    8);
363759a0cc5SAnish Bhatt 		req->peer_ip_hi = *(__be64 *)(csk->daddr6.sin6_addr.s6_addr);
364759a0cc5SAnish Bhatt 		req->peer_ip_lo = *(__be64 *)(csk->daddr6.sin6_addr.s6_addr +
365759a0cc5SAnish Bhatt 								    8);
366759a0cc5SAnish Bhatt 
367759a0cc5SAnish Bhatt 		req->opt0 = cpu_to_be64(opt0);
368759a0cc5SAnish Bhatt 
369d7990b0cSAnish Bhatt 		opt2 |= RX_FC_VALID_F;
370759a0cc5SAnish Bhatt 		req->opt2 = cpu_to_be32(opt2);
371759a0cc5SAnish Bhatt 
372759a0cc5SAnish Bhatt 		req->params = cpu_to_be32(cxgb4_select_ntuple(
373759a0cc5SAnish Bhatt 					  csk->cdev->ports[csk->port_id],
374759a0cc5SAnish Bhatt 					  csk->l2t));
375586be7cbSVarun Prakash 	} else if (is_t5(lldi->adapter_type)) {
376759a0cc5SAnish Bhatt 		struct cpl_t5_act_open_req6 *req =
377759a0cc5SAnish Bhatt 				(struct cpl_t5_act_open_req6 *)skb->head;
378759a0cc5SAnish Bhatt 
379759a0cc5SAnish Bhatt 		INIT_TP_WR(req, 0);
380759a0cc5SAnish Bhatt 		OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_ACT_OPEN_REQ6,
381759a0cc5SAnish Bhatt 							    qid_atid));
382759a0cc5SAnish Bhatt 		req->local_port = csk->saddr6.sin6_port;
383759a0cc5SAnish Bhatt 		req->peer_port = csk->daddr6.sin6_port;
384759a0cc5SAnish Bhatt 		req->local_ip_hi = *(__be64 *)(csk->saddr6.sin6_addr.s6_addr);
385759a0cc5SAnish Bhatt 		req->local_ip_lo = *(__be64 *)(csk->saddr6.sin6_addr.s6_addr +
386759a0cc5SAnish Bhatt 									8);
387759a0cc5SAnish Bhatt 		req->peer_ip_hi = *(__be64 *)(csk->daddr6.sin6_addr.s6_addr);
388759a0cc5SAnish Bhatt 		req->peer_ip_lo = *(__be64 *)(csk->daddr6.sin6_addr.s6_addr +
389759a0cc5SAnish Bhatt 									8);
390759a0cc5SAnish Bhatt 		req->opt0 = cpu_to_be64(opt0);
391759a0cc5SAnish Bhatt 
392d7990b0cSAnish Bhatt 		opt2 |= T5_OPT_2_VALID_F;
393759a0cc5SAnish Bhatt 		req->opt2 = cpu_to_be32(opt2);
394759a0cc5SAnish Bhatt 
395d7990b0cSAnish Bhatt 		req->params = cpu_to_be64(FILTER_TUPLE_V(cxgb4_select_ntuple(
396759a0cc5SAnish Bhatt 					  csk->cdev->ports[csk->port_id],
397759a0cc5SAnish Bhatt 					  csk->l2t)));
398586be7cbSVarun Prakash 	} else {
399586be7cbSVarun Prakash 		struct cpl_t6_act_open_req6 *req =
400586be7cbSVarun Prakash 				(struct cpl_t6_act_open_req6 *)skb->head;
401586be7cbSVarun Prakash 
402586be7cbSVarun Prakash 		INIT_TP_WR(req, 0);
403586be7cbSVarun Prakash 		OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_ACT_OPEN_REQ6,
404586be7cbSVarun Prakash 							    qid_atid));
405586be7cbSVarun Prakash 		req->local_port = csk->saddr6.sin6_port;
406586be7cbSVarun Prakash 		req->peer_port = csk->daddr6.sin6_port;
407586be7cbSVarun Prakash 		req->local_ip_hi = *(__be64 *)(csk->saddr6.sin6_addr.s6_addr);
408586be7cbSVarun Prakash 		req->local_ip_lo = *(__be64 *)(csk->saddr6.sin6_addr.s6_addr +
409586be7cbSVarun Prakash 									8);
410586be7cbSVarun Prakash 		req->peer_ip_hi = *(__be64 *)(csk->daddr6.sin6_addr.s6_addr);
411586be7cbSVarun Prakash 		req->peer_ip_lo = *(__be64 *)(csk->daddr6.sin6_addr.s6_addr +
412586be7cbSVarun Prakash 									8);
413586be7cbSVarun Prakash 		req->opt0 = cpu_to_be64(opt0);
414586be7cbSVarun Prakash 
415586be7cbSVarun Prakash 		opt2 |= RX_FC_DISABLE_F;
416586be7cbSVarun Prakash 		opt2 |= T5_OPT_2_VALID_F;
417586be7cbSVarun Prakash 
418586be7cbSVarun Prakash 		req->opt2 = cpu_to_be32(opt2);
419586be7cbSVarun Prakash 
420586be7cbSVarun Prakash 		req->params = cpu_to_be64(FILTER_TUPLE_V(cxgb4_select_ntuple(
421586be7cbSVarun Prakash 					  csk->cdev->ports[csk->port_id],
422586be7cbSVarun Prakash 					  csk->l2t)));
423586be7cbSVarun Prakash 
424586be7cbSVarun Prakash 		req->rsvd2 = cpu_to_be32(0);
425586be7cbSVarun Prakash 		req->opt3 = cpu_to_be32(0);
426759a0cc5SAnish Bhatt 	}
427759a0cc5SAnish Bhatt 
428759a0cc5SAnish Bhatt 	set_wr_txq(skb, CPL_PRIORITY_SETUP, csk->port_id);
429759a0cc5SAnish Bhatt 
430759a0cc5SAnish Bhatt 	pr_info("t%d csk 0x%p,%u,0x%lx,%u, [%pI6]:%u-[%pI6]:%u, rss_qid %u.\n",
431586be7cbSVarun Prakash 		CHELSIO_CHIP_VERSION(lldi->adapter_type), csk, csk->state,
432586be7cbSVarun Prakash 		csk->flags, csk->atid,
433759a0cc5SAnish Bhatt 		&csk->saddr6.sin6_addr, ntohs(csk->saddr.sin_port),
434759a0cc5SAnish Bhatt 		&csk->daddr6.sin6_addr, ntohs(csk->daddr.sin_port),
435759a0cc5SAnish Bhatt 		csk->rss_qid);
436759a0cc5SAnish Bhatt 
4377b36b6e0Skxie@chelsio.com 	cxgb4_l2t_send(csk->cdev->ports[csk->port_id], skb, csk->l2t);
4387b36b6e0Skxie@chelsio.com }
439f42bb57cSAnish Bhatt #endif
4407b36b6e0Skxie@chelsio.com 
send_close_req(struct cxgbi_sock * csk)4417b36b6e0Skxie@chelsio.com static void send_close_req(struct cxgbi_sock *csk)
4427b36b6e0Skxie@chelsio.com {
4437b36b6e0Skxie@chelsio.com 	struct sk_buff *skb = csk->cpl_close;
4447b36b6e0Skxie@chelsio.com 	struct cpl_close_con_req *req = (struct cpl_close_con_req *)skb->head;
4457b36b6e0Skxie@chelsio.com 	unsigned int tid = csk->tid;
4467b36b6e0Skxie@chelsio.com 
4477b36b6e0Skxie@chelsio.com 	log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
4487b36b6e0Skxie@chelsio.com 		"csk 0x%p,%u,0x%lx, tid %u.\n",
4497b36b6e0Skxie@chelsio.com 		csk, csk->state, csk->flags, csk->tid);
4507b36b6e0Skxie@chelsio.com 	csk->cpl_close = NULL;
4517b36b6e0Skxie@chelsio.com 	set_wr_txq(skb, CPL_PRIORITY_DATA, csk->port_id);
4527b36b6e0Skxie@chelsio.com 	INIT_TP_WR(req, tid);
4537b36b6e0Skxie@chelsio.com 	OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_CLOSE_CON_REQ, tid));
4547b36b6e0Skxie@chelsio.com 	req->rsvd = 0;
4557b36b6e0Skxie@chelsio.com 
4567b36b6e0Skxie@chelsio.com 	cxgbi_sock_skb_entail(csk, skb);
4577b36b6e0Skxie@chelsio.com 	if (csk->state >= CTP_ESTABLISHED)
4587b36b6e0Skxie@chelsio.com 		push_tx_frames(csk, 1);
4597b36b6e0Skxie@chelsio.com }
4607b36b6e0Skxie@chelsio.com 
abort_arp_failure(void * handle,struct sk_buff * skb)4617b36b6e0Skxie@chelsio.com static void abort_arp_failure(void *handle, struct sk_buff *skb)
4627b36b6e0Skxie@chelsio.com {
4637b36b6e0Skxie@chelsio.com 	struct cxgbi_sock *csk = (struct cxgbi_sock *)handle;
4647b36b6e0Skxie@chelsio.com 	struct cpl_abort_req *req;
4657b36b6e0Skxie@chelsio.com 
4667b36b6e0Skxie@chelsio.com 	log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
4677b36b6e0Skxie@chelsio.com 		"csk 0x%p,%u,0x%lx, tid %u, abort.\n",
4687b36b6e0Skxie@chelsio.com 		csk, csk->state, csk->flags, csk->tid);
4697b36b6e0Skxie@chelsio.com 	req = (struct cpl_abort_req *)skb->data;
4707b36b6e0Skxie@chelsio.com 	req->cmd = CPL_ABORT_NO_RST;
4717b36b6e0Skxie@chelsio.com 	cxgb4_ofld_send(csk->cdev->ports[csk->port_id], skb);
4727b36b6e0Skxie@chelsio.com }
4737b36b6e0Skxie@chelsio.com 
send_abort_req(struct cxgbi_sock * csk)4747b36b6e0Skxie@chelsio.com static void send_abort_req(struct cxgbi_sock *csk)
4757b36b6e0Skxie@chelsio.com {
4767b36b6e0Skxie@chelsio.com 	struct cpl_abort_req *req;
4777b36b6e0Skxie@chelsio.com 	struct sk_buff *skb = csk->cpl_abort_req;
4787b36b6e0Skxie@chelsio.com 
4797b36b6e0Skxie@chelsio.com 	if (unlikely(csk->state == CTP_ABORTING) || !skb || !csk->cdev)
4807b36b6e0Skxie@chelsio.com 		return;
48164bfead8SKaren Xie 
48264bfead8SKaren Xie 	if (!cxgbi_sock_flag(csk, CTPF_TX_DATA_SENT)) {
48364bfead8SKaren Xie 		send_tx_flowc_wr(csk);
48464bfead8SKaren Xie 		cxgbi_sock_set_flag(csk, CTPF_TX_DATA_SENT);
48564bfead8SKaren Xie 	}
48664bfead8SKaren Xie 
4877b36b6e0Skxie@chelsio.com 	cxgbi_sock_set_state(csk, CTP_ABORTING);
4887b36b6e0Skxie@chelsio.com 	cxgbi_sock_set_flag(csk, CTPF_ABORT_RPL_PENDING);
4897b36b6e0Skxie@chelsio.com 	cxgbi_sock_purge_write_queue(csk);
4907b36b6e0Skxie@chelsio.com 
4917b36b6e0Skxie@chelsio.com 	csk->cpl_abort_req = NULL;
4927b36b6e0Skxie@chelsio.com 	req = (struct cpl_abort_req *)skb->head;
4932126bc5eSKaren Xie 	set_wr_txq(skb, CPL_PRIORITY_DATA, csk->port_id);
4947b36b6e0Skxie@chelsio.com 	req->cmd = CPL_ABORT_SEND_RST;
4957b36b6e0Skxie@chelsio.com 	t4_set_arp_err_handler(skb, csk, abort_arp_failure);
4967b36b6e0Skxie@chelsio.com 	INIT_TP_WR(req, csk->tid);
4977b36b6e0Skxie@chelsio.com 	OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_ABORT_REQ, csk->tid));
4987b36b6e0Skxie@chelsio.com 	req->rsvd0 = htonl(csk->snd_nxt);
4997b36b6e0Skxie@chelsio.com 	req->rsvd1 = !cxgbi_sock_flag(csk, CTPF_TX_DATA_SENT);
5007b36b6e0Skxie@chelsio.com 
5017b36b6e0Skxie@chelsio.com 	log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
5027b36b6e0Skxie@chelsio.com 		"csk 0x%p,%u,0x%lx,%u, snd_nxt %u, 0x%x.\n",
5037b36b6e0Skxie@chelsio.com 		csk, csk->state, csk->flags, csk->tid, csk->snd_nxt,
5047b36b6e0Skxie@chelsio.com 		req->rsvd1);
5057b36b6e0Skxie@chelsio.com 
5067b36b6e0Skxie@chelsio.com 	cxgb4_l2t_send(csk->cdev->ports[csk->port_id], skb, csk->l2t);
5077b36b6e0Skxie@chelsio.com }
5087b36b6e0Skxie@chelsio.com 
send_abort_rpl(struct cxgbi_sock * csk,int rst_status)5097b36b6e0Skxie@chelsio.com static void send_abort_rpl(struct cxgbi_sock *csk, int rst_status)
5107b36b6e0Skxie@chelsio.com {
5117b36b6e0Skxie@chelsio.com 	struct sk_buff *skb = csk->cpl_abort_rpl;
5127b36b6e0Skxie@chelsio.com 	struct cpl_abort_rpl *rpl = (struct cpl_abort_rpl *)skb->head;
5137b36b6e0Skxie@chelsio.com 
5147b36b6e0Skxie@chelsio.com 	log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
5157b36b6e0Skxie@chelsio.com 		"csk 0x%p,%u,0x%lx,%u, status %d.\n",
5167b36b6e0Skxie@chelsio.com 		csk, csk->state, csk->flags, csk->tid, rst_status);
5177b36b6e0Skxie@chelsio.com 
5187b36b6e0Skxie@chelsio.com 	csk->cpl_abort_rpl = NULL;
5192126bc5eSKaren Xie 	set_wr_txq(skb, CPL_PRIORITY_DATA, csk->port_id);
5207b36b6e0Skxie@chelsio.com 	INIT_TP_WR(rpl, csk->tid);
5217b36b6e0Skxie@chelsio.com 	OPCODE_TID(rpl) = cpu_to_be32(MK_OPCODE_TID(CPL_ABORT_RPL, csk->tid));
5227b36b6e0Skxie@chelsio.com 	rpl->cmd = rst_status;
5237b36b6e0Skxie@chelsio.com 	cxgb4_ofld_send(csk->cdev->ports[csk->port_id], skb);
5247b36b6e0Skxie@chelsio.com }
5257b36b6e0Skxie@chelsio.com 
5267b36b6e0Skxie@chelsio.com /*
5277b36b6e0Skxie@chelsio.com  * CPL connection rx data ack: host ->
5287b36b6e0Skxie@chelsio.com  * Send RX credits through an RX_DATA_ACK CPL message. Returns the number of
5297b36b6e0Skxie@chelsio.com  * credits sent.
5307b36b6e0Skxie@chelsio.com  */
send_rx_credits(struct cxgbi_sock * csk,u32 credits)5317b36b6e0Skxie@chelsio.com static u32 send_rx_credits(struct cxgbi_sock *csk, u32 credits)
5327b36b6e0Skxie@chelsio.com {
5337b36b6e0Skxie@chelsio.com 	struct sk_buff *skb;
5347b36b6e0Skxie@chelsio.com 	struct cpl_rx_data_ack *req;
5357b36b6e0Skxie@chelsio.com 
5367b36b6e0Skxie@chelsio.com 	log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_PDU_RX,
5377b36b6e0Skxie@chelsio.com 		"csk 0x%p,%u,0x%lx,%u, credit %u.\n",
5387b36b6e0Skxie@chelsio.com 		csk, csk->state, csk->flags, csk->tid, credits);
5397b36b6e0Skxie@chelsio.com 
54024d3f95aSkxie@chelsio.com 	skb = alloc_wr(sizeof(*req), 0, GFP_ATOMIC);
5417b36b6e0Skxie@chelsio.com 	if (!skb) {
5427b36b6e0Skxie@chelsio.com 		pr_info("csk 0x%p, credit %u, OOM.\n", csk, credits);
5437b36b6e0Skxie@chelsio.com 		return 0;
5447b36b6e0Skxie@chelsio.com 	}
5457b36b6e0Skxie@chelsio.com 	req = (struct cpl_rx_data_ack *)skb->head;
5467b36b6e0Skxie@chelsio.com 
5477b36b6e0Skxie@chelsio.com 	set_wr_txq(skb, CPL_PRIORITY_ACK, csk->port_id);
5487b36b6e0Skxie@chelsio.com 	INIT_TP_WR(req, csk->tid);
5497b36b6e0Skxie@chelsio.com 	OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_RX_DATA_ACK,
5507b36b6e0Skxie@chelsio.com 				      csk->tid));
551d7990b0cSAnish Bhatt 	req->credit_dack = cpu_to_be32(RX_CREDITS_V(credits)
552d7990b0cSAnish Bhatt 				       | RX_FORCE_ACK_F);
5537b36b6e0Skxie@chelsio.com 	cxgb4_ofld_send(csk->cdev->ports[csk->port_id], skb);
5547b36b6e0Skxie@chelsio.com 	return credits;
5557b36b6e0Skxie@chelsio.com }
5567b36b6e0Skxie@chelsio.com 
5577b36b6e0Skxie@chelsio.com /*
5587b36b6e0Skxie@chelsio.com  * sgl_len - calculates the size of an SGL of the given capacity
5597b36b6e0Skxie@chelsio.com  * @n: the number of SGL entries
5607b36b6e0Skxie@chelsio.com  * Calculates the number of flits needed for a scatter/gather list that
5617b36b6e0Skxie@chelsio.com  * can hold the given number of entries.
5627b36b6e0Skxie@chelsio.com  */
sgl_len(unsigned int n)5637b36b6e0Skxie@chelsio.com static inline unsigned int sgl_len(unsigned int n)
5647b36b6e0Skxie@chelsio.com {
5657b36b6e0Skxie@chelsio.com 	n--;
5667b36b6e0Skxie@chelsio.com 	return (3 * n) / 2 + (n & 1) + 2;
5677b36b6e0Skxie@chelsio.com }
5687b36b6e0Skxie@chelsio.com 
5697b36b6e0Skxie@chelsio.com /*
5707b36b6e0Skxie@chelsio.com  * calc_tx_flits_ofld - calculate # of flits for an offload packet
5717b36b6e0Skxie@chelsio.com  * @skb: the packet
5727b36b6e0Skxie@chelsio.com  *
5737b36b6e0Skxie@chelsio.com  * Returns the number of flits needed for the given offload packet.
5747b36b6e0Skxie@chelsio.com  * These packets are already fully constructed and no additional headers
5757b36b6e0Skxie@chelsio.com  * will be added.
5767b36b6e0Skxie@chelsio.com  */
calc_tx_flits_ofld(const struct sk_buff * skb)5777b36b6e0Skxie@chelsio.com static inline unsigned int calc_tx_flits_ofld(const struct sk_buff *skb)
5787b36b6e0Skxie@chelsio.com {
5797b36b6e0Skxie@chelsio.com 	unsigned int flits, cnt;
5807b36b6e0Skxie@chelsio.com 
5817b36b6e0Skxie@chelsio.com 	if (is_ofld_imm(skb))
5827b36b6e0Skxie@chelsio.com 		return DIV_ROUND_UP(skb->len, 8);
5837b36b6e0Skxie@chelsio.com 	flits = skb_transport_offset(skb) / 8;
5847b36b6e0Skxie@chelsio.com 	cnt = skb_shinfo(skb)->nr_frags;
585499e2e6fSIsaku Yamahata 	if (skb_tail_pointer(skb) != skb_transport_header(skb))
5867b36b6e0Skxie@chelsio.com 		cnt++;
5877b36b6e0Skxie@chelsio.com 	return flits + sgl_len(cnt);
5887b36b6e0Skxie@chelsio.com }
5897b36b6e0Skxie@chelsio.com 
59064bfead8SKaren Xie #define FLOWC_WR_NPARAMS_MIN	9
tx_flowc_wr_credits(int * nparamsp,int * flowclenp)59164bfead8SKaren Xie static inline int tx_flowc_wr_credits(int *nparamsp, int *flowclenp)
59264bfead8SKaren Xie {
59364bfead8SKaren Xie 	int nparams, flowclen16, flowclen;
59464bfead8SKaren Xie 
59564bfead8SKaren Xie 	nparams = FLOWC_WR_NPARAMS_MIN;
596b5a5fe4eSVarun Prakash #ifdef CONFIG_CHELSIO_T4_DCB
597b5a5fe4eSVarun Prakash 	nparams++;
598b5a5fe4eSVarun Prakash #endif
59964bfead8SKaren Xie 	flowclen = offsetof(struct fw_flowc_wr, mnemval[nparams]);
60064bfead8SKaren Xie 	flowclen16 = DIV_ROUND_UP(flowclen, 16);
60164bfead8SKaren Xie 	flowclen = flowclen16 * 16;
60264bfead8SKaren Xie 	/*
60364bfead8SKaren Xie 	 * Return the number of 16-byte credits used by the FlowC request.
60464bfead8SKaren Xie 	 * Pass back the nparams and actual FlowC length if requested.
60564bfead8SKaren Xie 	 */
60664bfead8SKaren Xie 	if (nparamsp)
60764bfead8SKaren Xie 		*nparamsp = nparams;
60864bfead8SKaren Xie 	if (flowclenp)
60964bfead8SKaren Xie 		*flowclenp = flowclen;
61064bfead8SKaren Xie 
61164bfead8SKaren Xie 	return flowclen16;
61264bfead8SKaren Xie }
61364bfead8SKaren Xie 
send_tx_flowc_wr(struct cxgbi_sock * csk)61464bfead8SKaren Xie static inline int send_tx_flowc_wr(struct cxgbi_sock *csk)
6157b36b6e0Skxie@chelsio.com {
6167b36b6e0Skxie@chelsio.com 	struct sk_buff *skb;
6177b36b6e0Skxie@chelsio.com 	struct fw_flowc_wr *flowc;
61864bfead8SKaren Xie 	int nparams, flowclen16, flowclen;
6197b36b6e0Skxie@chelsio.com 
620b5a5fe4eSVarun Prakash #ifdef CONFIG_CHELSIO_T4_DCB
621b5a5fe4eSVarun Prakash 	u16 vlan = ((struct l2t_entry *)csk->l2t)->vlan;
622b5a5fe4eSVarun Prakash #endif
62364bfead8SKaren Xie 	flowclen16 = tx_flowc_wr_credits(&nparams, &flowclen);
62424d3f95aSkxie@chelsio.com 	skb = alloc_wr(flowclen, 0, GFP_ATOMIC);
6257b36b6e0Skxie@chelsio.com 	flowc = (struct fw_flowc_wr *)skb->head;
6267b36b6e0Skxie@chelsio.com 	flowc->op_to_nparams =
62764bfead8SKaren Xie 		htonl(FW_WR_OP_V(FW_FLOWC_WR) | FW_FLOWC_WR_NPARAMS_V(nparams));
6287b36b6e0Skxie@chelsio.com 	flowc->flowid_len16 =
62964bfead8SKaren Xie 		htonl(FW_WR_LEN16_V(flowclen16) | FW_WR_FLOWID_V(csk->tid));
6307b36b6e0Skxie@chelsio.com 	flowc->mnemval[0].mnemonic = FW_FLOWC_MNEM_PFNVFN;
631e27d6169Skxie@chelsio.com 	flowc->mnemval[0].val = htonl(csk->cdev->pfvf);
6327b36b6e0Skxie@chelsio.com 	flowc->mnemval[1].mnemonic = FW_FLOWC_MNEM_CH;
6337b36b6e0Skxie@chelsio.com 	flowc->mnemval[1].val = htonl(csk->tx_chan);
6347b36b6e0Skxie@chelsio.com 	flowc->mnemval[2].mnemonic = FW_FLOWC_MNEM_PORT;
6357b36b6e0Skxie@chelsio.com 	flowc->mnemval[2].val = htonl(csk->tx_chan);
6367b36b6e0Skxie@chelsio.com 	flowc->mnemval[3].mnemonic = FW_FLOWC_MNEM_IQID;
6377b36b6e0Skxie@chelsio.com 	flowc->mnemval[3].val = htonl(csk->rss_qid);
6387b36b6e0Skxie@chelsio.com 	flowc->mnemval[4].mnemonic = FW_FLOWC_MNEM_SNDNXT;
6397b36b6e0Skxie@chelsio.com 	flowc->mnemval[4].val = htonl(csk->snd_nxt);
6407b36b6e0Skxie@chelsio.com 	flowc->mnemval[5].mnemonic = FW_FLOWC_MNEM_RCVNXT;
6417b36b6e0Skxie@chelsio.com 	flowc->mnemval[5].val = htonl(csk->rcv_nxt);
6427b36b6e0Skxie@chelsio.com 	flowc->mnemval[6].mnemonic = FW_FLOWC_MNEM_SNDBUF;
64381daf10cSKaren Xie 	flowc->mnemval[6].val = htonl(csk->snd_win);
6447b36b6e0Skxie@chelsio.com 	flowc->mnemval[7].mnemonic = FW_FLOWC_MNEM_MSS;
6457b36b6e0Skxie@chelsio.com 	flowc->mnemval[7].val = htonl(csk->advmss);
6467b36b6e0Skxie@chelsio.com 	flowc->mnemval[8].mnemonic = 0;
6477b36b6e0Skxie@chelsio.com 	flowc->mnemval[8].val = 0;
64864bfead8SKaren Xie 	flowc->mnemval[8].mnemonic = FW_FLOWC_MNEM_TXDATAPLEN_MAX;
649e33c2482SVarun Prakash 	if (csk->cdev->skb_iso_txhdr)
650e33c2482SVarun Prakash 		flowc->mnemval[8].val = cpu_to_be32(CXGBI_MAX_ISO_DATA_IN_SKB);
651e33c2482SVarun Prakash 	else
652e33c2482SVarun Prakash 		flowc->mnemval[8].val = cpu_to_be32(16128);
653b5a5fe4eSVarun Prakash #ifdef CONFIG_CHELSIO_T4_DCB
654b5a5fe4eSVarun Prakash 	flowc->mnemval[9].mnemonic = FW_FLOWC_MNEM_DCBPRIO;
655b5a5fe4eSVarun Prakash 	if (vlan == CPL_L2T_VLAN_NONE) {
656b5a5fe4eSVarun Prakash 		pr_warn_ratelimited("csk %u without VLAN Tag on DCB Link\n",
657b5a5fe4eSVarun Prakash 				    csk->tid);
658b5a5fe4eSVarun Prakash 		flowc->mnemval[9].val = cpu_to_be32(0);
659b5a5fe4eSVarun Prakash 	} else {
660b5a5fe4eSVarun Prakash 		flowc->mnemval[9].val = cpu_to_be32((vlan & VLAN_PRIO_MASK) >>
661b5a5fe4eSVarun Prakash 					VLAN_PRIO_SHIFT);
662b5a5fe4eSVarun Prakash 	}
663b5a5fe4eSVarun Prakash #endif
66464bfead8SKaren Xie 
6652126bc5eSKaren Xie 	set_wr_txq(skb, CPL_PRIORITY_DATA, csk->port_id);
6667b36b6e0Skxie@chelsio.com 
6677b36b6e0Skxie@chelsio.com 	log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
6687b36b6e0Skxie@chelsio.com 		"csk 0x%p, tid 0x%x, %u,%u,%u,%u,%u,%u,%u.\n",
6697b36b6e0Skxie@chelsio.com 		csk, csk->tid, 0, csk->tx_chan, csk->rss_qid,
67081daf10cSKaren Xie 		csk->snd_nxt, csk->rcv_nxt, csk->snd_win,
6717b36b6e0Skxie@chelsio.com 		csk->advmss);
6727b36b6e0Skxie@chelsio.com 
6737b36b6e0Skxie@chelsio.com 	cxgb4_ofld_send(csk->cdev->ports[csk->port_id], skb);
67464bfead8SKaren Xie 
67564bfead8SKaren Xie 	return flowclen16;
6767b36b6e0Skxie@chelsio.com }
6777b36b6e0Skxie@chelsio.com 
678e33c2482SVarun Prakash static void
cxgb4i_make_tx_iso_cpl(struct sk_buff * skb,struct cpl_tx_data_iso * cpl)679e33c2482SVarun Prakash cxgb4i_make_tx_iso_cpl(struct sk_buff *skb, struct cpl_tx_data_iso *cpl)
6807b36b6e0Skxie@chelsio.com {
681e33c2482SVarun Prakash 	struct cxgbi_iso_info *info = (struct cxgbi_iso_info *)skb->head;
682e33c2482SVarun Prakash 	u32 imm_en = !!(info->flags & CXGBI_ISO_INFO_IMM_ENABLE);
683e33c2482SVarun Prakash 	u32 fslice = !!(info->flags & CXGBI_ISO_INFO_FSLICE);
684e33c2482SVarun Prakash 	u32 lslice = !!(info->flags & CXGBI_ISO_INFO_LSLICE);
685e33c2482SVarun Prakash 	u32 pdu_type = (info->op == ISCSI_OP_SCSI_CMD) ? 0 : 1;
686e33c2482SVarun Prakash 	u32 submode = cxgbi_skcb_tx_ulp_mode(skb) & 0x3;
6877b36b6e0Skxie@chelsio.com 
688e33c2482SVarun Prakash 	cpl->op_to_scsi = cpu_to_be32(CPL_TX_DATA_ISO_OP_V(CPL_TX_DATA_ISO) |
689e33c2482SVarun Prakash 				CPL_TX_DATA_ISO_FIRST_V(fslice) |
690e33c2482SVarun Prakash 				CPL_TX_DATA_ISO_LAST_V(lslice) |
691e33c2482SVarun Prakash 				CPL_TX_DATA_ISO_CPLHDRLEN_V(0) |
692e33c2482SVarun Prakash 				CPL_TX_DATA_ISO_HDRCRC_V(submode & 1) |
693e33c2482SVarun Prakash 				CPL_TX_DATA_ISO_PLDCRC_V(((submode >> 1) & 1)) |
694e33c2482SVarun Prakash 				CPL_TX_DATA_ISO_IMMEDIATE_V(imm_en) |
695e33c2482SVarun Prakash 				CPL_TX_DATA_ISO_SCSI_V(pdu_type));
6967b36b6e0Skxie@chelsio.com 
697e33c2482SVarun Prakash 	cpl->ahs_len = info->ahs;
698e33c2482SVarun Prakash 	cpl->mpdu = cpu_to_be16(DIV_ROUND_UP(info->mpdu, 4));
699e33c2482SVarun Prakash 	cpl->burst_size = cpu_to_be32(info->burst_size);
700e33c2482SVarun Prakash 	cpl->len = cpu_to_be32(info->len);
701e33c2482SVarun Prakash 	cpl->reserved2_seglen_offset =
702e33c2482SVarun Prakash 	     cpu_to_be32(CPL_TX_DATA_ISO_SEGLEN_OFFSET_V(info->segment_offset));
703e33c2482SVarun Prakash 	cpl->datasn_offset = cpu_to_be32(info->datasn_offset);
704e33c2482SVarun Prakash 	cpl->buffer_offset = cpu_to_be32(info->buffer_offset);
705e33c2482SVarun Prakash 	cpl->reserved3 = cpu_to_be32(0);
706e33c2482SVarun Prakash 	log_debug(1 << CXGBI_DBG_ISCSI | 1 << CXGBI_DBG_PDU_TX,
707e33c2482SVarun Prakash 		  "iso: flags 0x%x, op %u, ahs %u, num_pdu %u, mpdu %u, "
708e33c2482SVarun Prakash 		  "burst_size %u, iso_len %u\n",
709e33c2482SVarun Prakash 		  info->flags, info->op, info->ahs, info->num_pdu,
710e33c2482SVarun Prakash 		  info->mpdu, info->burst_size << 2, info->len);
7117b36b6e0Skxie@chelsio.com }
712e33c2482SVarun Prakash 
713e33c2482SVarun Prakash static void
cxgb4i_make_tx_data_wr(struct cxgbi_sock * csk,struct sk_buff * skb,int dlen,int len,u32 credits,int compl)714e33c2482SVarun Prakash cxgb4i_make_tx_data_wr(struct cxgbi_sock *csk, struct sk_buff *skb, int dlen,
715e33c2482SVarun Prakash 		       int len, u32 credits, int compl)
716e33c2482SVarun Prakash {
717e33c2482SVarun Prakash 	struct cxgbi_device *cdev = csk->cdev;
718e33c2482SVarun Prakash 	struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(cdev);
719e33c2482SVarun Prakash 	struct fw_ofld_tx_data_wr *req;
720e33c2482SVarun Prakash 	struct cpl_tx_data_iso *cpl;
721e33c2482SVarun Prakash 	u32 submode = cxgbi_skcb_tx_ulp_mode(skb) & 0x3;
722e33c2482SVarun Prakash 	u32 wr_ulp_mode = 0;
723e33c2482SVarun Prakash 	u32 hdr_size = sizeof(*req);
724e33c2482SVarun Prakash 	u32 opcode = FW_OFLD_TX_DATA_WR;
725e33c2482SVarun Prakash 	u32 immlen = 0;
726e33c2482SVarun Prakash 	u32 force = is_t5(lldi->adapter_type) ? TX_FORCE_V(!submode) :
727e33c2482SVarun Prakash 						T6_TX_FORCE_F;
728e33c2482SVarun Prakash 
729e33c2482SVarun Prakash 	if (cxgbi_skcb_test_flag(skb, SKCBF_TX_ISO)) {
730e33c2482SVarun Prakash 		hdr_size += sizeof(struct cpl_tx_data_iso);
731e33c2482SVarun Prakash 		opcode = FW_ISCSI_TX_DATA_WR;
732e33c2482SVarun Prakash 		immlen += sizeof(struct cpl_tx_data_iso);
733e33c2482SVarun Prakash 		submode |= 8;
734e33c2482SVarun Prakash 	}
735e33c2482SVarun Prakash 
736e33c2482SVarun Prakash 	if (is_ofld_imm(skb))
737e33c2482SVarun Prakash 		immlen += dlen;
738e33c2482SVarun Prakash 
739e33c2482SVarun Prakash 	req = (struct fw_ofld_tx_data_wr *)__skb_push(skb, hdr_size);
740e33c2482SVarun Prakash 	req->op_to_immdlen = cpu_to_be32(FW_WR_OP_V(opcode) |
741e33c2482SVarun Prakash 					 FW_WR_COMPL_V(compl) |
742e33c2482SVarun Prakash 					 FW_WR_IMMDLEN_V(immlen));
743e33c2482SVarun Prakash 	req->flowid_len16 = cpu_to_be32(FW_WR_FLOWID_V(csk->tid) |
744e33c2482SVarun Prakash 					FW_WR_LEN16_V(credits));
745e33c2482SVarun Prakash 	req->plen = cpu_to_be32(len);
746e33c2482SVarun Prakash 	cpl =  (struct cpl_tx_data_iso *)(req + 1);
747e33c2482SVarun Prakash 
748e33c2482SVarun Prakash 	if (likely(cxgbi_skcb_test_flag(skb, SKCBF_TX_ISO)))
749e33c2482SVarun Prakash 		cxgb4i_make_tx_iso_cpl(skb, cpl);
750e33c2482SVarun Prakash 
7517b36b6e0Skxie@chelsio.com 	if (submode)
752e2ac9628SHariprasad Shenai 		wr_ulp_mode = FW_OFLD_TX_DATA_WR_ULPMODE_V(ULP2_MODE_ISCSI) |
753e2ac9628SHariprasad Shenai 			      FW_OFLD_TX_DATA_WR_ULPSUBMODE_V(submode);
754e33c2482SVarun Prakash 
755e33c2482SVarun Prakash 	req->tunnel_to_proxy = cpu_to_be32(wr_ulp_mode | force |
756e33c2482SVarun Prakash 					   FW_OFLD_TX_DATA_WR_SHOVE_V(1U));
757e33c2482SVarun Prakash 
7587b36b6e0Skxie@chelsio.com 	if (!cxgbi_sock_flag(csk, CTPF_TX_DATA_SENT))
7597b36b6e0Skxie@chelsio.com 		cxgbi_sock_set_flag(csk, CTPF_TX_DATA_SENT);
7607b36b6e0Skxie@chelsio.com }
7617b36b6e0Skxie@chelsio.com 
arp_failure_skb_discard(void * handle,struct sk_buff * skb)7627b36b6e0Skxie@chelsio.com static void arp_failure_skb_discard(void *handle, struct sk_buff *skb)
7637b36b6e0Skxie@chelsio.com {
7647b36b6e0Skxie@chelsio.com 	kfree_skb(skb);
7657b36b6e0Skxie@chelsio.com }
7667b36b6e0Skxie@chelsio.com 
push_tx_frames(struct cxgbi_sock * csk,int req_completion)7677b36b6e0Skxie@chelsio.com static int push_tx_frames(struct cxgbi_sock *csk, int req_completion)
7687b36b6e0Skxie@chelsio.com {
7697b36b6e0Skxie@chelsio.com 	int total_size = 0;
7707b36b6e0Skxie@chelsio.com 	struct sk_buff *skb;
7717b36b6e0Skxie@chelsio.com 
7727b36b6e0Skxie@chelsio.com 	if (unlikely(csk->state < CTP_ESTABLISHED ||
7737b36b6e0Skxie@chelsio.com 		csk->state == CTP_CLOSE_WAIT_1 || csk->state >= CTP_ABORTING)) {
7747b36b6e0Skxie@chelsio.com 		log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK |
7757b36b6e0Skxie@chelsio.com 			  1 << CXGBI_DBG_PDU_TX,
7767b36b6e0Skxie@chelsio.com 			  "csk 0x%p,%u,0x%lx,%u, in closing state.\n",
7777b36b6e0Skxie@chelsio.com 			  csk, csk->state, csk->flags, csk->tid);
7787b36b6e0Skxie@chelsio.com 		return 0;
7797b36b6e0Skxie@chelsio.com 	}
7807b36b6e0Skxie@chelsio.com 
781e33c2482SVarun Prakash 	while (csk->wr_cred && ((skb = skb_peek(&csk->write_queue)) != NULL)) {
782e33c2482SVarun Prakash 		struct cxgbi_iso_info *iso_cpl;
783e33c2482SVarun Prakash 		u32 dlen = skb->len;
784e33c2482SVarun Prakash 		u32 len = skb->len;
785e33c2482SVarun Prakash 		u32 iso_cpl_len = 0;
786e33c2482SVarun Prakash 		u32 flowclen16 = 0;
787e33c2482SVarun Prakash 		u32 credits_needed;
788e33c2482SVarun Prakash 		u32 num_pdu = 1, hdr_len;
7897b36b6e0Skxie@chelsio.com 
790e33c2482SVarun Prakash 		if (cxgbi_skcb_test_flag(skb, SKCBF_TX_ISO))
791e33c2482SVarun Prakash 			iso_cpl_len = sizeof(struct cpl_tx_data_iso);
792e33c2482SVarun Prakash 
7937b36b6e0Skxie@chelsio.com 		if (is_ofld_imm(skb))
794e33c2482SVarun Prakash 			credits_needed = DIV_ROUND_UP(dlen + iso_cpl_len, 16);
7957b36b6e0Skxie@chelsio.com 		else
796e33c2482SVarun Prakash 			credits_needed =
797e33c2482SVarun Prakash 				DIV_ROUND_UP((8 * calc_tx_flits_ofld(skb)) +
798e33c2482SVarun Prakash 					     iso_cpl_len, 16);
79984944d8cSKaren Xie 
80084944d8cSKaren Xie 		if (likely(cxgbi_skcb_test_flag(skb, SKCBF_TX_NEED_HDR)))
801e33c2482SVarun Prakash 			credits_needed +=
802e33c2482SVarun Prakash 			   DIV_ROUND_UP(sizeof(struct fw_ofld_tx_data_wr), 16);
8037b36b6e0Skxie@chelsio.com 
80464bfead8SKaren Xie 		/*
80564bfead8SKaren Xie 		 * Assumes the initial credits is large enough to support
80664bfead8SKaren Xie 		 * fw_flowc_wr plus largest possible first payload
80764bfead8SKaren Xie 		 */
80864bfead8SKaren Xie 		if (!cxgbi_sock_flag(csk, CTPF_TX_DATA_SENT)) {
80964bfead8SKaren Xie 			flowclen16 = send_tx_flowc_wr(csk);
81064bfead8SKaren Xie 			csk->wr_cred -= flowclen16;
81164bfead8SKaren Xie 			csk->wr_una_cred += flowclen16;
81264bfead8SKaren Xie 			cxgbi_sock_set_flag(csk, CTPF_TX_DATA_SENT);
81364bfead8SKaren Xie 		}
81464bfead8SKaren Xie 
8157b36b6e0Skxie@chelsio.com 		if (csk->wr_cred < credits_needed) {
8167b36b6e0Skxie@chelsio.com 			log_debug(1 << CXGBI_DBG_PDU_TX,
8177b36b6e0Skxie@chelsio.com 				  "csk 0x%p, skb %u/%u, wr %d < %u.\n",
8187b36b6e0Skxie@chelsio.com 				  csk, skb->len, skb->data_len,
8197b36b6e0Skxie@chelsio.com 				  credits_needed, csk->wr_cred);
820e33c2482SVarun Prakash 
821e33c2482SVarun Prakash 			csk->no_tx_credits++;
8227b36b6e0Skxie@chelsio.com 			break;
8237b36b6e0Skxie@chelsio.com 		}
824e33c2482SVarun Prakash 
825e33c2482SVarun Prakash 		csk->no_tx_credits = 0;
826e33c2482SVarun Prakash 
8277b36b6e0Skxie@chelsio.com 		__skb_unlink(skb, &csk->write_queue);
8282126bc5eSKaren Xie 		set_wr_txq(skb, CPL_PRIORITY_DATA, csk->port_id);
829e33c2482SVarun Prakash 		skb->csum = (__force __wsum)(credits_needed + flowclen16);
8307b36b6e0Skxie@chelsio.com 		csk->wr_cred -= credits_needed;
8317b36b6e0Skxie@chelsio.com 		csk->wr_una_cred += credits_needed;
8327b36b6e0Skxie@chelsio.com 		cxgbi_sock_enqueue_wr(csk, skb);
8337b36b6e0Skxie@chelsio.com 
8347b36b6e0Skxie@chelsio.com 		log_debug(1 << CXGBI_DBG_PDU_TX,
8357b36b6e0Skxie@chelsio.com 			"csk 0x%p, skb %u/%u, wr %d, left %u, unack %u.\n",
8367b36b6e0Skxie@chelsio.com 			csk, skb->len, skb->data_len, credits_needed,
8377b36b6e0Skxie@chelsio.com 			csk->wr_cred, csk->wr_una_cred);
8387b36b6e0Skxie@chelsio.com 
839e33c2482SVarun Prakash 		if (!req_completion &&
840e33c2482SVarun Prakash 		    ((csk->wr_una_cred >= (csk->wr_max_cred / 2)) ||
841e33c2482SVarun Prakash 		     after(csk->write_seq, (csk->snd_una + csk->snd_win / 2))))
842e33c2482SVarun Prakash 			req_completion = 1;
843e33c2482SVarun Prakash 
8447b36b6e0Skxie@chelsio.com 		if (likely(cxgbi_skcb_test_flag(skb, SKCBF_TX_NEED_HDR))) {
845e33c2482SVarun Prakash 			u32 ulp_mode = cxgbi_skcb_tx_ulp_mode(skb);
846e33c2482SVarun Prakash 
847e33c2482SVarun Prakash 			if (cxgbi_skcb_test_flag(skb, SKCBF_TX_ISO)) {
848e33c2482SVarun Prakash 				iso_cpl = (struct cxgbi_iso_info *)skb->head;
849e33c2482SVarun Prakash 				num_pdu = iso_cpl->num_pdu;
850e33c2482SVarun Prakash 				hdr_len = cxgbi_skcb_tx_iscsi_hdrlen(skb);
851e33c2482SVarun Prakash 				len += (cxgbi_ulp_extra_len(ulp_mode) * num_pdu) +
852e33c2482SVarun Prakash 				       (hdr_len * (num_pdu - 1));
853e33c2482SVarun Prakash 			} else {
854e33c2482SVarun Prakash 				len += cxgbi_ulp_extra_len(ulp_mode);
855e33c2482SVarun Prakash 			}
856e33c2482SVarun Prakash 
857e33c2482SVarun Prakash 			cxgb4i_make_tx_data_wr(csk, skb, dlen, len,
858e33c2482SVarun Prakash 					       credits_needed, req_completion);
8597b36b6e0Skxie@chelsio.com 			csk->snd_nxt += len;
8607b36b6e0Skxie@chelsio.com 			cxgbi_skcb_clear_flag(skb, SKCBF_TX_NEED_HDR);
861fe9b34bfSVarun Prakash 		} else if (cxgbi_skcb_test_flag(skb, SKCBF_TX_FLAG_COMPL) &&
862fe9b34bfSVarun Prakash 			   (csk->wr_una_cred >= (csk->wr_max_cred / 2))) {
863fe9b34bfSVarun Prakash 			struct cpl_close_con_req *req =
864fe9b34bfSVarun Prakash 				(struct cpl_close_con_req *)skb->data;
865e33c2482SVarun Prakash 
866e33c2482SVarun Prakash 			req->wr.wr_hi |= cpu_to_be32(FW_WR_COMPL_F);
8677b36b6e0Skxie@chelsio.com 		}
868e33c2482SVarun Prakash 
8697b36b6e0Skxie@chelsio.com 		total_size += skb->truesize;
8707b36b6e0Skxie@chelsio.com 		t4_set_arp_err_handler(skb, csk, arp_failure_skb_discard);
8717b36b6e0Skxie@chelsio.com 
8727b36b6e0Skxie@chelsio.com 		log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_PDU_TX,
8737b36b6e0Skxie@chelsio.com 			  "csk 0x%p,%u,0x%lx,%u, skb 0x%p, %u.\n",
8747b36b6e0Skxie@chelsio.com 			  csk, csk->state, csk->flags, csk->tid, skb, len);
8757b36b6e0Skxie@chelsio.com 		cxgb4_l2t_send(csk->cdev->ports[csk->port_id], skb, csk->l2t);
8767b36b6e0Skxie@chelsio.com 	}
8777b36b6e0Skxie@chelsio.com 	return total_size;
8787b36b6e0Skxie@chelsio.com }
8797b36b6e0Skxie@chelsio.com 
free_atid(struct cxgbi_sock * csk)8807b36b6e0Skxie@chelsio.com static inline void free_atid(struct cxgbi_sock *csk)
8817b36b6e0Skxie@chelsio.com {
8827b36b6e0Skxie@chelsio.com 	struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(csk->cdev);
8837b36b6e0Skxie@chelsio.com 
8847b36b6e0Skxie@chelsio.com 	if (cxgbi_sock_flag(csk, CTPF_HAS_ATID)) {
8857b36b6e0Skxie@chelsio.com 		cxgb4_free_atid(lldi->tids, csk->atid);
8867b36b6e0Skxie@chelsio.com 		cxgbi_sock_clear_flag(csk, CTPF_HAS_ATID);
8877b36b6e0Skxie@chelsio.com 		cxgbi_sock_put(csk);
8887b36b6e0Skxie@chelsio.com 	}
8897b36b6e0Skxie@chelsio.com }
8907b36b6e0Skxie@chelsio.com 
do_act_establish(struct cxgbi_device * cdev,struct sk_buff * skb)8917b36b6e0Skxie@chelsio.com static void do_act_establish(struct cxgbi_device *cdev, struct sk_buff *skb)
8927b36b6e0Skxie@chelsio.com {
8937b36b6e0Skxie@chelsio.com 	struct cxgbi_sock *csk;
8947b36b6e0Skxie@chelsio.com 	struct cpl_act_establish *req = (struct cpl_act_establish *)skb->data;
8957b36b6e0Skxie@chelsio.com 	unsigned short tcp_opt = ntohs(req->tcp_opt);
8967b36b6e0Skxie@chelsio.com 	unsigned int tid = GET_TID(req);
8976c53e938SHariprasad Shenai 	unsigned int atid = TID_TID_G(ntohl(req->tos_atid));
8987b36b6e0Skxie@chelsio.com 	struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(cdev);
8997b36b6e0Skxie@chelsio.com 	struct tid_info *t = lldi->tids;
9007b36b6e0Skxie@chelsio.com 	u32 rcv_isn = be32_to_cpu(req->rcv_isn);
9017b36b6e0Skxie@chelsio.com 
9027b36b6e0Skxie@chelsio.com 	csk = lookup_atid(t, atid);
9037b36b6e0Skxie@chelsio.com 	if (unlikely(!csk)) {
9047b36b6e0Skxie@chelsio.com 		pr_err("NO conn. for atid %u, cdev 0x%p.\n", atid, cdev);
9057b36b6e0Skxie@chelsio.com 		goto rel_skb;
9067b36b6e0Skxie@chelsio.com 	}
9077b36b6e0Skxie@chelsio.com 
908e27d6169Skxie@chelsio.com 	if (csk->atid != atid) {
909e27d6169Skxie@chelsio.com 		pr_err("bad conn atid %u, csk 0x%p,%u,0x%lx,tid %u, atid %u.\n",
910e27d6169Skxie@chelsio.com 			atid, csk, csk->state, csk->flags, csk->tid, csk->atid);
911e27d6169Skxie@chelsio.com 		goto rel_skb;
912e27d6169Skxie@chelsio.com 	}
913e27d6169Skxie@chelsio.com 
914759a0cc5SAnish Bhatt 	pr_info_ipaddr("atid 0x%x, tid 0x%x, csk 0x%p,%u,0x%lx, isn %u.\n",
915759a0cc5SAnish Bhatt 		       (&csk->saddr), (&csk->daddr),
916759a0cc5SAnish Bhatt 		       atid, tid, csk, csk->state, csk->flags, rcv_isn);
917759a0cc5SAnish Bhatt 
9181fe1fdb0SVarun Prakash 	module_put(cdev->owner);
9197b36b6e0Skxie@chelsio.com 
9207b36b6e0Skxie@chelsio.com 	cxgbi_sock_get(csk);
9217b36b6e0Skxie@chelsio.com 	csk->tid = tid;
9221dec4cecSGanesh Goudar 	cxgb4_insert_tid(lldi->tids, csk, tid, csk->csk_family);
9237b36b6e0Skxie@chelsio.com 	cxgbi_sock_set_flag(csk, CTPF_HAS_TID);
9247b36b6e0Skxie@chelsio.com 
9257b36b6e0Skxie@chelsio.com 	free_atid(csk);
9267b36b6e0Skxie@chelsio.com 
9277b36b6e0Skxie@chelsio.com 	spin_lock_bh(&csk->lock);
9287b36b6e0Skxie@chelsio.com 	if (unlikely(csk->state != CTP_ACTIVE_OPEN))
9297b36b6e0Skxie@chelsio.com 		pr_info("csk 0x%p,%u,0x%lx,%u, got EST.\n",
9307b36b6e0Skxie@chelsio.com 			csk, csk->state, csk->flags, csk->tid);
9317b36b6e0Skxie@chelsio.com 
9327b36b6e0Skxie@chelsio.com 	if (csk->retry_timer.function) {
9337b36b6e0Skxie@chelsio.com 		del_timer(&csk->retry_timer);
9347b36b6e0Skxie@chelsio.com 		csk->retry_timer.function = NULL;
9357b36b6e0Skxie@chelsio.com 	}
9367b36b6e0Skxie@chelsio.com 
9377b36b6e0Skxie@chelsio.com 	csk->copied_seq = csk->rcv_wup = csk->rcv_nxt = rcv_isn;
9387b36b6e0Skxie@chelsio.com 	/*
9397b36b6e0Skxie@chelsio.com 	 * Causes the first RX_DATA_ACK to supply any Rx credits we couldn't
9407b36b6e0Skxie@chelsio.com 	 * pass through opt0.
9417b36b6e0Skxie@chelsio.com 	 */
94281daf10cSKaren Xie 	if (csk->rcv_win > (RCV_BUFSIZ_MASK << 10))
94381daf10cSKaren Xie 		csk->rcv_wup -= csk->rcv_win - (RCV_BUFSIZ_MASK << 10);
9447b36b6e0Skxie@chelsio.com 
9456c53e938SHariprasad Shenai 	csk->advmss = lldi->mtus[TCPOPT_MSS_G(tcp_opt)] - 40;
9466c53e938SHariprasad Shenai 	if (TCPOPT_TSTAMP_G(tcp_opt))
9477b36b6e0Skxie@chelsio.com 		csk->advmss -= 12;
9487b36b6e0Skxie@chelsio.com 	if (csk->advmss < 128)
9497b36b6e0Skxie@chelsio.com 		csk->advmss = 128;
9507b36b6e0Skxie@chelsio.com 
9517b36b6e0Skxie@chelsio.com 	log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
9527b36b6e0Skxie@chelsio.com 		"csk 0x%p, mss_idx %u, advmss %u.\n",
9536c53e938SHariprasad Shenai 			csk, TCPOPT_MSS_G(tcp_opt), csk->advmss);
9547b36b6e0Skxie@chelsio.com 
9557b36b6e0Skxie@chelsio.com 	cxgbi_sock_established(csk, ntohl(req->snd_isn), ntohs(req->tcp_opt));
9567b36b6e0Skxie@chelsio.com 
9577b36b6e0Skxie@chelsio.com 	if (unlikely(cxgbi_sock_flag(csk, CTPF_ACTIVE_CLOSE_NEEDED)))
9587b36b6e0Skxie@chelsio.com 		send_abort_req(csk);
9597b36b6e0Skxie@chelsio.com 	else {
9607b36b6e0Skxie@chelsio.com 		if (skb_queue_len(&csk->write_queue))
9617b36b6e0Skxie@chelsio.com 			push_tx_frames(csk, 0);
9627b36b6e0Skxie@chelsio.com 		cxgbi_conn_tx_open(csk);
9637b36b6e0Skxie@chelsio.com 	}
9647b36b6e0Skxie@chelsio.com 	spin_unlock_bh(&csk->lock);
9657b36b6e0Skxie@chelsio.com 
9667b36b6e0Skxie@chelsio.com rel_skb:
9677b36b6e0Skxie@chelsio.com 	__kfree_skb(skb);
9687b36b6e0Skxie@chelsio.com }
9697b36b6e0Skxie@chelsio.com 
act_open_rpl_status_to_errno(int status)9707b36b6e0Skxie@chelsio.com static int act_open_rpl_status_to_errno(int status)
9717b36b6e0Skxie@chelsio.com {
9727b36b6e0Skxie@chelsio.com 	switch (status) {
9737b36b6e0Skxie@chelsio.com 	case CPL_ERR_CONN_RESET:
9747b36b6e0Skxie@chelsio.com 		return -ECONNREFUSED;
9757b36b6e0Skxie@chelsio.com 	case CPL_ERR_ARP_MISS:
9767b36b6e0Skxie@chelsio.com 		return -EHOSTUNREACH;
9777b36b6e0Skxie@chelsio.com 	case CPL_ERR_CONN_TIMEDOUT:
9787b36b6e0Skxie@chelsio.com 		return -ETIMEDOUT;
9797b36b6e0Skxie@chelsio.com 	case CPL_ERR_TCAM_FULL:
9807b36b6e0Skxie@chelsio.com 		return -ENOMEM;
9817b36b6e0Skxie@chelsio.com 	case CPL_ERR_CONN_EXIST:
9827b36b6e0Skxie@chelsio.com 		return -EADDRINUSE;
9837b36b6e0Skxie@chelsio.com 	default:
9847b36b6e0Skxie@chelsio.com 		return -EIO;
9857b36b6e0Skxie@chelsio.com 	}
9867b36b6e0Skxie@chelsio.com }
9877b36b6e0Skxie@chelsio.com 
csk_act_open_retry_timer(struct timer_list * t)988cd07f958SKees Cook static void csk_act_open_retry_timer(struct timer_list *t)
9897b36b6e0Skxie@chelsio.com {
990001586a7SAnish Bhatt 	struct sk_buff *skb = NULL;
991cd07f958SKees Cook 	struct cxgbi_sock *csk = from_timer(csk, t, retry_timer);
9923bd3e8bfSKaren Xie 	struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(csk->cdev);
993759a0cc5SAnish Bhatt 	void (*send_act_open_func)(struct cxgbi_sock *, struct sk_buff *,
994759a0cc5SAnish Bhatt 				   struct l2t_entry *);
995759a0cc5SAnish Bhatt 	int t4 = is_t4(lldi->adapter_type), size, size6;
9967b36b6e0Skxie@chelsio.com 
9977b36b6e0Skxie@chelsio.com 	log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
9987b36b6e0Skxie@chelsio.com 		"csk 0x%p,%u,0x%lx,%u.\n",
9997b36b6e0Skxie@chelsio.com 		csk, csk->state, csk->flags, csk->tid);
10007b36b6e0Skxie@chelsio.com 
10017b36b6e0Skxie@chelsio.com 	cxgbi_sock_get(csk);
10027b36b6e0Skxie@chelsio.com 	spin_lock_bh(&csk->lock);
1003759a0cc5SAnish Bhatt 
1004759a0cc5SAnish Bhatt 	if (t4) {
1005759a0cc5SAnish Bhatt 		size = sizeof(struct cpl_act_open_req);
1006759a0cc5SAnish Bhatt 		size6 = sizeof(struct cpl_act_open_req6);
1007759a0cc5SAnish Bhatt 	} else {
1008759a0cc5SAnish Bhatt 		size = sizeof(struct cpl_t5_act_open_req);
1009759a0cc5SAnish Bhatt 		size6 = sizeof(struct cpl_t5_act_open_req6);
1010759a0cc5SAnish Bhatt 	}
1011759a0cc5SAnish Bhatt 
1012759a0cc5SAnish Bhatt 	if (csk->csk_family == AF_INET) {
1013759a0cc5SAnish Bhatt 		send_act_open_func = send_act_open_req;
1014759a0cc5SAnish Bhatt 		skb = alloc_wr(size, 0, GFP_ATOMIC);
1015f42bb57cSAnish Bhatt #if IS_ENABLED(CONFIG_IPV6)
1016759a0cc5SAnish Bhatt 	} else {
1017759a0cc5SAnish Bhatt 		send_act_open_func = send_act_open_req6;
1018759a0cc5SAnish Bhatt 		skb = alloc_wr(size6, 0, GFP_ATOMIC);
1019f42bb57cSAnish Bhatt #endif
1020759a0cc5SAnish Bhatt 	}
1021759a0cc5SAnish Bhatt 
10227b36b6e0Skxie@chelsio.com 	if (!skb)
10237b36b6e0Skxie@chelsio.com 		cxgbi_sock_fail_act_open(csk, -ENOMEM);
10247b36b6e0Skxie@chelsio.com 	else {
10257b36b6e0Skxie@chelsio.com 		skb->sk = (struct sock *)csk;
10267b36b6e0Skxie@chelsio.com 		t4_set_arp_err_handler(skb, csk,
10277b36b6e0Skxie@chelsio.com 				       cxgbi_sock_act_open_req_arp_failure);
1028759a0cc5SAnish Bhatt 		send_act_open_func(csk, skb, csk->l2t);
10297b36b6e0Skxie@chelsio.com 	}
1030759a0cc5SAnish Bhatt 
10317b36b6e0Skxie@chelsio.com 	spin_unlock_bh(&csk->lock);
10327b36b6e0Skxie@chelsio.com 	cxgbi_sock_put(csk);
1033759a0cc5SAnish Bhatt 
10347b36b6e0Skxie@chelsio.com }
10357b36b6e0Skxie@chelsio.com 
is_neg_adv(unsigned int status)1036928567adSKaren Xie static inline bool is_neg_adv(unsigned int status)
1037928567adSKaren Xie {
1038928567adSKaren Xie 	return status == CPL_ERR_RTX_NEG_ADVICE ||
1039928567adSKaren Xie 		status == CPL_ERR_KEEPALV_NEG_ADVICE ||
1040928567adSKaren Xie 		status == CPL_ERR_PERSIST_NEG_ADVICE;
1041928567adSKaren Xie }
1042928567adSKaren Xie 
do_act_open_rpl(struct cxgbi_device * cdev,struct sk_buff * skb)10437b36b6e0Skxie@chelsio.com static void do_act_open_rpl(struct cxgbi_device *cdev, struct sk_buff *skb)
10447b36b6e0Skxie@chelsio.com {
10457b36b6e0Skxie@chelsio.com 	struct cxgbi_sock *csk;
10467b36b6e0Skxie@chelsio.com 	struct cpl_act_open_rpl *rpl = (struct cpl_act_open_rpl *)skb->data;
10477b36b6e0Skxie@chelsio.com 	unsigned int tid = GET_TID(rpl);
10487b36b6e0Skxie@chelsio.com 	unsigned int atid =
10496c53e938SHariprasad Shenai 		TID_TID_G(AOPEN_ATID_G(be32_to_cpu(rpl->atid_status)));
10506c53e938SHariprasad Shenai 	unsigned int status = AOPEN_STATUS_G(be32_to_cpu(rpl->atid_status));
10517b36b6e0Skxie@chelsio.com 	struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(cdev);
10527b36b6e0Skxie@chelsio.com 	struct tid_info *t = lldi->tids;
10537b36b6e0Skxie@chelsio.com 
10547b36b6e0Skxie@chelsio.com 	csk = lookup_atid(t, atid);
10557b36b6e0Skxie@chelsio.com 	if (unlikely(!csk)) {
10567b36b6e0Skxie@chelsio.com 		pr_err("NO matching conn. atid %u, tid %u.\n", atid, tid);
10577b36b6e0Skxie@chelsio.com 		goto rel_skb;
10587b36b6e0Skxie@chelsio.com 	}
10597b36b6e0Skxie@chelsio.com 
1060759a0cc5SAnish Bhatt 	pr_info_ipaddr("tid %u/%u, status %u.\n"
1061759a0cc5SAnish Bhatt 		       "csk 0x%p,%u,0x%lx. ", (&csk->saddr), (&csk->daddr),
1062e27d6169Skxie@chelsio.com 		       atid, tid, status, csk, csk->state, csk->flags);
10637b36b6e0Skxie@chelsio.com 
1064928567adSKaren Xie 	if (is_neg_adv(status))
1065150cca7cSKaren Xie 		goto rel_skb;
1066150cca7cSKaren Xie 
10671fe1fdb0SVarun Prakash 	module_put(cdev->owner);
1068ee7255adSAnish Bhatt 
10697b36b6e0Skxie@chelsio.com 	if (status && status != CPL_ERR_TCAM_FULL &&
10707b36b6e0Skxie@chelsio.com 	    status != CPL_ERR_CONN_EXIST &&
10717b36b6e0Skxie@chelsio.com 	    status != CPL_ERR_ARP_MISS)
10721dec4cecSGanesh Goudar 		cxgb4_remove_tid(lldi->tids, csk->port_id, GET_TID(rpl),
10731dec4cecSGanesh Goudar 				 csk->csk_family);
10747b36b6e0Skxie@chelsio.com 
10757b36b6e0Skxie@chelsio.com 	cxgbi_sock_get(csk);
10767b36b6e0Skxie@chelsio.com 	spin_lock_bh(&csk->lock);
10777b36b6e0Skxie@chelsio.com 
10787b36b6e0Skxie@chelsio.com 	if (status == CPL_ERR_CONN_EXIST &&
1079841b86f3SKees Cook 	    csk->retry_timer.function != csk_act_open_retry_timer) {
1080841b86f3SKees Cook 		csk->retry_timer.function = csk_act_open_retry_timer;
10817b36b6e0Skxie@chelsio.com 		mod_timer(&csk->retry_timer, jiffies + HZ / 2);
10827b36b6e0Skxie@chelsio.com 	} else
10837b36b6e0Skxie@chelsio.com 		cxgbi_sock_fail_act_open(csk,
10847b36b6e0Skxie@chelsio.com 					act_open_rpl_status_to_errno(status));
10857b36b6e0Skxie@chelsio.com 
10867b36b6e0Skxie@chelsio.com 	spin_unlock_bh(&csk->lock);
10877b36b6e0Skxie@chelsio.com 	cxgbi_sock_put(csk);
10887b36b6e0Skxie@chelsio.com rel_skb:
10897b36b6e0Skxie@chelsio.com 	__kfree_skb(skb);
10907b36b6e0Skxie@chelsio.com }
10917b36b6e0Skxie@chelsio.com 
do_peer_close(struct cxgbi_device * cdev,struct sk_buff * skb)10927b36b6e0Skxie@chelsio.com static void do_peer_close(struct cxgbi_device *cdev, struct sk_buff *skb)
10937b36b6e0Skxie@chelsio.com {
10947b36b6e0Skxie@chelsio.com 	struct cxgbi_sock *csk;
10957b36b6e0Skxie@chelsio.com 	struct cpl_peer_close *req = (struct cpl_peer_close *)skb->data;
10967b36b6e0Skxie@chelsio.com 	unsigned int tid = GET_TID(req);
10977b36b6e0Skxie@chelsio.com 	struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(cdev);
10987b36b6e0Skxie@chelsio.com 	struct tid_info *t = lldi->tids;
10997b36b6e0Skxie@chelsio.com 
11007b36b6e0Skxie@chelsio.com 	csk = lookup_tid(t, tid);
11017b36b6e0Skxie@chelsio.com 	if (unlikely(!csk)) {
11027b36b6e0Skxie@chelsio.com 		pr_err("can't find connection for tid %u.\n", tid);
11037b36b6e0Skxie@chelsio.com 		goto rel_skb;
11047b36b6e0Skxie@chelsio.com 	}
1105759a0cc5SAnish Bhatt 	pr_info_ipaddr("csk 0x%p,%u,0x%lx,%u.\n",
1106759a0cc5SAnish Bhatt 		       (&csk->saddr), (&csk->daddr),
11077b36b6e0Skxie@chelsio.com 		       csk, csk->state, csk->flags, csk->tid);
11087b36b6e0Skxie@chelsio.com 	cxgbi_sock_rcv_peer_close(csk);
11097b36b6e0Skxie@chelsio.com rel_skb:
11107b36b6e0Skxie@chelsio.com 	__kfree_skb(skb);
11117b36b6e0Skxie@chelsio.com }
11127b36b6e0Skxie@chelsio.com 
do_close_con_rpl(struct cxgbi_device * cdev,struct sk_buff * skb)11137b36b6e0Skxie@chelsio.com static void do_close_con_rpl(struct cxgbi_device *cdev, struct sk_buff *skb)
11147b36b6e0Skxie@chelsio.com {
11157b36b6e0Skxie@chelsio.com 	struct cxgbi_sock *csk;
11167b36b6e0Skxie@chelsio.com 	struct cpl_close_con_rpl *rpl = (struct cpl_close_con_rpl *)skb->data;
11177b36b6e0Skxie@chelsio.com 	unsigned int tid = GET_TID(rpl);
11187b36b6e0Skxie@chelsio.com 	struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(cdev);
11197b36b6e0Skxie@chelsio.com 	struct tid_info *t = lldi->tids;
11207b36b6e0Skxie@chelsio.com 
11217b36b6e0Skxie@chelsio.com 	csk = lookup_tid(t, tid);
11227b36b6e0Skxie@chelsio.com 	if (unlikely(!csk)) {
11237b36b6e0Skxie@chelsio.com 		pr_err("can't find connection for tid %u.\n", tid);
11247b36b6e0Skxie@chelsio.com 		goto rel_skb;
11257b36b6e0Skxie@chelsio.com 	}
1126759a0cc5SAnish Bhatt 	pr_info_ipaddr("csk 0x%p,%u,0x%lx,%u.\n",
1127759a0cc5SAnish Bhatt 		       (&csk->saddr), (&csk->daddr),
11287b36b6e0Skxie@chelsio.com 		       csk, csk->state, csk->flags, csk->tid);
11297b36b6e0Skxie@chelsio.com 	cxgbi_sock_rcv_close_conn_rpl(csk, ntohl(rpl->snd_nxt));
11307b36b6e0Skxie@chelsio.com rel_skb:
11317b36b6e0Skxie@chelsio.com 	__kfree_skb(skb);
11327b36b6e0Skxie@chelsio.com }
11337b36b6e0Skxie@chelsio.com 
abort_status_to_errno(struct cxgbi_sock * csk,int abort_reason,int * need_rst)11347b36b6e0Skxie@chelsio.com static int abort_status_to_errno(struct cxgbi_sock *csk, int abort_reason,
11357b36b6e0Skxie@chelsio.com 								int *need_rst)
11367b36b6e0Skxie@chelsio.com {
11377b36b6e0Skxie@chelsio.com 	switch (abort_reason) {
1138df561f66SGustavo A. R. Silva 	case CPL_ERR_BAD_SYN:
11397b36b6e0Skxie@chelsio.com 	case CPL_ERR_CONN_RESET:
11407b36b6e0Skxie@chelsio.com 		return csk->state > CTP_ESTABLISHED ?
11417b36b6e0Skxie@chelsio.com 			-EPIPE : -ECONNRESET;
11427b36b6e0Skxie@chelsio.com 	case CPL_ERR_XMIT_TIMEDOUT:
11437b36b6e0Skxie@chelsio.com 	case CPL_ERR_PERSIST_TIMEDOUT:
11447b36b6e0Skxie@chelsio.com 	case CPL_ERR_FINWAIT2_TIMEDOUT:
11457b36b6e0Skxie@chelsio.com 	case CPL_ERR_KEEPALIVE_TIMEDOUT:
11467b36b6e0Skxie@chelsio.com 		return -ETIMEDOUT;
11477b36b6e0Skxie@chelsio.com 	default:
11487b36b6e0Skxie@chelsio.com 		return -EIO;
11497b36b6e0Skxie@chelsio.com 	}
11507b36b6e0Skxie@chelsio.com }
11517b36b6e0Skxie@chelsio.com 
do_abort_req_rss(struct cxgbi_device * cdev,struct sk_buff * skb)11527b36b6e0Skxie@chelsio.com static void do_abort_req_rss(struct cxgbi_device *cdev, struct sk_buff *skb)
11537b36b6e0Skxie@chelsio.com {
11547b36b6e0Skxie@chelsio.com 	struct cxgbi_sock *csk;
11557b36b6e0Skxie@chelsio.com 	struct cpl_abort_req_rss *req = (struct cpl_abort_req_rss *)skb->data;
11567b36b6e0Skxie@chelsio.com 	unsigned int tid = GET_TID(req);
11577b36b6e0Skxie@chelsio.com 	struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(cdev);
11587b36b6e0Skxie@chelsio.com 	struct tid_info *t = lldi->tids;
11597b36b6e0Skxie@chelsio.com 	int rst_status = CPL_ABORT_NO_RST;
11607b36b6e0Skxie@chelsio.com 
11617b36b6e0Skxie@chelsio.com 	csk = lookup_tid(t, tid);
11627b36b6e0Skxie@chelsio.com 	if (unlikely(!csk)) {
11637b36b6e0Skxie@chelsio.com 		pr_err("can't find connection for tid %u.\n", tid);
11647b36b6e0Skxie@chelsio.com 		goto rel_skb;
11657b36b6e0Skxie@chelsio.com 	}
11667b36b6e0Skxie@chelsio.com 
1167759a0cc5SAnish Bhatt 	pr_info_ipaddr("csk 0x%p,%u,0x%lx,%u, status %u.\n",
1168759a0cc5SAnish Bhatt 		       (&csk->saddr), (&csk->daddr),
11697b36b6e0Skxie@chelsio.com 		       csk, csk->state, csk->flags, csk->tid, req->status);
11707b36b6e0Skxie@chelsio.com 
1171928567adSKaren Xie 	if (is_neg_adv(req->status))
11727b36b6e0Skxie@chelsio.com 		goto rel_skb;
11737b36b6e0Skxie@chelsio.com 
11747b36b6e0Skxie@chelsio.com 	cxgbi_sock_get(csk);
11757b36b6e0Skxie@chelsio.com 	spin_lock_bh(&csk->lock);
11767b36b6e0Skxie@chelsio.com 
11777b07bf24SAnish Bhatt 	cxgbi_sock_clear_flag(csk, CTPF_ABORT_REQ_RCVD);
11787b07bf24SAnish Bhatt 
11797b07bf24SAnish Bhatt 	if (!cxgbi_sock_flag(csk, CTPF_TX_DATA_SENT)) {
11807b07bf24SAnish Bhatt 		send_tx_flowc_wr(csk);
11817b07bf24SAnish Bhatt 		cxgbi_sock_set_flag(csk, CTPF_TX_DATA_SENT);
11827b36b6e0Skxie@chelsio.com 	}
11837b36b6e0Skxie@chelsio.com 
11847b07bf24SAnish Bhatt 	cxgbi_sock_set_flag(csk, CTPF_ABORT_REQ_RCVD);
11857b07bf24SAnish Bhatt 	cxgbi_sock_set_state(csk, CTP_ABORTING);
11867b07bf24SAnish Bhatt 
11877b36b6e0Skxie@chelsio.com 	send_abort_rpl(csk, rst_status);
11887b36b6e0Skxie@chelsio.com 
11897b36b6e0Skxie@chelsio.com 	if (!cxgbi_sock_flag(csk, CTPF_ABORT_RPL_PENDING)) {
11907b36b6e0Skxie@chelsio.com 		csk->err = abort_status_to_errno(csk, req->status, &rst_status);
11917b36b6e0Skxie@chelsio.com 		cxgbi_sock_closed(csk);
11927b36b6e0Skxie@chelsio.com 	}
11937b07bf24SAnish Bhatt 
11947b36b6e0Skxie@chelsio.com 	spin_unlock_bh(&csk->lock);
11957b36b6e0Skxie@chelsio.com 	cxgbi_sock_put(csk);
11967b36b6e0Skxie@chelsio.com rel_skb:
11977b36b6e0Skxie@chelsio.com 	__kfree_skb(skb);
11987b36b6e0Skxie@chelsio.com }
11997b36b6e0Skxie@chelsio.com 
do_abort_rpl_rss(struct cxgbi_device * cdev,struct sk_buff * skb)12007b36b6e0Skxie@chelsio.com static void do_abort_rpl_rss(struct cxgbi_device *cdev, struct sk_buff *skb)
12017b36b6e0Skxie@chelsio.com {
12027b36b6e0Skxie@chelsio.com 	struct cxgbi_sock *csk;
12037b36b6e0Skxie@chelsio.com 	struct cpl_abort_rpl_rss *rpl = (struct cpl_abort_rpl_rss *)skb->data;
12047b36b6e0Skxie@chelsio.com 	unsigned int tid = GET_TID(rpl);
12057b36b6e0Skxie@chelsio.com 	struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(cdev);
12067b36b6e0Skxie@chelsio.com 	struct tid_info *t = lldi->tids;
12077b36b6e0Skxie@chelsio.com 
12087b36b6e0Skxie@chelsio.com 	csk = lookup_tid(t, tid);
12097b36b6e0Skxie@chelsio.com 	if (!csk)
12107b36b6e0Skxie@chelsio.com 		goto rel_skb;
12117b36b6e0Skxie@chelsio.com 
1212759a0cc5SAnish Bhatt 	pr_info_ipaddr("csk 0x%p,%u,0x%lx,%u, status %u.\n",
1213759a0cc5SAnish Bhatt 		       (&csk->saddr), (&csk->daddr), csk,
1214759a0cc5SAnish Bhatt 		       csk->state, csk->flags, csk->tid, rpl->status);
12157b36b6e0Skxie@chelsio.com 
12167b36b6e0Skxie@chelsio.com 	if (rpl->status == CPL_ERR_ABORT_FAILED)
12177b36b6e0Skxie@chelsio.com 		goto rel_skb;
12187b36b6e0Skxie@chelsio.com 
12197b36b6e0Skxie@chelsio.com 	cxgbi_sock_rcv_abort_rpl(csk);
12207b36b6e0Skxie@chelsio.com rel_skb:
12217b36b6e0Skxie@chelsio.com 	__kfree_skb(skb);
12227b36b6e0Skxie@chelsio.com }
12237b36b6e0Skxie@chelsio.com 
do_rx_data(struct cxgbi_device * cdev,struct sk_buff * skb)1224f7bcd2e1SKaren Xie static void do_rx_data(struct cxgbi_device *cdev, struct sk_buff *skb)
1225f7bcd2e1SKaren Xie {
1226f7bcd2e1SKaren Xie 	struct cxgbi_sock *csk;
1227f7bcd2e1SKaren Xie 	struct cpl_rx_data *cpl = (struct cpl_rx_data *)skb->data;
1228f7bcd2e1SKaren Xie 	unsigned int tid = GET_TID(cpl);
1229f7bcd2e1SKaren Xie 	struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(cdev);
1230f7bcd2e1SKaren Xie 	struct tid_info *t = lldi->tids;
1231f7bcd2e1SKaren Xie 
1232f7bcd2e1SKaren Xie 	csk = lookup_tid(t, tid);
1233f7bcd2e1SKaren Xie 	if (!csk) {
1234f7bcd2e1SKaren Xie 		pr_err("can't find connection for tid %u.\n", tid);
1235f7bcd2e1SKaren Xie 	} else {
1236f7bcd2e1SKaren Xie 		/* not expecting this, reset the connection. */
1237f7bcd2e1SKaren Xie 		pr_err("csk 0x%p, tid %u, rcv cpl_rx_data.\n", csk, tid);
1238f7bcd2e1SKaren Xie 		spin_lock_bh(&csk->lock);
1239f7bcd2e1SKaren Xie 		send_abort_req(csk);
1240f7bcd2e1SKaren Xie 		spin_unlock_bh(&csk->lock);
1241f7bcd2e1SKaren Xie 	}
1242f7bcd2e1SKaren Xie 	__kfree_skb(skb);
1243f7bcd2e1SKaren Xie }
1244f7bcd2e1SKaren Xie 
do_rx_iscsi_hdr(struct cxgbi_device * cdev,struct sk_buff * skb)12457b36b6e0Skxie@chelsio.com static void do_rx_iscsi_hdr(struct cxgbi_device *cdev, struct sk_buff *skb)
12467b36b6e0Skxie@chelsio.com {
12477b36b6e0Skxie@chelsio.com 	struct cxgbi_sock *csk;
12487b36b6e0Skxie@chelsio.com 	struct cpl_iscsi_hdr *cpl = (struct cpl_iscsi_hdr *)skb->data;
12497b36b6e0Skxie@chelsio.com 	unsigned short pdu_len_ddp = be16_to_cpu(cpl->pdu_len_ddp);
12507b36b6e0Skxie@chelsio.com 	unsigned int tid = GET_TID(cpl);
12517b36b6e0Skxie@chelsio.com 	struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(cdev);
12527b36b6e0Skxie@chelsio.com 	struct tid_info *t = lldi->tids;
12537b36b6e0Skxie@chelsio.com 
12547b36b6e0Skxie@chelsio.com 	csk = lookup_tid(t, tid);
12557b36b6e0Skxie@chelsio.com 	if (unlikely(!csk)) {
12567b36b6e0Skxie@chelsio.com 		pr_err("can't find conn. for tid %u.\n", tid);
12577b36b6e0Skxie@chelsio.com 		goto rel_skb;
12587b36b6e0Skxie@chelsio.com 	}
12597b36b6e0Skxie@chelsio.com 
12607b36b6e0Skxie@chelsio.com 	log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_PDU_RX,
12617b36b6e0Skxie@chelsio.com 		"csk 0x%p,%u,0x%lx, tid %u, skb 0x%p,%u, 0x%x.\n",
12627b36b6e0Skxie@chelsio.com 		csk, csk->state, csk->flags, csk->tid, skb, skb->len,
12637b36b6e0Skxie@chelsio.com 		pdu_len_ddp);
12647b36b6e0Skxie@chelsio.com 
12657b36b6e0Skxie@chelsio.com 	spin_lock_bh(&csk->lock);
12667b36b6e0Skxie@chelsio.com 
12677b36b6e0Skxie@chelsio.com 	if (unlikely(csk->state >= CTP_PASSIVE_CLOSE)) {
12687b36b6e0Skxie@chelsio.com 		log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
12697b36b6e0Skxie@chelsio.com 			"csk 0x%p,%u,0x%lx,%u, bad state.\n",
12707b36b6e0Skxie@chelsio.com 			csk, csk->state, csk->flags, csk->tid);
12717b36b6e0Skxie@chelsio.com 		if (csk->state != CTP_ABORTING)
12727b36b6e0Skxie@chelsio.com 			goto abort_conn;
12737b36b6e0Skxie@chelsio.com 		else
12747b36b6e0Skxie@chelsio.com 			goto discard;
12757b36b6e0Skxie@chelsio.com 	}
12767b36b6e0Skxie@chelsio.com 
12777b36b6e0Skxie@chelsio.com 	cxgbi_skcb_tcp_seq(skb) = ntohl(cpl->seq);
1278e27d6169Skxie@chelsio.com 	cxgbi_skcb_flags(skb) = 0;
1279e27d6169Skxie@chelsio.com 
12807b36b6e0Skxie@chelsio.com 	skb_reset_transport_header(skb);
12817b36b6e0Skxie@chelsio.com 	__skb_pull(skb, sizeof(*cpl));
12827b36b6e0Skxie@chelsio.com 	__pskb_trim(skb, ntohs(cpl->len));
12837b36b6e0Skxie@chelsio.com 
12847b36b6e0Skxie@chelsio.com 	if (!csk->skb_ulp_lhdr) {
12857b36b6e0Skxie@chelsio.com 		unsigned char *bhs;
12863bd3e8bfSKaren Xie 		unsigned int hlen, dlen, plen;
12877b36b6e0Skxie@chelsio.com 
12887b36b6e0Skxie@chelsio.com 		log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_PDU_RX,
12897b36b6e0Skxie@chelsio.com 			"csk 0x%p,%u,0x%lx, tid %u, skb 0x%p header.\n",
12907b36b6e0Skxie@chelsio.com 			csk, csk->state, csk->flags, csk->tid, skb);
12917b36b6e0Skxie@chelsio.com 		csk->skb_ulp_lhdr = skb;
1292e27d6169Skxie@chelsio.com 		cxgbi_skcb_set_flag(skb, SKCBF_RX_HDR);
12937b36b6e0Skxie@chelsio.com 
129426af1a36SVarun Prakash 		if ((CHELSIO_CHIP_VERSION(lldi->adapter_type) <= CHELSIO_T5) &&
129526af1a36SVarun Prakash 		    (cxgbi_skcb_tcp_seq(skb) != csk->rcv_nxt)) {
12967b36b6e0Skxie@chelsio.com 			pr_info("tid %u, CPL_ISCSI_HDR, bad seq, 0x%x/0x%x.\n",
1297e27d6169Skxie@chelsio.com 				csk->tid, cxgbi_skcb_tcp_seq(skb),
12987b36b6e0Skxie@chelsio.com 				csk->rcv_nxt);
12997b36b6e0Skxie@chelsio.com 			goto abort_conn;
13007b36b6e0Skxie@chelsio.com 		}
13017b36b6e0Skxie@chelsio.com 
1302e27d6169Skxie@chelsio.com 		bhs = skb->data;
13037b36b6e0Skxie@chelsio.com 		hlen = ntohs(cpl->len);
13047b36b6e0Skxie@chelsio.com 		dlen = ntohl(*(unsigned int *)(bhs + 4)) & 0xFFFFFF;
13057b36b6e0Skxie@chelsio.com 
1306bdc590b9SHariprasad Shenai 		plen = ISCSI_PDU_LEN_G(pdu_len_ddp);
13073bd3e8bfSKaren Xie 		if (is_t4(lldi->adapter_type))
13083bd3e8bfSKaren Xie 			plen -= 40;
13093bd3e8bfSKaren Xie 
13103bd3e8bfSKaren Xie 		if ((hlen + dlen) != plen) {
13117b36b6e0Skxie@chelsio.com 			pr_info("tid 0x%x, CPL_ISCSI_HDR, pdu len "
13127b36b6e0Skxie@chelsio.com 				"mismatch %u != %u + %u, seq 0x%x.\n",
13133bd3e8bfSKaren Xie 				csk->tid, plen, hlen, dlen,
13143bd3e8bfSKaren Xie 				cxgbi_skcb_tcp_seq(skb));
13157b36b6e0Skxie@chelsio.com 			goto abort_conn;
13167b36b6e0Skxie@chelsio.com 		}
13177b36b6e0Skxie@chelsio.com 
13187b36b6e0Skxie@chelsio.com 		cxgbi_skcb_rx_pdulen(skb) = (hlen + dlen + 3) & (~0x3);
13197b36b6e0Skxie@chelsio.com 		if (dlen)
13207b36b6e0Skxie@chelsio.com 			cxgbi_skcb_rx_pdulen(skb) += csk->dcrc_len;
13217b36b6e0Skxie@chelsio.com 		csk->rcv_nxt += cxgbi_skcb_rx_pdulen(skb);
13227b36b6e0Skxie@chelsio.com 
13237b36b6e0Skxie@chelsio.com 		log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_PDU_RX,
13247b36b6e0Skxie@chelsio.com 			"csk 0x%p, skb 0x%p, 0x%x,%u+%u,0x%x,0x%x.\n",
13257b36b6e0Skxie@chelsio.com 			csk, skb, *bhs, hlen, dlen,
13267b36b6e0Skxie@chelsio.com 			ntohl(*((unsigned int *)(bhs + 16))),
13277b36b6e0Skxie@chelsio.com 			ntohl(*((unsigned int *)(bhs + 24))));
13287b36b6e0Skxie@chelsio.com 
13297b36b6e0Skxie@chelsio.com 	} else {
1330e27d6169Skxie@chelsio.com 		struct sk_buff *lskb = csk->skb_ulp_lhdr;
13317b36b6e0Skxie@chelsio.com 
1332e27d6169Skxie@chelsio.com 		cxgbi_skcb_set_flag(lskb, SKCBF_RX_DATA);
13337b36b6e0Skxie@chelsio.com 		log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_PDU_RX,
13347b36b6e0Skxie@chelsio.com 			"csk 0x%p,%u,0x%lx, skb 0x%p data, 0x%p.\n",
13357b36b6e0Skxie@chelsio.com 			csk, csk->state, csk->flags, skb, lskb);
13367b36b6e0Skxie@chelsio.com 	}
13377b36b6e0Skxie@chelsio.com 
13387b36b6e0Skxie@chelsio.com 	__skb_queue_tail(&csk->receive_queue, skb);
13397b36b6e0Skxie@chelsio.com 	spin_unlock_bh(&csk->lock);
13407b36b6e0Skxie@chelsio.com 	return;
13417b36b6e0Skxie@chelsio.com 
13427b36b6e0Skxie@chelsio.com abort_conn:
13437b36b6e0Skxie@chelsio.com 	send_abort_req(csk);
13447b36b6e0Skxie@chelsio.com discard:
13457b36b6e0Skxie@chelsio.com 	spin_unlock_bh(&csk->lock);
13467b36b6e0Skxie@chelsio.com rel_skb:
13477b36b6e0Skxie@chelsio.com 	__kfree_skb(skb);
13487b36b6e0Skxie@chelsio.com }
13497b36b6e0Skxie@chelsio.com 
do_rx_iscsi_data(struct cxgbi_device * cdev,struct sk_buff * skb)135044830d8fSVarun Prakash static void do_rx_iscsi_data(struct cxgbi_device *cdev, struct sk_buff *skb)
135144830d8fSVarun Prakash {
135244830d8fSVarun Prakash 	struct cxgbi_sock *csk;
135344830d8fSVarun Prakash 	struct cpl_iscsi_hdr *cpl = (struct cpl_iscsi_hdr *)skb->data;
135444830d8fSVarun Prakash 	struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(cdev);
135544830d8fSVarun Prakash 	struct tid_info *t = lldi->tids;
135644830d8fSVarun Prakash 	struct sk_buff *lskb;
135744830d8fSVarun Prakash 	u32 tid = GET_TID(cpl);
135844830d8fSVarun Prakash 	u16 pdu_len_ddp = be16_to_cpu(cpl->pdu_len_ddp);
135944830d8fSVarun Prakash 
136044830d8fSVarun Prakash 	csk = lookup_tid(t, tid);
136144830d8fSVarun Prakash 	if (unlikely(!csk)) {
136244830d8fSVarun Prakash 		pr_err("can't find conn. for tid %u.\n", tid);
136344830d8fSVarun Prakash 		goto rel_skb;
136444830d8fSVarun Prakash 	}
136544830d8fSVarun Prakash 
136644830d8fSVarun Prakash 	log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_PDU_RX,
136744830d8fSVarun Prakash 		  "csk 0x%p,%u,0x%lx, tid %u, skb 0x%p,%u, 0x%x.\n",
136844830d8fSVarun Prakash 		  csk, csk->state, csk->flags, csk->tid, skb,
136944830d8fSVarun Prakash 		  skb->len, pdu_len_ddp);
137044830d8fSVarun Prakash 
137144830d8fSVarun Prakash 	spin_lock_bh(&csk->lock);
137244830d8fSVarun Prakash 
137344830d8fSVarun Prakash 	if (unlikely(csk->state >= CTP_PASSIVE_CLOSE)) {
137444830d8fSVarun Prakash 		log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
137544830d8fSVarun Prakash 			  "csk 0x%p,%u,0x%lx,%u, bad state.\n",
137644830d8fSVarun Prakash 			  csk, csk->state, csk->flags, csk->tid);
137744830d8fSVarun Prakash 
137844830d8fSVarun Prakash 		if (csk->state != CTP_ABORTING)
137944830d8fSVarun Prakash 			goto abort_conn;
138044830d8fSVarun Prakash 		else
138144830d8fSVarun Prakash 			goto discard;
138244830d8fSVarun Prakash 	}
138344830d8fSVarun Prakash 
138444830d8fSVarun Prakash 	cxgbi_skcb_tcp_seq(skb) = be32_to_cpu(cpl->seq);
138544830d8fSVarun Prakash 	cxgbi_skcb_flags(skb) = 0;
138644830d8fSVarun Prakash 
138744830d8fSVarun Prakash 	skb_reset_transport_header(skb);
138844830d8fSVarun Prakash 	__skb_pull(skb, sizeof(*cpl));
138944830d8fSVarun Prakash 	__pskb_trim(skb, ntohs(cpl->len));
139044830d8fSVarun Prakash 
139144830d8fSVarun Prakash 	if (!csk->skb_ulp_lhdr)
139244830d8fSVarun Prakash 		csk->skb_ulp_lhdr = skb;
139344830d8fSVarun Prakash 
139444830d8fSVarun Prakash 	lskb = csk->skb_ulp_lhdr;
139544830d8fSVarun Prakash 	cxgbi_skcb_set_flag(lskb, SKCBF_RX_DATA);
139644830d8fSVarun Prakash 
139744830d8fSVarun Prakash 	log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_PDU_RX,
139844830d8fSVarun Prakash 		  "csk 0x%p,%u,0x%lx, skb 0x%p data, 0x%p.\n",
139944830d8fSVarun Prakash 		  csk, csk->state, csk->flags, skb, lskb);
140044830d8fSVarun Prakash 
140144830d8fSVarun Prakash 	__skb_queue_tail(&csk->receive_queue, skb);
140244830d8fSVarun Prakash 	spin_unlock_bh(&csk->lock);
140344830d8fSVarun Prakash 	return;
140444830d8fSVarun Prakash 
140544830d8fSVarun Prakash abort_conn:
140644830d8fSVarun Prakash 	send_abort_req(csk);
140744830d8fSVarun Prakash discard:
140844830d8fSVarun Prakash 	spin_unlock_bh(&csk->lock);
140944830d8fSVarun Prakash rel_skb:
141044830d8fSVarun Prakash 	__kfree_skb(skb);
141144830d8fSVarun Prakash }
141244830d8fSVarun Prakash 
141344830d8fSVarun Prakash static void
cxgb4i_process_ddpvld(struct cxgbi_sock * csk,struct sk_buff * skb,u32 ddpvld)141444830d8fSVarun Prakash cxgb4i_process_ddpvld(struct cxgbi_sock *csk,
141544830d8fSVarun Prakash 		      struct sk_buff *skb, u32 ddpvld)
141644830d8fSVarun Prakash {
141744830d8fSVarun Prakash 	if (ddpvld & (1 << CPL_RX_DDP_STATUS_HCRC_SHIFT)) {
141844830d8fSVarun Prakash 		pr_info("csk 0x%p, lhdr 0x%p, status 0x%x, hcrc bad 0x%lx.\n",
141944830d8fSVarun Prakash 			csk, skb, ddpvld, cxgbi_skcb_flags(skb));
142044830d8fSVarun Prakash 		cxgbi_skcb_set_flag(skb, SKCBF_RX_HCRC_ERR);
142144830d8fSVarun Prakash 	}
142244830d8fSVarun Prakash 
142344830d8fSVarun Prakash 	if (ddpvld & (1 << CPL_RX_DDP_STATUS_DCRC_SHIFT)) {
142444830d8fSVarun Prakash 		pr_info("csk 0x%p, lhdr 0x%p, status 0x%x, dcrc bad 0x%lx.\n",
142544830d8fSVarun Prakash 			csk, skb, ddpvld, cxgbi_skcb_flags(skb));
142644830d8fSVarun Prakash 		cxgbi_skcb_set_flag(skb, SKCBF_RX_DCRC_ERR);
142744830d8fSVarun Prakash 	}
142844830d8fSVarun Prakash 
142944830d8fSVarun Prakash 	if (ddpvld & (1 << CPL_RX_DDP_STATUS_PAD_SHIFT)) {
143044830d8fSVarun Prakash 		log_debug(1 << CXGBI_DBG_PDU_RX,
143144830d8fSVarun Prakash 			  "csk 0x%p, lhdr 0x%p, status 0x%x, pad bad.\n",
143244830d8fSVarun Prakash 			  csk, skb, ddpvld);
143344830d8fSVarun Prakash 		cxgbi_skcb_set_flag(skb, SKCBF_RX_PAD_ERR);
143444830d8fSVarun Prakash 	}
143544830d8fSVarun Prakash 
143644830d8fSVarun Prakash 	if ((ddpvld & (1 << CPL_RX_DDP_STATUS_DDP_SHIFT)) &&
143744830d8fSVarun Prakash 	    !cxgbi_skcb_test_flag(skb, SKCBF_RX_DATA)) {
143844830d8fSVarun Prakash 		log_debug(1 << CXGBI_DBG_PDU_RX,
143944830d8fSVarun Prakash 			  "csk 0x%p, lhdr 0x%p, 0x%x, data ddp'ed.\n",
144044830d8fSVarun Prakash 			  csk, skb, ddpvld);
144144830d8fSVarun Prakash 		cxgbi_skcb_set_flag(skb, SKCBF_RX_DATA_DDPD);
144244830d8fSVarun Prakash 	}
144344830d8fSVarun Prakash }
144444830d8fSVarun Prakash 
do_rx_data_ddp(struct cxgbi_device * cdev,struct sk_buff * skb)14457b36b6e0Skxie@chelsio.com static void do_rx_data_ddp(struct cxgbi_device *cdev,
14467b36b6e0Skxie@chelsio.com 				  struct sk_buff *skb)
14477b36b6e0Skxie@chelsio.com {
14487b36b6e0Skxie@chelsio.com 	struct cxgbi_sock *csk;
14497b36b6e0Skxie@chelsio.com 	struct sk_buff *lskb;
14507b36b6e0Skxie@chelsio.com 	struct cpl_rx_data_ddp *rpl = (struct cpl_rx_data_ddp *)skb->data;
14517b36b6e0Skxie@chelsio.com 	unsigned int tid = GET_TID(rpl);
14527b36b6e0Skxie@chelsio.com 	struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(cdev);
14537b36b6e0Skxie@chelsio.com 	struct tid_info *t = lldi->tids;
145444830d8fSVarun Prakash 	u32 ddpvld = be32_to_cpu(rpl->ddpvld);
14557b36b6e0Skxie@chelsio.com 
14567b36b6e0Skxie@chelsio.com 	csk = lookup_tid(t, tid);
14577b36b6e0Skxie@chelsio.com 	if (unlikely(!csk)) {
14587b36b6e0Skxie@chelsio.com 		pr_err("can't find connection for tid %u.\n", tid);
14597b36b6e0Skxie@chelsio.com 		goto rel_skb;
14607b36b6e0Skxie@chelsio.com 	}
14617b36b6e0Skxie@chelsio.com 
14627b36b6e0Skxie@chelsio.com 	log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_PDU_RX,
14637b36b6e0Skxie@chelsio.com 		"csk 0x%p,%u,0x%lx, skb 0x%p,0x%x, lhdr 0x%p.\n",
146444830d8fSVarun Prakash 		csk, csk->state, csk->flags, skb, ddpvld, csk->skb_ulp_lhdr);
14657b36b6e0Skxie@chelsio.com 
14667b36b6e0Skxie@chelsio.com 	spin_lock_bh(&csk->lock);
14677b36b6e0Skxie@chelsio.com 
14687b36b6e0Skxie@chelsio.com 	if (unlikely(csk->state >= CTP_PASSIVE_CLOSE)) {
14697b36b6e0Skxie@chelsio.com 		log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
14707b36b6e0Skxie@chelsio.com 			"csk 0x%p,%u,0x%lx,%u, bad state.\n",
14717b36b6e0Skxie@chelsio.com 			csk, csk->state, csk->flags, csk->tid);
14727b36b6e0Skxie@chelsio.com 		if (csk->state != CTP_ABORTING)
14737b36b6e0Skxie@chelsio.com 			goto abort_conn;
14747b36b6e0Skxie@chelsio.com 		else
14757b36b6e0Skxie@chelsio.com 			goto discard;
14767b36b6e0Skxie@chelsio.com 	}
14777b36b6e0Skxie@chelsio.com 
14787b36b6e0Skxie@chelsio.com 	if (!csk->skb_ulp_lhdr) {
14797b36b6e0Skxie@chelsio.com 		pr_err("tid 0x%x, rcv RX_DATA_DDP w/o pdu bhs.\n", csk->tid);
14807b36b6e0Skxie@chelsio.com 		goto abort_conn;
14817b36b6e0Skxie@chelsio.com 	}
14827b36b6e0Skxie@chelsio.com 
14837b36b6e0Skxie@chelsio.com 	lskb = csk->skb_ulp_lhdr;
14847b36b6e0Skxie@chelsio.com 	csk->skb_ulp_lhdr = NULL;
14857b36b6e0Skxie@chelsio.com 
14867b36b6e0Skxie@chelsio.com 	cxgbi_skcb_rx_ddigest(lskb) = ntohl(rpl->ulp_crc);
14877b36b6e0Skxie@chelsio.com 
14887b36b6e0Skxie@chelsio.com 	if (ntohs(rpl->len) != cxgbi_skcb_rx_pdulen(lskb))
14897b36b6e0Skxie@chelsio.com 		pr_info("tid 0x%x, RX_DATA_DDP pdulen %u != %u.\n",
14907b36b6e0Skxie@chelsio.com 			csk->tid, ntohs(rpl->len), cxgbi_skcb_rx_pdulen(lskb));
14917b36b6e0Skxie@chelsio.com 
149244830d8fSVarun Prakash 	cxgb4i_process_ddpvld(csk, lskb, ddpvld);
149344830d8fSVarun Prakash 
14947b36b6e0Skxie@chelsio.com 	log_debug(1 << CXGBI_DBG_PDU_RX,
14957b36b6e0Skxie@chelsio.com 		"csk 0x%p, lskb 0x%p, f 0x%lx.\n",
14967b36b6e0Skxie@chelsio.com 		csk, lskb, cxgbi_skcb_flags(lskb));
14977b36b6e0Skxie@chelsio.com 
1498e27d6169Skxie@chelsio.com 	cxgbi_skcb_set_flag(lskb, SKCBF_RX_STATUS);
14997b36b6e0Skxie@chelsio.com 	cxgbi_conn_pdu_ready(csk);
15007b36b6e0Skxie@chelsio.com 	spin_unlock_bh(&csk->lock);
15017b36b6e0Skxie@chelsio.com 	goto rel_skb;
15027b36b6e0Skxie@chelsio.com 
15037b36b6e0Skxie@chelsio.com abort_conn:
15047b36b6e0Skxie@chelsio.com 	send_abort_req(csk);
15057b36b6e0Skxie@chelsio.com discard:
15067b36b6e0Skxie@chelsio.com 	spin_unlock_bh(&csk->lock);
15077b36b6e0Skxie@chelsio.com rel_skb:
15087b36b6e0Skxie@chelsio.com 	__kfree_skb(skb);
15097b36b6e0Skxie@chelsio.com }
15107b36b6e0Skxie@chelsio.com 
151144830d8fSVarun Prakash static void
do_rx_iscsi_cmp(struct cxgbi_device * cdev,struct sk_buff * skb)151244830d8fSVarun Prakash do_rx_iscsi_cmp(struct cxgbi_device *cdev, struct sk_buff *skb)
151344830d8fSVarun Prakash {
151444830d8fSVarun Prakash 	struct cxgbi_sock *csk;
151544830d8fSVarun Prakash 	struct cpl_rx_iscsi_cmp *rpl = (struct cpl_rx_iscsi_cmp *)skb->data;
151644830d8fSVarun Prakash 	struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(cdev);
151744830d8fSVarun Prakash 	struct tid_info *t = lldi->tids;
151844830d8fSVarun Prakash 	struct sk_buff *data_skb = NULL;
151944830d8fSVarun Prakash 	u32 tid = GET_TID(rpl);
152044830d8fSVarun Prakash 	u32 ddpvld = be32_to_cpu(rpl->ddpvld);
152144830d8fSVarun Prakash 	u32 seq = be32_to_cpu(rpl->seq);
152244830d8fSVarun Prakash 	u16 pdu_len_ddp = be16_to_cpu(rpl->pdu_len_ddp);
152344830d8fSVarun Prakash 
152444830d8fSVarun Prakash 	csk = lookup_tid(t, tid);
152544830d8fSVarun Prakash 	if (unlikely(!csk)) {
152644830d8fSVarun Prakash 		pr_err("can't find connection for tid %u.\n", tid);
152744830d8fSVarun Prakash 		goto rel_skb;
152844830d8fSVarun Prakash 	}
152944830d8fSVarun Prakash 
153044830d8fSVarun Prakash 	log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_PDU_RX,
153144830d8fSVarun Prakash 		  "csk 0x%p,%u,0x%lx, skb 0x%p,0x%x, lhdr 0x%p, len %u, "
153244830d8fSVarun Prakash 		  "pdu_len_ddp %u, status %u.\n",
153344830d8fSVarun Prakash 		  csk, csk->state, csk->flags, skb, ddpvld, csk->skb_ulp_lhdr,
153444830d8fSVarun Prakash 		  ntohs(rpl->len), pdu_len_ddp,  rpl->status);
153544830d8fSVarun Prakash 
153644830d8fSVarun Prakash 	spin_lock_bh(&csk->lock);
153744830d8fSVarun Prakash 
153844830d8fSVarun Prakash 	if (unlikely(csk->state >= CTP_PASSIVE_CLOSE)) {
153944830d8fSVarun Prakash 		log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
154044830d8fSVarun Prakash 			  "csk 0x%p,%u,0x%lx,%u, bad state.\n",
154144830d8fSVarun Prakash 			  csk, csk->state, csk->flags, csk->tid);
154244830d8fSVarun Prakash 
154344830d8fSVarun Prakash 		if (csk->state != CTP_ABORTING)
154444830d8fSVarun Prakash 			goto abort_conn;
154544830d8fSVarun Prakash 		else
154644830d8fSVarun Prakash 			goto discard;
154744830d8fSVarun Prakash 	}
154844830d8fSVarun Prakash 
154944830d8fSVarun Prakash 	cxgbi_skcb_tcp_seq(skb) = seq;
155044830d8fSVarun Prakash 	cxgbi_skcb_flags(skb) = 0;
155144830d8fSVarun Prakash 	cxgbi_skcb_rx_pdulen(skb) = 0;
155244830d8fSVarun Prakash 
155344830d8fSVarun Prakash 	skb_reset_transport_header(skb);
155444830d8fSVarun Prakash 	__skb_pull(skb, sizeof(*rpl));
155544830d8fSVarun Prakash 	__pskb_trim(skb, be16_to_cpu(rpl->len));
155644830d8fSVarun Prakash 
155744830d8fSVarun Prakash 	csk->rcv_nxt = seq + pdu_len_ddp;
155844830d8fSVarun Prakash 
155944830d8fSVarun Prakash 	if (csk->skb_ulp_lhdr) {
156044830d8fSVarun Prakash 		data_skb = skb_peek(&csk->receive_queue);
156144830d8fSVarun Prakash 		if (!data_skb ||
156244830d8fSVarun Prakash 		    !cxgbi_skcb_test_flag(data_skb, SKCBF_RX_DATA)) {
156344830d8fSVarun Prakash 			pr_err("Error! freelist data not found 0x%p, tid %u\n",
156444830d8fSVarun Prakash 			       data_skb, tid);
156544830d8fSVarun Prakash 
156644830d8fSVarun Prakash 			goto abort_conn;
156744830d8fSVarun Prakash 		}
156844830d8fSVarun Prakash 		__skb_unlink(data_skb, &csk->receive_queue);
156944830d8fSVarun Prakash 
157044830d8fSVarun Prakash 		cxgbi_skcb_set_flag(skb, SKCBF_RX_DATA);
157144830d8fSVarun Prakash 
157244830d8fSVarun Prakash 		__skb_queue_tail(&csk->receive_queue, skb);
157344830d8fSVarun Prakash 		__skb_queue_tail(&csk->receive_queue, data_skb);
157444830d8fSVarun Prakash 	} else {
157544830d8fSVarun Prakash 		 __skb_queue_tail(&csk->receive_queue, skb);
157644830d8fSVarun Prakash 	}
157744830d8fSVarun Prakash 
157844830d8fSVarun Prakash 	csk->skb_ulp_lhdr = NULL;
157944830d8fSVarun Prakash 
158044830d8fSVarun Prakash 	cxgbi_skcb_set_flag(skb, SKCBF_RX_HDR);
158144830d8fSVarun Prakash 	cxgbi_skcb_set_flag(skb, SKCBF_RX_STATUS);
158244830d8fSVarun Prakash 	cxgbi_skcb_set_flag(skb, SKCBF_RX_ISCSI_COMPL);
158344830d8fSVarun Prakash 	cxgbi_skcb_rx_ddigest(skb) = be32_to_cpu(rpl->ulp_crc);
158444830d8fSVarun Prakash 
158544830d8fSVarun Prakash 	cxgb4i_process_ddpvld(csk, skb, ddpvld);
158644830d8fSVarun Prakash 
158744830d8fSVarun Prakash 	log_debug(1 << CXGBI_DBG_PDU_RX, "csk 0x%p, skb 0x%p, f 0x%lx.\n",
158844830d8fSVarun Prakash 		  csk, skb, cxgbi_skcb_flags(skb));
158944830d8fSVarun Prakash 
159044830d8fSVarun Prakash 	cxgbi_conn_pdu_ready(csk);
159144830d8fSVarun Prakash 	spin_unlock_bh(&csk->lock);
159244830d8fSVarun Prakash 
159344830d8fSVarun Prakash 	return;
159444830d8fSVarun Prakash 
159544830d8fSVarun Prakash abort_conn:
159644830d8fSVarun Prakash 	send_abort_req(csk);
159744830d8fSVarun Prakash discard:
159844830d8fSVarun Prakash 	spin_unlock_bh(&csk->lock);
159944830d8fSVarun Prakash rel_skb:
160044830d8fSVarun Prakash 	__kfree_skb(skb);
160144830d8fSVarun Prakash }
160244830d8fSVarun Prakash 
do_fw4_ack(struct cxgbi_device * cdev,struct sk_buff * skb)16037b36b6e0Skxie@chelsio.com static void do_fw4_ack(struct cxgbi_device *cdev, struct sk_buff *skb)
16047b36b6e0Skxie@chelsio.com {
16057b36b6e0Skxie@chelsio.com 	struct cxgbi_sock *csk;
16067b36b6e0Skxie@chelsio.com 	struct cpl_fw4_ack *rpl = (struct cpl_fw4_ack *)skb->data;
16077b36b6e0Skxie@chelsio.com 	unsigned int tid = GET_TID(rpl);
16087b36b6e0Skxie@chelsio.com 	struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(cdev);
16097b36b6e0Skxie@chelsio.com 	struct tid_info *t = lldi->tids;
16107b36b6e0Skxie@chelsio.com 
16117b36b6e0Skxie@chelsio.com 	csk = lookup_tid(t, tid);
16127b36b6e0Skxie@chelsio.com 	if (unlikely(!csk))
16137b36b6e0Skxie@chelsio.com 		pr_err("can't find connection for tid %u.\n", tid);
16147b36b6e0Skxie@chelsio.com 	else {
16157b36b6e0Skxie@chelsio.com 		log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
16167b36b6e0Skxie@chelsio.com 			"csk 0x%p,%u,0x%lx,%u.\n",
16177b36b6e0Skxie@chelsio.com 			csk, csk->state, csk->flags, csk->tid);
16187b36b6e0Skxie@chelsio.com 		cxgbi_sock_rcv_wr_ack(csk, rpl->credits, ntohl(rpl->snd_una),
16197b36b6e0Skxie@chelsio.com 					rpl->seq_vld);
16207b36b6e0Skxie@chelsio.com 	}
16217b36b6e0Skxie@chelsio.com 	__kfree_skb(skb);
16227b36b6e0Skxie@chelsio.com }
16237b36b6e0Skxie@chelsio.com 
do_set_tcb_rpl(struct cxgbi_device * cdev,struct sk_buff * skb)16247b36b6e0Skxie@chelsio.com static void do_set_tcb_rpl(struct cxgbi_device *cdev, struct sk_buff *skb)
16257b36b6e0Skxie@chelsio.com {
16267b36b6e0Skxie@chelsio.com 	struct cpl_set_tcb_rpl *rpl = (struct cpl_set_tcb_rpl *)skb->data;
16277b36b6e0Skxie@chelsio.com 	unsigned int tid = GET_TID(rpl);
16287b36b6e0Skxie@chelsio.com 	struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(cdev);
16297b36b6e0Skxie@chelsio.com 	struct tid_info *t = lldi->tids;
16307b36b6e0Skxie@chelsio.com 	struct cxgbi_sock *csk;
16317b36b6e0Skxie@chelsio.com 
16327b36b6e0Skxie@chelsio.com 	csk = lookup_tid(t, tid);
16339e8f1c79SVarun Prakash 	if (!csk) {
16347b36b6e0Skxie@chelsio.com 		pr_err("can't find conn. for tid %u.\n", tid);
16359e8f1c79SVarun Prakash 		return;
16369e8f1c79SVarun Prakash 	}
16377b36b6e0Skxie@chelsio.com 
16387b36b6e0Skxie@chelsio.com 	log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
16397b36b6e0Skxie@chelsio.com 		"csk 0x%p,%u,%lx,%u, status 0x%x.\n",
16407b36b6e0Skxie@chelsio.com 		csk, csk->state, csk->flags, csk->tid, rpl->status);
16417b36b6e0Skxie@chelsio.com 
16429e8f1c79SVarun Prakash 	if (rpl->status != CPL_ERR_NONE) {
16437b36b6e0Skxie@chelsio.com 		pr_err("csk 0x%p,%u, SET_TCB_RPL status %u.\n",
16447b36b6e0Skxie@chelsio.com 			csk, tid, rpl->status);
16459e8f1c79SVarun Prakash 		csk->err = -EINVAL;
16469e8f1c79SVarun Prakash 	}
16479e8f1c79SVarun Prakash 
16489e8f1c79SVarun Prakash 	complete(&csk->cmpl);
16497b36b6e0Skxie@chelsio.com 
16507b36b6e0Skxie@chelsio.com 	__kfree_skb(skb);
16517b36b6e0Skxie@chelsio.com }
16527b36b6e0Skxie@chelsio.com 
alloc_cpls(struct cxgbi_sock * csk)16537b36b6e0Skxie@chelsio.com static int alloc_cpls(struct cxgbi_sock *csk)
16547b36b6e0Skxie@chelsio.com {
165524d3f95aSkxie@chelsio.com 	csk->cpl_close = alloc_wr(sizeof(struct cpl_close_con_req),
165624d3f95aSkxie@chelsio.com 					0, GFP_KERNEL);
16577b36b6e0Skxie@chelsio.com 	if (!csk->cpl_close)
16587b36b6e0Skxie@chelsio.com 		return -ENOMEM;
16597b36b6e0Skxie@chelsio.com 
166024d3f95aSkxie@chelsio.com 	csk->cpl_abort_req = alloc_wr(sizeof(struct cpl_abort_req),
166124d3f95aSkxie@chelsio.com 					0, GFP_KERNEL);
16627b36b6e0Skxie@chelsio.com 	if (!csk->cpl_abort_req)
16637b36b6e0Skxie@chelsio.com 		goto free_cpls;
16647b36b6e0Skxie@chelsio.com 
166524d3f95aSkxie@chelsio.com 	csk->cpl_abort_rpl = alloc_wr(sizeof(struct cpl_abort_rpl),
166624d3f95aSkxie@chelsio.com 					0, GFP_KERNEL);
16677b36b6e0Skxie@chelsio.com 	if (!csk->cpl_abort_rpl)
16687b36b6e0Skxie@chelsio.com 		goto free_cpls;
16697b36b6e0Skxie@chelsio.com 	return 0;
16707b36b6e0Skxie@chelsio.com 
16717b36b6e0Skxie@chelsio.com free_cpls:
16727b36b6e0Skxie@chelsio.com 	cxgbi_sock_free_cpl_skbs(csk);
16737b36b6e0Skxie@chelsio.com 	return -ENOMEM;
16747b36b6e0Skxie@chelsio.com }
16757b36b6e0Skxie@chelsio.com 
l2t_put(struct cxgbi_sock * csk)16767b36b6e0Skxie@chelsio.com static inline void l2t_put(struct cxgbi_sock *csk)
16777b36b6e0Skxie@chelsio.com {
16787b36b6e0Skxie@chelsio.com 	if (csk->l2t) {
16797b36b6e0Skxie@chelsio.com 		cxgb4_l2t_release(csk->l2t);
16807b36b6e0Skxie@chelsio.com 		csk->l2t = NULL;
16817b36b6e0Skxie@chelsio.com 		cxgbi_sock_put(csk);
16827b36b6e0Skxie@chelsio.com 	}
16837b36b6e0Skxie@chelsio.com }
16847b36b6e0Skxie@chelsio.com 
release_offload_resources(struct cxgbi_sock * csk)16857b36b6e0Skxie@chelsio.com static void release_offload_resources(struct cxgbi_sock *csk)
16867b36b6e0Skxie@chelsio.com {
16877b36b6e0Skxie@chelsio.com 	struct cxgb4_lld_info *lldi;
1688211a84e3SAnish Bhatt #if IS_ENABLED(CONFIG_IPV6)
1689211a84e3SAnish Bhatt 	struct net_device *ndev = csk->cdev->ports[csk->port_id];
1690211a84e3SAnish Bhatt #endif
16917b36b6e0Skxie@chelsio.com 
16927b36b6e0Skxie@chelsio.com 	log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
16937b36b6e0Skxie@chelsio.com 		"csk 0x%p,%u,0x%lx,%u.\n",
16947b36b6e0Skxie@chelsio.com 		csk, csk->state, csk->flags, csk->tid);
16957b36b6e0Skxie@chelsio.com 
16967b36b6e0Skxie@chelsio.com 	cxgbi_sock_free_cpl_skbs(csk);
16979b3a081fSVarun Prakash 	cxgbi_sock_purge_write_queue(csk);
16987b36b6e0Skxie@chelsio.com 	if (csk->wr_cred != csk->wr_max_cred) {
16997b36b6e0Skxie@chelsio.com 		cxgbi_sock_purge_wr_queue(csk);
17007b36b6e0Skxie@chelsio.com 		cxgbi_sock_reset_wr_list(csk);
17017b36b6e0Skxie@chelsio.com 	}
17027b36b6e0Skxie@chelsio.com 
17037b36b6e0Skxie@chelsio.com 	l2t_put(csk);
1704211a84e3SAnish Bhatt #if IS_ENABLED(CONFIG_IPV6)
1705211a84e3SAnish Bhatt 	if (csk->csk_family == AF_INET6)
1706211a84e3SAnish Bhatt 		cxgb4_clip_release(ndev,
1707211a84e3SAnish Bhatt 				   (const u32 *)&csk->saddr6.sin6_addr, 1);
1708211a84e3SAnish Bhatt #endif
1709211a84e3SAnish Bhatt 
17107b36b6e0Skxie@chelsio.com 	if (cxgbi_sock_flag(csk, CTPF_HAS_ATID))
17117b36b6e0Skxie@chelsio.com 		free_atid(csk);
17127b36b6e0Skxie@chelsio.com 	else if (cxgbi_sock_flag(csk, CTPF_HAS_TID)) {
17137b36b6e0Skxie@chelsio.com 		lldi = cxgbi_cdev_priv(csk->cdev);
17141dec4cecSGanesh Goudar 		cxgb4_remove_tid(lldi->tids, 0, csk->tid,
17151dec4cecSGanesh Goudar 				 csk->csk_family);
17167b36b6e0Skxie@chelsio.com 		cxgbi_sock_clear_flag(csk, CTPF_HAS_TID);
17177b36b6e0Skxie@chelsio.com 		cxgbi_sock_put(csk);
17187b36b6e0Skxie@chelsio.com 	}
17197b36b6e0Skxie@chelsio.com 	csk->dst = NULL;
17207b36b6e0Skxie@chelsio.com }
17217b36b6e0Skxie@chelsio.com 
1722b5a5fe4eSVarun Prakash #ifdef CONFIG_CHELSIO_T4_DCB
get_iscsi_dcb_state(struct net_device * ndev)1723b5a5fe4eSVarun Prakash static inline u8 get_iscsi_dcb_state(struct net_device *ndev)
1724b5a5fe4eSVarun Prakash {
1725b5a5fe4eSVarun Prakash 	return ndev->dcbnl_ops->getstate(ndev);
1726b5a5fe4eSVarun Prakash }
1727b5a5fe4eSVarun Prakash 
select_priority(int pri_mask)1728b5a5fe4eSVarun Prakash static int select_priority(int pri_mask)
1729b5a5fe4eSVarun Prakash {
1730b5a5fe4eSVarun Prakash 	if (!pri_mask)
1731b5a5fe4eSVarun Prakash 		return 0;
1732b5a5fe4eSVarun Prakash 	return (ffs(pri_mask) - 1);
1733b5a5fe4eSVarun Prakash }
1734b5a5fe4eSVarun Prakash 
get_iscsi_dcb_priority(struct net_device * ndev)1735b5a5fe4eSVarun Prakash static u8 get_iscsi_dcb_priority(struct net_device *ndev)
1736b5a5fe4eSVarun Prakash {
1737b5a5fe4eSVarun Prakash 	int rv;
1738b5a5fe4eSVarun Prakash 	u8 caps;
1739b5a5fe4eSVarun Prakash 
1740b5a5fe4eSVarun Prakash 	struct dcb_app iscsi_dcb_app = {
1741b5a5fe4eSVarun Prakash 		.protocol = 3260
1742b5a5fe4eSVarun Prakash 	};
1743b5a5fe4eSVarun Prakash 
1744b5a5fe4eSVarun Prakash 	rv = (int)ndev->dcbnl_ops->getcap(ndev, DCB_CAP_ATTR_DCBX, &caps);
1745b5a5fe4eSVarun Prakash 	if (rv)
1746b5a5fe4eSVarun Prakash 		return 0;
1747b5a5fe4eSVarun Prakash 
1748b5a5fe4eSVarun Prakash 	if (caps & DCB_CAP_DCBX_VER_IEEE) {
1749152e30fcSVarun Prakash 		iscsi_dcb_app.selector = IEEE_8021QAZ_APP_SEL_STREAM;
1750152e30fcSVarun Prakash 		rv = dcb_ieee_getapp_mask(ndev, &iscsi_dcb_app);
1751152e30fcSVarun Prakash 		if (!rv) {
1752b5a5fe4eSVarun Prakash 			iscsi_dcb_app.selector = IEEE_8021QAZ_APP_SEL_ANY;
1753b5a5fe4eSVarun Prakash 			rv = dcb_ieee_getapp_mask(ndev, &iscsi_dcb_app);
1754152e30fcSVarun Prakash 		}
1755b5a5fe4eSVarun Prakash 	} else if (caps & DCB_CAP_DCBX_VER_CEE) {
1756b5a5fe4eSVarun Prakash 		iscsi_dcb_app.selector = DCB_APP_IDTYPE_PORTNUM;
1757b5a5fe4eSVarun Prakash 		rv = dcb_getapp(ndev, &iscsi_dcb_app);
1758b5a5fe4eSVarun Prakash 	}
1759b5a5fe4eSVarun Prakash 
1760b5a5fe4eSVarun Prakash 	log_debug(1 << CXGBI_DBG_ISCSI,
1761b5a5fe4eSVarun Prakash 		  "iSCSI priority is set to %u\n", select_priority(rv));
1762b5a5fe4eSVarun Prakash 	return select_priority(rv);
1763b5a5fe4eSVarun Prakash }
1764b5a5fe4eSVarun Prakash #endif
1765b5a5fe4eSVarun Prakash 
init_act_open(struct cxgbi_sock * csk)17667b36b6e0Skxie@chelsio.com static int init_act_open(struct cxgbi_sock *csk)
17677b36b6e0Skxie@chelsio.com {
17687b36b6e0Skxie@chelsio.com 	struct cxgbi_device *cdev = csk->cdev;
17697b36b6e0Skxie@chelsio.com 	struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(cdev);
17707b36b6e0Skxie@chelsio.com 	struct net_device *ndev = cdev->ports[csk->port_id];
17717b36b6e0Skxie@chelsio.com 	struct sk_buff *skb = NULL;
1772759a0cc5SAnish Bhatt 	struct neighbour *n = NULL;
1773759a0cc5SAnish Bhatt 	void *daddr;
17747b36b6e0Skxie@chelsio.com 	unsigned int step;
17756c9e2770SVarun Prakash 	unsigned int rxq_idx;
1776759a0cc5SAnish Bhatt 	unsigned int size, size6;
177781daf10cSKaren Xie 	unsigned int linkspeed;
177881daf10cSKaren Xie 	unsigned int rcv_winf, snd_winf;
1779b5a5fe4eSVarun Prakash #ifdef CONFIG_CHELSIO_T4_DCB
1780b5a5fe4eSVarun Prakash 	u8 priority = 0;
1781b5a5fe4eSVarun Prakash #endif
17827b36b6e0Skxie@chelsio.com 	log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
17837b36b6e0Skxie@chelsio.com 		"csk 0x%p,%u,0x%lx,%u.\n",
17847b36b6e0Skxie@chelsio.com 		csk, csk->state, csk->flags, csk->tid);
17857b36b6e0Skxie@chelsio.com 
1786759a0cc5SAnish Bhatt 	if (csk->csk_family == AF_INET)
1787759a0cc5SAnish Bhatt 		daddr = &csk->daddr.sin_addr.s_addr;
1788e81fbf6cSAnish Bhatt #if IS_ENABLED(CONFIG_IPV6)
1789e81fbf6cSAnish Bhatt 	else if (csk->csk_family == AF_INET6)
1790759a0cc5SAnish Bhatt 		daddr = &csk->daddr6.sin6_addr;
1791e81fbf6cSAnish Bhatt #endif
1792e81fbf6cSAnish Bhatt 	else {
1793e81fbf6cSAnish Bhatt 		pr_err("address family 0x%x not supported\n", csk->csk_family);
1794e81fbf6cSAnish Bhatt 		goto rel_resource;
1795e81fbf6cSAnish Bhatt 	}
1796759a0cc5SAnish Bhatt 
1797759a0cc5SAnish Bhatt 	n = dst_neigh_lookup(csk->dst, daddr);
1798759a0cc5SAnish Bhatt 
1799759a0cc5SAnish Bhatt 	if (!n) {
1800759a0cc5SAnish Bhatt 		pr_err("%s, can't get neighbour of csk->dst.\n", ndev->name);
1801759a0cc5SAnish Bhatt 		goto rel_resource;
1802759a0cc5SAnish Bhatt 	}
1803759a0cc5SAnish Bhatt 
180471eb2ac5SVarun Prakash 	if (!(n->nud_state & NUD_VALID))
180571eb2ac5SVarun Prakash 		neigh_event_send(n, NULL);
180671eb2ac5SVarun Prakash 
18077b36b6e0Skxie@chelsio.com 	csk->atid = cxgb4_alloc_atid(lldi->tids, csk);
18087b36b6e0Skxie@chelsio.com 	if (csk->atid < 0) {
18097b36b6e0Skxie@chelsio.com 		pr_err("%s, NO atid available.\n", ndev->name);
1810338be072SQuentin Lambert 		goto rel_resource_without_clip;
18117b36b6e0Skxie@chelsio.com 	}
18127b36b6e0Skxie@chelsio.com 	cxgbi_sock_set_flag(csk, CTPF_HAS_ATID);
18137b36b6e0Skxie@chelsio.com 	cxgbi_sock_get(csk);
18147b36b6e0Skxie@chelsio.com 
1815b5a5fe4eSVarun Prakash #ifdef CONFIG_CHELSIO_T4_DCB
1816b5a5fe4eSVarun Prakash 	if (get_iscsi_dcb_state(ndev))
1817b5a5fe4eSVarun Prakash 		priority = get_iscsi_dcb_priority(ndev);
1818b5a5fe4eSVarun Prakash 
1819b5a5fe4eSVarun Prakash 	csk->dcb_priority = priority;
1820b5a5fe4eSVarun Prakash 	csk->l2t = cxgb4_l2t_get(lldi->l2t, n, ndev, priority);
1821b5a5fe4eSVarun Prakash #else
182251e059bdSDavid Miller 	csk->l2t = cxgb4_l2t_get(lldi->l2t, n, ndev, 0);
1823b5a5fe4eSVarun Prakash #endif
18247b36b6e0Skxie@chelsio.com 	if (!csk->l2t) {
18257b36b6e0Skxie@chelsio.com 		pr_err("%s, cannot alloc l2t.\n", ndev->name);
1826211a84e3SAnish Bhatt 		goto rel_resource_without_clip;
18277b36b6e0Skxie@chelsio.com 	}
18287b36b6e0Skxie@chelsio.com 	cxgbi_sock_get(csk);
18297b36b6e0Skxie@chelsio.com 
1830211a84e3SAnish Bhatt #if IS_ENABLED(CONFIG_IPV6)
1831211a84e3SAnish Bhatt 	if (csk->csk_family == AF_INET6)
1832211a84e3SAnish Bhatt 		cxgb4_clip_get(ndev, (const u32 *)&csk->saddr6.sin6_addr, 1);
1833211a84e3SAnish Bhatt #endif
1834211a84e3SAnish Bhatt 
1835586be7cbSVarun Prakash 	if (is_t4(lldi->adapter_type)) {
1836759a0cc5SAnish Bhatt 		size = sizeof(struct cpl_act_open_req);
1837759a0cc5SAnish Bhatt 		size6 = sizeof(struct cpl_act_open_req6);
1838586be7cbSVarun Prakash 	} else if (is_t5(lldi->adapter_type)) {
1839759a0cc5SAnish Bhatt 		size = sizeof(struct cpl_t5_act_open_req);
1840759a0cc5SAnish Bhatt 		size6 = sizeof(struct cpl_t5_act_open_req6);
1841586be7cbSVarun Prakash 	} else {
1842586be7cbSVarun Prakash 		size = sizeof(struct cpl_t6_act_open_req);
1843586be7cbSVarun Prakash 		size6 = sizeof(struct cpl_t6_act_open_req6);
1844759a0cc5SAnish Bhatt 	}
1845759a0cc5SAnish Bhatt 
1846759a0cc5SAnish Bhatt 	if (csk->csk_family == AF_INET)
1847759a0cc5SAnish Bhatt 		skb = alloc_wr(size, 0, GFP_NOIO);
1848f42bb57cSAnish Bhatt #if IS_ENABLED(CONFIG_IPV6)
1849759a0cc5SAnish Bhatt 	else
1850759a0cc5SAnish Bhatt 		skb = alloc_wr(size6, 0, GFP_NOIO);
1851f42bb57cSAnish Bhatt #endif
1852759a0cc5SAnish Bhatt 
18537b36b6e0Skxie@chelsio.com 	if (!skb)
18547b36b6e0Skxie@chelsio.com 		goto rel_resource;
18557b36b6e0Skxie@chelsio.com 	skb->sk = (struct sock *)csk;
18567b36b6e0Skxie@chelsio.com 	t4_set_arp_err_handler(skb, csk, cxgbi_sock_act_open_req_arp_failure);
18577b36b6e0Skxie@chelsio.com 
18587b36b6e0Skxie@chelsio.com 	if (!csk->mtu)
18597b36b6e0Skxie@chelsio.com 		csk->mtu = dst_mtu(csk->dst);
18607b36b6e0Skxie@chelsio.com 	cxgb4_best_mtu(lldi->mtus, csk->mtu, &csk->mss_idx);
18617b36b6e0Skxie@chelsio.com 	csk->tx_chan = cxgb4_port_chan(ndev);
186202d805dcSSantosh Rastapur 	csk->smac_idx = ((struct port_info *)netdev_priv(ndev))->smt_idx;
18637b36b6e0Skxie@chelsio.com 	step = lldi->ntxq / lldi->nchan;
18647b36b6e0Skxie@chelsio.com 	csk->txq_idx = cxgb4_port_idx(ndev) * step;
18657b36b6e0Skxie@chelsio.com 	step = lldi->nrxq / lldi->nchan;
18666c9e2770SVarun Prakash 	rxq_idx = (cxgb4_port_idx(ndev) * step) + (cdev->rxq_idx_cntr % step);
18676c9e2770SVarun Prakash 	cdev->rxq_idx_cntr++;
18686c9e2770SVarun Prakash 	csk->rss_qid = lldi->rxq_ids[rxq_idx];
186981daf10cSKaren Xie 	linkspeed = ((struct port_info *)netdev_priv(ndev))->link_cfg.speed;
187081daf10cSKaren Xie 	csk->snd_win = cxgb4i_snd_win;
187181daf10cSKaren Xie 	csk->rcv_win = cxgb4i_rcv_win;
187281daf10cSKaren Xie 	if (cxgb4i_rcv_win <= 0) {
187381daf10cSKaren Xie 		csk->rcv_win = CXGB4I_DEFAULT_10G_RCV_WIN;
187481daf10cSKaren Xie 		rcv_winf = linkspeed / SPEED_10000;
187581daf10cSKaren Xie 		if (rcv_winf)
187681daf10cSKaren Xie 			csk->rcv_win *= rcv_winf;
187781daf10cSKaren Xie 	}
187881daf10cSKaren Xie 	if (cxgb4i_snd_win <= 0) {
187981daf10cSKaren Xie 		csk->snd_win = CXGB4I_DEFAULT_10G_SND_WIN;
188081daf10cSKaren Xie 		snd_winf = linkspeed / SPEED_10000;
188181daf10cSKaren Xie 		if (snd_winf)
188281daf10cSKaren Xie 			csk->snd_win *= snd_winf;
188381daf10cSKaren Xie 	}
1884759a0cc5SAnish Bhatt 	csk->wr_cred = lldi->wr_cred -
1885759a0cc5SAnish Bhatt 		       DIV_ROUND_UP(sizeof(struct cpl_abort_req), 16);
1886759a0cc5SAnish Bhatt 	csk->wr_max_cred = csk->wr_cred;
18877b36b6e0Skxie@chelsio.com 	csk->wr_una_cred = 0;
18887b36b6e0Skxie@chelsio.com 	cxgbi_sock_reset_wr_list(csk);
18897b36b6e0Skxie@chelsio.com 	csk->err = 0;
18907b36b6e0Skxie@chelsio.com 
1891759a0cc5SAnish Bhatt 	pr_info_ipaddr("csk 0x%p,%u,0x%lx,%u,%u,%u, mtu %u,%u, smac %u.\n",
1892759a0cc5SAnish Bhatt 		       (&csk->saddr), (&csk->daddr), csk, csk->state,
1893759a0cc5SAnish Bhatt 		       csk->flags, csk->tx_chan, csk->txq_idx, csk->rss_qid,
1894759a0cc5SAnish Bhatt 		       csk->mtu, csk->mss_idx, csk->smac_idx);
1895759a0cc5SAnish Bhatt 
1896759a0cc5SAnish Bhatt 	/* must wait for either a act_open_rpl or act_open_establish */
18971fe1fdb0SVarun Prakash 	if (!try_module_get(cdev->owner)) {
18981fe1fdb0SVarun Prakash 		pr_err("%s, try_module_get failed.\n", ndev->name);
18991fe1fdb0SVarun Prakash 		goto rel_resource;
19001fe1fdb0SVarun Prakash 	}
19011fe1fdb0SVarun Prakash 
19027b36b6e0Skxie@chelsio.com 	cxgbi_sock_set_state(csk, CTP_ACTIVE_OPEN);
1903759a0cc5SAnish Bhatt 	if (csk->csk_family == AF_INET)
19047b36b6e0Skxie@chelsio.com 		send_act_open_req(csk, skb, csk->l2t);
1905f42bb57cSAnish Bhatt #if IS_ENABLED(CONFIG_IPV6)
1906759a0cc5SAnish Bhatt 	else
1907759a0cc5SAnish Bhatt 		send_act_open_req6(csk, skb, csk->l2t);
1908f42bb57cSAnish Bhatt #endif
1909c4737377SDavid S. Miller 	neigh_release(n);
1910759a0cc5SAnish Bhatt 
19117b36b6e0Skxie@chelsio.com 	return 0;
19127b36b6e0Skxie@chelsio.com 
19137b36b6e0Skxie@chelsio.com rel_resource:
1914211a84e3SAnish Bhatt #if IS_ENABLED(CONFIG_IPV6)
1915211a84e3SAnish Bhatt 	if (csk->csk_family == AF_INET6)
1916211a84e3SAnish Bhatt 		cxgb4_clip_release(ndev,
1917211a84e3SAnish Bhatt 				   (const u32 *)&csk->saddr6.sin6_addr, 1);
1918211a84e3SAnish Bhatt #endif
1919211a84e3SAnish Bhatt rel_resource_without_clip:
1920c4737377SDavid S. Miller 	if (n)
1921c4737377SDavid S. Miller 		neigh_release(n);
19227b36b6e0Skxie@chelsio.com 	if (skb)
19237b36b6e0Skxie@chelsio.com 		__kfree_skb(skb);
19247b36b6e0Skxie@chelsio.com 	return -EINVAL;
19257b36b6e0Skxie@chelsio.com }
19267b36b6e0Skxie@chelsio.com 
19274665bdd5SVarun Prakash static cxgb4i_cplhandler_func cxgb4i_cplhandlers[NUM_CPL_CMDS] = {
19287b36b6e0Skxie@chelsio.com 	[CPL_ACT_ESTABLISH] = do_act_establish,
19297b36b6e0Skxie@chelsio.com 	[CPL_ACT_OPEN_RPL] = do_act_open_rpl,
19307b36b6e0Skxie@chelsio.com 	[CPL_PEER_CLOSE] = do_peer_close,
19317b36b6e0Skxie@chelsio.com 	[CPL_ABORT_REQ_RSS] = do_abort_req_rss,
19327b36b6e0Skxie@chelsio.com 	[CPL_ABORT_RPL_RSS] = do_abort_rpl_rss,
19337b36b6e0Skxie@chelsio.com 	[CPL_CLOSE_CON_RPL] = do_close_con_rpl,
19347b36b6e0Skxie@chelsio.com 	[CPL_FW4_ACK] = do_fw4_ack,
19357b36b6e0Skxie@chelsio.com 	[CPL_ISCSI_HDR] = do_rx_iscsi_hdr,
193644830d8fSVarun Prakash 	[CPL_ISCSI_DATA] = do_rx_iscsi_data,
19377b36b6e0Skxie@chelsio.com 	[CPL_SET_TCB_RPL] = do_set_tcb_rpl,
19387b36b6e0Skxie@chelsio.com 	[CPL_RX_DATA_DDP] = do_rx_data_ddp,
19393bd3e8bfSKaren Xie 	[CPL_RX_ISCSI_DDP] = do_rx_data_ddp,
194044830d8fSVarun Prakash 	[CPL_RX_ISCSI_CMP] = do_rx_iscsi_cmp,
1941f7bcd2e1SKaren Xie 	[CPL_RX_DATA] = do_rx_data,
19427b36b6e0Skxie@chelsio.com };
19437b36b6e0Skxie@chelsio.com 
cxgb4i_ofld_init(struct cxgbi_device * cdev)19444665bdd5SVarun Prakash static int cxgb4i_ofld_init(struct cxgbi_device *cdev)
19457b36b6e0Skxie@chelsio.com {
19467b36b6e0Skxie@chelsio.com 	int rc;
19477b36b6e0Skxie@chelsio.com 
19487b36b6e0Skxie@chelsio.com 	if (cxgb4i_max_connect > CXGB4I_MAX_CONN)
19497b36b6e0Skxie@chelsio.com 		cxgb4i_max_connect = CXGB4I_MAX_CONN;
19507b36b6e0Skxie@chelsio.com 
19517b36b6e0Skxie@chelsio.com 	rc = cxgbi_device_portmap_create(cdev, cxgb4i_sport_base,
19527b36b6e0Skxie@chelsio.com 					cxgb4i_max_connect);
19537b36b6e0Skxie@chelsio.com 	if (rc < 0)
19547b36b6e0Skxie@chelsio.com 		return rc;
19557b36b6e0Skxie@chelsio.com 
19567b36b6e0Skxie@chelsio.com 	cdev->csk_release_offload_resources = release_offload_resources;
19577b36b6e0Skxie@chelsio.com 	cdev->csk_push_tx_frames = push_tx_frames;
19587b36b6e0Skxie@chelsio.com 	cdev->csk_send_abort_req = send_abort_req;
19597b36b6e0Skxie@chelsio.com 	cdev->csk_send_close_req = send_close_req;
19607b36b6e0Skxie@chelsio.com 	cdev->csk_send_rx_credits = send_rx_credits;
19617b36b6e0Skxie@chelsio.com 	cdev->csk_alloc_cpls = alloc_cpls;
19627b36b6e0Skxie@chelsio.com 	cdev->csk_init_act_open = init_act_open;
19637b36b6e0Skxie@chelsio.com 
19647b36b6e0Skxie@chelsio.com 	pr_info("cdev 0x%p, offload up, added.\n", cdev);
19657b36b6e0Skxie@chelsio.com 	return 0;
19667b36b6e0Skxie@chelsio.com }
19677b36b6e0Skxie@chelsio.com 
196871f7a00bSVarun Prakash static inline void
ulp_mem_io_set_hdr(struct cxgbi_device * cdev,struct ulp_mem_io * req,unsigned int wr_len,unsigned int dlen,unsigned int pm_addr,int tid)196971f7a00bSVarun Prakash ulp_mem_io_set_hdr(struct cxgbi_device *cdev,
197071f7a00bSVarun Prakash 		   struct ulp_mem_io *req,
197171f7a00bSVarun Prakash 		   unsigned int wr_len, unsigned int dlen,
197271f7a00bSVarun Prakash 		   unsigned int pm_addr,
197371f7a00bSVarun Prakash 		   int tid)
197471f7a00bSVarun Prakash {
197571f7a00bSVarun Prakash 	struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(cdev);
197671f7a00bSVarun Prakash 	struct ulptx_idata *idata = (struct ulptx_idata *)(req + 1);
197771f7a00bSVarun Prakash 
197871f7a00bSVarun Prakash 	INIT_ULPTX_WR(req, wr_len, 0, tid);
197971f7a00bSVarun Prakash 	req->wr.wr_hi = htonl(FW_WR_OP_V(FW_ULPTX_WR) |
198071f7a00bSVarun Prakash 		FW_WR_ATOMIC_V(0));
198171f7a00bSVarun Prakash 	req->cmd = htonl(ULPTX_CMD_V(ULP_TX_MEM_WRITE) |
198271f7a00bSVarun Prakash 		ULP_MEMIO_ORDER_V(is_t4(lldi->adapter_type)) |
198371f7a00bSVarun Prakash 		T5_ULP_MEMIO_IMM_V(!is_t4(lldi->adapter_type)));
198471f7a00bSVarun Prakash 	req->dlen = htonl(ULP_MEMIO_DATA_LEN_V(dlen >> 5));
198571f7a00bSVarun Prakash 	req->lock_addr = htonl(ULP_MEMIO_ADDR_V(pm_addr >> 5));
198671f7a00bSVarun Prakash 	req->len16 = htonl(DIV_ROUND_UP(wr_len - sizeof(req->wr), 16));
198771f7a00bSVarun Prakash 
198871f7a00bSVarun Prakash 	idata->cmd_more = htonl(ULPTX_CMD_V(ULP_TX_SC_IMM));
198971f7a00bSVarun Prakash 	idata->len = htonl(dlen);
199071f7a00bSVarun Prakash }
199171f7a00bSVarun Prakash 
199271f7a00bSVarun Prakash static struct sk_buff *
ddp_ppod_init_idata(struct cxgbi_device * cdev,struct cxgbi_ppm * ppm,unsigned int idx,unsigned int npods,unsigned int tid)199371f7a00bSVarun Prakash ddp_ppod_init_idata(struct cxgbi_device *cdev,
199471f7a00bSVarun Prakash 		    struct cxgbi_ppm *ppm,
199571f7a00bSVarun Prakash 		    unsigned int idx, unsigned int npods,
199671f7a00bSVarun Prakash 		    unsigned int tid)
199771f7a00bSVarun Prakash {
199871f7a00bSVarun Prakash 	unsigned int pm_addr = (idx << PPOD_SIZE_SHIFT) + ppm->llimit;
199971f7a00bSVarun Prakash 	unsigned int dlen = npods << PPOD_SIZE_SHIFT;
200071f7a00bSVarun Prakash 	unsigned int wr_len = roundup(sizeof(struct ulp_mem_io) +
200171f7a00bSVarun Prakash 				sizeof(struct ulptx_idata) + dlen, 16);
200271f7a00bSVarun Prakash 	struct sk_buff *skb = alloc_wr(wr_len, 0, GFP_ATOMIC);
200371f7a00bSVarun Prakash 
200471f7a00bSVarun Prakash 	if (!skb) {
200571f7a00bSVarun Prakash 		pr_err("%s: %s idx %u, npods %u, OOM.\n",
200671f7a00bSVarun Prakash 		       __func__, ppm->ndev->name, idx, npods);
200771f7a00bSVarun Prakash 		return NULL;
200871f7a00bSVarun Prakash 	}
200971f7a00bSVarun Prakash 
201071f7a00bSVarun Prakash 	ulp_mem_io_set_hdr(cdev, (struct ulp_mem_io *)skb->head, wr_len, dlen,
201171f7a00bSVarun Prakash 			   pm_addr, tid);
201271f7a00bSVarun Prakash 
201371f7a00bSVarun Prakash 	return skb;
201471f7a00bSVarun Prakash }
201571f7a00bSVarun Prakash 
ddp_ppod_write_idata(struct cxgbi_ppm * ppm,struct cxgbi_sock * csk,struct cxgbi_task_tag_info * ttinfo,unsigned int idx,unsigned int npods,struct scatterlist ** sg_pp,unsigned int * sg_off)201671f7a00bSVarun Prakash static int ddp_ppod_write_idata(struct cxgbi_ppm *ppm, struct cxgbi_sock *csk,
201771f7a00bSVarun Prakash 				struct cxgbi_task_tag_info *ttinfo,
201871f7a00bSVarun Prakash 				unsigned int idx, unsigned int npods,
201971f7a00bSVarun Prakash 				struct scatterlist **sg_pp,
202071f7a00bSVarun Prakash 				unsigned int *sg_off)
202171f7a00bSVarun Prakash {
202271f7a00bSVarun Prakash 	struct cxgbi_device *cdev = csk->cdev;
202371f7a00bSVarun Prakash 	struct sk_buff *skb = ddp_ppod_init_idata(cdev, ppm, idx, npods,
202471f7a00bSVarun Prakash 						  csk->tid);
202571f7a00bSVarun Prakash 	struct ulp_mem_io *req;
202671f7a00bSVarun Prakash 	struct ulptx_idata *idata;
202771f7a00bSVarun Prakash 	struct cxgbi_pagepod *ppod;
202871f7a00bSVarun Prakash 	int i;
202971f7a00bSVarun Prakash 
203071f7a00bSVarun Prakash 	if (!skb)
203171f7a00bSVarun Prakash 		return -ENOMEM;
203271f7a00bSVarun Prakash 
203371f7a00bSVarun Prakash 	req = (struct ulp_mem_io *)skb->head;
203471f7a00bSVarun Prakash 	idata = (struct ulptx_idata *)(req + 1);
203571f7a00bSVarun Prakash 	ppod = (struct cxgbi_pagepod *)(idata + 1);
203671f7a00bSVarun Prakash 
203771f7a00bSVarun Prakash 	for (i = 0; i < npods; i++, ppod++)
203871f7a00bSVarun Prakash 		cxgbi_ddp_set_one_ppod(ppod, ttinfo, sg_pp, sg_off);
203971f7a00bSVarun Prakash 
204071f7a00bSVarun Prakash 	cxgbi_skcb_set_flag(skb, SKCBF_TX_MEM_WRITE);
204171f7a00bSVarun Prakash 	cxgbi_skcb_set_flag(skb, SKCBF_TX_FLAG_COMPL);
204271f7a00bSVarun Prakash 	set_wr_txq(skb, CPL_PRIORITY_DATA, csk->port_id);
204371f7a00bSVarun Prakash 
204471f7a00bSVarun Prakash 	spin_lock_bh(&csk->lock);
204571f7a00bSVarun Prakash 	cxgbi_sock_skb_entail(csk, skb);
204671f7a00bSVarun Prakash 	spin_unlock_bh(&csk->lock);
204771f7a00bSVarun Prakash 
204871f7a00bSVarun Prakash 	return 0;
204971f7a00bSVarun Prakash }
205071f7a00bSVarun Prakash 
ddp_set_map(struct cxgbi_ppm * ppm,struct cxgbi_sock * csk,struct cxgbi_task_tag_info * ttinfo)205171f7a00bSVarun Prakash static int ddp_set_map(struct cxgbi_ppm *ppm, struct cxgbi_sock *csk,
205271f7a00bSVarun Prakash 		       struct cxgbi_task_tag_info *ttinfo)
205371f7a00bSVarun Prakash {
205471f7a00bSVarun Prakash 	unsigned int pidx = ttinfo->idx;
205571f7a00bSVarun Prakash 	unsigned int npods = ttinfo->npods;
205671f7a00bSVarun Prakash 	unsigned int i, cnt;
205771f7a00bSVarun Prakash 	int err = 0;
205871f7a00bSVarun Prakash 	struct scatterlist *sg = ttinfo->sgl;
205971f7a00bSVarun Prakash 	unsigned int offset = 0;
206071f7a00bSVarun Prakash 
206171f7a00bSVarun Prakash 	ttinfo->cid = csk->port_id;
206271f7a00bSVarun Prakash 
206371f7a00bSVarun Prakash 	for (i = 0; i < npods; i += cnt, pidx += cnt) {
206471f7a00bSVarun Prakash 		cnt = npods - i;
206571f7a00bSVarun Prakash 
206671f7a00bSVarun Prakash 		if (cnt > ULPMEM_IDATA_MAX_NPPODS)
206771f7a00bSVarun Prakash 			cnt = ULPMEM_IDATA_MAX_NPPODS;
206871f7a00bSVarun Prakash 		err = ddp_ppod_write_idata(ppm, csk, ttinfo, pidx, cnt,
206971f7a00bSVarun Prakash 					   &sg, &offset);
207071f7a00bSVarun Prakash 		if (err < 0)
207171f7a00bSVarun Prakash 			break;
207271f7a00bSVarun Prakash 	}
207371f7a00bSVarun Prakash 
207471f7a00bSVarun Prakash 	return err;
207571f7a00bSVarun Prakash }
207671f7a00bSVarun Prakash 
ddp_setup_conn_pgidx(struct cxgbi_sock * csk,unsigned int tid,int pg_idx)20777b36b6e0Skxie@chelsio.com static int ddp_setup_conn_pgidx(struct cxgbi_sock *csk, unsigned int tid,
20789e8f1c79SVarun Prakash 				int pg_idx)
20797b36b6e0Skxie@chelsio.com {
20807b36b6e0Skxie@chelsio.com 	struct sk_buff *skb;
20817b36b6e0Skxie@chelsio.com 	struct cpl_set_tcb_field *req;
20827b36b6e0Skxie@chelsio.com 
2083e27d6169Skxie@chelsio.com 	if (!pg_idx || pg_idx >= DDP_PGIDX_MAX)
20847b36b6e0Skxie@chelsio.com 		return 0;
20857b36b6e0Skxie@chelsio.com 
208624d3f95aSkxie@chelsio.com 	skb = alloc_wr(sizeof(*req), 0, GFP_KERNEL);
20877b36b6e0Skxie@chelsio.com 	if (!skb)
20887b36b6e0Skxie@chelsio.com 		return -ENOMEM;
20897b36b6e0Skxie@chelsio.com 
2090e27d6169Skxie@chelsio.com 	/*  set up ulp page size */
20917b36b6e0Skxie@chelsio.com 	req = (struct cpl_set_tcb_field *)skb->head;
20927b36b6e0Skxie@chelsio.com 	INIT_TP_WR(req, csk->tid);
20937b36b6e0Skxie@chelsio.com 	OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_SET_TCB_FIELD, csk->tid));
20949e8f1c79SVarun Prakash 	req->reply_ctrl = htons(NO_REPLY_V(0) | QUEUENO_V(csk->rss_qid));
2095e27d6169Skxie@chelsio.com 	req->word_cookie = htons(0);
2096e27d6169Skxie@chelsio.com 	req->mask = cpu_to_be64(0x3 << 8);
2097e27d6169Skxie@chelsio.com 	req->val = cpu_to_be64(pg_idx << 8);
20987b36b6e0Skxie@chelsio.com 	set_wr_txq(skb, CPL_PRIORITY_CONTROL, csk->port_id);
20997b36b6e0Skxie@chelsio.com 
21007b36b6e0Skxie@chelsio.com 	log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
21017b36b6e0Skxie@chelsio.com 		"csk 0x%p, tid 0x%x, pg_idx %u.\n", csk, csk->tid, pg_idx);
21027b36b6e0Skxie@chelsio.com 
21039e8f1c79SVarun Prakash 	reinit_completion(&csk->cmpl);
21047b36b6e0Skxie@chelsio.com 	cxgb4_ofld_send(csk->cdev->ports[csk->port_id], skb);
21059e8f1c79SVarun Prakash 	wait_for_completion(&csk->cmpl);
21069e8f1c79SVarun Prakash 
21079e8f1c79SVarun Prakash 	return csk->err;
21087b36b6e0Skxie@chelsio.com }
21097b36b6e0Skxie@chelsio.com 
ddp_setup_conn_digest(struct cxgbi_sock * csk,unsigned int tid,int hcrc,int dcrc)21107b36b6e0Skxie@chelsio.com static int ddp_setup_conn_digest(struct cxgbi_sock *csk, unsigned int tid,
21119e8f1c79SVarun Prakash 				 int hcrc, int dcrc)
21127b36b6e0Skxie@chelsio.com {
21137b36b6e0Skxie@chelsio.com 	struct sk_buff *skb;
21147b36b6e0Skxie@chelsio.com 	struct cpl_set_tcb_field *req;
21157b36b6e0Skxie@chelsio.com 
2116e27d6169Skxie@chelsio.com 	if (!hcrc && !dcrc)
2117e27d6169Skxie@chelsio.com 		return 0;
21187b36b6e0Skxie@chelsio.com 
211924d3f95aSkxie@chelsio.com 	skb = alloc_wr(sizeof(*req), 0, GFP_KERNEL);
21207b36b6e0Skxie@chelsio.com 	if (!skb)
21217b36b6e0Skxie@chelsio.com 		return -ENOMEM;
21227b36b6e0Skxie@chelsio.com 
21237b36b6e0Skxie@chelsio.com 	csk->hcrc_len = (hcrc ? 4 : 0);
21247b36b6e0Skxie@chelsio.com 	csk->dcrc_len = (dcrc ? 4 : 0);
2125e27d6169Skxie@chelsio.com 	/*  set up ulp submode */
21267b36b6e0Skxie@chelsio.com 	req = (struct cpl_set_tcb_field *)skb->head;
21277b36b6e0Skxie@chelsio.com 	INIT_TP_WR(req, tid);
21287b36b6e0Skxie@chelsio.com 	OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_SET_TCB_FIELD, tid));
21299e8f1c79SVarun Prakash 	req->reply_ctrl = htons(NO_REPLY_V(0) | QUEUENO_V(csk->rss_qid));
2130e27d6169Skxie@chelsio.com 	req->word_cookie = htons(0);
2131e27d6169Skxie@chelsio.com 	req->mask = cpu_to_be64(0x3 << 4);
2132e27d6169Skxie@chelsio.com 	req->val = cpu_to_be64(((hcrc ? ULP_CRC_HEADER : 0) |
2133e27d6169Skxie@chelsio.com 				(dcrc ? ULP_CRC_DATA : 0)) << 4);
21347b36b6e0Skxie@chelsio.com 	set_wr_txq(skb, CPL_PRIORITY_CONTROL, csk->port_id);
21357b36b6e0Skxie@chelsio.com 
21367b36b6e0Skxie@chelsio.com 	log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
21377b36b6e0Skxie@chelsio.com 		"csk 0x%p, tid 0x%x, crc %d,%d.\n", csk, csk->tid, hcrc, dcrc);
21387b36b6e0Skxie@chelsio.com 
21399e8f1c79SVarun Prakash 	reinit_completion(&csk->cmpl);
21407b36b6e0Skxie@chelsio.com 	cxgb4_ofld_send(csk->cdev->ports[csk->port_id], skb);
21419e8f1c79SVarun Prakash 	wait_for_completion(&csk->cmpl);
21429e8f1c79SVarun Prakash 
21439e8f1c79SVarun Prakash 	return csk->err;
21447b36b6e0Skxie@chelsio.com }
21457b36b6e0Skxie@chelsio.com 
cdev2ppm(struct cxgbi_device * cdev)214671f7a00bSVarun Prakash static struct cxgbi_ppm *cdev2ppm(struct cxgbi_device *cdev)
214771f7a00bSVarun Prakash {
214871f7a00bSVarun Prakash 	return (struct cxgbi_ppm *)(*((struct cxgb4_lld_info *)
214971f7a00bSVarun Prakash 				       (cxgbi_cdev_priv(cdev)))->iscsi_ppm);
215071f7a00bSVarun Prakash }
215171f7a00bSVarun Prakash 
cxgb4i_ddp_init(struct cxgbi_device * cdev)21527b36b6e0Skxie@chelsio.com static int cxgb4i_ddp_init(struct cxgbi_device *cdev)
21537b36b6e0Skxie@chelsio.com {
215471f7a00bSVarun Prakash 	struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(cdev);
215571f7a00bSVarun Prakash 	struct net_device *ndev = cdev->ports[0];
215671f7a00bSVarun Prakash 	struct cxgbi_tag_format tformat;
2157a248384eSVarun Prakash 	int i, err;
215871f7a00bSVarun Prakash 
215971f7a00bSVarun Prakash 	if (!lldi->vr->iscsi.size) {
216071f7a00bSVarun Prakash 		pr_warn("%s, iscsi NOT enabled, check config!\n", ndev->name);
216171f7a00bSVarun Prakash 		return -EACCES;
216271f7a00bSVarun Prakash 	}
216371f7a00bSVarun Prakash 
216471f7a00bSVarun Prakash 	cdev->flags |= CXGBI_FLAG_USE_PPOD_OFLDQ;
216571f7a00bSVarun Prakash 
216671f7a00bSVarun Prakash 	memset(&tformat, 0, sizeof(struct cxgbi_tag_format));
216771f7a00bSVarun Prakash 	for (i = 0; i < 4; i++)
216871f7a00bSVarun Prakash 		tformat.pgsz_order[i] = (lldi->iscsi_pgsz_order >> (i << 3))
216971f7a00bSVarun Prakash 					 & 0xF;
217071f7a00bSVarun Prakash 	cxgbi_tagmask_check(lldi->iscsi_tagmask, &tformat);
217171f7a00bSVarun Prakash 
2172a248384eSVarun Prakash 	pr_info("iscsi_edram.start 0x%x iscsi_edram.size 0x%x",
2173a248384eSVarun Prakash 		lldi->vr->ppod_edram.start, lldi->vr->ppod_edram.size);
2174a248384eSVarun Prakash 
2175a248384eSVarun Prakash 	err = cxgbi_ddp_ppm_setup(lldi->iscsi_ppm, cdev, &tformat,
2176a248384eSVarun Prakash 				  lldi->vr->iscsi.size, lldi->iscsi_llimit,
2177a248384eSVarun Prakash 				  lldi->vr->iscsi.start, 2,
2178a248384eSVarun Prakash 				  lldi->vr->ppod_edram.start,
2179a248384eSVarun Prakash 				  lldi->vr->ppod_edram.size);
2180a248384eSVarun Prakash 
2181a248384eSVarun Prakash 	if (err < 0)
2182a248384eSVarun Prakash 		return err;
218371f7a00bSVarun Prakash 
21847b36b6e0Skxie@chelsio.com 	cdev->csk_ddp_setup_digest = ddp_setup_conn_digest;
21857b36b6e0Skxie@chelsio.com 	cdev->csk_ddp_setup_pgidx = ddp_setup_conn_pgidx;
218671f7a00bSVarun Prakash 	cdev->csk_ddp_set_map = ddp_set_map;
218771f7a00bSVarun Prakash 	cdev->tx_max_size = min_t(unsigned int, ULP2_MAX_PDU_PAYLOAD,
218871f7a00bSVarun Prakash 				  lldi->iscsi_iolen - ISCSI_PDU_NONPAYLOAD_LEN);
218971f7a00bSVarun Prakash 	cdev->rx_max_size = min_t(unsigned int, ULP2_MAX_PDU_PAYLOAD,
219071f7a00bSVarun Prakash 				  lldi->iscsi_iolen - ISCSI_PDU_NONPAYLOAD_LEN);
219171f7a00bSVarun Prakash 	cdev->cdev2ppm = cdev2ppm;
219271f7a00bSVarun Prakash 
21937b36b6e0Skxie@chelsio.com 	return 0;
21947b36b6e0Skxie@chelsio.com }
21957b36b6e0Skxie@chelsio.com 
is_memfree(struct adapter * adap)2196e33c2482SVarun Prakash static bool is_memfree(struct adapter *adap)
2197e33c2482SVarun Prakash {
2198e33c2482SVarun Prakash 	u32 io;
2199e33c2482SVarun Prakash 
2200e33c2482SVarun Prakash 	io = t4_read_reg(adap, MA_TARGET_MEM_ENABLE_A);
2201e33c2482SVarun Prakash 	if (is_t5(adap->params.chip)) {
2202e33c2482SVarun Prakash 		if ((io & EXT_MEM0_ENABLE_F) || (io & EXT_MEM1_ENABLE_F))
2203e33c2482SVarun Prakash 			return false;
2204e33c2482SVarun Prakash 	} else if (io & EXT_MEM_ENABLE_F) {
2205e33c2482SVarun Prakash 		return false;
2206e33c2482SVarun Prakash 	}
2207e33c2482SVarun Prakash 
2208e33c2482SVarun Prakash 	return true;
2209e33c2482SVarun Prakash }
2210e33c2482SVarun Prakash 
t4_uld_add(const struct cxgb4_lld_info * lldi)22117b36b6e0Skxie@chelsio.com static void *t4_uld_add(const struct cxgb4_lld_info *lldi)
22127b36b6e0Skxie@chelsio.com {
22137b36b6e0Skxie@chelsio.com 	struct cxgbi_device *cdev;
22147b36b6e0Skxie@chelsio.com 	struct port_info *pi;
2215e33c2482SVarun Prakash 	struct net_device *ndev;
2216e33c2482SVarun Prakash 	struct adapter *adap;
2217e33c2482SVarun Prakash 	struct tid_info *t;
2218e33c2482SVarun Prakash 	u32 max_cmds = CXGB4I_SCSI_HOST_QDEPTH;
2219e33c2482SVarun Prakash 	u32 max_conn = CXGBI_MAX_CONN;
22207b36b6e0Skxie@chelsio.com 	int i, rc;
22217b36b6e0Skxie@chelsio.com 
22227b36b6e0Skxie@chelsio.com 	cdev = cxgbi_device_register(sizeof(*lldi), lldi->nports);
22237b36b6e0Skxie@chelsio.com 	if (!cdev) {
22247b36b6e0Skxie@chelsio.com 		pr_info("t4 device 0x%p, register failed.\n", lldi);
22257b36b6e0Skxie@chelsio.com 		return NULL;
22267b36b6e0Skxie@chelsio.com 	}
22277b36b6e0Skxie@chelsio.com 	pr_info("0x%p,0x%x, ports %u,%s, chan %u, q %u,%u, wr %u.\n",
22287b36b6e0Skxie@chelsio.com 		cdev, lldi->adapter_type, lldi->nports,
22297b36b6e0Skxie@chelsio.com 		lldi->ports[0]->name, lldi->nchan, lldi->ntxq,
22307b36b6e0Skxie@chelsio.com 		lldi->nrxq, lldi->wr_cred);
22317b36b6e0Skxie@chelsio.com 	for (i = 0; i < lldi->nrxq; i++)
22327b36b6e0Skxie@chelsio.com 		log_debug(1 << CXGBI_DBG_DEV,
22337b36b6e0Skxie@chelsio.com 			"t4 0x%p, rxq id #%d: %u.\n",
22347b36b6e0Skxie@chelsio.com 			cdev, i, lldi->rxq_ids[i]);
22357b36b6e0Skxie@chelsio.com 
22367b36b6e0Skxie@chelsio.com 	memcpy(cxgbi_cdev_priv(cdev), lldi, sizeof(*lldi));
22377b36b6e0Skxie@chelsio.com 	cdev->flags = CXGBI_FLAG_DEV_T4;
22387b36b6e0Skxie@chelsio.com 	cdev->pdev = lldi->pdev;
22397b36b6e0Skxie@chelsio.com 	cdev->ports = lldi->ports;
22407b36b6e0Skxie@chelsio.com 	cdev->nports = lldi->nports;
22417b36b6e0Skxie@chelsio.com 	cdev->mtus = lldi->mtus;
22427b36b6e0Skxie@chelsio.com 	cdev->nmtus = NMTUS;
2243586be7cbSVarun Prakash 	cdev->rx_credit_thres = (CHELSIO_CHIP_VERSION(lldi->adapter_type) <=
2244586be7cbSVarun Prakash 				 CHELSIO_T5) ? cxgb4i_rx_credit_thres : 0;
22457b36b6e0Skxie@chelsio.com 	cdev->skb_tx_rsvd = CXGB4I_TX_HEADER_LEN;
22467b36b6e0Skxie@chelsio.com 	cdev->skb_rx_extra = sizeof(struct cpl_iscsi_hdr);
22477b36b6e0Skxie@chelsio.com 	cdev->itp = &cxgb4i_iscsi_transport;
22481fe1fdb0SVarun Prakash 	cdev->owner = THIS_MODULE;
22497b36b6e0Skxie@chelsio.com 
2250b184487cSVarun Prakash 	cdev->pfvf = FW_PFVF_CMD_PFN_V(lldi->pf);
2251e27d6169Skxie@chelsio.com 	pr_info("cdev 0x%p,%s, pfvf %u.\n",
2252e27d6169Skxie@chelsio.com 		cdev, lldi->ports[0]->name, cdev->pfvf);
2253e27d6169Skxie@chelsio.com 
22547b36b6e0Skxie@chelsio.com 	rc = cxgb4i_ddp_init(cdev);
22557b36b6e0Skxie@chelsio.com 	if (rc) {
2256a248384eSVarun Prakash 		pr_info("t4 0x%p ddp init failed %d.\n", cdev, rc);
22577b36b6e0Skxie@chelsio.com 		goto err_out;
22587b36b6e0Skxie@chelsio.com 	}
2259e33c2482SVarun Prakash 
2260e33c2482SVarun Prakash 	ndev = cdev->ports[0];
2261e33c2482SVarun Prakash 	adap = netdev2adap(ndev);
2262e33c2482SVarun Prakash 	if (adap) {
2263e33c2482SVarun Prakash 		t = &adap->tids;
2264e33c2482SVarun Prakash 		if (t->ntids <= CXGBI_MAX_CONN)
2265e33c2482SVarun Prakash 			max_conn = t->ntids;
2266e33c2482SVarun Prakash 
2267e33c2482SVarun Prakash 		if (is_memfree(adap)) {
2268e33c2482SVarun Prakash 			cdev->flags |=	CXGBI_FLAG_DEV_ISO_OFF;
2269e33c2482SVarun Prakash 			max_cmds = CXGB4I_SCSI_HOST_QDEPTH >> 2;
2270e33c2482SVarun Prakash 
2271e33c2482SVarun Prakash 			pr_info("%s: 0x%p, tid %u, SO adapter.\n",
2272e33c2482SVarun Prakash 				ndev->name, cdev, t->ntids);
2273e33c2482SVarun Prakash 		}
2274e33c2482SVarun Prakash 	} else {
2275e33c2482SVarun Prakash 		pr_info("%s, 0x%p, NO adapter struct.\n", ndev->name, cdev);
2276e33c2482SVarun Prakash 	}
2277e33c2482SVarun Prakash 
2278e33c2482SVarun Prakash 	/* ISO is enabled in T5/T6 firmware version >= 1.13.43.0 */
2279e33c2482SVarun Prakash 	if (!is_t4(lldi->adapter_type) &&
2280e33c2482SVarun Prakash 	    (lldi->fw_vers >= 0x10d2b00) &&
2281e33c2482SVarun Prakash 	    !(cdev->flags & CXGBI_FLAG_DEV_ISO_OFF))
2282e33c2482SVarun Prakash 		cdev->skb_iso_txhdr = sizeof(struct cpl_tx_data_iso);
2283e33c2482SVarun Prakash 
22847b36b6e0Skxie@chelsio.com 	rc = cxgb4i_ofld_init(cdev);
22857b36b6e0Skxie@chelsio.com 	if (rc) {
22867b36b6e0Skxie@chelsio.com 		pr_info("t4 0x%p ofld init failed.\n", cdev);
22877b36b6e0Skxie@chelsio.com 		goto err_out;
22887b36b6e0Skxie@chelsio.com 	}
22897b36b6e0Skxie@chelsio.com 
2290e33c2482SVarun Prakash 	cxgb4i_host_template.can_queue = max_cmds;
2291e33c2482SVarun Prakash 	rc = cxgbi_hbas_add(cdev, CXGB4I_MAX_LUN, max_conn,
22927b36b6e0Skxie@chelsio.com 			    &cxgb4i_host_template, cxgb4i_stt);
22937b36b6e0Skxie@chelsio.com 	if (rc)
22947b36b6e0Skxie@chelsio.com 		goto err_out;
22957b36b6e0Skxie@chelsio.com 
22967b36b6e0Skxie@chelsio.com 	for (i = 0; i < cdev->nports; i++) {
22977b36b6e0Skxie@chelsio.com 		pi = netdev_priv(lldi->ports[i]);
22987b36b6e0Skxie@chelsio.com 		cdev->hbas[i]->port_id = pi->port_id;
22997b36b6e0Skxie@chelsio.com 	}
23007b36b6e0Skxie@chelsio.com 	return cdev;
23017b36b6e0Skxie@chelsio.com 
23027b36b6e0Skxie@chelsio.com err_out:
23037b36b6e0Skxie@chelsio.com 	cxgbi_device_unregister(cdev);
23047b36b6e0Skxie@chelsio.com 	return ERR_PTR(-ENOMEM);
23057b36b6e0Skxie@chelsio.com }
23067b36b6e0Skxie@chelsio.com 
23077b36b6e0Skxie@chelsio.com #define RX_PULL_LEN	128
t4_uld_rx_handler(void * handle,const __be64 * rsp,const struct pkt_gl * pgl)23087b36b6e0Skxie@chelsio.com static int t4_uld_rx_handler(void *handle, const __be64 *rsp,
23097b36b6e0Skxie@chelsio.com 				const struct pkt_gl *pgl)
23107b36b6e0Skxie@chelsio.com {
23117b36b6e0Skxie@chelsio.com 	const struct cpl_act_establish *rpl;
23127b36b6e0Skxie@chelsio.com 	struct sk_buff *skb;
23137b36b6e0Skxie@chelsio.com 	unsigned int opc;
23147b36b6e0Skxie@chelsio.com 	struct cxgbi_device *cdev = handle;
23157b36b6e0Skxie@chelsio.com 
23167b36b6e0Skxie@chelsio.com 	if (pgl == NULL) {
23177b36b6e0Skxie@chelsio.com 		unsigned int len = 64 - sizeof(struct rsp_ctrl) - 8;
23187b36b6e0Skxie@chelsio.com 
231924d3f95aSkxie@chelsio.com 		skb = alloc_wr(len, 0, GFP_ATOMIC);
23207b36b6e0Skxie@chelsio.com 		if (!skb)
23217b36b6e0Skxie@chelsio.com 			goto nomem;
23227b36b6e0Skxie@chelsio.com 		skb_copy_to_linear_data(skb, &rsp[1], len);
23237b36b6e0Skxie@chelsio.com 	} else {
23247b36b6e0Skxie@chelsio.com 		if (unlikely(*(u8 *)rsp != *(u8 *)pgl->va)) {
23257b36b6e0Skxie@chelsio.com 			pr_info("? FL 0x%p,RSS%#llx,FL %#llx,len %u.\n",
23267b36b6e0Skxie@chelsio.com 				pgl->va, be64_to_cpu(*rsp),
23277b36b6e0Skxie@chelsio.com 				be64_to_cpu(*(u64 *)pgl->va),
23287b36b6e0Skxie@chelsio.com 				pgl->tot_len);
23297b36b6e0Skxie@chelsio.com 			return 0;
23307b36b6e0Skxie@chelsio.com 		}
23317b36b6e0Skxie@chelsio.com 		skb = cxgb4_pktgl_to_skb(pgl, RX_PULL_LEN, RX_PULL_LEN);
23327b36b6e0Skxie@chelsio.com 		if (unlikely(!skb))
23337b36b6e0Skxie@chelsio.com 			goto nomem;
23347b36b6e0Skxie@chelsio.com 	}
23357b36b6e0Skxie@chelsio.com 
23367b36b6e0Skxie@chelsio.com 	rpl = (struct cpl_act_establish *)skb->data;
23377b36b6e0Skxie@chelsio.com 	opc = rpl->ot.opcode;
23387b36b6e0Skxie@chelsio.com 	log_debug(1 << CXGBI_DBG_TOE,
23397b36b6e0Skxie@chelsio.com 		"cdev %p, opcode 0x%x(0x%x,0x%x), skb %p.\n",
23407b36b6e0Skxie@chelsio.com 		 cdev, opc, rpl->ot.opcode_tid, ntohl(rpl->ot.opcode_tid), skb);
2341ccc495efSDan Carpenter 	if (opc >= ARRAY_SIZE(cxgb4i_cplhandlers) || !cxgb4i_cplhandlers[opc]) {
23427b36b6e0Skxie@chelsio.com 		pr_err("No handler for opcode 0x%x.\n", opc);
23437b36b6e0Skxie@chelsio.com 		__kfree_skb(skb);
2344ccc495efSDan Carpenter 	} else
2345ccc495efSDan Carpenter 		cxgb4i_cplhandlers[opc](cdev, skb);
2346ccc495efSDan Carpenter 
23477b36b6e0Skxie@chelsio.com 	return 0;
23487b36b6e0Skxie@chelsio.com nomem:
23497b36b6e0Skxie@chelsio.com 	log_debug(1 << CXGBI_DBG_TOE, "OOM bailing out.\n");
23507b36b6e0Skxie@chelsio.com 	return 1;
23517b36b6e0Skxie@chelsio.com }
23527b36b6e0Skxie@chelsio.com 
t4_uld_state_change(void * handle,enum cxgb4_state state)23537b36b6e0Skxie@chelsio.com static int t4_uld_state_change(void *handle, enum cxgb4_state state)
23547b36b6e0Skxie@chelsio.com {
23557b36b6e0Skxie@chelsio.com 	struct cxgbi_device *cdev = handle;
23567b36b6e0Skxie@chelsio.com 
23577b36b6e0Skxie@chelsio.com 	switch (state) {
23587b36b6e0Skxie@chelsio.com 	case CXGB4_STATE_UP:
23597b36b6e0Skxie@chelsio.com 		pr_info("cdev 0x%p, UP.\n", cdev);
23607b36b6e0Skxie@chelsio.com 		break;
23617b36b6e0Skxie@chelsio.com 	case CXGB4_STATE_START_RECOVERY:
23627b36b6e0Skxie@chelsio.com 		pr_info("cdev 0x%p, RECOVERY.\n", cdev);
23637b36b6e0Skxie@chelsio.com 		/* close all connections */
23647b36b6e0Skxie@chelsio.com 		break;
23657b36b6e0Skxie@chelsio.com 	case CXGB4_STATE_DOWN:
23667b36b6e0Skxie@chelsio.com 		pr_info("cdev 0x%p, DOWN.\n", cdev);
23677b36b6e0Skxie@chelsio.com 		break;
23687b36b6e0Skxie@chelsio.com 	case CXGB4_STATE_DETACH:
23697b36b6e0Skxie@chelsio.com 		pr_info("cdev 0x%p, DETACH.\n", cdev);
2370c3b331a3SThadeu Lima de Souza Cascardo 		cxgbi_device_unregister(cdev);
23717b36b6e0Skxie@chelsio.com 		break;
23727b36b6e0Skxie@chelsio.com 	default:
23737b36b6e0Skxie@chelsio.com 		pr_info("cdev 0x%p, unknown state %d.\n", cdev, state);
23747b36b6e0Skxie@chelsio.com 		break;
23757b36b6e0Skxie@chelsio.com 	}
23767b36b6e0Skxie@chelsio.com 	return 0;
23777b36b6e0Skxie@chelsio.com }
23787b36b6e0Skxie@chelsio.com 
2379b5a5fe4eSVarun Prakash #ifdef CONFIG_CHELSIO_T4_DCB
2380b5a5fe4eSVarun Prakash static int
cxgb4_dcb_change_notify(struct notifier_block * self,unsigned long val,void * data)2381b5a5fe4eSVarun Prakash cxgb4_dcb_change_notify(struct notifier_block *self, unsigned long val,
2382b5a5fe4eSVarun Prakash 			void *data)
2383b5a5fe4eSVarun Prakash {
2384b5a5fe4eSVarun Prakash 	int i, port = 0xFF;
2385b5a5fe4eSVarun Prakash 	struct net_device *ndev;
2386b5a5fe4eSVarun Prakash 	struct cxgbi_device *cdev = NULL;
2387b5a5fe4eSVarun Prakash 	struct dcb_app_type *iscsi_app = data;
2388b5a5fe4eSVarun Prakash 	struct cxgbi_ports_map *pmap;
2389b5a5fe4eSVarun Prakash 	u8 priority;
2390b5a5fe4eSVarun Prakash 
2391b5a5fe4eSVarun Prakash 	if (iscsi_app->dcbx & DCB_CAP_DCBX_VER_IEEE) {
2392152e30fcSVarun Prakash 		if ((iscsi_app->app.selector != IEEE_8021QAZ_APP_SEL_STREAM) &&
2393152e30fcSVarun Prakash 		    (iscsi_app->app.selector != IEEE_8021QAZ_APP_SEL_ANY))
2394b5a5fe4eSVarun Prakash 			return NOTIFY_DONE;
2395b5a5fe4eSVarun Prakash 
2396b5a5fe4eSVarun Prakash 		priority = iscsi_app->app.priority;
2397b5a5fe4eSVarun Prakash 	} else if (iscsi_app->dcbx & DCB_CAP_DCBX_VER_CEE) {
2398b5a5fe4eSVarun Prakash 		if (iscsi_app->app.selector != DCB_APP_IDTYPE_PORTNUM)
2399b5a5fe4eSVarun Prakash 			return NOTIFY_DONE;
2400b5a5fe4eSVarun Prakash 
2401b5a5fe4eSVarun Prakash 		if (!iscsi_app->app.priority)
2402b5a5fe4eSVarun Prakash 			return NOTIFY_DONE;
2403b5a5fe4eSVarun Prakash 
2404b5a5fe4eSVarun Prakash 		priority = ffs(iscsi_app->app.priority) - 1;
2405b5a5fe4eSVarun Prakash 	} else {
2406b5a5fe4eSVarun Prakash 		return NOTIFY_DONE;
2407b5a5fe4eSVarun Prakash 	}
2408b5a5fe4eSVarun Prakash 
2409b5a5fe4eSVarun Prakash 	if (iscsi_app->app.protocol != 3260)
2410b5a5fe4eSVarun Prakash 		return NOTIFY_DONE;
2411b5a5fe4eSVarun Prakash 
2412b5a5fe4eSVarun Prakash 	log_debug(1 << CXGBI_DBG_ISCSI, "iSCSI priority for ifid %d is %u\n",
2413b5a5fe4eSVarun Prakash 		  iscsi_app->ifindex, priority);
2414b5a5fe4eSVarun Prakash 
2415b5a5fe4eSVarun Prakash 	ndev = dev_get_by_index(&init_net, iscsi_app->ifindex);
2416b5a5fe4eSVarun Prakash 	if (!ndev)
2417b5a5fe4eSVarun Prakash 		return NOTIFY_DONE;
2418b5a5fe4eSVarun Prakash 
2419b5a5fe4eSVarun Prakash 	cdev = cxgbi_device_find_by_netdev_rcu(ndev, &port);
2420b5a5fe4eSVarun Prakash 
2421b5a5fe4eSVarun Prakash 	dev_put(ndev);
2422b5a5fe4eSVarun Prakash 	if (!cdev)
2423b5a5fe4eSVarun Prakash 		return NOTIFY_DONE;
2424b5a5fe4eSVarun Prakash 
2425b5a5fe4eSVarun Prakash 	pmap = &cdev->pmap;
2426b5a5fe4eSVarun Prakash 
2427b5a5fe4eSVarun Prakash 	for (i = 0; i < pmap->used; i++) {
2428b5a5fe4eSVarun Prakash 		if (pmap->port_csk[i]) {
2429b5a5fe4eSVarun Prakash 			struct cxgbi_sock *csk = pmap->port_csk[i];
2430b5a5fe4eSVarun Prakash 
2431b5a5fe4eSVarun Prakash 			if (csk->dcb_priority != priority) {
2432b5a5fe4eSVarun Prakash 				iscsi_conn_failure(csk->user_data,
2433b5a5fe4eSVarun Prakash 						   ISCSI_ERR_CONN_FAILED);
2434b5a5fe4eSVarun Prakash 				pr_info("Restarting iSCSI connection %p with "
2435b5a5fe4eSVarun Prakash 					"priority %u->%u.\n", csk,
2436b5a5fe4eSVarun Prakash 					csk->dcb_priority, priority);
2437b5a5fe4eSVarun Prakash 			}
2438b5a5fe4eSVarun Prakash 		}
2439b5a5fe4eSVarun Prakash 	}
2440b5a5fe4eSVarun Prakash 	return NOTIFY_OK;
2441b5a5fe4eSVarun Prakash }
2442b5a5fe4eSVarun Prakash #endif
2443b5a5fe4eSVarun Prakash 
cxgb4i_init_module(void)24447b36b6e0Skxie@chelsio.com static int __init cxgb4i_init_module(void)
24457b36b6e0Skxie@chelsio.com {
24467b36b6e0Skxie@chelsio.com 	int rc;
24477b36b6e0Skxie@chelsio.com 
24487b36b6e0Skxie@chelsio.com 	printk(KERN_INFO "%s", version);
24497b36b6e0Skxie@chelsio.com 
24507b36b6e0Skxie@chelsio.com 	rc = cxgbi_iscsi_init(&cxgb4i_iscsi_transport, &cxgb4i_stt);
24517b36b6e0Skxie@chelsio.com 	if (rc < 0)
24527b36b6e0Skxie@chelsio.com 		return rc;
24537b36b6e0Skxie@chelsio.com 	cxgb4_register_uld(CXGB4_ULD_ISCSI, &cxgb4i_uld_info);
2454759a0cc5SAnish Bhatt 
2455b5a5fe4eSVarun Prakash #ifdef CONFIG_CHELSIO_T4_DCB
2456b5a5fe4eSVarun Prakash 	pr_info("%s dcb enabled.\n", DRV_MODULE_NAME);
2457b5a5fe4eSVarun Prakash 	register_dcbevent_notifier(&cxgb4_dcb_change);
2458b5a5fe4eSVarun Prakash #endif
24597b36b6e0Skxie@chelsio.com 	return 0;
24607b36b6e0Skxie@chelsio.com }
24617b36b6e0Skxie@chelsio.com 
cxgb4i_exit_module(void)24627b36b6e0Skxie@chelsio.com static void __exit cxgb4i_exit_module(void)
24637b36b6e0Skxie@chelsio.com {
2464b5a5fe4eSVarun Prakash #ifdef CONFIG_CHELSIO_T4_DCB
2465b5a5fe4eSVarun Prakash 	unregister_dcbevent_notifier(&cxgb4_dcb_change);
2466b5a5fe4eSVarun Prakash #endif
24677b36b6e0Skxie@chelsio.com 	cxgb4_unregister_uld(CXGB4_ULD_ISCSI);
24687b36b6e0Skxie@chelsio.com 	cxgbi_device_unregister_all(CXGBI_FLAG_DEV_T4);
24697b36b6e0Skxie@chelsio.com 	cxgbi_iscsi_cleanup(&cxgb4i_iscsi_transport, &cxgb4i_stt);
24707b36b6e0Skxie@chelsio.com }
24717b36b6e0Skxie@chelsio.com 
24727b36b6e0Skxie@chelsio.com module_init(cxgb4i_init_module);
24737b36b6e0Skxie@chelsio.com module_exit(cxgb4i_exit_module);
2474