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,
62 .dma_boundary = QEDI_HW_DMA_BOUNDARY,
64 .use_clustering = ENABLE_CLUSTERING,
65 .shost_attrs = qedi_shost_attrs,
68 static void qedi_conn_free_login_resources(struct qedi_ctx *qedi,
69 struct qedi_conn *qedi_conn)
71 if (qedi_conn->gen_pdu.resp_bd_tbl) {
72 dma_free_coherent(&qedi->pdev->dev, QEDI_PAGE_SIZE,
73 qedi_conn->gen_pdu.resp_bd_tbl,
74 qedi_conn->gen_pdu.resp_bd_dma);
75 qedi_conn->gen_pdu.resp_bd_tbl = NULL;
78 if (qedi_conn->gen_pdu.req_bd_tbl) {
79 dma_free_coherent(&qedi->pdev->dev, QEDI_PAGE_SIZE,
80 qedi_conn->gen_pdu.req_bd_tbl,
81 qedi_conn->gen_pdu.req_bd_dma);
82 qedi_conn->gen_pdu.req_bd_tbl = NULL;
85 if (qedi_conn->gen_pdu.resp_buf) {
86 dma_free_coherent(&qedi->pdev->dev,
87 ISCSI_DEF_MAX_RECV_SEG_LEN,
88 qedi_conn->gen_pdu.resp_buf,
89 qedi_conn->gen_pdu.resp_dma_addr);
90 qedi_conn->gen_pdu.resp_buf = NULL;
93 if (qedi_conn->gen_pdu.req_buf) {
94 dma_free_coherent(&qedi->pdev->dev,
95 ISCSI_DEF_MAX_RECV_SEG_LEN,
96 qedi_conn->gen_pdu.req_buf,
97 qedi_conn->gen_pdu.req_dma_addr);
98 qedi_conn->gen_pdu.req_buf = NULL;
102 static int qedi_conn_alloc_login_resources(struct qedi_ctx *qedi,
103 struct qedi_conn *qedi_conn)
105 qedi_conn->gen_pdu.req_buf =
106 dma_alloc_coherent(&qedi->pdev->dev,
107 ISCSI_DEF_MAX_RECV_SEG_LEN,
108 &qedi_conn->gen_pdu.req_dma_addr,
110 if (!qedi_conn->gen_pdu.req_buf)
111 goto login_req_buf_failure;
113 qedi_conn->gen_pdu.req_buf_size = 0;
114 qedi_conn->gen_pdu.req_wr_ptr = qedi_conn->gen_pdu.req_buf;
116 qedi_conn->gen_pdu.resp_buf =
117 dma_alloc_coherent(&qedi->pdev->dev,
118 ISCSI_DEF_MAX_RECV_SEG_LEN,
119 &qedi_conn->gen_pdu.resp_dma_addr,
121 if (!qedi_conn->gen_pdu.resp_buf)
122 goto login_resp_buf_failure;
124 qedi_conn->gen_pdu.resp_buf_size = ISCSI_DEF_MAX_RECV_SEG_LEN;
125 qedi_conn->gen_pdu.resp_wr_ptr = qedi_conn->gen_pdu.resp_buf;
127 qedi_conn->gen_pdu.req_bd_tbl =
128 dma_alloc_coherent(&qedi->pdev->dev, QEDI_PAGE_SIZE,
129 &qedi_conn->gen_pdu.req_bd_dma, GFP_KERNEL);
130 if (!qedi_conn->gen_pdu.req_bd_tbl)
131 goto login_req_bd_tbl_failure;
133 qedi_conn->gen_pdu.resp_bd_tbl =
134 dma_alloc_coherent(&qedi->pdev->dev, QEDI_PAGE_SIZE,
135 &qedi_conn->gen_pdu.resp_bd_dma,
137 if (!qedi_conn->gen_pdu.resp_bd_tbl)
138 goto login_resp_bd_tbl_failure;
140 QEDI_INFO(&qedi->dbg_ctx, QEDI_LOG_SESS,
141 "Allocation successful, cid=0x%x\n",
142 qedi_conn->iscsi_conn_id);
145 login_resp_bd_tbl_failure:
146 dma_free_coherent(&qedi->pdev->dev, QEDI_PAGE_SIZE,
147 qedi_conn->gen_pdu.req_bd_tbl,
148 qedi_conn->gen_pdu.req_bd_dma);
149 qedi_conn->gen_pdu.req_bd_tbl = NULL;
151 login_req_bd_tbl_failure:
152 dma_free_coherent(&qedi->pdev->dev, ISCSI_DEF_MAX_RECV_SEG_LEN,
153 qedi_conn->gen_pdu.resp_buf,
154 qedi_conn->gen_pdu.resp_dma_addr);
155 qedi_conn->gen_pdu.resp_buf = NULL;
156 login_resp_buf_failure:
157 dma_free_coherent(&qedi->pdev->dev, ISCSI_DEF_MAX_RECV_SEG_LEN,
158 qedi_conn->gen_pdu.req_buf,
159 qedi_conn->gen_pdu.req_dma_addr);
160 qedi_conn->gen_pdu.req_buf = NULL;
161 login_req_buf_failure:
162 iscsi_conn_printk(KERN_ERR, qedi_conn->cls_conn->dd_data,
163 "login resource alloc failed!!\n");
167 static void qedi_destroy_cmd_pool(struct qedi_ctx *qedi,
168 struct iscsi_session *session)
172 for (i = 0; i < session->cmds_max; i++) {
173 struct iscsi_task *task = session->cmds[i];
174 struct qedi_cmd *cmd = task->dd_data;
176 if (cmd->io_tbl.sge_tbl)
177 dma_free_coherent(&qedi->pdev->dev,
178 QEDI_ISCSI_MAX_BDS_PER_CMD *
179 sizeof(struct scsi_sge),
181 cmd->io_tbl.sge_tbl_dma);
183 if (cmd->sense_buffer)
184 dma_free_coherent(&qedi->pdev->dev,
185 SCSI_SENSE_BUFFERSIZE,
187 cmd->sense_buffer_dma);
191 static int qedi_alloc_sget(struct qedi_ctx *qedi, struct iscsi_session *session,
192 struct qedi_cmd *cmd)
194 struct qedi_io_bdt *io = &cmd->io_tbl;
195 struct scsi_sge *sge;
197 io->sge_tbl = dma_alloc_coherent(&qedi->pdev->dev,
198 QEDI_ISCSI_MAX_BDS_PER_CMD *
200 &io->sge_tbl_dma, GFP_KERNEL);
202 iscsi_session_printk(KERN_ERR, session,
203 "Could not allocate BD table.\n");
211 static int qedi_setup_cmd_pool(struct qedi_ctx *qedi,
212 struct iscsi_session *session)
216 for (i = 0; i < session->cmds_max; i++) {
217 struct iscsi_task *task = session->cmds[i];
218 struct qedi_cmd *cmd = task->dd_data;
220 task->hdr = &cmd->hdr;
221 task->hdr_max = sizeof(struct iscsi_hdr);
223 if (qedi_alloc_sget(qedi, session, cmd))
226 cmd->sense_buffer = dma_alloc_coherent(&qedi->pdev->dev,
227 SCSI_SENSE_BUFFERSIZE,
228 &cmd->sense_buffer_dma,
230 if (!cmd->sense_buffer)
237 qedi_destroy_cmd_pool(qedi, session);
241 static struct iscsi_cls_session *
242 qedi_session_create(struct iscsi_endpoint *ep, u16 cmds_max,
243 u16 qdepth, uint32_t initial_cmdsn)
245 struct Scsi_Host *shost;
246 struct iscsi_cls_session *cls_session;
247 struct qedi_ctx *qedi;
248 struct qedi_endpoint *qedi_ep;
253 qedi_ep = ep->dd_data;
254 shost = qedi_ep->qedi->shost;
255 qedi = iscsi_host_priv(shost);
257 if (cmds_max > qedi->max_sqes)
258 cmds_max = qedi->max_sqes;
259 else if (cmds_max < QEDI_SQ_WQES_MIN)
260 cmds_max = QEDI_SQ_WQES_MIN;
262 cls_session = iscsi_session_setup(&qedi_iscsi_transport, shost,
263 cmds_max, 0, sizeof(struct qedi_cmd),
264 initial_cmdsn, ISCSI_MAX_TARGET);
266 QEDI_ERR(&qedi->dbg_ctx,
267 "Failed to setup session for ep=%p\n", qedi_ep);
271 if (qedi_setup_cmd_pool(qedi, cls_session->dd_data)) {
272 QEDI_ERR(&qedi->dbg_ctx,
273 "Failed to setup cmd pool for ep=%p\n", qedi_ep);
274 goto session_teardown;
280 iscsi_session_teardown(cls_session);
284 static void qedi_session_destroy(struct iscsi_cls_session *cls_session)
286 struct iscsi_session *session = cls_session->dd_data;
287 struct Scsi_Host *shost = iscsi_session_to_shost(cls_session);
288 struct qedi_ctx *qedi = iscsi_host_priv(shost);
290 qedi_destroy_cmd_pool(qedi, session);
291 iscsi_session_teardown(cls_session);
294 static struct iscsi_cls_conn *
295 qedi_conn_create(struct iscsi_cls_session *cls_session, uint32_t cid)
297 struct Scsi_Host *shost = iscsi_session_to_shost(cls_session);
298 struct qedi_ctx *qedi = iscsi_host_priv(shost);
299 struct iscsi_cls_conn *cls_conn;
300 struct qedi_conn *qedi_conn;
301 struct iscsi_conn *conn;
303 cls_conn = iscsi_conn_setup(cls_session, sizeof(*qedi_conn),
306 QEDI_ERR(&qedi->dbg_ctx,
307 "conn_new: iscsi conn setup failed, cid=0x%x, cls_sess=%p!\n",
312 conn = cls_conn->dd_data;
313 qedi_conn = conn->dd_data;
314 qedi_conn->cls_conn = cls_conn;
315 qedi_conn->qedi = qedi;
316 qedi_conn->ep = NULL;
317 qedi_conn->active_cmd_count = 0;
318 INIT_LIST_HEAD(&qedi_conn->active_cmd_list);
319 spin_lock_init(&qedi_conn->list_lock);
321 if (qedi_conn_alloc_login_resources(qedi, qedi_conn)) {
322 iscsi_conn_printk(KERN_ALERT, conn,
323 "conn_new: login resc alloc failed, cid=0x%x, cls_sess=%p!!\n",
331 iscsi_conn_teardown(cls_conn);
335 void qedi_mark_device_missing(struct iscsi_cls_session *cls_session)
337 iscsi_block_session(cls_session);
340 void qedi_mark_device_available(struct iscsi_cls_session *cls_session)
342 iscsi_unblock_session(cls_session);
345 static int qedi_bind_conn_to_iscsi_cid(struct qedi_ctx *qedi,
346 struct qedi_conn *qedi_conn)
348 u32 iscsi_cid = qedi_conn->iscsi_conn_id;
350 if (qedi->cid_que.conn_cid_tbl[iscsi_cid]) {
351 iscsi_conn_printk(KERN_ALERT, qedi_conn->cls_conn->dd_data,
352 "conn bind - entry #%d not free\n",
357 qedi->cid_que.conn_cid_tbl[iscsi_cid] = qedi_conn;
361 struct qedi_conn *qedi_get_conn_from_id(struct qedi_ctx *qedi, u32 iscsi_cid)
363 if (!qedi->cid_que.conn_cid_tbl) {
364 QEDI_ERR(&qedi->dbg_ctx, "missing conn<->cid table\n");
367 } else if (iscsi_cid >= qedi->max_active_conns) {
368 QEDI_ERR(&qedi->dbg_ctx, "wrong cid #%d\n", iscsi_cid);
371 return qedi->cid_que.conn_cid_tbl[iscsi_cid];
374 static int qedi_conn_bind(struct iscsi_cls_session *cls_session,
375 struct iscsi_cls_conn *cls_conn,
376 u64 transport_fd, int is_leading)
378 struct iscsi_conn *conn = cls_conn->dd_data;
379 struct qedi_conn *qedi_conn = conn->dd_data;
380 struct Scsi_Host *shost = iscsi_session_to_shost(cls_session);
381 struct qedi_ctx *qedi = iscsi_host_priv(shost);
382 struct qedi_endpoint *qedi_ep;
383 struct iscsi_endpoint *ep;
385 ep = iscsi_lookup_endpoint(transport_fd);
389 qedi_ep = ep->dd_data;
390 if ((qedi_ep->state == EP_STATE_TCP_FIN_RCVD) ||
391 (qedi_ep->state == EP_STATE_TCP_RST_RCVD))
394 if (iscsi_conn_bind(cls_session, cls_conn, is_leading))
397 qedi_ep->conn = qedi_conn;
398 qedi_conn->ep = qedi_ep;
399 qedi_conn->iscsi_conn_id = qedi_ep->iscsi_cid;
400 qedi_conn->fw_cid = qedi_ep->fw_cid;
401 qedi_conn->cmd_cleanup_req = 0;
402 qedi_conn->cmd_cleanup_cmpl = 0;
404 if (qedi_bind_conn_to_iscsi_cid(qedi, qedi_conn))
407 spin_lock_init(&qedi_conn->tmf_work_lock);
408 INIT_LIST_HEAD(&qedi_conn->tmf_work_list);
409 init_waitqueue_head(&qedi_conn->wait_queue);
413 static int qedi_iscsi_update_conn(struct qedi_ctx *qedi,
414 struct qedi_conn *qedi_conn)
416 struct qed_iscsi_params_update *conn_info;
417 struct iscsi_cls_conn *cls_conn = qedi_conn->cls_conn;
418 struct iscsi_conn *conn = cls_conn->dd_data;
419 struct qedi_endpoint *qedi_ep;
422 qedi_ep = qedi_conn->ep;
424 conn_info = kzalloc(sizeof(*conn_info), GFP_KERNEL);
426 QEDI_ERR(&qedi->dbg_ctx, "memory alloc failed\n");
430 conn_info->update_flag = 0;
432 if (conn->hdrdgst_en)
433 SET_FIELD(conn_info->update_flag,
434 ISCSI_CONN_UPDATE_RAMROD_PARAMS_HD_EN, true);
435 if (conn->datadgst_en)
436 SET_FIELD(conn_info->update_flag,
437 ISCSI_CONN_UPDATE_RAMROD_PARAMS_DD_EN, true);
438 if (conn->session->initial_r2t_en)
439 SET_FIELD(conn_info->update_flag,
440 ISCSI_CONN_UPDATE_RAMROD_PARAMS_INITIAL_R2T,
442 if (conn->session->imm_data_en)
443 SET_FIELD(conn_info->update_flag,
444 ISCSI_CONN_UPDATE_RAMROD_PARAMS_IMMEDIATE_DATA,
447 conn_info->max_seq_size = conn->session->max_burst;
448 conn_info->max_recv_pdu_length = conn->max_recv_dlength;
449 conn_info->max_send_pdu_length = conn->max_xmit_dlength;
450 conn_info->first_seq_length = conn->session->first_burst;
451 conn_info->exp_stat_sn = conn->exp_statsn;
453 rval = qedi_ops->update_conn(qedi->cdev, qedi_ep->handle,
457 QEDI_ERR(&qedi->dbg_ctx, "Could not update connection\n");
464 static u16 qedi_calc_mss(u16 pmtu, u8 is_ipv6, u8 tcp_ts_en, u8 vlan_en)
467 u16 hdrs = TCP_HDR_LEN;
470 hdrs += IPV6_HDR_LEN;
472 hdrs += IPV4_HDR_LEN;
480 mss -= TCP_OPTION_LEN;
488 static int qedi_iscsi_offload_conn(struct qedi_endpoint *qedi_ep)
490 struct qedi_ctx *qedi = qedi_ep->qedi;
491 struct qed_iscsi_params_offload *conn_info;
495 conn_info = kzalloc(sizeof(*conn_info), GFP_KERNEL);
497 QEDI_ERR(&qedi->dbg_ctx,
498 "Failed to allocate memory ep=%p\n", qedi_ep);
502 ether_addr_copy(conn_info->src.mac, qedi_ep->src_mac);
503 ether_addr_copy(conn_info->dst.mac, qedi_ep->dst_mac);
505 conn_info->src.ip[0] = ntohl(qedi_ep->src_addr[0]);
506 conn_info->dst.ip[0] = ntohl(qedi_ep->dst_addr[0]);
508 if (qedi_ep->ip_type == TCP_IPV4) {
509 conn_info->ip_version = 0;
510 QEDI_INFO(&qedi->dbg_ctx, QEDI_LOG_CONN,
511 "After ntohl: src_addr=%pI4, dst_addr=%pI4\n",
512 qedi_ep->src_addr, qedi_ep->dst_addr);
514 for (i = 1; i < 4; i++) {
515 conn_info->src.ip[i] = ntohl(qedi_ep->src_addr[i]);
516 conn_info->dst.ip[i] = ntohl(qedi_ep->dst_addr[i]);
519 conn_info->ip_version = 1;
520 QEDI_INFO(&qedi->dbg_ctx, QEDI_LOG_CONN,
521 "After ntohl: src_addr=%pI6, dst_addr=%pI6\n",
522 qedi_ep->src_addr, qedi_ep->dst_addr);
525 conn_info->src.port = qedi_ep->src_port;
526 conn_info->dst.port = qedi_ep->dst_port;
528 conn_info->layer_code = ISCSI_SLOW_PATH_LAYER_CODE;
529 conn_info->sq_pbl_addr = qedi_ep->sq_pbl_dma;
530 conn_info->vlan_id = qedi_ep->vlan_id;
532 SET_FIELD(conn_info->tcp_flags, TCP_OFFLOAD_PARAMS_TS_EN, 1);
533 SET_FIELD(conn_info->tcp_flags, TCP_OFFLOAD_PARAMS_DA_EN, 1);
534 SET_FIELD(conn_info->tcp_flags, TCP_OFFLOAD_PARAMS_DA_CNT_EN, 1);
535 SET_FIELD(conn_info->tcp_flags, TCP_OFFLOAD_PARAMS_KA_EN, 1);
537 conn_info->default_cq = (qedi_ep->fw_cid % qedi->num_queues);
539 conn_info->ka_max_probe_cnt = DEF_KA_MAX_PROBE_COUNT;
540 conn_info->dup_ack_theshold = 3;
541 conn_info->rcv_wnd = 65535;
542 conn_info->cwnd = DEF_MAX_CWND;
544 conn_info->ss_thresh = 65535;
545 conn_info->srtt = 300;
546 conn_info->rtt_var = 150;
547 conn_info->flow_label = 0;
548 conn_info->ka_timeout = DEF_KA_TIMEOUT;
549 conn_info->ka_interval = DEF_KA_INTERVAL;
550 conn_info->max_rt_time = DEF_MAX_RT_TIME;
551 conn_info->ttl = DEF_TTL;
552 conn_info->tos_or_tc = DEF_TOS;
553 conn_info->remote_port = qedi_ep->dst_port;
554 conn_info->local_port = qedi_ep->src_port;
556 conn_info->mss = qedi_calc_mss(qedi_ep->pmtu,
557 (qedi_ep->ip_type == TCP_IPV6),
558 1, (qedi_ep->vlan_id != 0));
560 conn_info->rcv_wnd_scale = 4;
561 conn_info->ts_ticks_per_second = 1000;
562 conn_info->da_timeout_value = 200;
563 conn_info->ack_frequency = 2;
565 QEDI_INFO(&qedi->dbg_ctx, QEDI_LOG_INFO,
566 "Default cq index [%d], mss [%d]\n",
567 conn_info->default_cq, conn_info->mss);
569 rval = qedi_ops->offload_conn(qedi->cdev, qedi_ep->handle, conn_info);
571 QEDI_ERR(&qedi->dbg_ctx, "offload_conn returned %d, ep=%p\n",
578 static int qedi_conn_start(struct iscsi_cls_conn *cls_conn)
580 struct iscsi_conn *conn = cls_conn->dd_data;
581 struct qedi_conn *qedi_conn = conn->dd_data;
582 struct qedi_ctx *qedi;
585 qedi = qedi_conn->qedi;
587 rval = qedi_iscsi_update_conn(qedi, qedi_conn);
589 iscsi_conn_printk(KERN_ALERT, conn,
590 "conn_start: FW oflload conn failed.\n");
595 clear_bit(QEDI_CONN_FW_CLEANUP, &qedi_conn->flags);
596 qedi_conn->abrt_conn = 0;
598 rval = iscsi_conn_start(cls_conn);
600 iscsi_conn_printk(KERN_ALERT, conn,
601 "iscsi_conn_start: FW oflload conn failed!!\n");
608 static void qedi_conn_destroy(struct iscsi_cls_conn *cls_conn)
610 struct iscsi_conn *conn = cls_conn->dd_data;
611 struct qedi_conn *qedi_conn = conn->dd_data;
612 struct Scsi_Host *shost;
613 struct qedi_ctx *qedi;
615 shost = iscsi_session_to_shost(iscsi_conn_to_session(cls_conn));
616 qedi = iscsi_host_priv(shost);
618 qedi_conn_free_login_resources(qedi, qedi_conn);
619 iscsi_conn_teardown(cls_conn);
622 static int qedi_ep_get_param(struct iscsi_endpoint *ep,
623 enum iscsi_param param, char *buf)
625 struct qedi_endpoint *qedi_ep = ep->dd_data;
632 case ISCSI_PARAM_CONN_PORT:
633 len = sprintf(buf, "%hu\n", qedi_ep->dst_port);
635 case ISCSI_PARAM_CONN_ADDRESS:
636 if (qedi_ep->ip_type == TCP_IPV4)
637 len = sprintf(buf, "%pI4\n", qedi_ep->dst_addr);
639 len = sprintf(buf, "%pI6\n", qedi_ep->dst_addr);
648 static int qedi_host_get_param(struct Scsi_Host *shost,
649 enum iscsi_host_param param, char *buf)
651 struct qedi_ctx *qedi;
654 qedi = iscsi_host_priv(shost);
657 case ISCSI_HOST_PARAM_HWADDRESS:
658 len = sysfs_format_mac(buf, qedi->mac, 6);
660 case ISCSI_HOST_PARAM_NETDEV_NAME:
661 len = sprintf(buf, "host%d\n", shost->host_no);
663 case ISCSI_HOST_PARAM_IPADDRESS:
664 if (qedi->ip_type == TCP_IPV4)
665 len = sprintf(buf, "%pI4\n", qedi->src_ip);
667 len = sprintf(buf, "%pI6\n", qedi->src_ip);
670 return iscsi_host_get_param(shost, param, buf);
676 static void qedi_conn_get_stats(struct iscsi_cls_conn *cls_conn,
677 struct iscsi_stats *stats)
679 struct iscsi_conn *conn = cls_conn->dd_data;
680 struct qed_iscsi_stats iscsi_stats;
681 struct Scsi_Host *shost;
682 struct qedi_ctx *qedi;
684 shost = iscsi_session_to_shost(iscsi_conn_to_session(cls_conn));
685 qedi = iscsi_host_priv(shost);
686 qedi_ops->get_stats(qedi->cdev, &iscsi_stats);
688 conn->txdata_octets = iscsi_stats.iscsi_tx_bytes_cnt;
689 conn->rxdata_octets = iscsi_stats.iscsi_rx_bytes_cnt;
690 conn->dataout_pdus_cnt = (uint32_t)iscsi_stats.iscsi_tx_data_pdu_cnt;
691 conn->datain_pdus_cnt = (uint32_t)iscsi_stats.iscsi_rx_data_pdu_cnt;
692 conn->r2t_pdus_cnt = (uint32_t)iscsi_stats.iscsi_rx_r2t_pdu_cnt;
694 stats->txdata_octets = conn->txdata_octets;
695 stats->rxdata_octets = conn->rxdata_octets;
696 stats->scsicmd_pdus = conn->scsicmd_pdus_cnt;
697 stats->dataout_pdus = conn->dataout_pdus_cnt;
698 stats->scsirsp_pdus = conn->scsirsp_pdus_cnt;
699 stats->datain_pdus = conn->datain_pdus_cnt;
700 stats->r2t_pdus = conn->r2t_pdus_cnt;
701 stats->tmfcmd_pdus = conn->tmfcmd_pdus_cnt;
702 stats->tmfrsp_pdus = conn->tmfrsp_pdus_cnt;
703 stats->digest_err = 0;
704 stats->timeout_err = 0;
705 strcpy(stats->custom[0].desc, "eh_abort_cnt");
706 stats->custom[0].value = conn->eh_abort_cnt;
707 stats->custom_length = 1;
710 static void qedi_iscsi_prep_generic_pdu_bd(struct qedi_conn *qedi_conn)
712 struct scsi_sge *bd_tbl;
714 bd_tbl = (struct scsi_sge *)qedi_conn->gen_pdu.req_bd_tbl;
716 bd_tbl->sge_addr.hi =
717 (u32)((u64)qedi_conn->gen_pdu.req_dma_addr >> 32);
718 bd_tbl->sge_addr.lo = (u32)qedi_conn->gen_pdu.req_dma_addr;
719 bd_tbl->sge_len = qedi_conn->gen_pdu.req_wr_ptr -
720 qedi_conn->gen_pdu.req_buf;
721 bd_tbl = (struct scsi_sge *)qedi_conn->gen_pdu.resp_bd_tbl;
722 bd_tbl->sge_addr.hi =
723 (u32)((u64)qedi_conn->gen_pdu.resp_dma_addr >> 32);
724 bd_tbl->sge_addr.lo = (u32)qedi_conn->gen_pdu.resp_dma_addr;
725 bd_tbl->sge_len = ISCSI_DEF_MAX_RECV_SEG_LEN;
728 static int qedi_iscsi_send_generic_request(struct iscsi_task *task)
730 struct qedi_cmd *cmd = task->dd_data;
731 struct qedi_conn *qedi_conn = cmd->conn;
736 qedi_iscsi_prep_generic_pdu_bd(qedi_conn);
737 switch (task->hdr->opcode & ISCSI_OPCODE_MASK) {
739 qedi_send_iscsi_login(qedi_conn, task);
741 case ISCSI_OP_NOOP_OUT:
742 data_len = qedi_conn->gen_pdu.req_buf_size;
743 buf = qedi_conn->gen_pdu.req_buf;
745 rc = qedi_send_iscsi_nopout(qedi_conn, task,
748 rc = qedi_send_iscsi_nopout(qedi_conn, task,
751 case ISCSI_OP_LOGOUT:
752 rc = qedi_send_iscsi_logout(qedi_conn, task);
754 case ISCSI_OP_SCSI_TMFUNC:
755 rc = qedi_iscsi_abort_work(qedi_conn, task);
758 rc = qedi_send_iscsi_text(qedi_conn, task);
761 iscsi_conn_printk(KERN_ALERT, qedi_conn->cls_conn->dd_data,
762 "unsupported op 0x%x\n", task->hdr->opcode);
768 static int qedi_mtask_xmit(struct iscsi_conn *conn, struct iscsi_task *task)
770 struct qedi_conn *qedi_conn = conn->dd_data;
771 struct qedi_cmd *cmd = task->dd_data;
773 memset(qedi_conn->gen_pdu.req_buf, 0, ISCSI_DEF_MAX_RECV_SEG_LEN);
775 qedi_conn->gen_pdu.req_buf_size = task->data_count;
777 if (task->data_count) {
778 memcpy(qedi_conn->gen_pdu.req_buf, task->data,
780 qedi_conn->gen_pdu.req_wr_ptr =
781 qedi_conn->gen_pdu.req_buf + task->data_count;
784 cmd->conn = conn->dd_data;
785 cmd->scsi_cmd = NULL;
786 return qedi_iscsi_send_generic_request(task);
789 static int qedi_task_xmit(struct iscsi_task *task)
791 struct iscsi_conn *conn = task->conn;
792 struct qedi_conn *qedi_conn = conn->dd_data;
793 struct qedi_cmd *cmd = task->dd_data;
794 struct scsi_cmnd *sc = task->sc;
798 cmd->use_slowpath = false;
799 cmd->conn = qedi_conn;
801 cmd->io_cmd_in_list = false;
802 INIT_LIST_HEAD(&cmd->io_cmd);
805 return qedi_mtask_xmit(conn, task);
808 return qedi_iscsi_send_ioreq(task);
811 static struct iscsi_endpoint *
812 qedi_ep_connect(struct Scsi_Host *shost, struct sockaddr *dst_addr,
815 struct qedi_ctx *qedi;
816 struct iscsi_endpoint *ep;
817 struct qedi_endpoint *qedi_ep;
818 struct sockaddr_in *addr;
819 struct sockaddr_in6 *addr6;
820 struct iscsi_path path_req;
821 u32 msg_type = ISCSI_KEVENT_IF_DOWN;
822 u32 iscsi_cid = QEDI_CID_RESERVED;
829 QEDI_ERR(NULL, "shost is NULL\n");
833 if (qedi_do_not_recover) {
838 qedi = iscsi_host_priv(shost);
840 if (test_bit(QEDI_IN_OFFLINE, &qedi->flags) ||
841 test_bit(QEDI_IN_RECOVERY, &qedi->flags)) {
846 ep = iscsi_create_endpoint(sizeof(struct qedi_endpoint));
848 QEDI_ERR(&qedi->dbg_ctx, "endpoint create fail\n");
852 qedi_ep = ep->dd_data;
853 memset(qedi_ep, 0, sizeof(struct qedi_endpoint));
854 qedi_ep->state = EP_STATE_IDLE;
855 qedi_ep->iscsi_cid = (u32)-1;
856 qedi_ep->qedi = qedi;
858 if (dst_addr->sa_family == AF_INET) {
859 addr = (struct sockaddr_in *)dst_addr;
860 memcpy(qedi_ep->dst_addr, &addr->sin_addr.s_addr,
861 sizeof(struct in_addr));
862 qedi_ep->dst_port = ntohs(addr->sin_port);
863 qedi_ep->ip_type = TCP_IPV4;
864 QEDI_INFO(&qedi->dbg_ctx, QEDI_LOG_CONN,
865 "dst_addr=%pI4, dst_port=%u\n",
866 qedi_ep->dst_addr, qedi_ep->dst_port);
867 } else if (dst_addr->sa_family == AF_INET6) {
868 addr6 = (struct sockaddr_in6 *)dst_addr;
869 memcpy(qedi_ep->dst_addr, &addr6->sin6_addr,
870 sizeof(struct in6_addr));
871 qedi_ep->dst_port = ntohs(addr6->sin6_port);
872 qedi_ep->ip_type = TCP_IPV6;
873 QEDI_INFO(&qedi->dbg_ctx, QEDI_LOG_CONN,
874 "dst_addr=%pI6, dst_port=%u\n",
875 qedi_ep->dst_addr, qedi_ep->dst_port);
877 QEDI_ERR(&qedi->dbg_ctx, "Invalid endpoint\n");
880 if (atomic_read(&qedi->link_state) != QEDI_LINK_UP) {
881 QEDI_WARN(&qedi->dbg_ctx, "qedi link down\n");
886 ret = qedi_alloc_sq(qedi, qedi_ep);
890 ret = qedi_ops->acquire_conn(qedi->cdev, &qedi_ep->handle,
891 &qedi_ep->fw_cid, &qedi_ep->p_doorbell);
894 QEDI_ERR(&qedi->dbg_ctx, "Could not acquire connection\n");
899 iscsi_cid = qedi_ep->handle;
900 qedi_ep->iscsi_cid = iscsi_cid;
902 init_waitqueue_head(&qedi_ep->ofld_wait);
903 init_waitqueue_head(&qedi_ep->tcp_ofld_wait);
904 qedi_ep->state = EP_STATE_OFLDCONN_START;
905 qedi->ep_tbl[iscsi_cid] = qedi_ep;
907 buf = (char *)&path_req;
908 len = sizeof(path_req);
909 memset(&path_req, 0, len);
911 msg_type = ISCSI_KEVENT_PATH_REQ;
912 path_req.handle = (u64)qedi_ep->iscsi_cid;
913 path_req.pmtu = qedi->ll2_mtu;
914 qedi_ep->pmtu = qedi->ll2_mtu;
915 if (qedi_ep->ip_type == TCP_IPV4) {
916 memcpy(&path_req.dst.v4_addr, &qedi_ep->dst_addr,
917 sizeof(struct in_addr));
918 path_req.ip_addr_len = 4;
920 memcpy(&path_req.dst.v6_addr, &qedi_ep->dst_addr,
921 sizeof(struct in6_addr));
922 path_req.ip_addr_len = 16;
925 ret = iscsi_offload_mesg(shost, &qedi_iscsi_transport, msg_type, buf,
928 QEDI_ERR(&qedi->dbg_ctx,
929 "iscsi_offload_mesg() failed for cid=0x%x ret=%d\n",
934 atomic_inc(&qedi->num_offloads);
938 qedi->ep_tbl[iscsi_cid] = NULL;
939 tmp = qedi_ops->release_conn(qedi->cdev, qedi_ep->handle);
941 QEDI_WARN(&qedi->dbg_ctx, "release_conn returned %d\n",
944 qedi_free_sq(qedi, qedi_ep);
946 iscsi_destroy_endpoint(ep);
950 static int qedi_ep_poll(struct iscsi_endpoint *ep, int timeout_ms)
952 struct qedi_endpoint *qedi_ep;
955 if (qedi_do_not_recover)
958 qedi_ep = ep->dd_data;
959 if (qedi_ep->state == EP_STATE_IDLE ||
960 qedi_ep->state == EP_STATE_OFLDCONN_NONE ||
961 qedi_ep->state == EP_STATE_OFLDCONN_FAILED)
964 if (qedi_ep->state == EP_STATE_OFLDCONN_COMPL)
967 ret = wait_event_interruptible_timeout(qedi_ep->ofld_wait,
968 QEDI_OFLD_WAIT_STATE(qedi_ep),
969 msecs_to_jiffies(timeout_ms));
971 if (qedi_ep->state == EP_STATE_OFLDCONN_FAILED)
982 static void qedi_cleanup_active_cmd_list(struct qedi_conn *qedi_conn)
984 struct qedi_cmd *cmd, *cmd_tmp;
986 spin_lock(&qedi_conn->list_lock);
987 list_for_each_entry_safe(cmd, cmd_tmp, &qedi_conn->active_cmd_list,
989 list_del_init(&cmd->io_cmd);
990 qedi_conn->active_cmd_count--;
992 spin_unlock(&qedi_conn->list_lock);
995 static void qedi_ep_disconnect(struct iscsi_endpoint *ep)
997 struct qedi_endpoint *qedi_ep;
998 struct qedi_conn *qedi_conn = NULL;
999 struct iscsi_conn *conn = NULL;
1000 struct qedi_ctx *qedi;
1002 int wait_delay = 20 * HZ;
1006 qedi_ep = ep->dd_data;
1007 qedi = qedi_ep->qedi;
1009 if (qedi_ep->state == EP_STATE_OFLDCONN_START)
1010 goto ep_exit_recover;
1012 if (qedi_ep->state != EP_STATE_OFLDCONN_NONE)
1013 flush_work(&qedi_ep->offload_work);
1015 if (qedi_ep->conn) {
1016 qedi_conn = qedi_ep->conn;
1017 conn = qedi_conn->cls_conn->dd_data;
1018 iscsi_suspend_queue(conn);
1019 abrt_conn = qedi_conn->abrt_conn;
1022 if (!test_bit(QEDI_CONN_FW_CLEANUP,
1023 &qedi_conn->flags)) {
1029 if (test_bit(QEDI_IN_RECOVERY, &qedi->flags)) {
1030 if (qedi_do_not_recover) {
1031 QEDI_INFO(&qedi->dbg_ctx, QEDI_LOG_INFO,
1032 "Do not recover cid=0x%x\n",
1033 qedi_ep->iscsi_cid);
1034 goto ep_exit_recover;
1036 QEDI_INFO(&qedi->dbg_ctx, QEDI_LOG_INFO,
1037 "Reset recovery cid=0x%x, qedi_ep=%p, state=0x%x\n",
1038 qedi_ep->iscsi_cid, qedi_ep, qedi_ep->state);
1039 qedi_cleanup_active_cmd_list(qedi_conn);
1040 goto ep_release_conn;
1044 if (qedi_do_not_recover)
1045 goto ep_exit_recover;
1047 switch (qedi_ep->state) {
1048 case EP_STATE_OFLDCONN_START:
1049 case EP_STATE_OFLDCONN_NONE:
1050 goto ep_release_conn;
1051 case EP_STATE_OFLDCONN_FAILED:
1053 case EP_STATE_OFLDCONN_COMPL:
1054 if (unlikely(!qedi_conn))
1057 QEDI_INFO(&qedi->dbg_ctx, QEDI_LOG_INFO,
1058 "Active cmd count=%d, abrt_conn=%d, ep state=0x%x, cid=0x%x, qedi_conn=%p\n",
1059 qedi_conn->active_cmd_count, abrt_conn,
1065 if (!qedi_conn->active_cmd_count)
1071 qedi_clearsq(qedi, qedi_conn, NULL);
1078 wait_delay += qedi->pf_params.iscsi_pf_params.two_msl_timer;
1080 qedi_ep->state = EP_STATE_DISCONN_START;
1081 ret = qedi_ops->destroy_conn(qedi->cdev, qedi_ep->handle, abrt_conn);
1083 QEDI_WARN(&qedi->dbg_ctx,
1084 "destroy_conn failed returned %d\n", ret);
1086 ret = wait_event_interruptible_timeout(
1087 qedi_ep->tcp_ofld_wait,
1089 EP_STATE_DISCONN_START),
1091 if ((ret <= 0) || (qedi_ep->state == EP_STATE_DISCONN_START)) {
1092 QEDI_WARN(&qedi->dbg_ctx,
1093 "Destroy conn timedout or interrupted, ret=%d, delay=%d, cid=0x%x\n",
1094 ret, wait_delay, qedi_ep->iscsi_cid);
1099 ret = qedi_ops->release_conn(qedi->cdev, qedi_ep->handle);
1101 QEDI_WARN(&qedi->dbg_ctx,
1102 "release_conn returned %d, cid=0x%x\n",
1103 ret, qedi_ep->iscsi_cid);
1105 qedi_ep->state = EP_STATE_IDLE;
1106 qedi->ep_tbl[qedi_ep->iscsi_cid] = NULL;
1107 qedi->cid_que.conn_cid_tbl[qedi_ep->iscsi_cid] = NULL;
1108 qedi_free_id(&qedi->lcl_port_tbl, qedi_ep->src_port);
1109 qedi_free_sq(qedi, qedi_ep);
1112 qedi_conn->ep = NULL;
1114 qedi_ep->conn = NULL;
1115 qedi_ep->qedi = NULL;
1116 atomic_dec(&qedi->num_offloads);
1118 iscsi_destroy_endpoint(ep);
1121 static int qedi_data_avail(struct qedi_ctx *qedi, u16 vlanid)
1123 struct qed_dev *cdev = qedi->cdev;
1124 struct qedi_uio_dev *udev;
1125 struct qedi_uio_ctrl *uctrl;
1126 struct sk_buff *skb;
1132 QEDI_ERR(&qedi->dbg_ctx, "udev is NULL.\n");
1136 uctrl = (struct qedi_uio_ctrl *)udev->uctrl;
1138 QEDI_ERR(&qedi->dbg_ctx, "uctlr is NULL.\n");
1142 len = uctrl->host_tx_pkt_len;
1144 QEDI_ERR(&qedi->dbg_ctx, "Invalid len %u\n", len);
1148 skb = alloc_skb(len, GFP_ATOMIC);
1150 QEDI_ERR(&qedi->dbg_ctx, "alloc_skb failed\n");
1155 memcpy(skb->data, udev->tx_pkt, len);
1156 skb->ip_summed = CHECKSUM_NONE;
1159 __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), vlanid);
1161 rc = qedi_ops->ll2->start_xmit(cdev, skb);
1163 QEDI_ERR(&qedi->dbg_ctx, "ll2 start_xmit returned %d\n",
1168 uctrl->host_tx_pkt_len = 0;
1169 uctrl->hw_tx_cons++;
1174 static void qedi_offload_work(struct work_struct *work)
1176 struct qedi_endpoint *qedi_ep =
1177 container_of(work, struct qedi_endpoint, offload_work);
1178 struct qedi_ctx *qedi;
1179 int wait_delay = 20 * HZ;
1182 qedi = qedi_ep->qedi;
1184 ret = qedi_iscsi_offload_conn(qedi_ep);
1186 QEDI_ERR(&qedi->dbg_ctx,
1187 "offload error: iscsi_cid=%u, qedi_ep=%p, ret=%d\n",
1188 qedi_ep->iscsi_cid, qedi_ep, ret);
1189 qedi_ep->state = EP_STATE_OFLDCONN_FAILED;
1193 ret = wait_event_interruptible_timeout(qedi_ep->tcp_ofld_wait,
1195 EP_STATE_OFLDCONN_COMPL),
1197 if ((ret <= 0) || (qedi_ep->state != EP_STATE_OFLDCONN_COMPL)) {
1198 qedi_ep->state = EP_STATE_OFLDCONN_FAILED;
1199 QEDI_ERR(&qedi->dbg_ctx,
1200 "Offload conn TIMEOUT iscsi_cid=%u, qedi_ep=%p\n",
1201 qedi_ep->iscsi_cid, qedi_ep);
1205 static int qedi_set_path(struct Scsi_Host *shost, struct iscsi_path *path_data)
1207 struct qedi_ctx *qedi;
1208 struct qedi_endpoint *qedi_ep;
1215 QEDI_ERR(NULL, "shost is NULL\n");
1219 if (strcmp(shost->hostt->proc_name, "qedi")) {
1221 QEDI_ERR(NULL, "shost %s is invalid\n",
1222 shost->hostt->proc_name);
1226 qedi = iscsi_host_priv(shost);
1227 if (path_data->handle == QEDI_PATH_HANDLE) {
1228 ret = qedi_data_avail(qedi, path_data->vlan_id);
1232 iscsi_cid = (u32)path_data->handle;
1233 if (iscsi_cid >= qedi->max_active_conns) {
1237 qedi_ep = qedi->ep_tbl[iscsi_cid];
1238 QEDI_INFO(&qedi->dbg_ctx, QEDI_LOG_INFO,
1239 "iscsi_cid=0x%x, qedi_ep=%p\n", iscsi_cid, qedi_ep);
1245 if (!is_valid_ether_addr(&path_data->mac_addr[0])) {
1246 QEDI_NOTICE(&qedi->dbg_ctx, "dst mac NOT VALID\n");
1247 qedi_ep->state = EP_STATE_OFLDCONN_NONE;
1252 ether_addr_copy(&qedi_ep->src_mac[0], &qedi->mac[0]);
1253 ether_addr_copy(&qedi_ep->dst_mac[0], &path_data->mac_addr[0]);
1255 qedi_ep->vlan_id = path_data->vlan_id;
1256 if (path_data->pmtu < DEF_PATH_MTU) {
1257 qedi_ep->pmtu = qedi->ll2_mtu;
1258 QEDI_INFO(&qedi->dbg_ctx, QEDI_LOG_INFO,
1259 "MTU cannot be %u, using default MTU %u\n",
1260 path_data->pmtu, qedi_ep->pmtu);
1263 if (path_data->pmtu != qedi->ll2_mtu) {
1264 if (path_data->pmtu > JUMBO_MTU) {
1266 QEDI_ERR(NULL, "Invalid MTU %u\n", path_data->pmtu);
1270 qedi_reset_host_mtu(qedi, path_data->pmtu);
1271 qedi_ep->pmtu = qedi->ll2_mtu;
1274 port_id = qedi_ep->src_port;
1275 if (port_id >= QEDI_LOCAL_PORT_MIN &&
1276 port_id < QEDI_LOCAL_PORT_MAX) {
1277 if (qedi_alloc_id(&qedi->lcl_port_tbl, port_id))
1284 port_id = qedi_alloc_new_id(&qedi->lcl_port_tbl);
1285 if (port_id == QEDI_LOCAL_PORT_INVALID) {
1286 QEDI_ERR(&qedi->dbg_ctx,
1287 "Failed to allocate port id for iscsi_cid=0x%x\n",
1294 qedi_ep->src_port = port_id;
1296 if (qedi_ep->ip_type == TCP_IPV4) {
1297 memcpy(&qedi_ep->src_addr[0], &path_data->src.v4_addr,
1298 sizeof(struct in_addr));
1299 memcpy(&qedi->src_ip[0], &path_data->src.v4_addr,
1300 sizeof(struct in_addr));
1301 qedi->ip_type = TCP_IPV4;
1303 QEDI_INFO(&qedi->dbg_ctx, QEDI_LOG_CONN,
1304 "src addr:port=%pI4:%u, dst addr:port=%pI4:%u\n",
1305 qedi_ep->src_addr, qedi_ep->src_port,
1306 qedi_ep->dst_addr, qedi_ep->dst_port);
1308 memcpy(&qedi_ep->src_addr[0], &path_data->src.v6_addr,
1309 sizeof(struct in6_addr));
1310 memcpy(&qedi->src_ip[0], &path_data->src.v6_addr,
1311 sizeof(struct in6_addr));
1312 qedi->ip_type = TCP_IPV6;
1314 QEDI_INFO(&qedi->dbg_ctx, QEDI_LOG_CONN,
1315 "src addr:port=%pI6:%u, dst addr:port=%pI6:%u\n",
1316 qedi_ep->src_addr, qedi_ep->src_port,
1317 qedi_ep->dst_addr, qedi_ep->dst_port);
1320 INIT_WORK(&qedi_ep->offload_work, qedi_offload_work);
1321 queue_work(qedi->offload_thread, &qedi_ep->offload_work);
1329 static umode_t qedi_attr_is_visible(int param_type, int param)
1331 switch (param_type) {
1332 case ISCSI_HOST_PARAM:
1334 case ISCSI_HOST_PARAM_NETDEV_NAME:
1335 case ISCSI_HOST_PARAM_HWADDRESS:
1336 case ISCSI_HOST_PARAM_IPADDRESS:
1343 case ISCSI_PARAM_MAX_RECV_DLENGTH:
1344 case ISCSI_PARAM_MAX_XMIT_DLENGTH:
1345 case ISCSI_PARAM_HDRDGST_EN:
1346 case ISCSI_PARAM_DATADGST_EN:
1347 case ISCSI_PARAM_CONN_ADDRESS:
1348 case ISCSI_PARAM_CONN_PORT:
1349 case ISCSI_PARAM_EXP_STATSN:
1350 case ISCSI_PARAM_PERSISTENT_ADDRESS:
1351 case ISCSI_PARAM_PERSISTENT_PORT:
1352 case ISCSI_PARAM_PING_TMO:
1353 case ISCSI_PARAM_RECV_TMO:
1354 case ISCSI_PARAM_INITIAL_R2T_EN:
1355 case ISCSI_PARAM_MAX_R2T:
1356 case ISCSI_PARAM_IMM_DATA_EN:
1357 case ISCSI_PARAM_FIRST_BURST:
1358 case ISCSI_PARAM_MAX_BURST:
1359 case ISCSI_PARAM_PDU_INORDER_EN:
1360 case ISCSI_PARAM_DATASEQ_INORDER_EN:
1361 case ISCSI_PARAM_ERL:
1362 case ISCSI_PARAM_TARGET_NAME:
1363 case ISCSI_PARAM_TPGT:
1364 case ISCSI_PARAM_USERNAME:
1365 case ISCSI_PARAM_PASSWORD:
1366 case ISCSI_PARAM_USERNAME_IN:
1367 case ISCSI_PARAM_PASSWORD_IN:
1368 case ISCSI_PARAM_FAST_ABORT:
1369 case ISCSI_PARAM_ABORT_TMO:
1370 case ISCSI_PARAM_LU_RESET_TMO:
1371 case ISCSI_PARAM_TGT_RESET_TMO:
1372 case ISCSI_PARAM_IFACE_NAME:
1373 case ISCSI_PARAM_INITIATOR_NAME:
1374 case ISCSI_PARAM_BOOT_ROOT:
1375 case ISCSI_PARAM_BOOT_NIC:
1376 case ISCSI_PARAM_BOOT_TARGET:
1386 static void qedi_cleanup_task(struct iscsi_task *task)
1388 if (!task->sc || task->state == ISCSI_TASK_PENDING) {
1389 QEDI_INFO(NULL, QEDI_LOG_IO, "Returning ref_cnt=%d\n",
1390 refcount_read(&task->refcount));
1394 qedi_iscsi_unmap_sg_list(task->dd_data);
1397 struct iscsi_transport qedi_iscsi_transport = {
1398 .owner = THIS_MODULE,
1399 .name = QEDI_MODULE_NAME,
1400 .caps = CAP_RECOVERY_L0 | CAP_HDRDGST | CAP_MULTI_R2T | CAP_DATADGST |
1401 CAP_DATA_PATH_OFFLOAD | CAP_TEXT_NEGO,
1402 .create_session = qedi_session_create,
1403 .destroy_session = qedi_session_destroy,
1404 .create_conn = qedi_conn_create,
1405 .bind_conn = qedi_conn_bind,
1406 .start_conn = qedi_conn_start,
1407 .stop_conn = iscsi_conn_stop,
1408 .destroy_conn = qedi_conn_destroy,
1409 .set_param = iscsi_set_param,
1410 .get_ep_param = qedi_ep_get_param,
1411 .get_conn_param = iscsi_conn_get_param,
1412 .get_session_param = iscsi_session_get_param,
1413 .get_host_param = qedi_host_get_param,
1414 .send_pdu = iscsi_conn_send_pdu,
1415 .get_stats = qedi_conn_get_stats,
1416 .xmit_task = qedi_task_xmit,
1417 .cleanup_task = qedi_cleanup_task,
1418 .session_recovery_timedout = iscsi_session_recovery_timedout,
1419 .ep_connect = qedi_ep_connect,
1420 .ep_poll = qedi_ep_poll,
1421 .ep_disconnect = qedi_ep_disconnect,
1422 .set_path = qedi_set_path,
1423 .attr_is_visible = qedi_attr_is_visible,
1426 void qedi_start_conn_recovery(struct qedi_ctx *qedi,
1427 struct qedi_conn *qedi_conn)
1429 struct iscsi_cls_session *cls_sess;
1430 struct iscsi_cls_conn *cls_conn;
1431 struct iscsi_conn *conn;
1433 cls_conn = qedi_conn->cls_conn;
1434 conn = cls_conn->dd_data;
1435 cls_sess = iscsi_conn_to_session(cls_conn);
1437 if (iscsi_is_session_online(cls_sess)) {
1438 qedi_conn->abrt_conn = 1;
1439 QEDI_ERR(&qedi->dbg_ctx,
1440 "Failing connection, state=0x%x, cid=0x%x\n",
1441 conn->session->state, qedi_conn->iscsi_conn_id);
1442 iscsi_conn_failure(qedi_conn->cls_conn->dd_data,
1443 ISCSI_ERR_CONN_FAILED);
1447 static const struct {
1448 enum iscsi_error_types error_code;
1450 } qedi_iscsi_error[] = {
1451 { ISCSI_STATUS_NONE,
1454 { ISCSI_CONN_ERROR_TASK_CID_MISMATCH,
1457 { ISCSI_CONN_ERROR_TASK_NOT_VALID,
1460 { ISCSI_CONN_ERROR_RQ_RING_IS_FULL,
1463 { ISCSI_CONN_ERROR_CMDQ_RING_IS_FULL,
1466 { ISCSI_CONN_ERROR_HQE_CACHING_FAILED,
1467 "sge caching failed"
1469 { ISCSI_CONN_ERROR_HEADER_DIGEST_ERROR,
1472 { ISCSI_CONN_ERROR_LOCAL_COMPLETION_ERROR,
1475 { ISCSI_CONN_ERROR_DATA_OVERRUN,
1478 { ISCSI_CONN_ERROR_OUT_OF_SGES_ERROR,
1481 { ISCSI_CONN_ERROR_TCP_IP_FRAGMENT_ERROR,
1482 "tcp ip fragment error"
1484 { ISCSI_CONN_ERROR_PROTOCOL_ERR_AHS_LEN,
1485 "AHS len protocol error"
1487 { ISCSI_CONN_ERROR_PROTOCOL_ERR_ITT_OUT_OF_RANGE,
1488 "itt out of range error"
1490 { ISCSI_CONN_ERROR_PROTOCOL_ERR_DATA_SEG_LEN_EXCEEDS_PDU_SIZE,
1491 "data seg more than pdu size"
1493 { ISCSI_CONN_ERROR_PROTOCOL_ERR_INVALID_OPCODE,
1496 { ISCSI_CONN_ERROR_PROTOCOL_ERR_INVALID_OPCODE_BEFORE_UPDATE,
1497 "invalid opcode before update"
1499 { ISCSI_CONN_ERROR_UNVALID_NOPIN_DSL,
1502 { ISCSI_CONN_ERROR_PROTOCOL_ERR_R2T_CARRIES_NO_DATA,
1503 "r2t carries no data"
1505 { ISCSI_CONN_ERROR_PROTOCOL_ERR_DATA_SN,
1508 { ISCSI_CONN_ERROR_PROTOCOL_ERR_DATA_IN_TTT,
1511 { ISCSI_CONN_ERROR_PROTOCOL_ERR_R2T_TTT,
1514 { ISCSI_CONN_ERROR_PROTOCOL_ERR_R2T_BUFFER_OFFSET,
1515 "buffer offset error"
1517 { ISCSI_CONN_ERROR_PROTOCOL_ERR_BUFFER_OFFSET_OOO,
1520 { ISCSI_CONN_ERROR_PROTOCOL_ERR_R2T_SN,
1523 { ISCSI_CONN_ERROR_PROTOCOL_ERR_DESIRED_DATA_TRNS_LEN_0,
1524 "data xer len error"
1526 { ISCSI_CONN_ERROR_PROTOCOL_ERR_DESIRED_DATA_TRNS_LEN_1,
1527 "data xer len1 error"
1529 { ISCSI_CONN_ERROR_PROTOCOL_ERR_DESIRED_DATA_TRNS_LEN_2,
1530 "data xer len2 error"
1532 { ISCSI_CONN_ERROR_PROTOCOL_ERR_LUN,
1533 "protocol lun error"
1535 { ISCSI_CONN_ERROR_PROTOCOL_ERR_F_BIT_ZERO,
1538 { ISCSI_CONN_ERROR_PROTOCOL_ERR_EXP_STAT_SN,
1541 { ISCSI_CONN_ERROR_PROTOCOL_ERR_DSL_NOT_ZERO,
1542 "dsl not zero error"
1544 { ISCSI_CONN_ERROR_PROTOCOL_ERR_INVALID_DSL,
1547 { ISCSI_CONN_ERROR_PROTOCOL_ERR_DATA_SEG_LEN_TOO_BIG,
1548 "data seg len too big"
1550 { ISCSI_CONN_ERROR_PROTOCOL_ERR_OUTSTANDING_R2T_COUNT,
1551 "outstanding r2t count error"
1553 { ISCSI_CONN_ERROR_SENSE_DATA_LENGTH,
1554 "sense datalen error"
1558 char *qedi_get_iscsi_error(enum iscsi_error_types err_code)
1563 for (i = 0; i < ARRAY_SIZE(qedi_iscsi_error); i++) {
1564 if (qedi_iscsi_error[i].error_code == err_code) {
1565 msg = qedi_iscsi_error[i].err_string;
1572 void qedi_process_iscsi_error(struct qedi_endpoint *ep, struct async_data *data)
1574 struct qedi_conn *qedi_conn;
1575 struct qedi_ctx *qedi;
1576 char warn_notice[] = "iscsi_warning";
1577 char error_notice[] = "iscsi_error";
1578 char unknown_msg[] = "Unknown error";
1580 int need_recovery = 0;
1587 qedi_conn = ep->conn;
1593 QEDI_ERR(&qedi->dbg_ctx, "async event iscsi error:0x%x\n",
1598 message = warn_notice;
1601 message = error_notice;
1604 msg = qedi_get_iscsi_error(data->error_code);
1610 iscsi_conn_printk(KERN_ALERT,
1611 qedi_conn->cls_conn->dd_data,
1612 "qedi: %s - %s\n", message, msg);
1615 qedi_start_conn_recovery(qedi_conn->qedi, qedi_conn);
1618 void qedi_process_tcp_error(struct qedi_endpoint *ep, struct async_data *data)
1620 struct qedi_conn *qedi_conn;
1625 qedi_conn = ep->conn;
1629 QEDI_ERR(&ep->qedi->dbg_ctx, "async event TCP error:0x%x\n",
1632 qedi_start_conn_recovery(qedi_conn->qedi, qedi_conn);