GNU Linux-libre 5.15.54-gnu
[releases.git] / drivers / scsi / qedi / qedi_iscsi.c
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         int rc = 0;
391
392         ep = iscsi_lookup_endpoint(transport_fd);
393         if (!ep)
394                 return -EINVAL;
395
396         qedi_ep = ep->dd_data;
397         if ((qedi_ep->state == EP_STATE_TCP_FIN_RCVD) ||
398             (qedi_ep->state == EP_STATE_TCP_RST_RCVD)) {
399                 rc = -EINVAL;
400                 goto put_ep;
401         }
402
403         if (iscsi_conn_bind(cls_session, cls_conn, is_leading)) {
404                 rc = -EINVAL;
405                 goto put_ep;
406         }
407
408
409         qedi_ep->conn = qedi_conn;
410         qedi_conn->ep = qedi_ep;
411         qedi_conn->iscsi_ep = ep;
412         qedi_conn->iscsi_conn_id = qedi_ep->iscsi_cid;
413         qedi_conn->fw_cid = qedi_ep->fw_cid;
414         qedi_conn->cmd_cleanup_req = 0;
415         qedi_conn->cmd_cleanup_cmpl = 0;
416
417         if (qedi_bind_conn_to_iscsi_cid(qedi, qedi_conn)) {
418                 rc = -EINVAL;
419                 goto put_ep;
420         }
421
422
423         spin_lock_init(&qedi_conn->tmf_work_lock);
424         INIT_LIST_HEAD(&qedi_conn->tmf_work_list);
425         init_waitqueue_head(&qedi_conn->wait_queue);
426 put_ep:
427         iscsi_put_endpoint(ep);
428         return rc;
429 }
430
431 static int qedi_iscsi_update_conn(struct qedi_ctx *qedi,
432                                   struct qedi_conn *qedi_conn)
433 {
434         struct qed_iscsi_params_update *conn_info;
435         struct iscsi_cls_conn *cls_conn = qedi_conn->cls_conn;
436         struct iscsi_conn *conn = cls_conn->dd_data;
437         struct qedi_endpoint *qedi_ep;
438         int rval;
439
440         qedi_ep = qedi_conn->ep;
441
442         conn_info = kzalloc(sizeof(*conn_info), GFP_KERNEL);
443         if (!conn_info) {
444                 QEDI_ERR(&qedi->dbg_ctx, "memory alloc failed\n");
445                 return -ENOMEM;
446         }
447
448         conn_info->update_flag = 0;
449
450         if (conn->hdrdgst_en)
451                 SET_FIELD(conn_info->update_flag,
452                           ISCSI_CONN_UPDATE_RAMROD_PARAMS_HD_EN, true);
453         if (conn->datadgst_en)
454                 SET_FIELD(conn_info->update_flag,
455                           ISCSI_CONN_UPDATE_RAMROD_PARAMS_DD_EN, true);
456         if (conn->session->initial_r2t_en)
457                 SET_FIELD(conn_info->update_flag,
458                           ISCSI_CONN_UPDATE_RAMROD_PARAMS_INITIAL_R2T,
459                           true);
460         if (conn->session->imm_data_en)
461                 SET_FIELD(conn_info->update_flag,
462                           ISCSI_CONN_UPDATE_RAMROD_PARAMS_IMMEDIATE_DATA,
463                           true);
464
465         conn_info->max_seq_size = conn->session->max_burst;
466         conn_info->max_recv_pdu_length = conn->max_recv_dlength;
467         conn_info->max_send_pdu_length = conn->max_xmit_dlength;
468         conn_info->first_seq_length = conn->session->first_burst;
469         conn_info->exp_stat_sn = conn->exp_statsn;
470
471         rval = qedi_ops->update_conn(qedi->cdev, qedi_ep->handle,
472                                      conn_info);
473         if (rval) {
474                 rval = -ENXIO;
475                 QEDI_ERR(&qedi->dbg_ctx, "Could not update connection\n");
476         }
477
478         kfree(conn_info);
479         return rval;
480 }
481
482 static u16 qedi_calc_mss(u16 pmtu, u8 is_ipv6, u8 tcp_ts_en, u8 vlan_en)
483 {
484         u16 mss = 0;
485         u16 hdrs = TCP_HDR_LEN;
486
487         if (is_ipv6)
488                 hdrs += IPV6_HDR_LEN;
489         else
490                 hdrs += IPV4_HDR_LEN;
491
492         mss = pmtu - hdrs;
493
494         if (!mss)
495                 mss = DEF_MSS;
496
497         return mss;
498 }
499
500 static int qedi_iscsi_offload_conn(struct qedi_endpoint *qedi_ep)
501 {
502         struct qed_iscsi_params_offload *conn_info;
503         struct qedi_ctx *qedi = qedi_ep->qedi;
504         int rval;
505         int i;
506
507         conn_info = kzalloc(sizeof(*conn_info), GFP_KERNEL);
508         if (!conn_info) {
509                 QEDI_ERR(&qedi->dbg_ctx,
510                          "Failed to allocate memory ep=%p\n", qedi_ep);
511                 return -ENOMEM;
512         }
513
514         ether_addr_copy(conn_info->src.mac, qedi_ep->src_mac);
515         ether_addr_copy(conn_info->dst.mac, qedi_ep->dst_mac);
516
517         conn_info->src.ip[0] = ntohl(qedi_ep->src_addr[0]);
518         conn_info->dst.ip[0] = ntohl(qedi_ep->dst_addr[0]);
519
520         if (qedi_ep->ip_type == TCP_IPV4) {
521                 conn_info->ip_version = 0;
522                 QEDI_INFO(&qedi->dbg_ctx, QEDI_LOG_CONN,
523                           "After ntohl: src_addr=%pI4, dst_addr=%pI4\n",
524                           qedi_ep->src_addr, qedi_ep->dst_addr);
525         } else {
526                 for (i = 1; i < 4; i++) {
527                         conn_info->src.ip[i] = ntohl(qedi_ep->src_addr[i]);
528                         conn_info->dst.ip[i] = ntohl(qedi_ep->dst_addr[i]);
529                 }
530
531                 conn_info->ip_version = 1;
532                 QEDI_INFO(&qedi->dbg_ctx, QEDI_LOG_CONN,
533                           "After ntohl: src_addr=%pI6, dst_addr=%pI6\n",
534                           qedi_ep->src_addr, qedi_ep->dst_addr);
535         }
536
537         conn_info->src.port = qedi_ep->src_port;
538         conn_info->dst.port = qedi_ep->dst_port;
539
540         conn_info->layer_code = ISCSI_SLOW_PATH_LAYER_CODE;
541         conn_info->sq_pbl_addr = qedi_ep->sq_pbl_dma;
542         conn_info->vlan_id = qedi_ep->vlan_id;
543
544         SET_FIELD(conn_info->tcp_flags, TCP_OFFLOAD_PARAMS_TS_EN, 1);
545         SET_FIELD(conn_info->tcp_flags, TCP_OFFLOAD_PARAMS_DA_EN, 1);
546         SET_FIELD(conn_info->tcp_flags, TCP_OFFLOAD_PARAMS_DA_CNT_EN, 1);
547         SET_FIELD(conn_info->tcp_flags, TCP_OFFLOAD_PARAMS_KA_EN, 1);
548
549         conn_info->default_cq = (qedi_ep->fw_cid % qedi->num_queues);
550
551         conn_info->ka_max_probe_cnt = DEF_KA_MAX_PROBE_COUNT;
552         conn_info->dup_ack_theshold = 3;
553         conn_info->rcv_wnd = 65535;
554
555         conn_info->ss_thresh = 65535;
556         conn_info->srtt = 300;
557         conn_info->rtt_var = 150;
558         conn_info->flow_label = 0;
559         conn_info->ka_timeout = DEF_KA_TIMEOUT;
560         conn_info->ka_interval = DEF_KA_INTERVAL;
561         conn_info->max_rt_time = DEF_MAX_RT_TIME;
562         conn_info->ttl = DEF_TTL;
563         conn_info->tos_or_tc = DEF_TOS;
564         conn_info->remote_port = qedi_ep->dst_port;
565         conn_info->local_port = qedi_ep->src_port;
566
567         conn_info->mss = qedi_calc_mss(qedi_ep->pmtu,
568                                        (qedi_ep->ip_type == TCP_IPV6),
569                                        1, (qedi_ep->vlan_id != 0));
570
571         conn_info->cwnd = DEF_MAX_CWND * conn_info->mss;
572         conn_info->rcv_wnd_scale = 4;
573         conn_info->da_timeout_value = 200;
574         conn_info->ack_frequency = 2;
575
576         QEDI_INFO(&qedi->dbg_ctx, QEDI_LOG_INFO,
577                   "Default cq index [%d], mss [%d]\n",
578                   conn_info->default_cq, conn_info->mss);
579
580         /* Prepare the doorbell parameters */
581         qedi_ep->db_data.agg_flags = 0;
582         qedi_ep->db_data.params = 0;
583         SET_FIELD(qedi_ep->db_data.params, ISCSI_DB_DATA_DEST, DB_DEST_XCM);
584         SET_FIELD(qedi_ep->db_data.params, ISCSI_DB_DATA_AGG_CMD,
585                   DB_AGG_CMD_MAX);
586         SET_FIELD(qedi_ep->db_data.params, ISCSI_DB_DATA_AGG_VAL_SEL,
587                   DQ_XCM_ISCSI_SQ_PROD_CMD);
588         SET_FIELD(qedi_ep->db_data.params, ISCSI_DB_DATA_BYPASS_EN, 1);
589
590         /* Register doorbell with doorbell recovery mechanism */
591         rval = qedi_ops->common->db_recovery_add(qedi->cdev,
592                                                  qedi_ep->p_doorbell,
593                                                  &qedi_ep->db_data,
594                                                  DB_REC_WIDTH_32B,
595                                                  DB_REC_KERNEL);
596         if (rval) {
597                 kfree(conn_info);
598                 return rval;
599         }
600
601         rval = qedi_ops->offload_conn(qedi->cdev, qedi_ep->handle, conn_info);
602         if (rval) {
603                 /* delete doorbell from doorbell recovery mechanism */
604                 rval = qedi_ops->common->db_recovery_del(qedi->cdev,
605                                                          qedi_ep->p_doorbell,
606                                                          &qedi_ep->db_data);
607
608                 QEDI_ERR(&qedi->dbg_ctx, "offload_conn returned %d, ep=%p\n",
609                          rval, qedi_ep);
610         }
611
612         kfree(conn_info);
613         return rval;
614 }
615
616 static int qedi_conn_start(struct iscsi_cls_conn *cls_conn)
617 {
618         struct iscsi_conn *conn = cls_conn->dd_data;
619         struct qedi_conn *qedi_conn = conn->dd_data;
620         struct qedi_ctx *qedi;
621         int rval;
622
623         qedi = qedi_conn->qedi;
624
625         rval = qedi_iscsi_update_conn(qedi, qedi_conn);
626         if (rval) {
627                 iscsi_conn_printk(KERN_ALERT, conn,
628                                   "conn_start: FW offload conn failed.\n");
629                 rval = -EINVAL;
630                 goto start_err;
631         }
632
633         spin_lock(&qedi_conn->tmf_work_lock);
634         qedi_conn->fw_cleanup_works = 0;
635         qedi_conn->ep_disconnect_starting = false;
636         spin_unlock(&qedi_conn->tmf_work_lock);
637
638         qedi_conn->abrt_conn = 0;
639
640         rval = iscsi_conn_start(cls_conn);
641         if (rval) {
642                 iscsi_conn_printk(KERN_ALERT, conn,
643                                   "iscsi_conn_start: FW offload conn failed!!\n");
644         }
645
646 start_err:
647         return rval;
648 }
649
650 static void qedi_conn_destroy(struct iscsi_cls_conn *cls_conn)
651 {
652         struct iscsi_conn *conn = cls_conn->dd_data;
653         struct qedi_conn *qedi_conn = conn->dd_data;
654         struct Scsi_Host *shost;
655         struct qedi_ctx *qedi;
656
657         shost = iscsi_session_to_shost(iscsi_conn_to_session(cls_conn));
658         qedi = iscsi_host_priv(shost);
659
660         qedi_conn_free_login_resources(qedi, qedi_conn);
661         iscsi_conn_teardown(cls_conn);
662 }
663
664 static int qedi_ep_get_param(struct iscsi_endpoint *ep,
665                              enum iscsi_param param, char *buf)
666 {
667         struct qedi_endpoint *qedi_ep = ep->dd_data;
668         int len;
669
670         if (!qedi_ep)
671                 return -ENOTCONN;
672
673         switch (param) {
674         case ISCSI_PARAM_CONN_PORT:
675                 len = sprintf(buf, "%hu\n", qedi_ep->dst_port);
676                 break;
677         case ISCSI_PARAM_CONN_ADDRESS:
678                 if (qedi_ep->ip_type == TCP_IPV4)
679                         len = sprintf(buf, "%pI4\n", qedi_ep->dst_addr);
680                 else
681                         len = sprintf(buf, "%pI6\n", qedi_ep->dst_addr);
682                 break;
683         default:
684                 return -ENOTCONN;
685         }
686
687         return len;
688 }
689
690 static int qedi_host_get_param(struct Scsi_Host *shost,
691                                enum iscsi_host_param param, char *buf)
692 {
693         struct qedi_ctx *qedi;
694         int len;
695
696         qedi = iscsi_host_priv(shost);
697
698         switch (param) {
699         case ISCSI_HOST_PARAM_HWADDRESS:
700                 len = sysfs_format_mac(buf, qedi->mac, 6);
701                 break;
702         case ISCSI_HOST_PARAM_NETDEV_NAME:
703                 len = sprintf(buf, "host%d\n", shost->host_no);
704                 break;
705         case ISCSI_HOST_PARAM_IPADDRESS:
706                 if (qedi->ip_type == TCP_IPV4)
707                         len = sprintf(buf, "%pI4\n", qedi->src_ip);
708                 else
709                         len = sprintf(buf, "%pI6\n", qedi->src_ip);
710                 break;
711         default:
712                 return iscsi_host_get_param(shost, param, buf);
713         }
714
715         return len;
716 }
717
718 static void qedi_conn_get_stats(struct iscsi_cls_conn *cls_conn,
719                                 struct iscsi_stats *stats)
720 {
721         struct iscsi_conn *conn = cls_conn->dd_data;
722         struct qed_iscsi_stats iscsi_stats;
723         struct Scsi_Host *shost;
724         struct qedi_ctx *qedi;
725
726         shost = iscsi_session_to_shost(iscsi_conn_to_session(cls_conn));
727         qedi = iscsi_host_priv(shost);
728         qedi_ops->get_stats(qedi->cdev, &iscsi_stats);
729
730         conn->txdata_octets = iscsi_stats.iscsi_tx_bytes_cnt;
731         conn->rxdata_octets = iscsi_stats.iscsi_rx_bytes_cnt;
732         conn->dataout_pdus_cnt = (uint32_t)iscsi_stats.iscsi_tx_data_pdu_cnt;
733         conn->datain_pdus_cnt = (uint32_t)iscsi_stats.iscsi_rx_data_pdu_cnt;
734         conn->r2t_pdus_cnt = (uint32_t)iscsi_stats.iscsi_rx_r2t_pdu_cnt;
735
736         stats->txdata_octets = conn->txdata_octets;
737         stats->rxdata_octets = conn->rxdata_octets;
738         stats->scsicmd_pdus = conn->scsicmd_pdus_cnt;
739         stats->dataout_pdus = conn->dataout_pdus_cnt;
740         stats->scsirsp_pdus = conn->scsirsp_pdus_cnt;
741         stats->datain_pdus = conn->datain_pdus_cnt;
742         stats->r2t_pdus = conn->r2t_pdus_cnt;
743         stats->tmfcmd_pdus = conn->tmfcmd_pdus_cnt;
744         stats->tmfrsp_pdus = conn->tmfrsp_pdus_cnt;
745         stats->digest_err = 0;
746         stats->timeout_err = 0;
747         strcpy(stats->custom[0].desc, "eh_abort_cnt");
748         stats->custom[0].value = conn->eh_abort_cnt;
749         stats->custom_length = 1;
750 }
751
752 static void qedi_iscsi_prep_generic_pdu_bd(struct qedi_conn *qedi_conn)
753 {
754         struct scsi_sge *bd_tbl;
755
756         bd_tbl = (struct scsi_sge *)qedi_conn->gen_pdu.req_bd_tbl;
757
758         bd_tbl->sge_addr.hi =
759                 (u32)((u64)qedi_conn->gen_pdu.req_dma_addr >> 32);
760         bd_tbl->sge_addr.lo = (u32)qedi_conn->gen_pdu.req_dma_addr;
761         bd_tbl->sge_len = qedi_conn->gen_pdu.req_wr_ptr -
762                                 qedi_conn->gen_pdu.req_buf;
763         bd_tbl = (struct scsi_sge  *)qedi_conn->gen_pdu.resp_bd_tbl;
764         bd_tbl->sge_addr.hi =
765                         (u32)((u64)qedi_conn->gen_pdu.resp_dma_addr >> 32);
766         bd_tbl->sge_addr.lo = (u32)qedi_conn->gen_pdu.resp_dma_addr;
767         bd_tbl->sge_len = ISCSI_DEF_MAX_RECV_SEG_LEN;
768 }
769
770 static int qedi_iscsi_send_generic_request(struct iscsi_task *task)
771 {
772         struct qedi_cmd *cmd = task->dd_data;
773         struct qedi_conn *qedi_conn = cmd->conn;
774         char *buf;
775         int data_len;
776         int rc = 0;
777
778         qedi_iscsi_prep_generic_pdu_bd(qedi_conn);
779         switch (task->hdr->opcode & ISCSI_OPCODE_MASK) {
780         case ISCSI_OP_LOGIN:
781                 qedi_send_iscsi_login(qedi_conn, task);
782                 break;
783         case ISCSI_OP_NOOP_OUT:
784                 data_len = qedi_conn->gen_pdu.req_buf_size;
785                 buf = qedi_conn->gen_pdu.req_buf;
786                 if (data_len)
787                         rc = qedi_send_iscsi_nopout(qedi_conn, task,
788                                                     buf, data_len, 1);
789                 else
790                         rc = qedi_send_iscsi_nopout(qedi_conn, task,
791                                                     NULL, 0, 1);
792                 break;
793         case ISCSI_OP_LOGOUT:
794                 rc = qedi_send_iscsi_logout(qedi_conn, task);
795                 break;
796         case ISCSI_OP_SCSI_TMFUNC:
797                 rc = qedi_send_iscsi_tmf(qedi_conn, task);
798                 break;
799         case ISCSI_OP_TEXT:
800                 rc = qedi_send_iscsi_text(qedi_conn, task);
801                 break;
802         default:
803                 iscsi_conn_printk(KERN_ALERT, qedi_conn->cls_conn->dd_data,
804                                   "unsupported op 0x%x\n", task->hdr->opcode);
805         }
806
807         return rc;
808 }
809
810 static int qedi_mtask_xmit(struct iscsi_conn *conn, struct iscsi_task *task)
811 {
812         struct qedi_conn *qedi_conn = conn->dd_data;
813         struct qedi_cmd *cmd = task->dd_data;
814
815         memset(qedi_conn->gen_pdu.req_buf, 0, ISCSI_DEF_MAX_RECV_SEG_LEN);
816
817         qedi_conn->gen_pdu.req_buf_size = task->data_count;
818
819         if (task->data_count) {
820                 memcpy(qedi_conn->gen_pdu.req_buf, task->data,
821                        task->data_count);
822                 qedi_conn->gen_pdu.req_wr_ptr =
823                         qedi_conn->gen_pdu.req_buf + task->data_count;
824         }
825
826         cmd->conn = conn->dd_data;
827         return qedi_iscsi_send_generic_request(task);
828 }
829
830 static int qedi_task_xmit(struct iscsi_task *task)
831 {
832         struct iscsi_conn *conn = task->conn;
833         struct qedi_conn *qedi_conn = conn->dd_data;
834         struct qedi_cmd *cmd = task->dd_data;
835         struct scsi_cmnd *sc = task->sc;
836
837         /* Clear now so in cleanup_task we know it didn't make it */
838         cmd->scsi_cmd = NULL;
839         cmd->task_id = U16_MAX;
840
841         if (test_bit(QEDI_IN_SHUTDOWN, &qedi_conn->qedi->flags))
842                 return -ENODEV;
843
844         if (test_bit(QEDI_BLOCK_IO, &qedi_conn->qedi->flags))
845                 return -EACCES;
846
847         cmd->state = 0;
848         cmd->task = NULL;
849         cmd->use_slowpath = false;
850         cmd->conn = qedi_conn;
851         cmd->task = task;
852         cmd->io_cmd_in_list = false;
853         INIT_LIST_HEAD(&cmd->io_cmd);
854
855         if (!sc)
856                 return qedi_mtask_xmit(conn, task);
857
858         cmd->scsi_cmd = sc;
859         return qedi_iscsi_send_ioreq(task);
860 }
861
862 static void qedi_offload_work(struct work_struct *work)
863 {
864         struct qedi_endpoint *qedi_ep =
865                 container_of(work, struct qedi_endpoint, offload_work);
866         struct qedi_ctx *qedi;
867         int wait_delay = 5 * HZ;
868         int ret;
869
870         qedi = qedi_ep->qedi;
871
872         ret = qedi_iscsi_offload_conn(qedi_ep);
873         if (ret) {
874                 QEDI_ERR(&qedi->dbg_ctx,
875                          "offload error: iscsi_cid=%u, qedi_ep=%p, ret=%d\n",
876                          qedi_ep->iscsi_cid, qedi_ep, ret);
877                 qedi_ep->state = EP_STATE_OFLDCONN_FAILED;
878                 return;
879         }
880
881         ret = wait_event_interruptible_timeout(qedi_ep->tcp_ofld_wait,
882                                                (qedi_ep->state ==
883                                                EP_STATE_OFLDCONN_COMPL),
884                                                wait_delay);
885         if (ret <= 0 || qedi_ep->state != EP_STATE_OFLDCONN_COMPL) {
886                 qedi_ep->state = EP_STATE_OFLDCONN_FAILED;
887                 QEDI_ERR(&qedi->dbg_ctx,
888                          "Offload conn TIMEOUT iscsi_cid=%u, qedi_ep=%p\n",
889                          qedi_ep->iscsi_cid, qedi_ep);
890         }
891 }
892
893 static struct iscsi_endpoint *
894 qedi_ep_connect(struct Scsi_Host *shost, struct sockaddr *dst_addr,
895                 int non_blocking)
896 {
897         struct qedi_ctx *qedi;
898         struct iscsi_endpoint *ep;
899         struct qedi_endpoint *qedi_ep;
900         struct sockaddr_in *addr;
901         struct sockaddr_in6 *addr6;
902         struct iscsi_path path_req;
903         u32 msg_type = ISCSI_KEVENT_IF_DOWN;
904         u32 iscsi_cid = QEDI_CID_RESERVED;
905         u16 len = 0;
906         char *buf = NULL;
907         int ret, tmp;
908
909         if (!shost) {
910                 ret = -ENXIO;
911                 QEDI_ERR(NULL, "shost is NULL\n");
912                 return ERR_PTR(ret);
913         }
914
915         if (qedi_do_not_recover) {
916                 ret = -ENOMEM;
917                 return ERR_PTR(ret);
918         }
919
920         qedi = iscsi_host_priv(shost);
921
922         if (test_bit(QEDI_IN_OFFLINE, &qedi->flags) ||
923             test_bit(QEDI_IN_RECOVERY, &qedi->flags)) {
924                 ret = -ENOMEM;
925                 return ERR_PTR(ret);
926         }
927
928         if (atomic_read(&qedi->link_state) != QEDI_LINK_UP) {
929                 QEDI_WARN(&qedi->dbg_ctx, "qedi link down\n");
930                 return ERR_PTR(-ENXIO);
931         }
932
933         ep = iscsi_create_endpoint(sizeof(struct qedi_endpoint));
934         if (!ep) {
935                 QEDI_ERR(&qedi->dbg_ctx, "endpoint create fail\n");
936                 ret = -ENOMEM;
937                 return ERR_PTR(ret);
938         }
939         qedi_ep = ep->dd_data;
940         memset(qedi_ep, 0, sizeof(struct qedi_endpoint));
941         INIT_WORK(&qedi_ep->offload_work, qedi_offload_work);
942         qedi_ep->state = EP_STATE_IDLE;
943         qedi_ep->iscsi_cid = (u32)-1;
944         qedi_ep->qedi = qedi;
945
946         if (dst_addr->sa_family == AF_INET) {
947                 addr = (struct sockaddr_in *)dst_addr;
948                 memcpy(qedi_ep->dst_addr, &addr->sin_addr.s_addr,
949                        sizeof(struct in_addr));
950                 qedi_ep->dst_port = ntohs(addr->sin_port);
951                 qedi_ep->ip_type = TCP_IPV4;
952                 QEDI_INFO(&qedi->dbg_ctx, QEDI_LOG_CONN,
953                           "dst_addr=%pI4, dst_port=%u\n",
954                           qedi_ep->dst_addr, qedi_ep->dst_port);
955         } else if (dst_addr->sa_family == AF_INET6) {
956                 addr6 = (struct sockaddr_in6 *)dst_addr;
957                 memcpy(qedi_ep->dst_addr, &addr6->sin6_addr,
958                        sizeof(struct in6_addr));
959                 qedi_ep->dst_port = ntohs(addr6->sin6_port);
960                 qedi_ep->ip_type = TCP_IPV6;
961                 QEDI_INFO(&qedi->dbg_ctx, QEDI_LOG_CONN,
962                           "dst_addr=%pI6, dst_port=%u\n",
963                           qedi_ep->dst_addr, qedi_ep->dst_port);
964         } else {
965                 QEDI_ERR(&qedi->dbg_ctx, "Invalid endpoint\n");
966         }
967
968         ret = qedi_alloc_sq(qedi, qedi_ep);
969         if (ret)
970                 goto ep_conn_exit;
971
972         ret = qedi_ops->acquire_conn(qedi->cdev, &qedi_ep->handle,
973                                      &qedi_ep->fw_cid, &qedi_ep->p_doorbell);
974
975         if (ret) {
976                 QEDI_ERR(&qedi->dbg_ctx, "Could not acquire connection\n");
977                 ret = -ENXIO;
978                 goto ep_free_sq;
979         }
980
981         iscsi_cid = qedi_ep->handle;
982         qedi_ep->iscsi_cid = iscsi_cid;
983
984         init_waitqueue_head(&qedi_ep->ofld_wait);
985         init_waitqueue_head(&qedi_ep->tcp_ofld_wait);
986         qedi_ep->state = EP_STATE_OFLDCONN_START;
987         qedi->ep_tbl[iscsi_cid] = qedi_ep;
988
989         buf = (char *)&path_req;
990         len = sizeof(path_req);
991         memset(&path_req, 0, len);
992
993         msg_type = ISCSI_KEVENT_PATH_REQ;
994         path_req.handle = (u64)qedi_ep->iscsi_cid;
995         path_req.pmtu = qedi->ll2_mtu;
996         qedi_ep->pmtu = qedi->ll2_mtu;
997         if (qedi_ep->ip_type == TCP_IPV4) {
998                 memcpy(&path_req.dst.v4_addr, &qedi_ep->dst_addr,
999                        sizeof(struct in_addr));
1000                 path_req.ip_addr_len = 4;
1001         } else {
1002                 memcpy(&path_req.dst.v6_addr, &qedi_ep->dst_addr,
1003                        sizeof(struct in6_addr));
1004                 path_req.ip_addr_len = 16;
1005         }
1006
1007         ret = iscsi_offload_mesg(shost, &qedi_iscsi_transport, msg_type, buf,
1008                                  len);
1009         if (ret) {
1010                 QEDI_ERR(&qedi->dbg_ctx,
1011                          "iscsi_offload_mesg() failed for cid=0x%x ret=%d\n",
1012                          iscsi_cid, ret);
1013                 goto ep_rel_conn;
1014         }
1015
1016         atomic_inc(&qedi->num_offloads);
1017         return ep;
1018
1019 ep_rel_conn:
1020         qedi->ep_tbl[iscsi_cid] = NULL;
1021         tmp = qedi_ops->release_conn(qedi->cdev, qedi_ep->handle);
1022         if (tmp)
1023                 QEDI_WARN(&qedi->dbg_ctx, "release_conn returned %d\n",
1024                           tmp);
1025 ep_free_sq:
1026         qedi_free_sq(qedi, qedi_ep);
1027 ep_conn_exit:
1028         iscsi_destroy_endpoint(ep);
1029         return ERR_PTR(ret);
1030 }
1031
1032 static int qedi_ep_poll(struct iscsi_endpoint *ep, int timeout_ms)
1033 {
1034         struct qedi_endpoint *qedi_ep;
1035         int ret = 0;
1036
1037         if (qedi_do_not_recover)
1038                 return 1;
1039
1040         qedi_ep = ep->dd_data;
1041         if (qedi_ep->state == EP_STATE_IDLE ||
1042             qedi_ep->state == EP_STATE_OFLDCONN_NONE ||
1043             qedi_ep->state == EP_STATE_OFLDCONN_FAILED)
1044                 return -1;
1045
1046         if (qedi_ep->state == EP_STATE_OFLDCONN_COMPL)
1047                 ret = 1;
1048
1049         ret = wait_event_interruptible_timeout(qedi_ep->ofld_wait,
1050                                                QEDI_OFLD_WAIT_STATE(qedi_ep),
1051                                                msecs_to_jiffies(timeout_ms));
1052
1053         if (qedi_ep->state == EP_STATE_OFLDCONN_FAILED)
1054                 ret = -1;
1055
1056         if (ret > 0)
1057                 return 1;
1058         else if (!ret)
1059                 return 0;
1060         else
1061                 return ret;
1062 }
1063
1064 static void qedi_cleanup_active_cmd_list(struct qedi_conn *qedi_conn)
1065 {
1066         struct qedi_cmd *cmd, *cmd_tmp;
1067
1068         spin_lock(&qedi_conn->list_lock);
1069         list_for_each_entry_safe(cmd, cmd_tmp, &qedi_conn->active_cmd_list,
1070                                  io_cmd) {
1071                 list_del_init(&cmd->io_cmd);
1072                 qedi_conn->active_cmd_count--;
1073         }
1074         spin_unlock(&qedi_conn->list_lock);
1075 }
1076
1077 static void qedi_ep_disconnect(struct iscsi_endpoint *ep)
1078 {
1079         struct qedi_endpoint *qedi_ep;
1080         struct qedi_conn *qedi_conn = NULL;
1081         struct qedi_ctx *qedi;
1082         int ret = 0;
1083         int wait_delay;
1084         int abrt_conn = 0;
1085
1086         wait_delay = 60 * HZ + DEF_MAX_RT_TIME;
1087         qedi_ep = ep->dd_data;
1088         qedi = qedi_ep->qedi;
1089
1090         flush_work(&qedi_ep->offload_work);
1091
1092         if (qedi_ep->state == EP_STATE_OFLDCONN_START)
1093                 goto ep_exit_recover;
1094
1095         if (qedi_ep->conn) {
1096                 qedi_conn = qedi_ep->conn;
1097                 abrt_conn = qedi_conn->abrt_conn;
1098
1099                 QEDI_INFO(&qedi->dbg_ctx, QEDI_LOG_INFO,
1100                           "cid=0x%x qedi_ep=%p waiting for %d tmfs\n",
1101                           qedi_ep->iscsi_cid, qedi_ep,
1102                           qedi_conn->fw_cleanup_works);
1103
1104                 spin_lock(&qedi_conn->tmf_work_lock);
1105                 qedi_conn->ep_disconnect_starting = true;
1106                 while (qedi_conn->fw_cleanup_works > 0) {
1107                         spin_unlock(&qedi_conn->tmf_work_lock);
1108                         msleep(1000);
1109                         spin_lock(&qedi_conn->tmf_work_lock);
1110                 }
1111                 spin_unlock(&qedi_conn->tmf_work_lock);
1112
1113                 if (test_bit(QEDI_IN_RECOVERY, &qedi->flags)) {
1114                         if (qedi_do_not_recover) {
1115                                 QEDI_INFO(&qedi->dbg_ctx, QEDI_LOG_INFO,
1116                                           "Do not recover cid=0x%x\n",
1117                                           qedi_ep->iscsi_cid);
1118                                 goto ep_exit_recover;
1119                         }
1120                         QEDI_INFO(&qedi->dbg_ctx, QEDI_LOG_INFO,
1121                                   "Reset recovery cid=0x%x, qedi_ep=%p, state=0x%x\n",
1122                                   qedi_ep->iscsi_cid, qedi_ep, qedi_ep->state);
1123                         qedi_cleanup_active_cmd_list(qedi_conn);
1124                         goto ep_release_conn;
1125                 }
1126         }
1127
1128         if (qedi_do_not_recover)
1129                 goto ep_exit_recover;
1130
1131         switch (qedi_ep->state) {
1132         case EP_STATE_OFLDCONN_START:
1133         case EP_STATE_OFLDCONN_NONE:
1134                 goto ep_release_conn;
1135         case EP_STATE_OFLDCONN_FAILED:
1136                         break;
1137         case EP_STATE_OFLDCONN_COMPL:
1138                 if (unlikely(!qedi_conn))
1139                         break;
1140
1141                 QEDI_INFO(&qedi->dbg_ctx, QEDI_LOG_INFO,
1142                           "Active cmd count=%d, abrt_conn=%d, ep state=0x%x, cid=0x%x, qedi_conn=%p\n",
1143                           qedi_conn->active_cmd_count, abrt_conn,
1144                           qedi_ep->state,
1145                           qedi_ep->iscsi_cid,
1146                           qedi_ep->conn
1147                           );
1148
1149                 if (!qedi_conn->active_cmd_count)
1150                         abrt_conn = 0;
1151                 else
1152                         abrt_conn = 1;
1153
1154                 if (abrt_conn)
1155                         qedi_clearsq(qedi, qedi_conn, NULL);
1156                 break;
1157         default:
1158                 break;
1159         }
1160
1161         if (!abrt_conn)
1162                 wait_delay += qedi->pf_params.iscsi_pf_params.two_msl_timer;
1163
1164         qedi_ep->state = EP_STATE_DISCONN_START;
1165
1166         if (test_bit(QEDI_IN_SHUTDOWN, &qedi->flags) ||
1167             test_bit(QEDI_IN_RECOVERY, &qedi->flags))
1168                 goto ep_release_conn;
1169
1170         /* Delete doorbell from doorbell recovery mechanism */
1171         ret = qedi_ops->common->db_recovery_del(qedi->cdev,
1172                                                qedi_ep->p_doorbell,
1173                                                &qedi_ep->db_data);
1174
1175         ret = qedi_ops->destroy_conn(qedi->cdev, qedi_ep->handle, abrt_conn);
1176         if (ret) {
1177                 QEDI_WARN(&qedi->dbg_ctx,
1178                           "destroy_conn failed returned %d\n", ret);
1179         } else {
1180                 ret = wait_event_interruptible_timeout(
1181                                         qedi_ep->tcp_ofld_wait,
1182                                         (qedi_ep->state !=
1183                                          EP_STATE_DISCONN_START),
1184                                         wait_delay);
1185                 if ((ret <= 0) || (qedi_ep->state == EP_STATE_DISCONN_START)) {
1186                         QEDI_WARN(&qedi->dbg_ctx,
1187                                   "Destroy conn timedout or interrupted, ret=%d, delay=%d, cid=0x%x\n",
1188                                   ret, wait_delay, qedi_ep->iscsi_cid);
1189                 }
1190         }
1191
1192 ep_release_conn:
1193         ret = qedi_ops->release_conn(qedi->cdev, qedi_ep->handle);
1194         if (ret)
1195                 QEDI_WARN(&qedi->dbg_ctx,
1196                           "release_conn returned %d, cid=0x%x\n",
1197                           ret, qedi_ep->iscsi_cid);
1198 ep_exit_recover:
1199         qedi_ep->state = EP_STATE_IDLE;
1200         qedi->ep_tbl[qedi_ep->iscsi_cid] = NULL;
1201         qedi->cid_que.conn_cid_tbl[qedi_ep->iscsi_cid] = NULL;
1202         qedi_free_id(&qedi->lcl_port_tbl, qedi_ep->src_port);
1203         qedi_free_sq(qedi, qedi_ep);
1204
1205         if (qedi_conn)
1206                 qedi_conn->ep = NULL;
1207
1208         qedi_ep->conn = NULL;
1209         qedi_ep->qedi = NULL;
1210         atomic_dec(&qedi->num_offloads);
1211
1212         iscsi_destroy_endpoint(ep);
1213 }
1214
1215 static int qedi_data_avail(struct qedi_ctx *qedi, u16 vlanid)
1216 {
1217         struct qed_dev *cdev = qedi->cdev;
1218         struct qedi_uio_dev *udev;
1219         struct qedi_uio_ctrl *uctrl;
1220         struct sk_buff *skb;
1221         u32 len;
1222         int rc = 0;
1223
1224         udev = qedi->udev;
1225         if (!udev) {
1226                 QEDI_ERR(&qedi->dbg_ctx, "udev is NULL.\n");
1227                 return -EINVAL;
1228         }
1229
1230         uctrl = (struct qedi_uio_ctrl *)udev->uctrl;
1231         if (!uctrl) {
1232                 QEDI_ERR(&qedi->dbg_ctx, "uctlr is NULL.\n");
1233                 return -EINVAL;
1234         }
1235
1236         len = uctrl->host_tx_pkt_len;
1237         if (!len) {
1238                 QEDI_ERR(&qedi->dbg_ctx, "Invalid len %u\n", len);
1239                 return -EINVAL;
1240         }
1241
1242         skb = alloc_skb(len, GFP_ATOMIC);
1243         if (!skb) {
1244                 QEDI_ERR(&qedi->dbg_ctx, "alloc_skb failed\n");
1245                 return -EINVAL;
1246         }
1247
1248         skb_put(skb, len);
1249         memcpy(skb->data, udev->tx_pkt, len);
1250         skb->ip_summed = CHECKSUM_NONE;
1251
1252         if (vlanid)
1253                 __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), vlanid);
1254
1255         rc = qedi_ops->ll2->start_xmit(cdev, skb, 0);
1256         if (rc) {
1257                 QEDI_ERR(&qedi->dbg_ctx, "ll2 start_xmit returned %d\n",
1258                          rc);
1259                 kfree_skb(skb);
1260         }
1261
1262         uctrl->host_tx_pkt_len = 0;
1263         uctrl->hw_tx_cons++;
1264
1265         return rc;
1266 }
1267
1268 static int qedi_set_path(struct Scsi_Host *shost, struct iscsi_path *path_data)
1269 {
1270         struct qedi_ctx *qedi;
1271         struct qedi_endpoint *qedi_ep;
1272         int ret = 0;
1273         u32 iscsi_cid;
1274         u16 port_id = 0;
1275
1276         if (!shost) {
1277                 ret = -ENXIO;
1278                 QEDI_ERR(NULL, "shost is NULL\n");
1279                 return ret;
1280         }
1281
1282         if (strcmp(shost->hostt->proc_name, "qedi")) {
1283                 ret = -ENXIO;
1284                 QEDI_ERR(NULL, "shost %s is invalid\n",
1285                          shost->hostt->proc_name);
1286                 return ret;
1287         }
1288
1289         qedi = iscsi_host_priv(shost);
1290         if (path_data->handle == QEDI_PATH_HANDLE) {
1291                 ret = qedi_data_avail(qedi, path_data->vlan_id);
1292                 goto set_path_exit;
1293         }
1294
1295         iscsi_cid = (u32)path_data->handle;
1296         if (iscsi_cid >= qedi->max_active_conns) {
1297                 ret = -EINVAL;
1298                 goto set_path_exit;
1299         }
1300         qedi_ep = qedi->ep_tbl[iscsi_cid];
1301         QEDI_INFO(&qedi->dbg_ctx, QEDI_LOG_INFO,
1302                   "iscsi_cid=0x%x, qedi_ep=%p\n", iscsi_cid, qedi_ep);
1303         if (!qedi_ep) {
1304                 ret = -EINVAL;
1305                 goto set_path_exit;
1306         }
1307
1308         if (!is_valid_ether_addr(&path_data->mac_addr[0])) {
1309                 QEDI_NOTICE(&qedi->dbg_ctx, "dst mac NOT VALID\n");
1310                 qedi_ep->state = EP_STATE_OFLDCONN_NONE;
1311                 ret = -EIO;
1312                 goto set_path_exit;
1313         }
1314
1315         ether_addr_copy(&qedi_ep->src_mac[0], &qedi->mac[0]);
1316         ether_addr_copy(&qedi_ep->dst_mac[0], &path_data->mac_addr[0]);
1317
1318         qedi_ep->vlan_id = path_data->vlan_id;
1319         if (path_data->pmtu < DEF_PATH_MTU) {
1320                 qedi_ep->pmtu = qedi->ll2_mtu;
1321                 QEDI_INFO(&qedi->dbg_ctx, QEDI_LOG_INFO,
1322                           "MTU cannot be %u, using default MTU %u\n",
1323                            path_data->pmtu, qedi_ep->pmtu);
1324         }
1325
1326         if (path_data->pmtu != qedi->ll2_mtu) {
1327                 if (path_data->pmtu > JUMBO_MTU) {
1328                         ret = -EINVAL;
1329                         QEDI_ERR(NULL, "Invalid MTU %u\n", path_data->pmtu);
1330                         goto set_path_exit;
1331                 }
1332
1333                 qedi_reset_host_mtu(qedi, path_data->pmtu);
1334                 qedi_ep->pmtu = qedi->ll2_mtu;
1335         }
1336
1337         port_id = qedi_ep->src_port;
1338         if (port_id >= QEDI_LOCAL_PORT_MIN &&
1339             port_id < QEDI_LOCAL_PORT_MAX) {
1340                 if (qedi_alloc_id(&qedi->lcl_port_tbl, port_id))
1341                         port_id = 0;
1342         } else {
1343                 port_id = 0;
1344         }
1345
1346         if (!port_id) {
1347                 port_id = qedi_alloc_new_id(&qedi->lcl_port_tbl);
1348                 if (port_id == QEDI_LOCAL_PORT_INVALID) {
1349                         QEDI_ERR(&qedi->dbg_ctx,
1350                                  "Failed to allocate port id for iscsi_cid=0x%x\n",
1351                                  iscsi_cid);
1352                         ret = -ENOMEM;
1353                         goto set_path_exit;
1354                 }
1355         }
1356
1357         qedi_ep->src_port = port_id;
1358
1359         if (qedi_ep->ip_type == TCP_IPV4) {
1360                 memcpy(&qedi_ep->src_addr[0], &path_data->src.v4_addr,
1361                        sizeof(struct in_addr));
1362                 memcpy(&qedi->src_ip[0], &path_data->src.v4_addr,
1363                        sizeof(struct in_addr));
1364                 qedi->ip_type = TCP_IPV4;
1365
1366                 QEDI_INFO(&qedi->dbg_ctx, QEDI_LOG_CONN,
1367                           "src addr:port=%pI4:%u, dst addr:port=%pI4:%u\n",
1368                           qedi_ep->src_addr, qedi_ep->src_port,
1369                           qedi_ep->dst_addr, qedi_ep->dst_port);
1370         } else {
1371                 memcpy(&qedi_ep->src_addr[0], &path_data->src.v6_addr,
1372                        sizeof(struct in6_addr));
1373                 memcpy(&qedi->src_ip[0], &path_data->src.v6_addr,
1374                        sizeof(struct in6_addr));
1375                 qedi->ip_type = TCP_IPV6;
1376
1377                 QEDI_INFO(&qedi->dbg_ctx, QEDI_LOG_CONN,
1378                           "src addr:port=%pI6:%u, dst addr:port=%pI6:%u\n",
1379                           qedi_ep->src_addr, qedi_ep->src_port,
1380                           qedi_ep->dst_addr, qedi_ep->dst_port);
1381         }
1382
1383         queue_work(qedi->offload_thread, &qedi_ep->offload_work);
1384
1385         ret = 0;
1386
1387 set_path_exit:
1388         return ret;
1389 }
1390
1391 static umode_t qedi_attr_is_visible(int param_type, int param)
1392 {
1393         switch (param_type) {
1394         case ISCSI_HOST_PARAM:
1395                 switch (param) {
1396                 case ISCSI_HOST_PARAM_NETDEV_NAME:
1397                 case ISCSI_HOST_PARAM_HWADDRESS:
1398                 case ISCSI_HOST_PARAM_IPADDRESS:
1399                         return 0444;
1400                 default:
1401                         return 0;
1402                 }
1403         case ISCSI_PARAM:
1404                 switch (param) {
1405                 case ISCSI_PARAM_MAX_RECV_DLENGTH:
1406                 case ISCSI_PARAM_MAX_XMIT_DLENGTH:
1407                 case ISCSI_PARAM_HDRDGST_EN:
1408                 case ISCSI_PARAM_DATADGST_EN:
1409                 case ISCSI_PARAM_CONN_ADDRESS:
1410                 case ISCSI_PARAM_CONN_PORT:
1411                 case ISCSI_PARAM_EXP_STATSN:
1412                 case ISCSI_PARAM_PERSISTENT_ADDRESS:
1413                 case ISCSI_PARAM_PERSISTENT_PORT:
1414                 case ISCSI_PARAM_PING_TMO:
1415                 case ISCSI_PARAM_RECV_TMO:
1416                 case ISCSI_PARAM_INITIAL_R2T_EN:
1417                 case ISCSI_PARAM_MAX_R2T:
1418                 case ISCSI_PARAM_IMM_DATA_EN:
1419                 case ISCSI_PARAM_FIRST_BURST:
1420                 case ISCSI_PARAM_MAX_BURST:
1421                 case ISCSI_PARAM_PDU_INORDER_EN:
1422                 case ISCSI_PARAM_DATASEQ_INORDER_EN:
1423                 case ISCSI_PARAM_ERL:
1424                 case ISCSI_PARAM_TARGET_NAME:
1425                 case ISCSI_PARAM_TPGT:
1426                 case ISCSI_PARAM_USERNAME:
1427                 case ISCSI_PARAM_PASSWORD:
1428                 case ISCSI_PARAM_USERNAME_IN:
1429                 case ISCSI_PARAM_PASSWORD_IN:
1430                 case ISCSI_PARAM_FAST_ABORT:
1431                 case ISCSI_PARAM_ABORT_TMO:
1432                 case ISCSI_PARAM_LU_RESET_TMO:
1433                 case ISCSI_PARAM_TGT_RESET_TMO:
1434                 case ISCSI_PARAM_IFACE_NAME:
1435                 case ISCSI_PARAM_INITIATOR_NAME:
1436                 case ISCSI_PARAM_BOOT_ROOT:
1437                 case ISCSI_PARAM_BOOT_NIC:
1438                 case ISCSI_PARAM_BOOT_TARGET:
1439                         return 0444;
1440                 default:
1441                         return 0;
1442                 }
1443         }
1444
1445         return 0;
1446 }
1447
1448 static void qedi_cleanup_task(struct iscsi_task *task)
1449 {
1450         struct qedi_cmd *cmd;
1451
1452         if (task->state == ISCSI_TASK_PENDING) {
1453                 QEDI_INFO(NULL, QEDI_LOG_IO, "Returning ref_cnt=%d\n",
1454                           refcount_read(&task->refcount));
1455                 return;
1456         }
1457
1458         if (task->sc)
1459                 qedi_iscsi_unmap_sg_list(task->dd_data);
1460
1461         cmd = task->dd_data;
1462         if (cmd->task_id != U16_MAX)
1463                 qedi_clear_task_idx(iscsi_host_priv(task->conn->session->host),
1464                                     cmd->task_id);
1465
1466         cmd->task_id = U16_MAX;
1467         cmd->scsi_cmd = NULL;
1468 }
1469
1470 struct iscsi_transport qedi_iscsi_transport = {
1471         .owner = THIS_MODULE,
1472         .name = QEDI_MODULE_NAME,
1473         .caps = CAP_RECOVERY_L0 | CAP_HDRDGST | CAP_MULTI_R2T | CAP_DATADGST |
1474                 CAP_DATA_PATH_OFFLOAD | CAP_TEXT_NEGO,
1475         .create_session = qedi_session_create,
1476         .destroy_session = qedi_session_destroy,
1477         .create_conn = qedi_conn_create,
1478         .bind_conn = qedi_conn_bind,
1479         .unbind_conn = iscsi_conn_unbind,
1480         .start_conn = qedi_conn_start,
1481         .stop_conn = iscsi_conn_stop,
1482         .destroy_conn = qedi_conn_destroy,
1483         .set_param = iscsi_set_param,
1484         .get_ep_param = qedi_ep_get_param,
1485         .get_conn_param = iscsi_conn_get_param,
1486         .get_session_param = iscsi_session_get_param,
1487         .get_host_param = qedi_host_get_param,
1488         .send_pdu = iscsi_conn_send_pdu,
1489         .get_stats = qedi_conn_get_stats,
1490         .xmit_task = qedi_task_xmit,
1491         .cleanup_task = qedi_cleanup_task,
1492         .session_recovery_timedout = iscsi_session_recovery_timedout,
1493         .ep_connect = qedi_ep_connect,
1494         .ep_poll = qedi_ep_poll,
1495         .ep_disconnect = qedi_ep_disconnect,
1496         .set_path = qedi_set_path,
1497         .attr_is_visible = qedi_attr_is_visible,
1498 };
1499
1500 void qedi_start_conn_recovery(struct qedi_ctx *qedi,
1501                               struct qedi_conn *qedi_conn)
1502 {
1503         struct iscsi_cls_session *cls_sess;
1504         struct iscsi_cls_conn *cls_conn;
1505         struct iscsi_conn *conn;
1506
1507         cls_conn = qedi_conn->cls_conn;
1508         conn = cls_conn->dd_data;
1509         cls_sess = iscsi_conn_to_session(cls_conn);
1510
1511         if (iscsi_is_session_online(cls_sess)) {
1512                 qedi_conn->abrt_conn = 1;
1513                 QEDI_ERR(&qedi->dbg_ctx,
1514                          "Failing connection, state=0x%x, cid=0x%x\n",
1515                          conn->session->state, qedi_conn->iscsi_conn_id);
1516                 iscsi_conn_failure(qedi_conn->cls_conn->dd_data,
1517                                    ISCSI_ERR_CONN_FAILED);
1518         }
1519 }
1520
1521 static const struct {
1522         enum iscsi_error_types error_code;
1523         char *err_string;
1524 } qedi_iscsi_error[] = {
1525         { ISCSI_STATUS_NONE,
1526           "tcp_error none"
1527         },
1528         { ISCSI_CONN_ERROR_TASK_CID_MISMATCH,
1529           "task cid mismatch"
1530         },
1531         { ISCSI_CONN_ERROR_TASK_NOT_VALID,
1532           "invalid task"
1533         },
1534         { ISCSI_CONN_ERROR_RQ_RING_IS_FULL,
1535           "rq ring full"
1536         },
1537         { ISCSI_CONN_ERROR_CMDQ_RING_IS_FULL,
1538           "cmdq ring full"
1539         },
1540         { ISCSI_CONN_ERROR_HQE_CACHING_FAILED,
1541           "sge caching failed"
1542         },
1543         { ISCSI_CONN_ERROR_HEADER_DIGEST_ERROR,
1544           "hdr digest error"
1545         },
1546         { ISCSI_CONN_ERROR_LOCAL_COMPLETION_ERROR,
1547           "local cmpl error"
1548         },
1549         { ISCSI_CONN_ERROR_DATA_OVERRUN,
1550           "invalid task"
1551         },
1552         { ISCSI_CONN_ERROR_OUT_OF_SGES_ERROR,
1553           "out of sge error"
1554         },
1555         { ISCSI_CONN_ERROR_TCP_IP_FRAGMENT_ERROR,
1556           "tcp ip fragment error"
1557         },
1558         { ISCSI_CONN_ERROR_PROTOCOL_ERR_AHS_LEN,
1559           "AHS len protocol error"
1560         },
1561         { ISCSI_CONN_ERROR_PROTOCOL_ERR_ITT_OUT_OF_RANGE,
1562           "itt out of range error"
1563         },
1564         { ISCSI_CONN_ERROR_PROTOCOL_ERR_DATA_SEG_LEN_EXCEEDS_PDU_SIZE,
1565           "data seg more than pdu size"
1566         },
1567         { ISCSI_CONN_ERROR_PROTOCOL_ERR_INVALID_OPCODE,
1568           "invalid opcode"
1569         },
1570         { ISCSI_CONN_ERROR_PROTOCOL_ERR_INVALID_OPCODE_BEFORE_UPDATE,
1571           "invalid opcode before update"
1572         },
1573         { ISCSI_CONN_ERROR_UNVALID_NOPIN_DSL,
1574           "unexpected opcode"
1575         },
1576         { ISCSI_CONN_ERROR_PROTOCOL_ERR_R2T_CARRIES_NO_DATA,
1577           "r2t carries no data"
1578         },
1579         { ISCSI_CONN_ERROR_PROTOCOL_ERR_DATA_SN,
1580           "data sn error"
1581         },
1582         { ISCSI_CONN_ERROR_PROTOCOL_ERR_DATA_IN_TTT,
1583           "data TTT error"
1584         },
1585         { ISCSI_CONN_ERROR_PROTOCOL_ERR_R2T_TTT,
1586           "r2t TTT error"
1587         },
1588         { ISCSI_CONN_ERROR_PROTOCOL_ERR_R2T_BUFFER_OFFSET,
1589           "buffer offset error"
1590         },
1591         { ISCSI_CONN_ERROR_PROTOCOL_ERR_BUFFER_OFFSET_OOO,
1592           "buffer offset ooo"
1593         },
1594         { ISCSI_CONN_ERROR_PROTOCOL_ERR_R2T_SN,
1595           "data seg len 0"
1596         },
1597         { ISCSI_CONN_ERROR_PROTOCOL_ERR_DESIRED_DATA_TRNS_LEN_0,
1598           "data xer len error"
1599         },
1600         { ISCSI_CONN_ERROR_PROTOCOL_ERR_DESIRED_DATA_TRNS_LEN_1,
1601           "data xer len1 error"
1602         },
1603         { ISCSI_CONN_ERROR_PROTOCOL_ERR_DESIRED_DATA_TRNS_LEN_2,
1604           "data xer len2 error"
1605         },
1606         { ISCSI_CONN_ERROR_PROTOCOL_ERR_LUN,
1607           "protocol lun error"
1608         },
1609         { ISCSI_CONN_ERROR_PROTOCOL_ERR_F_BIT_ZERO,
1610           "f bit zero error"
1611         },
1612         { ISCSI_CONN_ERROR_PROTOCOL_ERR_EXP_STAT_SN,
1613           "exp stat sn error"
1614         },
1615         { ISCSI_CONN_ERROR_PROTOCOL_ERR_DSL_NOT_ZERO,
1616           "dsl not zero error"
1617         },
1618         { ISCSI_CONN_ERROR_PROTOCOL_ERR_INVALID_DSL,
1619           "invalid dsl"
1620         },
1621         { ISCSI_CONN_ERROR_PROTOCOL_ERR_DATA_SEG_LEN_TOO_BIG,
1622           "data seg len too big"
1623         },
1624         { ISCSI_CONN_ERROR_PROTOCOL_ERR_OUTSTANDING_R2T_COUNT,
1625           "outstanding r2t count error"
1626         },
1627         { ISCSI_CONN_ERROR_SENSE_DATA_LENGTH,
1628           "sense datalen error"
1629         },
1630 };
1631
1632 static char *qedi_get_iscsi_error(enum iscsi_error_types err_code)
1633 {
1634         int i;
1635         char *msg = NULL;
1636
1637         for (i = 0; i < ARRAY_SIZE(qedi_iscsi_error); i++) {
1638                 if (qedi_iscsi_error[i].error_code == err_code) {
1639                         msg = qedi_iscsi_error[i].err_string;
1640                         break;
1641                 }
1642         }
1643         return msg;
1644 }
1645
1646 void qedi_process_iscsi_error(struct qedi_endpoint *ep,
1647                               struct iscsi_eqe_data *data)
1648 {
1649         struct qedi_conn *qedi_conn;
1650         struct qedi_ctx *qedi;
1651         char warn_notice[] = "iscsi_warning";
1652         char error_notice[] = "iscsi_error";
1653         char unknown_msg[] = "Unknown error";
1654         char *message;
1655         int need_recovery = 0;
1656         u32 err_mask = 0;
1657         char *msg;
1658
1659         if (!ep)
1660                 return;
1661
1662         qedi_conn = ep->conn;
1663         if (!qedi_conn)
1664                 return;
1665
1666         qedi = ep->qedi;
1667
1668         QEDI_ERR(&qedi->dbg_ctx, "async event iscsi error:0x%x\n",
1669                  data->error_code);
1670
1671         if (err_mask) {
1672                 need_recovery = 0;
1673                 message = warn_notice;
1674         } else {
1675                 need_recovery = 1;
1676                 message = error_notice;
1677         }
1678
1679         msg = qedi_get_iscsi_error(data->error_code);
1680         if (!msg) {
1681                 need_recovery = 0;
1682                 msg = unknown_msg;
1683         }
1684
1685         iscsi_conn_printk(KERN_ALERT,
1686                           qedi_conn->cls_conn->dd_data,
1687                           "qedi: %s - %s\n", message, msg);
1688
1689         if (need_recovery)
1690                 qedi_start_conn_recovery(qedi_conn->qedi, qedi_conn);
1691 }
1692
1693 void qedi_process_tcp_error(struct qedi_endpoint *ep,
1694                             struct iscsi_eqe_data *data)
1695 {
1696         struct qedi_conn *qedi_conn;
1697
1698         if (!ep)
1699                 return;
1700
1701         qedi_conn = ep->conn;
1702         if (!qedi_conn)
1703                 return;
1704
1705         QEDI_ERR(&ep->qedi->dbg_ctx, "async event TCP error:0x%x\n",
1706                  data->error_code);
1707
1708         qedi_start_conn_recovery(qedi_conn->qedi, qedi_conn);
1709 }