xref: /openbmc/linux/drivers/scsi/cxgbi/cxgb4i/cxgb4i.c (revision e81fbf6c)
17b36b6e0Skxie@chelsio.com /*
27b36b6e0Skxie@chelsio.com  * cxgb4i.c: Chelsio T4 iSCSI driver.
37b36b6e0Skxie@chelsio.com  *
47b36b6e0Skxie@chelsio.com  * Copyright (c) 2010 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 
167b36b6e0Skxie@chelsio.com #include <linux/module.h>
177b36b6e0Skxie@chelsio.com #include <linux/moduleparam.h>
187b36b6e0Skxie@chelsio.com #include <scsi/scsi_host.h>
197b36b6e0Skxie@chelsio.com #include <net/tcp.h>
207b36b6e0Skxie@chelsio.com #include <net/dst.h>
217b36b6e0Skxie@chelsio.com #include <linux/netdevice.h>
22759a0cc5SAnish Bhatt #include <net/addrconf.h>
237b36b6e0Skxie@chelsio.com 
243bd3e8bfSKaren Xie #include "t4_regs.h"
257b36b6e0Skxie@chelsio.com #include "t4_msg.h"
267b36b6e0Skxie@chelsio.com #include "cxgb4.h"
277b36b6e0Skxie@chelsio.com #include "cxgb4_uld.h"
287b36b6e0Skxie@chelsio.com #include "t4fw_api.h"
297b36b6e0Skxie@chelsio.com #include "l2t.h"
307b36b6e0Skxie@chelsio.com #include "cxgb4i.h"
317b36b6e0Skxie@chelsio.com 
327b36b6e0Skxie@chelsio.com static unsigned int dbg_level;
337b36b6e0Skxie@chelsio.com 
347b36b6e0Skxie@chelsio.com #include "../libcxgbi.h"
357b36b6e0Skxie@chelsio.com 
367b36b6e0Skxie@chelsio.com #define	DRV_MODULE_NAME		"cxgb4i"
373bd3e8bfSKaren Xie #define DRV_MODULE_DESC		"Chelsio T4/T5 iSCSI Driver"
383bd3e8bfSKaren Xie #define	DRV_MODULE_VERSION	"0.9.4"
397b36b6e0Skxie@chelsio.com 
407b36b6e0Skxie@chelsio.com static char version[] =
417b36b6e0Skxie@chelsio.com 	DRV_MODULE_DESC " " DRV_MODULE_NAME
423bd3e8bfSKaren Xie 	" v" DRV_MODULE_VERSION "\n";
437b36b6e0Skxie@chelsio.com 
447b36b6e0Skxie@chelsio.com MODULE_AUTHOR("Chelsio Communications, Inc.");
457b36b6e0Skxie@chelsio.com MODULE_DESCRIPTION(DRV_MODULE_DESC);
467b36b6e0Skxie@chelsio.com MODULE_VERSION(DRV_MODULE_VERSION);
477b36b6e0Skxie@chelsio.com MODULE_LICENSE("GPL");
487b36b6e0Skxie@chelsio.com 
497b36b6e0Skxie@chelsio.com module_param(dbg_level, uint, 0644);
507b36b6e0Skxie@chelsio.com MODULE_PARM_DESC(dbg_level, "Debug flag (default=0)");
517b36b6e0Skxie@chelsio.com 
527b36b6e0Skxie@chelsio.com static int cxgb4i_rcv_win = 256 * 1024;
537b36b6e0Skxie@chelsio.com module_param(cxgb4i_rcv_win, int, 0644);
547b36b6e0Skxie@chelsio.com MODULE_PARM_DESC(cxgb4i_rcv_win, "TCP reveive window in bytes");
557b36b6e0Skxie@chelsio.com 
567b36b6e0Skxie@chelsio.com static int cxgb4i_snd_win = 128 * 1024;
577b36b6e0Skxie@chelsio.com module_param(cxgb4i_snd_win, int, 0644);
587b36b6e0Skxie@chelsio.com MODULE_PARM_DESC(cxgb4i_snd_win, "TCP send window in bytes");
597b36b6e0Skxie@chelsio.com 
607b36b6e0Skxie@chelsio.com static int cxgb4i_rx_credit_thres = 10 * 1024;
617b36b6e0Skxie@chelsio.com module_param(cxgb4i_rx_credit_thres, int, 0644);
627b36b6e0Skxie@chelsio.com MODULE_PARM_DESC(cxgb4i_rx_credit_thres,
637b36b6e0Skxie@chelsio.com 		"RX credits return threshold in bytes (default=10KB)");
647b36b6e0Skxie@chelsio.com 
657b36b6e0Skxie@chelsio.com static unsigned int cxgb4i_max_connect = (8 * 1024);
667b36b6e0Skxie@chelsio.com module_param(cxgb4i_max_connect, uint, 0644);
677b36b6e0Skxie@chelsio.com MODULE_PARM_DESC(cxgb4i_max_connect, "Maximum number of connections");
687b36b6e0Skxie@chelsio.com 
697b36b6e0Skxie@chelsio.com static unsigned short cxgb4i_sport_base = 20000;
707b36b6e0Skxie@chelsio.com module_param(cxgb4i_sport_base, ushort, 0644);
717b36b6e0Skxie@chelsio.com MODULE_PARM_DESC(cxgb4i_sport_base, "Starting port number (default 20000)");
727b36b6e0Skxie@chelsio.com 
737b36b6e0Skxie@chelsio.com typedef void (*cxgb4i_cplhandler_func)(struct cxgbi_device *, struct sk_buff *);
747b36b6e0Skxie@chelsio.com 
757b36b6e0Skxie@chelsio.com static void *t4_uld_add(const struct cxgb4_lld_info *);
767b36b6e0Skxie@chelsio.com static int t4_uld_rx_handler(void *, const __be64 *, const struct pkt_gl *);
777b36b6e0Skxie@chelsio.com static int t4_uld_state_change(void *, enum cxgb4_state state);
787b36b6e0Skxie@chelsio.com 
797b36b6e0Skxie@chelsio.com static const struct cxgb4_uld_info cxgb4i_uld_info = {
807b36b6e0Skxie@chelsio.com 	.name = DRV_MODULE_NAME,
817b36b6e0Skxie@chelsio.com 	.add = t4_uld_add,
827b36b6e0Skxie@chelsio.com 	.rx_handler = t4_uld_rx_handler,
837b36b6e0Skxie@chelsio.com 	.state_change = t4_uld_state_change,
847b36b6e0Skxie@chelsio.com };
857b36b6e0Skxie@chelsio.com 
867b36b6e0Skxie@chelsio.com static struct scsi_host_template cxgb4i_host_template = {
877b36b6e0Skxie@chelsio.com 	.module		= THIS_MODULE,
887b36b6e0Skxie@chelsio.com 	.name		= DRV_MODULE_NAME,
897b36b6e0Skxie@chelsio.com 	.proc_name	= DRV_MODULE_NAME,
907b36b6e0Skxie@chelsio.com 	.can_queue	= CXGB4I_SCSI_HOST_QDEPTH,
917b36b6e0Skxie@chelsio.com 	.queuecommand	= iscsi_queuecommand,
927b36b6e0Skxie@chelsio.com 	.change_queue_depth = iscsi_change_queue_depth,
937b36b6e0Skxie@chelsio.com 	.sg_tablesize	= SG_ALL,
947b36b6e0Skxie@chelsio.com 	.max_sectors	= 0xFFFF,
957b36b6e0Skxie@chelsio.com 	.cmd_per_lun	= ISCSI_DEF_CMD_PER_LUN,
967b36b6e0Skxie@chelsio.com 	.eh_abort_handler = iscsi_eh_abort,
977b36b6e0Skxie@chelsio.com 	.eh_device_reset_handler = iscsi_eh_device_reset,
987b36b6e0Skxie@chelsio.com 	.eh_target_reset_handler = iscsi_eh_recover_target,
997b36b6e0Skxie@chelsio.com 	.target_alloc	= iscsi_target_alloc,
1007b36b6e0Skxie@chelsio.com 	.use_clustering	= DISABLE_CLUSTERING,
1017b36b6e0Skxie@chelsio.com 	.this_id	= -1,
1027b36b6e0Skxie@chelsio.com };
1037b36b6e0Skxie@chelsio.com 
1047b36b6e0Skxie@chelsio.com static struct iscsi_transport cxgb4i_iscsi_transport = {
1057b36b6e0Skxie@chelsio.com 	.owner		= THIS_MODULE,
1067b36b6e0Skxie@chelsio.com 	.name		= DRV_MODULE_NAME,
1077b36b6e0Skxie@chelsio.com 	.caps		= CAP_RECOVERY_L0 | CAP_MULTI_R2T | CAP_HDRDGST |
1087b36b6e0Skxie@chelsio.com 				CAP_DATADGST | CAP_DIGEST_OFFLOAD |
109fdafd4dfSMike Christie 				CAP_PADDING_OFFLOAD | CAP_TEXT_NEGO,
1103128c6c7SMike Christie 	.attr_is_visible	= cxgbi_attr_is_visible,
1117b36b6e0Skxie@chelsio.com 	.get_host_param	= cxgbi_get_host_param,
1127b36b6e0Skxie@chelsio.com 	.set_host_param	= cxgbi_set_host_param,
1137b36b6e0Skxie@chelsio.com 	/* session management */
1147b36b6e0Skxie@chelsio.com 	.create_session	= cxgbi_create_session,
1157b36b6e0Skxie@chelsio.com 	.destroy_session	= cxgbi_destroy_session,
1167b36b6e0Skxie@chelsio.com 	.get_session_param = iscsi_session_get_param,
1177b36b6e0Skxie@chelsio.com 	/* connection management */
1187b36b6e0Skxie@chelsio.com 	.create_conn	= cxgbi_create_conn,
1197b36b6e0Skxie@chelsio.com 	.bind_conn		= cxgbi_bind_conn,
1207b36b6e0Skxie@chelsio.com 	.destroy_conn	= iscsi_tcp_conn_teardown,
1217b36b6e0Skxie@chelsio.com 	.start_conn		= iscsi_conn_start,
1227b36b6e0Skxie@chelsio.com 	.stop_conn		= iscsi_conn_stop,
123c71b9b66SMike Christie 	.get_conn_param	= iscsi_conn_get_param,
1247b36b6e0Skxie@chelsio.com 	.set_param	= cxgbi_set_conn_param,
1257b36b6e0Skxie@chelsio.com 	.get_stats	= cxgbi_get_conn_stats,
1267b36b6e0Skxie@chelsio.com 	/* pdu xmit req from user space */
1277b36b6e0Skxie@chelsio.com 	.send_pdu	= iscsi_conn_send_pdu,
1287b36b6e0Skxie@chelsio.com 	/* task */
1297b36b6e0Skxie@chelsio.com 	.init_task	= iscsi_tcp_task_init,
1307b36b6e0Skxie@chelsio.com 	.xmit_task	= iscsi_tcp_task_xmit,
1317b36b6e0Skxie@chelsio.com 	.cleanup_task	= cxgbi_cleanup_task,
1327b36b6e0Skxie@chelsio.com 	/* pdu */
1337b36b6e0Skxie@chelsio.com 	.alloc_pdu	= cxgbi_conn_alloc_pdu,
1347b36b6e0Skxie@chelsio.com 	.init_pdu	= cxgbi_conn_init_pdu,
1357b36b6e0Skxie@chelsio.com 	.xmit_pdu	= cxgbi_conn_xmit_pdu,
1367b36b6e0Skxie@chelsio.com 	.parse_pdu_itt	= cxgbi_parse_pdu_itt,
1377b36b6e0Skxie@chelsio.com 	/* TCP connect/disconnect */
138c71b9b66SMike Christie 	.get_ep_param	= cxgbi_get_ep_param,
1397b36b6e0Skxie@chelsio.com 	.ep_connect	= cxgbi_ep_connect,
1407b36b6e0Skxie@chelsio.com 	.ep_poll	= cxgbi_ep_poll,
1417b36b6e0Skxie@chelsio.com 	.ep_disconnect	= cxgbi_ep_disconnect,
1427b36b6e0Skxie@chelsio.com 	/* Error recovery timeout call */
1437b36b6e0Skxie@chelsio.com 	.session_recovery_timedout = iscsi_session_recovery_timedout,
1447b36b6e0Skxie@chelsio.com };
1457b36b6e0Skxie@chelsio.com 
1467b36b6e0Skxie@chelsio.com static struct scsi_transport_template *cxgb4i_stt;
1477b36b6e0Skxie@chelsio.com 
1487b36b6e0Skxie@chelsio.com /*
1497b36b6e0Skxie@chelsio.com  * CPL (Chelsio Protocol Language) defines a message passing interface between
1507b36b6e0Skxie@chelsio.com  * the host driver and Chelsio asic.
1517b36b6e0Skxie@chelsio.com  * The section below implments CPLs that related to iscsi tcp connection
1527b36b6e0Skxie@chelsio.com  * open/close/abort and data send/receive.
1537b36b6e0Skxie@chelsio.com  */
154759a0cc5SAnish Bhatt 
1557b36b6e0Skxie@chelsio.com #define DIV_ROUND_UP(n, d)	(((n) + (d) - 1) / (d))
1567b36b6e0Skxie@chelsio.com #define RCV_BUFSIZ_MASK		0x3FFU
1577b36b6e0Skxie@chelsio.com #define MAX_IMM_TX_PKT_LEN	128
1587b36b6e0Skxie@chelsio.com 
1597b36b6e0Skxie@chelsio.com static inline void set_queue(struct sk_buff *skb, unsigned int queue,
1607b36b6e0Skxie@chelsio.com 				const struct cxgbi_sock *csk)
1617b36b6e0Skxie@chelsio.com {
1627b36b6e0Skxie@chelsio.com 	skb->queue_mapping = queue;
1637b36b6e0Skxie@chelsio.com }
1647b36b6e0Skxie@chelsio.com 
1657b36b6e0Skxie@chelsio.com static int push_tx_frames(struct cxgbi_sock *, int);
1667b36b6e0Skxie@chelsio.com 
1677b36b6e0Skxie@chelsio.com /*
1687b36b6e0Skxie@chelsio.com  * is_ofld_imm - check whether a packet can be sent as immediate data
1697b36b6e0Skxie@chelsio.com  * @skb: the packet
1707b36b6e0Skxie@chelsio.com  *
1717b36b6e0Skxie@chelsio.com  * Returns true if a packet can be sent as an offload WR with immediate
1727b36b6e0Skxie@chelsio.com  * data.  We currently use the same limit as for Ethernet packets.
1737b36b6e0Skxie@chelsio.com  */
1747b36b6e0Skxie@chelsio.com static inline int is_ofld_imm(const struct sk_buff *skb)
1757b36b6e0Skxie@chelsio.com {
1767b36b6e0Skxie@chelsio.com 	return skb->len <= (MAX_IMM_TX_PKT_LEN -
1777b36b6e0Skxie@chelsio.com 			sizeof(struct fw_ofld_tx_data_wr));
1787b36b6e0Skxie@chelsio.com }
1797b36b6e0Skxie@chelsio.com 
1807b36b6e0Skxie@chelsio.com static void send_act_open_req(struct cxgbi_sock *csk, struct sk_buff *skb,
1817b36b6e0Skxie@chelsio.com 				struct l2t_entry *e)
1827b36b6e0Skxie@chelsio.com {
1833bd3e8bfSKaren Xie 	struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(csk->cdev);
184759a0cc5SAnish Bhatt 	int t4 = is_t4(lldi->adapter_type);
1857b36b6e0Skxie@chelsio.com 	int wscale = cxgbi_sock_compute_wscale(csk->mss_idx);
1867b36b6e0Skxie@chelsio.com 	unsigned long long opt0;
1877b36b6e0Skxie@chelsio.com 	unsigned int opt2;
1887b36b6e0Skxie@chelsio.com 	unsigned int qid_atid = ((unsigned int)csk->atid) |
1897b36b6e0Skxie@chelsio.com 				 (((unsigned int)csk->rss_qid) << 14);
1907b36b6e0Skxie@chelsio.com 
1917b36b6e0Skxie@chelsio.com 	opt0 = KEEP_ALIVE(1) |
1927b36b6e0Skxie@chelsio.com 		WND_SCALE(wscale) |
1937b36b6e0Skxie@chelsio.com 		MSS_IDX(csk->mss_idx) |
1947b36b6e0Skxie@chelsio.com 		L2T_IDX(((struct l2t_entry *)csk->l2t)->idx) |
1957b36b6e0Skxie@chelsio.com 		TX_CHAN(csk->tx_chan) |
1967b36b6e0Skxie@chelsio.com 		SMAC_SEL(csk->smac_idx) |
1977b36b6e0Skxie@chelsio.com 		ULP_MODE(ULP_MODE_ISCSI) |
1987b36b6e0Skxie@chelsio.com 		RCV_BUFSIZ(cxgb4i_rcv_win >> 10);
1997b36b6e0Skxie@chelsio.com 	opt2 = RX_CHANNEL(0) |
2007b36b6e0Skxie@chelsio.com 		RSS_QUEUE_VALID |
2013bd3e8bfSKaren Xie 		(1 << 20) |
2027b36b6e0Skxie@chelsio.com 		RSS_QUEUE(csk->rss_qid);
2037b36b6e0Skxie@chelsio.com 
2043bd3e8bfSKaren Xie 	if (is_t4(lldi->adapter_type)) {
2053bd3e8bfSKaren Xie 		struct cpl_act_open_req *req =
2063bd3e8bfSKaren Xie 				(struct cpl_act_open_req *)skb->head;
2073bd3e8bfSKaren Xie 
2087b36b6e0Skxie@chelsio.com 		INIT_TP_WR(req, 0);
2097b36b6e0Skxie@chelsio.com 		OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_ACT_OPEN_REQ,
2107b36b6e0Skxie@chelsio.com 					qid_atid));
2117b36b6e0Skxie@chelsio.com 		req->local_port = csk->saddr.sin_port;
2127b36b6e0Skxie@chelsio.com 		req->peer_port = csk->daddr.sin_port;
2137b36b6e0Skxie@chelsio.com 		req->local_ip = csk->saddr.sin_addr.s_addr;
2147b36b6e0Skxie@chelsio.com 		req->peer_ip = csk->daddr.sin_addr.s_addr;
2157b36b6e0Skxie@chelsio.com 		req->opt0 = cpu_to_be64(opt0);
216ac0245ffSKaren Xie 		req->params = cpu_to_be32(cxgb4_select_ntuple(
217ac0245ffSKaren Xie 					csk->cdev->ports[csk->port_id],
218ac0245ffSKaren Xie 					csk->l2t));
2193bd3e8bfSKaren Xie 		opt2 |= 1 << 22;
2207b36b6e0Skxie@chelsio.com 		req->opt2 = cpu_to_be32(opt2);
2217b36b6e0Skxie@chelsio.com 
2227b36b6e0Skxie@chelsio.com 		log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
2233bd3e8bfSKaren Xie 			"csk t4 0x%p, %pI4:%u-%pI4:%u, atid %d, qid %u.\n",
2247b36b6e0Skxie@chelsio.com 			csk, &req->local_ip, ntohs(req->local_port),
2257b36b6e0Skxie@chelsio.com 			&req->peer_ip, ntohs(req->peer_port),
2267b36b6e0Skxie@chelsio.com 			csk->atid, csk->rss_qid);
2273bd3e8bfSKaren Xie 	} else {
2283bd3e8bfSKaren Xie 		struct cpl_t5_act_open_req *req =
2293bd3e8bfSKaren Xie 				(struct cpl_t5_act_open_req *)skb->head;
2307b36b6e0Skxie@chelsio.com 
2313bd3e8bfSKaren Xie 		INIT_TP_WR(req, 0);
2323bd3e8bfSKaren Xie 		OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_ACT_OPEN_REQ,
2333bd3e8bfSKaren Xie 					qid_atid));
2343bd3e8bfSKaren Xie 		req->local_port = csk->saddr.sin_port;
2353bd3e8bfSKaren Xie 		req->peer_port = csk->daddr.sin_port;
2363bd3e8bfSKaren Xie 		req->local_ip = csk->saddr.sin_addr.s_addr;
2373bd3e8bfSKaren Xie 		req->peer_ip = csk->daddr.sin_addr.s_addr;
2383bd3e8bfSKaren Xie 		req->opt0 = cpu_to_be64(opt0);
239ac0245ffSKaren Xie 		req->params = cpu_to_be64(V_FILTER_TUPLE(
240ac0245ffSKaren Xie 				cxgb4_select_ntuple(
241ac0245ffSKaren Xie 					csk->cdev->ports[csk->port_id],
242ac0245ffSKaren Xie 					csk->l2t)));
2433bd3e8bfSKaren Xie 		opt2 |= 1 << 31;
2443bd3e8bfSKaren Xie 		req->opt2 = cpu_to_be32(opt2);
2453bd3e8bfSKaren Xie 
2463bd3e8bfSKaren Xie 		log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
2473bd3e8bfSKaren Xie 			"csk t5 0x%p, %pI4:%u-%pI4:%u, atid %d, qid %u.\n",
2483bd3e8bfSKaren Xie 			csk, &req->local_ip, ntohs(req->local_port),
2493bd3e8bfSKaren Xie 			&req->peer_ip, ntohs(req->peer_port),
2503bd3e8bfSKaren Xie 			csk->atid, csk->rss_qid);
2513bd3e8bfSKaren Xie 	}
2523bd3e8bfSKaren Xie 
2533bd3e8bfSKaren Xie 	set_wr_txq(skb, CPL_PRIORITY_SETUP, csk->port_id);
254759a0cc5SAnish Bhatt 
255759a0cc5SAnish Bhatt 	pr_info_ipaddr("t%d csk 0x%p,%u,0x%lx,%u, rss_qid %u.\n",
256759a0cc5SAnish Bhatt 		       (&csk->saddr), (&csk->daddr), t4 ? 4 : 5, csk,
257759a0cc5SAnish Bhatt 		       csk->state, csk->flags, csk->atid, csk->rss_qid);
258759a0cc5SAnish Bhatt 
259759a0cc5SAnish Bhatt 	cxgb4_l2t_send(csk->cdev->ports[csk->port_id], skb, csk->l2t);
260759a0cc5SAnish Bhatt }
261759a0cc5SAnish Bhatt 
262759a0cc5SAnish Bhatt static void send_act_open_req6(struct cxgbi_sock *csk, struct sk_buff *skb,
263759a0cc5SAnish Bhatt 			       struct l2t_entry *e)
264759a0cc5SAnish Bhatt {
265759a0cc5SAnish Bhatt 	struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(csk->cdev);
266759a0cc5SAnish Bhatt 	int t4 = is_t4(lldi->adapter_type);
267759a0cc5SAnish Bhatt 	int wscale = cxgbi_sock_compute_wscale(csk->mss_idx);
268759a0cc5SAnish Bhatt 	unsigned long long opt0;
269759a0cc5SAnish Bhatt 	unsigned int opt2;
270759a0cc5SAnish Bhatt 	unsigned int qid_atid = ((unsigned int)csk->atid) |
271759a0cc5SAnish Bhatt 				 (((unsigned int)csk->rss_qid) << 14);
272759a0cc5SAnish Bhatt 
273759a0cc5SAnish Bhatt 	opt0 = KEEP_ALIVE(1) |
274759a0cc5SAnish Bhatt 		WND_SCALE(wscale) |
275759a0cc5SAnish Bhatt 		MSS_IDX(csk->mss_idx) |
276759a0cc5SAnish Bhatt 		L2T_IDX(((struct l2t_entry *)csk->l2t)->idx) |
277759a0cc5SAnish Bhatt 		TX_CHAN(csk->tx_chan) |
278759a0cc5SAnish Bhatt 		SMAC_SEL(csk->smac_idx) |
279759a0cc5SAnish Bhatt 		ULP_MODE(ULP_MODE_ISCSI) |
280759a0cc5SAnish Bhatt 		RCV_BUFSIZ(cxgb4i_rcv_win >> 10);
281759a0cc5SAnish Bhatt 
282759a0cc5SAnish Bhatt 	opt2 = RX_CHANNEL(0) |
283759a0cc5SAnish Bhatt 		RSS_QUEUE_VALID |
284759a0cc5SAnish Bhatt 		RX_FC_DISABLE |
285759a0cc5SAnish Bhatt 		RSS_QUEUE(csk->rss_qid);
286759a0cc5SAnish Bhatt 
287759a0cc5SAnish Bhatt 	if (t4) {
288759a0cc5SAnish Bhatt 		struct cpl_act_open_req6 *req =
289759a0cc5SAnish Bhatt 			    (struct cpl_act_open_req6 *)skb->head;
290759a0cc5SAnish Bhatt 
291759a0cc5SAnish Bhatt 		INIT_TP_WR(req, 0);
292759a0cc5SAnish Bhatt 		OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_ACT_OPEN_REQ6,
293759a0cc5SAnish Bhatt 							    qid_atid));
294759a0cc5SAnish Bhatt 		req->local_port = csk->saddr6.sin6_port;
295759a0cc5SAnish Bhatt 		req->peer_port = csk->daddr6.sin6_port;
296759a0cc5SAnish Bhatt 
297759a0cc5SAnish Bhatt 		req->local_ip_hi = *(__be64 *)(csk->saddr6.sin6_addr.s6_addr);
298759a0cc5SAnish Bhatt 		req->local_ip_lo = *(__be64 *)(csk->saddr6.sin6_addr.s6_addr +
299759a0cc5SAnish Bhatt 								    8);
300759a0cc5SAnish Bhatt 		req->peer_ip_hi = *(__be64 *)(csk->daddr6.sin6_addr.s6_addr);
301759a0cc5SAnish Bhatt 		req->peer_ip_lo = *(__be64 *)(csk->daddr6.sin6_addr.s6_addr +
302759a0cc5SAnish Bhatt 								    8);
303759a0cc5SAnish Bhatt 
304759a0cc5SAnish Bhatt 		req->opt0 = cpu_to_be64(opt0);
305759a0cc5SAnish Bhatt 
306759a0cc5SAnish Bhatt 		opt2 |= RX_FC_VALID;
307759a0cc5SAnish Bhatt 		req->opt2 = cpu_to_be32(opt2);
308759a0cc5SAnish Bhatt 
309759a0cc5SAnish Bhatt 		req->params = cpu_to_be32(cxgb4_select_ntuple(
310759a0cc5SAnish Bhatt 					  csk->cdev->ports[csk->port_id],
311759a0cc5SAnish Bhatt 					  csk->l2t));
312759a0cc5SAnish Bhatt 	} else {
313759a0cc5SAnish Bhatt 		struct cpl_t5_act_open_req6 *req =
314759a0cc5SAnish Bhatt 				(struct cpl_t5_act_open_req6 *)skb->head;
315759a0cc5SAnish Bhatt 
316759a0cc5SAnish Bhatt 		INIT_TP_WR(req, 0);
317759a0cc5SAnish Bhatt 		OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_ACT_OPEN_REQ6,
318759a0cc5SAnish Bhatt 							    qid_atid));
319759a0cc5SAnish Bhatt 		req->local_port = csk->saddr6.sin6_port;
320759a0cc5SAnish Bhatt 		req->peer_port = csk->daddr6.sin6_port;
321759a0cc5SAnish Bhatt 		req->local_ip_hi = *(__be64 *)(csk->saddr6.sin6_addr.s6_addr);
322759a0cc5SAnish Bhatt 		req->local_ip_lo = *(__be64 *)(csk->saddr6.sin6_addr.s6_addr +
323759a0cc5SAnish Bhatt 									8);
324759a0cc5SAnish Bhatt 		req->peer_ip_hi = *(__be64 *)(csk->daddr6.sin6_addr.s6_addr);
325759a0cc5SAnish Bhatt 		req->peer_ip_lo = *(__be64 *)(csk->daddr6.sin6_addr.s6_addr +
326759a0cc5SAnish Bhatt 									8);
327759a0cc5SAnish Bhatt 		req->opt0 = cpu_to_be64(opt0);
328759a0cc5SAnish Bhatt 
329759a0cc5SAnish Bhatt 		opt2 |= T5_OPT_2_VALID;
330759a0cc5SAnish Bhatt 		req->opt2 = cpu_to_be32(opt2);
331759a0cc5SAnish Bhatt 
332759a0cc5SAnish Bhatt 		req->params = cpu_to_be64(V_FILTER_TUPLE(cxgb4_select_ntuple(
333759a0cc5SAnish Bhatt 					  csk->cdev->ports[csk->port_id],
334759a0cc5SAnish Bhatt 					  csk->l2t)));
335759a0cc5SAnish Bhatt 	}
336759a0cc5SAnish Bhatt 
337759a0cc5SAnish Bhatt 	set_wr_txq(skb, CPL_PRIORITY_SETUP, csk->port_id);
338759a0cc5SAnish Bhatt 
339759a0cc5SAnish Bhatt 	pr_info("t%d csk 0x%p,%u,0x%lx,%u, [%pI6]:%u-[%pI6]:%u, rss_qid %u.\n",
340759a0cc5SAnish Bhatt 		t4 ? 4 : 5, csk, csk->state, csk->flags, csk->atid,
341759a0cc5SAnish Bhatt 		&csk->saddr6.sin6_addr, ntohs(csk->saddr.sin_port),
342759a0cc5SAnish Bhatt 		&csk->daddr6.sin6_addr, ntohs(csk->daddr.sin_port),
343759a0cc5SAnish Bhatt 		csk->rss_qid);
344759a0cc5SAnish Bhatt 
3457b36b6e0Skxie@chelsio.com 	cxgb4_l2t_send(csk->cdev->ports[csk->port_id], skb, csk->l2t);
3467b36b6e0Skxie@chelsio.com }
3477b36b6e0Skxie@chelsio.com 
3487b36b6e0Skxie@chelsio.com static void send_close_req(struct cxgbi_sock *csk)
3497b36b6e0Skxie@chelsio.com {
3507b36b6e0Skxie@chelsio.com 	struct sk_buff *skb = csk->cpl_close;
3517b36b6e0Skxie@chelsio.com 	struct cpl_close_con_req *req = (struct cpl_close_con_req *)skb->head;
3527b36b6e0Skxie@chelsio.com 	unsigned int tid = csk->tid;
3537b36b6e0Skxie@chelsio.com 
3547b36b6e0Skxie@chelsio.com 	log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
3557b36b6e0Skxie@chelsio.com 		"csk 0x%p,%u,0x%lx, tid %u.\n",
3567b36b6e0Skxie@chelsio.com 		csk, csk->state, csk->flags, csk->tid);
3577b36b6e0Skxie@chelsio.com 	csk->cpl_close = NULL;
3587b36b6e0Skxie@chelsio.com 	set_wr_txq(skb, CPL_PRIORITY_DATA, csk->port_id);
3597b36b6e0Skxie@chelsio.com 	INIT_TP_WR(req, tid);
3607b36b6e0Skxie@chelsio.com 	OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_CLOSE_CON_REQ, tid));
3617b36b6e0Skxie@chelsio.com 	req->rsvd = 0;
3627b36b6e0Skxie@chelsio.com 
3637b36b6e0Skxie@chelsio.com 	cxgbi_sock_skb_entail(csk, skb);
3647b36b6e0Skxie@chelsio.com 	if (csk->state >= CTP_ESTABLISHED)
3657b36b6e0Skxie@chelsio.com 		push_tx_frames(csk, 1);
3667b36b6e0Skxie@chelsio.com }
3677b36b6e0Skxie@chelsio.com 
3687b36b6e0Skxie@chelsio.com static void abort_arp_failure(void *handle, struct sk_buff *skb)
3697b36b6e0Skxie@chelsio.com {
3707b36b6e0Skxie@chelsio.com 	struct cxgbi_sock *csk = (struct cxgbi_sock *)handle;
3717b36b6e0Skxie@chelsio.com 	struct cpl_abort_req *req;
3727b36b6e0Skxie@chelsio.com 
3737b36b6e0Skxie@chelsio.com 	log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
3747b36b6e0Skxie@chelsio.com 		"csk 0x%p,%u,0x%lx, tid %u, abort.\n",
3757b36b6e0Skxie@chelsio.com 		csk, csk->state, csk->flags, csk->tid);
3767b36b6e0Skxie@chelsio.com 	req = (struct cpl_abort_req *)skb->data;
3777b36b6e0Skxie@chelsio.com 	req->cmd = CPL_ABORT_NO_RST;
3787b36b6e0Skxie@chelsio.com 	cxgb4_ofld_send(csk->cdev->ports[csk->port_id], skb);
3797b36b6e0Skxie@chelsio.com }
3807b36b6e0Skxie@chelsio.com 
3817b36b6e0Skxie@chelsio.com static void send_abort_req(struct cxgbi_sock *csk)
3827b36b6e0Skxie@chelsio.com {
3837b36b6e0Skxie@chelsio.com 	struct cpl_abort_req *req;
3847b36b6e0Skxie@chelsio.com 	struct sk_buff *skb = csk->cpl_abort_req;
3857b36b6e0Skxie@chelsio.com 
3867b36b6e0Skxie@chelsio.com 	if (unlikely(csk->state == CTP_ABORTING) || !skb || !csk->cdev)
3877b36b6e0Skxie@chelsio.com 		return;
3887b36b6e0Skxie@chelsio.com 	cxgbi_sock_set_state(csk, CTP_ABORTING);
3897b36b6e0Skxie@chelsio.com 	cxgbi_sock_set_flag(csk, CTPF_ABORT_RPL_PENDING);
3907b36b6e0Skxie@chelsio.com 	cxgbi_sock_purge_write_queue(csk);
3917b36b6e0Skxie@chelsio.com 
3927b36b6e0Skxie@chelsio.com 	csk->cpl_abort_req = NULL;
3937b36b6e0Skxie@chelsio.com 	req = (struct cpl_abort_req *)skb->head;
3947b36b6e0Skxie@chelsio.com 	set_queue(skb, CPL_PRIORITY_DATA, csk);
3957b36b6e0Skxie@chelsio.com 	req->cmd = CPL_ABORT_SEND_RST;
3967b36b6e0Skxie@chelsio.com 	t4_set_arp_err_handler(skb, csk, abort_arp_failure);
3977b36b6e0Skxie@chelsio.com 	INIT_TP_WR(req, csk->tid);
3987b36b6e0Skxie@chelsio.com 	OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_ABORT_REQ, csk->tid));
3997b36b6e0Skxie@chelsio.com 	req->rsvd0 = htonl(csk->snd_nxt);
4007b36b6e0Skxie@chelsio.com 	req->rsvd1 = !cxgbi_sock_flag(csk, CTPF_TX_DATA_SENT);
4017b36b6e0Skxie@chelsio.com 
4027b36b6e0Skxie@chelsio.com 	log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
4037b36b6e0Skxie@chelsio.com 		"csk 0x%p,%u,0x%lx,%u, snd_nxt %u, 0x%x.\n",
4047b36b6e0Skxie@chelsio.com 		csk, csk->state, csk->flags, csk->tid, csk->snd_nxt,
4057b36b6e0Skxie@chelsio.com 		req->rsvd1);
4067b36b6e0Skxie@chelsio.com 
4077b36b6e0Skxie@chelsio.com 	cxgb4_l2t_send(csk->cdev->ports[csk->port_id], skb, csk->l2t);
4087b36b6e0Skxie@chelsio.com }
4097b36b6e0Skxie@chelsio.com 
4107b36b6e0Skxie@chelsio.com static void send_abort_rpl(struct cxgbi_sock *csk, int rst_status)
4117b36b6e0Skxie@chelsio.com {
4127b36b6e0Skxie@chelsio.com 	struct sk_buff *skb = csk->cpl_abort_rpl;
4137b36b6e0Skxie@chelsio.com 	struct cpl_abort_rpl *rpl = (struct cpl_abort_rpl *)skb->head;
4147b36b6e0Skxie@chelsio.com 
4157b36b6e0Skxie@chelsio.com 	log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
4167b36b6e0Skxie@chelsio.com 		"csk 0x%p,%u,0x%lx,%u, status %d.\n",
4177b36b6e0Skxie@chelsio.com 		csk, csk->state, csk->flags, csk->tid, rst_status);
4187b36b6e0Skxie@chelsio.com 
4197b36b6e0Skxie@chelsio.com 	csk->cpl_abort_rpl = NULL;
4207b36b6e0Skxie@chelsio.com 	set_queue(skb, CPL_PRIORITY_DATA, csk);
4217b36b6e0Skxie@chelsio.com 	INIT_TP_WR(rpl, csk->tid);
4227b36b6e0Skxie@chelsio.com 	OPCODE_TID(rpl) = cpu_to_be32(MK_OPCODE_TID(CPL_ABORT_RPL, csk->tid));
4237b36b6e0Skxie@chelsio.com 	rpl->cmd = rst_status;
4247b36b6e0Skxie@chelsio.com 	cxgb4_ofld_send(csk->cdev->ports[csk->port_id], skb);
4257b36b6e0Skxie@chelsio.com }
4267b36b6e0Skxie@chelsio.com 
4277b36b6e0Skxie@chelsio.com /*
4287b36b6e0Skxie@chelsio.com  * CPL connection rx data ack: host ->
4297b36b6e0Skxie@chelsio.com  * Send RX credits through an RX_DATA_ACK CPL message. Returns the number of
4307b36b6e0Skxie@chelsio.com  * credits sent.
4317b36b6e0Skxie@chelsio.com  */
4327b36b6e0Skxie@chelsio.com static u32 send_rx_credits(struct cxgbi_sock *csk, u32 credits)
4337b36b6e0Skxie@chelsio.com {
4347b36b6e0Skxie@chelsio.com 	struct sk_buff *skb;
4357b36b6e0Skxie@chelsio.com 	struct cpl_rx_data_ack *req;
4367b36b6e0Skxie@chelsio.com 
4377b36b6e0Skxie@chelsio.com 	log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_PDU_RX,
4387b36b6e0Skxie@chelsio.com 		"csk 0x%p,%u,0x%lx,%u, credit %u.\n",
4397b36b6e0Skxie@chelsio.com 		csk, csk->state, csk->flags, csk->tid, credits);
4407b36b6e0Skxie@chelsio.com 
44124d3f95aSkxie@chelsio.com 	skb = alloc_wr(sizeof(*req), 0, GFP_ATOMIC);
4427b36b6e0Skxie@chelsio.com 	if (!skb) {
4437b36b6e0Skxie@chelsio.com 		pr_info("csk 0x%p, credit %u, OOM.\n", csk, credits);
4447b36b6e0Skxie@chelsio.com 		return 0;
4457b36b6e0Skxie@chelsio.com 	}
4467b36b6e0Skxie@chelsio.com 	req = (struct cpl_rx_data_ack *)skb->head;
4477b36b6e0Skxie@chelsio.com 
4487b36b6e0Skxie@chelsio.com 	set_wr_txq(skb, CPL_PRIORITY_ACK, csk->port_id);
4497b36b6e0Skxie@chelsio.com 	INIT_TP_WR(req, csk->tid);
4507b36b6e0Skxie@chelsio.com 	OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_RX_DATA_ACK,
4517b36b6e0Skxie@chelsio.com 				      csk->tid));
4527b36b6e0Skxie@chelsio.com 	req->credit_dack = cpu_to_be32(RX_CREDITS(credits) | RX_FORCE_ACK(1));
4537b36b6e0Skxie@chelsio.com 	cxgb4_ofld_send(csk->cdev->ports[csk->port_id], skb);
4547b36b6e0Skxie@chelsio.com 	return credits;
4557b36b6e0Skxie@chelsio.com }
4567b36b6e0Skxie@chelsio.com 
4577b36b6e0Skxie@chelsio.com /*
4587b36b6e0Skxie@chelsio.com  * sgl_len - calculates the size of an SGL of the given capacity
4597b36b6e0Skxie@chelsio.com  * @n: the number of SGL entries
4607b36b6e0Skxie@chelsio.com  * Calculates the number of flits needed for a scatter/gather list that
4617b36b6e0Skxie@chelsio.com  * can hold the given number of entries.
4627b36b6e0Skxie@chelsio.com  */
4637b36b6e0Skxie@chelsio.com static inline unsigned int sgl_len(unsigned int n)
4647b36b6e0Skxie@chelsio.com {
4657b36b6e0Skxie@chelsio.com 	n--;
4667b36b6e0Skxie@chelsio.com 	return (3 * n) / 2 + (n & 1) + 2;
4677b36b6e0Skxie@chelsio.com }
4687b36b6e0Skxie@chelsio.com 
4697b36b6e0Skxie@chelsio.com /*
4707b36b6e0Skxie@chelsio.com  * calc_tx_flits_ofld - calculate # of flits for an offload packet
4717b36b6e0Skxie@chelsio.com  * @skb: the packet
4727b36b6e0Skxie@chelsio.com  *
4737b36b6e0Skxie@chelsio.com  * Returns the number of flits needed for the given offload packet.
4747b36b6e0Skxie@chelsio.com  * These packets are already fully constructed and no additional headers
4757b36b6e0Skxie@chelsio.com  * will be added.
4767b36b6e0Skxie@chelsio.com  */
4777b36b6e0Skxie@chelsio.com static inline unsigned int calc_tx_flits_ofld(const struct sk_buff *skb)
4787b36b6e0Skxie@chelsio.com {
4797b36b6e0Skxie@chelsio.com 	unsigned int flits, cnt;
4807b36b6e0Skxie@chelsio.com 
4817b36b6e0Skxie@chelsio.com 	if (is_ofld_imm(skb))
4827b36b6e0Skxie@chelsio.com 		return DIV_ROUND_UP(skb->len, 8);
4837b36b6e0Skxie@chelsio.com 	flits = skb_transport_offset(skb) / 8;
4847b36b6e0Skxie@chelsio.com 	cnt = skb_shinfo(skb)->nr_frags;
485499e2e6fSIsaku Yamahata 	if (skb_tail_pointer(skb) != skb_transport_header(skb))
4867b36b6e0Skxie@chelsio.com 		cnt++;
4877b36b6e0Skxie@chelsio.com 	return flits + sgl_len(cnt);
4887b36b6e0Skxie@chelsio.com }
4897b36b6e0Skxie@chelsio.com 
4907b36b6e0Skxie@chelsio.com static inline void send_tx_flowc_wr(struct cxgbi_sock *csk)
4917b36b6e0Skxie@chelsio.com {
4927b36b6e0Skxie@chelsio.com 	struct sk_buff *skb;
4937b36b6e0Skxie@chelsio.com 	struct fw_flowc_wr *flowc;
4947b36b6e0Skxie@chelsio.com 	int flowclen, i;
4957b36b6e0Skxie@chelsio.com 
4967b36b6e0Skxie@chelsio.com 	flowclen = 80;
49724d3f95aSkxie@chelsio.com 	skb = alloc_wr(flowclen, 0, GFP_ATOMIC);
4987b36b6e0Skxie@chelsio.com 	flowc = (struct fw_flowc_wr *)skb->head;
4997b36b6e0Skxie@chelsio.com 	flowc->op_to_nparams =
5007b36b6e0Skxie@chelsio.com 		htonl(FW_WR_OP(FW_FLOWC_WR) | FW_FLOWC_WR_NPARAMS(8));
5017b36b6e0Skxie@chelsio.com 	flowc->flowid_len16 =
5027b36b6e0Skxie@chelsio.com 		htonl(FW_WR_LEN16(DIV_ROUND_UP(72, 16)) |
5037b36b6e0Skxie@chelsio.com 				FW_WR_FLOWID(csk->tid));
5047b36b6e0Skxie@chelsio.com 	flowc->mnemval[0].mnemonic = FW_FLOWC_MNEM_PFNVFN;
505e27d6169Skxie@chelsio.com 	flowc->mnemval[0].val = htonl(csk->cdev->pfvf);
5067b36b6e0Skxie@chelsio.com 	flowc->mnemval[1].mnemonic = FW_FLOWC_MNEM_CH;
5077b36b6e0Skxie@chelsio.com 	flowc->mnemval[1].val = htonl(csk->tx_chan);
5087b36b6e0Skxie@chelsio.com 	flowc->mnemval[2].mnemonic = FW_FLOWC_MNEM_PORT;
5097b36b6e0Skxie@chelsio.com 	flowc->mnemval[2].val = htonl(csk->tx_chan);
5107b36b6e0Skxie@chelsio.com 	flowc->mnemval[3].mnemonic = FW_FLOWC_MNEM_IQID;
5117b36b6e0Skxie@chelsio.com 	flowc->mnemval[3].val = htonl(csk->rss_qid);
5127b36b6e0Skxie@chelsio.com 	flowc->mnemval[4].mnemonic = FW_FLOWC_MNEM_SNDNXT;
5137b36b6e0Skxie@chelsio.com 	flowc->mnemval[4].val = htonl(csk->snd_nxt);
5147b36b6e0Skxie@chelsio.com 	flowc->mnemval[5].mnemonic = FW_FLOWC_MNEM_RCVNXT;
5157b36b6e0Skxie@chelsio.com 	flowc->mnemval[5].val = htonl(csk->rcv_nxt);
5167b36b6e0Skxie@chelsio.com 	flowc->mnemval[6].mnemonic = FW_FLOWC_MNEM_SNDBUF;
5177b36b6e0Skxie@chelsio.com 	flowc->mnemval[6].val = htonl(cxgb4i_snd_win);
5187b36b6e0Skxie@chelsio.com 	flowc->mnemval[7].mnemonic = FW_FLOWC_MNEM_MSS;
5197b36b6e0Skxie@chelsio.com 	flowc->mnemval[7].val = htonl(csk->advmss);
5207b36b6e0Skxie@chelsio.com 	flowc->mnemval[8].mnemonic = 0;
5217b36b6e0Skxie@chelsio.com 	flowc->mnemval[8].val = 0;
5227b36b6e0Skxie@chelsio.com 	for (i = 0; i < 9; i++) {
5237b36b6e0Skxie@chelsio.com 		flowc->mnemval[i].r4[0] = 0;
5247b36b6e0Skxie@chelsio.com 		flowc->mnemval[i].r4[1] = 0;
5257b36b6e0Skxie@chelsio.com 		flowc->mnemval[i].r4[2] = 0;
5267b36b6e0Skxie@chelsio.com 	}
5277b36b6e0Skxie@chelsio.com 	set_queue(skb, CPL_PRIORITY_DATA, csk);
5287b36b6e0Skxie@chelsio.com 
5297b36b6e0Skxie@chelsio.com 	log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
5307b36b6e0Skxie@chelsio.com 		"csk 0x%p, tid 0x%x, %u,%u,%u,%u,%u,%u,%u.\n",
5317b36b6e0Skxie@chelsio.com 		csk, csk->tid, 0, csk->tx_chan, csk->rss_qid,
5327b36b6e0Skxie@chelsio.com 		csk->snd_nxt, csk->rcv_nxt, cxgb4i_snd_win,
5337b36b6e0Skxie@chelsio.com 		csk->advmss);
5347b36b6e0Skxie@chelsio.com 
5357b36b6e0Skxie@chelsio.com 	cxgb4_ofld_send(csk->cdev->ports[csk->port_id], skb);
5367b36b6e0Skxie@chelsio.com }
5377b36b6e0Skxie@chelsio.com 
5387b36b6e0Skxie@chelsio.com static inline void make_tx_data_wr(struct cxgbi_sock *csk, struct sk_buff *skb,
5397b36b6e0Skxie@chelsio.com 				   int dlen, int len, u32 credits, int compl)
5407b36b6e0Skxie@chelsio.com {
5417b36b6e0Skxie@chelsio.com 	struct fw_ofld_tx_data_wr *req;
5427b36b6e0Skxie@chelsio.com 	unsigned int submode = cxgbi_skcb_ulp_mode(skb) & 3;
5437b36b6e0Skxie@chelsio.com 	unsigned int wr_ulp_mode = 0;
5447b36b6e0Skxie@chelsio.com 
5457b36b6e0Skxie@chelsio.com 	req = (struct fw_ofld_tx_data_wr *)__skb_push(skb, sizeof(*req));
5467b36b6e0Skxie@chelsio.com 
5477b36b6e0Skxie@chelsio.com 	if (is_ofld_imm(skb)) {
5487b36b6e0Skxie@chelsio.com 		req->op_to_immdlen = htonl(FW_WR_OP(FW_OFLD_TX_DATA_WR) |
5497b36b6e0Skxie@chelsio.com 					FW_WR_COMPL(1) |
5507b36b6e0Skxie@chelsio.com 					FW_WR_IMMDLEN(dlen));
5517b36b6e0Skxie@chelsio.com 		req->flowid_len16 = htonl(FW_WR_FLOWID(csk->tid) |
5527b36b6e0Skxie@chelsio.com 						FW_WR_LEN16(credits));
5537b36b6e0Skxie@chelsio.com 	} else {
5547b36b6e0Skxie@chelsio.com 		req->op_to_immdlen =
5557b36b6e0Skxie@chelsio.com 			cpu_to_be32(FW_WR_OP(FW_OFLD_TX_DATA_WR) |
5567b36b6e0Skxie@chelsio.com 					FW_WR_COMPL(1) |
5577b36b6e0Skxie@chelsio.com 					FW_WR_IMMDLEN(0));
5587b36b6e0Skxie@chelsio.com 		req->flowid_len16 =
5597b36b6e0Skxie@chelsio.com 			cpu_to_be32(FW_WR_FLOWID(csk->tid) |
5607b36b6e0Skxie@chelsio.com 					FW_WR_LEN16(credits));
5617b36b6e0Skxie@chelsio.com 	}
5627b36b6e0Skxie@chelsio.com 	if (submode)
5637b36b6e0Skxie@chelsio.com 		wr_ulp_mode = FW_OFLD_TX_DATA_WR_ULPMODE(ULP2_MODE_ISCSI) |
5647b36b6e0Skxie@chelsio.com 				FW_OFLD_TX_DATA_WR_ULPSUBMODE(submode);
5656aca4112SKaren Xie 	req->tunnel_to_proxy = htonl(wr_ulp_mode |
5666aca4112SKaren Xie 		 FW_OFLD_TX_DATA_WR_SHOVE(skb_peek(&csk->write_queue) ? 0 : 1));
5677b36b6e0Skxie@chelsio.com 	req->plen = htonl(len);
5687b36b6e0Skxie@chelsio.com 	if (!cxgbi_sock_flag(csk, CTPF_TX_DATA_SENT))
5697b36b6e0Skxie@chelsio.com 		cxgbi_sock_set_flag(csk, CTPF_TX_DATA_SENT);
5707b36b6e0Skxie@chelsio.com }
5717b36b6e0Skxie@chelsio.com 
5727b36b6e0Skxie@chelsio.com static void arp_failure_skb_discard(void *handle, struct sk_buff *skb)
5737b36b6e0Skxie@chelsio.com {
5747b36b6e0Skxie@chelsio.com 	kfree_skb(skb);
5757b36b6e0Skxie@chelsio.com }
5767b36b6e0Skxie@chelsio.com 
5777b36b6e0Skxie@chelsio.com static int push_tx_frames(struct cxgbi_sock *csk, int req_completion)
5787b36b6e0Skxie@chelsio.com {
5797b36b6e0Skxie@chelsio.com 	int total_size = 0;
5807b36b6e0Skxie@chelsio.com 	struct sk_buff *skb;
5817b36b6e0Skxie@chelsio.com 
5827b36b6e0Skxie@chelsio.com 	if (unlikely(csk->state < CTP_ESTABLISHED ||
5837b36b6e0Skxie@chelsio.com 		csk->state == CTP_CLOSE_WAIT_1 || csk->state >= CTP_ABORTING)) {
5847b36b6e0Skxie@chelsio.com 		log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK |
5857b36b6e0Skxie@chelsio.com 			 1 << CXGBI_DBG_PDU_TX,
5867b36b6e0Skxie@chelsio.com 			"csk 0x%p,%u,0x%lx,%u, in closing state.\n",
5877b36b6e0Skxie@chelsio.com 			csk, csk->state, csk->flags, csk->tid);
5887b36b6e0Skxie@chelsio.com 		return 0;
5897b36b6e0Skxie@chelsio.com 	}
5907b36b6e0Skxie@chelsio.com 
5917b36b6e0Skxie@chelsio.com 	while (csk->wr_cred && (skb = skb_peek(&csk->write_queue)) != NULL) {
5927b36b6e0Skxie@chelsio.com 		int dlen = skb->len;
5937b36b6e0Skxie@chelsio.com 		int len = skb->len;
5947b36b6e0Skxie@chelsio.com 		unsigned int credits_needed;
5957b36b6e0Skxie@chelsio.com 
5967b36b6e0Skxie@chelsio.com 		skb_reset_transport_header(skb);
5977b36b6e0Skxie@chelsio.com 		if (is_ofld_imm(skb))
5987b36b6e0Skxie@chelsio.com 			credits_needed = DIV_ROUND_UP(dlen +
5997b36b6e0Skxie@chelsio.com 					sizeof(struct fw_ofld_tx_data_wr), 16);
6007b36b6e0Skxie@chelsio.com 		else
6017b36b6e0Skxie@chelsio.com 			credits_needed = DIV_ROUND_UP(8*calc_tx_flits_ofld(skb)
6027b36b6e0Skxie@chelsio.com 					+ sizeof(struct fw_ofld_tx_data_wr),
6037b36b6e0Skxie@chelsio.com 					16);
6047b36b6e0Skxie@chelsio.com 
6057b36b6e0Skxie@chelsio.com 		if (csk->wr_cred < credits_needed) {
6067b36b6e0Skxie@chelsio.com 			log_debug(1 << CXGBI_DBG_PDU_TX,
6077b36b6e0Skxie@chelsio.com 				"csk 0x%p, skb %u/%u, wr %d < %u.\n",
6087b36b6e0Skxie@chelsio.com 				csk, skb->len, skb->data_len,
6097b36b6e0Skxie@chelsio.com 				credits_needed, csk->wr_cred);
6107b36b6e0Skxie@chelsio.com 			break;
6117b36b6e0Skxie@chelsio.com 		}
6127b36b6e0Skxie@chelsio.com 		__skb_unlink(skb, &csk->write_queue);
6137b36b6e0Skxie@chelsio.com 		set_queue(skb, CPL_PRIORITY_DATA, csk);
6147b36b6e0Skxie@chelsio.com 		skb->csum = credits_needed;
6157b36b6e0Skxie@chelsio.com 		csk->wr_cred -= credits_needed;
6167b36b6e0Skxie@chelsio.com 		csk->wr_una_cred += credits_needed;
6177b36b6e0Skxie@chelsio.com 		cxgbi_sock_enqueue_wr(csk, skb);
6187b36b6e0Skxie@chelsio.com 
6197b36b6e0Skxie@chelsio.com 		log_debug(1 << CXGBI_DBG_PDU_TX,
6207b36b6e0Skxie@chelsio.com 			"csk 0x%p, skb %u/%u, wr %d, left %u, unack %u.\n",
6217b36b6e0Skxie@chelsio.com 			csk, skb->len, skb->data_len, credits_needed,
6227b36b6e0Skxie@chelsio.com 			csk->wr_cred, csk->wr_una_cred);
6237b36b6e0Skxie@chelsio.com 
6247b36b6e0Skxie@chelsio.com 		if (likely(cxgbi_skcb_test_flag(skb, SKCBF_TX_NEED_HDR))) {
6257b36b6e0Skxie@chelsio.com 			if (!cxgbi_sock_flag(csk, CTPF_TX_DATA_SENT)) {
6267b36b6e0Skxie@chelsio.com 				send_tx_flowc_wr(csk);
6277b36b6e0Skxie@chelsio.com 				skb->csum += 5;
6287b36b6e0Skxie@chelsio.com 				csk->wr_cred -= 5;
6297b36b6e0Skxie@chelsio.com 				csk->wr_una_cred += 5;
6307b36b6e0Skxie@chelsio.com 			}
6317b36b6e0Skxie@chelsio.com 			len += cxgbi_ulp_extra_len(cxgbi_skcb_ulp_mode(skb));
6327b36b6e0Skxie@chelsio.com 			make_tx_data_wr(csk, skb, dlen, len, credits_needed,
6337b36b6e0Skxie@chelsio.com 					req_completion);
6347b36b6e0Skxie@chelsio.com 			csk->snd_nxt += len;
6357b36b6e0Skxie@chelsio.com 			cxgbi_skcb_clear_flag(skb, SKCBF_TX_NEED_HDR);
6367b36b6e0Skxie@chelsio.com 		}
6377b36b6e0Skxie@chelsio.com 		total_size += skb->truesize;
6387b36b6e0Skxie@chelsio.com 		t4_set_arp_err_handler(skb, csk, arp_failure_skb_discard);
6397b36b6e0Skxie@chelsio.com 
6407b36b6e0Skxie@chelsio.com 		log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_PDU_TX,
6417b36b6e0Skxie@chelsio.com 			"csk 0x%p,%u,0x%lx,%u, skb 0x%p, %u.\n",
6427b36b6e0Skxie@chelsio.com 			csk, csk->state, csk->flags, csk->tid, skb, len);
6437b36b6e0Skxie@chelsio.com 
6447b36b6e0Skxie@chelsio.com 		cxgb4_l2t_send(csk->cdev->ports[csk->port_id], skb, csk->l2t);
6457b36b6e0Skxie@chelsio.com 	}
6467b36b6e0Skxie@chelsio.com 	return total_size;
6477b36b6e0Skxie@chelsio.com }
6487b36b6e0Skxie@chelsio.com 
6497b36b6e0Skxie@chelsio.com static inline void free_atid(struct cxgbi_sock *csk)
6507b36b6e0Skxie@chelsio.com {
6517b36b6e0Skxie@chelsio.com 	struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(csk->cdev);
6527b36b6e0Skxie@chelsio.com 
6537b36b6e0Skxie@chelsio.com 	if (cxgbi_sock_flag(csk, CTPF_HAS_ATID)) {
6547b36b6e0Skxie@chelsio.com 		cxgb4_free_atid(lldi->tids, csk->atid);
6557b36b6e0Skxie@chelsio.com 		cxgbi_sock_clear_flag(csk, CTPF_HAS_ATID);
6567b36b6e0Skxie@chelsio.com 		cxgbi_sock_put(csk);
6577b36b6e0Skxie@chelsio.com 	}
6587b36b6e0Skxie@chelsio.com }
6597b36b6e0Skxie@chelsio.com 
6607b36b6e0Skxie@chelsio.com static void do_act_establish(struct cxgbi_device *cdev, struct sk_buff *skb)
6617b36b6e0Skxie@chelsio.com {
6627b36b6e0Skxie@chelsio.com 	struct cxgbi_sock *csk;
6637b36b6e0Skxie@chelsio.com 	struct cpl_act_establish *req = (struct cpl_act_establish *)skb->data;
6647b36b6e0Skxie@chelsio.com 	unsigned short tcp_opt = ntohs(req->tcp_opt);
6657b36b6e0Skxie@chelsio.com 	unsigned int tid = GET_TID(req);
6667b36b6e0Skxie@chelsio.com 	unsigned int atid = GET_TID_TID(ntohl(req->tos_atid));
6677b36b6e0Skxie@chelsio.com 	struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(cdev);
6687b36b6e0Skxie@chelsio.com 	struct tid_info *t = lldi->tids;
6697b36b6e0Skxie@chelsio.com 	u32 rcv_isn = be32_to_cpu(req->rcv_isn);
6707b36b6e0Skxie@chelsio.com 
6717b36b6e0Skxie@chelsio.com 	csk = lookup_atid(t, atid);
6727b36b6e0Skxie@chelsio.com 	if (unlikely(!csk)) {
6737b36b6e0Skxie@chelsio.com 		pr_err("NO conn. for atid %u, cdev 0x%p.\n", atid, cdev);
6747b36b6e0Skxie@chelsio.com 		goto rel_skb;
6757b36b6e0Skxie@chelsio.com 	}
6767b36b6e0Skxie@chelsio.com 
677e27d6169Skxie@chelsio.com 	if (csk->atid != atid) {
678e27d6169Skxie@chelsio.com 		pr_err("bad conn atid %u, csk 0x%p,%u,0x%lx,tid %u, atid %u.\n",
679e27d6169Skxie@chelsio.com 			atid, csk, csk->state, csk->flags, csk->tid, csk->atid);
680e27d6169Skxie@chelsio.com 		goto rel_skb;
681e27d6169Skxie@chelsio.com 	}
682e27d6169Skxie@chelsio.com 
683759a0cc5SAnish Bhatt 	pr_info_ipaddr("atid 0x%x, tid 0x%x, csk 0x%p,%u,0x%lx, isn %u.\n",
684759a0cc5SAnish Bhatt 		       (&csk->saddr), (&csk->daddr),
685759a0cc5SAnish Bhatt 		       atid, tid, csk, csk->state, csk->flags, rcv_isn);
686759a0cc5SAnish Bhatt 
687759a0cc5SAnish Bhatt 	module_put(THIS_MODULE);
6887b36b6e0Skxie@chelsio.com 
6897b36b6e0Skxie@chelsio.com 	cxgbi_sock_get(csk);
6907b36b6e0Skxie@chelsio.com 	csk->tid = tid;
6917b36b6e0Skxie@chelsio.com 	cxgb4_insert_tid(lldi->tids, csk, tid);
6927b36b6e0Skxie@chelsio.com 	cxgbi_sock_set_flag(csk, CTPF_HAS_TID);
6937b36b6e0Skxie@chelsio.com 
6947b36b6e0Skxie@chelsio.com 	free_atid(csk);
6957b36b6e0Skxie@chelsio.com 
6967b36b6e0Skxie@chelsio.com 	spin_lock_bh(&csk->lock);
6977b36b6e0Skxie@chelsio.com 	if (unlikely(csk->state != CTP_ACTIVE_OPEN))
6987b36b6e0Skxie@chelsio.com 		pr_info("csk 0x%p,%u,0x%lx,%u, got EST.\n",
6997b36b6e0Skxie@chelsio.com 			csk, csk->state, csk->flags, csk->tid);
7007b36b6e0Skxie@chelsio.com 
7017b36b6e0Skxie@chelsio.com 	if (csk->retry_timer.function) {
7027b36b6e0Skxie@chelsio.com 		del_timer(&csk->retry_timer);
7037b36b6e0Skxie@chelsio.com 		csk->retry_timer.function = NULL;
7047b36b6e0Skxie@chelsio.com 	}
7057b36b6e0Skxie@chelsio.com 
7067b36b6e0Skxie@chelsio.com 	csk->copied_seq = csk->rcv_wup = csk->rcv_nxt = rcv_isn;
7077b36b6e0Skxie@chelsio.com 	/*
7087b36b6e0Skxie@chelsio.com 	 * Causes the first RX_DATA_ACK to supply any Rx credits we couldn't
7097b36b6e0Skxie@chelsio.com 	 * pass through opt0.
7107b36b6e0Skxie@chelsio.com 	 */
7117b36b6e0Skxie@chelsio.com 	if (cxgb4i_rcv_win > (RCV_BUFSIZ_MASK << 10))
7127b36b6e0Skxie@chelsio.com 		csk->rcv_wup -= cxgb4i_rcv_win - (RCV_BUFSIZ_MASK << 10);
7137b36b6e0Skxie@chelsio.com 
7147b36b6e0Skxie@chelsio.com 	csk->advmss = lldi->mtus[GET_TCPOPT_MSS(tcp_opt)] - 40;
7157b36b6e0Skxie@chelsio.com 	if (GET_TCPOPT_TSTAMP(tcp_opt))
7167b36b6e0Skxie@chelsio.com 		csk->advmss -= 12;
7177b36b6e0Skxie@chelsio.com 	if (csk->advmss < 128)
7187b36b6e0Skxie@chelsio.com 		csk->advmss = 128;
7197b36b6e0Skxie@chelsio.com 
7207b36b6e0Skxie@chelsio.com 	log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
7217b36b6e0Skxie@chelsio.com 		"csk 0x%p, mss_idx %u, advmss %u.\n",
7227b36b6e0Skxie@chelsio.com 			csk, GET_TCPOPT_MSS(tcp_opt), csk->advmss);
7237b36b6e0Skxie@chelsio.com 
7247b36b6e0Skxie@chelsio.com 	cxgbi_sock_established(csk, ntohl(req->snd_isn), ntohs(req->tcp_opt));
7257b36b6e0Skxie@chelsio.com 
7267b36b6e0Skxie@chelsio.com 	if (unlikely(cxgbi_sock_flag(csk, CTPF_ACTIVE_CLOSE_NEEDED)))
7277b36b6e0Skxie@chelsio.com 		send_abort_req(csk);
7287b36b6e0Skxie@chelsio.com 	else {
7297b36b6e0Skxie@chelsio.com 		if (skb_queue_len(&csk->write_queue))
7307b36b6e0Skxie@chelsio.com 			push_tx_frames(csk, 0);
7317b36b6e0Skxie@chelsio.com 		cxgbi_conn_tx_open(csk);
7327b36b6e0Skxie@chelsio.com 	}
7337b36b6e0Skxie@chelsio.com 	spin_unlock_bh(&csk->lock);
7347b36b6e0Skxie@chelsio.com 
7357b36b6e0Skxie@chelsio.com rel_skb:
7367b36b6e0Skxie@chelsio.com 	__kfree_skb(skb);
7377b36b6e0Skxie@chelsio.com }
7387b36b6e0Skxie@chelsio.com 
7397b36b6e0Skxie@chelsio.com static int act_open_rpl_status_to_errno(int status)
7407b36b6e0Skxie@chelsio.com {
7417b36b6e0Skxie@chelsio.com 	switch (status) {
7427b36b6e0Skxie@chelsio.com 	case CPL_ERR_CONN_RESET:
7437b36b6e0Skxie@chelsio.com 		return -ECONNREFUSED;
7447b36b6e0Skxie@chelsio.com 	case CPL_ERR_ARP_MISS:
7457b36b6e0Skxie@chelsio.com 		return -EHOSTUNREACH;
7467b36b6e0Skxie@chelsio.com 	case CPL_ERR_CONN_TIMEDOUT:
7477b36b6e0Skxie@chelsio.com 		return -ETIMEDOUT;
7487b36b6e0Skxie@chelsio.com 	case CPL_ERR_TCAM_FULL:
7497b36b6e0Skxie@chelsio.com 		return -ENOMEM;
7507b36b6e0Skxie@chelsio.com 	case CPL_ERR_CONN_EXIST:
7517b36b6e0Skxie@chelsio.com 		return -EADDRINUSE;
7527b36b6e0Skxie@chelsio.com 	default:
7537b36b6e0Skxie@chelsio.com 		return -EIO;
7547b36b6e0Skxie@chelsio.com 	}
7557b36b6e0Skxie@chelsio.com }
7567b36b6e0Skxie@chelsio.com 
7577b36b6e0Skxie@chelsio.com static void csk_act_open_retry_timer(unsigned long data)
7587b36b6e0Skxie@chelsio.com {
7597b36b6e0Skxie@chelsio.com 	struct sk_buff *skb;
7607b36b6e0Skxie@chelsio.com 	struct cxgbi_sock *csk = (struct cxgbi_sock *)data;
7613bd3e8bfSKaren Xie 	struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(csk->cdev);
762759a0cc5SAnish Bhatt 	void (*send_act_open_func)(struct cxgbi_sock *, struct sk_buff *,
763759a0cc5SAnish Bhatt 				   struct l2t_entry *);
764759a0cc5SAnish Bhatt 	int t4 = is_t4(lldi->adapter_type), size, size6;
7657b36b6e0Skxie@chelsio.com 
7667b36b6e0Skxie@chelsio.com 	log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
7677b36b6e0Skxie@chelsio.com 		"csk 0x%p,%u,0x%lx,%u.\n",
7687b36b6e0Skxie@chelsio.com 		csk, csk->state, csk->flags, csk->tid);
7697b36b6e0Skxie@chelsio.com 
7707b36b6e0Skxie@chelsio.com 	cxgbi_sock_get(csk);
7717b36b6e0Skxie@chelsio.com 	spin_lock_bh(&csk->lock);
772759a0cc5SAnish Bhatt 
773759a0cc5SAnish Bhatt 	if (t4) {
774759a0cc5SAnish Bhatt 		size = sizeof(struct cpl_act_open_req);
775759a0cc5SAnish Bhatt 		size6 = sizeof(struct cpl_act_open_req6);
776759a0cc5SAnish Bhatt 	} else {
777759a0cc5SAnish Bhatt 		size = sizeof(struct cpl_t5_act_open_req);
778759a0cc5SAnish Bhatt 		size6 = sizeof(struct cpl_t5_act_open_req6);
779759a0cc5SAnish Bhatt 	}
780759a0cc5SAnish Bhatt 
781759a0cc5SAnish Bhatt 	if (csk->csk_family == AF_INET) {
782759a0cc5SAnish Bhatt 		send_act_open_func = send_act_open_req;
783759a0cc5SAnish Bhatt 		skb = alloc_wr(size, 0, GFP_ATOMIC);
784759a0cc5SAnish Bhatt 	} else {
785759a0cc5SAnish Bhatt 		send_act_open_func = send_act_open_req6;
786759a0cc5SAnish Bhatt 		skb = alloc_wr(size6, 0, GFP_ATOMIC);
787759a0cc5SAnish Bhatt 	}
788759a0cc5SAnish Bhatt 
7897b36b6e0Skxie@chelsio.com 	if (!skb)
7907b36b6e0Skxie@chelsio.com 		cxgbi_sock_fail_act_open(csk, -ENOMEM);
7917b36b6e0Skxie@chelsio.com 	else {
7927b36b6e0Skxie@chelsio.com 		skb->sk = (struct sock *)csk;
7937b36b6e0Skxie@chelsio.com 		t4_set_arp_err_handler(skb, csk,
7947b36b6e0Skxie@chelsio.com 				       cxgbi_sock_act_open_req_arp_failure);
795759a0cc5SAnish Bhatt 		send_act_open_func(csk, skb, csk->l2t);
7967b36b6e0Skxie@chelsio.com 	}
797759a0cc5SAnish Bhatt 
7987b36b6e0Skxie@chelsio.com 	spin_unlock_bh(&csk->lock);
7997b36b6e0Skxie@chelsio.com 	cxgbi_sock_put(csk);
800759a0cc5SAnish Bhatt 
8017b36b6e0Skxie@chelsio.com }
8027b36b6e0Skxie@chelsio.com 
8037b36b6e0Skxie@chelsio.com static void do_act_open_rpl(struct cxgbi_device *cdev, struct sk_buff *skb)
8047b36b6e0Skxie@chelsio.com {
8057b36b6e0Skxie@chelsio.com 	struct cxgbi_sock *csk;
8067b36b6e0Skxie@chelsio.com 	struct cpl_act_open_rpl *rpl = (struct cpl_act_open_rpl *)skb->data;
8077b36b6e0Skxie@chelsio.com 	unsigned int tid = GET_TID(rpl);
8087b36b6e0Skxie@chelsio.com 	unsigned int atid =
8097b36b6e0Skxie@chelsio.com 		GET_TID_TID(GET_AOPEN_ATID(be32_to_cpu(rpl->atid_status)));
8107b36b6e0Skxie@chelsio.com 	unsigned int status = GET_AOPEN_STATUS(be32_to_cpu(rpl->atid_status));
8117b36b6e0Skxie@chelsio.com 	struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(cdev);
8127b36b6e0Skxie@chelsio.com 	struct tid_info *t = lldi->tids;
8137b36b6e0Skxie@chelsio.com 
8147b36b6e0Skxie@chelsio.com 	csk = lookup_atid(t, atid);
8157b36b6e0Skxie@chelsio.com 	if (unlikely(!csk)) {
8167b36b6e0Skxie@chelsio.com 		pr_err("NO matching conn. atid %u, tid %u.\n", atid, tid);
8177b36b6e0Skxie@chelsio.com 		goto rel_skb;
8187b36b6e0Skxie@chelsio.com 	}
8197b36b6e0Skxie@chelsio.com 
820759a0cc5SAnish Bhatt 	pr_info_ipaddr("tid %u/%u, status %u.\n"
821759a0cc5SAnish Bhatt 		       "csk 0x%p,%u,0x%lx. ", (&csk->saddr), (&csk->daddr),
822e27d6169Skxie@chelsio.com 		       atid, tid, status, csk, csk->state, csk->flags);
8237b36b6e0Skxie@chelsio.com 
824150cca7cSKaren Xie 	if (status == CPL_ERR_RTX_NEG_ADVICE)
825150cca7cSKaren Xie 		goto rel_skb;
826150cca7cSKaren Xie 
8277b36b6e0Skxie@chelsio.com 	if (status && status != CPL_ERR_TCAM_FULL &&
8287b36b6e0Skxie@chelsio.com 	    status != CPL_ERR_CONN_EXIST &&
8297b36b6e0Skxie@chelsio.com 	    status != CPL_ERR_ARP_MISS)
8307b36b6e0Skxie@chelsio.com 		cxgb4_remove_tid(lldi->tids, csk->port_id, GET_TID(rpl));
8317b36b6e0Skxie@chelsio.com 
8327b36b6e0Skxie@chelsio.com 	cxgbi_sock_get(csk);
8337b36b6e0Skxie@chelsio.com 	spin_lock_bh(&csk->lock);
8347b36b6e0Skxie@chelsio.com 
8357b36b6e0Skxie@chelsio.com 	if (status == CPL_ERR_CONN_EXIST &&
8367b36b6e0Skxie@chelsio.com 	    csk->retry_timer.function != csk_act_open_retry_timer) {
8377b36b6e0Skxie@chelsio.com 		csk->retry_timer.function = csk_act_open_retry_timer;
8387b36b6e0Skxie@chelsio.com 		mod_timer(&csk->retry_timer, jiffies + HZ / 2);
8397b36b6e0Skxie@chelsio.com 	} else
8407b36b6e0Skxie@chelsio.com 		cxgbi_sock_fail_act_open(csk,
8417b36b6e0Skxie@chelsio.com 					act_open_rpl_status_to_errno(status));
8427b36b6e0Skxie@chelsio.com 
8437b36b6e0Skxie@chelsio.com 	spin_unlock_bh(&csk->lock);
8447b36b6e0Skxie@chelsio.com 	cxgbi_sock_put(csk);
8457b36b6e0Skxie@chelsio.com rel_skb:
8467b36b6e0Skxie@chelsio.com 	__kfree_skb(skb);
8477b36b6e0Skxie@chelsio.com }
8487b36b6e0Skxie@chelsio.com 
8497b36b6e0Skxie@chelsio.com static void do_peer_close(struct cxgbi_device *cdev, struct sk_buff *skb)
8507b36b6e0Skxie@chelsio.com {
8517b36b6e0Skxie@chelsio.com 	struct cxgbi_sock *csk;
8527b36b6e0Skxie@chelsio.com 	struct cpl_peer_close *req = (struct cpl_peer_close *)skb->data;
8537b36b6e0Skxie@chelsio.com 	unsigned int tid = GET_TID(req);
8547b36b6e0Skxie@chelsio.com 	struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(cdev);
8557b36b6e0Skxie@chelsio.com 	struct tid_info *t = lldi->tids;
8567b36b6e0Skxie@chelsio.com 
8577b36b6e0Skxie@chelsio.com 	csk = lookup_tid(t, tid);
8587b36b6e0Skxie@chelsio.com 	if (unlikely(!csk)) {
8597b36b6e0Skxie@chelsio.com 		pr_err("can't find connection for tid %u.\n", tid);
8607b36b6e0Skxie@chelsio.com 		goto rel_skb;
8617b36b6e0Skxie@chelsio.com 	}
862759a0cc5SAnish Bhatt 	pr_info_ipaddr("csk 0x%p,%u,0x%lx,%u.\n",
863759a0cc5SAnish Bhatt 		       (&csk->saddr), (&csk->daddr),
8647b36b6e0Skxie@chelsio.com 		       csk, csk->state, csk->flags, csk->tid);
8657b36b6e0Skxie@chelsio.com 	cxgbi_sock_rcv_peer_close(csk);
8667b36b6e0Skxie@chelsio.com rel_skb:
8677b36b6e0Skxie@chelsio.com 	__kfree_skb(skb);
8687b36b6e0Skxie@chelsio.com }
8697b36b6e0Skxie@chelsio.com 
8707b36b6e0Skxie@chelsio.com static void do_close_con_rpl(struct cxgbi_device *cdev, struct sk_buff *skb)
8717b36b6e0Skxie@chelsio.com {
8727b36b6e0Skxie@chelsio.com 	struct cxgbi_sock *csk;
8737b36b6e0Skxie@chelsio.com 	struct cpl_close_con_rpl *rpl = (struct cpl_close_con_rpl *)skb->data;
8747b36b6e0Skxie@chelsio.com 	unsigned int tid = GET_TID(rpl);
8757b36b6e0Skxie@chelsio.com 	struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(cdev);
8767b36b6e0Skxie@chelsio.com 	struct tid_info *t = lldi->tids;
8777b36b6e0Skxie@chelsio.com 
8787b36b6e0Skxie@chelsio.com 	csk = lookup_tid(t, tid);
8797b36b6e0Skxie@chelsio.com 	if (unlikely(!csk)) {
8807b36b6e0Skxie@chelsio.com 		pr_err("can't find connection for tid %u.\n", tid);
8817b36b6e0Skxie@chelsio.com 		goto rel_skb;
8827b36b6e0Skxie@chelsio.com 	}
883759a0cc5SAnish Bhatt 	pr_info_ipaddr("csk 0x%p,%u,0x%lx,%u.\n",
884759a0cc5SAnish Bhatt 		       (&csk->saddr), (&csk->daddr),
8857b36b6e0Skxie@chelsio.com 		       csk, csk->state, csk->flags, csk->tid);
8867b36b6e0Skxie@chelsio.com 	cxgbi_sock_rcv_close_conn_rpl(csk, ntohl(rpl->snd_nxt));
8877b36b6e0Skxie@chelsio.com rel_skb:
8887b36b6e0Skxie@chelsio.com 	__kfree_skb(skb);
8897b36b6e0Skxie@chelsio.com }
8907b36b6e0Skxie@chelsio.com 
8917b36b6e0Skxie@chelsio.com static int abort_status_to_errno(struct cxgbi_sock *csk, int abort_reason,
8927b36b6e0Skxie@chelsio.com 								int *need_rst)
8937b36b6e0Skxie@chelsio.com {
8947b36b6e0Skxie@chelsio.com 	switch (abort_reason) {
8957b36b6e0Skxie@chelsio.com 	case CPL_ERR_BAD_SYN: /* fall through */
8967b36b6e0Skxie@chelsio.com 	case CPL_ERR_CONN_RESET:
8977b36b6e0Skxie@chelsio.com 		return csk->state > CTP_ESTABLISHED ?
8987b36b6e0Skxie@chelsio.com 			-EPIPE : -ECONNRESET;
8997b36b6e0Skxie@chelsio.com 	case CPL_ERR_XMIT_TIMEDOUT:
9007b36b6e0Skxie@chelsio.com 	case CPL_ERR_PERSIST_TIMEDOUT:
9017b36b6e0Skxie@chelsio.com 	case CPL_ERR_FINWAIT2_TIMEDOUT:
9027b36b6e0Skxie@chelsio.com 	case CPL_ERR_KEEPALIVE_TIMEDOUT:
9037b36b6e0Skxie@chelsio.com 		return -ETIMEDOUT;
9047b36b6e0Skxie@chelsio.com 	default:
9057b36b6e0Skxie@chelsio.com 		return -EIO;
9067b36b6e0Skxie@chelsio.com 	}
9077b36b6e0Skxie@chelsio.com }
9087b36b6e0Skxie@chelsio.com 
9097b36b6e0Skxie@chelsio.com static void do_abort_req_rss(struct cxgbi_device *cdev, struct sk_buff *skb)
9107b36b6e0Skxie@chelsio.com {
9117b36b6e0Skxie@chelsio.com 	struct cxgbi_sock *csk;
9127b36b6e0Skxie@chelsio.com 	struct cpl_abort_req_rss *req = (struct cpl_abort_req_rss *)skb->data;
9137b36b6e0Skxie@chelsio.com 	unsigned int tid = GET_TID(req);
9147b36b6e0Skxie@chelsio.com 	struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(cdev);
9157b36b6e0Skxie@chelsio.com 	struct tid_info *t = lldi->tids;
9167b36b6e0Skxie@chelsio.com 	int rst_status = CPL_ABORT_NO_RST;
9177b36b6e0Skxie@chelsio.com 
9187b36b6e0Skxie@chelsio.com 	csk = lookup_tid(t, tid);
9197b36b6e0Skxie@chelsio.com 	if (unlikely(!csk)) {
9207b36b6e0Skxie@chelsio.com 		pr_err("can't find connection for tid %u.\n", tid);
9217b36b6e0Skxie@chelsio.com 		goto rel_skb;
9227b36b6e0Skxie@chelsio.com 	}
9237b36b6e0Skxie@chelsio.com 
924759a0cc5SAnish Bhatt 	pr_info_ipaddr("csk 0x%p,%u,0x%lx,%u, status %u.\n",
925759a0cc5SAnish Bhatt 		       (&csk->saddr), (&csk->daddr),
9267b36b6e0Skxie@chelsio.com 		       csk, csk->state, csk->flags, csk->tid, req->status);
9277b36b6e0Skxie@chelsio.com 
9287b36b6e0Skxie@chelsio.com 	if (req->status == CPL_ERR_RTX_NEG_ADVICE ||
9297b36b6e0Skxie@chelsio.com 	    req->status == CPL_ERR_PERSIST_NEG_ADVICE)
9307b36b6e0Skxie@chelsio.com 		goto rel_skb;
9317b36b6e0Skxie@chelsio.com 
9327b36b6e0Skxie@chelsio.com 	cxgbi_sock_get(csk);
9337b36b6e0Skxie@chelsio.com 	spin_lock_bh(&csk->lock);
9347b36b6e0Skxie@chelsio.com 
9357b36b6e0Skxie@chelsio.com 	if (!cxgbi_sock_flag(csk, CTPF_ABORT_REQ_RCVD)) {
9367b36b6e0Skxie@chelsio.com 		cxgbi_sock_set_flag(csk, CTPF_ABORT_REQ_RCVD);
9377b36b6e0Skxie@chelsio.com 		cxgbi_sock_set_state(csk, CTP_ABORTING);
9387b36b6e0Skxie@chelsio.com 		goto done;
9397b36b6e0Skxie@chelsio.com 	}
9407b36b6e0Skxie@chelsio.com 
9417b36b6e0Skxie@chelsio.com 	cxgbi_sock_clear_flag(csk, CTPF_ABORT_REQ_RCVD);
9427b36b6e0Skxie@chelsio.com 	send_abort_rpl(csk, rst_status);
9437b36b6e0Skxie@chelsio.com 
9447b36b6e0Skxie@chelsio.com 	if (!cxgbi_sock_flag(csk, CTPF_ABORT_RPL_PENDING)) {
9457b36b6e0Skxie@chelsio.com 		csk->err = abort_status_to_errno(csk, req->status, &rst_status);
9467b36b6e0Skxie@chelsio.com 		cxgbi_sock_closed(csk);
9477b36b6e0Skxie@chelsio.com 	}
9487b36b6e0Skxie@chelsio.com done:
9497b36b6e0Skxie@chelsio.com 	spin_unlock_bh(&csk->lock);
9507b36b6e0Skxie@chelsio.com 	cxgbi_sock_put(csk);
9517b36b6e0Skxie@chelsio.com rel_skb:
9527b36b6e0Skxie@chelsio.com 	__kfree_skb(skb);
9537b36b6e0Skxie@chelsio.com }
9547b36b6e0Skxie@chelsio.com 
9557b36b6e0Skxie@chelsio.com static void do_abort_rpl_rss(struct cxgbi_device *cdev, struct sk_buff *skb)
9567b36b6e0Skxie@chelsio.com {
9577b36b6e0Skxie@chelsio.com 	struct cxgbi_sock *csk;
9587b36b6e0Skxie@chelsio.com 	struct cpl_abort_rpl_rss *rpl = (struct cpl_abort_rpl_rss *)skb->data;
9597b36b6e0Skxie@chelsio.com 	unsigned int tid = GET_TID(rpl);
9607b36b6e0Skxie@chelsio.com 	struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(cdev);
9617b36b6e0Skxie@chelsio.com 	struct tid_info *t = lldi->tids;
9627b36b6e0Skxie@chelsio.com 
9637b36b6e0Skxie@chelsio.com 	csk = lookup_tid(t, tid);
9647b36b6e0Skxie@chelsio.com 	if (!csk)
9657b36b6e0Skxie@chelsio.com 		goto rel_skb;
9667b36b6e0Skxie@chelsio.com 
967759a0cc5SAnish Bhatt 	if (csk)
968759a0cc5SAnish Bhatt 		pr_info_ipaddr("csk 0x%p,%u,0x%lx,%u, status %u.\n",
969759a0cc5SAnish Bhatt 			       (&csk->saddr), (&csk->daddr), csk,
970759a0cc5SAnish Bhatt 			       csk->state, csk->flags, csk->tid, rpl->status);
9717b36b6e0Skxie@chelsio.com 
9727b36b6e0Skxie@chelsio.com 	if (rpl->status == CPL_ERR_ABORT_FAILED)
9737b36b6e0Skxie@chelsio.com 		goto rel_skb;
9747b36b6e0Skxie@chelsio.com 
9757b36b6e0Skxie@chelsio.com 	cxgbi_sock_rcv_abort_rpl(csk);
9767b36b6e0Skxie@chelsio.com rel_skb:
9777b36b6e0Skxie@chelsio.com 	__kfree_skb(skb);
9787b36b6e0Skxie@chelsio.com }
9797b36b6e0Skxie@chelsio.com 
9807b36b6e0Skxie@chelsio.com static void do_rx_iscsi_hdr(struct cxgbi_device *cdev, struct sk_buff *skb)
9817b36b6e0Skxie@chelsio.com {
9827b36b6e0Skxie@chelsio.com 	struct cxgbi_sock *csk;
9837b36b6e0Skxie@chelsio.com 	struct cpl_iscsi_hdr *cpl = (struct cpl_iscsi_hdr *)skb->data;
9847b36b6e0Skxie@chelsio.com 	unsigned short pdu_len_ddp = be16_to_cpu(cpl->pdu_len_ddp);
9857b36b6e0Skxie@chelsio.com 	unsigned int tid = GET_TID(cpl);
9867b36b6e0Skxie@chelsio.com 	struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(cdev);
9877b36b6e0Skxie@chelsio.com 	struct tid_info *t = lldi->tids;
9887b36b6e0Skxie@chelsio.com 
9897b36b6e0Skxie@chelsio.com 	csk = lookup_tid(t, tid);
9907b36b6e0Skxie@chelsio.com 	if (unlikely(!csk)) {
9917b36b6e0Skxie@chelsio.com 		pr_err("can't find conn. for tid %u.\n", tid);
9927b36b6e0Skxie@chelsio.com 		goto rel_skb;
9937b36b6e0Skxie@chelsio.com 	}
9947b36b6e0Skxie@chelsio.com 
9957b36b6e0Skxie@chelsio.com 	log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_PDU_RX,
9967b36b6e0Skxie@chelsio.com 		"csk 0x%p,%u,0x%lx, tid %u, skb 0x%p,%u, 0x%x.\n",
9977b36b6e0Skxie@chelsio.com 		csk, csk->state, csk->flags, csk->tid, skb, skb->len,
9987b36b6e0Skxie@chelsio.com 		pdu_len_ddp);
9997b36b6e0Skxie@chelsio.com 
10007b36b6e0Skxie@chelsio.com 	spin_lock_bh(&csk->lock);
10017b36b6e0Skxie@chelsio.com 
10027b36b6e0Skxie@chelsio.com 	if (unlikely(csk->state >= CTP_PASSIVE_CLOSE)) {
10037b36b6e0Skxie@chelsio.com 		log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
10047b36b6e0Skxie@chelsio.com 			"csk 0x%p,%u,0x%lx,%u, bad state.\n",
10057b36b6e0Skxie@chelsio.com 			csk, csk->state, csk->flags, csk->tid);
10067b36b6e0Skxie@chelsio.com 		if (csk->state != CTP_ABORTING)
10077b36b6e0Skxie@chelsio.com 			goto abort_conn;
10087b36b6e0Skxie@chelsio.com 		else
10097b36b6e0Skxie@chelsio.com 			goto discard;
10107b36b6e0Skxie@chelsio.com 	}
10117b36b6e0Skxie@chelsio.com 
10127b36b6e0Skxie@chelsio.com 	cxgbi_skcb_tcp_seq(skb) = ntohl(cpl->seq);
1013e27d6169Skxie@chelsio.com 	cxgbi_skcb_flags(skb) = 0;
1014e27d6169Skxie@chelsio.com 
10157b36b6e0Skxie@chelsio.com 	skb_reset_transport_header(skb);
10167b36b6e0Skxie@chelsio.com 	__skb_pull(skb, sizeof(*cpl));
10177b36b6e0Skxie@chelsio.com 	__pskb_trim(skb, ntohs(cpl->len));
10187b36b6e0Skxie@chelsio.com 
10197b36b6e0Skxie@chelsio.com 	if (!csk->skb_ulp_lhdr) {
10207b36b6e0Skxie@chelsio.com 		unsigned char *bhs;
10213bd3e8bfSKaren Xie 		unsigned int hlen, dlen, plen;
10227b36b6e0Skxie@chelsio.com 
10237b36b6e0Skxie@chelsio.com 		log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_PDU_RX,
10247b36b6e0Skxie@chelsio.com 			"csk 0x%p,%u,0x%lx, tid %u, skb 0x%p header.\n",
10257b36b6e0Skxie@chelsio.com 			csk, csk->state, csk->flags, csk->tid, skb);
10267b36b6e0Skxie@chelsio.com 		csk->skb_ulp_lhdr = skb;
1027e27d6169Skxie@chelsio.com 		cxgbi_skcb_set_flag(skb, SKCBF_RX_HDR);
10287b36b6e0Skxie@chelsio.com 
1029e27d6169Skxie@chelsio.com 		if (cxgbi_skcb_tcp_seq(skb) != csk->rcv_nxt) {
10307b36b6e0Skxie@chelsio.com 			pr_info("tid %u, CPL_ISCSI_HDR, bad seq, 0x%x/0x%x.\n",
1031e27d6169Skxie@chelsio.com 				csk->tid, cxgbi_skcb_tcp_seq(skb),
10327b36b6e0Skxie@chelsio.com 				csk->rcv_nxt);
10337b36b6e0Skxie@chelsio.com 			goto abort_conn;
10347b36b6e0Skxie@chelsio.com 		}
10357b36b6e0Skxie@chelsio.com 
1036e27d6169Skxie@chelsio.com 		bhs = skb->data;
10377b36b6e0Skxie@chelsio.com 		hlen = ntohs(cpl->len);
10387b36b6e0Skxie@chelsio.com 		dlen = ntohl(*(unsigned int *)(bhs + 4)) & 0xFFFFFF;
10397b36b6e0Skxie@chelsio.com 
10403bd3e8bfSKaren Xie 		plen = ISCSI_PDU_LEN(pdu_len_ddp);
10413bd3e8bfSKaren Xie 		if (is_t4(lldi->adapter_type))
10423bd3e8bfSKaren Xie 			plen -= 40;
10433bd3e8bfSKaren Xie 
10443bd3e8bfSKaren Xie 		if ((hlen + dlen) != plen) {
10457b36b6e0Skxie@chelsio.com 			pr_info("tid 0x%x, CPL_ISCSI_HDR, pdu len "
10467b36b6e0Skxie@chelsio.com 				"mismatch %u != %u + %u, seq 0x%x.\n",
10473bd3e8bfSKaren Xie 				csk->tid, plen, hlen, dlen,
10483bd3e8bfSKaren Xie 				cxgbi_skcb_tcp_seq(skb));
10497b36b6e0Skxie@chelsio.com 			goto abort_conn;
10507b36b6e0Skxie@chelsio.com 		}
10517b36b6e0Skxie@chelsio.com 
10527b36b6e0Skxie@chelsio.com 		cxgbi_skcb_rx_pdulen(skb) = (hlen + dlen + 3) & (~0x3);
10537b36b6e0Skxie@chelsio.com 		if (dlen)
10547b36b6e0Skxie@chelsio.com 			cxgbi_skcb_rx_pdulen(skb) += csk->dcrc_len;
10557b36b6e0Skxie@chelsio.com 		csk->rcv_nxt += cxgbi_skcb_rx_pdulen(skb);
10567b36b6e0Skxie@chelsio.com 
10577b36b6e0Skxie@chelsio.com 		log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_PDU_RX,
10587b36b6e0Skxie@chelsio.com 			"csk 0x%p, skb 0x%p, 0x%x,%u+%u,0x%x,0x%x.\n",
10597b36b6e0Skxie@chelsio.com 			csk, skb, *bhs, hlen, dlen,
10607b36b6e0Skxie@chelsio.com 			ntohl(*((unsigned int *)(bhs + 16))),
10617b36b6e0Skxie@chelsio.com 			ntohl(*((unsigned int *)(bhs + 24))));
10627b36b6e0Skxie@chelsio.com 
10637b36b6e0Skxie@chelsio.com 	} else {
1064e27d6169Skxie@chelsio.com 		struct sk_buff *lskb = csk->skb_ulp_lhdr;
10657b36b6e0Skxie@chelsio.com 
1066e27d6169Skxie@chelsio.com 		cxgbi_skcb_set_flag(lskb, SKCBF_RX_DATA);
10677b36b6e0Skxie@chelsio.com 		log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_PDU_RX,
10687b36b6e0Skxie@chelsio.com 			"csk 0x%p,%u,0x%lx, skb 0x%p data, 0x%p.\n",
10697b36b6e0Skxie@chelsio.com 			csk, csk->state, csk->flags, skb, lskb);
10707b36b6e0Skxie@chelsio.com 	}
10717b36b6e0Skxie@chelsio.com 
10727b36b6e0Skxie@chelsio.com 	__skb_queue_tail(&csk->receive_queue, skb);
10737b36b6e0Skxie@chelsio.com 	spin_unlock_bh(&csk->lock);
10747b36b6e0Skxie@chelsio.com 	return;
10757b36b6e0Skxie@chelsio.com 
10767b36b6e0Skxie@chelsio.com abort_conn:
10777b36b6e0Skxie@chelsio.com 	send_abort_req(csk);
10787b36b6e0Skxie@chelsio.com discard:
10797b36b6e0Skxie@chelsio.com 	spin_unlock_bh(&csk->lock);
10807b36b6e0Skxie@chelsio.com rel_skb:
10817b36b6e0Skxie@chelsio.com 	__kfree_skb(skb);
10827b36b6e0Skxie@chelsio.com }
10837b36b6e0Skxie@chelsio.com 
10847b36b6e0Skxie@chelsio.com static void do_rx_data_ddp(struct cxgbi_device *cdev,
10857b36b6e0Skxie@chelsio.com 				  struct sk_buff *skb)
10867b36b6e0Skxie@chelsio.com {
10877b36b6e0Skxie@chelsio.com 	struct cxgbi_sock *csk;
10887b36b6e0Skxie@chelsio.com 	struct sk_buff *lskb;
10897b36b6e0Skxie@chelsio.com 	struct cpl_rx_data_ddp *rpl = (struct cpl_rx_data_ddp *)skb->data;
10907b36b6e0Skxie@chelsio.com 	unsigned int tid = GET_TID(rpl);
10917b36b6e0Skxie@chelsio.com 	struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(cdev);
10927b36b6e0Skxie@chelsio.com 	struct tid_info *t = lldi->tids;
10937b36b6e0Skxie@chelsio.com 	unsigned int status = ntohl(rpl->ddpvld);
10947b36b6e0Skxie@chelsio.com 
10957b36b6e0Skxie@chelsio.com 	csk = lookup_tid(t, tid);
10967b36b6e0Skxie@chelsio.com 	if (unlikely(!csk)) {
10977b36b6e0Skxie@chelsio.com 		pr_err("can't find connection for tid %u.\n", tid);
10987b36b6e0Skxie@chelsio.com 		goto rel_skb;
10997b36b6e0Skxie@chelsio.com 	}
11007b36b6e0Skxie@chelsio.com 
11017b36b6e0Skxie@chelsio.com 	log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_PDU_RX,
11027b36b6e0Skxie@chelsio.com 		"csk 0x%p,%u,0x%lx, skb 0x%p,0x%x, lhdr 0x%p.\n",
11037b36b6e0Skxie@chelsio.com 		csk, csk->state, csk->flags, skb, status, csk->skb_ulp_lhdr);
11047b36b6e0Skxie@chelsio.com 
11057b36b6e0Skxie@chelsio.com 	spin_lock_bh(&csk->lock);
11067b36b6e0Skxie@chelsio.com 
11077b36b6e0Skxie@chelsio.com 	if (unlikely(csk->state >= CTP_PASSIVE_CLOSE)) {
11087b36b6e0Skxie@chelsio.com 		log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
11097b36b6e0Skxie@chelsio.com 			"csk 0x%p,%u,0x%lx,%u, bad state.\n",
11107b36b6e0Skxie@chelsio.com 			csk, csk->state, csk->flags, csk->tid);
11117b36b6e0Skxie@chelsio.com 		if (csk->state != CTP_ABORTING)
11127b36b6e0Skxie@chelsio.com 			goto abort_conn;
11137b36b6e0Skxie@chelsio.com 		else
11147b36b6e0Skxie@chelsio.com 			goto discard;
11157b36b6e0Skxie@chelsio.com 	}
11167b36b6e0Skxie@chelsio.com 
11177b36b6e0Skxie@chelsio.com 	if (!csk->skb_ulp_lhdr) {
11187b36b6e0Skxie@chelsio.com 		pr_err("tid 0x%x, rcv RX_DATA_DDP w/o pdu bhs.\n", csk->tid);
11197b36b6e0Skxie@chelsio.com 		goto abort_conn;
11207b36b6e0Skxie@chelsio.com 	}
11217b36b6e0Skxie@chelsio.com 
11227b36b6e0Skxie@chelsio.com 	lskb = csk->skb_ulp_lhdr;
11237b36b6e0Skxie@chelsio.com 	csk->skb_ulp_lhdr = NULL;
11247b36b6e0Skxie@chelsio.com 
11257b36b6e0Skxie@chelsio.com 	cxgbi_skcb_rx_ddigest(lskb) = ntohl(rpl->ulp_crc);
11267b36b6e0Skxie@chelsio.com 
11277b36b6e0Skxie@chelsio.com 	if (ntohs(rpl->len) != cxgbi_skcb_rx_pdulen(lskb))
11287b36b6e0Skxie@chelsio.com 		pr_info("tid 0x%x, RX_DATA_DDP pdulen %u != %u.\n",
11297b36b6e0Skxie@chelsio.com 			csk->tid, ntohs(rpl->len), cxgbi_skcb_rx_pdulen(lskb));
11307b36b6e0Skxie@chelsio.com 
11317b36b6e0Skxie@chelsio.com 	if (status & (1 << CPL_RX_DDP_STATUS_HCRC_SHIFT)) {
1132e27d6169Skxie@chelsio.com 		pr_info("csk 0x%p, lhdr 0x%p, status 0x%x, hcrc bad 0x%lx.\n",
1133e27d6169Skxie@chelsio.com 			csk, lskb, status, cxgbi_skcb_flags(lskb));
11347b36b6e0Skxie@chelsio.com 		cxgbi_skcb_set_flag(lskb, SKCBF_RX_HCRC_ERR);
11357b36b6e0Skxie@chelsio.com 	}
11367b36b6e0Skxie@chelsio.com 	if (status & (1 << CPL_RX_DDP_STATUS_DCRC_SHIFT)) {
1137e27d6169Skxie@chelsio.com 		pr_info("csk 0x%p, lhdr 0x%p, status 0x%x, dcrc bad 0x%lx.\n",
1138e27d6169Skxie@chelsio.com 			csk, lskb, status, cxgbi_skcb_flags(lskb));
11397b36b6e0Skxie@chelsio.com 		cxgbi_skcb_set_flag(lskb, SKCBF_RX_DCRC_ERR);
11407b36b6e0Skxie@chelsio.com 	}
11417b36b6e0Skxie@chelsio.com 	if (status & (1 << CPL_RX_DDP_STATUS_PAD_SHIFT)) {
11427b36b6e0Skxie@chelsio.com 		log_debug(1 << CXGBI_DBG_PDU_RX,
11437b36b6e0Skxie@chelsio.com 			"csk 0x%p, lhdr 0x%p, status 0x%x, pad bad.\n",
11447b36b6e0Skxie@chelsio.com 			csk, lskb, status);
11457b36b6e0Skxie@chelsio.com 		cxgbi_skcb_set_flag(lskb, SKCBF_RX_PAD_ERR);
11467b36b6e0Skxie@chelsio.com 	}
11477b36b6e0Skxie@chelsio.com 	if ((status & (1 << CPL_RX_DDP_STATUS_DDP_SHIFT)) &&
11487b36b6e0Skxie@chelsio.com 		!cxgbi_skcb_test_flag(lskb, SKCBF_RX_DATA)) {
11497b36b6e0Skxie@chelsio.com 		log_debug(1 << CXGBI_DBG_PDU_RX,
11507b36b6e0Skxie@chelsio.com 			"csk 0x%p, lhdr 0x%p, 0x%x, data ddp'ed.\n",
11517b36b6e0Skxie@chelsio.com 			csk, lskb, status);
11527b36b6e0Skxie@chelsio.com 		cxgbi_skcb_set_flag(lskb, SKCBF_RX_DATA_DDPD);
11537b36b6e0Skxie@chelsio.com 	}
11547b36b6e0Skxie@chelsio.com 	log_debug(1 << CXGBI_DBG_PDU_RX,
11557b36b6e0Skxie@chelsio.com 		"csk 0x%p, lskb 0x%p, f 0x%lx.\n",
11567b36b6e0Skxie@chelsio.com 		csk, lskb, cxgbi_skcb_flags(lskb));
11577b36b6e0Skxie@chelsio.com 
1158e27d6169Skxie@chelsio.com 	cxgbi_skcb_set_flag(lskb, SKCBF_RX_STATUS);
11597b36b6e0Skxie@chelsio.com 	cxgbi_conn_pdu_ready(csk);
11607b36b6e0Skxie@chelsio.com 	spin_unlock_bh(&csk->lock);
11617b36b6e0Skxie@chelsio.com 	goto rel_skb;
11627b36b6e0Skxie@chelsio.com 
11637b36b6e0Skxie@chelsio.com abort_conn:
11647b36b6e0Skxie@chelsio.com 	send_abort_req(csk);
11657b36b6e0Skxie@chelsio.com discard:
11667b36b6e0Skxie@chelsio.com 	spin_unlock_bh(&csk->lock);
11677b36b6e0Skxie@chelsio.com rel_skb:
11687b36b6e0Skxie@chelsio.com 	__kfree_skb(skb);
11697b36b6e0Skxie@chelsio.com }
11707b36b6e0Skxie@chelsio.com 
11717b36b6e0Skxie@chelsio.com static void do_fw4_ack(struct cxgbi_device *cdev, struct sk_buff *skb)
11727b36b6e0Skxie@chelsio.com {
11737b36b6e0Skxie@chelsio.com 	struct cxgbi_sock *csk;
11747b36b6e0Skxie@chelsio.com 	struct cpl_fw4_ack *rpl = (struct cpl_fw4_ack *)skb->data;
11757b36b6e0Skxie@chelsio.com 	unsigned int tid = GET_TID(rpl);
11767b36b6e0Skxie@chelsio.com 	struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(cdev);
11777b36b6e0Skxie@chelsio.com 	struct tid_info *t = lldi->tids;
11787b36b6e0Skxie@chelsio.com 
11797b36b6e0Skxie@chelsio.com 	csk = lookup_tid(t, tid);
11807b36b6e0Skxie@chelsio.com 	if (unlikely(!csk))
11817b36b6e0Skxie@chelsio.com 		pr_err("can't find connection for tid %u.\n", tid);
11827b36b6e0Skxie@chelsio.com 	else {
11837b36b6e0Skxie@chelsio.com 		log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
11847b36b6e0Skxie@chelsio.com 			"csk 0x%p,%u,0x%lx,%u.\n",
11857b36b6e0Skxie@chelsio.com 			csk, csk->state, csk->flags, csk->tid);
11867b36b6e0Skxie@chelsio.com 		cxgbi_sock_rcv_wr_ack(csk, rpl->credits, ntohl(rpl->snd_una),
11877b36b6e0Skxie@chelsio.com 					rpl->seq_vld);
11887b36b6e0Skxie@chelsio.com 	}
11897b36b6e0Skxie@chelsio.com 	__kfree_skb(skb);
11907b36b6e0Skxie@chelsio.com }
11917b36b6e0Skxie@chelsio.com 
11927b36b6e0Skxie@chelsio.com static void do_set_tcb_rpl(struct cxgbi_device *cdev, struct sk_buff *skb)
11937b36b6e0Skxie@chelsio.com {
11947b36b6e0Skxie@chelsio.com 	struct cpl_set_tcb_rpl *rpl = (struct cpl_set_tcb_rpl *)skb->data;
11957b36b6e0Skxie@chelsio.com 	unsigned int tid = GET_TID(rpl);
11967b36b6e0Skxie@chelsio.com 	struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(cdev);
11977b36b6e0Skxie@chelsio.com 	struct tid_info *t = lldi->tids;
11987b36b6e0Skxie@chelsio.com 	struct cxgbi_sock *csk;
11997b36b6e0Skxie@chelsio.com 
12007b36b6e0Skxie@chelsio.com 	csk = lookup_tid(t, tid);
12017b36b6e0Skxie@chelsio.com 	if (!csk)
12027b36b6e0Skxie@chelsio.com 		pr_err("can't find conn. for tid %u.\n", tid);
12037b36b6e0Skxie@chelsio.com 
12047b36b6e0Skxie@chelsio.com 	log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
12057b36b6e0Skxie@chelsio.com 		"csk 0x%p,%u,%lx,%u, status 0x%x.\n",
12067b36b6e0Skxie@chelsio.com 		csk, csk->state, csk->flags, csk->tid, rpl->status);
12077b36b6e0Skxie@chelsio.com 
12087b36b6e0Skxie@chelsio.com 	if (rpl->status != CPL_ERR_NONE)
12097b36b6e0Skxie@chelsio.com 		pr_err("csk 0x%p,%u, SET_TCB_RPL status %u.\n",
12107b36b6e0Skxie@chelsio.com 			csk, tid, rpl->status);
12117b36b6e0Skxie@chelsio.com 
12127b36b6e0Skxie@chelsio.com 	__kfree_skb(skb);
12137b36b6e0Skxie@chelsio.com }
12147b36b6e0Skxie@chelsio.com 
12157b36b6e0Skxie@chelsio.com static int alloc_cpls(struct cxgbi_sock *csk)
12167b36b6e0Skxie@chelsio.com {
121724d3f95aSkxie@chelsio.com 	csk->cpl_close = alloc_wr(sizeof(struct cpl_close_con_req),
121824d3f95aSkxie@chelsio.com 					0, GFP_KERNEL);
12197b36b6e0Skxie@chelsio.com 	if (!csk->cpl_close)
12207b36b6e0Skxie@chelsio.com 		return -ENOMEM;
12217b36b6e0Skxie@chelsio.com 
122224d3f95aSkxie@chelsio.com 	csk->cpl_abort_req = alloc_wr(sizeof(struct cpl_abort_req),
122324d3f95aSkxie@chelsio.com 					0, GFP_KERNEL);
12247b36b6e0Skxie@chelsio.com 	if (!csk->cpl_abort_req)
12257b36b6e0Skxie@chelsio.com 		goto free_cpls;
12267b36b6e0Skxie@chelsio.com 
122724d3f95aSkxie@chelsio.com 	csk->cpl_abort_rpl = alloc_wr(sizeof(struct cpl_abort_rpl),
122824d3f95aSkxie@chelsio.com 					0, GFP_KERNEL);
12297b36b6e0Skxie@chelsio.com 	if (!csk->cpl_abort_rpl)
12307b36b6e0Skxie@chelsio.com 		goto free_cpls;
12317b36b6e0Skxie@chelsio.com 	return 0;
12327b36b6e0Skxie@chelsio.com 
12337b36b6e0Skxie@chelsio.com free_cpls:
12347b36b6e0Skxie@chelsio.com 	cxgbi_sock_free_cpl_skbs(csk);
12357b36b6e0Skxie@chelsio.com 	return -ENOMEM;
12367b36b6e0Skxie@chelsio.com }
12377b36b6e0Skxie@chelsio.com 
12387b36b6e0Skxie@chelsio.com static inline void l2t_put(struct cxgbi_sock *csk)
12397b36b6e0Skxie@chelsio.com {
12407b36b6e0Skxie@chelsio.com 	if (csk->l2t) {
12417b36b6e0Skxie@chelsio.com 		cxgb4_l2t_release(csk->l2t);
12427b36b6e0Skxie@chelsio.com 		csk->l2t = NULL;
12437b36b6e0Skxie@chelsio.com 		cxgbi_sock_put(csk);
12447b36b6e0Skxie@chelsio.com 	}
12457b36b6e0Skxie@chelsio.com }
12467b36b6e0Skxie@chelsio.com 
12477b36b6e0Skxie@chelsio.com static void release_offload_resources(struct cxgbi_sock *csk)
12487b36b6e0Skxie@chelsio.com {
12497b36b6e0Skxie@chelsio.com 	struct cxgb4_lld_info *lldi;
12507b36b6e0Skxie@chelsio.com 
12517b36b6e0Skxie@chelsio.com 	log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
12527b36b6e0Skxie@chelsio.com 		"csk 0x%p,%u,0x%lx,%u.\n",
12537b36b6e0Skxie@chelsio.com 		csk, csk->state, csk->flags, csk->tid);
12547b36b6e0Skxie@chelsio.com 
12557b36b6e0Skxie@chelsio.com 	cxgbi_sock_free_cpl_skbs(csk);
12567b36b6e0Skxie@chelsio.com 	if (csk->wr_cred != csk->wr_max_cred) {
12577b36b6e0Skxie@chelsio.com 		cxgbi_sock_purge_wr_queue(csk);
12587b36b6e0Skxie@chelsio.com 		cxgbi_sock_reset_wr_list(csk);
12597b36b6e0Skxie@chelsio.com 	}
12607b36b6e0Skxie@chelsio.com 
12617b36b6e0Skxie@chelsio.com 	l2t_put(csk);
12627b36b6e0Skxie@chelsio.com 	if (cxgbi_sock_flag(csk, CTPF_HAS_ATID))
12637b36b6e0Skxie@chelsio.com 		free_atid(csk);
12647b36b6e0Skxie@chelsio.com 	else if (cxgbi_sock_flag(csk, CTPF_HAS_TID)) {
12657b36b6e0Skxie@chelsio.com 		lldi = cxgbi_cdev_priv(csk->cdev);
12667b36b6e0Skxie@chelsio.com 		cxgb4_remove_tid(lldi->tids, 0, csk->tid);
12677b36b6e0Skxie@chelsio.com 		cxgbi_sock_clear_flag(csk, CTPF_HAS_TID);
12687b36b6e0Skxie@chelsio.com 		cxgbi_sock_put(csk);
12697b36b6e0Skxie@chelsio.com 	}
12707b36b6e0Skxie@chelsio.com 	csk->dst = NULL;
12717b36b6e0Skxie@chelsio.com 	csk->cdev = NULL;
12727b36b6e0Skxie@chelsio.com }
12737b36b6e0Skxie@chelsio.com 
12747b36b6e0Skxie@chelsio.com static int init_act_open(struct cxgbi_sock *csk)
12757b36b6e0Skxie@chelsio.com {
12767b36b6e0Skxie@chelsio.com 	struct cxgbi_device *cdev = csk->cdev;
12777b36b6e0Skxie@chelsio.com 	struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(cdev);
12787b36b6e0Skxie@chelsio.com 	struct net_device *ndev = cdev->ports[csk->port_id];
12797b36b6e0Skxie@chelsio.com 	struct sk_buff *skb = NULL;
1280759a0cc5SAnish Bhatt 	struct neighbour *n = NULL;
1281759a0cc5SAnish Bhatt 	void *daddr;
12827b36b6e0Skxie@chelsio.com 	unsigned int step;
1283759a0cc5SAnish Bhatt 	unsigned int size, size6;
1284759a0cc5SAnish Bhatt 	int t4 = is_t4(lldi->adapter_type);
12857b36b6e0Skxie@chelsio.com 
12867b36b6e0Skxie@chelsio.com 	log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
12877b36b6e0Skxie@chelsio.com 		"csk 0x%p,%u,0x%lx,%u.\n",
12887b36b6e0Skxie@chelsio.com 		csk, csk->state, csk->flags, csk->tid);
12897b36b6e0Skxie@chelsio.com 
1290759a0cc5SAnish Bhatt 	if (csk->csk_family == AF_INET)
1291759a0cc5SAnish Bhatt 		daddr = &csk->daddr.sin_addr.s_addr;
1292e81fbf6cSAnish Bhatt #if IS_ENABLED(CONFIG_IPV6)
1293e81fbf6cSAnish Bhatt 	else if (csk->csk_family == AF_INET6)
1294759a0cc5SAnish Bhatt 		daddr = &csk->daddr6.sin6_addr;
1295e81fbf6cSAnish Bhatt #endif
1296e81fbf6cSAnish Bhatt 	else {
1297e81fbf6cSAnish Bhatt 		pr_err("address family 0x%x not supported\n", csk->csk_family);
1298e81fbf6cSAnish Bhatt 		goto rel_resource;
1299e81fbf6cSAnish Bhatt 	}
1300759a0cc5SAnish Bhatt 
1301759a0cc5SAnish Bhatt 	n = dst_neigh_lookup(csk->dst, daddr);
1302759a0cc5SAnish Bhatt 
1303759a0cc5SAnish Bhatt 	if (!n) {
1304759a0cc5SAnish Bhatt 		pr_err("%s, can't get neighbour of csk->dst.\n", ndev->name);
1305759a0cc5SAnish Bhatt 		goto rel_resource;
1306759a0cc5SAnish Bhatt 	}
1307759a0cc5SAnish Bhatt 
13087b36b6e0Skxie@chelsio.com 	csk->atid = cxgb4_alloc_atid(lldi->tids, csk);
13097b36b6e0Skxie@chelsio.com 	if (csk->atid < 0) {
13107b36b6e0Skxie@chelsio.com 		pr_err("%s, NO atid available.\n", ndev->name);
13117b36b6e0Skxie@chelsio.com 		return -EINVAL;
13127b36b6e0Skxie@chelsio.com 	}
13137b36b6e0Skxie@chelsio.com 	cxgbi_sock_set_flag(csk, CTPF_HAS_ATID);
13147b36b6e0Skxie@chelsio.com 	cxgbi_sock_get(csk);
13157b36b6e0Skxie@chelsio.com 
1316c4737377SDavid S. Miller 	n = dst_neigh_lookup(csk->dst, &csk->daddr.sin_addr.s_addr);
131751e059bdSDavid Miller 	if (!n) {
131851e059bdSDavid Miller 		pr_err("%s, can't get neighbour of csk->dst.\n", ndev->name);
131951e059bdSDavid Miller 		goto rel_resource;
132051e059bdSDavid Miller 	}
132151e059bdSDavid Miller 	csk->l2t = cxgb4_l2t_get(lldi->l2t, n, ndev, 0);
13227b36b6e0Skxie@chelsio.com 	if (!csk->l2t) {
13237b36b6e0Skxie@chelsio.com 		pr_err("%s, cannot alloc l2t.\n", ndev->name);
13247b36b6e0Skxie@chelsio.com 		goto rel_resource;
13257b36b6e0Skxie@chelsio.com 	}
13267b36b6e0Skxie@chelsio.com 	cxgbi_sock_get(csk);
13277b36b6e0Skxie@chelsio.com 
1328759a0cc5SAnish Bhatt 	if (t4) {
1329759a0cc5SAnish Bhatt 		size = sizeof(struct cpl_act_open_req);
1330759a0cc5SAnish Bhatt 		size6 = sizeof(struct cpl_act_open_req6);
1331759a0cc5SAnish Bhatt 	} else {
1332759a0cc5SAnish Bhatt 		size = sizeof(struct cpl_t5_act_open_req);
1333759a0cc5SAnish Bhatt 		size6 = sizeof(struct cpl_t5_act_open_req6);
1334759a0cc5SAnish Bhatt 	}
1335759a0cc5SAnish Bhatt 
1336759a0cc5SAnish Bhatt 	if (csk->csk_family == AF_INET)
1337759a0cc5SAnish Bhatt 		skb = alloc_wr(size, 0, GFP_NOIO);
1338759a0cc5SAnish Bhatt 	else
1339759a0cc5SAnish Bhatt 		skb = alloc_wr(size6, 0, GFP_NOIO);
1340759a0cc5SAnish Bhatt 
13417b36b6e0Skxie@chelsio.com 	if (!skb)
13427b36b6e0Skxie@chelsio.com 		goto rel_resource;
13437b36b6e0Skxie@chelsio.com 	skb->sk = (struct sock *)csk;
13447b36b6e0Skxie@chelsio.com 	t4_set_arp_err_handler(skb, csk, cxgbi_sock_act_open_req_arp_failure);
13457b36b6e0Skxie@chelsio.com 
13467b36b6e0Skxie@chelsio.com 	if (!csk->mtu)
13477b36b6e0Skxie@chelsio.com 		csk->mtu = dst_mtu(csk->dst);
13487b36b6e0Skxie@chelsio.com 	cxgb4_best_mtu(lldi->mtus, csk->mtu, &csk->mss_idx);
13497b36b6e0Skxie@chelsio.com 	csk->tx_chan = cxgb4_port_chan(ndev);
13507b36b6e0Skxie@chelsio.com 	/* SMT two entries per row */
13517b36b6e0Skxie@chelsio.com 	csk->smac_idx = ((cxgb4_port_viid(ndev) & 0x7F)) << 1;
13527b36b6e0Skxie@chelsio.com 	step = lldi->ntxq / lldi->nchan;
13537b36b6e0Skxie@chelsio.com 	csk->txq_idx = cxgb4_port_idx(ndev) * step;
13547b36b6e0Skxie@chelsio.com 	step = lldi->nrxq / lldi->nchan;
13557b36b6e0Skxie@chelsio.com 	csk->rss_qid = lldi->rxq_ids[cxgb4_port_idx(ndev) * step];
1356759a0cc5SAnish Bhatt 	csk->wr_cred = lldi->wr_cred -
1357759a0cc5SAnish Bhatt 		       DIV_ROUND_UP(sizeof(struct cpl_abort_req), 16);
1358759a0cc5SAnish Bhatt 	csk->wr_max_cred = csk->wr_cred;
13597b36b6e0Skxie@chelsio.com 	csk->wr_una_cred = 0;
13607b36b6e0Skxie@chelsio.com 	cxgbi_sock_reset_wr_list(csk);
13617b36b6e0Skxie@chelsio.com 	csk->err = 0;
13627b36b6e0Skxie@chelsio.com 
1363759a0cc5SAnish Bhatt 	pr_info_ipaddr("csk 0x%p,%u,0x%lx,%u,%u,%u, mtu %u,%u, smac %u.\n",
1364759a0cc5SAnish Bhatt 		       (&csk->saddr), (&csk->daddr), csk, csk->state,
1365759a0cc5SAnish Bhatt 		       csk->flags, csk->tx_chan, csk->txq_idx, csk->rss_qid,
1366759a0cc5SAnish Bhatt 		       csk->mtu, csk->mss_idx, csk->smac_idx);
1367759a0cc5SAnish Bhatt 
1368759a0cc5SAnish Bhatt 	/* must wait for either a act_open_rpl or act_open_establish */
1369759a0cc5SAnish Bhatt 	try_module_get(THIS_MODULE);
13707b36b6e0Skxie@chelsio.com 	cxgbi_sock_set_state(csk, CTP_ACTIVE_OPEN);
1371759a0cc5SAnish Bhatt 	if (csk->csk_family == AF_INET)
13727b36b6e0Skxie@chelsio.com 		send_act_open_req(csk, skb, csk->l2t);
1373759a0cc5SAnish Bhatt 	else
1374759a0cc5SAnish Bhatt 		send_act_open_req6(csk, skb, csk->l2t);
1375c4737377SDavid S. Miller 	neigh_release(n);
1376759a0cc5SAnish Bhatt 
13777b36b6e0Skxie@chelsio.com 	return 0;
13787b36b6e0Skxie@chelsio.com 
13797b36b6e0Skxie@chelsio.com rel_resource:
1380c4737377SDavid S. Miller 	if (n)
1381c4737377SDavid S. Miller 		neigh_release(n);
13827b36b6e0Skxie@chelsio.com 	if (skb)
13837b36b6e0Skxie@chelsio.com 		__kfree_skb(skb);
13847b36b6e0Skxie@chelsio.com 	return -EINVAL;
13857b36b6e0Skxie@chelsio.com }
13867b36b6e0Skxie@chelsio.com 
13873bd3e8bfSKaren Xie #define CPL_ISCSI_DATA		0xB2
13883bd3e8bfSKaren Xie #define CPL_RX_ISCSI_DDP	0x49
13897b36b6e0Skxie@chelsio.com cxgb4i_cplhandler_func cxgb4i_cplhandlers[NUM_CPL_CMDS] = {
13907b36b6e0Skxie@chelsio.com 	[CPL_ACT_ESTABLISH] = do_act_establish,
13917b36b6e0Skxie@chelsio.com 	[CPL_ACT_OPEN_RPL] = do_act_open_rpl,
13927b36b6e0Skxie@chelsio.com 	[CPL_PEER_CLOSE] = do_peer_close,
13937b36b6e0Skxie@chelsio.com 	[CPL_ABORT_REQ_RSS] = do_abort_req_rss,
13947b36b6e0Skxie@chelsio.com 	[CPL_ABORT_RPL_RSS] = do_abort_rpl_rss,
13957b36b6e0Skxie@chelsio.com 	[CPL_CLOSE_CON_RPL] = do_close_con_rpl,
13967b36b6e0Skxie@chelsio.com 	[CPL_FW4_ACK] = do_fw4_ack,
13977b36b6e0Skxie@chelsio.com 	[CPL_ISCSI_HDR] = do_rx_iscsi_hdr,
13983bd3e8bfSKaren Xie 	[CPL_ISCSI_DATA] = do_rx_iscsi_hdr,
13997b36b6e0Skxie@chelsio.com 	[CPL_SET_TCB_RPL] = do_set_tcb_rpl,
14007b36b6e0Skxie@chelsio.com 	[CPL_RX_DATA_DDP] = do_rx_data_ddp,
14013bd3e8bfSKaren Xie 	[CPL_RX_ISCSI_DDP] = do_rx_data_ddp,
14027b36b6e0Skxie@chelsio.com };
14037b36b6e0Skxie@chelsio.com 
14047b36b6e0Skxie@chelsio.com int cxgb4i_ofld_init(struct cxgbi_device *cdev)
14057b36b6e0Skxie@chelsio.com {
14067b36b6e0Skxie@chelsio.com 	int rc;
14077b36b6e0Skxie@chelsio.com 
14087b36b6e0Skxie@chelsio.com 	if (cxgb4i_max_connect > CXGB4I_MAX_CONN)
14097b36b6e0Skxie@chelsio.com 		cxgb4i_max_connect = CXGB4I_MAX_CONN;
14107b36b6e0Skxie@chelsio.com 
14117b36b6e0Skxie@chelsio.com 	rc = cxgbi_device_portmap_create(cdev, cxgb4i_sport_base,
14127b36b6e0Skxie@chelsio.com 					cxgb4i_max_connect);
14137b36b6e0Skxie@chelsio.com 	if (rc < 0)
14147b36b6e0Skxie@chelsio.com 		return rc;
14157b36b6e0Skxie@chelsio.com 
14167b36b6e0Skxie@chelsio.com 	cdev->csk_release_offload_resources = release_offload_resources;
14177b36b6e0Skxie@chelsio.com 	cdev->csk_push_tx_frames = push_tx_frames;
14187b36b6e0Skxie@chelsio.com 	cdev->csk_send_abort_req = send_abort_req;
14197b36b6e0Skxie@chelsio.com 	cdev->csk_send_close_req = send_close_req;
14207b36b6e0Skxie@chelsio.com 	cdev->csk_send_rx_credits = send_rx_credits;
14217b36b6e0Skxie@chelsio.com 	cdev->csk_alloc_cpls = alloc_cpls;
14227b36b6e0Skxie@chelsio.com 	cdev->csk_init_act_open = init_act_open;
14237b36b6e0Skxie@chelsio.com 
14247b36b6e0Skxie@chelsio.com 	pr_info("cdev 0x%p, offload up, added.\n", cdev);
14257b36b6e0Skxie@chelsio.com 	return 0;
14267b36b6e0Skxie@chelsio.com }
14277b36b6e0Skxie@chelsio.com 
14287b36b6e0Skxie@chelsio.com /*
14297b36b6e0Skxie@chelsio.com  * functions to program the pagepod in h/w
14307b36b6e0Skxie@chelsio.com  */
1431e27d6169Skxie@chelsio.com #define ULPMEM_IDATA_MAX_NPPODS	4 /* 256/PPOD_SIZE */
14323bd3e8bfSKaren Xie static inline void ulp_mem_io_set_hdr(struct cxgb4_lld_info *lldi,
14333bd3e8bfSKaren Xie 				struct ulp_mem_io *req,
1434e27d6169Skxie@chelsio.com 				unsigned int wr_len, unsigned int dlen,
1435e27d6169Skxie@chelsio.com 				unsigned int pm_addr)
14367b36b6e0Skxie@chelsio.com {
1437e27d6169Skxie@chelsio.com 	struct ulptx_idata *idata = (struct ulptx_idata *)(req + 1);
14387b36b6e0Skxie@chelsio.com 
14397b36b6e0Skxie@chelsio.com 	INIT_ULPTX_WR(req, wr_len, 0, 0);
14403bd3e8bfSKaren Xie 	if (is_t4(lldi->adapter_type))
14413bd3e8bfSKaren Xie 		req->cmd = htonl(ULPTX_CMD(ULP_TX_MEM_WRITE) |
14423bd3e8bfSKaren Xie 					(ULP_MEMIO_ORDER(1)));
14433bd3e8bfSKaren Xie 	else
14443bd3e8bfSKaren Xie 		req->cmd = htonl(ULPTX_CMD(ULP_TX_MEM_WRITE) |
14453bd3e8bfSKaren Xie 					(V_T5_ULP_MEMIO_IMM(1)));
14467b36b6e0Skxie@chelsio.com 	req->dlen = htonl(ULP_MEMIO_DATA_LEN(dlen >> 5));
14477b36b6e0Skxie@chelsio.com 	req->lock_addr = htonl(ULP_MEMIO_ADDR(pm_addr >> 5));
14487b36b6e0Skxie@chelsio.com 	req->len16 = htonl(DIV_ROUND_UP(wr_len - sizeof(req->wr), 16));
1449e27d6169Skxie@chelsio.com 
1450e27d6169Skxie@chelsio.com 	idata->cmd_more = htonl(ULPTX_CMD(ULP_TX_SC_IMM));
1451e27d6169Skxie@chelsio.com 	idata->len = htonl(dlen);
14527b36b6e0Skxie@chelsio.com }
14537b36b6e0Skxie@chelsio.com 
1454e27d6169Skxie@chelsio.com static int ddp_ppod_write_idata(struct cxgbi_device *cdev, unsigned int port_id,
14557b36b6e0Skxie@chelsio.com 				struct cxgbi_pagepod_hdr *hdr, unsigned int idx,
14567b36b6e0Skxie@chelsio.com 				unsigned int npods,
14577b36b6e0Skxie@chelsio.com 				struct cxgbi_gather_list *gl,
14587b36b6e0Skxie@chelsio.com 				unsigned int gl_pidx)
14597b36b6e0Skxie@chelsio.com {
14607b36b6e0Skxie@chelsio.com 	struct cxgbi_ddp_info *ddp = cdev->ddp;
14613bd3e8bfSKaren Xie 	struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(cdev);
14627b36b6e0Skxie@chelsio.com 	struct sk_buff *skb;
14637b36b6e0Skxie@chelsio.com 	struct ulp_mem_io *req;
1464e27d6169Skxie@chelsio.com 	struct ulptx_idata *idata;
14657b36b6e0Skxie@chelsio.com 	struct cxgbi_pagepod *ppod;
1466e27d6169Skxie@chelsio.com 	unsigned int pm_addr = idx * PPOD_SIZE + ddp->llimit;
1467e27d6169Skxie@chelsio.com 	unsigned int dlen = PPOD_SIZE * npods;
1468e27d6169Skxie@chelsio.com 	unsigned int wr_len = roundup(sizeof(struct ulp_mem_io) +
1469e27d6169Skxie@chelsio.com 				sizeof(struct ulptx_idata) + dlen, 16);
14707b36b6e0Skxie@chelsio.com 	unsigned int i;
14717b36b6e0Skxie@chelsio.com 
1472e27d6169Skxie@chelsio.com 	skb = alloc_wr(wr_len, 0, GFP_ATOMIC);
14737b36b6e0Skxie@chelsio.com 	if (!skb) {
14747b36b6e0Skxie@chelsio.com 		pr_err("cdev 0x%p, idx %u, npods %u, OOM.\n",
14757b36b6e0Skxie@chelsio.com 			cdev, idx, npods);
14767b36b6e0Skxie@chelsio.com 		return -ENOMEM;
14777b36b6e0Skxie@chelsio.com 	}
14787b36b6e0Skxie@chelsio.com 	req = (struct ulp_mem_io *)skb->head;
14797b36b6e0Skxie@chelsio.com 	set_queue(skb, CPL_PRIORITY_CONTROL, NULL);
14807b36b6e0Skxie@chelsio.com 
14813bd3e8bfSKaren Xie 	ulp_mem_io_set_hdr(lldi, req, wr_len, dlen, pm_addr);
1482e27d6169Skxie@chelsio.com 	idata = (struct ulptx_idata *)(req + 1);
1483e27d6169Skxie@chelsio.com 	ppod = (struct cxgbi_pagepod *)(idata + 1);
14847b36b6e0Skxie@chelsio.com 
14857b36b6e0Skxie@chelsio.com 	for (i = 0; i < npods; i++, ppod++, gl_pidx += PPOD_PAGES_MAX) {
14867b36b6e0Skxie@chelsio.com 		if (!hdr && !gl)
14877b36b6e0Skxie@chelsio.com 			cxgbi_ddp_ppod_clear(ppod);
14887b36b6e0Skxie@chelsio.com 		else
14897b36b6e0Skxie@chelsio.com 			cxgbi_ddp_ppod_set(ppod, hdr, gl, gl_pidx);
14907b36b6e0Skxie@chelsio.com 	}
14917b36b6e0Skxie@chelsio.com 
14927b36b6e0Skxie@chelsio.com 	cxgb4_ofld_send(cdev->ports[port_id], skb);
14937b36b6e0Skxie@chelsio.com 	return 0;
14947b36b6e0Skxie@chelsio.com }
14957b36b6e0Skxie@chelsio.com 
14967b36b6e0Skxie@chelsio.com static int ddp_set_map(struct cxgbi_sock *csk, struct cxgbi_pagepod_hdr *hdr,
14977b36b6e0Skxie@chelsio.com 			unsigned int idx, unsigned int npods,
14987b36b6e0Skxie@chelsio.com 			struct cxgbi_gather_list *gl)
14997b36b6e0Skxie@chelsio.com {
15007b36b6e0Skxie@chelsio.com 	unsigned int i, cnt;
15017b36b6e0Skxie@chelsio.com 	int err = 0;
15027b36b6e0Skxie@chelsio.com 
15037b36b6e0Skxie@chelsio.com 	for (i = 0; i < npods; i += cnt, idx += cnt) {
15047b36b6e0Skxie@chelsio.com 		cnt = npods - i;
1505e27d6169Skxie@chelsio.com 		if (cnt > ULPMEM_IDATA_MAX_NPPODS)
1506e27d6169Skxie@chelsio.com 			cnt = ULPMEM_IDATA_MAX_NPPODS;
1507e27d6169Skxie@chelsio.com 		err = ddp_ppod_write_idata(csk->cdev, csk->port_id, hdr,
15087b36b6e0Skxie@chelsio.com 					idx, cnt, gl, 4 * i);
15097b36b6e0Skxie@chelsio.com 		if (err < 0)
15107b36b6e0Skxie@chelsio.com 			break;
15117b36b6e0Skxie@chelsio.com 	}
15127b36b6e0Skxie@chelsio.com 	return err;
15137b36b6e0Skxie@chelsio.com }
15147b36b6e0Skxie@chelsio.com 
15157b36b6e0Skxie@chelsio.com static void ddp_clear_map(struct cxgbi_hba *chba, unsigned int tag,
15167b36b6e0Skxie@chelsio.com 			  unsigned int idx, unsigned int npods)
15177b36b6e0Skxie@chelsio.com {
15187b36b6e0Skxie@chelsio.com 	unsigned int i, cnt;
15197b36b6e0Skxie@chelsio.com 	int err;
15207b36b6e0Skxie@chelsio.com 
15217b36b6e0Skxie@chelsio.com 	for (i = 0; i < npods; i += cnt, idx += cnt) {
15227b36b6e0Skxie@chelsio.com 		cnt = npods - i;
1523e27d6169Skxie@chelsio.com 		if (cnt > ULPMEM_IDATA_MAX_NPPODS)
1524e27d6169Skxie@chelsio.com 			cnt = ULPMEM_IDATA_MAX_NPPODS;
1525e27d6169Skxie@chelsio.com 		err = ddp_ppod_write_idata(chba->cdev, chba->port_id, NULL,
15267b36b6e0Skxie@chelsio.com 					idx, cnt, NULL, 0);
15277b36b6e0Skxie@chelsio.com 		if (err < 0)
15287b36b6e0Skxie@chelsio.com 			break;
15297b36b6e0Skxie@chelsio.com 	}
15307b36b6e0Skxie@chelsio.com }
15317b36b6e0Skxie@chelsio.com 
15327b36b6e0Skxie@chelsio.com static int ddp_setup_conn_pgidx(struct cxgbi_sock *csk, unsigned int tid,
15337b36b6e0Skxie@chelsio.com 				int pg_idx, bool reply)
15347b36b6e0Skxie@chelsio.com {
15357b36b6e0Skxie@chelsio.com 	struct sk_buff *skb;
15367b36b6e0Skxie@chelsio.com 	struct cpl_set_tcb_field *req;
15377b36b6e0Skxie@chelsio.com 
1538e27d6169Skxie@chelsio.com 	if (!pg_idx || pg_idx >= DDP_PGIDX_MAX)
15397b36b6e0Skxie@chelsio.com 		return 0;
15407b36b6e0Skxie@chelsio.com 
154124d3f95aSkxie@chelsio.com 	skb = alloc_wr(sizeof(*req), 0, GFP_KERNEL);
15427b36b6e0Skxie@chelsio.com 	if (!skb)
15437b36b6e0Skxie@chelsio.com 		return -ENOMEM;
15447b36b6e0Skxie@chelsio.com 
1545e27d6169Skxie@chelsio.com 	/*  set up ulp page size */
15467b36b6e0Skxie@chelsio.com 	req = (struct cpl_set_tcb_field *)skb->head;
15477b36b6e0Skxie@chelsio.com 	INIT_TP_WR(req, csk->tid);
15487b36b6e0Skxie@chelsio.com 	OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_SET_TCB_FIELD, csk->tid));
15497b36b6e0Skxie@chelsio.com 	req->reply_ctrl = htons(NO_REPLY(reply) | QUEUENO(csk->rss_qid));
1550e27d6169Skxie@chelsio.com 	req->word_cookie = htons(0);
1551e27d6169Skxie@chelsio.com 	req->mask = cpu_to_be64(0x3 << 8);
1552e27d6169Skxie@chelsio.com 	req->val = cpu_to_be64(pg_idx << 8);
15537b36b6e0Skxie@chelsio.com 	set_wr_txq(skb, CPL_PRIORITY_CONTROL, csk->port_id);
15547b36b6e0Skxie@chelsio.com 
15557b36b6e0Skxie@chelsio.com 	log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
15567b36b6e0Skxie@chelsio.com 		"csk 0x%p, tid 0x%x, pg_idx %u.\n", csk, csk->tid, pg_idx);
15577b36b6e0Skxie@chelsio.com 
15587b36b6e0Skxie@chelsio.com 	cxgb4_ofld_send(csk->cdev->ports[csk->port_id], skb);
15597b36b6e0Skxie@chelsio.com 	return 0;
15607b36b6e0Skxie@chelsio.com }
15617b36b6e0Skxie@chelsio.com 
15627b36b6e0Skxie@chelsio.com static int ddp_setup_conn_digest(struct cxgbi_sock *csk, unsigned int tid,
15637b36b6e0Skxie@chelsio.com 				 int hcrc, int dcrc, int reply)
15647b36b6e0Skxie@chelsio.com {
15657b36b6e0Skxie@chelsio.com 	struct sk_buff *skb;
15667b36b6e0Skxie@chelsio.com 	struct cpl_set_tcb_field *req;
15677b36b6e0Skxie@chelsio.com 
1568e27d6169Skxie@chelsio.com 	if (!hcrc && !dcrc)
1569e27d6169Skxie@chelsio.com 		return 0;
15707b36b6e0Skxie@chelsio.com 
157124d3f95aSkxie@chelsio.com 	skb = alloc_wr(sizeof(*req), 0, GFP_KERNEL);
15727b36b6e0Skxie@chelsio.com 	if (!skb)
15737b36b6e0Skxie@chelsio.com 		return -ENOMEM;
15747b36b6e0Skxie@chelsio.com 
15757b36b6e0Skxie@chelsio.com 	csk->hcrc_len = (hcrc ? 4 : 0);
15767b36b6e0Skxie@chelsio.com 	csk->dcrc_len = (dcrc ? 4 : 0);
1577e27d6169Skxie@chelsio.com 	/*  set up ulp submode */
15787b36b6e0Skxie@chelsio.com 	req = (struct cpl_set_tcb_field *)skb->head;
15797b36b6e0Skxie@chelsio.com 	INIT_TP_WR(req, tid);
15807b36b6e0Skxie@chelsio.com 	OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_SET_TCB_FIELD, tid));
15817b36b6e0Skxie@chelsio.com 	req->reply_ctrl = htons(NO_REPLY(reply) | QUEUENO(csk->rss_qid));
1582e27d6169Skxie@chelsio.com 	req->word_cookie = htons(0);
1583e27d6169Skxie@chelsio.com 	req->mask = cpu_to_be64(0x3 << 4);
1584e27d6169Skxie@chelsio.com 	req->val = cpu_to_be64(((hcrc ? ULP_CRC_HEADER : 0) |
1585e27d6169Skxie@chelsio.com 				(dcrc ? ULP_CRC_DATA : 0)) << 4);
15867b36b6e0Skxie@chelsio.com 	set_wr_txq(skb, CPL_PRIORITY_CONTROL, csk->port_id);
15877b36b6e0Skxie@chelsio.com 
15887b36b6e0Skxie@chelsio.com 	log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
15897b36b6e0Skxie@chelsio.com 		"csk 0x%p, tid 0x%x, crc %d,%d.\n", csk, csk->tid, hcrc, dcrc);
15907b36b6e0Skxie@chelsio.com 
15917b36b6e0Skxie@chelsio.com 	cxgb4_ofld_send(csk->cdev->ports[csk->port_id], skb);
15927b36b6e0Skxie@chelsio.com 	return 0;
15937b36b6e0Skxie@chelsio.com }
15947b36b6e0Skxie@chelsio.com 
15957b36b6e0Skxie@chelsio.com static int cxgb4i_ddp_init(struct cxgbi_device *cdev)
15967b36b6e0Skxie@chelsio.com {
15977b36b6e0Skxie@chelsio.com 	struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(cdev);
15987b36b6e0Skxie@chelsio.com 	struct cxgbi_ddp_info *ddp = cdev->ddp;
15997b36b6e0Skxie@chelsio.com 	unsigned int tagmask, pgsz_factor[4];
16007b36b6e0Skxie@chelsio.com 	int err;
16017b36b6e0Skxie@chelsio.com 
16027b36b6e0Skxie@chelsio.com 	if (ddp) {
16037b36b6e0Skxie@chelsio.com 		kref_get(&ddp->refcnt);
16047b36b6e0Skxie@chelsio.com 		pr_warn("cdev 0x%p, ddp 0x%p already set up.\n",
16057b36b6e0Skxie@chelsio.com 			cdev, cdev->ddp);
16067b36b6e0Skxie@chelsio.com 		return -EALREADY;
16077b36b6e0Skxie@chelsio.com 	}
16087b36b6e0Skxie@chelsio.com 
16097b36b6e0Skxie@chelsio.com 	err = cxgbi_ddp_init(cdev, lldi->vr->iscsi.start,
16107b36b6e0Skxie@chelsio.com 			lldi->vr->iscsi.start + lldi->vr->iscsi.size - 1,
16117b36b6e0Skxie@chelsio.com 			lldi->iscsi_iolen, lldi->iscsi_iolen);
16127b36b6e0Skxie@chelsio.com 	if (err < 0)
16137b36b6e0Skxie@chelsio.com 		return err;
16147b36b6e0Skxie@chelsio.com 
16157b36b6e0Skxie@chelsio.com 	ddp = cdev->ddp;
16167b36b6e0Skxie@chelsio.com 
16177b36b6e0Skxie@chelsio.com 	tagmask = ddp->idx_mask << PPOD_IDX_SHIFT;
16187b36b6e0Skxie@chelsio.com 	cxgbi_ddp_page_size_factor(pgsz_factor);
16197b36b6e0Skxie@chelsio.com 	cxgb4_iscsi_init(lldi->ports[0], tagmask, pgsz_factor);
16207b36b6e0Skxie@chelsio.com 
16217b36b6e0Skxie@chelsio.com 	cdev->csk_ddp_setup_digest = ddp_setup_conn_digest;
16227b36b6e0Skxie@chelsio.com 	cdev->csk_ddp_setup_pgidx = ddp_setup_conn_pgidx;
16237b36b6e0Skxie@chelsio.com 	cdev->csk_ddp_set = ddp_set_map;
16247b36b6e0Skxie@chelsio.com 	cdev->csk_ddp_clear = ddp_clear_map;
16257b36b6e0Skxie@chelsio.com 
16267b36b6e0Skxie@chelsio.com 	pr_info("cxgb4i 0x%p tag: sw %u, rsvd %u,%u, mask 0x%x.\n",
16277b36b6e0Skxie@chelsio.com 		cdev, cdev->tag_format.sw_bits, cdev->tag_format.rsvd_bits,
16287b36b6e0Skxie@chelsio.com 		cdev->tag_format.rsvd_shift, cdev->tag_format.rsvd_mask);
16297b36b6e0Skxie@chelsio.com 	pr_info("cxgb4i 0x%p, nppods %u, bits %u, mask 0x%x,0x%x pkt %u/%u, "
16307b36b6e0Skxie@chelsio.com 		" %u/%u.\n",
16317b36b6e0Skxie@chelsio.com 		cdev, ddp->nppods, ddp->idx_bits, ddp->idx_mask,
16327b36b6e0Skxie@chelsio.com 		ddp->rsvd_tag_mask, ddp->max_txsz, lldi->iscsi_iolen,
16337b36b6e0Skxie@chelsio.com 		ddp->max_rxsz, lldi->iscsi_iolen);
16347b36b6e0Skxie@chelsio.com 	pr_info("cxgb4i 0x%p max payload size: %u/%u, %u/%u.\n",
16357b36b6e0Skxie@chelsio.com 		cdev, cdev->tx_max_size, ddp->max_txsz, cdev->rx_max_size,
16367b36b6e0Skxie@chelsio.com 		ddp->max_rxsz);
16377b36b6e0Skxie@chelsio.com 	return 0;
16387b36b6e0Skxie@chelsio.com }
16397b36b6e0Skxie@chelsio.com 
1640e81fbf6cSAnish Bhatt #if IS_ENABLED(CONFIG_IPV6)
1641759a0cc5SAnish Bhatt static int cxgbi_inet6addr_handler(struct notifier_block *this,
1642759a0cc5SAnish Bhatt 				   unsigned long event, void *data)
1643759a0cc5SAnish Bhatt {
1644759a0cc5SAnish Bhatt 	struct inet6_ifaddr *ifa = data;
1645759a0cc5SAnish Bhatt 	struct net_device *event_dev = ifa->idev->dev;
1646759a0cc5SAnish Bhatt 	struct cxgbi_device *cdev;
1647759a0cc5SAnish Bhatt 	int ret = NOTIFY_DONE;
1648759a0cc5SAnish Bhatt 
1649759a0cc5SAnish Bhatt 	rcu_read_lock();
1650759a0cc5SAnish Bhatt 
1651759a0cc5SAnish Bhatt 	if (event_dev->priv_flags & IFF_802_1Q_VLAN)
1652759a0cc5SAnish Bhatt 		event_dev = vlan_dev_real_dev(event_dev);
1653759a0cc5SAnish Bhatt 
1654759a0cc5SAnish Bhatt 	cdev = cxgbi_device_find_by_netdev(event_dev, NULL);
1655759a0cc5SAnish Bhatt 	if (!cdev) {
1656759a0cc5SAnish Bhatt 		rcu_read_unlock();
1657759a0cc5SAnish Bhatt 		return ret;
1658759a0cc5SAnish Bhatt 	}
1659759a0cc5SAnish Bhatt 	switch (event) {
1660759a0cc5SAnish Bhatt 	case NETDEV_UP:
1661759a0cc5SAnish Bhatt 		ret = cxgb4_clip_get(event_dev,
1662759a0cc5SAnish Bhatt 				     (const struct in6_addr *)
1663759a0cc5SAnish Bhatt 				     ((ifa)->addr.s6_addr));
1664759a0cc5SAnish Bhatt 		if (ret < 0) {
1665759a0cc5SAnish Bhatt 			rcu_read_unlock();
1666759a0cc5SAnish Bhatt 			return ret;
1667759a0cc5SAnish Bhatt 		}
1668759a0cc5SAnish Bhatt 		ret = NOTIFY_OK;
1669759a0cc5SAnish Bhatt 		break;
1670759a0cc5SAnish Bhatt 
1671759a0cc5SAnish Bhatt 	case NETDEV_DOWN:
1672759a0cc5SAnish Bhatt 		cxgb4_clip_release(event_dev,
1673759a0cc5SAnish Bhatt 				   (const struct in6_addr *)
1674759a0cc5SAnish Bhatt 				   ((ifa)->addr.s6_addr));
1675759a0cc5SAnish Bhatt 		ret = NOTIFY_OK;
1676759a0cc5SAnish Bhatt 		break;
1677759a0cc5SAnish Bhatt 
1678759a0cc5SAnish Bhatt 	default:
1679759a0cc5SAnish Bhatt 		break;
1680759a0cc5SAnish Bhatt 	}
1681759a0cc5SAnish Bhatt 
1682759a0cc5SAnish Bhatt 	rcu_read_unlock();
1683759a0cc5SAnish Bhatt 	return ret;
1684759a0cc5SAnish Bhatt }
1685759a0cc5SAnish Bhatt 
1686759a0cc5SAnish Bhatt static struct notifier_block cxgbi_inet6addr_notifier = {
1687759a0cc5SAnish Bhatt 	.notifier_call = cxgbi_inet6addr_handler
1688759a0cc5SAnish Bhatt };
1689759a0cc5SAnish Bhatt 
1690759a0cc5SAnish Bhatt /* Retrieve IPv6 addresses from a root device (bond, vlan) associated with
1691759a0cc5SAnish Bhatt  * a physical device.
1692759a0cc5SAnish Bhatt  * The physical device reference is needed to send the actual CLIP command.
1693759a0cc5SAnish Bhatt  */
1694759a0cc5SAnish Bhatt static int update_dev_clip(struct net_device *root_dev, struct net_device *dev)
1695759a0cc5SAnish Bhatt {
1696759a0cc5SAnish Bhatt 	struct inet6_dev *idev = NULL;
1697759a0cc5SAnish Bhatt 	struct inet6_ifaddr *ifa;
1698759a0cc5SAnish Bhatt 	int ret = 0;
1699759a0cc5SAnish Bhatt 
1700759a0cc5SAnish Bhatt 	idev = __in6_dev_get(root_dev);
1701759a0cc5SAnish Bhatt 	if (!idev)
1702759a0cc5SAnish Bhatt 		return ret;
1703759a0cc5SAnish Bhatt 
1704759a0cc5SAnish Bhatt 	read_lock_bh(&idev->lock);
1705759a0cc5SAnish Bhatt 	list_for_each_entry(ifa, &idev->addr_list, if_list) {
1706759a0cc5SAnish Bhatt 		pr_info("updating the clip for addr %pI6\n",
1707759a0cc5SAnish Bhatt 			ifa->addr.s6_addr);
1708759a0cc5SAnish Bhatt 		ret = cxgb4_clip_get(dev, (const struct in6_addr *)
1709759a0cc5SAnish Bhatt 				     ifa->addr.s6_addr);
1710759a0cc5SAnish Bhatt 		if (ret < 0)
1711759a0cc5SAnish Bhatt 			break;
1712759a0cc5SAnish Bhatt 	}
1713759a0cc5SAnish Bhatt 
1714759a0cc5SAnish Bhatt 	read_unlock_bh(&idev->lock);
1715759a0cc5SAnish Bhatt 	return ret;
1716759a0cc5SAnish Bhatt }
1717759a0cc5SAnish Bhatt 
1718759a0cc5SAnish Bhatt static int update_root_dev_clip(struct net_device *dev)
1719759a0cc5SAnish Bhatt {
1720759a0cc5SAnish Bhatt 	struct net_device *root_dev = NULL;
1721759a0cc5SAnish Bhatt 	int i, ret = 0;
1722759a0cc5SAnish Bhatt 
1723759a0cc5SAnish Bhatt 	/* First populate the real net device's IPv6 address */
1724759a0cc5SAnish Bhatt 	ret = update_dev_clip(dev, dev);
1725759a0cc5SAnish Bhatt 	if (ret)
1726759a0cc5SAnish Bhatt 		return ret;
1727759a0cc5SAnish Bhatt 
1728759a0cc5SAnish Bhatt 	/* Parse all bond and vlan devices layered on top of the physical dev */
1729759a0cc5SAnish Bhatt 	root_dev = netdev_master_upper_dev_get(dev);
1730759a0cc5SAnish Bhatt 	if (root_dev) {
1731759a0cc5SAnish Bhatt 		ret = update_dev_clip(root_dev, dev);
1732759a0cc5SAnish Bhatt 		if (ret)
1733759a0cc5SAnish Bhatt 			return ret;
1734759a0cc5SAnish Bhatt 	}
1735759a0cc5SAnish Bhatt 
1736759a0cc5SAnish Bhatt 	for (i = 0; i < VLAN_N_VID; i++) {
1737759a0cc5SAnish Bhatt 		root_dev = __vlan_find_dev_deep_rcu(dev, htons(ETH_P_8021Q), i);
1738759a0cc5SAnish Bhatt 		if (!root_dev)
1739759a0cc5SAnish Bhatt 			continue;
1740759a0cc5SAnish Bhatt 
1741759a0cc5SAnish Bhatt 		ret = update_dev_clip(root_dev, dev);
1742759a0cc5SAnish Bhatt 		if (ret)
1743759a0cc5SAnish Bhatt 			break;
1744759a0cc5SAnish Bhatt 	}
1745759a0cc5SAnish Bhatt 	return ret;
1746759a0cc5SAnish Bhatt }
1747759a0cc5SAnish Bhatt 
1748759a0cc5SAnish Bhatt static void cxgbi_update_clip(struct cxgbi_device *cdev)
1749759a0cc5SAnish Bhatt {
1750759a0cc5SAnish Bhatt 	int i;
1751759a0cc5SAnish Bhatt 
1752759a0cc5SAnish Bhatt 	rcu_read_lock();
1753759a0cc5SAnish Bhatt 
1754759a0cc5SAnish Bhatt 	for (i = 0; i < cdev->nports; i++) {
1755759a0cc5SAnish Bhatt 		struct net_device *dev = cdev->ports[i];
1756759a0cc5SAnish Bhatt 		int ret = 0;
1757759a0cc5SAnish Bhatt 
1758759a0cc5SAnish Bhatt 		if (dev)
1759759a0cc5SAnish Bhatt 			ret = update_root_dev_clip(dev);
1760759a0cc5SAnish Bhatt 		if (ret < 0)
1761759a0cc5SAnish Bhatt 			break;
1762759a0cc5SAnish Bhatt 	}
1763759a0cc5SAnish Bhatt 	rcu_read_unlock();
1764759a0cc5SAnish Bhatt }
1765e81fbf6cSAnish Bhatt #endif /* IS_ENABLED(CONFIG_IPV6) */
1766759a0cc5SAnish Bhatt 
17677b36b6e0Skxie@chelsio.com static void *t4_uld_add(const struct cxgb4_lld_info *lldi)
17687b36b6e0Skxie@chelsio.com {
17697b36b6e0Skxie@chelsio.com 	struct cxgbi_device *cdev;
17707b36b6e0Skxie@chelsio.com 	struct port_info *pi;
17717b36b6e0Skxie@chelsio.com 	int i, rc;
17727b36b6e0Skxie@chelsio.com 
17737b36b6e0Skxie@chelsio.com 	cdev = cxgbi_device_register(sizeof(*lldi), lldi->nports);
17747b36b6e0Skxie@chelsio.com 	if (!cdev) {
17757b36b6e0Skxie@chelsio.com 		pr_info("t4 device 0x%p, register failed.\n", lldi);
17767b36b6e0Skxie@chelsio.com 		return NULL;
17777b36b6e0Skxie@chelsio.com 	}
17787b36b6e0Skxie@chelsio.com 	pr_info("0x%p,0x%x, ports %u,%s, chan %u, q %u,%u, wr %u.\n",
17797b36b6e0Skxie@chelsio.com 		cdev, lldi->adapter_type, lldi->nports,
17807b36b6e0Skxie@chelsio.com 		lldi->ports[0]->name, lldi->nchan, lldi->ntxq,
17817b36b6e0Skxie@chelsio.com 		lldi->nrxq, lldi->wr_cred);
17827b36b6e0Skxie@chelsio.com 	for (i = 0; i < lldi->nrxq; i++)
17837b36b6e0Skxie@chelsio.com 		log_debug(1 << CXGBI_DBG_DEV,
17847b36b6e0Skxie@chelsio.com 			"t4 0x%p, rxq id #%d: %u.\n",
17857b36b6e0Skxie@chelsio.com 			cdev, i, lldi->rxq_ids[i]);
17867b36b6e0Skxie@chelsio.com 
17877b36b6e0Skxie@chelsio.com 	memcpy(cxgbi_cdev_priv(cdev), lldi, sizeof(*lldi));
17887b36b6e0Skxie@chelsio.com 	cdev->flags = CXGBI_FLAG_DEV_T4;
17897b36b6e0Skxie@chelsio.com 	cdev->pdev = lldi->pdev;
17907b36b6e0Skxie@chelsio.com 	cdev->ports = lldi->ports;
17917b36b6e0Skxie@chelsio.com 	cdev->nports = lldi->nports;
17927b36b6e0Skxie@chelsio.com 	cdev->mtus = lldi->mtus;
17937b36b6e0Skxie@chelsio.com 	cdev->nmtus = NMTUS;
17947b36b6e0Skxie@chelsio.com 	cdev->snd_win = cxgb4i_snd_win;
17957b36b6e0Skxie@chelsio.com 	cdev->rcv_win = cxgb4i_rcv_win;
17967b36b6e0Skxie@chelsio.com 	cdev->rx_credit_thres = cxgb4i_rx_credit_thres;
17977b36b6e0Skxie@chelsio.com 	cdev->skb_tx_rsvd = CXGB4I_TX_HEADER_LEN;
17987b36b6e0Skxie@chelsio.com 	cdev->skb_rx_extra = sizeof(struct cpl_iscsi_hdr);
17997b36b6e0Skxie@chelsio.com 	cdev->itp = &cxgb4i_iscsi_transport;
18007b36b6e0Skxie@chelsio.com 
1801e27d6169Skxie@chelsio.com 	cdev->pfvf = FW_VIID_PFN_GET(cxgb4_port_viid(lldi->ports[0])) << 8;
1802e27d6169Skxie@chelsio.com 	pr_info("cdev 0x%p,%s, pfvf %u.\n",
1803e27d6169Skxie@chelsio.com 		cdev, lldi->ports[0]->name, cdev->pfvf);
1804e27d6169Skxie@chelsio.com 
18057b36b6e0Skxie@chelsio.com 	rc = cxgb4i_ddp_init(cdev);
18067b36b6e0Skxie@chelsio.com 	if (rc) {
18077b36b6e0Skxie@chelsio.com 		pr_info("t4 0x%p ddp init failed.\n", cdev);
18087b36b6e0Skxie@chelsio.com 		goto err_out;
18097b36b6e0Skxie@chelsio.com 	}
18107b36b6e0Skxie@chelsio.com 	rc = cxgb4i_ofld_init(cdev);
18117b36b6e0Skxie@chelsio.com 	if (rc) {
18127b36b6e0Skxie@chelsio.com 		pr_info("t4 0x%p ofld init failed.\n", cdev);
18137b36b6e0Skxie@chelsio.com 		goto err_out;
18147b36b6e0Skxie@chelsio.com 	}
18157b36b6e0Skxie@chelsio.com 
18167b36b6e0Skxie@chelsio.com 	rc = cxgbi_hbas_add(cdev, CXGB4I_MAX_LUN, CXGBI_MAX_CONN,
18177b36b6e0Skxie@chelsio.com 				&cxgb4i_host_template, cxgb4i_stt);
18187b36b6e0Skxie@chelsio.com 	if (rc)
18197b36b6e0Skxie@chelsio.com 		goto err_out;
18207b36b6e0Skxie@chelsio.com 
18217b36b6e0Skxie@chelsio.com 	for (i = 0; i < cdev->nports; i++) {
18227b36b6e0Skxie@chelsio.com 		pi = netdev_priv(lldi->ports[i]);
18237b36b6e0Skxie@chelsio.com 		cdev->hbas[i]->port_id = pi->port_id;
18247b36b6e0Skxie@chelsio.com 	}
18257b36b6e0Skxie@chelsio.com 	return cdev;
18267b36b6e0Skxie@chelsio.com 
18277b36b6e0Skxie@chelsio.com err_out:
18287b36b6e0Skxie@chelsio.com 	cxgbi_device_unregister(cdev);
18297b36b6e0Skxie@chelsio.com 	return ERR_PTR(-ENOMEM);
18307b36b6e0Skxie@chelsio.com }
18317b36b6e0Skxie@chelsio.com 
18327b36b6e0Skxie@chelsio.com #define RX_PULL_LEN	128
18337b36b6e0Skxie@chelsio.com static int t4_uld_rx_handler(void *handle, const __be64 *rsp,
18347b36b6e0Skxie@chelsio.com 				const struct pkt_gl *pgl)
18357b36b6e0Skxie@chelsio.com {
18367b36b6e0Skxie@chelsio.com 	const struct cpl_act_establish *rpl;
18377b36b6e0Skxie@chelsio.com 	struct sk_buff *skb;
18387b36b6e0Skxie@chelsio.com 	unsigned int opc;
18397b36b6e0Skxie@chelsio.com 	struct cxgbi_device *cdev = handle;
18407b36b6e0Skxie@chelsio.com 
18417b36b6e0Skxie@chelsio.com 	if (pgl == NULL) {
18427b36b6e0Skxie@chelsio.com 		unsigned int len = 64 - sizeof(struct rsp_ctrl) - 8;
18437b36b6e0Skxie@chelsio.com 
184424d3f95aSkxie@chelsio.com 		skb = alloc_wr(len, 0, GFP_ATOMIC);
18457b36b6e0Skxie@chelsio.com 		if (!skb)
18467b36b6e0Skxie@chelsio.com 			goto nomem;
18477b36b6e0Skxie@chelsio.com 		skb_copy_to_linear_data(skb, &rsp[1], len);
18487b36b6e0Skxie@chelsio.com 	} else {
18497b36b6e0Skxie@chelsio.com 		if (unlikely(*(u8 *)rsp != *(u8 *)pgl->va)) {
18507b36b6e0Skxie@chelsio.com 			pr_info("? FL 0x%p,RSS%#llx,FL %#llx,len %u.\n",
18517b36b6e0Skxie@chelsio.com 				pgl->va, be64_to_cpu(*rsp),
18527b36b6e0Skxie@chelsio.com 				be64_to_cpu(*(u64 *)pgl->va),
18537b36b6e0Skxie@chelsio.com 				pgl->tot_len);
18547b36b6e0Skxie@chelsio.com 			return 0;
18557b36b6e0Skxie@chelsio.com 		}
18567b36b6e0Skxie@chelsio.com 		skb = cxgb4_pktgl_to_skb(pgl, RX_PULL_LEN, RX_PULL_LEN);
18577b36b6e0Skxie@chelsio.com 		if (unlikely(!skb))
18587b36b6e0Skxie@chelsio.com 			goto nomem;
18597b36b6e0Skxie@chelsio.com 	}
18607b36b6e0Skxie@chelsio.com 
18617b36b6e0Skxie@chelsio.com 	rpl = (struct cpl_act_establish *)skb->data;
18627b36b6e0Skxie@chelsio.com 	opc = rpl->ot.opcode;
18637b36b6e0Skxie@chelsio.com 	log_debug(1 << CXGBI_DBG_TOE,
18647b36b6e0Skxie@chelsio.com 		"cdev %p, opcode 0x%x(0x%x,0x%x), skb %p.\n",
18657b36b6e0Skxie@chelsio.com 		 cdev, opc, rpl->ot.opcode_tid, ntohl(rpl->ot.opcode_tid), skb);
18667b36b6e0Skxie@chelsio.com 	if (cxgb4i_cplhandlers[opc])
18677b36b6e0Skxie@chelsio.com 		cxgb4i_cplhandlers[opc](cdev, skb);
18687b36b6e0Skxie@chelsio.com 	else {
18697b36b6e0Skxie@chelsio.com 		pr_err("No handler for opcode 0x%x.\n", opc);
18707b36b6e0Skxie@chelsio.com 		__kfree_skb(skb);
18717b36b6e0Skxie@chelsio.com 	}
18727b36b6e0Skxie@chelsio.com 	return 0;
18737b36b6e0Skxie@chelsio.com nomem:
18747b36b6e0Skxie@chelsio.com 	log_debug(1 << CXGBI_DBG_TOE, "OOM bailing out.\n");
18757b36b6e0Skxie@chelsio.com 	return 1;
18767b36b6e0Skxie@chelsio.com }
18777b36b6e0Skxie@chelsio.com 
18787b36b6e0Skxie@chelsio.com static int t4_uld_state_change(void *handle, enum cxgb4_state state)
18797b36b6e0Skxie@chelsio.com {
18807b36b6e0Skxie@chelsio.com 	struct cxgbi_device *cdev = handle;
18817b36b6e0Skxie@chelsio.com 
18827b36b6e0Skxie@chelsio.com 	switch (state) {
18837b36b6e0Skxie@chelsio.com 	case CXGB4_STATE_UP:
18847b36b6e0Skxie@chelsio.com 		pr_info("cdev 0x%p, UP.\n", cdev);
1885e81fbf6cSAnish Bhatt #if IS_ENABLED(CONFIG_IPV6)
1886759a0cc5SAnish Bhatt 		cxgbi_update_clip(cdev);
1887e81fbf6cSAnish Bhatt #endif
18887b36b6e0Skxie@chelsio.com 		/* re-initialize */
18897b36b6e0Skxie@chelsio.com 		break;
18907b36b6e0Skxie@chelsio.com 	case CXGB4_STATE_START_RECOVERY:
18917b36b6e0Skxie@chelsio.com 		pr_info("cdev 0x%p, RECOVERY.\n", cdev);
18927b36b6e0Skxie@chelsio.com 		/* close all connections */
18937b36b6e0Skxie@chelsio.com 		break;
18947b36b6e0Skxie@chelsio.com 	case CXGB4_STATE_DOWN:
18957b36b6e0Skxie@chelsio.com 		pr_info("cdev 0x%p, DOWN.\n", cdev);
18967b36b6e0Skxie@chelsio.com 		break;
18977b36b6e0Skxie@chelsio.com 	case CXGB4_STATE_DETACH:
18987b36b6e0Skxie@chelsio.com 		pr_info("cdev 0x%p, DETACH.\n", cdev);
1899c3b331a3SThadeu Lima de Souza Cascardo 		cxgbi_device_unregister(cdev);
19007b36b6e0Skxie@chelsio.com 		break;
19017b36b6e0Skxie@chelsio.com 	default:
19027b36b6e0Skxie@chelsio.com 		pr_info("cdev 0x%p, unknown state %d.\n", cdev, state);
19037b36b6e0Skxie@chelsio.com 		break;
19047b36b6e0Skxie@chelsio.com 	}
19057b36b6e0Skxie@chelsio.com 	return 0;
19067b36b6e0Skxie@chelsio.com }
19077b36b6e0Skxie@chelsio.com 
19087b36b6e0Skxie@chelsio.com static int __init cxgb4i_init_module(void)
19097b36b6e0Skxie@chelsio.com {
19107b36b6e0Skxie@chelsio.com 	int rc;
19117b36b6e0Skxie@chelsio.com 
19127b36b6e0Skxie@chelsio.com 	printk(KERN_INFO "%s", version);
19137b36b6e0Skxie@chelsio.com 
19147b36b6e0Skxie@chelsio.com 	rc = cxgbi_iscsi_init(&cxgb4i_iscsi_transport, &cxgb4i_stt);
19157b36b6e0Skxie@chelsio.com 	if (rc < 0)
19167b36b6e0Skxie@chelsio.com 		return rc;
19177b36b6e0Skxie@chelsio.com 	cxgb4_register_uld(CXGB4_ULD_ISCSI, &cxgb4i_uld_info);
1918759a0cc5SAnish Bhatt 
1919e81fbf6cSAnish Bhatt #if IS_ENABLED(CONFIG_IPV6)
1920759a0cc5SAnish Bhatt 	register_inet6addr_notifier(&cxgbi_inet6addr_notifier);
1921e81fbf6cSAnish Bhatt #endif
19227b36b6e0Skxie@chelsio.com 	return 0;
19237b36b6e0Skxie@chelsio.com }
19247b36b6e0Skxie@chelsio.com 
19257b36b6e0Skxie@chelsio.com static void __exit cxgb4i_exit_module(void)
19267b36b6e0Skxie@chelsio.com {
1927e81fbf6cSAnish Bhatt #if IS_ENABLED(CONFIG_IPV6)
1928759a0cc5SAnish Bhatt 	unregister_inet6addr_notifier(&cxgbi_inet6addr_notifier);
1929e81fbf6cSAnish Bhatt #endif
19307b36b6e0Skxie@chelsio.com 	cxgb4_unregister_uld(CXGB4_ULD_ISCSI);
19317b36b6e0Skxie@chelsio.com 	cxgbi_device_unregister_all(CXGBI_FLAG_DEV_T4);
19327b36b6e0Skxie@chelsio.com 	cxgbi_iscsi_cleanup(&cxgb4i_iscsi_transport, &cxgb4i_stt);
19337b36b6e0Skxie@chelsio.com }
19347b36b6e0Skxie@chelsio.com 
19357b36b6e0Skxie@chelsio.com module_init(cxgb4i_init_module);
19367b36b6e0Skxie@chelsio.com module_exit(cxgb4i_exit_module);
1937