Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /*
0003  * QLogic iSCSI Offload Driver
0004  * Copyright (c) 2016 Cavium Inc.
0005  */
0006 
0007 #include <linux/blkdev.h>
0008 #include <linux/etherdevice.h>
0009 #include <linux/if_ether.h>
0010 #include <linux/if_vlan.h>
0011 #include <scsi/scsi_tcq.h>
0012 
0013 #include "qedi.h"
0014 #include "qedi_iscsi.h"
0015 #include "qedi_gbl.h"
0016 
0017 int qedi_recover_all_conns(struct qedi_ctx *qedi)
0018 {
0019     struct qedi_conn *qedi_conn;
0020     int i;
0021 
0022     for (i = 0; i < qedi->max_active_conns; i++) {
0023         qedi_conn = qedi_get_conn_from_id(qedi, i);
0024         if (!qedi_conn)
0025             continue;
0026 
0027         qedi_start_conn_recovery(qedi, qedi_conn);
0028     }
0029 
0030     return SUCCESS;
0031 }
0032 
0033 static int qedi_eh_host_reset(struct scsi_cmnd *cmd)
0034 {
0035     struct Scsi_Host *shost = cmd->device->host;
0036     struct qedi_ctx *qedi;
0037 
0038     qedi = iscsi_host_priv(shost);
0039 
0040     return qedi_recover_all_conns(qedi);
0041 }
0042 
0043 struct scsi_host_template qedi_host_template = {
0044     .module = THIS_MODULE,
0045     .name = "QLogic QEDI 25/40/100Gb iSCSI Initiator Driver",
0046     .proc_name = QEDI_MODULE_NAME,
0047     .queuecommand = iscsi_queuecommand,
0048     .eh_timed_out = iscsi_eh_cmd_timed_out,
0049     .eh_abort_handler = iscsi_eh_abort,
0050     .eh_device_reset_handler = iscsi_eh_device_reset,
0051     .eh_target_reset_handler = iscsi_eh_recover_target,
0052     .eh_host_reset_handler = qedi_eh_host_reset,
0053     .target_alloc = iscsi_target_alloc,
0054     .change_queue_depth = scsi_change_queue_depth,
0055     .can_queue = QEDI_MAX_ISCSI_TASK,
0056     .this_id = -1,
0057     .sg_tablesize = QEDI_ISCSI_MAX_BDS_PER_CMD,
0058     .max_sectors = 0xffff,
0059     .dma_boundary = QEDI_HW_DMA_BOUNDARY,
0060     .cmd_per_lun = 128,
0061     .shost_groups = qedi_shost_groups,
0062     .cmd_size = sizeof(struct iscsi_cmd),
0063 };
0064 
0065 static void qedi_conn_free_login_resources(struct qedi_ctx *qedi,
0066                        struct qedi_conn *qedi_conn)
0067 {
0068     if (qedi_conn->gen_pdu.resp_bd_tbl) {
0069         dma_free_coherent(&qedi->pdev->dev, QEDI_PAGE_SIZE,
0070                   qedi_conn->gen_pdu.resp_bd_tbl,
0071                   qedi_conn->gen_pdu.resp_bd_dma);
0072         qedi_conn->gen_pdu.resp_bd_tbl = NULL;
0073     }
0074 
0075     if (qedi_conn->gen_pdu.req_bd_tbl) {
0076         dma_free_coherent(&qedi->pdev->dev, QEDI_PAGE_SIZE,
0077                   qedi_conn->gen_pdu.req_bd_tbl,
0078                   qedi_conn->gen_pdu.req_bd_dma);
0079         qedi_conn->gen_pdu.req_bd_tbl = NULL;
0080     }
0081 
0082     if (qedi_conn->gen_pdu.resp_buf) {
0083         dma_free_coherent(&qedi->pdev->dev,
0084                   ISCSI_DEF_MAX_RECV_SEG_LEN,
0085                   qedi_conn->gen_pdu.resp_buf,
0086                   qedi_conn->gen_pdu.resp_dma_addr);
0087         qedi_conn->gen_pdu.resp_buf = NULL;
0088     }
0089 
0090     if (qedi_conn->gen_pdu.req_buf) {
0091         dma_free_coherent(&qedi->pdev->dev,
0092                   ISCSI_DEF_MAX_RECV_SEG_LEN,
0093                   qedi_conn->gen_pdu.req_buf,
0094                   qedi_conn->gen_pdu.req_dma_addr);
0095         qedi_conn->gen_pdu.req_buf = NULL;
0096     }
0097 }
0098 
0099 static int qedi_conn_alloc_login_resources(struct qedi_ctx *qedi,
0100                        struct qedi_conn *qedi_conn)
0101 {
0102     qedi_conn->gen_pdu.req_buf =
0103         dma_alloc_coherent(&qedi->pdev->dev,
0104                    ISCSI_DEF_MAX_RECV_SEG_LEN,
0105                    &qedi_conn->gen_pdu.req_dma_addr,
0106                    GFP_KERNEL);
0107     if (!qedi_conn->gen_pdu.req_buf)
0108         goto login_req_buf_failure;
0109 
0110     qedi_conn->gen_pdu.req_buf_size = 0;
0111     qedi_conn->gen_pdu.req_wr_ptr = qedi_conn->gen_pdu.req_buf;
0112 
0113     qedi_conn->gen_pdu.resp_buf =
0114         dma_alloc_coherent(&qedi->pdev->dev,
0115                    ISCSI_DEF_MAX_RECV_SEG_LEN,
0116                    &qedi_conn->gen_pdu.resp_dma_addr,
0117                    GFP_KERNEL);
0118     if (!qedi_conn->gen_pdu.resp_buf)
0119         goto login_resp_buf_failure;
0120 
0121     qedi_conn->gen_pdu.resp_buf_size = ISCSI_DEF_MAX_RECV_SEG_LEN;
0122     qedi_conn->gen_pdu.resp_wr_ptr = qedi_conn->gen_pdu.resp_buf;
0123 
0124     qedi_conn->gen_pdu.req_bd_tbl =
0125         dma_alloc_coherent(&qedi->pdev->dev, QEDI_PAGE_SIZE,
0126                    &qedi_conn->gen_pdu.req_bd_dma, GFP_KERNEL);
0127     if (!qedi_conn->gen_pdu.req_bd_tbl)
0128         goto login_req_bd_tbl_failure;
0129 
0130     qedi_conn->gen_pdu.resp_bd_tbl =
0131         dma_alloc_coherent(&qedi->pdev->dev, QEDI_PAGE_SIZE,
0132                    &qedi_conn->gen_pdu.resp_bd_dma,
0133                    GFP_KERNEL);
0134     if (!qedi_conn->gen_pdu.resp_bd_tbl)
0135         goto login_resp_bd_tbl_failure;
0136 
0137     QEDI_INFO(&qedi->dbg_ctx, QEDI_LOG_SESS,
0138           "Allocation successful, cid=0x%x\n",
0139           qedi_conn->iscsi_conn_id);
0140     return 0;
0141 
0142 login_resp_bd_tbl_failure:
0143     dma_free_coherent(&qedi->pdev->dev, QEDI_PAGE_SIZE,
0144               qedi_conn->gen_pdu.req_bd_tbl,
0145               qedi_conn->gen_pdu.req_bd_dma);
0146     qedi_conn->gen_pdu.req_bd_tbl = NULL;
0147 
0148 login_req_bd_tbl_failure:
0149     dma_free_coherent(&qedi->pdev->dev, ISCSI_DEF_MAX_RECV_SEG_LEN,
0150               qedi_conn->gen_pdu.resp_buf,
0151               qedi_conn->gen_pdu.resp_dma_addr);
0152     qedi_conn->gen_pdu.resp_buf = NULL;
0153 login_resp_buf_failure:
0154     dma_free_coherent(&qedi->pdev->dev, ISCSI_DEF_MAX_RECV_SEG_LEN,
0155               qedi_conn->gen_pdu.req_buf,
0156               qedi_conn->gen_pdu.req_dma_addr);
0157     qedi_conn->gen_pdu.req_buf = NULL;
0158 login_req_buf_failure:
0159     iscsi_conn_printk(KERN_ERR, qedi_conn->cls_conn->dd_data,
0160               "login resource alloc failed!!\n");
0161     return -ENOMEM;
0162 }
0163 
0164 static void qedi_destroy_cmd_pool(struct qedi_ctx *qedi,
0165                   struct iscsi_session *session)
0166 {
0167     int i;
0168 
0169     for (i = 0; i < session->cmds_max; i++) {
0170         struct iscsi_task *task = session->cmds[i];
0171         struct qedi_cmd *cmd = task->dd_data;
0172 
0173         if (cmd->io_tbl.sge_tbl)
0174             dma_free_coherent(&qedi->pdev->dev,
0175                       QEDI_ISCSI_MAX_BDS_PER_CMD *
0176                       sizeof(struct scsi_sge),
0177                       cmd->io_tbl.sge_tbl,
0178                       cmd->io_tbl.sge_tbl_dma);
0179 
0180         if (cmd->sense_buffer)
0181             dma_free_coherent(&qedi->pdev->dev,
0182                       SCSI_SENSE_BUFFERSIZE,
0183                       cmd->sense_buffer,
0184                       cmd->sense_buffer_dma);
0185     }
0186 }
0187 
0188 static int qedi_alloc_sget(struct qedi_ctx *qedi, struct iscsi_session *session,
0189                struct qedi_cmd *cmd)
0190 {
0191     struct qedi_io_bdt *io = &cmd->io_tbl;
0192     struct scsi_sge *sge;
0193 
0194     io->sge_tbl = dma_alloc_coherent(&qedi->pdev->dev,
0195                      QEDI_ISCSI_MAX_BDS_PER_CMD *
0196                      sizeof(*sge),
0197                      &io->sge_tbl_dma, GFP_KERNEL);
0198     if (!io->sge_tbl) {
0199         iscsi_session_printk(KERN_ERR, session,
0200                      "Could not allocate BD table.\n");
0201         return -ENOMEM;
0202     }
0203 
0204     io->sge_valid = 0;
0205     return 0;
0206 }
0207 
0208 static int qedi_setup_cmd_pool(struct qedi_ctx *qedi,
0209                    struct iscsi_session *session)
0210 {
0211     int i;
0212 
0213     for (i = 0; i < session->cmds_max; i++) {
0214         struct iscsi_task *task = session->cmds[i];
0215         struct qedi_cmd *cmd = task->dd_data;
0216 
0217         task->hdr = &cmd->hdr;
0218         task->hdr_max = sizeof(struct iscsi_hdr);
0219 
0220         if (qedi_alloc_sget(qedi, session, cmd))
0221             goto free_sgets;
0222 
0223         cmd->sense_buffer = dma_alloc_coherent(&qedi->pdev->dev,
0224                                SCSI_SENSE_BUFFERSIZE,
0225                                &cmd->sense_buffer_dma,
0226                                GFP_KERNEL);
0227         if (!cmd->sense_buffer)
0228             goto free_sgets;
0229     }
0230 
0231     return 0;
0232 
0233 free_sgets:
0234     qedi_destroy_cmd_pool(qedi, session);
0235     return -ENOMEM;
0236 }
0237 
0238 static struct iscsi_cls_session *
0239 qedi_session_create(struct iscsi_endpoint *ep, u16 cmds_max,
0240             u16 qdepth, uint32_t initial_cmdsn)
0241 {
0242     struct Scsi_Host *shost;
0243     struct iscsi_cls_session *cls_session;
0244     struct qedi_ctx *qedi;
0245     struct qedi_endpoint *qedi_ep;
0246 
0247     if (!ep)
0248         return NULL;
0249 
0250     qedi_ep = ep->dd_data;
0251     shost = qedi_ep->qedi->shost;
0252     qedi = iscsi_host_priv(shost);
0253 
0254     if (cmds_max > qedi->max_sqes)
0255         cmds_max = qedi->max_sqes;
0256     else if (cmds_max < QEDI_SQ_WQES_MIN)
0257         cmds_max = QEDI_SQ_WQES_MIN;
0258 
0259     cls_session = iscsi_session_setup(&qedi_iscsi_transport, shost,
0260                       cmds_max, 0, sizeof(struct qedi_cmd),
0261                       initial_cmdsn, ISCSI_MAX_TARGET);
0262     if (!cls_session) {
0263         QEDI_ERR(&qedi->dbg_ctx,
0264              "Failed to setup session for ep=%p\n", qedi_ep);
0265         return NULL;
0266     }
0267 
0268     if (qedi_setup_cmd_pool(qedi, cls_session->dd_data)) {
0269         QEDI_ERR(&qedi->dbg_ctx,
0270              "Failed to setup cmd pool for ep=%p\n", qedi_ep);
0271         goto session_teardown;
0272     }
0273 
0274     return cls_session;
0275 
0276 session_teardown:
0277     iscsi_session_teardown(cls_session);
0278     return NULL;
0279 }
0280 
0281 static void qedi_session_destroy(struct iscsi_cls_session *cls_session)
0282 {
0283     struct iscsi_session *session = cls_session->dd_data;
0284     struct Scsi_Host *shost = iscsi_session_to_shost(cls_session);
0285     struct qedi_ctx *qedi = iscsi_host_priv(shost);
0286 
0287     qedi_destroy_cmd_pool(qedi, session);
0288     iscsi_session_teardown(cls_session);
0289 }
0290 
0291 static struct iscsi_cls_conn *
0292 qedi_conn_create(struct iscsi_cls_session *cls_session, uint32_t cid)
0293 {
0294     struct Scsi_Host *shost = iscsi_session_to_shost(cls_session);
0295     struct qedi_ctx *qedi = iscsi_host_priv(shost);
0296     struct iscsi_cls_conn *cls_conn;
0297     struct qedi_conn *qedi_conn;
0298     struct iscsi_conn *conn;
0299 
0300     cls_conn = iscsi_conn_setup(cls_session, sizeof(*qedi_conn),
0301                     cid);
0302     if (!cls_conn) {
0303         QEDI_ERR(&qedi->dbg_ctx,
0304              "conn_new: iscsi conn setup failed, cid=0x%x, cls_sess=%p!\n",
0305              cid, cls_session);
0306         return NULL;
0307     }
0308 
0309     conn = cls_conn->dd_data;
0310     qedi_conn = conn->dd_data;
0311     qedi_conn->cls_conn = cls_conn;
0312     qedi_conn->qedi = qedi;
0313     qedi_conn->ep = NULL;
0314     qedi_conn->active_cmd_count = 0;
0315     INIT_LIST_HEAD(&qedi_conn->active_cmd_list);
0316     spin_lock_init(&qedi_conn->list_lock);
0317 
0318     if (qedi_conn_alloc_login_resources(qedi, qedi_conn)) {
0319         iscsi_conn_printk(KERN_ALERT, conn,
0320                   "conn_new: login resc alloc failed, cid=0x%x, cls_sess=%p!!\n",
0321                    cid, cls_session);
0322         goto free_conn;
0323     }
0324 
0325     return cls_conn;
0326 
0327 free_conn:
0328     iscsi_conn_teardown(cls_conn);
0329     return NULL;
0330 }
0331 
0332 void qedi_mark_device_missing(struct iscsi_cls_session *cls_session)
0333 {
0334     struct iscsi_session *session = cls_session->dd_data;
0335     struct qedi_conn *qedi_conn = session->leadconn->dd_data;
0336 
0337     spin_lock_bh(&session->frwd_lock);
0338     set_bit(QEDI_BLOCK_IO, &qedi_conn->qedi->flags);
0339     spin_unlock_bh(&session->frwd_lock);
0340 }
0341 
0342 void qedi_mark_device_available(struct iscsi_cls_session *cls_session)
0343 {
0344     struct iscsi_session *session = cls_session->dd_data;
0345     struct qedi_conn *qedi_conn = session->leadconn->dd_data;
0346 
0347     spin_lock_bh(&session->frwd_lock);
0348     clear_bit(QEDI_BLOCK_IO, &qedi_conn->qedi->flags);
0349     spin_unlock_bh(&session->frwd_lock);
0350 }
0351 
0352 static int qedi_bind_conn_to_iscsi_cid(struct qedi_ctx *qedi,
0353                        struct qedi_conn *qedi_conn)
0354 {
0355     u32 iscsi_cid = qedi_conn->iscsi_conn_id;
0356 
0357     if (qedi->cid_que.conn_cid_tbl[iscsi_cid]) {
0358         iscsi_conn_printk(KERN_ALERT, qedi_conn->cls_conn->dd_data,
0359                   "conn bind - entry #%d not free\n",
0360                   iscsi_cid);
0361         return -EBUSY;
0362     }
0363 
0364     qedi->cid_que.conn_cid_tbl[iscsi_cid] = qedi_conn;
0365     return 0;
0366 }
0367 
0368 struct qedi_conn *qedi_get_conn_from_id(struct qedi_ctx *qedi, u32 iscsi_cid)
0369 {
0370     if (!qedi->cid_que.conn_cid_tbl) {
0371         QEDI_ERR(&qedi->dbg_ctx, "missing conn<->cid table\n");
0372         return NULL;
0373 
0374     } else if (iscsi_cid >= qedi->max_active_conns) {
0375         QEDI_ERR(&qedi->dbg_ctx, "wrong cid #%d\n", iscsi_cid);
0376         return NULL;
0377     }
0378     return qedi->cid_que.conn_cid_tbl[iscsi_cid];
0379 }
0380 
0381 static int qedi_conn_bind(struct iscsi_cls_session *cls_session,
0382               struct iscsi_cls_conn *cls_conn,
0383               u64 transport_fd, int is_leading)
0384 {
0385     struct iscsi_conn *conn = cls_conn->dd_data;
0386     struct qedi_conn *qedi_conn = conn->dd_data;
0387     struct Scsi_Host *shost = iscsi_session_to_shost(cls_session);
0388     struct qedi_ctx *qedi = iscsi_host_priv(shost);
0389     struct qedi_endpoint *qedi_ep;
0390     struct iscsi_endpoint *ep;
0391     int rc = 0;
0392 
0393     ep = iscsi_lookup_endpoint(transport_fd);
0394     if (!ep)
0395         return -EINVAL;
0396 
0397     qedi_ep = ep->dd_data;
0398     if ((qedi_ep->state == EP_STATE_TCP_FIN_RCVD) ||
0399         (qedi_ep->state == EP_STATE_TCP_RST_RCVD)) {
0400         rc = -EINVAL;
0401         goto put_ep;
0402     }
0403 
0404     if (iscsi_conn_bind(cls_session, cls_conn, is_leading)) {
0405         rc = -EINVAL;
0406         goto put_ep;
0407     }
0408 
0409 
0410     qedi_ep->conn = qedi_conn;
0411     qedi_conn->ep = qedi_ep;
0412     qedi_conn->iscsi_ep = ep;
0413     qedi_conn->iscsi_conn_id = qedi_ep->iscsi_cid;
0414     qedi_conn->fw_cid = qedi_ep->fw_cid;
0415     qedi_conn->cmd_cleanup_req = 0;
0416     atomic_set(&qedi_conn->cmd_cleanup_cmpl, 0);
0417 
0418     if (qedi_bind_conn_to_iscsi_cid(qedi, qedi_conn)) {
0419         rc = -EINVAL;
0420         goto put_ep;
0421     }
0422 
0423 
0424     spin_lock_init(&qedi_conn->tmf_work_lock);
0425     INIT_LIST_HEAD(&qedi_conn->tmf_work_list);
0426     init_waitqueue_head(&qedi_conn->wait_queue);
0427 put_ep:
0428     iscsi_put_endpoint(ep);
0429     return rc;
0430 }
0431 
0432 static int qedi_iscsi_update_conn(struct qedi_ctx *qedi,
0433                   struct qedi_conn *qedi_conn)
0434 {
0435     struct qed_iscsi_params_update *conn_info;
0436     struct iscsi_cls_conn *cls_conn = qedi_conn->cls_conn;
0437     struct iscsi_conn *conn = cls_conn->dd_data;
0438     struct qedi_endpoint *qedi_ep;
0439     int rval;
0440 
0441     qedi_ep = qedi_conn->ep;
0442 
0443     conn_info = kzalloc(sizeof(*conn_info), GFP_KERNEL);
0444     if (!conn_info) {
0445         QEDI_ERR(&qedi->dbg_ctx, "memory alloc failed\n");
0446         return -ENOMEM;
0447     }
0448 
0449     conn_info->update_flag = 0;
0450 
0451     if (conn->hdrdgst_en)
0452         SET_FIELD(conn_info->update_flag,
0453               ISCSI_CONN_UPDATE_RAMROD_PARAMS_HD_EN, true);
0454     if (conn->datadgst_en)
0455         SET_FIELD(conn_info->update_flag,
0456               ISCSI_CONN_UPDATE_RAMROD_PARAMS_DD_EN, true);
0457     if (conn->session->initial_r2t_en)
0458         SET_FIELD(conn_info->update_flag,
0459               ISCSI_CONN_UPDATE_RAMROD_PARAMS_INITIAL_R2T,
0460               true);
0461     if (conn->session->imm_data_en)
0462         SET_FIELD(conn_info->update_flag,
0463               ISCSI_CONN_UPDATE_RAMROD_PARAMS_IMMEDIATE_DATA,
0464               true);
0465 
0466     conn_info->max_seq_size = conn->session->max_burst;
0467     conn_info->max_recv_pdu_length = conn->max_recv_dlength;
0468     conn_info->max_send_pdu_length = conn->max_xmit_dlength;
0469     conn_info->first_seq_length = conn->session->first_burst;
0470     conn_info->exp_stat_sn = conn->exp_statsn;
0471 
0472     rval = qedi_ops->update_conn(qedi->cdev, qedi_ep->handle,
0473                      conn_info);
0474     if (rval) {
0475         rval = -ENXIO;
0476         QEDI_ERR(&qedi->dbg_ctx, "Could not update connection\n");
0477     }
0478 
0479     kfree(conn_info);
0480     return rval;
0481 }
0482 
0483 static u16 qedi_calc_mss(u16 pmtu, u8 is_ipv6, u8 tcp_ts_en, u8 vlan_en)
0484 {
0485     u16 mss = 0;
0486     u16 hdrs = TCP_HDR_LEN;
0487 
0488     if (is_ipv6)
0489         hdrs += IPV6_HDR_LEN;
0490     else
0491         hdrs += IPV4_HDR_LEN;
0492 
0493     mss = pmtu - hdrs;
0494 
0495     if (!mss)
0496         mss = DEF_MSS;
0497 
0498     return mss;
0499 }
0500 
0501 static int qedi_iscsi_offload_conn(struct qedi_endpoint *qedi_ep)
0502 {
0503     struct qed_iscsi_params_offload *conn_info;
0504     struct qedi_ctx *qedi = qedi_ep->qedi;
0505     int rval;
0506     int i;
0507 
0508     conn_info = kzalloc(sizeof(*conn_info), GFP_KERNEL);
0509     if (!conn_info) {
0510         QEDI_ERR(&qedi->dbg_ctx,
0511              "Failed to allocate memory ep=%p\n", qedi_ep);
0512         return -ENOMEM;
0513     }
0514 
0515     ether_addr_copy(conn_info->src.mac, qedi_ep->src_mac);
0516     ether_addr_copy(conn_info->dst.mac, qedi_ep->dst_mac);
0517 
0518     conn_info->src.ip[0] = ntohl(qedi_ep->src_addr[0]);
0519     conn_info->dst.ip[0] = ntohl(qedi_ep->dst_addr[0]);
0520 
0521     if (qedi_ep->ip_type == TCP_IPV4) {
0522         conn_info->ip_version = 0;
0523         QEDI_INFO(&qedi->dbg_ctx, QEDI_LOG_CONN,
0524               "After ntohl: src_addr=%pI4, dst_addr=%pI4\n",
0525               qedi_ep->src_addr, qedi_ep->dst_addr);
0526     } else {
0527         for (i = 1; i < 4; i++) {
0528             conn_info->src.ip[i] = ntohl(qedi_ep->src_addr[i]);
0529             conn_info->dst.ip[i] = ntohl(qedi_ep->dst_addr[i]);
0530         }
0531 
0532         conn_info->ip_version = 1;
0533         QEDI_INFO(&qedi->dbg_ctx, QEDI_LOG_CONN,
0534               "After ntohl: src_addr=%pI6, dst_addr=%pI6\n",
0535               qedi_ep->src_addr, qedi_ep->dst_addr);
0536     }
0537 
0538     conn_info->src.port = qedi_ep->src_port;
0539     conn_info->dst.port = qedi_ep->dst_port;
0540 
0541     conn_info->layer_code = ISCSI_SLOW_PATH_LAYER_CODE;
0542     conn_info->sq_pbl_addr = qedi_ep->sq_pbl_dma;
0543     conn_info->vlan_id = qedi_ep->vlan_id;
0544 
0545     SET_FIELD(conn_info->tcp_flags, TCP_OFFLOAD_PARAMS_TS_EN, 1);
0546     SET_FIELD(conn_info->tcp_flags, TCP_OFFLOAD_PARAMS_DA_EN, 1);
0547     SET_FIELD(conn_info->tcp_flags, TCP_OFFLOAD_PARAMS_DA_CNT_EN, 1);
0548     SET_FIELD(conn_info->tcp_flags, TCP_OFFLOAD_PARAMS_KA_EN, 1);
0549 
0550     conn_info->default_cq = (qedi_ep->fw_cid % qedi->num_queues);
0551 
0552     conn_info->ka_max_probe_cnt = DEF_KA_MAX_PROBE_COUNT;
0553     conn_info->dup_ack_theshold = 3;
0554     conn_info->rcv_wnd = 65535;
0555 
0556     conn_info->ss_thresh = 65535;
0557     conn_info->srtt = 300;
0558     conn_info->rtt_var = 150;
0559     conn_info->flow_label = 0;
0560     conn_info->ka_timeout = DEF_KA_TIMEOUT;
0561     conn_info->ka_interval = DEF_KA_INTERVAL;
0562     conn_info->max_rt_time = DEF_MAX_RT_TIME;
0563     conn_info->ttl = DEF_TTL;
0564     conn_info->tos_or_tc = DEF_TOS;
0565     conn_info->remote_port = qedi_ep->dst_port;
0566     conn_info->local_port = qedi_ep->src_port;
0567 
0568     conn_info->mss = qedi_calc_mss(qedi_ep->pmtu,
0569                        (qedi_ep->ip_type == TCP_IPV6),
0570                        1, (qedi_ep->vlan_id != 0));
0571 
0572     conn_info->cwnd = DEF_MAX_CWND * conn_info->mss;
0573     conn_info->rcv_wnd_scale = 4;
0574     conn_info->da_timeout_value = 200;
0575     conn_info->ack_frequency = 2;
0576 
0577     QEDI_INFO(&qedi->dbg_ctx, QEDI_LOG_INFO,
0578           "Default cq index [%d], mss [%d]\n",
0579           conn_info->default_cq, conn_info->mss);
0580 
0581     /* Prepare the doorbell parameters */
0582     qedi_ep->db_data.agg_flags = 0;
0583     qedi_ep->db_data.params = 0;
0584     SET_FIELD(qedi_ep->db_data.params, ISCSI_DB_DATA_DEST, DB_DEST_XCM);
0585     SET_FIELD(qedi_ep->db_data.params, ISCSI_DB_DATA_AGG_CMD,
0586           DB_AGG_CMD_MAX);
0587     SET_FIELD(qedi_ep->db_data.params, ISCSI_DB_DATA_AGG_VAL_SEL,
0588           DQ_XCM_ISCSI_SQ_PROD_CMD);
0589     SET_FIELD(qedi_ep->db_data.params, ISCSI_DB_DATA_BYPASS_EN, 1);
0590 
0591     /* Register doorbell with doorbell recovery mechanism */
0592     rval = qedi_ops->common->db_recovery_add(qedi->cdev,
0593                          qedi_ep->p_doorbell,
0594                          &qedi_ep->db_data,
0595                          DB_REC_WIDTH_32B,
0596                          DB_REC_KERNEL);
0597     if (rval) {
0598         kfree(conn_info);
0599         return rval;
0600     }
0601 
0602     rval = qedi_ops->offload_conn(qedi->cdev, qedi_ep->handle, conn_info);
0603     if (rval) {
0604         /* delete doorbell from doorbell recovery mechanism */
0605         rval = qedi_ops->common->db_recovery_del(qedi->cdev,
0606                              qedi_ep->p_doorbell,
0607                              &qedi_ep->db_data);
0608 
0609         QEDI_ERR(&qedi->dbg_ctx, "offload_conn returned %d, ep=%p\n",
0610              rval, qedi_ep);
0611     }
0612 
0613     kfree(conn_info);
0614     return rval;
0615 }
0616 
0617 static int qedi_conn_start(struct iscsi_cls_conn *cls_conn)
0618 {
0619     struct iscsi_conn *conn = cls_conn->dd_data;
0620     struct qedi_conn *qedi_conn = conn->dd_data;
0621     struct qedi_ctx *qedi;
0622     int rval;
0623 
0624     qedi = qedi_conn->qedi;
0625 
0626     rval = qedi_iscsi_update_conn(qedi, qedi_conn);
0627     if (rval) {
0628         iscsi_conn_printk(KERN_ALERT, conn,
0629                   "conn_start: FW offload conn failed.\n");
0630         rval = -EINVAL;
0631         goto start_err;
0632     }
0633 
0634     spin_lock(&qedi_conn->tmf_work_lock);
0635     qedi_conn->fw_cleanup_works = 0;
0636     qedi_conn->ep_disconnect_starting = false;
0637     spin_unlock(&qedi_conn->tmf_work_lock);
0638 
0639     qedi_conn->abrt_conn = 0;
0640 
0641     rval = iscsi_conn_start(cls_conn);
0642     if (rval) {
0643         iscsi_conn_printk(KERN_ALERT, conn,
0644                   "iscsi_conn_start: FW offload conn failed!!\n");
0645     }
0646 
0647 start_err:
0648     return rval;
0649 }
0650 
0651 static void qedi_conn_destroy(struct iscsi_cls_conn *cls_conn)
0652 {
0653     struct iscsi_conn *conn = cls_conn->dd_data;
0654     struct qedi_conn *qedi_conn = conn->dd_data;
0655     struct Scsi_Host *shost;
0656     struct qedi_ctx *qedi;
0657 
0658     shost = iscsi_session_to_shost(iscsi_conn_to_session(cls_conn));
0659     qedi = iscsi_host_priv(shost);
0660 
0661     qedi_conn_free_login_resources(qedi, qedi_conn);
0662     iscsi_conn_teardown(cls_conn);
0663 }
0664 
0665 static int qedi_ep_get_param(struct iscsi_endpoint *ep,
0666                  enum iscsi_param param, char *buf)
0667 {
0668     struct qedi_endpoint *qedi_ep = ep->dd_data;
0669     int len;
0670 
0671     if (!qedi_ep)
0672         return -ENOTCONN;
0673 
0674     switch (param) {
0675     case ISCSI_PARAM_CONN_PORT:
0676         len = sprintf(buf, "%hu\n", qedi_ep->dst_port);
0677         break;
0678     case ISCSI_PARAM_CONN_ADDRESS:
0679         if (qedi_ep->ip_type == TCP_IPV4)
0680             len = sprintf(buf, "%pI4\n", qedi_ep->dst_addr);
0681         else
0682             len = sprintf(buf, "%pI6\n", qedi_ep->dst_addr);
0683         break;
0684     default:
0685         return -ENOTCONN;
0686     }
0687 
0688     return len;
0689 }
0690 
0691 static int qedi_host_get_param(struct Scsi_Host *shost,
0692                    enum iscsi_host_param param, char *buf)
0693 {
0694     struct qedi_ctx *qedi;
0695     int len;
0696 
0697     qedi = iscsi_host_priv(shost);
0698 
0699     switch (param) {
0700     case ISCSI_HOST_PARAM_HWADDRESS:
0701         len = sysfs_format_mac(buf, qedi->mac, 6);
0702         break;
0703     case ISCSI_HOST_PARAM_NETDEV_NAME:
0704         len = sprintf(buf, "host%d\n", shost->host_no);
0705         break;
0706     case ISCSI_HOST_PARAM_IPADDRESS:
0707         if (qedi->ip_type == TCP_IPV4)
0708             len = sprintf(buf, "%pI4\n", qedi->src_ip);
0709         else
0710             len = sprintf(buf, "%pI6\n", qedi->src_ip);
0711         break;
0712     default:
0713         return iscsi_host_get_param(shost, param, buf);
0714     }
0715 
0716     return len;
0717 }
0718 
0719 static void qedi_conn_get_stats(struct iscsi_cls_conn *cls_conn,
0720                 struct iscsi_stats *stats)
0721 {
0722     struct iscsi_conn *conn = cls_conn->dd_data;
0723     struct qed_iscsi_stats iscsi_stats;
0724     struct Scsi_Host *shost;
0725     struct qedi_ctx *qedi;
0726 
0727     shost = iscsi_session_to_shost(iscsi_conn_to_session(cls_conn));
0728     qedi = iscsi_host_priv(shost);
0729     qedi_ops->get_stats(qedi->cdev, &iscsi_stats);
0730 
0731     conn->txdata_octets = iscsi_stats.iscsi_tx_bytes_cnt;
0732     conn->rxdata_octets = iscsi_stats.iscsi_rx_bytes_cnt;
0733     conn->dataout_pdus_cnt = (uint32_t)iscsi_stats.iscsi_tx_data_pdu_cnt;
0734     conn->datain_pdus_cnt = (uint32_t)iscsi_stats.iscsi_rx_data_pdu_cnt;
0735     conn->r2t_pdus_cnt = (uint32_t)iscsi_stats.iscsi_rx_r2t_pdu_cnt;
0736 
0737     stats->txdata_octets = conn->txdata_octets;
0738     stats->rxdata_octets = conn->rxdata_octets;
0739     stats->scsicmd_pdus = conn->scsicmd_pdus_cnt;
0740     stats->dataout_pdus = conn->dataout_pdus_cnt;
0741     stats->scsirsp_pdus = conn->scsirsp_pdus_cnt;
0742     stats->datain_pdus = conn->datain_pdus_cnt;
0743     stats->r2t_pdus = conn->r2t_pdus_cnt;
0744     stats->tmfcmd_pdus = conn->tmfcmd_pdus_cnt;
0745     stats->tmfrsp_pdus = conn->tmfrsp_pdus_cnt;
0746     stats->digest_err = 0;
0747     stats->timeout_err = 0;
0748     strcpy(stats->custom[0].desc, "eh_abort_cnt");
0749     stats->custom[0].value = conn->eh_abort_cnt;
0750     stats->custom_length = 1;
0751 }
0752 
0753 static void qedi_iscsi_prep_generic_pdu_bd(struct qedi_conn *qedi_conn)
0754 {
0755     struct scsi_sge *bd_tbl;
0756 
0757     bd_tbl = (struct scsi_sge *)qedi_conn->gen_pdu.req_bd_tbl;
0758 
0759     bd_tbl->sge_addr.hi =
0760         (u32)((u64)qedi_conn->gen_pdu.req_dma_addr >> 32);
0761     bd_tbl->sge_addr.lo = (u32)qedi_conn->gen_pdu.req_dma_addr;
0762     bd_tbl->sge_len = qedi_conn->gen_pdu.req_wr_ptr -
0763                 qedi_conn->gen_pdu.req_buf;
0764     bd_tbl = (struct scsi_sge  *)qedi_conn->gen_pdu.resp_bd_tbl;
0765     bd_tbl->sge_addr.hi =
0766             (u32)((u64)qedi_conn->gen_pdu.resp_dma_addr >> 32);
0767     bd_tbl->sge_addr.lo = (u32)qedi_conn->gen_pdu.resp_dma_addr;
0768     bd_tbl->sge_len = ISCSI_DEF_MAX_RECV_SEG_LEN;
0769 }
0770 
0771 static int qedi_iscsi_send_generic_request(struct iscsi_task *task)
0772 {
0773     struct qedi_cmd *cmd = task->dd_data;
0774     struct qedi_conn *qedi_conn = cmd->conn;
0775     char *buf;
0776     int data_len;
0777     int rc = 0;
0778 
0779     qedi_iscsi_prep_generic_pdu_bd(qedi_conn);
0780     switch (task->hdr->opcode & ISCSI_OPCODE_MASK) {
0781     case ISCSI_OP_LOGIN:
0782         qedi_send_iscsi_login(qedi_conn, task);
0783         break;
0784     case ISCSI_OP_NOOP_OUT:
0785         data_len = qedi_conn->gen_pdu.req_buf_size;
0786         buf = qedi_conn->gen_pdu.req_buf;
0787         if (data_len)
0788             rc = qedi_send_iscsi_nopout(qedi_conn, task,
0789                             buf, data_len, 1);
0790         else
0791             rc = qedi_send_iscsi_nopout(qedi_conn, task,
0792                             NULL, 0, 1);
0793         break;
0794     case ISCSI_OP_LOGOUT:
0795         rc = qedi_send_iscsi_logout(qedi_conn, task);
0796         break;
0797     case ISCSI_OP_SCSI_TMFUNC:
0798         rc = qedi_send_iscsi_tmf(qedi_conn, task);
0799         break;
0800     case ISCSI_OP_TEXT:
0801         rc = qedi_send_iscsi_text(qedi_conn, task);
0802         break;
0803     default:
0804         iscsi_conn_printk(KERN_ALERT, qedi_conn->cls_conn->dd_data,
0805                   "unsupported op 0x%x\n", task->hdr->opcode);
0806     }
0807 
0808     return rc;
0809 }
0810 
0811 static int qedi_mtask_xmit(struct iscsi_conn *conn, struct iscsi_task *task)
0812 {
0813     struct qedi_conn *qedi_conn = conn->dd_data;
0814     struct qedi_cmd *cmd = task->dd_data;
0815 
0816     memset(qedi_conn->gen_pdu.req_buf, 0, ISCSI_DEF_MAX_RECV_SEG_LEN);
0817 
0818     qedi_conn->gen_pdu.req_buf_size = task->data_count;
0819 
0820     if (task->data_count) {
0821         memcpy(qedi_conn->gen_pdu.req_buf, task->data,
0822                task->data_count);
0823         qedi_conn->gen_pdu.req_wr_ptr =
0824             qedi_conn->gen_pdu.req_buf + task->data_count;
0825     }
0826 
0827     cmd->conn = conn->dd_data;
0828     return qedi_iscsi_send_generic_request(task);
0829 }
0830 
0831 static int qedi_task_xmit(struct iscsi_task *task)
0832 {
0833     struct iscsi_conn *conn = task->conn;
0834     struct qedi_conn *qedi_conn = conn->dd_data;
0835     struct qedi_cmd *cmd = task->dd_data;
0836     struct scsi_cmnd *sc = task->sc;
0837 
0838     /* Clear now so in cleanup_task we know it didn't make it */
0839     cmd->scsi_cmd = NULL;
0840     cmd->task_id = U16_MAX;
0841 
0842     if (test_bit(QEDI_IN_SHUTDOWN, &qedi_conn->qedi->flags))
0843         return -ENODEV;
0844 
0845     if (test_bit(QEDI_BLOCK_IO, &qedi_conn->qedi->flags))
0846         return -EACCES;
0847 
0848     cmd->state = 0;
0849     cmd->task = NULL;
0850     cmd->use_slowpath = false;
0851     cmd->conn = qedi_conn;
0852     cmd->task = task;
0853     cmd->io_cmd_in_list = false;
0854     INIT_LIST_HEAD(&cmd->io_cmd);
0855 
0856     if (!sc)
0857         return qedi_mtask_xmit(conn, task);
0858 
0859     cmd->scsi_cmd = sc;
0860     return qedi_iscsi_send_ioreq(task);
0861 }
0862 
0863 static void qedi_offload_work(struct work_struct *work)
0864 {
0865     struct qedi_endpoint *qedi_ep =
0866         container_of(work, struct qedi_endpoint, offload_work);
0867     struct qedi_ctx *qedi;
0868     int wait_delay = 5 * HZ;
0869     int ret;
0870 
0871     qedi = qedi_ep->qedi;
0872 
0873     ret = qedi_iscsi_offload_conn(qedi_ep);
0874     if (ret) {
0875         QEDI_ERR(&qedi->dbg_ctx,
0876              "offload error: iscsi_cid=%u, qedi_ep=%p, ret=%d\n",
0877              qedi_ep->iscsi_cid, qedi_ep, ret);
0878         qedi_ep->state = EP_STATE_OFLDCONN_FAILED;
0879         return;
0880     }
0881 
0882     ret = wait_event_interruptible_timeout(qedi_ep->tcp_ofld_wait,
0883                            (qedi_ep->state ==
0884                            EP_STATE_OFLDCONN_COMPL),
0885                            wait_delay);
0886     if (ret <= 0 || qedi_ep->state != EP_STATE_OFLDCONN_COMPL) {
0887         qedi_ep->state = EP_STATE_OFLDCONN_FAILED;
0888         QEDI_ERR(&qedi->dbg_ctx,
0889              "Offload conn TIMEOUT iscsi_cid=%u, qedi_ep=%p\n",
0890              qedi_ep->iscsi_cid, qedi_ep);
0891     }
0892 }
0893 
0894 static struct iscsi_endpoint *
0895 qedi_ep_connect(struct Scsi_Host *shost, struct sockaddr *dst_addr,
0896         int non_blocking)
0897 {
0898     struct qedi_ctx *qedi;
0899     struct iscsi_endpoint *ep;
0900     struct qedi_endpoint *qedi_ep;
0901     struct sockaddr_in *addr;
0902     struct sockaddr_in6 *addr6;
0903     struct iscsi_path path_req;
0904     u32 msg_type = ISCSI_KEVENT_IF_DOWN;
0905     u32 iscsi_cid = QEDI_CID_RESERVED;
0906     u16 len = 0;
0907     char *buf = NULL;
0908     int ret, tmp;
0909 
0910     if (!shost) {
0911         ret = -ENXIO;
0912         QEDI_ERR(NULL, "shost is NULL\n");
0913         return ERR_PTR(ret);
0914     }
0915 
0916     if (qedi_do_not_recover) {
0917         ret = -ENOMEM;
0918         return ERR_PTR(ret);
0919     }
0920 
0921     qedi = iscsi_host_priv(shost);
0922 
0923     if (test_bit(QEDI_IN_OFFLINE, &qedi->flags) ||
0924         test_bit(QEDI_IN_RECOVERY, &qedi->flags)) {
0925         ret = -ENOMEM;
0926         return ERR_PTR(ret);
0927     }
0928 
0929     if (atomic_read(&qedi->link_state) != QEDI_LINK_UP) {
0930         QEDI_WARN(&qedi->dbg_ctx, "qedi link down\n");
0931         return ERR_PTR(-ENXIO);
0932     }
0933 
0934     ep = iscsi_create_endpoint(sizeof(struct qedi_endpoint));
0935     if (!ep) {
0936         QEDI_ERR(&qedi->dbg_ctx, "endpoint create fail\n");
0937         ret = -ENOMEM;
0938         return ERR_PTR(ret);
0939     }
0940     qedi_ep = ep->dd_data;
0941     memset(qedi_ep, 0, sizeof(struct qedi_endpoint));
0942     INIT_WORK(&qedi_ep->offload_work, qedi_offload_work);
0943     qedi_ep->state = EP_STATE_IDLE;
0944     qedi_ep->iscsi_cid = (u32)-1;
0945     qedi_ep->qedi = qedi;
0946 
0947     if (dst_addr->sa_family == AF_INET) {
0948         addr = (struct sockaddr_in *)dst_addr;
0949         memcpy(qedi_ep->dst_addr, &addr->sin_addr.s_addr,
0950                sizeof(struct in_addr));
0951         qedi_ep->dst_port = ntohs(addr->sin_port);
0952         qedi_ep->ip_type = TCP_IPV4;
0953         QEDI_INFO(&qedi->dbg_ctx, QEDI_LOG_CONN,
0954               "dst_addr=%pI4, dst_port=%u\n",
0955               qedi_ep->dst_addr, qedi_ep->dst_port);
0956     } else if (dst_addr->sa_family == AF_INET6) {
0957         addr6 = (struct sockaddr_in6 *)dst_addr;
0958         memcpy(qedi_ep->dst_addr, &addr6->sin6_addr,
0959                sizeof(struct in6_addr));
0960         qedi_ep->dst_port = ntohs(addr6->sin6_port);
0961         qedi_ep->ip_type = TCP_IPV6;
0962         QEDI_INFO(&qedi->dbg_ctx, QEDI_LOG_CONN,
0963               "dst_addr=%pI6, dst_port=%u\n",
0964               qedi_ep->dst_addr, qedi_ep->dst_port);
0965     } else {
0966         QEDI_ERR(&qedi->dbg_ctx, "Invalid endpoint\n");
0967     }
0968 
0969     ret = qedi_alloc_sq(qedi, qedi_ep);
0970     if (ret)
0971         goto ep_conn_exit;
0972 
0973     ret = qedi_ops->acquire_conn(qedi->cdev, &qedi_ep->handle,
0974                      &qedi_ep->fw_cid, &qedi_ep->p_doorbell);
0975 
0976     if (ret) {
0977         QEDI_ERR(&qedi->dbg_ctx, "Could not acquire connection\n");
0978         ret = -ENXIO;
0979         goto ep_free_sq;
0980     }
0981 
0982     iscsi_cid = qedi_ep->handle;
0983     qedi_ep->iscsi_cid = iscsi_cid;
0984 
0985     init_waitqueue_head(&qedi_ep->ofld_wait);
0986     init_waitqueue_head(&qedi_ep->tcp_ofld_wait);
0987     qedi_ep->state = EP_STATE_OFLDCONN_START;
0988     qedi->ep_tbl[iscsi_cid] = qedi_ep;
0989 
0990     buf = (char *)&path_req;
0991     len = sizeof(path_req);
0992     memset(&path_req, 0, len);
0993 
0994     msg_type = ISCSI_KEVENT_PATH_REQ;
0995     path_req.handle = (u64)qedi_ep->iscsi_cid;
0996     path_req.pmtu = qedi->ll2_mtu;
0997     qedi_ep->pmtu = qedi->ll2_mtu;
0998     if (qedi_ep->ip_type == TCP_IPV4) {
0999         memcpy(&path_req.dst.v4_addr, &qedi_ep->dst_addr,
1000                sizeof(struct in_addr));
1001         path_req.ip_addr_len = 4;
1002     } else {
1003         memcpy(&path_req.dst.v6_addr, &qedi_ep->dst_addr,
1004                sizeof(struct in6_addr));
1005         path_req.ip_addr_len = 16;
1006     }
1007 
1008     ret = iscsi_offload_mesg(shost, &qedi_iscsi_transport, msg_type, buf,
1009                  len);
1010     if (ret) {
1011         QEDI_ERR(&qedi->dbg_ctx,
1012              "iscsi_offload_mesg() failed for cid=0x%x ret=%d\n",
1013              iscsi_cid, ret);
1014         goto ep_rel_conn;
1015     }
1016 
1017     atomic_inc(&qedi->num_offloads);
1018     return ep;
1019 
1020 ep_rel_conn:
1021     qedi->ep_tbl[iscsi_cid] = NULL;
1022     tmp = qedi_ops->release_conn(qedi->cdev, qedi_ep->handle);
1023     if (tmp)
1024         QEDI_WARN(&qedi->dbg_ctx, "release_conn returned %d\n",
1025               tmp);
1026 ep_free_sq:
1027     qedi_free_sq(qedi, qedi_ep);
1028 ep_conn_exit:
1029     iscsi_destroy_endpoint(ep);
1030     return ERR_PTR(ret);
1031 }
1032 
1033 static int qedi_ep_poll(struct iscsi_endpoint *ep, int timeout_ms)
1034 {
1035     struct qedi_endpoint *qedi_ep;
1036     int ret = 0;
1037 
1038     if (qedi_do_not_recover)
1039         return 1;
1040 
1041     qedi_ep = ep->dd_data;
1042     if (qedi_ep->state == EP_STATE_IDLE ||
1043         qedi_ep->state == EP_STATE_OFLDCONN_NONE ||
1044         qedi_ep->state == EP_STATE_OFLDCONN_FAILED)
1045         return -1;
1046 
1047     if (qedi_ep->state == EP_STATE_OFLDCONN_COMPL)
1048         ret = 1;
1049 
1050     ret = wait_event_interruptible_timeout(qedi_ep->ofld_wait,
1051                            QEDI_OFLD_WAIT_STATE(qedi_ep),
1052                            msecs_to_jiffies(timeout_ms));
1053 
1054     if (qedi_ep->state == EP_STATE_OFLDCONN_FAILED)
1055         ret = -1;
1056 
1057     if (ret > 0)
1058         return 1;
1059     else if (!ret)
1060         return 0;
1061     else
1062         return ret;
1063 }
1064 
1065 static void qedi_cleanup_active_cmd_list(struct qedi_conn *qedi_conn)
1066 {
1067     struct qedi_cmd *cmd, *cmd_tmp;
1068 
1069     spin_lock(&qedi_conn->list_lock);
1070     list_for_each_entry_safe(cmd, cmd_tmp, &qedi_conn->active_cmd_list,
1071                  io_cmd) {
1072         list_del_init(&cmd->io_cmd);
1073         qedi_conn->active_cmd_count--;
1074     }
1075     spin_unlock(&qedi_conn->list_lock);
1076 }
1077 
1078 static void qedi_ep_disconnect(struct iscsi_endpoint *ep)
1079 {
1080     struct qedi_endpoint *qedi_ep;
1081     struct qedi_conn *qedi_conn = NULL;
1082     struct qedi_ctx *qedi;
1083     int ret = 0;
1084     int wait_delay;
1085     int abrt_conn = 0;
1086 
1087     wait_delay = 60 * HZ + DEF_MAX_RT_TIME;
1088     qedi_ep = ep->dd_data;
1089     qedi = qedi_ep->qedi;
1090 
1091     flush_work(&qedi_ep->offload_work);
1092 
1093     if (qedi_ep->state == EP_STATE_OFLDCONN_START)
1094         goto ep_exit_recover;
1095 
1096     if (qedi_ep->conn) {
1097         qedi_conn = qedi_ep->conn;
1098         abrt_conn = qedi_conn->abrt_conn;
1099 
1100         QEDI_INFO(&qedi->dbg_ctx, QEDI_LOG_INFO,
1101               "cid=0x%x qedi_ep=%p waiting for %d tmfs\n",
1102               qedi_ep->iscsi_cid, qedi_ep,
1103               qedi_conn->fw_cleanup_works);
1104 
1105         spin_lock(&qedi_conn->tmf_work_lock);
1106         qedi_conn->ep_disconnect_starting = true;
1107         while (qedi_conn->fw_cleanup_works > 0) {
1108             spin_unlock(&qedi_conn->tmf_work_lock);
1109             msleep(1000);
1110             spin_lock(&qedi_conn->tmf_work_lock);
1111         }
1112         spin_unlock(&qedi_conn->tmf_work_lock);
1113 
1114         if (test_bit(QEDI_IN_RECOVERY, &qedi->flags)) {
1115             if (qedi_do_not_recover) {
1116                 QEDI_INFO(&qedi->dbg_ctx, QEDI_LOG_INFO,
1117                       "Do not recover cid=0x%x\n",
1118                       qedi_ep->iscsi_cid);
1119                 goto ep_exit_recover;
1120             }
1121             QEDI_INFO(&qedi->dbg_ctx, QEDI_LOG_INFO,
1122                   "Reset recovery cid=0x%x, qedi_ep=%p, state=0x%x\n",
1123                   qedi_ep->iscsi_cid, qedi_ep, qedi_ep->state);
1124             qedi_cleanup_active_cmd_list(qedi_conn);
1125             goto ep_release_conn;
1126         }
1127     }
1128 
1129     if (qedi_do_not_recover)
1130         goto ep_exit_recover;
1131 
1132     switch (qedi_ep->state) {
1133     case EP_STATE_OFLDCONN_START:
1134     case EP_STATE_OFLDCONN_NONE:
1135         goto ep_release_conn;
1136     case EP_STATE_OFLDCONN_FAILED:
1137             break;
1138     case EP_STATE_OFLDCONN_COMPL:
1139         if (unlikely(!qedi_conn))
1140             break;
1141 
1142         QEDI_INFO(&qedi->dbg_ctx, QEDI_LOG_INFO,
1143               "Active cmd count=%d, abrt_conn=%d, ep state=0x%x, cid=0x%x, qedi_conn=%p\n",
1144               qedi_conn->active_cmd_count, abrt_conn,
1145               qedi_ep->state,
1146               qedi_ep->iscsi_cid,
1147               qedi_ep->conn
1148               );
1149 
1150         if (!qedi_conn->active_cmd_count)
1151             abrt_conn = 0;
1152         else
1153             abrt_conn = 1;
1154 
1155         if (abrt_conn)
1156             qedi_clearsq(qedi, qedi_conn, NULL);
1157         break;
1158     default:
1159         break;
1160     }
1161 
1162     if (!abrt_conn)
1163         wait_delay += qedi->pf_params.iscsi_pf_params.two_msl_timer;
1164 
1165     qedi_ep->state = EP_STATE_DISCONN_START;
1166 
1167     if (test_bit(QEDI_IN_SHUTDOWN, &qedi->flags) ||
1168         test_bit(QEDI_IN_RECOVERY, &qedi->flags))
1169         goto ep_release_conn;
1170 
1171     /* Delete doorbell from doorbell recovery mechanism */
1172     ret = qedi_ops->common->db_recovery_del(qedi->cdev,
1173                            qedi_ep->p_doorbell,
1174                            &qedi_ep->db_data);
1175 
1176     ret = qedi_ops->destroy_conn(qedi->cdev, qedi_ep->handle, abrt_conn);
1177     if (ret) {
1178         QEDI_WARN(&qedi->dbg_ctx,
1179               "destroy_conn failed returned %d\n", ret);
1180     } else {
1181         ret = wait_event_interruptible_timeout(
1182                     qedi_ep->tcp_ofld_wait,
1183                     (qedi_ep->state !=
1184                      EP_STATE_DISCONN_START),
1185                     wait_delay);
1186         if ((ret <= 0) || (qedi_ep->state == EP_STATE_DISCONN_START)) {
1187             QEDI_WARN(&qedi->dbg_ctx,
1188                   "Destroy conn timedout or interrupted, ret=%d, delay=%d, cid=0x%x\n",
1189                   ret, wait_delay, qedi_ep->iscsi_cid);
1190         }
1191     }
1192 
1193 ep_release_conn:
1194     ret = qedi_ops->release_conn(qedi->cdev, qedi_ep->handle);
1195     if (ret)
1196         QEDI_WARN(&qedi->dbg_ctx,
1197               "release_conn returned %d, cid=0x%x\n",
1198               ret, qedi_ep->iscsi_cid);
1199 ep_exit_recover:
1200     qedi_ep->state = EP_STATE_IDLE;
1201     qedi->ep_tbl[qedi_ep->iscsi_cid] = NULL;
1202     qedi->cid_que.conn_cid_tbl[qedi_ep->iscsi_cid] = NULL;
1203     qedi_free_id(&qedi->lcl_port_tbl, qedi_ep->src_port);
1204     qedi_free_sq(qedi, qedi_ep);
1205 
1206     if (qedi_conn)
1207         qedi_conn->ep = NULL;
1208 
1209     qedi_ep->conn = NULL;
1210     qedi_ep->qedi = NULL;
1211     atomic_dec(&qedi->num_offloads);
1212 
1213     iscsi_destroy_endpoint(ep);
1214 }
1215 
1216 static int qedi_data_avail(struct qedi_ctx *qedi, u16 vlanid)
1217 {
1218     struct qed_dev *cdev = qedi->cdev;
1219     struct qedi_uio_dev *udev;
1220     struct qedi_uio_ctrl *uctrl;
1221     struct sk_buff *skb;
1222     u32 len;
1223     int rc = 0;
1224 
1225     udev = qedi->udev;
1226     if (!udev) {
1227         QEDI_ERR(&qedi->dbg_ctx, "udev is NULL.\n");
1228         return -EINVAL;
1229     }
1230 
1231     uctrl = (struct qedi_uio_ctrl *)udev->uctrl;
1232     if (!uctrl) {
1233         QEDI_ERR(&qedi->dbg_ctx, "uctlr is NULL.\n");
1234         return -EINVAL;
1235     }
1236 
1237     len = uctrl->host_tx_pkt_len;
1238     if (!len) {
1239         QEDI_ERR(&qedi->dbg_ctx, "Invalid len %u\n", len);
1240         return -EINVAL;
1241     }
1242 
1243     skb = alloc_skb(len, GFP_ATOMIC);
1244     if (!skb) {
1245         QEDI_ERR(&qedi->dbg_ctx, "alloc_skb failed\n");
1246         return -EINVAL;
1247     }
1248 
1249     skb_put(skb, len);
1250     memcpy(skb->data, udev->tx_pkt, len);
1251     skb->ip_summed = CHECKSUM_NONE;
1252 
1253     if (vlanid)
1254         __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), vlanid);
1255 
1256     rc = qedi_ops->ll2->start_xmit(cdev, skb, 0);
1257     if (rc) {
1258         QEDI_ERR(&qedi->dbg_ctx, "ll2 start_xmit returned %d\n",
1259              rc);
1260         kfree_skb(skb);
1261     }
1262 
1263     uctrl->host_tx_pkt_len = 0;
1264     uctrl->hw_tx_cons++;
1265 
1266     return rc;
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     queue_work(qedi->offload_thread, &qedi_ep->offload_work);
1385 
1386     ret = 0;
1387 
1388 set_path_exit:
1389     return ret;
1390 }
1391 
1392 static umode_t qedi_attr_is_visible(int param_type, int param)
1393 {
1394     switch (param_type) {
1395     case ISCSI_HOST_PARAM:
1396         switch (param) {
1397         case ISCSI_HOST_PARAM_NETDEV_NAME:
1398         case ISCSI_HOST_PARAM_HWADDRESS:
1399         case ISCSI_HOST_PARAM_IPADDRESS:
1400             return 0444;
1401         default:
1402             return 0;
1403         }
1404     case ISCSI_PARAM:
1405         switch (param) {
1406         case ISCSI_PARAM_MAX_RECV_DLENGTH:
1407         case ISCSI_PARAM_MAX_XMIT_DLENGTH:
1408         case ISCSI_PARAM_HDRDGST_EN:
1409         case ISCSI_PARAM_DATADGST_EN:
1410         case ISCSI_PARAM_CONN_ADDRESS:
1411         case ISCSI_PARAM_CONN_PORT:
1412         case ISCSI_PARAM_EXP_STATSN:
1413         case ISCSI_PARAM_PERSISTENT_ADDRESS:
1414         case ISCSI_PARAM_PERSISTENT_PORT:
1415         case ISCSI_PARAM_PING_TMO:
1416         case ISCSI_PARAM_RECV_TMO:
1417         case ISCSI_PARAM_INITIAL_R2T_EN:
1418         case ISCSI_PARAM_MAX_R2T:
1419         case ISCSI_PARAM_IMM_DATA_EN:
1420         case ISCSI_PARAM_FIRST_BURST:
1421         case ISCSI_PARAM_MAX_BURST:
1422         case ISCSI_PARAM_PDU_INORDER_EN:
1423         case ISCSI_PARAM_DATASEQ_INORDER_EN:
1424         case ISCSI_PARAM_ERL:
1425         case ISCSI_PARAM_TARGET_NAME:
1426         case ISCSI_PARAM_TPGT:
1427         case ISCSI_PARAM_USERNAME:
1428         case ISCSI_PARAM_PASSWORD:
1429         case ISCSI_PARAM_USERNAME_IN:
1430         case ISCSI_PARAM_PASSWORD_IN:
1431         case ISCSI_PARAM_FAST_ABORT:
1432         case ISCSI_PARAM_ABORT_TMO:
1433         case ISCSI_PARAM_LU_RESET_TMO:
1434         case ISCSI_PARAM_TGT_RESET_TMO:
1435         case ISCSI_PARAM_IFACE_NAME:
1436         case ISCSI_PARAM_INITIATOR_NAME:
1437         case ISCSI_PARAM_BOOT_ROOT:
1438         case ISCSI_PARAM_BOOT_NIC:
1439         case ISCSI_PARAM_BOOT_TARGET:
1440             return 0444;
1441         default:
1442             return 0;
1443         }
1444     }
1445 
1446     return 0;
1447 }
1448 
1449 static void qedi_cleanup_task(struct iscsi_task *task)
1450 {
1451     struct qedi_cmd *cmd;
1452 
1453     if (task->state == ISCSI_TASK_PENDING) {
1454         QEDI_INFO(NULL, QEDI_LOG_IO, "Returning ref_cnt=%d\n",
1455               refcount_read(&task->refcount));
1456         return;
1457     }
1458 
1459     if (task->sc)
1460         qedi_iscsi_unmap_sg_list(task->dd_data);
1461 
1462     cmd = task->dd_data;
1463     if (cmd->task_id != U16_MAX)
1464         qedi_clear_task_idx(iscsi_host_priv(task->conn->session->host),
1465                     cmd->task_id);
1466 
1467     cmd->task_id = U16_MAX;
1468     cmd->scsi_cmd = NULL;
1469 }
1470 
1471 struct iscsi_transport qedi_iscsi_transport = {
1472     .owner = THIS_MODULE,
1473     .name = QEDI_MODULE_NAME,
1474     .caps = CAP_RECOVERY_L0 | CAP_HDRDGST | CAP_MULTI_R2T | CAP_DATADGST |
1475         CAP_DATA_PATH_OFFLOAD | CAP_TEXT_NEGO,
1476     .create_session = qedi_session_create,
1477     .destroy_session = qedi_session_destroy,
1478     .create_conn = qedi_conn_create,
1479     .bind_conn = qedi_conn_bind,
1480     .unbind_conn = iscsi_conn_unbind,
1481     .start_conn = qedi_conn_start,
1482     .stop_conn = iscsi_conn_stop,
1483     .destroy_conn = qedi_conn_destroy,
1484     .set_param = iscsi_set_param,
1485     .get_ep_param = qedi_ep_get_param,
1486     .get_conn_param = iscsi_conn_get_param,
1487     .get_session_param = iscsi_session_get_param,
1488     .get_host_param = qedi_host_get_param,
1489     .send_pdu = iscsi_conn_send_pdu,
1490     .get_stats = qedi_conn_get_stats,
1491     .xmit_task = qedi_task_xmit,
1492     .cleanup_task = qedi_cleanup_task,
1493     .session_recovery_timedout = iscsi_session_recovery_timedout,
1494     .ep_connect = qedi_ep_connect,
1495     .ep_poll = qedi_ep_poll,
1496     .ep_disconnect = qedi_ep_disconnect,
1497     .set_path = qedi_set_path,
1498     .attr_is_visible = qedi_attr_is_visible,
1499 };
1500 
1501 void qedi_start_conn_recovery(struct qedi_ctx *qedi,
1502                   struct qedi_conn *qedi_conn)
1503 {
1504     struct iscsi_cls_session *cls_sess;
1505     struct iscsi_cls_conn *cls_conn;
1506     struct iscsi_conn *conn;
1507 
1508     cls_conn = qedi_conn->cls_conn;
1509     conn = cls_conn->dd_data;
1510     cls_sess = iscsi_conn_to_session(cls_conn);
1511 
1512     if (iscsi_is_session_online(cls_sess)) {
1513         qedi_conn->abrt_conn = 1;
1514         QEDI_ERR(&qedi->dbg_ctx,
1515              "Failing connection, state=0x%x, cid=0x%x\n",
1516              conn->session->state, qedi_conn->iscsi_conn_id);
1517         iscsi_conn_failure(qedi_conn->cls_conn->dd_data,
1518                    ISCSI_ERR_CONN_FAILED);
1519     }
1520 }
1521 
1522 static const struct {
1523     enum iscsi_error_types error_code;
1524     char *err_string;
1525 } qedi_iscsi_error[] = {
1526     { ISCSI_STATUS_NONE,
1527       "tcp_error none"
1528     },
1529     { ISCSI_CONN_ERROR_TASK_CID_MISMATCH,
1530       "task cid mismatch"
1531     },
1532     { ISCSI_CONN_ERROR_TASK_NOT_VALID,
1533       "invalid task"
1534     },
1535     { ISCSI_CONN_ERROR_RQ_RING_IS_FULL,
1536       "rq ring full"
1537     },
1538     { ISCSI_CONN_ERROR_CMDQ_RING_IS_FULL,
1539       "cmdq ring full"
1540     },
1541     { ISCSI_CONN_ERROR_HQE_CACHING_FAILED,
1542       "sge caching failed"
1543     },
1544     { ISCSI_CONN_ERROR_HEADER_DIGEST_ERROR,
1545       "hdr digest error"
1546     },
1547     { ISCSI_CONN_ERROR_LOCAL_COMPLETION_ERROR,
1548       "local cmpl error"
1549     },
1550     { ISCSI_CONN_ERROR_DATA_OVERRUN,
1551       "invalid task"
1552     },
1553     { ISCSI_CONN_ERROR_OUT_OF_SGES_ERROR,
1554       "out of sge error"
1555     },
1556     { ISCSI_CONN_ERROR_TCP_IP_FRAGMENT_ERROR,
1557       "tcp ip fragment error"
1558     },
1559     { ISCSI_CONN_ERROR_PROTOCOL_ERR_AHS_LEN,
1560       "AHS len protocol error"
1561     },
1562     { ISCSI_CONN_ERROR_PROTOCOL_ERR_ITT_OUT_OF_RANGE,
1563       "itt out of range error"
1564     },
1565     { ISCSI_CONN_ERROR_PROTOCOL_ERR_DATA_SEG_LEN_EXCEEDS_PDU_SIZE,
1566       "data seg more than pdu size"
1567     },
1568     { ISCSI_CONN_ERROR_PROTOCOL_ERR_INVALID_OPCODE,
1569       "invalid opcode"
1570     },
1571     { ISCSI_CONN_ERROR_PROTOCOL_ERR_INVALID_OPCODE_BEFORE_UPDATE,
1572       "invalid opcode before update"
1573     },
1574     { ISCSI_CONN_ERROR_UNVALID_NOPIN_DSL,
1575       "unexpected opcode"
1576     },
1577     { ISCSI_CONN_ERROR_PROTOCOL_ERR_R2T_CARRIES_NO_DATA,
1578       "r2t carries no data"
1579     },
1580     { ISCSI_CONN_ERROR_PROTOCOL_ERR_DATA_SN,
1581       "data sn error"
1582     },
1583     { ISCSI_CONN_ERROR_PROTOCOL_ERR_DATA_IN_TTT,
1584       "data TTT error"
1585     },
1586     { ISCSI_CONN_ERROR_PROTOCOL_ERR_R2T_TTT,
1587       "r2t TTT error"
1588     },
1589     { ISCSI_CONN_ERROR_PROTOCOL_ERR_R2T_BUFFER_OFFSET,
1590       "buffer offset error"
1591     },
1592     { ISCSI_CONN_ERROR_PROTOCOL_ERR_BUFFER_OFFSET_OOO,
1593       "buffer offset ooo"
1594     },
1595     { ISCSI_CONN_ERROR_PROTOCOL_ERR_R2T_SN,
1596       "data seg len 0"
1597     },
1598     { ISCSI_CONN_ERROR_PROTOCOL_ERR_DESIRED_DATA_TRNS_LEN_0,
1599       "data xer len error"
1600     },
1601     { ISCSI_CONN_ERROR_PROTOCOL_ERR_DESIRED_DATA_TRNS_LEN_1,
1602       "data xer len1 error"
1603     },
1604     { ISCSI_CONN_ERROR_PROTOCOL_ERR_DESIRED_DATA_TRNS_LEN_2,
1605       "data xer len2 error"
1606     },
1607     { ISCSI_CONN_ERROR_PROTOCOL_ERR_LUN,
1608       "protocol lun error"
1609     },
1610     { ISCSI_CONN_ERROR_PROTOCOL_ERR_F_BIT_ZERO,
1611       "f bit zero error"
1612     },
1613     { ISCSI_CONN_ERROR_PROTOCOL_ERR_EXP_STAT_SN,
1614       "exp stat sn error"
1615     },
1616     { ISCSI_CONN_ERROR_PROTOCOL_ERR_DSL_NOT_ZERO,
1617       "dsl not zero error"
1618     },
1619     { ISCSI_CONN_ERROR_PROTOCOL_ERR_INVALID_DSL,
1620       "invalid dsl"
1621     },
1622     { ISCSI_CONN_ERROR_PROTOCOL_ERR_DATA_SEG_LEN_TOO_BIG,
1623       "data seg len too big"
1624     },
1625     { ISCSI_CONN_ERROR_PROTOCOL_ERR_OUTSTANDING_R2T_COUNT,
1626       "outstanding r2t count error"
1627     },
1628     { ISCSI_CONN_ERROR_SENSE_DATA_LENGTH,
1629       "sense datalen error"
1630     },
1631 };
1632 
1633 static char *qedi_get_iscsi_error(enum iscsi_error_types err_code)
1634 {
1635     int i;
1636     char *msg = NULL;
1637 
1638     for (i = 0; i < ARRAY_SIZE(qedi_iscsi_error); i++) {
1639         if (qedi_iscsi_error[i].error_code == err_code) {
1640             msg = qedi_iscsi_error[i].err_string;
1641             break;
1642         }
1643     }
1644     return msg;
1645 }
1646 
1647 void qedi_process_iscsi_error(struct qedi_endpoint *ep,
1648                   struct iscsi_eqe_data *data)
1649 {
1650     struct qedi_conn *qedi_conn;
1651     struct qedi_ctx *qedi;
1652     char warn_notice[] = "iscsi_warning";
1653     char error_notice[] = "iscsi_error";
1654     char unknown_msg[] = "Unknown error";
1655     char *message;
1656     int need_recovery = 0;
1657     u32 err_mask = 0;
1658     char *msg;
1659 
1660     if (!ep)
1661         return;
1662 
1663     qedi_conn = ep->conn;
1664     if (!qedi_conn)
1665         return;
1666 
1667     qedi = ep->qedi;
1668 
1669     QEDI_ERR(&qedi->dbg_ctx, "async event iscsi error:0x%x\n",
1670          data->error_code);
1671 
1672     if (err_mask) {
1673         need_recovery = 0;
1674         message = warn_notice;
1675     } else {
1676         need_recovery = 1;
1677         message = error_notice;
1678     }
1679 
1680     msg = qedi_get_iscsi_error(data->error_code);
1681     if (!msg) {
1682         need_recovery = 0;
1683         msg = unknown_msg;
1684     }
1685 
1686     iscsi_conn_printk(KERN_ALERT,
1687               qedi_conn->cls_conn->dd_data,
1688               "qedi: %s - %s\n", message, msg);
1689 
1690     if (need_recovery)
1691         qedi_start_conn_recovery(qedi_conn->qedi, qedi_conn);
1692 }
1693 
1694 void qedi_process_tcp_error(struct qedi_endpoint *ep,
1695                 struct iscsi_eqe_data *data)
1696 {
1697     struct qedi_conn *qedi_conn;
1698 
1699     if (!ep)
1700         return;
1701 
1702     qedi_conn = ep->conn;
1703     if (!qedi_conn)
1704         return;
1705 
1706     QEDI_ERR(&ep->qedi->dbg_ctx, "async event TCP error:0x%x\n",
1707          data->error_code);
1708 
1709     qedi_start_conn_recovery(qedi_conn->qedi, qedi_conn);
1710 }