xref: /linux/drivers/scsi/qedi/qedi_iscsi.c (revision 1ac731c529cd4d6adbce134754b51ff7d822b145)
13287e96aSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only
2ace7f46bSManish Rangankar /*
3ace7f46bSManish Rangankar  * QLogic iSCSI Offload Driver
4ace7f46bSManish Rangankar  * Copyright (c) 2016 Cavium Inc.
5ace7f46bSManish Rangankar  */
6ace7f46bSManish Rangankar 
7ace7f46bSManish Rangankar #include <linux/blkdev.h>
8ace7f46bSManish Rangankar #include <linux/etherdevice.h>
9ace7f46bSManish Rangankar #include <linux/if_ether.h>
10ace7f46bSManish Rangankar #include <linux/if_vlan.h>
11ace7f46bSManish Rangankar #include <scsi/scsi_tcq.h>
12ace7f46bSManish Rangankar 
13ace7f46bSManish Rangankar #include "qedi.h"
14ace7f46bSManish Rangankar #include "qedi_iscsi.h"
15ace7f46bSManish Rangankar #include "qedi_gbl.h"
16ace7f46bSManish Rangankar 
qedi_recover_all_conns(struct qedi_ctx * qedi)17ace7f46bSManish Rangankar int qedi_recover_all_conns(struct qedi_ctx *qedi)
18ace7f46bSManish Rangankar {
19ace7f46bSManish Rangankar 	struct qedi_conn *qedi_conn;
20ace7f46bSManish Rangankar 	int i;
21ace7f46bSManish Rangankar 
22ace7f46bSManish Rangankar 	for (i = 0; i < qedi->max_active_conns; i++) {
23ace7f46bSManish Rangankar 		qedi_conn = qedi_get_conn_from_id(qedi, i);
24ace7f46bSManish Rangankar 		if (!qedi_conn)
25ace7f46bSManish Rangankar 			continue;
26ace7f46bSManish Rangankar 
27ace7f46bSManish Rangankar 		qedi_start_conn_recovery(qedi, qedi_conn);
28ace7f46bSManish Rangankar 	}
29ace7f46bSManish Rangankar 
30ace7f46bSManish Rangankar 	return SUCCESS;
31ace7f46bSManish Rangankar }
32ace7f46bSManish Rangankar 
qedi_eh_host_reset(struct scsi_cmnd * cmd)33ace7f46bSManish Rangankar static int qedi_eh_host_reset(struct scsi_cmnd *cmd)
34ace7f46bSManish Rangankar {
35ace7f46bSManish Rangankar 	struct Scsi_Host *shost = cmd->device->host;
36ace7f46bSManish Rangankar 	struct qedi_ctx *qedi;
37ace7f46bSManish Rangankar 
38ace7f46bSManish Rangankar 	qedi = iscsi_host_priv(shost);
39ace7f46bSManish Rangankar 
40ace7f46bSManish Rangankar 	return qedi_recover_all_conns(qedi);
41ace7f46bSManish Rangankar }
42ace7f46bSManish Rangankar 
43*80602acaSBart Van Assche const struct scsi_host_template qedi_host_template = {
44ace7f46bSManish Rangankar 	.module = THIS_MODULE,
45ace7f46bSManish Rangankar 	.name = "QLogic QEDI 25/40/100Gb iSCSI Initiator Driver",
46ace7f46bSManish Rangankar 	.proc_name = QEDI_MODULE_NAME,
47ace7f46bSManish Rangankar 	.queuecommand = iscsi_queuecommand,
48b6a05c82SChristoph Hellwig 	.eh_timed_out = iscsi_eh_cmd_timed_out,
49ace7f46bSManish Rangankar 	.eh_abort_handler = iscsi_eh_abort,
50ace7f46bSManish Rangankar 	.eh_device_reset_handler = iscsi_eh_device_reset,
51ace7f46bSManish Rangankar 	.eh_target_reset_handler = iscsi_eh_recover_target,
52ace7f46bSManish Rangankar 	.eh_host_reset_handler = qedi_eh_host_reset,
53ace7f46bSManish Rangankar 	.target_alloc = iscsi_target_alloc,
54ace7f46bSManish Rangankar 	.change_queue_depth = scsi_change_queue_depth,
55ace7f46bSManish Rangankar 	.can_queue = QEDI_MAX_ISCSI_TASK,
56ace7f46bSManish Rangankar 	.this_id = -1,
57ace7f46bSManish Rangankar 	.sg_tablesize = QEDI_ISCSI_MAX_BDS_PER_CMD,
58ace7f46bSManish Rangankar 	.max_sectors = 0xffff,
59d0788a52Smanish.rangankar@cavium.com 	.dma_boundary = QEDI_HW_DMA_BOUNDARY,
60ace7f46bSManish Rangankar 	.cmd_per_lun = 128,
611ebbd3b1SBart Van Assche 	.shost_groups = qedi_shost_groups,
62db22de3eSBart Van Assche 	.cmd_size = sizeof(struct iscsi_cmd),
63ace7f46bSManish Rangankar };
64ace7f46bSManish Rangankar 
qedi_conn_free_login_resources(struct qedi_ctx * qedi,struct qedi_conn * qedi_conn)65ace7f46bSManish Rangankar static void qedi_conn_free_login_resources(struct qedi_ctx *qedi,
66ace7f46bSManish Rangankar 					   struct qedi_conn *qedi_conn)
67ace7f46bSManish Rangankar {
68ace7f46bSManish Rangankar 	if (qedi_conn->gen_pdu.resp_bd_tbl) {
69ace7f46bSManish Rangankar 		dma_free_coherent(&qedi->pdev->dev, QEDI_PAGE_SIZE,
70ace7f46bSManish Rangankar 				  qedi_conn->gen_pdu.resp_bd_tbl,
71ace7f46bSManish Rangankar 				  qedi_conn->gen_pdu.resp_bd_dma);
72ace7f46bSManish Rangankar 		qedi_conn->gen_pdu.resp_bd_tbl = NULL;
73ace7f46bSManish Rangankar 	}
74ace7f46bSManish Rangankar 
75ace7f46bSManish Rangankar 	if (qedi_conn->gen_pdu.req_bd_tbl) {
76ace7f46bSManish Rangankar 		dma_free_coherent(&qedi->pdev->dev, QEDI_PAGE_SIZE,
77ace7f46bSManish Rangankar 				  qedi_conn->gen_pdu.req_bd_tbl,
78ace7f46bSManish Rangankar 				  qedi_conn->gen_pdu.req_bd_dma);
79ace7f46bSManish Rangankar 		qedi_conn->gen_pdu.req_bd_tbl = NULL;
80ace7f46bSManish Rangankar 	}
81ace7f46bSManish Rangankar 
82ace7f46bSManish Rangankar 	if (qedi_conn->gen_pdu.resp_buf) {
83ace7f46bSManish Rangankar 		dma_free_coherent(&qedi->pdev->dev,
84ace7f46bSManish Rangankar 				  ISCSI_DEF_MAX_RECV_SEG_LEN,
85ace7f46bSManish Rangankar 				  qedi_conn->gen_pdu.resp_buf,
86ace7f46bSManish Rangankar 				  qedi_conn->gen_pdu.resp_dma_addr);
87ace7f46bSManish Rangankar 		qedi_conn->gen_pdu.resp_buf = NULL;
88ace7f46bSManish Rangankar 	}
89ace7f46bSManish Rangankar 
90ace7f46bSManish Rangankar 	if (qedi_conn->gen_pdu.req_buf) {
91ace7f46bSManish Rangankar 		dma_free_coherent(&qedi->pdev->dev,
92ace7f46bSManish Rangankar 				  ISCSI_DEF_MAX_RECV_SEG_LEN,
93ace7f46bSManish Rangankar 				  qedi_conn->gen_pdu.req_buf,
94ace7f46bSManish Rangankar 				  qedi_conn->gen_pdu.req_dma_addr);
95ace7f46bSManish Rangankar 		qedi_conn->gen_pdu.req_buf = NULL;
96ace7f46bSManish Rangankar 	}
97ace7f46bSManish Rangankar }
98ace7f46bSManish Rangankar 
qedi_conn_alloc_login_resources(struct qedi_ctx * qedi,struct qedi_conn * qedi_conn)99ace7f46bSManish Rangankar static int qedi_conn_alloc_login_resources(struct qedi_ctx *qedi,
100ace7f46bSManish Rangankar 					   struct qedi_conn *qedi_conn)
101ace7f46bSManish Rangankar {
102ace7f46bSManish Rangankar 	qedi_conn->gen_pdu.req_buf =
103ace7f46bSManish Rangankar 		dma_alloc_coherent(&qedi->pdev->dev,
104ace7f46bSManish Rangankar 				   ISCSI_DEF_MAX_RECV_SEG_LEN,
105ace7f46bSManish Rangankar 				   &qedi_conn->gen_pdu.req_dma_addr,
106ace7f46bSManish Rangankar 				   GFP_KERNEL);
107ace7f46bSManish Rangankar 	if (!qedi_conn->gen_pdu.req_buf)
108ace7f46bSManish Rangankar 		goto login_req_buf_failure;
109ace7f46bSManish Rangankar 
110ace7f46bSManish Rangankar 	qedi_conn->gen_pdu.req_buf_size = 0;
111ace7f46bSManish Rangankar 	qedi_conn->gen_pdu.req_wr_ptr = qedi_conn->gen_pdu.req_buf;
112ace7f46bSManish Rangankar 
113ace7f46bSManish Rangankar 	qedi_conn->gen_pdu.resp_buf =
114ace7f46bSManish Rangankar 		dma_alloc_coherent(&qedi->pdev->dev,
115ace7f46bSManish Rangankar 				   ISCSI_DEF_MAX_RECV_SEG_LEN,
116ace7f46bSManish Rangankar 				   &qedi_conn->gen_pdu.resp_dma_addr,
117ace7f46bSManish Rangankar 				   GFP_KERNEL);
118ace7f46bSManish Rangankar 	if (!qedi_conn->gen_pdu.resp_buf)
119ace7f46bSManish Rangankar 		goto login_resp_buf_failure;
120ace7f46bSManish Rangankar 
121ace7f46bSManish Rangankar 	qedi_conn->gen_pdu.resp_buf_size = ISCSI_DEF_MAX_RECV_SEG_LEN;
122ace7f46bSManish Rangankar 	qedi_conn->gen_pdu.resp_wr_ptr = qedi_conn->gen_pdu.resp_buf;
123ace7f46bSManish Rangankar 
124ace7f46bSManish Rangankar 	qedi_conn->gen_pdu.req_bd_tbl =
125ace7f46bSManish Rangankar 		dma_alloc_coherent(&qedi->pdev->dev, QEDI_PAGE_SIZE,
126ace7f46bSManish Rangankar 				   &qedi_conn->gen_pdu.req_bd_dma, GFP_KERNEL);
127ace7f46bSManish Rangankar 	if (!qedi_conn->gen_pdu.req_bd_tbl)
128ace7f46bSManish Rangankar 		goto login_req_bd_tbl_failure;
129ace7f46bSManish Rangankar 
130ace7f46bSManish Rangankar 	qedi_conn->gen_pdu.resp_bd_tbl =
131ace7f46bSManish Rangankar 		dma_alloc_coherent(&qedi->pdev->dev, QEDI_PAGE_SIZE,
132ace7f46bSManish Rangankar 				   &qedi_conn->gen_pdu.resp_bd_dma,
133ace7f46bSManish Rangankar 				   GFP_KERNEL);
134ace7f46bSManish Rangankar 	if (!qedi_conn->gen_pdu.resp_bd_tbl)
135ace7f46bSManish Rangankar 		goto login_resp_bd_tbl_failure;
136ace7f46bSManish Rangankar 
137ace7f46bSManish Rangankar 	QEDI_INFO(&qedi->dbg_ctx, QEDI_LOG_SESS,
138ace7f46bSManish Rangankar 		  "Allocation successful, cid=0x%x\n",
139ace7f46bSManish Rangankar 		  qedi_conn->iscsi_conn_id);
140ace7f46bSManish Rangankar 	return 0;
141ace7f46bSManish Rangankar 
142ace7f46bSManish Rangankar login_resp_bd_tbl_failure:
143ace7f46bSManish Rangankar 	dma_free_coherent(&qedi->pdev->dev, QEDI_PAGE_SIZE,
144ace7f46bSManish Rangankar 			  qedi_conn->gen_pdu.req_bd_tbl,
145ace7f46bSManish Rangankar 			  qedi_conn->gen_pdu.req_bd_dma);
146ace7f46bSManish Rangankar 	qedi_conn->gen_pdu.req_bd_tbl = NULL;
147ace7f46bSManish Rangankar 
148ace7f46bSManish Rangankar login_req_bd_tbl_failure:
149ace7f46bSManish Rangankar 	dma_free_coherent(&qedi->pdev->dev, ISCSI_DEF_MAX_RECV_SEG_LEN,
150ace7f46bSManish Rangankar 			  qedi_conn->gen_pdu.resp_buf,
151ace7f46bSManish Rangankar 			  qedi_conn->gen_pdu.resp_dma_addr);
152ace7f46bSManish Rangankar 	qedi_conn->gen_pdu.resp_buf = NULL;
153ace7f46bSManish Rangankar login_resp_buf_failure:
154ace7f46bSManish Rangankar 	dma_free_coherent(&qedi->pdev->dev, ISCSI_DEF_MAX_RECV_SEG_LEN,
155ace7f46bSManish Rangankar 			  qedi_conn->gen_pdu.req_buf,
156ace7f46bSManish Rangankar 			  qedi_conn->gen_pdu.req_dma_addr);
157ace7f46bSManish Rangankar 	qedi_conn->gen_pdu.req_buf = NULL;
158ace7f46bSManish Rangankar login_req_buf_failure:
159ace7f46bSManish Rangankar 	iscsi_conn_printk(KERN_ERR, qedi_conn->cls_conn->dd_data,
160ace7f46bSManish Rangankar 			  "login resource alloc failed!!\n");
161ace7f46bSManish Rangankar 	return -ENOMEM;
162ace7f46bSManish Rangankar }
163ace7f46bSManish Rangankar 
qedi_destroy_cmd_pool(struct qedi_ctx * qedi,struct iscsi_session * session)164ace7f46bSManish Rangankar static void qedi_destroy_cmd_pool(struct qedi_ctx *qedi,
165ace7f46bSManish Rangankar 				  struct iscsi_session *session)
166ace7f46bSManish Rangankar {
167ace7f46bSManish Rangankar 	int i;
168ace7f46bSManish Rangankar 
169ace7f46bSManish Rangankar 	for (i = 0; i < session->cmds_max; i++) {
170ace7f46bSManish Rangankar 		struct iscsi_task *task = session->cmds[i];
171ace7f46bSManish Rangankar 		struct qedi_cmd *cmd = task->dd_data;
172ace7f46bSManish Rangankar 
173ace7f46bSManish Rangankar 		if (cmd->io_tbl.sge_tbl)
174ace7f46bSManish Rangankar 			dma_free_coherent(&qedi->pdev->dev,
175ace7f46bSManish Rangankar 					  QEDI_ISCSI_MAX_BDS_PER_CMD *
176be086e7cSMintz, Yuval 					  sizeof(struct scsi_sge),
177ace7f46bSManish Rangankar 					  cmd->io_tbl.sge_tbl,
178ace7f46bSManish Rangankar 					  cmd->io_tbl.sge_tbl_dma);
179ace7f46bSManish Rangankar 
180ace7f46bSManish Rangankar 		if (cmd->sense_buffer)
181ace7f46bSManish Rangankar 			dma_free_coherent(&qedi->pdev->dev,
182ace7f46bSManish Rangankar 					  SCSI_SENSE_BUFFERSIZE,
183ace7f46bSManish Rangankar 					  cmd->sense_buffer,
184ace7f46bSManish Rangankar 					  cmd->sense_buffer_dma);
185ace7f46bSManish Rangankar 	}
186ace7f46bSManish Rangankar }
187ace7f46bSManish Rangankar 
qedi_alloc_sget(struct qedi_ctx * qedi,struct iscsi_session * session,struct qedi_cmd * cmd)188ace7f46bSManish Rangankar static int qedi_alloc_sget(struct qedi_ctx *qedi, struct iscsi_session *session,
189ace7f46bSManish Rangankar 			   struct qedi_cmd *cmd)
190ace7f46bSManish Rangankar {
191ace7f46bSManish Rangankar 	struct qedi_io_bdt *io = &cmd->io_tbl;
192be086e7cSMintz, Yuval 	struct scsi_sge *sge;
193ace7f46bSManish Rangankar 
194ace7f46bSManish Rangankar 	io->sge_tbl = dma_alloc_coherent(&qedi->pdev->dev,
195ace7f46bSManish Rangankar 					 QEDI_ISCSI_MAX_BDS_PER_CMD *
196ace7f46bSManish Rangankar 					 sizeof(*sge),
197ace7f46bSManish Rangankar 					 &io->sge_tbl_dma, GFP_KERNEL);
198ace7f46bSManish Rangankar 	if (!io->sge_tbl) {
199ace7f46bSManish Rangankar 		iscsi_session_printk(KERN_ERR, session,
200ace7f46bSManish Rangankar 				     "Could not allocate BD table.\n");
201ace7f46bSManish Rangankar 		return -ENOMEM;
202ace7f46bSManish Rangankar 	}
203ace7f46bSManish Rangankar 
204ace7f46bSManish Rangankar 	io->sge_valid = 0;
205ace7f46bSManish Rangankar 	return 0;
206ace7f46bSManish Rangankar }
207ace7f46bSManish Rangankar 
qedi_setup_cmd_pool(struct qedi_ctx * qedi,struct iscsi_session * session)208ace7f46bSManish Rangankar static int qedi_setup_cmd_pool(struct qedi_ctx *qedi,
209ace7f46bSManish Rangankar 			       struct iscsi_session *session)
210ace7f46bSManish Rangankar {
211ace7f46bSManish Rangankar 	int i;
212ace7f46bSManish Rangankar 
213ace7f46bSManish Rangankar 	for (i = 0; i < session->cmds_max; i++) {
214ace7f46bSManish Rangankar 		struct iscsi_task *task = session->cmds[i];
215ace7f46bSManish Rangankar 		struct qedi_cmd *cmd = task->dd_data;
216ace7f46bSManish Rangankar 
217ace7f46bSManish Rangankar 		task->hdr = &cmd->hdr;
218ace7f46bSManish Rangankar 		task->hdr_max = sizeof(struct iscsi_hdr);
219ace7f46bSManish Rangankar 
220ace7f46bSManish Rangankar 		if (qedi_alloc_sget(qedi, session, cmd))
221ace7f46bSManish Rangankar 			goto free_sgets;
222ace7f46bSManish Rangankar 
223ace7f46bSManish Rangankar 		cmd->sense_buffer = dma_alloc_coherent(&qedi->pdev->dev,
224ace7f46bSManish Rangankar 						       SCSI_SENSE_BUFFERSIZE,
225ace7f46bSManish Rangankar 						       &cmd->sense_buffer_dma,
226ace7f46bSManish Rangankar 						       GFP_KERNEL);
227ace7f46bSManish Rangankar 		if (!cmd->sense_buffer)
228ace7f46bSManish Rangankar 			goto free_sgets;
229ace7f46bSManish Rangankar 	}
230ace7f46bSManish Rangankar 
231ace7f46bSManish Rangankar 	return 0;
232ace7f46bSManish Rangankar 
233ace7f46bSManish Rangankar free_sgets:
234ace7f46bSManish Rangankar 	qedi_destroy_cmd_pool(qedi, session);
235ace7f46bSManish Rangankar 	return -ENOMEM;
236ace7f46bSManish Rangankar }
237ace7f46bSManish Rangankar 
238ace7f46bSManish Rangankar static struct iscsi_cls_session *
qedi_session_create(struct iscsi_endpoint * ep,u16 cmds_max,u16 qdepth,uint32_t initial_cmdsn)239ace7f46bSManish Rangankar qedi_session_create(struct iscsi_endpoint *ep, u16 cmds_max,
240ace7f46bSManish Rangankar 		    u16 qdepth, uint32_t initial_cmdsn)
241ace7f46bSManish Rangankar {
242ace7f46bSManish Rangankar 	struct Scsi_Host *shost;
243ace7f46bSManish Rangankar 	struct iscsi_cls_session *cls_session;
244ace7f46bSManish Rangankar 	struct qedi_ctx *qedi;
245ace7f46bSManish Rangankar 	struct qedi_endpoint *qedi_ep;
246ace7f46bSManish Rangankar 
247ace7f46bSManish Rangankar 	if (!ep)
248ace7f46bSManish Rangankar 		return NULL;
249ace7f46bSManish Rangankar 
250ace7f46bSManish Rangankar 	qedi_ep = ep->dd_data;
251ace7f46bSManish Rangankar 	shost = qedi_ep->qedi->shost;
252ace7f46bSManish Rangankar 	qedi = iscsi_host_priv(shost);
253ace7f46bSManish Rangankar 
254ace7f46bSManish Rangankar 	if (cmds_max > qedi->max_sqes)
255ace7f46bSManish Rangankar 		cmds_max = qedi->max_sqes;
256ace7f46bSManish Rangankar 	else if (cmds_max < QEDI_SQ_WQES_MIN)
257ace7f46bSManish Rangankar 		cmds_max = QEDI_SQ_WQES_MIN;
258ace7f46bSManish Rangankar 
259ace7f46bSManish Rangankar 	cls_session = iscsi_session_setup(&qedi_iscsi_transport, shost,
260ace7f46bSManish Rangankar 					  cmds_max, 0, sizeof(struct qedi_cmd),
261ace7f46bSManish Rangankar 					  initial_cmdsn, ISCSI_MAX_TARGET);
262ace7f46bSManish Rangankar 	if (!cls_session) {
263ace7f46bSManish Rangankar 		QEDI_ERR(&qedi->dbg_ctx,
264ace7f46bSManish Rangankar 			 "Failed to setup session for ep=%p\n", qedi_ep);
265ace7f46bSManish Rangankar 		return NULL;
266ace7f46bSManish Rangankar 	}
267ace7f46bSManish Rangankar 
268ace7f46bSManish Rangankar 	if (qedi_setup_cmd_pool(qedi, cls_session->dd_data)) {
269ace7f46bSManish Rangankar 		QEDI_ERR(&qedi->dbg_ctx,
270ace7f46bSManish Rangankar 			 "Failed to setup cmd pool for ep=%p\n", qedi_ep);
271ace7f46bSManish Rangankar 		goto session_teardown;
272ace7f46bSManish Rangankar 	}
273ace7f46bSManish Rangankar 
274ace7f46bSManish Rangankar 	return cls_session;
275ace7f46bSManish Rangankar 
276ace7f46bSManish Rangankar session_teardown:
277ace7f46bSManish Rangankar 	iscsi_session_teardown(cls_session);
278ace7f46bSManish Rangankar 	return NULL;
279ace7f46bSManish Rangankar }
280ace7f46bSManish Rangankar 
qedi_session_destroy(struct iscsi_cls_session * cls_session)281ace7f46bSManish Rangankar static void qedi_session_destroy(struct iscsi_cls_session *cls_session)
282ace7f46bSManish Rangankar {
283ace7f46bSManish Rangankar 	struct iscsi_session *session = cls_session->dd_data;
284ace7f46bSManish Rangankar 	struct Scsi_Host *shost = iscsi_session_to_shost(cls_session);
285ace7f46bSManish Rangankar 	struct qedi_ctx *qedi = iscsi_host_priv(shost);
286ace7f46bSManish Rangankar 
287ace7f46bSManish Rangankar 	qedi_destroy_cmd_pool(qedi, session);
288ace7f46bSManish Rangankar 	iscsi_session_teardown(cls_session);
289ace7f46bSManish Rangankar }
290ace7f46bSManish Rangankar 
291ace7f46bSManish Rangankar static struct iscsi_cls_conn *
qedi_conn_create(struct iscsi_cls_session * cls_session,uint32_t cid)292ace7f46bSManish Rangankar qedi_conn_create(struct iscsi_cls_session *cls_session, uint32_t cid)
293ace7f46bSManish Rangankar {
294ace7f46bSManish Rangankar 	struct Scsi_Host *shost = iscsi_session_to_shost(cls_session);
295ace7f46bSManish Rangankar 	struct qedi_ctx *qedi = iscsi_host_priv(shost);
296ace7f46bSManish Rangankar 	struct iscsi_cls_conn *cls_conn;
297ace7f46bSManish Rangankar 	struct qedi_conn *qedi_conn;
298ace7f46bSManish Rangankar 	struct iscsi_conn *conn;
299ace7f46bSManish Rangankar 
300ace7f46bSManish Rangankar 	cls_conn = iscsi_conn_setup(cls_session, sizeof(*qedi_conn),
301ace7f46bSManish Rangankar 				    cid);
302ace7f46bSManish Rangankar 	if (!cls_conn) {
303ace7f46bSManish Rangankar 		QEDI_ERR(&qedi->dbg_ctx,
304ace7f46bSManish Rangankar 			 "conn_new: iscsi conn setup failed, cid=0x%x, cls_sess=%p!\n",
305ace7f46bSManish Rangankar 			 cid, cls_session);
306ace7f46bSManish Rangankar 		return NULL;
307ace7f46bSManish Rangankar 	}
308ace7f46bSManish Rangankar 
309ace7f46bSManish Rangankar 	conn = cls_conn->dd_data;
310ace7f46bSManish Rangankar 	qedi_conn = conn->dd_data;
311ace7f46bSManish Rangankar 	qedi_conn->cls_conn = cls_conn;
312ace7f46bSManish Rangankar 	qedi_conn->qedi = qedi;
313ace7f46bSManish Rangankar 	qedi_conn->ep = NULL;
314ace7f46bSManish Rangankar 	qedi_conn->active_cmd_count = 0;
315ace7f46bSManish Rangankar 	INIT_LIST_HEAD(&qedi_conn->active_cmd_list);
316ace7f46bSManish Rangankar 	spin_lock_init(&qedi_conn->list_lock);
317ace7f46bSManish Rangankar 
318ace7f46bSManish Rangankar 	if (qedi_conn_alloc_login_resources(qedi, qedi_conn)) {
319ace7f46bSManish Rangankar 		iscsi_conn_printk(KERN_ALERT, conn,
320ace7f46bSManish Rangankar 				  "conn_new: login resc alloc failed, cid=0x%x, cls_sess=%p!!\n",
321ace7f46bSManish Rangankar 				   cid, cls_session);
322ace7f46bSManish Rangankar 		goto free_conn;
323ace7f46bSManish Rangankar 	}
324ace7f46bSManish Rangankar 
325ace7f46bSManish Rangankar 	return cls_conn;
326ace7f46bSManish Rangankar 
327ace7f46bSManish Rangankar free_conn:
328ace7f46bSManish Rangankar 	iscsi_conn_teardown(cls_conn);
329ace7f46bSManish Rangankar 	return NULL;
330ace7f46bSManish Rangankar }
331ace7f46bSManish Rangankar 
qedi_mark_device_missing(struct iscsi_cls_session * cls_session)332ace7f46bSManish Rangankar void qedi_mark_device_missing(struct iscsi_cls_session *cls_session)
333ace7f46bSManish Rangankar {
3340c72191dSMike Christie 	struct iscsi_session *session = cls_session->dd_data;
3350c72191dSMike Christie 	struct qedi_conn *qedi_conn = session->leadconn->dd_data;
3360c72191dSMike Christie 
3370c72191dSMike Christie 	spin_lock_bh(&session->frwd_lock);
3380c72191dSMike Christie 	set_bit(QEDI_BLOCK_IO, &qedi_conn->qedi->flags);
3390c72191dSMike Christie 	spin_unlock_bh(&session->frwd_lock);
340ace7f46bSManish Rangankar }
341ace7f46bSManish Rangankar 
qedi_mark_device_available(struct iscsi_cls_session * cls_session)342ace7f46bSManish Rangankar void qedi_mark_device_available(struct iscsi_cls_session *cls_session)
343ace7f46bSManish Rangankar {
3440c72191dSMike Christie 	struct iscsi_session *session = cls_session->dd_data;
3450c72191dSMike Christie 	struct qedi_conn *qedi_conn = session->leadconn->dd_data;
3460c72191dSMike Christie 
3470c72191dSMike Christie 	spin_lock_bh(&session->frwd_lock);
3480c72191dSMike Christie 	clear_bit(QEDI_BLOCK_IO, &qedi_conn->qedi->flags);
3490c72191dSMike Christie 	spin_unlock_bh(&session->frwd_lock);
350ace7f46bSManish Rangankar }
351ace7f46bSManish Rangankar 
qedi_bind_conn_to_iscsi_cid(struct qedi_ctx * qedi,struct qedi_conn * qedi_conn)352ace7f46bSManish Rangankar static int qedi_bind_conn_to_iscsi_cid(struct qedi_ctx *qedi,
353ace7f46bSManish Rangankar 				       struct qedi_conn *qedi_conn)
354ace7f46bSManish Rangankar {
355ace7f46bSManish Rangankar 	u32 iscsi_cid = qedi_conn->iscsi_conn_id;
356ace7f46bSManish Rangankar 
357ace7f46bSManish Rangankar 	if (qedi->cid_que.conn_cid_tbl[iscsi_cid]) {
358ace7f46bSManish Rangankar 		iscsi_conn_printk(KERN_ALERT, qedi_conn->cls_conn->dd_data,
359ace7f46bSManish Rangankar 				  "conn bind - entry #%d not free\n",
360ace7f46bSManish Rangankar 				  iscsi_cid);
361ace7f46bSManish Rangankar 		return -EBUSY;
362ace7f46bSManish Rangankar 	}
363ace7f46bSManish Rangankar 
364ace7f46bSManish Rangankar 	qedi->cid_que.conn_cid_tbl[iscsi_cid] = qedi_conn;
365ace7f46bSManish Rangankar 	return 0;
366ace7f46bSManish Rangankar }
367ace7f46bSManish Rangankar 
qedi_get_conn_from_id(struct qedi_ctx * qedi,u32 iscsi_cid)368ace7f46bSManish Rangankar struct qedi_conn *qedi_get_conn_from_id(struct qedi_ctx *qedi, u32 iscsi_cid)
369ace7f46bSManish Rangankar {
370ace7f46bSManish Rangankar 	if (!qedi->cid_que.conn_cid_tbl) {
371ace7f46bSManish Rangankar 		QEDI_ERR(&qedi->dbg_ctx, "missing conn<->cid table\n");
372ace7f46bSManish Rangankar 		return NULL;
373ace7f46bSManish Rangankar 
374ace7f46bSManish Rangankar 	} else if (iscsi_cid >= qedi->max_active_conns) {
375ace7f46bSManish Rangankar 		QEDI_ERR(&qedi->dbg_ctx, "wrong cid #%d\n", iscsi_cid);
376ace7f46bSManish Rangankar 		return NULL;
377ace7f46bSManish Rangankar 	}
378ace7f46bSManish Rangankar 	return qedi->cid_que.conn_cid_tbl[iscsi_cid];
379ace7f46bSManish Rangankar }
380ace7f46bSManish Rangankar 
qedi_conn_bind(struct iscsi_cls_session * cls_session,struct iscsi_cls_conn * cls_conn,u64 transport_fd,int is_leading)381ace7f46bSManish Rangankar static int qedi_conn_bind(struct iscsi_cls_session *cls_session,
382ace7f46bSManish Rangankar 			  struct iscsi_cls_conn *cls_conn,
383ace7f46bSManish Rangankar 			  u64 transport_fd, int is_leading)
384ace7f46bSManish Rangankar {
385ace7f46bSManish Rangankar 	struct iscsi_conn *conn = cls_conn->dd_data;
386ace7f46bSManish Rangankar 	struct qedi_conn *qedi_conn = conn->dd_data;
387ace7f46bSManish Rangankar 	struct Scsi_Host *shost = iscsi_session_to_shost(cls_session);
388ace7f46bSManish Rangankar 	struct qedi_ctx *qedi = iscsi_host_priv(shost);
389ace7f46bSManish Rangankar 	struct qedi_endpoint *qedi_ep;
390ace7f46bSManish Rangankar 	struct iscsi_endpoint *ep;
3919e5fe170SMike Christie 	int rc = 0;
392ace7f46bSManish Rangankar 
393ace7f46bSManish Rangankar 	ep = iscsi_lookup_endpoint(transport_fd);
394ace7f46bSManish Rangankar 	if (!ep)
395ace7f46bSManish Rangankar 		return -EINVAL;
396ace7f46bSManish Rangankar 
397ace7f46bSManish Rangankar 	qedi_ep = ep->dd_data;
398ace7f46bSManish Rangankar 	if ((qedi_ep->state == EP_STATE_TCP_FIN_RCVD) ||
3999e5fe170SMike Christie 	    (qedi_ep->state == EP_STATE_TCP_RST_RCVD)) {
4009e5fe170SMike Christie 		rc = -EINVAL;
4019e5fe170SMike Christie 		goto put_ep;
4029e5fe170SMike Christie 	}
403ace7f46bSManish Rangankar 
4049e5fe170SMike Christie 	if (iscsi_conn_bind(cls_session, cls_conn, is_leading)) {
4059e5fe170SMike Christie 		rc = -EINVAL;
4069e5fe170SMike Christie 		goto put_ep;
4079e5fe170SMike Christie 	}
4089e5fe170SMike Christie 
409ace7f46bSManish Rangankar 
410ace7f46bSManish Rangankar 	qedi_ep->conn = qedi_conn;
411ace7f46bSManish Rangankar 	qedi_conn->ep = qedi_ep;
4124f93c4bfSManish Rangankar 	qedi_conn->iscsi_ep = ep;
413ace7f46bSManish Rangankar 	qedi_conn->iscsi_conn_id = qedi_ep->iscsi_cid;
414ace7f46bSManish Rangankar 	qedi_conn->fw_cid = qedi_ep->fw_cid;
415ace7f46bSManish Rangankar 	qedi_conn->cmd_cleanup_req = 0;
4163fe5185dSManish Rangankar 	atomic_set(&qedi_conn->cmd_cleanup_cmpl, 0);
417ace7f46bSManish Rangankar 
4189e5fe170SMike Christie 	if (qedi_bind_conn_to_iscsi_cid(qedi, qedi_conn)) {
4199e5fe170SMike Christie 		rc = -EINVAL;
4209e5fe170SMike Christie 		goto put_ep;
4219e5fe170SMike Christie 	}
4229e5fe170SMike Christie 
423ace7f46bSManish Rangankar 
424ace7f46bSManish Rangankar 	spin_lock_init(&qedi_conn->tmf_work_lock);
425ace7f46bSManish Rangankar 	INIT_LIST_HEAD(&qedi_conn->tmf_work_list);
426ace7f46bSManish Rangankar 	init_waitqueue_head(&qedi_conn->wait_queue);
4279e5fe170SMike Christie put_ep:
4289e5fe170SMike Christie 	iscsi_put_endpoint(ep);
4299e5fe170SMike Christie 	return rc;
430ace7f46bSManish Rangankar }
431ace7f46bSManish Rangankar 
qedi_iscsi_update_conn(struct qedi_ctx * qedi,struct qedi_conn * qedi_conn)432ace7f46bSManish Rangankar static int qedi_iscsi_update_conn(struct qedi_ctx *qedi,
433ace7f46bSManish Rangankar 				  struct qedi_conn *qedi_conn)
434ace7f46bSManish Rangankar {
435ace7f46bSManish Rangankar 	struct qed_iscsi_params_update *conn_info;
436ace7f46bSManish Rangankar 	struct iscsi_cls_conn *cls_conn = qedi_conn->cls_conn;
437ace7f46bSManish Rangankar 	struct iscsi_conn *conn = cls_conn->dd_data;
438ace7f46bSManish Rangankar 	struct qedi_endpoint *qedi_ep;
439ace7f46bSManish Rangankar 	int rval;
440ace7f46bSManish Rangankar 
441ace7f46bSManish Rangankar 	qedi_ep = qedi_conn->ep;
442ace7f46bSManish Rangankar 
443ace7f46bSManish Rangankar 	conn_info = kzalloc(sizeof(*conn_info), GFP_KERNEL);
444ace7f46bSManish Rangankar 	if (!conn_info) {
445ace7f46bSManish Rangankar 		QEDI_ERR(&qedi->dbg_ctx, "memory alloc failed\n");
446ace7f46bSManish Rangankar 		return -ENOMEM;
447ace7f46bSManish Rangankar 	}
448ace7f46bSManish Rangankar 
449ace7f46bSManish Rangankar 	conn_info->update_flag = 0;
450ace7f46bSManish Rangankar 
451ace7f46bSManish Rangankar 	if (conn->hdrdgst_en)
452ace7f46bSManish Rangankar 		SET_FIELD(conn_info->update_flag,
453ace7f46bSManish Rangankar 			  ISCSI_CONN_UPDATE_RAMROD_PARAMS_HD_EN, true);
454ace7f46bSManish Rangankar 	if (conn->datadgst_en)
455ace7f46bSManish Rangankar 		SET_FIELD(conn_info->update_flag,
456ace7f46bSManish Rangankar 			  ISCSI_CONN_UPDATE_RAMROD_PARAMS_DD_EN, true);
457ace7f46bSManish Rangankar 	if (conn->session->initial_r2t_en)
458ace7f46bSManish Rangankar 		SET_FIELD(conn_info->update_flag,
459ace7f46bSManish Rangankar 			  ISCSI_CONN_UPDATE_RAMROD_PARAMS_INITIAL_R2T,
460ace7f46bSManish Rangankar 			  true);
461ace7f46bSManish Rangankar 	if (conn->session->imm_data_en)
462ace7f46bSManish Rangankar 		SET_FIELD(conn_info->update_flag,
463ace7f46bSManish Rangankar 			  ISCSI_CONN_UPDATE_RAMROD_PARAMS_IMMEDIATE_DATA,
464ace7f46bSManish Rangankar 			  true);
465ace7f46bSManish Rangankar 
466ace7f46bSManish Rangankar 	conn_info->max_seq_size = conn->session->max_burst;
467ace7f46bSManish Rangankar 	conn_info->max_recv_pdu_length = conn->max_recv_dlength;
468ace7f46bSManish Rangankar 	conn_info->max_send_pdu_length = conn->max_xmit_dlength;
469ace7f46bSManish Rangankar 	conn_info->first_seq_length = conn->session->first_burst;
470ace7f46bSManish Rangankar 	conn_info->exp_stat_sn = conn->exp_statsn;
471ace7f46bSManish Rangankar 
472ace7f46bSManish Rangankar 	rval = qedi_ops->update_conn(qedi->cdev, qedi_ep->handle,
473ace7f46bSManish Rangankar 				     conn_info);
474ace7f46bSManish Rangankar 	if (rval) {
475ace7f46bSManish Rangankar 		rval = -ENXIO;
476ace7f46bSManish Rangankar 		QEDI_ERR(&qedi->dbg_ctx, "Could not update connection\n");
477ace7f46bSManish Rangankar 	}
478ace7f46bSManish Rangankar 
479ace7f46bSManish Rangankar 	kfree(conn_info);
480ace7f46bSManish Rangankar 	return rval;
481ace7f46bSManish Rangankar }
482ace7f46bSManish Rangankar 
qedi_calc_mss(u16 pmtu,u8 is_ipv6,u8 tcp_ts_en,u8 vlan_en)483ace7f46bSManish Rangankar static u16 qedi_calc_mss(u16 pmtu, u8 is_ipv6, u8 tcp_ts_en, u8 vlan_en)
484ace7f46bSManish Rangankar {
485ace7f46bSManish Rangankar 	u16 mss = 0;
486ace7f46bSManish Rangankar 	u16 hdrs = TCP_HDR_LEN;
487ace7f46bSManish Rangankar 
488ace7f46bSManish Rangankar 	if (is_ipv6)
489ace7f46bSManish Rangankar 		hdrs += IPV6_HDR_LEN;
490ace7f46bSManish Rangankar 	else
491ace7f46bSManish Rangankar 		hdrs += IPV4_HDR_LEN;
492ace7f46bSManish Rangankar 
493ace7f46bSManish Rangankar 	mss = pmtu - hdrs;
494ace7f46bSManish Rangankar 
495ace7f46bSManish Rangankar 	if (!mss)
496ace7f46bSManish Rangankar 		mss = DEF_MSS;
497ace7f46bSManish Rangankar 
498ace7f46bSManish Rangankar 	return mss;
499ace7f46bSManish Rangankar }
500ace7f46bSManish Rangankar 
qedi_iscsi_offload_conn(struct qedi_endpoint * qedi_ep)501ace7f46bSManish Rangankar static int qedi_iscsi_offload_conn(struct qedi_endpoint *qedi_ep)
502ace7f46bSManish Rangankar {
503ace7f46bSManish Rangankar 	struct qed_iscsi_params_offload *conn_info;
5049757f8afSShai Malin 	struct qedi_ctx *qedi = qedi_ep->qedi;
505ace7f46bSManish Rangankar 	int rval;
506ace7f46bSManish Rangankar 	int i;
507ace7f46bSManish Rangankar 
508ace7f46bSManish Rangankar 	conn_info = kzalloc(sizeof(*conn_info), GFP_KERNEL);
509ace7f46bSManish Rangankar 	if (!conn_info) {
510ace7f46bSManish Rangankar 		QEDI_ERR(&qedi->dbg_ctx,
511ace7f46bSManish Rangankar 			 "Failed to allocate memory ep=%p\n", qedi_ep);
512ace7f46bSManish Rangankar 		return -ENOMEM;
513ace7f46bSManish Rangankar 	}
514ace7f46bSManish Rangankar 
515ace7f46bSManish Rangankar 	ether_addr_copy(conn_info->src.mac, qedi_ep->src_mac);
516ace7f46bSManish Rangankar 	ether_addr_copy(conn_info->dst.mac, qedi_ep->dst_mac);
517ace7f46bSManish Rangankar 
518ace7f46bSManish Rangankar 	conn_info->src.ip[0] = ntohl(qedi_ep->src_addr[0]);
519ace7f46bSManish Rangankar 	conn_info->dst.ip[0] = ntohl(qedi_ep->dst_addr[0]);
520ace7f46bSManish Rangankar 
521ace7f46bSManish Rangankar 	if (qedi_ep->ip_type == TCP_IPV4) {
522ace7f46bSManish Rangankar 		conn_info->ip_version = 0;
523ace7f46bSManish Rangankar 		QEDI_INFO(&qedi->dbg_ctx, QEDI_LOG_CONN,
524ace7f46bSManish Rangankar 			  "After ntohl: src_addr=%pI4, dst_addr=%pI4\n",
525ace7f46bSManish Rangankar 			  qedi_ep->src_addr, qedi_ep->dst_addr);
526ace7f46bSManish Rangankar 	} else {
527ace7f46bSManish Rangankar 		for (i = 1; i < 4; i++) {
528ace7f46bSManish Rangankar 			conn_info->src.ip[i] = ntohl(qedi_ep->src_addr[i]);
529ace7f46bSManish Rangankar 			conn_info->dst.ip[i] = ntohl(qedi_ep->dst_addr[i]);
530ace7f46bSManish Rangankar 		}
531ace7f46bSManish Rangankar 
532ace7f46bSManish Rangankar 		conn_info->ip_version = 1;
533ace7f46bSManish Rangankar 		QEDI_INFO(&qedi->dbg_ctx, QEDI_LOG_CONN,
534ace7f46bSManish Rangankar 			  "After ntohl: src_addr=%pI6, dst_addr=%pI6\n",
535ace7f46bSManish Rangankar 			  qedi_ep->src_addr, qedi_ep->dst_addr);
536ace7f46bSManish Rangankar 	}
537ace7f46bSManish Rangankar 
538ace7f46bSManish Rangankar 	conn_info->src.port = qedi_ep->src_port;
539ace7f46bSManish Rangankar 	conn_info->dst.port = qedi_ep->dst_port;
540ace7f46bSManish Rangankar 
541ace7f46bSManish Rangankar 	conn_info->layer_code = ISCSI_SLOW_PATH_LAYER_CODE;
542ace7f46bSManish Rangankar 	conn_info->sq_pbl_addr = qedi_ep->sq_pbl_dma;
543ace7f46bSManish Rangankar 	conn_info->vlan_id = qedi_ep->vlan_id;
544ace7f46bSManish Rangankar 
545ace7f46bSManish Rangankar 	SET_FIELD(conn_info->tcp_flags, TCP_OFFLOAD_PARAMS_TS_EN, 1);
546ace7f46bSManish Rangankar 	SET_FIELD(conn_info->tcp_flags, TCP_OFFLOAD_PARAMS_DA_EN, 1);
547ace7f46bSManish Rangankar 	SET_FIELD(conn_info->tcp_flags, TCP_OFFLOAD_PARAMS_DA_CNT_EN, 1);
548ace7f46bSManish Rangankar 	SET_FIELD(conn_info->tcp_flags, TCP_OFFLOAD_PARAMS_KA_EN, 1);
549ace7f46bSManish Rangankar 
55042d7c10fSManish Rangankar 	conn_info->default_cq = (qedi_ep->fw_cid % qedi->num_queues);
551ace7f46bSManish Rangankar 
552ace7f46bSManish Rangankar 	conn_info->ka_max_probe_cnt = DEF_KA_MAX_PROBE_COUNT;
553ace7f46bSManish Rangankar 	conn_info->dup_ack_theshold = 3;
554ace7f46bSManish Rangankar 	conn_info->rcv_wnd = 65535;
555ace7f46bSManish Rangankar 
556ace7f46bSManish Rangankar 	conn_info->ss_thresh = 65535;
557ace7f46bSManish Rangankar 	conn_info->srtt = 300;
558ace7f46bSManish Rangankar 	conn_info->rtt_var = 150;
559ace7f46bSManish Rangankar 	conn_info->flow_label = 0;
560ace7f46bSManish Rangankar 	conn_info->ka_timeout = DEF_KA_TIMEOUT;
561ace7f46bSManish Rangankar 	conn_info->ka_interval = DEF_KA_INTERVAL;
562ace7f46bSManish Rangankar 	conn_info->max_rt_time = DEF_MAX_RT_TIME;
563ace7f46bSManish Rangankar 	conn_info->ttl = DEF_TTL;
564ace7f46bSManish Rangankar 	conn_info->tos_or_tc = DEF_TOS;
565ace7f46bSManish Rangankar 	conn_info->remote_port = qedi_ep->dst_port;
566ace7f46bSManish Rangankar 	conn_info->local_port = qedi_ep->src_port;
567ace7f46bSManish Rangankar 
568ace7f46bSManish Rangankar 	conn_info->mss = qedi_calc_mss(qedi_ep->pmtu,
569ace7f46bSManish Rangankar 				       (qedi_ep->ip_type == TCP_IPV6),
570ace7f46bSManish Rangankar 				       1, (qedi_ep->vlan_id != 0));
571ace7f46bSManish Rangankar 
572da090917STomer Tayar 	conn_info->cwnd = DEF_MAX_CWND * conn_info->mss;
573ace7f46bSManish Rangankar 	conn_info->rcv_wnd_scale = 4;
574ace7f46bSManish Rangankar 	conn_info->da_timeout_value = 200;
575ace7f46bSManish Rangankar 	conn_info->ack_frequency = 2;
576ace7f46bSManish Rangankar 
577ace7f46bSManish Rangankar 	QEDI_INFO(&qedi->dbg_ctx, QEDI_LOG_INFO,
578ace7f46bSManish Rangankar 		  "Default cq index [%d], mss [%d]\n",
579ace7f46bSManish Rangankar 		  conn_info->default_cq, conn_info->mss);
580ace7f46bSManish Rangankar 
5819757f8afSShai Malin 	/* Prepare the doorbell parameters */
5829757f8afSShai Malin 	qedi_ep->db_data.agg_flags = 0;
5839757f8afSShai Malin 	qedi_ep->db_data.params = 0;
5849757f8afSShai Malin 	SET_FIELD(qedi_ep->db_data.params, ISCSI_DB_DATA_DEST, DB_DEST_XCM);
5859757f8afSShai Malin 	SET_FIELD(qedi_ep->db_data.params, ISCSI_DB_DATA_AGG_CMD,
5869757f8afSShai Malin 		  DB_AGG_CMD_MAX);
5879757f8afSShai Malin 	SET_FIELD(qedi_ep->db_data.params, ISCSI_DB_DATA_AGG_VAL_SEL,
5889757f8afSShai Malin 		  DQ_XCM_ISCSI_SQ_PROD_CMD);
5899757f8afSShai Malin 	SET_FIELD(qedi_ep->db_data.params, ISCSI_DB_DATA_BYPASS_EN, 1);
5909757f8afSShai Malin 
5919757f8afSShai Malin 	/* Register doorbell with doorbell recovery mechanism */
5929757f8afSShai Malin 	rval = qedi_ops->common->db_recovery_add(qedi->cdev,
5939757f8afSShai Malin 						 qedi_ep->p_doorbell,
5949757f8afSShai Malin 						 &qedi_ep->db_data,
5959757f8afSShai Malin 						 DB_REC_WIDTH_32B,
5969757f8afSShai Malin 						 DB_REC_KERNEL);
5979757f8afSShai Malin 	if (rval) {
5989757f8afSShai Malin 		kfree(conn_info);
5999757f8afSShai Malin 		return rval;
6009757f8afSShai Malin 	}
6019757f8afSShai Malin 
602ace7f46bSManish Rangankar 	rval = qedi_ops->offload_conn(qedi->cdev, qedi_ep->handle, conn_info);
6039757f8afSShai Malin 	if (rval) {
6049757f8afSShai Malin 		/* delete doorbell from doorbell recovery mechanism */
6059757f8afSShai Malin 		rval = qedi_ops->common->db_recovery_del(qedi->cdev,
6069757f8afSShai Malin 							 qedi_ep->p_doorbell,
6079757f8afSShai Malin 							 &qedi_ep->db_data);
6089757f8afSShai Malin 
609ace7f46bSManish Rangankar 		QEDI_ERR(&qedi->dbg_ctx, "offload_conn returned %d, ep=%p\n",
610ace7f46bSManish Rangankar 			 rval, qedi_ep);
6119757f8afSShai Malin 	}
612ace7f46bSManish Rangankar 
613ace7f46bSManish Rangankar 	kfree(conn_info);
614ace7f46bSManish Rangankar 	return rval;
615ace7f46bSManish Rangankar }
616ace7f46bSManish Rangankar 
qedi_conn_start(struct iscsi_cls_conn * cls_conn)617ace7f46bSManish Rangankar static int qedi_conn_start(struct iscsi_cls_conn *cls_conn)
618ace7f46bSManish Rangankar {
619ace7f46bSManish Rangankar 	struct iscsi_conn *conn = cls_conn->dd_data;
620ace7f46bSManish Rangankar 	struct qedi_conn *qedi_conn = conn->dd_data;
621ace7f46bSManish Rangankar 	struct qedi_ctx *qedi;
622ace7f46bSManish Rangankar 	int rval;
623ace7f46bSManish Rangankar 
624ace7f46bSManish Rangankar 	qedi = qedi_conn->qedi;
625ace7f46bSManish Rangankar 
626ace7f46bSManish Rangankar 	rval = qedi_iscsi_update_conn(qedi, qedi_conn);
627ace7f46bSManish Rangankar 	if (rval) {
628ace7f46bSManish Rangankar 		iscsi_conn_printk(KERN_ALERT, conn,
629bc136f4dSColin Ian King 				  "conn_start: FW offload conn failed.\n");
630ace7f46bSManish Rangankar 		rval = -EINVAL;
631ace7f46bSManish Rangankar 		goto start_err;
632ace7f46bSManish Rangankar 	}
633ace7f46bSManish Rangankar 
634b40f3894SMike Christie 	spin_lock(&qedi_conn->tmf_work_lock);
635b40f3894SMike Christie 	qedi_conn->fw_cleanup_works = 0;
636b40f3894SMike Christie 	qedi_conn->ep_disconnect_starting = false;
637b40f3894SMike Christie 	spin_unlock(&qedi_conn->tmf_work_lock);
638b40f3894SMike Christie 
639ace7f46bSManish Rangankar 	qedi_conn->abrt_conn = 0;
640ace7f46bSManish Rangankar 
641ace7f46bSManish Rangankar 	rval = iscsi_conn_start(cls_conn);
642ace7f46bSManish Rangankar 	if (rval) {
643ace7f46bSManish Rangankar 		iscsi_conn_printk(KERN_ALERT, conn,
644bc136f4dSColin Ian King 				  "iscsi_conn_start: FW offload conn failed!!\n");
645ace7f46bSManish Rangankar 	}
646ace7f46bSManish Rangankar 
647ace7f46bSManish Rangankar start_err:
648ace7f46bSManish Rangankar 	return rval;
649ace7f46bSManish Rangankar }
650ace7f46bSManish Rangankar 
qedi_conn_destroy(struct iscsi_cls_conn * cls_conn)651ace7f46bSManish Rangankar static void qedi_conn_destroy(struct iscsi_cls_conn *cls_conn)
652ace7f46bSManish Rangankar {
653ace7f46bSManish Rangankar 	struct iscsi_conn *conn = cls_conn->dd_data;
654ace7f46bSManish Rangankar 	struct qedi_conn *qedi_conn = conn->dd_data;
655ace7f46bSManish Rangankar 	struct Scsi_Host *shost;
656ace7f46bSManish Rangankar 	struct qedi_ctx *qedi;
657ace7f46bSManish Rangankar 
658ace7f46bSManish Rangankar 	shost = iscsi_session_to_shost(iscsi_conn_to_session(cls_conn));
659ace7f46bSManish Rangankar 	qedi = iscsi_host_priv(shost);
660ace7f46bSManish Rangankar 
661ace7f46bSManish Rangankar 	qedi_conn_free_login_resources(qedi, qedi_conn);
662ace7f46bSManish Rangankar 	iscsi_conn_teardown(cls_conn);
663ace7f46bSManish Rangankar }
664ace7f46bSManish Rangankar 
qedi_ep_get_param(struct iscsi_endpoint * ep,enum iscsi_param param,char * buf)665ace7f46bSManish Rangankar static int qedi_ep_get_param(struct iscsi_endpoint *ep,
666ace7f46bSManish Rangankar 			     enum iscsi_param param, char *buf)
667ace7f46bSManish Rangankar {
668ace7f46bSManish Rangankar 	struct qedi_endpoint *qedi_ep = ep->dd_data;
669ace7f46bSManish Rangankar 	int len;
670ace7f46bSManish Rangankar 
671ace7f46bSManish Rangankar 	if (!qedi_ep)
672ace7f46bSManish Rangankar 		return -ENOTCONN;
673ace7f46bSManish Rangankar 
674ace7f46bSManish Rangankar 	switch (param) {
675ace7f46bSManish Rangankar 	case ISCSI_PARAM_CONN_PORT:
676ace7f46bSManish Rangankar 		len = sprintf(buf, "%hu\n", qedi_ep->dst_port);
677ace7f46bSManish Rangankar 		break;
678ace7f46bSManish Rangankar 	case ISCSI_PARAM_CONN_ADDRESS:
679ace7f46bSManish Rangankar 		if (qedi_ep->ip_type == TCP_IPV4)
680ace7f46bSManish Rangankar 			len = sprintf(buf, "%pI4\n", qedi_ep->dst_addr);
681ace7f46bSManish Rangankar 		else
682ace7f46bSManish Rangankar 			len = sprintf(buf, "%pI6\n", qedi_ep->dst_addr);
683ace7f46bSManish Rangankar 		break;
684ace7f46bSManish Rangankar 	default:
685ace7f46bSManish Rangankar 		return -ENOTCONN;
686ace7f46bSManish Rangankar 	}
687ace7f46bSManish Rangankar 
688ace7f46bSManish Rangankar 	return len;
689ace7f46bSManish Rangankar }
690ace7f46bSManish Rangankar 
qedi_host_get_param(struct Scsi_Host * shost,enum iscsi_host_param param,char * buf)691ace7f46bSManish Rangankar static int qedi_host_get_param(struct Scsi_Host *shost,
692ace7f46bSManish Rangankar 			       enum iscsi_host_param param, char *buf)
693ace7f46bSManish Rangankar {
694ace7f46bSManish Rangankar 	struct qedi_ctx *qedi;
695ace7f46bSManish Rangankar 	int len;
696ace7f46bSManish Rangankar 
697ace7f46bSManish Rangankar 	qedi = iscsi_host_priv(shost);
698ace7f46bSManish Rangankar 
699ace7f46bSManish Rangankar 	switch (param) {
700ace7f46bSManish Rangankar 	case ISCSI_HOST_PARAM_HWADDRESS:
701ace7f46bSManish Rangankar 		len = sysfs_format_mac(buf, qedi->mac, 6);
702ace7f46bSManish Rangankar 		break;
703ace7f46bSManish Rangankar 	case ISCSI_HOST_PARAM_NETDEV_NAME:
704ace7f46bSManish Rangankar 		len = sprintf(buf, "host%d\n", shost->host_no);
705ace7f46bSManish Rangankar 		break;
706ace7f46bSManish Rangankar 	case ISCSI_HOST_PARAM_IPADDRESS:
707ace7f46bSManish Rangankar 		if (qedi->ip_type == TCP_IPV4)
708ace7f46bSManish Rangankar 			len = sprintf(buf, "%pI4\n", qedi->src_ip);
709ace7f46bSManish Rangankar 		else
710ace7f46bSManish Rangankar 			len = sprintf(buf, "%pI6\n", qedi->src_ip);
711ace7f46bSManish Rangankar 		break;
712ace7f46bSManish Rangankar 	default:
713ace7f46bSManish Rangankar 		return iscsi_host_get_param(shost, param, buf);
714ace7f46bSManish Rangankar 	}
715ace7f46bSManish Rangankar 
716ace7f46bSManish Rangankar 	return len;
717ace7f46bSManish Rangankar }
718ace7f46bSManish Rangankar 
qedi_conn_get_stats(struct iscsi_cls_conn * cls_conn,struct iscsi_stats * stats)719ace7f46bSManish Rangankar static void qedi_conn_get_stats(struct iscsi_cls_conn *cls_conn,
720ace7f46bSManish Rangankar 				struct iscsi_stats *stats)
721ace7f46bSManish Rangankar {
722ace7f46bSManish Rangankar 	struct iscsi_conn *conn = cls_conn->dd_data;
723ace7f46bSManish Rangankar 	struct qed_iscsi_stats iscsi_stats;
724ace7f46bSManish Rangankar 	struct Scsi_Host *shost;
725ace7f46bSManish Rangankar 	struct qedi_ctx *qedi;
726ace7f46bSManish Rangankar 
727ace7f46bSManish Rangankar 	shost = iscsi_session_to_shost(iscsi_conn_to_session(cls_conn));
728ace7f46bSManish Rangankar 	qedi = iscsi_host_priv(shost);
729ace7f46bSManish Rangankar 	qedi_ops->get_stats(qedi->cdev, &iscsi_stats);
730ace7f46bSManish Rangankar 
731ace7f46bSManish Rangankar 	conn->txdata_octets = iscsi_stats.iscsi_tx_bytes_cnt;
732ace7f46bSManish Rangankar 	conn->rxdata_octets = iscsi_stats.iscsi_rx_bytes_cnt;
733ace7f46bSManish Rangankar 	conn->dataout_pdus_cnt = (uint32_t)iscsi_stats.iscsi_tx_data_pdu_cnt;
734ace7f46bSManish Rangankar 	conn->datain_pdus_cnt = (uint32_t)iscsi_stats.iscsi_rx_data_pdu_cnt;
735ace7f46bSManish Rangankar 	conn->r2t_pdus_cnt = (uint32_t)iscsi_stats.iscsi_rx_r2t_pdu_cnt;
736ace7f46bSManish Rangankar 
737ace7f46bSManish Rangankar 	stats->txdata_octets = conn->txdata_octets;
738ace7f46bSManish Rangankar 	stats->rxdata_octets = conn->rxdata_octets;
739ace7f46bSManish Rangankar 	stats->scsicmd_pdus = conn->scsicmd_pdus_cnt;
740ace7f46bSManish Rangankar 	stats->dataout_pdus = conn->dataout_pdus_cnt;
741ace7f46bSManish Rangankar 	stats->scsirsp_pdus = conn->scsirsp_pdus_cnt;
742ace7f46bSManish Rangankar 	stats->datain_pdus = conn->datain_pdus_cnt;
743ace7f46bSManish Rangankar 	stats->r2t_pdus = conn->r2t_pdus_cnt;
744ace7f46bSManish Rangankar 	stats->tmfcmd_pdus = conn->tmfcmd_pdus_cnt;
745ace7f46bSManish Rangankar 	stats->tmfrsp_pdus = conn->tmfrsp_pdus_cnt;
746ace7f46bSManish Rangankar 	stats->digest_err = 0;
747ace7f46bSManish Rangankar 	stats->timeout_err = 0;
748ace7f46bSManish Rangankar 	strcpy(stats->custom[0].desc, "eh_abort_cnt");
749ace7f46bSManish Rangankar 	stats->custom[0].value = conn->eh_abort_cnt;
750ace7f46bSManish Rangankar 	stats->custom_length = 1;
751ace7f46bSManish Rangankar }
752ace7f46bSManish Rangankar 
qedi_iscsi_prep_generic_pdu_bd(struct qedi_conn * qedi_conn)753ace7f46bSManish Rangankar static void qedi_iscsi_prep_generic_pdu_bd(struct qedi_conn *qedi_conn)
754ace7f46bSManish Rangankar {
755be086e7cSMintz, Yuval 	struct scsi_sge *bd_tbl;
756ace7f46bSManish Rangankar 
757be086e7cSMintz, Yuval 	bd_tbl = (struct scsi_sge *)qedi_conn->gen_pdu.req_bd_tbl;
758ace7f46bSManish Rangankar 
759ace7f46bSManish Rangankar 	bd_tbl->sge_addr.hi =
760ace7f46bSManish Rangankar 		(u32)((u64)qedi_conn->gen_pdu.req_dma_addr >> 32);
761ace7f46bSManish Rangankar 	bd_tbl->sge_addr.lo = (u32)qedi_conn->gen_pdu.req_dma_addr;
762ace7f46bSManish Rangankar 	bd_tbl->sge_len = qedi_conn->gen_pdu.req_wr_ptr -
763ace7f46bSManish Rangankar 				qedi_conn->gen_pdu.req_buf;
764be086e7cSMintz, Yuval 	bd_tbl = (struct scsi_sge  *)qedi_conn->gen_pdu.resp_bd_tbl;
765ace7f46bSManish Rangankar 	bd_tbl->sge_addr.hi =
766ace7f46bSManish Rangankar 			(u32)((u64)qedi_conn->gen_pdu.resp_dma_addr >> 32);
767ace7f46bSManish Rangankar 	bd_tbl->sge_addr.lo = (u32)qedi_conn->gen_pdu.resp_dma_addr;
768ace7f46bSManish Rangankar 	bd_tbl->sge_len = ISCSI_DEF_MAX_RECV_SEG_LEN;
769ace7f46bSManish Rangankar }
770ace7f46bSManish Rangankar 
qedi_iscsi_send_generic_request(struct iscsi_task * task)771ace7f46bSManish Rangankar static int qedi_iscsi_send_generic_request(struct iscsi_task *task)
772ace7f46bSManish Rangankar {
773ace7f46bSManish Rangankar 	struct qedi_cmd *cmd = task->dd_data;
774ace7f46bSManish Rangankar 	struct qedi_conn *qedi_conn = cmd->conn;
775ace7f46bSManish Rangankar 	char *buf;
776ace7f46bSManish Rangankar 	int data_len;
777ace7f46bSManish Rangankar 	int rc = 0;
778ace7f46bSManish Rangankar 
779ace7f46bSManish Rangankar 	qedi_iscsi_prep_generic_pdu_bd(qedi_conn);
780ace7f46bSManish Rangankar 	switch (task->hdr->opcode & ISCSI_OPCODE_MASK) {
781ace7f46bSManish Rangankar 	case ISCSI_OP_LOGIN:
782ace7f46bSManish Rangankar 		qedi_send_iscsi_login(qedi_conn, task);
783ace7f46bSManish Rangankar 		break;
784ace7f46bSManish Rangankar 	case ISCSI_OP_NOOP_OUT:
785ace7f46bSManish Rangankar 		data_len = qedi_conn->gen_pdu.req_buf_size;
786ace7f46bSManish Rangankar 		buf = qedi_conn->gen_pdu.req_buf;
787ace7f46bSManish Rangankar 		if (data_len)
788ace7f46bSManish Rangankar 			rc = qedi_send_iscsi_nopout(qedi_conn, task,
789ace7f46bSManish Rangankar 						    buf, data_len, 1);
790ace7f46bSManish Rangankar 		else
791ace7f46bSManish Rangankar 			rc = qedi_send_iscsi_nopout(qedi_conn, task,
792ace7f46bSManish Rangankar 						    NULL, 0, 1);
793ace7f46bSManish Rangankar 		break;
794ace7f46bSManish Rangankar 	case ISCSI_OP_LOGOUT:
795ace7f46bSManish Rangankar 		rc = qedi_send_iscsi_logout(qedi_conn, task);
796ace7f46bSManish Rangankar 		break;
797ace7f46bSManish Rangankar 	case ISCSI_OP_SCSI_TMFUNC:
798f7eea752SMike Christie 		rc = qedi_send_iscsi_tmf(qedi_conn, task);
799ace7f46bSManish Rangankar 		break;
800ace7f46bSManish Rangankar 	case ISCSI_OP_TEXT:
801ace7f46bSManish Rangankar 		rc = qedi_send_iscsi_text(qedi_conn, task);
802ace7f46bSManish Rangankar 		break;
803ace7f46bSManish Rangankar 	default:
804ace7f46bSManish Rangankar 		iscsi_conn_printk(KERN_ALERT, qedi_conn->cls_conn->dd_data,
805ace7f46bSManish Rangankar 				  "unsupported op 0x%x\n", task->hdr->opcode);
806ace7f46bSManish Rangankar 	}
807ace7f46bSManish Rangankar 
808ace7f46bSManish Rangankar 	return rc;
809ace7f46bSManish Rangankar }
810ace7f46bSManish Rangankar 
qedi_mtask_xmit(struct iscsi_conn * conn,struct iscsi_task * task)811ace7f46bSManish Rangankar static int qedi_mtask_xmit(struct iscsi_conn *conn, struct iscsi_task *task)
812ace7f46bSManish Rangankar {
813ace7f46bSManish Rangankar 	struct qedi_conn *qedi_conn = conn->dd_data;
814ace7f46bSManish Rangankar 	struct qedi_cmd *cmd = task->dd_data;
815ace7f46bSManish Rangankar 
816ace7f46bSManish Rangankar 	memset(qedi_conn->gen_pdu.req_buf, 0, ISCSI_DEF_MAX_RECV_SEG_LEN);
817ace7f46bSManish Rangankar 
818ace7f46bSManish Rangankar 	qedi_conn->gen_pdu.req_buf_size = task->data_count;
819ace7f46bSManish Rangankar 
820ace7f46bSManish Rangankar 	if (task->data_count) {
821ace7f46bSManish Rangankar 		memcpy(qedi_conn->gen_pdu.req_buf, task->data,
822ace7f46bSManish Rangankar 		       task->data_count);
823ace7f46bSManish Rangankar 		qedi_conn->gen_pdu.req_wr_ptr =
824ace7f46bSManish Rangankar 			qedi_conn->gen_pdu.req_buf + task->data_count;
825ace7f46bSManish Rangankar 	}
826ace7f46bSManish Rangankar 
827ace7f46bSManish Rangankar 	cmd->conn = conn->dd_data;
828ace7f46bSManish Rangankar 	return qedi_iscsi_send_generic_request(task);
829ace7f46bSManish Rangankar }
830ace7f46bSManish Rangankar 
qedi_task_xmit(struct iscsi_task * task)831ace7f46bSManish Rangankar static int qedi_task_xmit(struct iscsi_task *task)
832ace7f46bSManish Rangankar {
833ace7f46bSManish Rangankar 	struct iscsi_conn *conn = task->conn;
834ace7f46bSManish Rangankar 	struct qedi_conn *qedi_conn = conn->dd_data;
835ace7f46bSManish Rangankar 	struct qedi_cmd *cmd = task->dd_data;
836ace7f46bSManish Rangankar 	struct scsi_cmnd *sc = task->sc;
837ace7f46bSManish Rangankar 
8382ce00236SMike Christie 	/* Clear now so in cleanup_task we know it didn't make it */
8392ce00236SMike Christie 	cmd->scsi_cmd = NULL;
8402ce00236SMike Christie 	cmd->task_id = U16_MAX;
8412ce00236SMike Christie 
8424f93c4bfSManish Rangankar 	if (test_bit(QEDI_IN_SHUTDOWN, &qedi_conn->qedi->flags))
8434f93c4bfSManish Rangankar 		return -ENODEV;
8444f93c4bfSManish Rangankar 
8450c72191dSMike Christie 	if (test_bit(QEDI_BLOCK_IO, &qedi_conn->qedi->flags))
8460c72191dSMike Christie 		return -EACCES;
8470c72191dSMike Christie 
848ace7f46bSManish Rangankar 	cmd->state = 0;
849ace7f46bSManish Rangankar 	cmd->task = NULL;
850ace7f46bSManish Rangankar 	cmd->use_slowpath = false;
851ace7f46bSManish Rangankar 	cmd->conn = qedi_conn;
852ace7f46bSManish Rangankar 	cmd->task = task;
853ace7f46bSManish Rangankar 	cmd->io_cmd_in_list = false;
854ace7f46bSManish Rangankar 	INIT_LIST_HEAD(&cmd->io_cmd);
855ace7f46bSManish Rangankar 
856ace7f46bSManish Rangankar 	if (!sc)
857ace7f46bSManish Rangankar 		return qedi_mtask_xmit(conn, task);
858ace7f46bSManish Rangankar 
859ace7f46bSManish Rangankar 	cmd->scsi_cmd = sc;
860ace7f46bSManish Rangankar 	return qedi_iscsi_send_ioreq(task);
861ace7f46bSManish Rangankar }
862ace7f46bSManish Rangankar 
qedi_offload_work(struct work_struct * work)863857b0652SMike Christie static void qedi_offload_work(struct work_struct *work)
864857b0652SMike Christie {
865857b0652SMike Christie 	struct qedi_endpoint *qedi_ep =
866857b0652SMike Christie 		container_of(work, struct qedi_endpoint, offload_work);
867857b0652SMike Christie 	struct qedi_ctx *qedi;
868857b0652SMike Christie 	int wait_delay = 5 * HZ;
869857b0652SMike Christie 	int ret;
870857b0652SMike Christie 
871857b0652SMike Christie 	qedi = qedi_ep->qedi;
872857b0652SMike Christie 
873857b0652SMike Christie 	ret = qedi_iscsi_offload_conn(qedi_ep);
874857b0652SMike Christie 	if (ret) {
875857b0652SMike Christie 		QEDI_ERR(&qedi->dbg_ctx,
876857b0652SMike Christie 			 "offload error: iscsi_cid=%u, qedi_ep=%p, ret=%d\n",
877857b0652SMike Christie 			 qedi_ep->iscsi_cid, qedi_ep, ret);
878857b0652SMike Christie 		qedi_ep->state = EP_STATE_OFLDCONN_FAILED;
879857b0652SMike Christie 		return;
880857b0652SMike Christie 	}
881857b0652SMike Christie 
882857b0652SMike Christie 	ret = wait_event_interruptible_timeout(qedi_ep->tcp_ofld_wait,
883857b0652SMike Christie 					       (qedi_ep->state ==
884857b0652SMike Christie 					       EP_STATE_OFLDCONN_COMPL),
885857b0652SMike Christie 					       wait_delay);
886857b0652SMike Christie 	if (ret <= 0 || qedi_ep->state != EP_STATE_OFLDCONN_COMPL) {
887857b0652SMike Christie 		qedi_ep->state = EP_STATE_OFLDCONN_FAILED;
888857b0652SMike Christie 		QEDI_ERR(&qedi->dbg_ctx,
889857b0652SMike Christie 			 "Offload conn TIMEOUT iscsi_cid=%u, qedi_ep=%p\n",
890857b0652SMike Christie 			 qedi_ep->iscsi_cid, qedi_ep);
891857b0652SMike Christie 	}
892857b0652SMike Christie }
893857b0652SMike Christie 
894ace7f46bSManish Rangankar static struct iscsi_endpoint *
qedi_ep_connect(struct Scsi_Host * shost,struct sockaddr * dst_addr,int non_blocking)895ace7f46bSManish Rangankar qedi_ep_connect(struct Scsi_Host *shost, struct sockaddr *dst_addr,
896ace7f46bSManish Rangankar 		int non_blocking)
897ace7f46bSManish Rangankar {
898ace7f46bSManish Rangankar 	struct qedi_ctx *qedi;
899ace7f46bSManish Rangankar 	struct iscsi_endpoint *ep;
900ace7f46bSManish Rangankar 	struct qedi_endpoint *qedi_ep;
901ace7f46bSManish Rangankar 	struct sockaddr_in *addr;
902ace7f46bSManish Rangankar 	struct sockaddr_in6 *addr6;
903ace7f46bSManish Rangankar 	struct iscsi_path path_req;
904ace7f46bSManish Rangankar 	u32 msg_type = ISCSI_KEVENT_IF_DOWN;
905ace7f46bSManish Rangankar 	u32 iscsi_cid = QEDI_CID_RESERVED;
906ace7f46bSManish Rangankar 	u16 len = 0;
907ace7f46bSManish Rangankar 	char *buf = NULL;
9082c675218SDan Carpenter 	int ret, tmp;
909ace7f46bSManish Rangankar 
910ace7f46bSManish Rangankar 	if (!shost) {
911ace7f46bSManish Rangankar 		ret = -ENXIO;
912ace7f46bSManish Rangankar 		QEDI_ERR(NULL, "shost is NULL\n");
913ace7f46bSManish Rangankar 		return ERR_PTR(ret);
914ace7f46bSManish Rangankar 	}
915ace7f46bSManish Rangankar 
916bd571195SArnd Bergmann 	if (qedi_do_not_recover) {
917ace7f46bSManish Rangankar 		ret = -ENOMEM;
918ace7f46bSManish Rangankar 		return ERR_PTR(ret);
919ace7f46bSManish Rangankar 	}
920ace7f46bSManish Rangankar 
921ace7f46bSManish Rangankar 	qedi = iscsi_host_priv(shost);
922ace7f46bSManish Rangankar 
923ace7f46bSManish Rangankar 	if (test_bit(QEDI_IN_OFFLINE, &qedi->flags) ||
924ace7f46bSManish Rangankar 	    test_bit(QEDI_IN_RECOVERY, &qedi->flags)) {
925ace7f46bSManish Rangankar 		ret = -ENOMEM;
926ace7f46bSManish Rangankar 		return ERR_PTR(ret);
927ace7f46bSManish Rangankar 	}
928ace7f46bSManish Rangankar 
9292e612fabSManish Rangankar 	if (atomic_read(&qedi->link_state) != QEDI_LINK_UP) {
9302e612fabSManish Rangankar 		QEDI_WARN(&qedi->dbg_ctx, "qedi link down\n");
9312e612fabSManish Rangankar 		return ERR_PTR(-ENXIO);
9322e612fabSManish Rangankar 	}
9332e612fabSManish Rangankar 
934ace7f46bSManish Rangankar 	ep = iscsi_create_endpoint(sizeof(struct qedi_endpoint));
935ace7f46bSManish Rangankar 	if (!ep) {
936ace7f46bSManish Rangankar 		QEDI_ERR(&qedi->dbg_ctx, "endpoint create fail\n");
937ace7f46bSManish Rangankar 		ret = -ENOMEM;
938ace7f46bSManish Rangankar 		return ERR_PTR(ret);
939ace7f46bSManish Rangankar 	}
940ace7f46bSManish Rangankar 	qedi_ep = ep->dd_data;
941ace7f46bSManish Rangankar 	memset(qedi_ep, 0, sizeof(struct qedi_endpoint));
942857b0652SMike Christie 	INIT_WORK(&qedi_ep->offload_work, qedi_offload_work);
943ace7f46bSManish Rangankar 	qedi_ep->state = EP_STATE_IDLE;
944ace7f46bSManish Rangankar 	qedi_ep->iscsi_cid = (u32)-1;
945ace7f46bSManish Rangankar 	qedi_ep->qedi = qedi;
946ace7f46bSManish Rangankar 
947ace7f46bSManish Rangankar 	if (dst_addr->sa_family == AF_INET) {
948ace7f46bSManish Rangankar 		addr = (struct sockaddr_in *)dst_addr;
949ace7f46bSManish Rangankar 		memcpy(qedi_ep->dst_addr, &addr->sin_addr.s_addr,
950ace7f46bSManish Rangankar 		       sizeof(struct in_addr));
951ace7f46bSManish Rangankar 		qedi_ep->dst_port = ntohs(addr->sin_port);
952ace7f46bSManish Rangankar 		qedi_ep->ip_type = TCP_IPV4;
953ace7f46bSManish Rangankar 		QEDI_INFO(&qedi->dbg_ctx, QEDI_LOG_CONN,
954ace7f46bSManish Rangankar 			  "dst_addr=%pI4, dst_port=%u\n",
955ace7f46bSManish Rangankar 			  qedi_ep->dst_addr, qedi_ep->dst_port);
956ace7f46bSManish Rangankar 	} else if (dst_addr->sa_family == AF_INET6) {
957ace7f46bSManish Rangankar 		addr6 = (struct sockaddr_in6 *)dst_addr;
958ace7f46bSManish Rangankar 		memcpy(qedi_ep->dst_addr, &addr6->sin6_addr,
959ace7f46bSManish Rangankar 		       sizeof(struct in6_addr));
960ace7f46bSManish Rangankar 		qedi_ep->dst_port = ntohs(addr6->sin6_port);
961ace7f46bSManish Rangankar 		qedi_ep->ip_type = TCP_IPV6;
962ace7f46bSManish Rangankar 		QEDI_INFO(&qedi->dbg_ctx, QEDI_LOG_CONN,
963ace7f46bSManish Rangankar 			  "dst_addr=%pI6, dst_port=%u\n",
964ace7f46bSManish Rangankar 			  qedi_ep->dst_addr, qedi_ep->dst_port);
965ace7f46bSManish Rangankar 	} else {
966ace7f46bSManish Rangankar 		QEDI_ERR(&qedi->dbg_ctx, "Invalid endpoint\n");
967ace7f46bSManish Rangankar 	}
968ace7f46bSManish Rangankar 
969ace7f46bSManish Rangankar 	ret = qedi_alloc_sq(qedi, qedi_ep);
970ace7f46bSManish Rangankar 	if (ret)
971ace7f46bSManish Rangankar 		goto ep_conn_exit;
972ace7f46bSManish Rangankar 
973ace7f46bSManish Rangankar 	ret = qedi_ops->acquire_conn(qedi->cdev, &qedi_ep->handle,
974ace7f46bSManish Rangankar 				     &qedi_ep->fw_cid, &qedi_ep->p_doorbell);
975ace7f46bSManish Rangankar 
976ace7f46bSManish Rangankar 	if (ret) {
977ace7f46bSManish Rangankar 		QEDI_ERR(&qedi->dbg_ctx, "Could not acquire connection\n");
978ace7f46bSManish Rangankar 		ret = -ENXIO;
979ace7f46bSManish Rangankar 		goto ep_free_sq;
980ace7f46bSManish Rangankar 	}
981ace7f46bSManish Rangankar 
982ace7f46bSManish Rangankar 	iscsi_cid = qedi_ep->handle;
983ace7f46bSManish Rangankar 	qedi_ep->iscsi_cid = iscsi_cid;
984ace7f46bSManish Rangankar 
985ace7f46bSManish Rangankar 	init_waitqueue_head(&qedi_ep->ofld_wait);
986ace7f46bSManish Rangankar 	init_waitqueue_head(&qedi_ep->tcp_ofld_wait);
987ace7f46bSManish Rangankar 	qedi_ep->state = EP_STATE_OFLDCONN_START;
988ace7f46bSManish Rangankar 	qedi->ep_tbl[iscsi_cid] = qedi_ep;
989ace7f46bSManish Rangankar 
990ace7f46bSManish Rangankar 	buf = (char *)&path_req;
991ace7f46bSManish Rangankar 	len = sizeof(path_req);
992ace7f46bSManish Rangankar 	memset(&path_req, 0, len);
993ace7f46bSManish Rangankar 
994ace7f46bSManish Rangankar 	msg_type = ISCSI_KEVENT_PATH_REQ;
995ace7f46bSManish Rangankar 	path_req.handle = (u64)qedi_ep->iscsi_cid;
996ace7f46bSManish Rangankar 	path_req.pmtu = qedi->ll2_mtu;
997ace7f46bSManish Rangankar 	qedi_ep->pmtu = qedi->ll2_mtu;
998ace7f46bSManish Rangankar 	if (qedi_ep->ip_type == TCP_IPV4) {
999ace7f46bSManish Rangankar 		memcpy(&path_req.dst.v4_addr, &qedi_ep->dst_addr,
1000ace7f46bSManish Rangankar 		       sizeof(struct in_addr));
1001ace7f46bSManish Rangankar 		path_req.ip_addr_len = 4;
1002ace7f46bSManish Rangankar 	} else {
1003ace7f46bSManish Rangankar 		memcpy(&path_req.dst.v6_addr, &qedi_ep->dst_addr,
1004ace7f46bSManish Rangankar 		       sizeof(struct in6_addr));
1005ace7f46bSManish Rangankar 		path_req.ip_addr_len = 16;
1006ace7f46bSManish Rangankar 	}
1007ace7f46bSManish Rangankar 
1008ace7f46bSManish Rangankar 	ret = iscsi_offload_mesg(shost, &qedi_iscsi_transport, msg_type, buf,
1009ace7f46bSManish Rangankar 				 len);
1010ace7f46bSManish Rangankar 	if (ret) {
1011ace7f46bSManish Rangankar 		QEDI_ERR(&qedi->dbg_ctx,
1012ace7f46bSManish Rangankar 			 "iscsi_offload_mesg() failed for cid=0x%x ret=%d\n",
1013ace7f46bSManish Rangankar 			 iscsi_cid, ret);
1014ace7f46bSManish Rangankar 		goto ep_rel_conn;
1015ace7f46bSManish Rangankar 	}
1016ace7f46bSManish Rangankar 
1017ace7f46bSManish Rangankar 	atomic_inc(&qedi->num_offloads);
1018ace7f46bSManish Rangankar 	return ep;
1019ace7f46bSManish Rangankar 
1020ace7f46bSManish Rangankar ep_rel_conn:
1021ace7f46bSManish Rangankar 	qedi->ep_tbl[iscsi_cid] = NULL;
10222c675218SDan Carpenter 	tmp = qedi_ops->release_conn(qedi->cdev, qedi_ep->handle);
10232c675218SDan Carpenter 	if (tmp)
1024ace7f46bSManish Rangankar 		QEDI_WARN(&qedi->dbg_ctx, "release_conn returned %d\n",
10252c675218SDan Carpenter 			  tmp);
1026ace7f46bSManish Rangankar ep_free_sq:
1027ace7f46bSManish Rangankar 	qedi_free_sq(qedi, qedi_ep);
1028ace7f46bSManish Rangankar ep_conn_exit:
1029ace7f46bSManish Rangankar 	iscsi_destroy_endpoint(ep);
1030ace7f46bSManish Rangankar 	return ERR_PTR(ret);
1031ace7f46bSManish Rangankar }
1032ace7f46bSManish Rangankar 
qedi_ep_poll(struct iscsi_endpoint * ep,int timeout_ms)1033ace7f46bSManish Rangankar static int qedi_ep_poll(struct iscsi_endpoint *ep, int timeout_ms)
1034ace7f46bSManish Rangankar {
1035ace7f46bSManish Rangankar 	struct qedi_endpoint *qedi_ep;
1036ace7f46bSManish Rangankar 	int ret = 0;
1037ace7f46bSManish Rangankar 
1038bd571195SArnd Bergmann 	if (qedi_do_not_recover)
1039ace7f46bSManish Rangankar 		return 1;
1040ace7f46bSManish Rangankar 
1041ace7f46bSManish Rangankar 	qedi_ep = ep->dd_data;
1042ace7f46bSManish Rangankar 	if (qedi_ep->state == EP_STATE_IDLE ||
104334a2ce88SManish Rangankar 	    qedi_ep->state == EP_STATE_OFLDCONN_NONE ||
1044ace7f46bSManish Rangankar 	    qedi_ep->state == EP_STATE_OFLDCONN_FAILED)
1045ace7f46bSManish Rangankar 		return -1;
1046ace7f46bSManish Rangankar 
1047ace7f46bSManish Rangankar 	if (qedi_ep->state == EP_STATE_OFLDCONN_COMPL)
1048ace7f46bSManish Rangankar 		ret = 1;
1049ace7f46bSManish Rangankar 
1050ace7f46bSManish Rangankar 	ret = wait_event_interruptible_timeout(qedi_ep->ofld_wait,
1051ace7f46bSManish Rangankar 					       QEDI_OFLD_WAIT_STATE(qedi_ep),
1052ace7f46bSManish Rangankar 					       msecs_to_jiffies(timeout_ms));
1053ace7f46bSManish Rangankar 
1054ace7f46bSManish Rangankar 	if (qedi_ep->state == EP_STATE_OFLDCONN_FAILED)
1055ace7f46bSManish Rangankar 		ret = -1;
1056ace7f46bSManish Rangankar 
1057ace7f46bSManish Rangankar 	if (ret > 0)
1058ace7f46bSManish Rangankar 		return 1;
1059ace7f46bSManish Rangankar 	else if (!ret)
1060ace7f46bSManish Rangankar 		return 0;
1061ace7f46bSManish Rangankar 	else
1062ace7f46bSManish Rangankar 		return ret;
1063ace7f46bSManish Rangankar }
1064ace7f46bSManish Rangankar 
qedi_cleanup_active_cmd_list(struct qedi_conn * qedi_conn)1065ace7f46bSManish Rangankar static void qedi_cleanup_active_cmd_list(struct qedi_conn *qedi_conn)
1066ace7f46bSManish Rangankar {
1067ace7f46bSManish Rangankar 	struct qedi_cmd *cmd, *cmd_tmp;
1068ace7f46bSManish Rangankar 
1069c0650e28SNilesh Javali 	spin_lock(&qedi_conn->list_lock);
1070ace7f46bSManish Rangankar 	list_for_each_entry_safe(cmd, cmd_tmp, &qedi_conn->active_cmd_list,
1071ace7f46bSManish Rangankar 				 io_cmd) {
1072ace7f46bSManish Rangankar 		list_del_init(&cmd->io_cmd);
1073ace7f46bSManish Rangankar 		qedi_conn->active_cmd_count--;
1074ace7f46bSManish Rangankar 	}
1075c0650e28SNilesh Javali 	spin_unlock(&qedi_conn->list_lock);
1076ace7f46bSManish Rangankar }
1077ace7f46bSManish Rangankar 
qedi_ep_disconnect(struct iscsi_endpoint * ep)1078ace7f46bSManish Rangankar static void qedi_ep_disconnect(struct iscsi_endpoint *ep)
1079ace7f46bSManish Rangankar {
1080ace7f46bSManish Rangankar 	struct qedi_endpoint *qedi_ep;
1081ace7f46bSManish Rangankar 	struct qedi_conn *qedi_conn = NULL;
1082ace7f46bSManish Rangankar 	struct qedi_ctx *qedi;
1083ace7f46bSManish Rangankar 	int ret = 0;
10843252688fSManish Rangankar 	int wait_delay;
1085ace7f46bSManish Rangankar 	int abrt_conn = 0;
1086ace7f46bSManish Rangankar 
10873252688fSManish Rangankar 	wait_delay = 60 * HZ + DEF_MAX_RT_TIME;
1088ace7f46bSManish Rangankar 	qedi_ep = ep->dd_data;
1089ace7f46bSManish Rangankar 	qedi = qedi_ep->qedi;
1090ace7f46bSManish Rangankar 
1091857b0652SMike Christie 	flush_work(&qedi_ep->offload_work);
1092857b0652SMike Christie 
1093f848bfd8SManish Rangankar 	if (qedi_ep->state == EP_STATE_OFLDCONN_START)
1094f848bfd8SManish Rangankar 		goto ep_exit_recover;
1095f848bfd8SManish Rangankar 
1096ace7f46bSManish Rangankar 	if (qedi_ep->conn) {
1097ace7f46bSManish Rangankar 		qedi_conn = qedi_ep->conn;
1098ace7f46bSManish Rangankar 		abrt_conn = qedi_conn->abrt_conn;
1099ace7f46bSManish Rangankar 
1100b40f3894SMike Christie 		QEDI_INFO(&qedi->dbg_ctx, QEDI_LOG_INFO,
1101b40f3894SMike Christie 			  "cid=0x%x qedi_ep=%p waiting for %d tmfs\n",
1102b40f3894SMike Christie 			  qedi_ep->iscsi_cid, qedi_ep,
1103b40f3894SMike Christie 			  qedi_conn->fw_cleanup_works);
1104b40f3894SMike Christie 
1105b40f3894SMike Christie 		spin_lock(&qedi_conn->tmf_work_lock);
1106b40f3894SMike Christie 		qedi_conn->ep_disconnect_starting = true;
1107b40f3894SMike Christie 		while (qedi_conn->fw_cleanup_works > 0) {
1108b40f3894SMike Christie 			spin_unlock(&qedi_conn->tmf_work_lock);
1109ace7f46bSManish Rangankar 			msleep(1000);
1110b40f3894SMike Christie 			spin_lock(&qedi_conn->tmf_work_lock);
1111ace7f46bSManish Rangankar 		}
1112b40f3894SMike Christie 		spin_unlock(&qedi_conn->tmf_work_lock);
1113ace7f46bSManish Rangankar 
1114ace7f46bSManish Rangankar 		if (test_bit(QEDI_IN_RECOVERY, &qedi->flags)) {
1115bd571195SArnd Bergmann 			if (qedi_do_not_recover) {
1116ace7f46bSManish Rangankar 				QEDI_INFO(&qedi->dbg_ctx, QEDI_LOG_INFO,
1117ace7f46bSManish Rangankar 					  "Do not recover cid=0x%x\n",
1118ace7f46bSManish Rangankar 					  qedi_ep->iscsi_cid);
1119ace7f46bSManish Rangankar 				goto ep_exit_recover;
1120ace7f46bSManish Rangankar 			}
1121ace7f46bSManish Rangankar 			QEDI_INFO(&qedi->dbg_ctx, QEDI_LOG_INFO,
1122ace7f46bSManish Rangankar 				  "Reset recovery cid=0x%x, qedi_ep=%p, state=0x%x\n",
1123ace7f46bSManish Rangankar 				  qedi_ep->iscsi_cid, qedi_ep, qedi_ep->state);
1124ace7f46bSManish Rangankar 			qedi_cleanup_active_cmd_list(qedi_conn);
1125ace7f46bSManish Rangankar 			goto ep_release_conn;
1126ace7f46bSManish Rangankar 		}
1127ace7f46bSManish Rangankar 	}
1128ace7f46bSManish Rangankar 
1129bd571195SArnd Bergmann 	if (qedi_do_not_recover)
1130ace7f46bSManish Rangankar 		goto ep_exit_recover;
1131ace7f46bSManish Rangankar 
1132ace7f46bSManish Rangankar 	switch (qedi_ep->state) {
1133ace7f46bSManish Rangankar 	case EP_STATE_OFLDCONN_START:
113434a2ce88SManish Rangankar 	case EP_STATE_OFLDCONN_NONE:
1135ace7f46bSManish Rangankar 		goto ep_release_conn;
1136ace7f46bSManish Rangankar 	case EP_STATE_OFLDCONN_FAILED:
1137ace7f46bSManish Rangankar 			break;
1138ace7f46bSManish Rangankar 	case EP_STATE_OFLDCONN_COMPL:
1139ace7f46bSManish Rangankar 		if (unlikely(!qedi_conn))
1140ace7f46bSManish Rangankar 			break;
1141ace7f46bSManish Rangankar 
1142ace7f46bSManish Rangankar 		QEDI_INFO(&qedi->dbg_ctx, QEDI_LOG_INFO,
1143ace7f46bSManish Rangankar 			  "Active cmd count=%d, abrt_conn=%d, ep state=0x%x, cid=0x%x, qedi_conn=%p\n",
1144ace7f46bSManish Rangankar 			  qedi_conn->active_cmd_count, abrt_conn,
1145ace7f46bSManish Rangankar 			  qedi_ep->state,
1146ace7f46bSManish Rangankar 			  qedi_ep->iscsi_cid,
1147ace7f46bSManish Rangankar 			  qedi_ep->conn
1148ace7f46bSManish Rangankar 			  );
1149ace7f46bSManish Rangankar 
1150ace7f46bSManish Rangankar 		if (!qedi_conn->active_cmd_count)
1151ace7f46bSManish Rangankar 			abrt_conn = 0;
1152ace7f46bSManish Rangankar 		else
1153ace7f46bSManish Rangankar 			abrt_conn = 1;
1154ace7f46bSManish Rangankar 
1155ace7f46bSManish Rangankar 		if (abrt_conn)
1156ace7f46bSManish Rangankar 			qedi_clearsq(qedi, qedi_conn, NULL);
1157ace7f46bSManish Rangankar 		break;
1158ace7f46bSManish Rangankar 	default:
1159ace7f46bSManish Rangankar 		break;
1160ace7f46bSManish Rangankar 	}
1161ace7f46bSManish Rangankar 
1162b9b97e69SNilesh Javali 	if (!abrt_conn)
1163b9b97e69SNilesh Javali 		wait_delay += qedi->pf_params.iscsi_pf_params.two_msl_timer;
1164b9b97e69SNilesh Javali 
1165ace7f46bSManish Rangankar 	qedi_ep->state = EP_STATE_DISCONN_START;
11665c35e464SManish Rangankar 
1167f4ba4e55SManish Rangankar 	if (test_bit(QEDI_IN_SHUTDOWN, &qedi->flags) ||
1168f4ba4e55SManish Rangankar 	    test_bit(QEDI_IN_RECOVERY, &qedi->flags))
11695c35e464SManish Rangankar 		goto ep_release_conn;
11705c35e464SManish Rangankar 
11719757f8afSShai Malin 	/* Delete doorbell from doorbell recovery mechanism */
11729757f8afSShai Malin 	ret = qedi_ops->common->db_recovery_del(qedi->cdev,
11739757f8afSShai Malin 					       qedi_ep->p_doorbell,
11749757f8afSShai Malin 					       &qedi_ep->db_data);
11759757f8afSShai Malin 
1176ace7f46bSManish Rangankar 	ret = qedi_ops->destroy_conn(qedi->cdev, qedi_ep->handle, abrt_conn);
1177ace7f46bSManish Rangankar 	if (ret) {
1178ace7f46bSManish Rangankar 		QEDI_WARN(&qedi->dbg_ctx,
1179ace7f46bSManish Rangankar 			  "destroy_conn failed returned %d\n", ret);
1180ace7f46bSManish Rangankar 	} else {
1181ace7f46bSManish Rangankar 		ret = wait_event_interruptible_timeout(
1182ace7f46bSManish Rangankar 					qedi_ep->tcp_ofld_wait,
1183ace7f46bSManish Rangankar 					(qedi_ep->state !=
1184ace7f46bSManish Rangankar 					 EP_STATE_DISCONN_START),
1185ace7f46bSManish Rangankar 					wait_delay);
1186ace7f46bSManish Rangankar 		if ((ret <= 0) || (qedi_ep->state == EP_STATE_DISCONN_START)) {
1187ace7f46bSManish Rangankar 			QEDI_WARN(&qedi->dbg_ctx,
1188ace7f46bSManish Rangankar 				  "Destroy conn timedout or interrupted, ret=%d, delay=%d, cid=0x%x\n",
1189ace7f46bSManish Rangankar 				  ret, wait_delay, qedi_ep->iscsi_cid);
1190ace7f46bSManish Rangankar 		}
1191ace7f46bSManish Rangankar 	}
1192ace7f46bSManish Rangankar 
1193ace7f46bSManish Rangankar ep_release_conn:
1194ace7f46bSManish Rangankar 	ret = qedi_ops->release_conn(qedi->cdev, qedi_ep->handle);
1195ace7f46bSManish Rangankar 	if (ret)
1196ace7f46bSManish Rangankar 		QEDI_WARN(&qedi->dbg_ctx,
1197ace7f46bSManish Rangankar 			  "release_conn returned %d, cid=0x%x\n",
1198ace7f46bSManish Rangankar 			  ret, qedi_ep->iscsi_cid);
1199ace7f46bSManish Rangankar ep_exit_recover:
1200ace7f46bSManish Rangankar 	qedi_ep->state = EP_STATE_IDLE;
1201ace7f46bSManish Rangankar 	qedi->ep_tbl[qedi_ep->iscsi_cid] = NULL;
1202ace7f46bSManish Rangankar 	qedi->cid_que.conn_cid_tbl[qedi_ep->iscsi_cid] = NULL;
1203ace7f46bSManish Rangankar 	qedi_free_id(&qedi->lcl_port_tbl, qedi_ep->src_port);
1204ace7f46bSManish Rangankar 	qedi_free_sq(qedi, qedi_ep);
1205ace7f46bSManish Rangankar 
1206ace7f46bSManish Rangankar 	if (qedi_conn)
1207ace7f46bSManish Rangankar 		qedi_conn->ep = NULL;
1208ace7f46bSManish Rangankar 
1209ace7f46bSManish Rangankar 	qedi_ep->conn = NULL;
1210ace7f46bSManish Rangankar 	qedi_ep->qedi = NULL;
1211ace7f46bSManish Rangankar 	atomic_dec(&qedi->num_offloads);
1212ace7f46bSManish Rangankar 
1213ace7f46bSManish Rangankar 	iscsi_destroy_endpoint(ep);
1214ace7f46bSManish Rangankar }
1215ace7f46bSManish Rangankar 
qedi_data_avail(struct qedi_ctx * qedi,u16 vlanid)1216ace7f46bSManish Rangankar static int qedi_data_avail(struct qedi_ctx *qedi, u16 vlanid)
1217ace7f46bSManish Rangankar {
1218ace7f46bSManish Rangankar 	struct qed_dev *cdev = qedi->cdev;
1219ace7f46bSManish Rangankar 	struct qedi_uio_dev *udev;
1220ace7f46bSManish Rangankar 	struct qedi_uio_ctrl *uctrl;
1221ace7f46bSManish Rangankar 	struct sk_buff *skb;
1222ace7f46bSManish Rangankar 	u32 len;
1223ace7f46bSManish Rangankar 	int rc = 0;
1224ace7f46bSManish Rangankar 
1225ace7f46bSManish Rangankar 	udev = qedi->udev;
1226ace7f46bSManish Rangankar 	if (!udev) {
1227ace7f46bSManish Rangankar 		QEDI_ERR(&qedi->dbg_ctx, "udev is NULL.\n");
1228ace7f46bSManish Rangankar 		return -EINVAL;
1229ace7f46bSManish Rangankar 	}
1230ace7f46bSManish Rangankar 
1231ace7f46bSManish Rangankar 	uctrl = (struct qedi_uio_ctrl *)udev->uctrl;
1232ace7f46bSManish Rangankar 	if (!uctrl) {
1233ace7f46bSManish Rangankar 		QEDI_ERR(&qedi->dbg_ctx, "uctlr is NULL.\n");
1234ace7f46bSManish Rangankar 		return -EINVAL;
1235ace7f46bSManish Rangankar 	}
1236ace7f46bSManish Rangankar 
1237ace7f46bSManish Rangankar 	len = uctrl->host_tx_pkt_len;
1238ace7f46bSManish Rangankar 	if (!len) {
1239ace7f46bSManish Rangankar 		QEDI_ERR(&qedi->dbg_ctx, "Invalid len %u\n", len);
1240ace7f46bSManish Rangankar 		return -EINVAL;
1241ace7f46bSManish Rangankar 	}
1242ace7f46bSManish Rangankar 
1243ace7f46bSManish Rangankar 	skb = alloc_skb(len, GFP_ATOMIC);
1244ace7f46bSManish Rangankar 	if (!skb) {
1245ace7f46bSManish Rangankar 		QEDI_ERR(&qedi->dbg_ctx, "alloc_skb failed\n");
1246ace7f46bSManish Rangankar 		return -EINVAL;
1247ace7f46bSManish Rangankar 	}
1248ace7f46bSManish Rangankar 
1249ace7f46bSManish Rangankar 	skb_put(skb, len);
1250ace7f46bSManish Rangankar 	memcpy(skb->data, udev->tx_pkt, len);
1251ace7f46bSManish Rangankar 	skb->ip_summed = CHECKSUM_NONE;
1252ace7f46bSManish Rangankar 
1253ace7f46bSManish Rangankar 	if (vlanid)
1254ace7f46bSManish Rangankar 		__vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), vlanid);
1255ace7f46bSManish Rangankar 
1256cac6f691SSudarsana Reddy Kalluru 	rc = qedi_ops->ll2->start_xmit(cdev, skb, 0);
1257ace7f46bSManish Rangankar 	if (rc) {
1258ace7f46bSManish Rangankar 		QEDI_ERR(&qedi->dbg_ctx, "ll2 start_xmit returned %d\n",
1259ace7f46bSManish Rangankar 			 rc);
1260ace7f46bSManish Rangankar 		kfree_skb(skb);
1261ace7f46bSManish Rangankar 	}
1262ace7f46bSManish Rangankar 
1263ace7f46bSManish Rangankar 	uctrl->host_tx_pkt_len = 0;
1264ace7f46bSManish Rangankar 	uctrl->hw_tx_cons++;
1265ace7f46bSManish Rangankar 
1266ace7f46bSManish Rangankar 	return rc;
1267ace7f46bSManish Rangankar }
1268ace7f46bSManish Rangankar 
qedi_set_path(struct Scsi_Host * shost,struct iscsi_path * path_data)1269ace7f46bSManish Rangankar static int qedi_set_path(struct Scsi_Host *shost, struct iscsi_path *path_data)
1270ace7f46bSManish Rangankar {
1271ace7f46bSManish Rangankar 	struct qedi_ctx *qedi;
1272ace7f46bSManish Rangankar 	struct qedi_endpoint *qedi_ep;
1273ace7f46bSManish Rangankar 	int ret = 0;
1274ace7f46bSManish Rangankar 	u32 iscsi_cid;
1275ace7f46bSManish Rangankar 	u16 port_id = 0;
1276ace7f46bSManish Rangankar 
1277ace7f46bSManish Rangankar 	if (!shost) {
1278ace7f46bSManish Rangankar 		ret = -ENXIO;
1279ace7f46bSManish Rangankar 		QEDI_ERR(NULL, "shost is NULL\n");
1280ace7f46bSManish Rangankar 		return ret;
1281ace7f46bSManish Rangankar 	}
1282ace7f46bSManish Rangankar 
1283ace7f46bSManish Rangankar 	if (strcmp(shost->hostt->proc_name, "qedi")) {
1284ace7f46bSManish Rangankar 		ret = -ENXIO;
1285ace7f46bSManish Rangankar 		QEDI_ERR(NULL, "shost %s is invalid\n",
1286ace7f46bSManish Rangankar 			 shost->hostt->proc_name);
1287ace7f46bSManish Rangankar 		return ret;
1288ace7f46bSManish Rangankar 	}
1289ace7f46bSManish Rangankar 
1290ace7f46bSManish Rangankar 	qedi = iscsi_host_priv(shost);
1291ace7f46bSManish Rangankar 	if (path_data->handle == QEDI_PATH_HANDLE) {
1292ace7f46bSManish Rangankar 		ret = qedi_data_avail(qedi, path_data->vlan_id);
1293ace7f46bSManish Rangankar 		goto set_path_exit;
1294ace7f46bSManish Rangankar 	}
1295ace7f46bSManish Rangankar 
1296ace7f46bSManish Rangankar 	iscsi_cid = (u32)path_data->handle;
12974a4c0cfbSDan Carpenter 	if (iscsi_cid >= qedi->max_active_conns) {
12984a4c0cfbSDan Carpenter 		ret = -EINVAL;
12994a4c0cfbSDan Carpenter 		goto set_path_exit;
13004a4c0cfbSDan Carpenter 	}
1301ace7f46bSManish Rangankar 	qedi_ep = qedi->ep_tbl[iscsi_cid];
13020ea9314fSmanish.rangankar@cavium.com 	QEDI_INFO(&qedi->dbg_ctx, QEDI_LOG_INFO,
1303ace7f46bSManish Rangankar 		  "iscsi_cid=0x%x, qedi_ep=%p\n", iscsi_cid, qedi_ep);
13040ea9314fSmanish.rangankar@cavium.com 	if (!qedi_ep) {
13050ea9314fSmanish.rangankar@cavium.com 		ret = -EINVAL;
13060ea9314fSmanish.rangankar@cavium.com 		goto set_path_exit;
13070ea9314fSmanish.rangankar@cavium.com 	}
1308ace7f46bSManish Rangankar 
1309ace7f46bSManish Rangankar 	if (!is_valid_ether_addr(&path_data->mac_addr[0])) {
1310ace7f46bSManish Rangankar 		QEDI_NOTICE(&qedi->dbg_ctx, "dst mac NOT VALID\n");
131134a2ce88SManish Rangankar 		qedi_ep->state = EP_STATE_OFLDCONN_NONE;
1312ace7f46bSManish Rangankar 		ret = -EIO;
1313ace7f46bSManish Rangankar 		goto set_path_exit;
1314ace7f46bSManish Rangankar 	}
1315ace7f46bSManish Rangankar 
1316ace7f46bSManish Rangankar 	ether_addr_copy(&qedi_ep->src_mac[0], &qedi->mac[0]);
1317ace7f46bSManish Rangankar 	ether_addr_copy(&qedi_ep->dst_mac[0], &path_data->mac_addr[0]);
1318ace7f46bSManish Rangankar 
1319ace7f46bSManish Rangankar 	qedi_ep->vlan_id = path_data->vlan_id;
1320ace7f46bSManish Rangankar 	if (path_data->pmtu < DEF_PATH_MTU) {
1321ace7f46bSManish Rangankar 		qedi_ep->pmtu = qedi->ll2_mtu;
1322ace7f46bSManish Rangankar 		QEDI_INFO(&qedi->dbg_ctx, QEDI_LOG_INFO,
1323ace7f46bSManish Rangankar 			  "MTU cannot be %u, using default MTU %u\n",
1324ace7f46bSManish Rangankar 			   path_data->pmtu, qedi_ep->pmtu);
1325ace7f46bSManish Rangankar 	}
1326ace7f46bSManish Rangankar 
1327ace7f46bSManish Rangankar 	if (path_data->pmtu != qedi->ll2_mtu) {
1328ace7f46bSManish Rangankar 		if (path_data->pmtu > JUMBO_MTU) {
1329ace7f46bSManish Rangankar 			ret = -EINVAL;
1330ace7f46bSManish Rangankar 			QEDI_ERR(NULL, "Invalid MTU %u\n", path_data->pmtu);
1331ace7f46bSManish Rangankar 			goto set_path_exit;
1332ace7f46bSManish Rangankar 		}
1333ace7f46bSManish Rangankar 
1334ace7f46bSManish Rangankar 		qedi_reset_host_mtu(qedi, path_data->pmtu);
1335ace7f46bSManish Rangankar 		qedi_ep->pmtu = qedi->ll2_mtu;
1336ace7f46bSManish Rangankar 	}
1337ace7f46bSManish Rangankar 
1338ace7f46bSManish Rangankar 	port_id = qedi_ep->src_port;
1339ace7f46bSManish Rangankar 	if (port_id >= QEDI_LOCAL_PORT_MIN &&
1340ace7f46bSManish Rangankar 	    port_id < QEDI_LOCAL_PORT_MAX) {
1341ace7f46bSManish Rangankar 		if (qedi_alloc_id(&qedi->lcl_port_tbl, port_id))
1342ace7f46bSManish Rangankar 			port_id = 0;
1343ace7f46bSManish Rangankar 	} else {
1344ace7f46bSManish Rangankar 		port_id = 0;
1345ace7f46bSManish Rangankar 	}
1346ace7f46bSManish Rangankar 
1347ace7f46bSManish Rangankar 	if (!port_id) {
1348ace7f46bSManish Rangankar 		port_id = qedi_alloc_new_id(&qedi->lcl_port_tbl);
1349ace7f46bSManish Rangankar 		if (port_id == QEDI_LOCAL_PORT_INVALID) {
1350ace7f46bSManish Rangankar 			QEDI_ERR(&qedi->dbg_ctx,
1351ace7f46bSManish Rangankar 				 "Failed to allocate port id for iscsi_cid=0x%x\n",
1352ace7f46bSManish Rangankar 				 iscsi_cid);
1353ace7f46bSManish Rangankar 			ret = -ENOMEM;
1354ace7f46bSManish Rangankar 			goto set_path_exit;
1355ace7f46bSManish Rangankar 		}
1356ace7f46bSManish Rangankar 	}
1357ace7f46bSManish Rangankar 
1358ace7f46bSManish Rangankar 	qedi_ep->src_port = port_id;
1359ace7f46bSManish Rangankar 
1360ace7f46bSManish Rangankar 	if (qedi_ep->ip_type == TCP_IPV4) {
1361ace7f46bSManish Rangankar 		memcpy(&qedi_ep->src_addr[0], &path_data->src.v4_addr,
1362ace7f46bSManish Rangankar 		       sizeof(struct in_addr));
1363ace7f46bSManish Rangankar 		memcpy(&qedi->src_ip[0], &path_data->src.v4_addr,
1364ace7f46bSManish Rangankar 		       sizeof(struct in_addr));
1365ace7f46bSManish Rangankar 		qedi->ip_type = TCP_IPV4;
1366ace7f46bSManish Rangankar 
1367ace7f46bSManish Rangankar 		QEDI_INFO(&qedi->dbg_ctx, QEDI_LOG_CONN,
1368ace7f46bSManish Rangankar 			  "src addr:port=%pI4:%u, dst addr:port=%pI4:%u\n",
1369ace7f46bSManish Rangankar 			  qedi_ep->src_addr, qedi_ep->src_port,
1370ace7f46bSManish Rangankar 			  qedi_ep->dst_addr, qedi_ep->dst_port);
1371ace7f46bSManish Rangankar 	} else {
1372ace7f46bSManish Rangankar 		memcpy(&qedi_ep->src_addr[0], &path_data->src.v6_addr,
1373ace7f46bSManish Rangankar 		       sizeof(struct in6_addr));
1374ace7f46bSManish Rangankar 		memcpy(&qedi->src_ip[0], &path_data->src.v6_addr,
1375ace7f46bSManish Rangankar 		       sizeof(struct in6_addr));
1376ace7f46bSManish Rangankar 		qedi->ip_type = TCP_IPV6;
1377ace7f46bSManish Rangankar 
1378ace7f46bSManish Rangankar 		QEDI_INFO(&qedi->dbg_ctx, QEDI_LOG_CONN,
1379ace7f46bSManish Rangankar 			  "src addr:port=%pI6:%u, dst addr:port=%pI6:%u\n",
1380ace7f46bSManish Rangankar 			  qedi_ep->src_addr, qedi_ep->src_port,
1381ace7f46bSManish Rangankar 			  qedi_ep->dst_addr, qedi_ep->dst_port);
1382ace7f46bSManish Rangankar 	}
1383ace7f46bSManish Rangankar 
1384ace7f46bSManish Rangankar 	queue_work(qedi->offload_thread, &qedi_ep->offload_work);
1385ace7f46bSManish Rangankar 
1386ace7f46bSManish Rangankar 	ret = 0;
1387ace7f46bSManish Rangankar 
1388ace7f46bSManish Rangankar set_path_exit:
1389ace7f46bSManish Rangankar 	return ret;
1390ace7f46bSManish Rangankar }
1391ace7f46bSManish Rangankar 
qedi_attr_is_visible(int param_type,int param)1392ace7f46bSManish Rangankar static umode_t qedi_attr_is_visible(int param_type, int param)
1393ace7f46bSManish Rangankar {
1394ace7f46bSManish Rangankar 	switch (param_type) {
1395ace7f46bSManish Rangankar 	case ISCSI_HOST_PARAM:
1396ace7f46bSManish Rangankar 		switch (param) {
1397ace7f46bSManish Rangankar 		case ISCSI_HOST_PARAM_NETDEV_NAME:
1398ace7f46bSManish Rangankar 		case ISCSI_HOST_PARAM_HWADDRESS:
1399ace7f46bSManish Rangankar 		case ISCSI_HOST_PARAM_IPADDRESS:
1400ace7f46bSManish Rangankar 			return 0444;
1401ace7f46bSManish Rangankar 		default:
1402ace7f46bSManish Rangankar 			return 0;
1403ace7f46bSManish Rangankar 		}
1404ace7f46bSManish Rangankar 	case ISCSI_PARAM:
1405ace7f46bSManish Rangankar 		switch (param) {
1406ace7f46bSManish Rangankar 		case ISCSI_PARAM_MAX_RECV_DLENGTH:
1407ace7f46bSManish Rangankar 		case ISCSI_PARAM_MAX_XMIT_DLENGTH:
1408ace7f46bSManish Rangankar 		case ISCSI_PARAM_HDRDGST_EN:
1409ace7f46bSManish Rangankar 		case ISCSI_PARAM_DATADGST_EN:
1410ace7f46bSManish Rangankar 		case ISCSI_PARAM_CONN_ADDRESS:
1411ace7f46bSManish Rangankar 		case ISCSI_PARAM_CONN_PORT:
1412ace7f46bSManish Rangankar 		case ISCSI_PARAM_EXP_STATSN:
1413ace7f46bSManish Rangankar 		case ISCSI_PARAM_PERSISTENT_ADDRESS:
1414ace7f46bSManish Rangankar 		case ISCSI_PARAM_PERSISTENT_PORT:
1415ace7f46bSManish Rangankar 		case ISCSI_PARAM_PING_TMO:
1416ace7f46bSManish Rangankar 		case ISCSI_PARAM_RECV_TMO:
1417ace7f46bSManish Rangankar 		case ISCSI_PARAM_INITIAL_R2T_EN:
1418ace7f46bSManish Rangankar 		case ISCSI_PARAM_MAX_R2T:
1419ace7f46bSManish Rangankar 		case ISCSI_PARAM_IMM_DATA_EN:
1420ace7f46bSManish Rangankar 		case ISCSI_PARAM_FIRST_BURST:
1421ace7f46bSManish Rangankar 		case ISCSI_PARAM_MAX_BURST:
1422ace7f46bSManish Rangankar 		case ISCSI_PARAM_PDU_INORDER_EN:
1423ace7f46bSManish Rangankar 		case ISCSI_PARAM_DATASEQ_INORDER_EN:
1424ace7f46bSManish Rangankar 		case ISCSI_PARAM_ERL:
1425ace7f46bSManish Rangankar 		case ISCSI_PARAM_TARGET_NAME:
1426ace7f46bSManish Rangankar 		case ISCSI_PARAM_TPGT:
1427ace7f46bSManish Rangankar 		case ISCSI_PARAM_USERNAME:
1428ace7f46bSManish Rangankar 		case ISCSI_PARAM_PASSWORD:
1429ace7f46bSManish Rangankar 		case ISCSI_PARAM_USERNAME_IN:
1430ace7f46bSManish Rangankar 		case ISCSI_PARAM_PASSWORD_IN:
1431ace7f46bSManish Rangankar 		case ISCSI_PARAM_FAST_ABORT:
1432ace7f46bSManish Rangankar 		case ISCSI_PARAM_ABORT_TMO:
1433ace7f46bSManish Rangankar 		case ISCSI_PARAM_LU_RESET_TMO:
1434ace7f46bSManish Rangankar 		case ISCSI_PARAM_TGT_RESET_TMO:
1435ace7f46bSManish Rangankar 		case ISCSI_PARAM_IFACE_NAME:
1436ace7f46bSManish Rangankar 		case ISCSI_PARAM_INITIATOR_NAME:
1437ace7f46bSManish Rangankar 		case ISCSI_PARAM_BOOT_ROOT:
1438ace7f46bSManish Rangankar 		case ISCSI_PARAM_BOOT_NIC:
1439ace7f46bSManish Rangankar 		case ISCSI_PARAM_BOOT_TARGET:
1440ace7f46bSManish Rangankar 			return 0444;
1441ace7f46bSManish Rangankar 		default:
1442ace7f46bSManish Rangankar 			return 0;
1443ace7f46bSManish Rangankar 		}
1444ace7f46bSManish Rangankar 	}
1445ace7f46bSManish Rangankar 
1446ace7f46bSManish Rangankar 	return 0;
1447ace7f46bSManish Rangankar }
1448ace7f46bSManish Rangankar 
qedi_cleanup_task(struct iscsi_task * task)1449ace7f46bSManish Rangankar static void qedi_cleanup_task(struct iscsi_task *task)
1450ace7f46bSManish Rangankar {
14512ce00236SMike Christie 	struct qedi_cmd *cmd;
14522ce00236SMike Christie 
14532ce00236SMike Christie 	if (task->state == ISCSI_TASK_PENDING) {
1454ace7f46bSManish Rangankar 		QEDI_INFO(NULL, QEDI_LOG_IO, "Returning ref_cnt=%d\n",
14556dc618cdSElena Reshetova 			  refcount_read(&task->refcount));
1456ace7f46bSManish Rangankar 		return;
1457ace7f46bSManish Rangankar 	}
1458ace7f46bSManish Rangankar 
14592ce00236SMike Christie 	if (task->sc)
1460ace7f46bSManish Rangankar 		qedi_iscsi_unmap_sg_list(task->dd_data);
14612ce00236SMike Christie 
14622ce00236SMike Christie 	cmd = task->dd_data;
14632ce00236SMike Christie 	if (cmd->task_id != U16_MAX)
14642ce00236SMike Christie 		qedi_clear_task_idx(iscsi_host_priv(task->conn->session->host),
14652ce00236SMike Christie 				    cmd->task_id);
14662ce00236SMike Christie 
14672ce00236SMike Christie 	cmd->task_id = U16_MAX;
14682ce00236SMike Christie 	cmd->scsi_cmd = NULL;
1469ace7f46bSManish Rangankar }
1470ace7f46bSManish Rangankar 
1471ace7f46bSManish Rangankar struct iscsi_transport qedi_iscsi_transport = {
1472ace7f46bSManish Rangankar 	.owner = THIS_MODULE,
1473ace7f46bSManish Rangankar 	.name = QEDI_MODULE_NAME,
1474ace7f46bSManish Rangankar 	.caps = CAP_RECOVERY_L0 | CAP_HDRDGST | CAP_MULTI_R2T | CAP_DATADGST |
1475ace7f46bSManish Rangankar 		CAP_DATA_PATH_OFFLOAD | CAP_TEXT_NEGO,
1476ace7f46bSManish Rangankar 	.create_session = qedi_session_create,
1477ace7f46bSManish Rangankar 	.destroy_session = qedi_session_destroy,
1478ace7f46bSManish Rangankar 	.create_conn = qedi_conn_create,
1479ace7f46bSManish Rangankar 	.bind_conn = qedi_conn_bind,
1480891e2639SMike Christie 	.unbind_conn = iscsi_conn_unbind,
1481ace7f46bSManish Rangankar 	.start_conn = qedi_conn_start,
1482ace7f46bSManish Rangankar 	.stop_conn = iscsi_conn_stop,
1483ace7f46bSManish Rangankar 	.destroy_conn = qedi_conn_destroy,
1484ace7f46bSManish Rangankar 	.set_param = iscsi_set_param,
1485ace7f46bSManish Rangankar 	.get_ep_param = qedi_ep_get_param,
1486ace7f46bSManish Rangankar 	.get_conn_param = iscsi_conn_get_param,
1487ace7f46bSManish Rangankar 	.get_session_param = iscsi_session_get_param,
1488ace7f46bSManish Rangankar 	.get_host_param = qedi_host_get_param,
1489ace7f46bSManish Rangankar 	.send_pdu = iscsi_conn_send_pdu,
1490ace7f46bSManish Rangankar 	.get_stats = qedi_conn_get_stats,
1491ace7f46bSManish Rangankar 	.xmit_task = qedi_task_xmit,
1492ace7f46bSManish Rangankar 	.cleanup_task = qedi_cleanup_task,
1493ace7f46bSManish Rangankar 	.session_recovery_timedout = iscsi_session_recovery_timedout,
1494ace7f46bSManish Rangankar 	.ep_connect = qedi_ep_connect,
1495ace7f46bSManish Rangankar 	.ep_poll = qedi_ep_poll,
1496ace7f46bSManish Rangankar 	.ep_disconnect = qedi_ep_disconnect,
1497ace7f46bSManish Rangankar 	.set_path = qedi_set_path,
1498ace7f46bSManish Rangankar 	.attr_is_visible = qedi_attr_is_visible,
1499ace7f46bSManish Rangankar };
1500ace7f46bSManish Rangankar 
qedi_start_conn_recovery(struct qedi_ctx * qedi,struct qedi_conn * qedi_conn)1501ace7f46bSManish Rangankar void qedi_start_conn_recovery(struct qedi_ctx *qedi,
1502ace7f46bSManish Rangankar 			      struct qedi_conn *qedi_conn)
1503ace7f46bSManish Rangankar {
1504ace7f46bSManish Rangankar 	struct iscsi_cls_session *cls_sess;
1505ace7f46bSManish Rangankar 	struct iscsi_cls_conn *cls_conn;
1506ace7f46bSManish Rangankar 	struct iscsi_conn *conn;
1507ace7f46bSManish Rangankar 
1508ace7f46bSManish Rangankar 	cls_conn = qedi_conn->cls_conn;
1509ace7f46bSManish Rangankar 	conn = cls_conn->dd_data;
1510ace7f46bSManish Rangankar 	cls_sess = iscsi_conn_to_session(cls_conn);
1511ace7f46bSManish Rangankar 
1512ace7f46bSManish Rangankar 	if (iscsi_is_session_online(cls_sess)) {
1513ace7f46bSManish Rangankar 		qedi_conn->abrt_conn = 1;
1514ace7f46bSManish Rangankar 		QEDI_ERR(&qedi->dbg_ctx,
1515ace7f46bSManish Rangankar 			 "Failing connection, state=0x%x, cid=0x%x\n",
1516ace7f46bSManish Rangankar 			 conn->session->state, qedi_conn->iscsi_conn_id);
1517ace7f46bSManish Rangankar 		iscsi_conn_failure(qedi_conn->cls_conn->dd_data,
1518ace7f46bSManish Rangankar 				   ISCSI_ERR_CONN_FAILED);
1519ace7f46bSManish Rangankar 	}
1520ace7f46bSManish Rangankar }
1521ace7f46bSManish Rangankar 
1522ace7f46bSManish Rangankar static const struct {
1523ace7f46bSManish Rangankar 	enum iscsi_error_types error_code;
1524ace7f46bSManish Rangankar 	char *err_string;
1525ace7f46bSManish Rangankar } qedi_iscsi_error[] = {
1526ace7f46bSManish Rangankar 	{ ISCSI_STATUS_NONE,
1527ace7f46bSManish Rangankar 	  "tcp_error none"
1528ace7f46bSManish Rangankar 	},
1529ace7f46bSManish Rangankar 	{ ISCSI_CONN_ERROR_TASK_CID_MISMATCH,
1530ace7f46bSManish Rangankar 	  "task cid mismatch"
1531ace7f46bSManish Rangankar 	},
1532ace7f46bSManish Rangankar 	{ ISCSI_CONN_ERROR_TASK_NOT_VALID,
1533ace7f46bSManish Rangankar 	  "invalid task"
1534ace7f46bSManish Rangankar 	},
1535ace7f46bSManish Rangankar 	{ ISCSI_CONN_ERROR_RQ_RING_IS_FULL,
1536ace7f46bSManish Rangankar 	  "rq ring full"
1537ace7f46bSManish Rangankar 	},
1538ace7f46bSManish Rangankar 	{ ISCSI_CONN_ERROR_CMDQ_RING_IS_FULL,
1539ace7f46bSManish Rangankar 	  "cmdq ring full"
1540ace7f46bSManish Rangankar 	},
1541ace7f46bSManish Rangankar 	{ ISCSI_CONN_ERROR_HQE_CACHING_FAILED,
1542ace7f46bSManish Rangankar 	  "sge caching failed"
1543ace7f46bSManish Rangankar 	},
1544ace7f46bSManish Rangankar 	{ ISCSI_CONN_ERROR_HEADER_DIGEST_ERROR,
1545ace7f46bSManish Rangankar 	  "hdr digest error"
1546ace7f46bSManish Rangankar 	},
1547ace7f46bSManish Rangankar 	{ ISCSI_CONN_ERROR_LOCAL_COMPLETION_ERROR,
1548ace7f46bSManish Rangankar 	  "local cmpl error"
1549ace7f46bSManish Rangankar 	},
1550ace7f46bSManish Rangankar 	{ ISCSI_CONN_ERROR_DATA_OVERRUN,
1551ace7f46bSManish Rangankar 	  "invalid task"
1552ace7f46bSManish Rangankar 	},
1553ace7f46bSManish Rangankar 	{ ISCSI_CONN_ERROR_OUT_OF_SGES_ERROR,
1554ace7f46bSManish Rangankar 	  "out of sge error"
1555ace7f46bSManish Rangankar 	},
1556ace7f46bSManish Rangankar 	{ ISCSI_CONN_ERROR_TCP_IP_FRAGMENT_ERROR,
1557ace7f46bSManish Rangankar 	  "tcp ip fragment error"
1558ace7f46bSManish Rangankar 	},
1559ace7f46bSManish Rangankar 	{ ISCSI_CONN_ERROR_PROTOCOL_ERR_AHS_LEN,
1560ace7f46bSManish Rangankar 	  "AHS len protocol error"
1561ace7f46bSManish Rangankar 	},
1562ace7f46bSManish Rangankar 	{ ISCSI_CONN_ERROR_PROTOCOL_ERR_ITT_OUT_OF_RANGE,
1563ace7f46bSManish Rangankar 	  "itt out of range error"
1564ace7f46bSManish Rangankar 	},
1565ace7f46bSManish Rangankar 	{ ISCSI_CONN_ERROR_PROTOCOL_ERR_DATA_SEG_LEN_EXCEEDS_PDU_SIZE,
1566ace7f46bSManish Rangankar 	  "data seg more than pdu size"
1567ace7f46bSManish Rangankar 	},
1568ace7f46bSManish Rangankar 	{ ISCSI_CONN_ERROR_PROTOCOL_ERR_INVALID_OPCODE,
1569ace7f46bSManish Rangankar 	  "invalid opcode"
1570ace7f46bSManish Rangankar 	},
1571ace7f46bSManish Rangankar 	{ ISCSI_CONN_ERROR_PROTOCOL_ERR_INVALID_OPCODE_BEFORE_UPDATE,
1572ace7f46bSManish Rangankar 	  "invalid opcode before update"
1573ace7f46bSManish Rangankar 	},
1574ace7f46bSManish Rangankar 	{ ISCSI_CONN_ERROR_UNVALID_NOPIN_DSL,
1575ace7f46bSManish Rangankar 	  "unexpected opcode"
1576ace7f46bSManish Rangankar 	},
1577ace7f46bSManish Rangankar 	{ ISCSI_CONN_ERROR_PROTOCOL_ERR_R2T_CARRIES_NO_DATA,
1578ace7f46bSManish Rangankar 	  "r2t carries no data"
1579ace7f46bSManish Rangankar 	},
1580ace7f46bSManish Rangankar 	{ ISCSI_CONN_ERROR_PROTOCOL_ERR_DATA_SN,
1581ace7f46bSManish Rangankar 	  "data sn error"
1582ace7f46bSManish Rangankar 	},
1583ace7f46bSManish Rangankar 	{ ISCSI_CONN_ERROR_PROTOCOL_ERR_DATA_IN_TTT,
1584ace7f46bSManish Rangankar 	  "data TTT error"
1585ace7f46bSManish Rangankar 	},
1586ace7f46bSManish Rangankar 	{ ISCSI_CONN_ERROR_PROTOCOL_ERR_R2T_TTT,
1587ace7f46bSManish Rangankar 	  "r2t TTT error"
1588ace7f46bSManish Rangankar 	},
1589ace7f46bSManish Rangankar 	{ ISCSI_CONN_ERROR_PROTOCOL_ERR_R2T_BUFFER_OFFSET,
1590ace7f46bSManish Rangankar 	  "buffer offset error"
1591ace7f46bSManish Rangankar 	},
1592ace7f46bSManish Rangankar 	{ ISCSI_CONN_ERROR_PROTOCOL_ERR_BUFFER_OFFSET_OOO,
1593ace7f46bSManish Rangankar 	  "buffer offset ooo"
1594ace7f46bSManish Rangankar 	},
1595ace7f46bSManish Rangankar 	{ ISCSI_CONN_ERROR_PROTOCOL_ERR_R2T_SN,
1596ace7f46bSManish Rangankar 	  "data seg len 0"
1597ace7f46bSManish Rangankar 	},
1598ace7f46bSManish Rangankar 	{ ISCSI_CONN_ERROR_PROTOCOL_ERR_DESIRED_DATA_TRNS_LEN_0,
1599ace7f46bSManish Rangankar 	  "data xer len error"
1600ace7f46bSManish Rangankar 	},
1601ace7f46bSManish Rangankar 	{ ISCSI_CONN_ERROR_PROTOCOL_ERR_DESIRED_DATA_TRNS_LEN_1,
1602ace7f46bSManish Rangankar 	  "data xer len1 error"
1603ace7f46bSManish Rangankar 	},
1604ace7f46bSManish Rangankar 	{ ISCSI_CONN_ERROR_PROTOCOL_ERR_DESIRED_DATA_TRNS_LEN_2,
1605ace7f46bSManish Rangankar 	  "data xer len2 error"
1606ace7f46bSManish Rangankar 	},
1607ace7f46bSManish Rangankar 	{ ISCSI_CONN_ERROR_PROTOCOL_ERR_LUN,
1608ace7f46bSManish Rangankar 	  "protocol lun error"
1609ace7f46bSManish Rangankar 	},
1610ace7f46bSManish Rangankar 	{ ISCSI_CONN_ERROR_PROTOCOL_ERR_F_BIT_ZERO,
1611ace7f46bSManish Rangankar 	  "f bit zero error"
1612ace7f46bSManish Rangankar 	},
1613ace7f46bSManish Rangankar 	{ ISCSI_CONN_ERROR_PROTOCOL_ERR_EXP_STAT_SN,
1614ace7f46bSManish Rangankar 	  "exp stat sn error"
1615ace7f46bSManish Rangankar 	},
1616ace7f46bSManish Rangankar 	{ ISCSI_CONN_ERROR_PROTOCOL_ERR_DSL_NOT_ZERO,
1617ace7f46bSManish Rangankar 	  "dsl not zero error"
1618ace7f46bSManish Rangankar 	},
1619ace7f46bSManish Rangankar 	{ ISCSI_CONN_ERROR_PROTOCOL_ERR_INVALID_DSL,
1620ace7f46bSManish Rangankar 	  "invalid dsl"
1621ace7f46bSManish Rangankar 	},
1622ace7f46bSManish Rangankar 	{ ISCSI_CONN_ERROR_PROTOCOL_ERR_DATA_SEG_LEN_TOO_BIG,
1623ace7f46bSManish Rangankar 	  "data seg len too big"
1624ace7f46bSManish Rangankar 	},
1625ace7f46bSManish Rangankar 	{ ISCSI_CONN_ERROR_PROTOCOL_ERR_OUTSTANDING_R2T_COUNT,
1626ace7f46bSManish Rangankar 	  "outstanding r2t count error"
1627ace7f46bSManish Rangankar 	},
1628ace7f46bSManish Rangankar 	{ ISCSI_CONN_ERROR_SENSE_DATA_LENGTH,
1629ace7f46bSManish Rangankar 	  "sense datalen error"
1630ace7f46bSManish Rangankar 	},
1631ace7f46bSManish Rangankar };
1632ace7f46bSManish Rangankar 
qedi_get_iscsi_error(enum iscsi_error_types err_code)1633010f7c2aSLee Jones static char *qedi_get_iscsi_error(enum iscsi_error_types err_code)
1634ace7f46bSManish Rangankar {
1635ace7f46bSManish Rangankar 	int i;
1636ace7f46bSManish Rangankar 	char *msg = NULL;
1637ace7f46bSManish Rangankar 
1638ace7f46bSManish Rangankar 	for (i = 0; i < ARRAY_SIZE(qedi_iscsi_error); i++) {
1639ace7f46bSManish Rangankar 		if (qedi_iscsi_error[i].error_code == err_code) {
1640ace7f46bSManish Rangankar 			msg = qedi_iscsi_error[i].err_string;
1641ace7f46bSManish Rangankar 			break;
1642ace7f46bSManish Rangankar 		}
1643ace7f46bSManish Rangankar 	}
1644ace7f46bSManish Rangankar 	return msg;
1645ace7f46bSManish Rangankar }
1646ace7f46bSManish Rangankar 
qedi_process_iscsi_error(struct qedi_endpoint * ep,struct iscsi_eqe_data * data)1647da090917STomer Tayar void qedi_process_iscsi_error(struct qedi_endpoint *ep,
1648da090917STomer Tayar 			      struct iscsi_eqe_data *data)
1649ace7f46bSManish Rangankar {
1650ace7f46bSManish Rangankar 	struct qedi_conn *qedi_conn;
1651ace7f46bSManish Rangankar 	struct qedi_ctx *qedi;
1652ace7f46bSManish Rangankar 	char warn_notice[] = "iscsi_warning";
1653ace7f46bSManish Rangankar 	char error_notice[] = "iscsi_error";
1654ace7f46bSManish Rangankar 	char unknown_msg[] = "Unknown error";
1655ace7f46bSManish Rangankar 	char *message;
1656ace7f46bSManish Rangankar 	int need_recovery = 0;
1657ace7f46bSManish Rangankar 	u32 err_mask = 0;
1658ace7f46bSManish Rangankar 	char *msg;
1659ace7f46bSManish Rangankar 
1660ace7f46bSManish Rangankar 	if (!ep)
1661ace7f46bSManish Rangankar 		return;
1662ace7f46bSManish Rangankar 
1663ace7f46bSManish Rangankar 	qedi_conn = ep->conn;
1664ace7f46bSManish Rangankar 	if (!qedi_conn)
1665ace7f46bSManish Rangankar 		return;
1666ace7f46bSManish Rangankar 
1667ace7f46bSManish Rangankar 	qedi = ep->qedi;
1668ace7f46bSManish Rangankar 
1669ace7f46bSManish Rangankar 	QEDI_ERR(&qedi->dbg_ctx, "async event iscsi error:0x%x\n",
1670ace7f46bSManish Rangankar 		 data->error_code);
1671ace7f46bSManish Rangankar 
1672ace7f46bSManish Rangankar 	if (err_mask) {
1673ace7f46bSManish Rangankar 		need_recovery = 0;
1674ace7f46bSManish Rangankar 		message = warn_notice;
1675ace7f46bSManish Rangankar 	} else {
1676ace7f46bSManish Rangankar 		need_recovery = 1;
1677ace7f46bSManish Rangankar 		message = error_notice;
1678ace7f46bSManish Rangankar 	}
1679ace7f46bSManish Rangankar 
1680ace7f46bSManish Rangankar 	msg = qedi_get_iscsi_error(data->error_code);
1681ace7f46bSManish Rangankar 	if (!msg) {
1682ace7f46bSManish Rangankar 		need_recovery = 0;
1683ace7f46bSManish Rangankar 		msg = unknown_msg;
1684ace7f46bSManish Rangankar 	}
1685ace7f46bSManish Rangankar 
1686ace7f46bSManish Rangankar 	iscsi_conn_printk(KERN_ALERT,
1687ace7f46bSManish Rangankar 			  qedi_conn->cls_conn->dd_data,
1688ace7f46bSManish Rangankar 			  "qedi: %s - %s\n", message, msg);
1689ace7f46bSManish Rangankar 
1690ace7f46bSManish Rangankar 	if (need_recovery)
1691ace7f46bSManish Rangankar 		qedi_start_conn_recovery(qedi_conn->qedi, qedi_conn);
1692ace7f46bSManish Rangankar }
1693ace7f46bSManish Rangankar 
qedi_process_tcp_error(struct qedi_endpoint * ep,struct iscsi_eqe_data * data)1694da090917STomer Tayar void qedi_process_tcp_error(struct qedi_endpoint *ep,
1695da090917STomer Tayar 			    struct iscsi_eqe_data *data)
1696ace7f46bSManish Rangankar {
1697ace7f46bSManish Rangankar 	struct qedi_conn *qedi_conn;
1698ace7f46bSManish Rangankar 
1699ace7f46bSManish Rangankar 	if (!ep)
1700ace7f46bSManish Rangankar 		return;
1701ace7f46bSManish Rangankar 
1702ace7f46bSManish Rangankar 	qedi_conn = ep->conn;
1703ace7f46bSManish Rangankar 	if (!qedi_conn)
1704ace7f46bSManish Rangankar 		return;
1705ace7f46bSManish Rangankar 
1706ace7f46bSManish Rangankar 	QEDI_ERR(&ep->qedi->dbg_ctx, "async event TCP error:0x%x\n",
1707ace7f46bSManish Rangankar 		 data->error_code);
1708ace7f46bSManish Rangankar 
1709ace7f46bSManish Rangankar 	qedi_start_conn_recovery(qedi_conn->qedi, qedi_conn);
1710ace7f46bSManish Rangankar }
1711