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