2 * QLogic iSCSI Offload Driver
3 * Copyright (c) 2016 Cavium Inc.
5 * This software is available under the terms of the GNU General Public License
6 * (GPL) Version 2, available from the file COPYING in the main directory of
10 #include <linux/blkdev.h>
11 #include <linux/etherdevice.h>
12 #include <linux/if_ether.h>
13 #include <linux/if_vlan.h>
14 #include <scsi/scsi_tcq.h>
17 #include "qedi_iscsi.h"
20 int qedi_recover_all_conns(struct qedi_ctx *qedi)
22 struct qedi_conn *qedi_conn;
25 for (i = 0; i < qedi->max_active_conns; i++) {
26 qedi_conn = qedi_get_conn_from_id(qedi, i);
30 qedi_start_conn_recovery(qedi, qedi_conn);
36 static int qedi_eh_host_reset(struct scsi_cmnd *cmd)
38 struct Scsi_Host *shost = cmd->device->host;
39 struct qedi_ctx *qedi;
41 qedi = iscsi_host_priv(shost);
43 return qedi_recover_all_conns(qedi);
46 struct scsi_host_template qedi_host_template = {
47 .module = THIS_MODULE,
48 .name = "QLogic QEDI 25/40/100Gb iSCSI Initiator Driver",
49 .proc_name = QEDI_MODULE_NAME,
50 .queuecommand = iscsi_queuecommand,
51 .eh_timed_out = iscsi_eh_cmd_timed_out,
52 .eh_abort_handler = iscsi_eh_abort,
53 .eh_device_reset_handler = iscsi_eh_device_reset,
54 .eh_target_reset_handler = iscsi_eh_recover_target,
55 .eh_host_reset_handler = qedi_eh_host_reset,
56 .target_alloc = iscsi_target_alloc,
57 .change_queue_depth = scsi_change_queue_depth,
58 .can_queue = QEDI_MAX_ISCSI_TASK,
60 .sg_tablesize = QEDI_ISCSI_MAX_BDS_PER_CMD,
61 .max_sectors = 0xffff,
63 .use_clustering = ENABLE_CLUSTERING,
64 .shost_attrs = qedi_shost_attrs,
67 static void qedi_conn_free_login_resources(struct qedi_ctx *qedi,
68 struct qedi_conn *qedi_conn)
70 if (qedi_conn->gen_pdu.resp_bd_tbl) {
71 dma_free_coherent(&qedi->pdev->dev, QEDI_PAGE_SIZE,
72 qedi_conn->gen_pdu.resp_bd_tbl,
73 qedi_conn->gen_pdu.resp_bd_dma);
74 qedi_conn->gen_pdu.resp_bd_tbl = NULL;
77 if (qedi_conn->gen_pdu.req_bd_tbl) {
78 dma_free_coherent(&qedi->pdev->dev, QEDI_PAGE_SIZE,
79 qedi_conn->gen_pdu.req_bd_tbl,
80 qedi_conn->gen_pdu.req_bd_dma);
81 qedi_conn->gen_pdu.req_bd_tbl = NULL;
84 if (qedi_conn->gen_pdu.resp_buf) {
85 dma_free_coherent(&qedi->pdev->dev,
86 ISCSI_DEF_MAX_RECV_SEG_LEN,
87 qedi_conn->gen_pdu.resp_buf,
88 qedi_conn->gen_pdu.resp_dma_addr);
89 qedi_conn->gen_pdu.resp_buf = NULL;
92 if (qedi_conn->gen_pdu.req_buf) {
93 dma_free_coherent(&qedi->pdev->dev,
94 ISCSI_DEF_MAX_RECV_SEG_LEN,
95 qedi_conn->gen_pdu.req_buf,
96 qedi_conn->gen_pdu.req_dma_addr);
97 qedi_conn->gen_pdu.req_buf = NULL;
101 static int qedi_conn_alloc_login_resources(struct qedi_ctx *qedi,
102 struct qedi_conn *qedi_conn)
104 qedi_conn->gen_pdu.req_buf =
105 dma_alloc_coherent(&qedi->pdev->dev,
106 ISCSI_DEF_MAX_RECV_SEG_LEN,
107 &qedi_conn->gen_pdu.req_dma_addr,
109 if (!qedi_conn->gen_pdu.req_buf)
110 goto login_req_buf_failure;
112 qedi_conn->gen_pdu.req_buf_size = 0;
113 qedi_conn->gen_pdu.req_wr_ptr = qedi_conn->gen_pdu.req_buf;
115 qedi_conn->gen_pdu.resp_buf =
116 dma_alloc_coherent(&qedi->pdev->dev,
117 ISCSI_DEF_MAX_RECV_SEG_LEN,
118 &qedi_conn->gen_pdu.resp_dma_addr,
120 if (!qedi_conn->gen_pdu.resp_buf)
121 goto login_resp_buf_failure;
123 qedi_conn->gen_pdu.resp_buf_size = ISCSI_DEF_MAX_RECV_SEG_LEN;
124 qedi_conn->gen_pdu.resp_wr_ptr = qedi_conn->gen_pdu.resp_buf;
126 qedi_conn->gen_pdu.req_bd_tbl =
127 dma_alloc_coherent(&qedi->pdev->dev, QEDI_PAGE_SIZE,
128 &qedi_conn->gen_pdu.req_bd_dma, GFP_KERNEL);
129 if (!qedi_conn->gen_pdu.req_bd_tbl)
130 goto login_req_bd_tbl_failure;
132 qedi_conn->gen_pdu.resp_bd_tbl =
133 dma_alloc_coherent(&qedi->pdev->dev, QEDI_PAGE_SIZE,
134 &qedi_conn->gen_pdu.resp_bd_dma,
136 if (!qedi_conn->gen_pdu.resp_bd_tbl)
137 goto login_resp_bd_tbl_failure;
139 QEDI_INFO(&qedi->dbg_ctx, QEDI_LOG_SESS,
140 "Allocation successful, cid=0x%x\n",
141 qedi_conn->iscsi_conn_id);
144 login_resp_bd_tbl_failure:
145 dma_free_coherent(&qedi->pdev->dev, QEDI_PAGE_SIZE,
146 qedi_conn->gen_pdu.req_bd_tbl,
147 qedi_conn->gen_pdu.req_bd_dma);
148 qedi_conn->gen_pdu.req_bd_tbl = NULL;
150 login_req_bd_tbl_failure:
151 dma_free_coherent(&qedi->pdev->dev, ISCSI_DEF_MAX_RECV_SEG_LEN,
152 qedi_conn->gen_pdu.resp_buf,
153 qedi_conn->gen_pdu.resp_dma_addr);
154 qedi_conn->gen_pdu.resp_buf = NULL;
155 login_resp_buf_failure:
156 dma_free_coherent(&qedi->pdev->dev, ISCSI_DEF_MAX_RECV_SEG_LEN,
157 qedi_conn->gen_pdu.req_buf,
158 qedi_conn->gen_pdu.req_dma_addr);
159 qedi_conn->gen_pdu.req_buf = NULL;
160 login_req_buf_failure:
161 iscsi_conn_printk(KERN_ERR, qedi_conn->cls_conn->dd_data,
162 "login resource alloc failed!!\n");
166 static void qedi_destroy_cmd_pool(struct qedi_ctx *qedi,
167 struct iscsi_session *session)
171 for (i = 0; i < session->cmds_max; i++) {
172 struct iscsi_task *task = session->cmds[i];
173 struct qedi_cmd *cmd = task->dd_data;
175 if (cmd->io_tbl.sge_tbl)
176 dma_free_coherent(&qedi->pdev->dev,
177 QEDI_ISCSI_MAX_BDS_PER_CMD *
178 sizeof(struct iscsi_sge),
180 cmd->io_tbl.sge_tbl_dma);
182 if (cmd->sense_buffer)
183 dma_free_coherent(&qedi->pdev->dev,
184 SCSI_SENSE_BUFFERSIZE,
186 cmd->sense_buffer_dma);
190 static int qedi_alloc_sget(struct qedi_ctx *qedi, struct iscsi_session *session,
191 struct qedi_cmd *cmd)
193 struct qedi_io_bdt *io = &cmd->io_tbl;
194 struct iscsi_sge *sge;
196 io->sge_tbl = dma_alloc_coherent(&qedi->pdev->dev,
197 QEDI_ISCSI_MAX_BDS_PER_CMD *
199 &io->sge_tbl_dma, GFP_KERNEL);
201 iscsi_session_printk(KERN_ERR, session,
202 "Could not allocate BD table.\n");
210 static int qedi_setup_cmd_pool(struct qedi_ctx *qedi,
211 struct iscsi_session *session)
215 for (i = 0; i < session->cmds_max; i++) {
216 struct iscsi_task *task = session->cmds[i];
217 struct qedi_cmd *cmd = task->dd_data;
219 task->hdr = &cmd->hdr;
220 task->hdr_max = sizeof(struct iscsi_hdr);
222 if (qedi_alloc_sget(qedi, session, cmd))
225 cmd->sense_buffer = dma_alloc_coherent(&qedi->pdev->dev,
226 SCSI_SENSE_BUFFERSIZE,
227 &cmd->sense_buffer_dma,
229 if (!cmd->sense_buffer)
236 qedi_destroy_cmd_pool(qedi, session);
240 static struct iscsi_cls_session *
241 qedi_session_create(struct iscsi_endpoint *ep, u16 cmds_max,
242 u16 qdepth, uint32_t initial_cmdsn)
244 struct Scsi_Host *shost;
245 struct iscsi_cls_session *cls_session;
246 struct qedi_ctx *qedi;
247 struct qedi_endpoint *qedi_ep;
252 qedi_ep = ep->dd_data;
253 shost = qedi_ep->qedi->shost;
254 qedi = iscsi_host_priv(shost);
256 if (cmds_max > qedi->max_sqes)
257 cmds_max = qedi->max_sqes;
258 else if (cmds_max < QEDI_SQ_WQES_MIN)
259 cmds_max = QEDI_SQ_WQES_MIN;
261 cls_session = iscsi_session_setup(&qedi_iscsi_transport, shost,
262 cmds_max, 0, sizeof(struct qedi_cmd),
263 initial_cmdsn, ISCSI_MAX_TARGET);
265 QEDI_ERR(&qedi->dbg_ctx,
266 "Failed to setup session for ep=%p\n", qedi_ep);
270 if (qedi_setup_cmd_pool(qedi, cls_session->dd_data)) {
271 QEDI_ERR(&qedi->dbg_ctx,
272 "Failed to setup cmd pool for ep=%p\n", qedi_ep);
273 goto session_teardown;
279 iscsi_session_teardown(cls_session);
283 static void qedi_session_destroy(struct iscsi_cls_session *cls_session)
285 struct iscsi_session *session = cls_session->dd_data;
286 struct Scsi_Host *shost = iscsi_session_to_shost(cls_session);
287 struct qedi_ctx *qedi = iscsi_host_priv(shost);
289 qedi_destroy_cmd_pool(qedi, session);
290 iscsi_session_teardown(cls_session);
293 static struct iscsi_cls_conn *
294 qedi_conn_create(struct iscsi_cls_session *cls_session, uint32_t cid)
296 struct Scsi_Host *shost = iscsi_session_to_shost(cls_session);
297 struct qedi_ctx *qedi = iscsi_host_priv(shost);
298 struct iscsi_cls_conn *cls_conn;
299 struct qedi_conn *qedi_conn;
300 struct iscsi_conn *conn;
302 cls_conn = iscsi_conn_setup(cls_session, sizeof(*qedi_conn),
305 QEDI_ERR(&qedi->dbg_ctx,
306 "conn_new: iscsi conn setup failed, cid=0x%x, cls_sess=%p!\n",
311 conn = cls_conn->dd_data;
312 qedi_conn = conn->dd_data;
313 qedi_conn->cls_conn = cls_conn;
314 qedi_conn->qedi = qedi;
315 qedi_conn->ep = NULL;
316 qedi_conn->active_cmd_count = 0;
317 INIT_LIST_HEAD(&qedi_conn->active_cmd_list);
318 spin_lock_init(&qedi_conn->list_lock);
320 if (qedi_conn_alloc_login_resources(qedi, qedi_conn)) {
321 iscsi_conn_printk(KERN_ALERT, conn,
322 "conn_new: login resc alloc failed, cid=0x%x, cls_sess=%p!!\n",
330 iscsi_conn_teardown(cls_conn);
334 void qedi_mark_device_missing(struct iscsi_cls_session *cls_session)
336 iscsi_block_session(cls_session);
339 void qedi_mark_device_available(struct iscsi_cls_session *cls_session)
341 iscsi_unblock_session(cls_session);
344 static int qedi_bind_conn_to_iscsi_cid(struct qedi_ctx *qedi,
345 struct qedi_conn *qedi_conn)
347 u32 iscsi_cid = qedi_conn->iscsi_conn_id;
349 if (qedi->cid_que.conn_cid_tbl[iscsi_cid]) {
350 iscsi_conn_printk(KERN_ALERT, qedi_conn->cls_conn->dd_data,
351 "conn bind - entry #%d not free\n",
356 qedi->cid_que.conn_cid_tbl[iscsi_cid] = qedi_conn;
360 struct qedi_conn *qedi_get_conn_from_id(struct qedi_ctx *qedi, u32 iscsi_cid)
362 if (!qedi->cid_que.conn_cid_tbl) {
363 QEDI_ERR(&qedi->dbg_ctx, "missing conn<->cid table\n");
366 } else if (iscsi_cid >= qedi->max_active_conns) {
367 QEDI_ERR(&qedi->dbg_ctx, "wrong cid #%d\n", iscsi_cid);
370 return qedi->cid_que.conn_cid_tbl[iscsi_cid];
373 static int qedi_conn_bind(struct iscsi_cls_session *cls_session,
374 struct iscsi_cls_conn *cls_conn,
375 u64 transport_fd, int is_leading)
377 struct iscsi_conn *conn = cls_conn->dd_data;
378 struct qedi_conn *qedi_conn = conn->dd_data;
379 struct Scsi_Host *shost = iscsi_session_to_shost(cls_session);
380 struct qedi_ctx *qedi = iscsi_host_priv(shost);
381 struct qedi_endpoint *qedi_ep;
382 struct iscsi_endpoint *ep;
384 ep = iscsi_lookup_endpoint(transport_fd);
388 qedi_ep = ep->dd_data;
389 if ((qedi_ep->state == EP_STATE_TCP_FIN_RCVD) ||
390 (qedi_ep->state == EP_STATE_TCP_RST_RCVD))
393 if (iscsi_conn_bind(cls_session, cls_conn, is_leading))
396 qedi_ep->conn = qedi_conn;
397 qedi_conn->ep = qedi_ep;
398 qedi_conn->iscsi_conn_id = qedi_ep->iscsi_cid;
399 qedi_conn->fw_cid = qedi_ep->fw_cid;
400 qedi_conn->cmd_cleanup_req = 0;
401 qedi_conn->cmd_cleanup_cmpl = 0;
403 if (qedi_bind_conn_to_iscsi_cid(qedi, qedi_conn))
406 spin_lock_init(&qedi_conn->tmf_work_lock);
407 INIT_LIST_HEAD(&qedi_conn->tmf_work_list);
408 init_waitqueue_head(&qedi_conn->wait_queue);
412 static int qedi_iscsi_update_conn(struct qedi_ctx *qedi,
413 struct qedi_conn *qedi_conn)
415 struct qed_iscsi_params_update *conn_info;
416 struct iscsi_cls_conn *cls_conn = qedi_conn->cls_conn;
417 struct iscsi_conn *conn = cls_conn->dd_data;
418 struct qedi_endpoint *qedi_ep;
421 qedi_ep = qedi_conn->ep;
423 conn_info = kzalloc(sizeof(*conn_info), GFP_KERNEL);
425 QEDI_ERR(&qedi->dbg_ctx, "memory alloc failed\n");
429 conn_info->update_flag = 0;
431 if (conn->hdrdgst_en)
432 SET_FIELD(conn_info->update_flag,
433 ISCSI_CONN_UPDATE_RAMROD_PARAMS_HD_EN, true);
434 if (conn->datadgst_en)
435 SET_FIELD(conn_info->update_flag,
436 ISCSI_CONN_UPDATE_RAMROD_PARAMS_DD_EN, true);
437 if (conn->session->initial_r2t_en)
438 SET_FIELD(conn_info->update_flag,
439 ISCSI_CONN_UPDATE_RAMROD_PARAMS_INITIAL_R2T,
441 if (conn->session->imm_data_en)
442 SET_FIELD(conn_info->update_flag,
443 ISCSI_CONN_UPDATE_RAMROD_PARAMS_IMMEDIATE_DATA,
446 conn_info->max_seq_size = conn->session->max_burst;
447 conn_info->max_recv_pdu_length = conn->max_recv_dlength;
448 conn_info->max_send_pdu_length = conn->max_xmit_dlength;
449 conn_info->first_seq_length = conn->session->first_burst;
450 conn_info->exp_stat_sn = conn->exp_statsn;
452 rval = qedi_ops->update_conn(qedi->cdev, qedi_ep->handle,
456 QEDI_ERR(&qedi->dbg_ctx, "Could not update connection\n");
463 static u16 qedi_calc_mss(u16 pmtu, u8 is_ipv6, u8 tcp_ts_en, u8 vlan_en)
466 u16 hdrs = TCP_HDR_LEN;
469 hdrs += IPV6_HDR_LEN;
471 hdrs += IPV4_HDR_LEN;
479 mss -= TCP_OPTION_LEN;
487 static int qedi_iscsi_offload_conn(struct qedi_endpoint *qedi_ep)
489 struct qedi_ctx *qedi = qedi_ep->qedi;
490 struct qed_iscsi_params_offload *conn_info;
494 conn_info = kzalloc(sizeof(*conn_info), GFP_KERNEL);
496 QEDI_ERR(&qedi->dbg_ctx,
497 "Failed to allocate memory ep=%p\n", qedi_ep);
501 ether_addr_copy(conn_info->src.mac, qedi_ep->src_mac);
502 ether_addr_copy(conn_info->dst.mac, qedi_ep->dst_mac);
504 conn_info->src.ip[0] = ntohl(qedi_ep->src_addr[0]);
505 conn_info->dst.ip[0] = ntohl(qedi_ep->dst_addr[0]);
507 if (qedi_ep->ip_type == TCP_IPV4) {
508 conn_info->ip_version = 0;
509 QEDI_INFO(&qedi->dbg_ctx, QEDI_LOG_CONN,
510 "After ntohl: src_addr=%pI4, dst_addr=%pI4\n",
511 qedi_ep->src_addr, qedi_ep->dst_addr);
513 for (i = 1; i < 4; i++) {
514 conn_info->src.ip[i] = ntohl(qedi_ep->src_addr[i]);
515 conn_info->dst.ip[i] = ntohl(qedi_ep->dst_addr[i]);
518 conn_info->ip_version = 1;
519 QEDI_INFO(&qedi->dbg_ctx, QEDI_LOG_CONN,
520 "After ntohl: src_addr=%pI6, dst_addr=%pI6\n",
521 qedi_ep->src_addr, qedi_ep->dst_addr);
524 conn_info->src.port = qedi_ep->src_port;
525 conn_info->dst.port = qedi_ep->dst_port;
527 conn_info->layer_code = ISCSI_SLOW_PATH_LAYER_CODE;
528 conn_info->sq_pbl_addr = qedi_ep->sq_pbl_dma;
529 conn_info->vlan_id = qedi_ep->vlan_id;
531 SET_FIELD(conn_info->tcp_flags, TCP_OFFLOAD_PARAMS_TS_EN, 1);
532 SET_FIELD(conn_info->tcp_flags, TCP_OFFLOAD_PARAMS_DA_EN, 1);
533 SET_FIELD(conn_info->tcp_flags, TCP_OFFLOAD_PARAMS_DA_CNT_EN, 1);
534 SET_FIELD(conn_info->tcp_flags, TCP_OFFLOAD_PARAMS_KA_EN, 1);
536 conn_info->default_cq = (qedi_ep->fw_cid % 8);
538 conn_info->ka_max_probe_cnt = DEF_KA_MAX_PROBE_COUNT;
539 conn_info->dup_ack_theshold = 3;
540 conn_info->rcv_wnd = 65535;
541 conn_info->cwnd = DEF_MAX_CWND;
543 conn_info->ss_thresh = 65535;
544 conn_info->srtt = 300;
545 conn_info->rtt_var = 150;
546 conn_info->flow_label = 0;
547 conn_info->ka_timeout = DEF_KA_TIMEOUT;
548 conn_info->ka_interval = DEF_KA_INTERVAL;
549 conn_info->max_rt_time = DEF_MAX_RT_TIME;
550 conn_info->ttl = DEF_TTL;
551 conn_info->tos_or_tc = DEF_TOS;
552 conn_info->remote_port = qedi_ep->dst_port;
553 conn_info->local_port = qedi_ep->src_port;
555 conn_info->mss = qedi_calc_mss(qedi_ep->pmtu,
556 (qedi_ep->ip_type == TCP_IPV6),
557 1, (qedi_ep->vlan_id != 0));
559 conn_info->rcv_wnd_scale = 4;
560 conn_info->ts_ticks_per_second = 1000;
561 conn_info->da_timeout_value = 200;
562 conn_info->ack_frequency = 2;
564 QEDI_INFO(&qedi->dbg_ctx, QEDI_LOG_INFO,
565 "Default cq index [%d], mss [%d]\n",
566 conn_info->default_cq, conn_info->mss);
568 rval = qedi_ops->offload_conn(qedi->cdev, qedi_ep->handle, conn_info);
570 QEDI_ERR(&qedi->dbg_ctx, "offload_conn returned %d, ep=%p\n",
577 static int qedi_conn_start(struct iscsi_cls_conn *cls_conn)
579 struct iscsi_conn *conn = cls_conn->dd_data;
580 struct qedi_conn *qedi_conn = conn->dd_data;
581 struct qedi_ctx *qedi;
584 qedi = qedi_conn->qedi;
586 rval = qedi_iscsi_update_conn(qedi, qedi_conn);
588 iscsi_conn_printk(KERN_ALERT, conn,
589 "conn_start: FW oflload conn failed.\n");
594 clear_bit(QEDI_CONN_FW_CLEANUP, &qedi_conn->flags);
595 qedi_conn->abrt_conn = 0;
597 rval = iscsi_conn_start(cls_conn);
599 iscsi_conn_printk(KERN_ALERT, conn,
600 "iscsi_conn_start: FW oflload conn failed!!\n");
607 static void qedi_conn_destroy(struct iscsi_cls_conn *cls_conn)
609 struct iscsi_conn *conn = cls_conn->dd_data;
610 struct qedi_conn *qedi_conn = conn->dd_data;
611 struct Scsi_Host *shost;
612 struct qedi_ctx *qedi;
614 shost = iscsi_session_to_shost(iscsi_conn_to_session(cls_conn));
615 qedi = iscsi_host_priv(shost);
617 qedi_conn_free_login_resources(qedi, qedi_conn);
618 iscsi_conn_teardown(cls_conn);
621 static int qedi_ep_get_param(struct iscsi_endpoint *ep,
622 enum iscsi_param param, char *buf)
624 struct qedi_endpoint *qedi_ep = ep->dd_data;
631 case ISCSI_PARAM_CONN_PORT:
632 len = sprintf(buf, "%hu\n", qedi_ep->dst_port);
634 case ISCSI_PARAM_CONN_ADDRESS:
635 if (qedi_ep->ip_type == TCP_IPV4)
636 len = sprintf(buf, "%pI4\n", qedi_ep->dst_addr);
638 len = sprintf(buf, "%pI6\n", qedi_ep->dst_addr);
647 static int qedi_host_get_param(struct Scsi_Host *shost,
648 enum iscsi_host_param param, char *buf)
650 struct qedi_ctx *qedi;
653 qedi = iscsi_host_priv(shost);
656 case ISCSI_HOST_PARAM_HWADDRESS:
657 len = sysfs_format_mac(buf, qedi->mac, 6);
659 case ISCSI_HOST_PARAM_NETDEV_NAME:
660 len = sprintf(buf, "host%d\n", shost->host_no);
662 case ISCSI_HOST_PARAM_IPADDRESS:
663 if (qedi->ip_type == TCP_IPV4)
664 len = sprintf(buf, "%pI4\n", qedi->src_ip);
666 len = sprintf(buf, "%pI6\n", qedi->src_ip);
669 return iscsi_host_get_param(shost, param, buf);
675 static void qedi_conn_get_stats(struct iscsi_cls_conn *cls_conn,
676 struct iscsi_stats *stats)
678 struct iscsi_conn *conn = cls_conn->dd_data;
679 struct qed_iscsi_stats iscsi_stats;
680 struct Scsi_Host *shost;
681 struct qedi_ctx *qedi;
683 shost = iscsi_session_to_shost(iscsi_conn_to_session(cls_conn));
684 qedi = iscsi_host_priv(shost);
685 qedi_ops->get_stats(qedi->cdev, &iscsi_stats);
687 conn->txdata_octets = iscsi_stats.iscsi_tx_bytes_cnt;
688 conn->rxdata_octets = iscsi_stats.iscsi_rx_bytes_cnt;
689 conn->dataout_pdus_cnt = (uint32_t)iscsi_stats.iscsi_tx_data_pdu_cnt;
690 conn->datain_pdus_cnt = (uint32_t)iscsi_stats.iscsi_rx_data_pdu_cnt;
691 conn->r2t_pdus_cnt = (uint32_t)iscsi_stats.iscsi_rx_r2t_pdu_cnt;
693 stats->txdata_octets = conn->txdata_octets;
694 stats->rxdata_octets = conn->rxdata_octets;
695 stats->scsicmd_pdus = conn->scsicmd_pdus_cnt;
696 stats->dataout_pdus = conn->dataout_pdus_cnt;
697 stats->scsirsp_pdus = conn->scsirsp_pdus_cnt;
698 stats->datain_pdus = conn->datain_pdus_cnt;
699 stats->r2t_pdus = conn->r2t_pdus_cnt;
700 stats->tmfcmd_pdus = conn->tmfcmd_pdus_cnt;
701 stats->tmfrsp_pdus = conn->tmfrsp_pdus_cnt;
702 stats->digest_err = 0;
703 stats->timeout_err = 0;
704 strcpy(stats->custom[0].desc, "eh_abort_cnt");
705 stats->custom[0].value = conn->eh_abort_cnt;
706 stats->custom_length = 1;
709 static void qedi_iscsi_prep_generic_pdu_bd(struct qedi_conn *qedi_conn)
711 struct iscsi_sge *bd_tbl;
713 bd_tbl = (struct iscsi_sge *)qedi_conn->gen_pdu.req_bd_tbl;
715 bd_tbl->sge_addr.hi =
716 (u32)((u64)qedi_conn->gen_pdu.req_dma_addr >> 32);
717 bd_tbl->sge_addr.lo = (u32)qedi_conn->gen_pdu.req_dma_addr;
718 bd_tbl->sge_len = qedi_conn->gen_pdu.req_wr_ptr -
719 qedi_conn->gen_pdu.req_buf;
720 bd_tbl->reserved0 = 0;
721 bd_tbl = (struct iscsi_sge *)qedi_conn->gen_pdu.resp_bd_tbl;
722 bd_tbl->sge_addr.hi =
723 (u32)((u64)qedi_conn->gen_pdu.resp_dma_addr >> 32);
724 bd_tbl->sge_addr.lo = (u32)qedi_conn->gen_pdu.resp_dma_addr;
725 bd_tbl->sge_len = ISCSI_DEF_MAX_RECV_SEG_LEN;
726 bd_tbl->reserved0 = 0;
729 static int qedi_iscsi_send_generic_request(struct iscsi_task *task)
731 struct qedi_cmd *cmd = task->dd_data;
732 struct qedi_conn *qedi_conn = cmd->conn;
737 qedi_iscsi_prep_generic_pdu_bd(qedi_conn);
738 switch (task->hdr->opcode & ISCSI_OPCODE_MASK) {
740 qedi_send_iscsi_login(qedi_conn, task);
742 case ISCSI_OP_NOOP_OUT:
743 data_len = qedi_conn->gen_pdu.req_buf_size;
744 buf = qedi_conn->gen_pdu.req_buf;
746 rc = qedi_send_iscsi_nopout(qedi_conn, task,
749 rc = qedi_send_iscsi_nopout(qedi_conn, task,
752 case ISCSI_OP_LOGOUT:
753 rc = qedi_send_iscsi_logout(qedi_conn, task);
755 case ISCSI_OP_SCSI_TMFUNC:
756 rc = qedi_iscsi_abort_work(qedi_conn, task);
759 rc = qedi_send_iscsi_text(qedi_conn, task);
762 iscsi_conn_printk(KERN_ALERT, qedi_conn->cls_conn->dd_data,
763 "unsupported op 0x%x\n", task->hdr->opcode);
769 static int qedi_mtask_xmit(struct iscsi_conn *conn, struct iscsi_task *task)
771 struct qedi_conn *qedi_conn = conn->dd_data;
772 struct qedi_cmd *cmd = task->dd_data;
774 memset(qedi_conn->gen_pdu.req_buf, 0, ISCSI_DEF_MAX_RECV_SEG_LEN);
776 qedi_conn->gen_pdu.req_buf_size = task->data_count;
778 if (task->data_count) {
779 memcpy(qedi_conn->gen_pdu.req_buf, task->data,
781 qedi_conn->gen_pdu.req_wr_ptr =
782 qedi_conn->gen_pdu.req_buf + task->data_count;
785 cmd->conn = conn->dd_data;
786 cmd->scsi_cmd = NULL;
787 return qedi_iscsi_send_generic_request(task);
790 static int qedi_task_xmit(struct iscsi_task *task)
792 struct iscsi_conn *conn = task->conn;
793 struct qedi_conn *qedi_conn = conn->dd_data;
794 struct qedi_cmd *cmd = task->dd_data;
795 struct scsi_cmnd *sc = task->sc;
799 cmd->use_slowpath = false;
800 cmd->conn = qedi_conn;
802 cmd->io_cmd_in_list = false;
803 INIT_LIST_HEAD(&cmd->io_cmd);
806 return qedi_mtask_xmit(conn, task);
809 return qedi_iscsi_send_ioreq(task);
812 static struct iscsi_endpoint *
813 qedi_ep_connect(struct Scsi_Host *shost, struct sockaddr *dst_addr,
816 struct qedi_ctx *qedi;
817 struct iscsi_endpoint *ep;
818 struct qedi_endpoint *qedi_ep;
819 struct sockaddr_in *addr;
820 struct sockaddr_in6 *addr6;
821 struct qed_dev *cdev = NULL;
822 struct qedi_uio_dev *udev = NULL;
823 struct iscsi_path path_req;
824 u32 msg_type = ISCSI_KEVENT_IF_DOWN;
825 u32 iscsi_cid = QEDI_CID_RESERVED;
832 QEDI_ERR(NULL, "shost is NULL\n");
836 if (do_not_recover) {
841 qedi = iscsi_host_priv(shost);
845 if (test_bit(QEDI_IN_OFFLINE, &qedi->flags) ||
846 test_bit(QEDI_IN_RECOVERY, &qedi->flags)) {
851 ep = iscsi_create_endpoint(sizeof(struct qedi_endpoint));
853 QEDI_ERR(&qedi->dbg_ctx, "endpoint create fail\n");
857 qedi_ep = ep->dd_data;
858 memset(qedi_ep, 0, sizeof(struct qedi_endpoint));
859 qedi_ep->state = EP_STATE_IDLE;
860 qedi_ep->iscsi_cid = (u32)-1;
861 qedi_ep->qedi = qedi;
863 if (dst_addr->sa_family == AF_INET) {
864 addr = (struct sockaddr_in *)dst_addr;
865 memcpy(qedi_ep->dst_addr, &addr->sin_addr.s_addr,
866 sizeof(struct in_addr));
867 qedi_ep->dst_port = ntohs(addr->sin_port);
868 qedi_ep->ip_type = TCP_IPV4;
869 QEDI_INFO(&qedi->dbg_ctx, QEDI_LOG_CONN,
870 "dst_addr=%pI4, dst_port=%u\n",
871 qedi_ep->dst_addr, qedi_ep->dst_port);
872 } else if (dst_addr->sa_family == AF_INET6) {
873 addr6 = (struct sockaddr_in6 *)dst_addr;
874 memcpy(qedi_ep->dst_addr, &addr6->sin6_addr,
875 sizeof(struct in6_addr));
876 qedi_ep->dst_port = ntohs(addr6->sin6_port);
877 qedi_ep->ip_type = TCP_IPV6;
878 QEDI_INFO(&qedi->dbg_ctx, QEDI_LOG_CONN,
879 "dst_addr=%pI6, dst_port=%u\n",
880 qedi_ep->dst_addr, qedi_ep->dst_port);
882 QEDI_ERR(&qedi->dbg_ctx, "Invalid endpoint\n");
885 if (atomic_read(&qedi->link_state) != QEDI_LINK_UP) {
886 QEDI_WARN(&qedi->dbg_ctx, "qedi link down\n");
891 ret = qedi_alloc_sq(qedi, qedi_ep);
895 ret = qedi_ops->acquire_conn(qedi->cdev, &qedi_ep->handle,
896 &qedi_ep->fw_cid, &qedi_ep->p_doorbell);
899 QEDI_ERR(&qedi->dbg_ctx, "Could not acquire connection\n");
904 iscsi_cid = qedi_ep->handle;
905 qedi_ep->iscsi_cid = iscsi_cid;
907 init_waitqueue_head(&qedi_ep->ofld_wait);
908 init_waitqueue_head(&qedi_ep->tcp_ofld_wait);
909 qedi_ep->state = EP_STATE_OFLDCONN_START;
910 qedi->ep_tbl[iscsi_cid] = qedi_ep;
912 buf = (char *)&path_req;
913 len = sizeof(path_req);
914 memset(&path_req, 0, len);
916 msg_type = ISCSI_KEVENT_PATH_REQ;
917 path_req.handle = (u64)qedi_ep->iscsi_cid;
918 path_req.pmtu = qedi->ll2_mtu;
919 qedi_ep->pmtu = qedi->ll2_mtu;
920 if (qedi_ep->ip_type == TCP_IPV4) {
921 memcpy(&path_req.dst.v4_addr, &qedi_ep->dst_addr,
922 sizeof(struct in_addr));
923 path_req.ip_addr_len = 4;
925 memcpy(&path_req.dst.v6_addr, &qedi_ep->dst_addr,
926 sizeof(struct in6_addr));
927 path_req.ip_addr_len = 16;
930 ret = iscsi_offload_mesg(shost, &qedi_iscsi_transport, msg_type, buf,
933 QEDI_ERR(&qedi->dbg_ctx,
934 "iscsi_offload_mesg() failed for cid=0x%x ret=%d\n",
939 atomic_inc(&qedi->num_offloads);
943 qedi->ep_tbl[iscsi_cid] = NULL;
944 ret = qedi_ops->release_conn(qedi->cdev, qedi_ep->handle);
946 QEDI_WARN(&qedi->dbg_ctx, "release_conn returned %d\n",
949 qedi_free_sq(qedi, qedi_ep);
951 iscsi_destroy_endpoint(ep);
955 static int qedi_ep_poll(struct iscsi_endpoint *ep, int timeout_ms)
957 struct qedi_endpoint *qedi_ep;
963 qedi_ep = ep->dd_data;
964 if (qedi_ep->state == EP_STATE_IDLE ||
965 qedi_ep->state == EP_STATE_OFLDCONN_FAILED)
968 if (qedi_ep->state == EP_STATE_OFLDCONN_COMPL)
971 ret = wait_event_interruptible_timeout(qedi_ep->ofld_wait,
972 QEDI_OFLD_WAIT_STATE(qedi_ep),
973 msecs_to_jiffies(timeout_ms));
975 if (qedi_ep->state == EP_STATE_OFLDCONN_FAILED)
986 static void qedi_cleanup_active_cmd_list(struct qedi_conn *qedi_conn)
988 struct qedi_cmd *cmd, *cmd_tmp;
990 list_for_each_entry_safe(cmd, cmd_tmp, &qedi_conn->active_cmd_list,
992 list_del_init(&cmd->io_cmd);
993 qedi_conn->active_cmd_count--;
997 static void qedi_ep_disconnect(struct iscsi_endpoint *ep)
999 struct qedi_endpoint *qedi_ep;
1000 struct qedi_conn *qedi_conn = NULL;
1001 struct iscsi_conn *conn = NULL;
1002 struct qedi_ctx *qedi;
1004 int wait_delay = 20 * HZ;
1008 qedi_ep = ep->dd_data;
1009 qedi = qedi_ep->qedi;
1011 flush_work(&qedi_ep->offload_work);
1013 if (qedi_ep->conn) {
1014 qedi_conn = qedi_ep->conn;
1015 conn = qedi_conn->cls_conn->dd_data;
1016 iscsi_suspend_queue(conn);
1017 abrt_conn = qedi_conn->abrt_conn;
1020 if (!test_bit(QEDI_CONN_FW_CLEANUP,
1021 &qedi_conn->flags)) {
1027 if (test_bit(QEDI_IN_RECOVERY, &qedi->flags)) {
1028 if (do_not_recover) {
1029 QEDI_INFO(&qedi->dbg_ctx, QEDI_LOG_INFO,
1030 "Do not recover cid=0x%x\n",
1031 qedi_ep->iscsi_cid);
1032 goto ep_exit_recover;
1034 QEDI_INFO(&qedi->dbg_ctx, QEDI_LOG_INFO,
1035 "Reset recovery cid=0x%x, qedi_ep=%p, state=0x%x\n",
1036 qedi_ep->iscsi_cid, qedi_ep, qedi_ep->state);
1037 qedi_cleanup_active_cmd_list(qedi_conn);
1038 goto ep_release_conn;
1043 goto ep_exit_recover;
1045 switch (qedi_ep->state) {
1046 case EP_STATE_OFLDCONN_START:
1047 goto ep_release_conn;
1048 case EP_STATE_OFLDCONN_FAILED:
1050 case EP_STATE_OFLDCONN_COMPL:
1051 if (unlikely(!qedi_conn))
1054 QEDI_INFO(&qedi->dbg_ctx, QEDI_LOG_INFO,
1055 "Active cmd count=%d, abrt_conn=%d, ep state=0x%x, cid=0x%x, qedi_conn=%p\n",
1056 qedi_conn->active_cmd_count, abrt_conn,
1062 if (!qedi_conn->active_cmd_count)
1068 qedi_clearsq(qedi, qedi_conn, NULL);
1074 qedi_ep->state = EP_STATE_DISCONN_START;
1075 ret = qedi_ops->destroy_conn(qedi->cdev, qedi_ep->handle, abrt_conn);
1077 QEDI_WARN(&qedi->dbg_ctx,
1078 "destroy_conn failed returned %d\n", ret);
1080 ret = wait_event_interruptible_timeout(
1081 qedi_ep->tcp_ofld_wait,
1083 EP_STATE_DISCONN_START),
1085 if ((ret <= 0) || (qedi_ep->state == EP_STATE_DISCONN_START)) {
1086 QEDI_WARN(&qedi->dbg_ctx,
1087 "Destroy conn timedout or interrupted, ret=%d, delay=%d, cid=0x%x\n",
1088 ret, wait_delay, qedi_ep->iscsi_cid);
1093 ret = qedi_ops->release_conn(qedi->cdev, qedi_ep->handle);
1095 QEDI_WARN(&qedi->dbg_ctx,
1096 "release_conn returned %d, cid=0x%x\n",
1097 ret, qedi_ep->iscsi_cid);
1099 qedi_ep->state = EP_STATE_IDLE;
1100 qedi->ep_tbl[qedi_ep->iscsi_cid] = NULL;
1101 qedi->cid_que.conn_cid_tbl[qedi_ep->iscsi_cid] = NULL;
1102 qedi_free_id(&qedi->lcl_port_tbl, qedi_ep->src_port);
1103 qedi_free_sq(qedi, qedi_ep);
1106 qedi_conn->ep = NULL;
1108 qedi_ep->conn = NULL;
1109 qedi_ep->qedi = NULL;
1110 atomic_dec(&qedi->num_offloads);
1112 iscsi_destroy_endpoint(ep);
1115 static int qedi_data_avail(struct qedi_ctx *qedi, u16 vlanid)
1117 struct qed_dev *cdev = qedi->cdev;
1118 struct qedi_uio_dev *udev;
1119 struct qedi_uio_ctrl *uctrl;
1120 struct sk_buff *skb;
1126 QEDI_ERR(&qedi->dbg_ctx, "udev is NULL.\n");
1130 uctrl = (struct qedi_uio_ctrl *)udev->uctrl;
1132 QEDI_ERR(&qedi->dbg_ctx, "uctlr is NULL.\n");
1136 len = uctrl->host_tx_pkt_len;
1138 QEDI_ERR(&qedi->dbg_ctx, "Invalid len %u\n", len);
1142 skb = alloc_skb(len, GFP_ATOMIC);
1144 QEDI_ERR(&qedi->dbg_ctx, "alloc_skb failed\n");
1149 memcpy(skb->data, udev->tx_pkt, len);
1150 skb->ip_summed = CHECKSUM_NONE;
1153 __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), vlanid);
1155 rc = qedi_ops->ll2->start_xmit(cdev, skb);
1157 QEDI_ERR(&qedi->dbg_ctx, "ll2 start_xmit returned %d\n",
1162 uctrl->host_tx_pkt_len = 0;
1163 uctrl->hw_tx_cons++;
1168 static void qedi_offload_work(struct work_struct *work)
1170 struct qedi_endpoint *qedi_ep =
1171 container_of(work, struct qedi_endpoint, offload_work);
1172 struct qedi_ctx *qedi;
1173 int wait_delay = 20 * HZ;
1176 qedi = qedi_ep->qedi;
1178 ret = qedi_iscsi_offload_conn(qedi_ep);
1180 QEDI_ERR(&qedi->dbg_ctx,
1181 "offload error: iscsi_cid=%u, qedi_ep=%p, ret=%d\n",
1182 qedi_ep->iscsi_cid, qedi_ep, ret);
1183 qedi_ep->state = EP_STATE_OFLDCONN_FAILED;
1187 ret = wait_event_interruptible_timeout(qedi_ep->tcp_ofld_wait,
1189 EP_STATE_OFLDCONN_COMPL),
1191 if ((ret <= 0) || (qedi_ep->state != EP_STATE_OFLDCONN_COMPL)) {
1192 qedi_ep->state = EP_STATE_OFLDCONN_FAILED;
1193 QEDI_ERR(&qedi->dbg_ctx,
1194 "Offload conn TIMEOUT iscsi_cid=%u, qedi_ep=%p\n",
1195 qedi_ep->iscsi_cid, qedi_ep);
1199 static int qedi_set_path(struct Scsi_Host *shost, struct iscsi_path *path_data)
1201 struct qedi_ctx *qedi;
1202 struct qedi_endpoint *qedi_ep;
1209 QEDI_ERR(NULL, "shost is NULL\n");
1213 if (strcmp(shost->hostt->proc_name, "qedi")) {
1215 QEDI_ERR(NULL, "shost %s is invalid\n",
1216 shost->hostt->proc_name);
1220 qedi = iscsi_host_priv(shost);
1221 if (path_data->handle == QEDI_PATH_HANDLE) {
1222 ret = qedi_data_avail(qedi, path_data->vlan_id);
1226 iscsi_cid = (u32)path_data->handle;
1227 qedi_ep = qedi->ep_tbl[iscsi_cid];
1228 QEDI_INFO(&qedi->dbg_ctx, QEDI_LOG_CONN,
1229 "iscsi_cid=0x%x, qedi_ep=%p\n", iscsi_cid, qedi_ep);
1231 if (!is_valid_ether_addr(&path_data->mac_addr[0])) {
1232 QEDI_NOTICE(&qedi->dbg_ctx, "dst mac NOT VALID\n");
1237 ether_addr_copy(&qedi_ep->src_mac[0], &qedi->mac[0]);
1238 ether_addr_copy(&qedi_ep->dst_mac[0], &path_data->mac_addr[0]);
1240 qedi_ep->vlan_id = path_data->vlan_id;
1241 if (path_data->pmtu < DEF_PATH_MTU) {
1242 qedi_ep->pmtu = qedi->ll2_mtu;
1243 QEDI_INFO(&qedi->dbg_ctx, QEDI_LOG_INFO,
1244 "MTU cannot be %u, using default MTU %u\n",
1245 path_data->pmtu, qedi_ep->pmtu);
1248 if (path_data->pmtu != qedi->ll2_mtu) {
1249 if (path_data->pmtu > JUMBO_MTU) {
1251 QEDI_ERR(NULL, "Invalid MTU %u\n", path_data->pmtu);
1255 qedi_reset_host_mtu(qedi, path_data->pmtu);
1256 qedi_ep->pmtu = qedi->ll2_mtu;
1259 port_id = qedi_ep->src_port;
1260 if (port_id >= QEDI_LOCAL_PORT_MIN &&
1261 port_id < QEDI_LOCAL_PORT_MAX) {
1262 if (qedi_alloc_id(&qedi->lcl_port_tbl, port_id))
1269 port_id = qedi_alloc_new_id(&qedi->lcl_port_tbl);
1270 if (port_id == QEDI_LOCAL_PORT_INVALID) {
1271 QEDI_ERR(&qedi->dbg_ctx,
1272 "Failed to allocate port id for iscsi_cid=0x%x\n",
1279 qedi_ep->src_port = port_id;
1281 if (qedi_ep->ip_type == TCP_IPV4) {
1282 memcpy(&qedi_ep->src_addr[0], &path_data->src.v4_addr,
1283 sizeof(struct in_addr));
1284 memcpy(&qedi->src_ip[0], &path_data->src.v4_addr,
1285 sizeof(struct in_addr));
1286 qedi->ip_type = TCP_IPV4;
1288 QEDI_INFO(&qedi->dbg_ctx, QEDI_LOG_CONN,
1289 "src addr:port=%pI4:%u, dst addr:port=%pI4:%u\n",
1290 qedi_ep->src_addr, qedi_ep->src_port,
1291 qedi_ep->dst_addr, qedi_ep->dst_port);
1293 memcpy(&qedi_ep->src_addr[0], &path_data->src.v6_addr,
1294 sizeof(struct in6_addr));
1295 memcpy(&qedi->src_ip[0], &path_data->src.v6_addr,
1296 sizeof(struct in6_addr));
1297 qedi->ip_type = TCP_IPV6;
1299 QEDI_INFO(&qedi->dbg_ctx, QEDI_LOG_CONN,
1300 "src addr:port=%pI6:%u, dst addr:port=%pI6:%u\n",
1301 qedi_ep->src_addr, qedi_ep->src_port,
1302 qedi_ep->dst_addr, qedi_ep->dst_port);
1305 INIT_WORK(&qedi_ep->offload_work, qedi_offload_work);
1306 queue_work(qedi->offload_thread, &qedi_ep->offload_work);
1314 static umode_t qedi_attr_is_visible(int param_type, int param)
1316 switch (param_type) {
1317 case ISCSI_HOST_PARAM:
1319 case ISCSI_HOST_PARAM_NETDEV_NAME:
1320 case ISCSI_HOST_PARAM_HWADDRESS:
1321 case ISCSI_HOST_PARAM_IPADDRESS:
1328 case ISCSI_PARAM_MAX_RECV_DLENGTH:
1329 case ISCSI_PARAM_MAX_XMIT_DLENGTH:
1330 case ISCSI_PARAM_HDRDGST_EN:
1331 case ISCSI_PARAM_DATADGST_EN:
1332 case ISCSI_PARAM_CONN_ADDRESS:
1333 case ISCSI_PARAM_CONN_PORT:
1334 case ISCSI_PARAM_EXP_STATSN:
1335 case ISCSI_PARAM_PERSISTENT_ADDRESS:
1336 case ISCSI_PARAM_PERSISTENT_PORT:
1337 case ISCSI_PARAM_PING_TMO:
1338 case ISCSI_PARAM_RECV_TMO:
1339 case ISCSI_PARAM_INITIAL_R2T_EN:
1340 case ISCSI_PARAM_MAX_R2T:
1341 case ISCSI_PARAM_IMM_DATA_EN:
1342 case ISCSI_PARAM_FIRST_BURST:
1343 case ISCSI_PARAM_MAX_BURST:
1344 case ISCSI_PARAM_PDU_INORDER_EN:
1345 case ISCSI_PARAM_DATASEQ_INORDER_EN:
1346 case ISCSI_PARAM_ERL:
1347 case ISCSI_PARAM_TARGET_NAME:
1348 case ISCSI_PARAM_TPGT:
1349 case ISCSI_PARAM_USERNAME:
1350 case ISCSI_PARAM_PASSWORD:
1351 case ISCSI_PARAM_USERNAME_IN:
1352 case ISCSI_PARAM_PASSWORD_IN:
1353 case ISCSI_PARAM_FAST_ABORT:
1354 case ISCSI_PARAM_ABORT_TMO:
1355 case ISCSI_PARAM_LU_RESET_TMO:
1356 case ISCSI_PARAM_TGT_RESET_TMO:
1357 case ISCSI_PARAM_IFACE_NAME:
1358 case ISCSI_PARAM_INITIATOR_NAME:
1359 case ISCSI_PARAM_BOOT_ROOT:
1360 case ISCSI_PARAM_BOOT_NIC:
1361 case ISCSI_PARAM_BOOT_TARGET:
1371 static void qedi_cleanup_task(struct iscsi_task *task)
1373 if (!task->sc || task->state == ISCSI_TASK_PENDING) {
1374 QEDI_INFO(NULL, QEDI_LOG_IO, "Returning ref_cnt=%d\n",
1375 atomic_read(&task->refcount));
1379 qedi_iscsi_unmap_sg_list(task->dd_data);
1382 struct iscsi_transport qedi_iscsi_transport = {
1383 .owner = THIS_MODULE,
1384 .name = QEDI_MODULE_NAME,
1385 .caps = CAP_RECOVERY_L0 | CAP_HDRDGST | CAP_MULTI_R2T | CAP_DATADGST |
1386 CAP_DATA_PATH_OFFLOAD | CAP_TEXT_NEGO,
1387 .create_session = qedi_session_create,
1388 .destroy_session = qedi_session_destroy,
1389 .create_conn = qedi_conn_create,
1390 .bind_conn = qedi_conn_bind,
1391 .start_conn = qedi_conn_start,
1392 .stop_conn = iscsi_conn_stop,
1393 .destroy_conn = qedi_conn_destroy,
1394 .set_param = iscsi_set_param,
1395 .get_ep_param = qedi_ep_get_param,
1396 .get_conn_param = iscsi_conn_get_param,
1397 .get_session_param = iscsi_session_get_param,
1398 .get_host_param = qedi_host_get_param,
1399 .send_pdu = iscsi_conn_send_pdu,
1400 .get_stats = qedi_conn_get_stats,
1401 .xmit_task = qedi_task_xmit,
1402 .cleanup_task = qedi_cleanup_task,
1403 .session_recovery_timedout = iscsi_session_recovery_timedout,
1404 .ep_connect = qedi_ep_connect,
1405 .ep_poll = qedi_ep_poll,
1406 .ep_disconnect = qedi_ep_disconnect,
1407 .set_path = qedi_set_path,
1408 .attr_is_visible = qedi_attr_is_visible,
1411 void qedi_start_conn_recovery(struct qedi_ctx *qedi,
1412 struct qedi_conn *qedi_conn)
1414 struct iscsi_cls_session *cls_sess;
1415 struct iscsi_cls_conn *cls_conn;
1416 struct iscsi_conn *conn;
1418 cls_conn = qedi_conn->cls_conn;
1419 conn = cls_conn->dd_data;
1420 cls_sess = iscsi_conn_to_session(cls_conn);
1422 if (iscsi_is_session_online(cls_sess)) {
1423 qedi_conn->abrt_conn = 1;
1424 QEDI_ERR(&qedi->dbg_ctx,
1425 "Failing connection, state=0x%x, cid=0x%x\n",
1426 conn->session->state, qedi_conn->iscsi_conn_id);
1427 iscsi_conn_failure(qedi_conn->cls_conn->dd_data,
1428 ISCSI_ERR_CONN_FAILED);
1432 static const struct {
1433 enum iscsi_error_types error_code;
1435 } qedi_iscsi_error[] = {
1436 { ISCSI_STATUS_NONE,
1439 { ISCSI_CONN_ERROR_TASK_CID_MISMATCH,
1442 { ISCSI_CONN_ERROR_TASK_NOT_VALID,
1445 { ISCSI_CONN_ERROR_RQ_RING_IS_FULL,
1448 { ISCSI_CONN_ERROR_CMDQ_RING_IS_FULL,
1451 { ISCSI_CONN_ERROR_HQE_CACHING_FAILED,
1452 "sge caching failed"
1454 { ISCSI_CONN_ERROR_HEADER_DIGEST_ERROR,
1457 { ISCSI_CONN_ERROR_LOCAL_COMPLETION_ERROR,
1460 { ISCSI_CONN_ERROR_DATA_OVERRUN,
1463 { ISCSI_CONN_ERROR_OUT_OF_SGES_ERROR,
1466 { ISCSI_CONN_ERROR_TCP_SEG_PROC_IP_OPTIONS_ERROR,
1467 "tcp seg ip options error"
1469 { ISCSI_CONN_ERROR_TCP_IP_FRAGMENT_ERROR,
1470 "tcp ip fragment error"
1472 { ISCSI_CONN_ERROR_PROTOCOL_ERR_AHS_LEN,
1473 "AHS len protocol error"
1475 { ISCSI_CONN_ERROR_PROTOCOL_ERR_ITT_OUT_OF_RANGE,
1476 "itt out of range error"
1478 { ISCSI_CONN_ERROR_PROTOCOL_ERR_DATA_SEG_LEN_EXCEEDS_PDU_SIZE,
1479 "data seg more than pdu size"
1481 { ISCSI_CONN_ERROR_PROTOCOL_ERR_INVALID_OPCODE,
1484 { ISCSI_CONN_ERROR_PROTOCOL_ERR_INVALID_OPCODE_BEFORE_UPDATE,
1485 "invalid opcode before update"
1487 { ISCSI_CONN_ERROR_UNVALID_NOPIN_DSL,
1490 { ISCSI_CONN_ERROR_PROTOCOL_ERR_R2T_CARRIES_NO_DATA,
1491 "r2t carries no data"
1493 { ISCSI_CONN_ERROR_PROTOCOL_ERR_DATA_SN,
1496 { ISCSI_CONN_ERROR_PROTOCOL_ERR_DATA_IN_TTT,
1499 { ISCSI_CONN_ERROR_PROTOCOL_ERR_R2T_TTT,
1502 { ISCSI_CONN_ERROR_PROTOCOL_ERR_R2T_BUFFER_OFFSET,
1503 "buffer offset error"
1505 { ISCSI_CONN_ERROR_PROTOCOL_ERR_BUFFER_OFFSET_OOO,
1508 { ISCSI_CONN_ERROR_PROTOCOL_ERR_R2T_SN,
1511 { ISCSI_CONN_ERROR_PROTOCOL_ERR_DESIRED_DATA_TRNS_LEN_0,
1512 "data xer len error"
1514 { ISCSI_CONN_ERROR_PROTOCOL_ERR_DESIRED_DATA_TRNS_LEN_1,
1515 "data xer len1 error"
1517 { ISCSI_CONN_ERROR_PROTOCOL_ERR_DESIRED_DATA_TRNS_LEN_2,
1518 "data xer len2 error"
1520 { ISCSI_CONN_ERROR_PROTOCOL_ERR_LUN,
1521 "protocol lun error"
1523 { ISCSI_CONN_ERROR_PROTOCOL_ERR_F_BIT_ZERO,
1526 { ISCSI_CONN_ERROR_PROTOCOL_ERR_EXP_STAT_SN,
1529 { ISCSI_CONN_ERROR_PROTOCOL_ERR_DSL_NOT_ZERO,
1530 "dsl not zero error"
1532 { ISCSI_CONN_ERROR_PROTOCOL_ERR_INVALID_DSL,
1535 { ISCSI_CONN_ERROR_PROTOCOL_ERR_DATA_SEG_LEN_TOO_BIG,
1536 "data seg len too big"
1538 { ISCSI_CONN_ERROR_PROTOCOL_ERR_OUTSTANDING_R2T_COUNT,
1539 "outstanding r2t count error"
1541 { ISCSI_CONN_ERROR_SENSE_DATA_LENGTH,
1542 "sense datalen error"
1546 char *qedi_get_iscsi_error(enum iscsi_error_types err_code)
1551 for (i = 0; i < ARRAY_SIZE(qedi_iscsi_error); i++) {
1552 if (qedi_iscsi_error[i].error_code == err_code) {
1553 msg = qedi_iscsi_error[i].err_string;
1560 void qedi_process_iscsi_error(struct qedi_endpoint *ep, struct async_data *data)
1562 struct qedi_conn *qedi_conn;
1563 struct qedi_ctx *qedi;
1564 char warn_notice[] = "iscsi_warning";
1565 char error_notice[] = "iscsi_error";
1566 char unknown_msg[] = "Unknown error";
1568 int need_recovery = 0;
1575 qedi_conn = ep->conn;
1581 QEDI_ERR(&qedi->dbg_ctx, "async event iscsi error:0x%x\n",
1586 message = warn_notice;
1589 message = error_notice;
1592 msg = qedi_get_iscsi_error(data->error_code);
1598 iscsi_conn_printk(KERN_ALERT,
1599 qedi_conn->cls_conn->dd_data,
1600 "qedi: %s - %s\n", message, msg);
1603 qedi_start_conn_recovery(qedi_conn->qedi, qedi_conn);
1606 void qedi_process_tcp_error(struct qedi_endpoint *ep, struct async_data *data)
1608 struct qedi_conn *qedi_conn;
1613 qedi_conn = ep->conn;
1617 QEDI_ERR(&ep->qedi->dbg_ctx, "async event TCP error:0x%x\n",
1620 qedi_start_conn_recovery(qedi_conn->qedi, qedi_conn);