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