1 // SPDX-License-Identifier: GPL-2.0-only
3 * QLogic iSCSI Offload Driver
4 * Copyright (c) 2016 Cavium Inc.
7 #include <linux/blkdev.h>
8 #include <linux/etherdevice.h>
9 #include <linux/if_ether.h>
10 #include <linux/if_vlan.h>
11 #include <scsi/scsi_tcq.h>
14 #include "qedi_iscsi.h"
17 int qedi_recover_all_conns(struct qedi_ctx *qedi)
19 struct qedi_conn *qedi_conn;
22 for (i = 0; i < qedi->max_active_conns; i++) {
23 qedi_conn = qedi_get_conn_from_id(qedi, i);
27 qedi_start_conn_recovery(qedi, qedi_conn);
33 static int qedi_eh_host_reset(struct scsi_cmnd *cmd)
35 struct Scsi_Host *shost = cmd->device->host;
36 struct qedi_ctx *qedi;
38 qedi = iscsi_host_priv(shost);
40 return qedi_recover_all_conns(qedi);
43 struct scsi_host_template qedi_host_template = {
44 .module = THIS_MODULE,
45 .name = "QLogic QEDI 25/40/100Gb iSCSI Initiator Driver",
46 .proc_name = QEDI_MODULE_NAME,
47 .queuecommand = iscsi_queuecommand,
48 .eh_timed_out = iscsi_eh_cmd_timed_out,
49 .eh_abort_handler = iscsi_eh_abort,
50 .eh_device_reset_handler = iscsi_eh_device_reset,
51 .eh_target_reset_handler = iscsi_eh_recover_target,
52 .eh_host_reset_handler = qedi_eh_host_reset,
53 .target_alloc = iscsi_target_alloc,
54 .change_queue_depth = scsi_change_queue_depth,
55 .can_queue = QEDI_MAX_ISCSI_TASK,
57 .sg_tablesize = QEDI_ISCSI_MAX_BDS_PER_CMD,
58 .max_sectors = 0xffff,
59 .dma_boundary = QEDI_HW_DMA_BOUNDARY,
61 .shost_groups = qedi_shost_groups,
62 .cmd_size = sizeof(struct iscsi_cmd),
65 static void qedi_conn_free_login_resources(struct qedi_ctx *qedi,
66 struct qedi_conn *qedi_conn)
68 if (qedi_conn->gen_pdu.resp_bd_tbl) {
69 dma_free_coherent(&qedi->pdev->dev, QEDI_PAGE_SIZE,
70 qedi_conn->gen_pdu.resp_bd_tbl,
71 qedi_conn->gen_pdu.resp_bd_dma);
72 qedi_conn->gen_pdu.resp_bd_tbl = NULL;
75 if (qedi_conn->gen_pdu.req_bd_tbl) {
76 dma_free_coherent(&qedi->pdev->dev, QEDI_PAGE_SIZE,
77 qedi_conn->gen_pdu.req_bd_tbl,
78 qedi_conn->gen_pdu.req_bd_dma);
79 qedi_conn->gen_pdu.req_bd_tbl = NULL;
82 if (qedi_conn->gen_pdu.resp_buf) {
83 dma_free_coherent(&qedi->pdev->dev,
84 ISCSI_DEF_MAX_RECV_SEG_LEN,
85 qedi_conn->gen_pdu.resp_buf,
86 qedi_conn->gen_pdu.resp_dma_addr);
87 qedi_conn->gen_pdu.resp_buf = NULL;
90 if (qedi_conn->gen_pdu.req_buf) {
91 dma_free_coherent(&qedi->pdev->dev,
92 ISCSI_DEF_MAX_RECV_SEG_LEN,
93 qedi_conn->gen_pdu.req_buf,
94 qedi_conn->gen_pdu.req_dma_addr);
95 qedi_conn->gen_pdu.req_buf = NULL;
99 static int qedi_conn_alloc_login_resources(struct qedi_ctx *qedi,
100 struct qedi_conn *qedi_conn)
102 qedi_conn->gen_pdu.req_buf =
103 dma_alloc_coherent(&qedi->pdev->dev,
104 ISCSI_DEF_MAX_RECV_SEG_LEN,
105 &qedi_conn->gen_pdu.req_dma_addr,
107 if (!qedi_conn->gen_pdu.req_buf)
108 goto login_req_buf_failure;
110 qedi_conn->gen_pdu.req_buf_size = 0;
111 qedi_conn->gen_pdu.req_wr_ptr = qedi_conn->gen_pdu.req_buf;
113 qedi_conn->gen_pdu.resp_buf =
114 dma_alloc_coherent(&qedi->pdev->dev,
115 ISCSI_DEF_MAX_RECV_SEG_LEN,
116 &qedi_conn->gen_pdu.resp_dma_addr,
118 if (!qedi_conn->gen_pdu.resp_buf)
119 goto login_resp_buf_failure;
121 qedi_conn->gen_pdu.resp_buf_size = ISCSI_DEF_MAX_RECV_SEG_LEN;
122 qedi_conn->gen_pdu.resp_wr_ptr = qedi_conn->gen_pdu.resp_buf;
124 qedi_conn->gen_pdu.req_bd_tbl =
125 dma_alloc_coherent(&qedi->pdev->dev, QEDI_PAGE_SIZE,
126 &qedi_conn->gen_pdu.req_bd_dma, GFP_KERNEL);
127 if (!qedi_conn->gen_pdu.req_bd_tbl)
128 goto login_req_bd_tbl_failure;
130 qedi_conn->gen_pdu.resp_bd_tbl =
131 dma_alloc_coherent(&qedi->pdev->dev, QEDI_PAGE_SIZE,
132 &qedi_conn->gen_pdu.resp_bd_dma,
134 if (!qedi_conn->gen_pdu.resp_bd_tbl)
135 goto login_resp_bd_tbl_failure;
137 QEDI_INFO(&qedi->dbg_ctx, QEDI_LOG_SESS,
138 "Allocation successful, cid=0x%x\n",
139 qedi_conn->iscsi_conn_id);
142 login_resp_bd_tbl_failure:
143 dma_free_coherent(&qedi->pdev->dev, QEDI_PAGE_SIZE,
144 qedi_conn->gen_pdu.req_bd_tbl,
145 qedi_conn->gen_pdu.req_bd_dma);
146 qedi_conn->gen_pdu.req_bd_tbl = NULL;
148 login_req_bd_tbl_failure:
149 dma_free_coherent(&qedi->pdev->dev, ISCSI_DEF_MAX_RECV_SEG_LEN,
150 qedi_conn->gen_pdu.resp_buf,
151 qedi_conn->gen_pdu.resp_dma_addr);
152 qedi_conn->gen_pdu.resp_buf = NULL;
153 login_resp_buf_failure:
154 dma_free_coherent(&qedi->pdev->dev, ISCSI_DEF_MAX_RECV_SEG_LEN,
155 qedi_conn->gen_pdu.req_buf,
156 qedi_conn->gen_pdu.req_dma_addr);
157 qedi_conn->gen_pdu.req_buf = NULL;
158 login_req_buf_failure:
159 iscsi_conn_printk(KERN_ERR, qedi_conn->cls_conn->dd_data,
160 "login resource alloc failed!!\n");
164 static void qedi_destroy_cmd_pool(struct qedi_ctx *qedi,
165 struct iscsi_session *session)
169 for (i = 0; i < session->cmds_max; i++) {
170 struct iscsi_task *task = session->cmds[i];
171 struct qedi_cmd *cmd = task->dd_data;
173 if (cmd->io_tbl.sge_tbl)
174 dma_free_coherent(&qedi->pdev->dev,
175 QEDI_ISCSI_MAX_BDS_PER_CMD *
176 sizeof(struct scsi_sge),
178 cmd->io_tbl.sge_tbl_dma);
180 if (cmd->sense_buffer)
181 dma_free_coherent(&qedi->pdev->dev,
182 SCSI_SENSE_BUFFERSIZE,
184 cmd->sense_buffer_dma);
188 static int qedi_alloc_sget(struct qedi_ctx *qedi, struct iscsi_session *session,
189 struct qedi_cmd *cmd)
191 struct qedi_io_bdt *io = &cmd->io_tbl;
192 struct scsi_sge *sge;
194 io->sge_tbl = dma_alloc_coherent(&qedi->pdev->dev,
195 QEDI_ISCSI_MAX_BDS_PER_CMD *
197 &io->sge_tbl_dma, GFP_KERNEL);
199 iscsi_session_printk(KERN_ERR, session,
200 "Could not allocate BD table.\n");
208 static int qedi_setup_cmd_pool(struct qedi_ctx *qedi,
209 struct iscsi_session *session)
213 for (i = 0; i < session->cmds_max; i++) {
214 struct iscsi_task *task = session->cmds[i];
215 struct qedi_cmd *cmd = task->dd_data;
217 task->hdr = &cmd->hdr;
218 task->hdr_max = sizeof(struct iscsi_hdr);
220 if (qedi_alloc_sget(qedi, session, cmd))
223 cmd->sense_buffer = dma_alloc_coherent(&qedi->pdev->dev,
224 SCSI_SENSE_BUFFERSIZE,
225 &cmd->sense_buffer_dma,
227 if (!cmd->sense_buffer)
234 qedi_destroy_cmd_pool(qedi, session);
238 static struct iscsi_cls_session *
239 qedi_session_create(struct iscsi_endpoint *ep, u16 cmds_max,
240 u16 qdepth, uint32_t initial_cmdsn)
242 struct Scsi_Host *shost;
243 struct iscsi_cls_session *cls_session;
244 struct qedi_ctx *qedi;
245 struct qedi_endpoint *qedi_ep;
250 qedi_ep = ep->dd_data;
251 shost = qedi_ep->qedi->shost;
252 qedi = iscsi_host_priv(shost);
254 if (cmds_max > qedi->max_sqes)
255 cmds_max = qedi->max_sqes;
256 else if (cmds_max < QEDI_SQ_WQES_MIN)
257 cmds_max = QEDI_SQ_WQES_MIN;
259 cls_session = iscsi_session_setup(&qedi_iscsi_transport, shost,
260 cmds_max, 0, sizeof(struct qedi_cmd),
261 initial_cmdsn, ISCSI_MAX_TARGET);
263 QEDI_ERR(&qedi->dbg_ctx,
264 "Failed to setup session for ep=%p\n", qedi_ep);
268 if (qedi_setup_cmd_pool(qedi, cls_session->dd_data)) {
269 QEDI_ERR(&qedi->dbg_ctx,
270 "Failed to setup cmd pool for ep=%p\n", qedi_ep);
271 goto session_teardown;
277 iscsi_session_teardown(cls_session);
281 static void qedi_session_destroy(struct iscsi_cls_session *cls_session)
283 struct iscsi_session *session = cls_session->dd_data;
284 struct Scsi_Host *shost = iscsi_session_to_shost(cls_session);
285 struct qedi_ctx *qedi = iscsi_host_priv(shost);
287 qedi_destroy_cmd_pool(qedi, session);
288 iscsi_session_teardown(cls_session);
291 static struct iscsi_cls_conn *
292 qedi_conn_create(struct iscsi_cls_session *cls_session, uint32_t cid)
294 struct Scsi_Host *shost = iscsi_session_to_shost(cls_session);
295 struct qedi_ctx *qedi = iscsi_host_priv(shost);
296 struct iscsi_cls_conn *cls_conn;
297 struct qedi_conn *qedi_conn;
298 struct iscsi_conn *conn;
300 cls_conn = iscsi_conn_setup(cls_session, sizeof(*qedi_conn),
303 QEDI_ERR(&qedi->dbg_ctx,
304 "conn_new: iscsi conn setup failed, cid=0x%x, cls_sess=%p!\n",
309 conn = cls_conn->dd_data;
310 qedi_conn = conn->dd_data;
311 qedi_conn->cls_conn = cls_conn;
312 qedi_conn->qedi = qedi;
313 qedi_conn->ep = NULL;
314 qedi_conn->active_cmd_count = 0;
315 INIT_LIST_HEAD(&qedi_conn->active_cmd_list);
316 spin_lock_init(&qedi_conn->list_lock);
318 if (qedi_conn_alloc_login_resources(qedi, qedi_conn)) {
319 iscsi_conn_printk(KERN_ALERT, conn,
320 "conn_new: login resc alloc failed, cid=0x%x, cls_sess=%p!!\n",
328 iscsi_conn_teardown(cls_conn);
332 void qedi_mark_device_missing(struct iscsi_cls_session *cls_session)
334 struct iscsi_session *session = cls_session->dd_data;
335 struct qedi_conn *qedi_conn = session->leadconn->dd_data;
337 spin_lock_bh(&session->frwd_lock);
338 set_bit(QEDI_BLOCK_IO, &qedi_conn->qedi->flags);
339 spin_unlock_bh(&session->frwd_lock);
342 void qedi_mark_device_available(struct iscsi_cls_session *cls_session)
344 struct iscsi_session *session = cls_session->dd_data;
345 struct qedi_conn *qedi_conn = session->leadconn->dd_data;
347 spin_lock_bh(&session->frwd_lock);
348 clear_bit(QEDI_BLOCK_IO, &qedi_conn->qedi->flags);
349 spin_unlock_bh(&session->frwd_lock);
352 static int qedi_bind_conn_to_iscsi_cid(struct qedi_ctx *qedi,
353 struct qedi_conn *qedi_conn)
355 u32 iscsi_cid = qedi_conn->iscsi_conn_id;
357 if (qedi->cid_que.conn_cid_tbl[iscsi_cid]) {
358 iscsi_conn_printk(KERN_ALERT, qedi_conn->cls_conn->dd_data,
359 "conn bind - entry #%d not free\n",
364 qedi->cid_que.conn_cid_tbl[iscsi_cid] = qedi_conn;
368 struct qedi_conn *qedi_get_conn_from_id(struct qedi_ctx *qedi, u32 iscsi_cid)
370 if (!qedi->cid_que.conn_cid_tbl) {
371 QEDI_ERR(&qedi->dbg_ctx, "missing conn<->cid table\n");
374 } else if (iscsi_cid >= qedi->max_active_conns) {
375 QEDI_ERR(&qedi->dbg_ctx, "wrong cid #%d\n", iscsi_cid);
378 return qedi->cid_que.conn_cid_tbl[iscsi_cid];
381 static int qedi_conn_bind(struct iscsi_cls_session *cls_session,
382 struct iscsi_cls_conn *cls_conn,
383 u64 transport_fd, int is_leading)
385 struct iscsi_conn *conn = cls_conn->dd_data;
386 struct qedi_conn *qedi_conn = conn->dd_data;
387 struct Scsi_Host *shost = iscsi_session_to_shost(cls_session);
388 struct qedi_ctx *qedi = iscsi_host_priv(shost);
389 struct qedi_endpoint *qedi_ep;
390 struct iscsi_endpoint *ep;
393 ep = iscsi_lookup_endpoint(transport_fd);
397 qedi_ep = ep->dd_data;
398 if ((qedi_ep->state == EP_STATE_TCP_FIN_RCVD) ||
399 (qedi_ep->state == EP_STATE_TCP_RST_RCVD)) {
404 if (iscsi_conn_bind(cls_session, cls_conn, is_leading)) {
410 qedi_ep->conn = qedi_conn;
411 qedi_conn->ep = qedi_ep;
412 qedi_conn->iscsi_ep = ep;
413 qedi_conn->iscsi_conn_id = qedi_ep->iscsi_cid;
414 qedi_conn->fw_cid = qedi_ep->fw_cid;
415 qedi_conn->cmd_cleanup_req = 0;
416 atomic_set(&qedi_conn->cmd_cleanup_cmpl, 0);
418 if (qedi_bind_conn_to_iscsi_cid(qedi, qedi_conn)) {
424 spin_lock_init(&qedi_conn->tmf_work_lock);
425 INIT_LIST_HEAD(&qedi_conn->tmf_work_list);
426 init_waitqueue_head(&qedi_conn->wait_queue);
428 iscsi_put_endpoint(ep);
432 static int qedi_iscsi_update_conn(struct qedi_ctx *qedi,
433 struct qedi_conn *qedi_conn)
435 struct qed_iscsi_params_update *conn_info;
436 struct iscsi_cls_conn *cls_conn = qedi_conn->cls_conn;
437 struct iscsi_conn *conn = cls_conn->dd_data;
438 struct qedi_endpoint *qedi_ep;
441 qedi_ep = qedi_conn->ep;
443 conn_info = kzalloc(sizeof(*conn_info), GFP_KERNEL);
445 QEDI_ERR(&qedi->dbg_ctx, "memory alloc failed\n");
449 conn_info->update_flag = 0;
451 if (conn->hdrdgst_en)
452 SET_FIELD(conn_info->update_flag,
453 ISCSI_CONN_UPDATE_RAMROD_PARAMS_HD_EN, true);
454 if (conn->datadgst_en)
455 SET_FIELD(conn_info->update_flag,
456 ISCSI_CONN_UPDATE_RAMROD_PARAMS_DD_EN, true);
457 if (conn->session->initial_r2t_en)
458 SET_FIELD(conn_info->update_flag,
459 ISCSI_CONN_UPDATE_RAMROD_PARAMS_INITIAL_R2T,
461 if (conn->session->imm_data_en)
462 SET_FIELD(conn_info->update_flag,
463 ISCSI_CONN_UPDATE_RAMROD_PARAMS_IMMEDIATE_DATA,
466 conn_info->max_seq_size = conn->session->max_burst;
467 conn_info->max_recv_pdu_length = conn->max_recv_dlength;
468 conn_info->max_send_pdu_length = conn->max_xmit_dlength;
469 conn_info->first_seq_length = conn->session->first_burst;
470 conn_info->exp_stat_sn = conn->exp_statsn;
472 rval = qedi_ops->update_conn(qedi->cdev, qedi_ep->handle,
476 QEDI_ERR(&qedi->dbg_ctx, "Could not update connection\n");
483 static u16 qedi_calc_mss(u16 pmtu, u8 is_ipv6, u8 tcp_ts_en, u8 vlan_en)
486 u16 hdrs = TCP_HDR_LEN;
489 hdrs += IPV6_HDR_LEN;
491 hdrs += IPV4_HDR_LEN;
501 static int qedi_iscsi_offload_conn(struct qedi_endpoint *qedi_ep)
503 struct qed_iscsi_params_offload *conn_info;
504 struct qedi_ctx *qedi = qedi_ep->qedi;
508 conn_info = kzalloc(sizeof(*conn_info), GFP_KERNEL);
510 QEDI_ERR(&qedi->dbg_ctx,
511 "Failed to allocate memory ep=%p\n", qedi_ep);
515 ether_addr_copy(conn_info->src.mac, qedi_ep->src_mac);
516 ether_addr_copy(conn_info->dst.mac, qedi_ep->dst_mac);
518 conn_info->src.ip[0] = ntohl(qedi_ep->src_addr[0]);
519 conn_info->dst.ip[0] = ntohl(qedi_ep->dst_addr[0]);
521 if (qedi_ep->ip_type == TCP_IPV4) {
522 conn_info->ip_version = 0;
523 QEDI_INFO(&qedi->dbg_ctx, QEDI_LOG_CONN,
524 "After ntohl: src_addr=%pI4, dst_addr=%pI4\n",
525 qedi_ep->src_addr, qedi_ep->dst_addr);
527 for (i = 1; i < 4; i++) {
528 conn_info->src.ip[i] = ntohl(qedi_ep->src_addr[i]);
529 conn_info->dst.ip[i] = ntohl(qedi_ep->dst_addr[i]);
532 conn_info->ip_version = 1;
533 QEDI_INFO(&qedi->dbg_ctx, QEDI_LOG_CONN,
534 "After ntohl: src_addr=%pI6, dst_addr=%pI6\n",
535 qedi_ep->src_addr, qedi_ep->dst_addr);
538 conn_info->src.port = qedi_ep->src_port;
539 conn_info->dst.port = qedi_ep->dst_port;
541 conn_info->layer_code = ISCSI_SLOW_PATH_LAYER_CODE;
542 conn_info->sq_pbl_addr = qedi_ep->sq_pbl_dma;
543 conn_info->vlan_id = qedi_ep->vlan_id;
545 SET_FIELD(conn_info->tcp_flags, TCP_OFFLOAD_PARAMS_TS_EN, 1);
546 SET_FIELD(conn_info->tcp_flags, TCP_OFFLOAD_PARAMS_DA_EN, 1);
547 SET_FIELD(conn_info->tcp_flags, TCP_OFFLOAD_PARAMS_DA_CNT_EN, 1);
548 SET_FIELD(conn_info->tcp_flags, TCP_OFFLOAD_PARAMS_KA_EN, 1);
550 conn_info->default_cq = (qedi_ep->fw_cid % qedi->num_queues);
552 conn_info->ka_max_probe_cnt = DEF_KA_MAX_PROBE_COUNT;
553 conn_info->dup_ack_theshold = 3;
554 conn_info->rcv_wnd = 65535;
556 conn_info->ss_thresh = 65535;
557 conn_info->srtt = 300;
558 conn_info->rtt_var = 150;
559 conn_info->flow_label = 0;
560 conn_info->ka_timeout = DEF_KA_TIMEOUT;
561 conn_info->ka_interval = DEF_KA_INTERVAL;
562 conn_info->max_rt_time = DEF_MAX_RT_TIME;
563 conn_info->ttl = DEF_TTL;
564 conn_info->tos_or_tc = DEF_TOS;
565 conn_info->remote_port = qedi_ep->dst_port;
566 conn_info->local_port = qedi_ep->src_port;
568 conn_info->mss = qedi_calc_mss(qedi_ep->pmtu,
569 (qedi_ep->ip_type == TCP_IPV6),
570 1, (qedi_ep->vlan_id != 0));
572 conn_info->cwnd = DEF_MAX_CWND * conn_info->mss;
573 conn_info->rcv_wnd_scale = 4;
574 conn_info->da_timeout_value = 200;
575 conn_info->ack_frequency = 2;
577 QEDI_INFO(&qedi->dbg_ctx, QEDI_LOG_INFO,
578 "Default cq index [%d], mss [%d]\n",
579 conn_info->default_cq, conn_info->mss);
581 /* Prepare the doorbell parameters */
582 qedi_ep->db_data.agg_flags = 0;
583 qedi_ep->db_data.params = 0;
584 SET_FIELD(qedi_ep->db_data.params, ISCSI_DB_DATA_DEST, DB_DEST_XCM);
585 SET_FIELD(qedi_ep->db_data.params, ISCSI_DB_DATA_AGG_CMD,
587 SET_FIELD(qedi_ep->db_data.params, ISCSI_DB_DATA_AGG_VAL_SEL,
588 DQ_XCM_ISCSI_SQ_PROD_CMD);
589 SET_FIELD(qedi_ep->db_data.params, ISCSI_DB_DATA_BYPASS_EN, 1);
591 /* Register doorbell with doorbell recovery mechanism */
592 rval = qedi_ops->common->db_recovery_add(qedi->cdev,
602 rval = qedi_ops->offload_conn(qedi->cdev, qedi_ep->handle, conn_info);
604 /* delete doorbell from doorbell recovery mechanism */
605 rval = qedi_ops->common->db_recovery_del(qedi->cdev,
609 QEDI_ERR(&qedi->dbg_ctx, "offload_conn returned %d, ep=%p\n",
617 static int qedi_conn_start(struct iscsi_cls_conn *cls_conn)
619 struct iscsi_conn *conn = cls_conn->dd_data;
620 struct qedi_conn *qedi_conn = conn->dd_data;
621 struct qedi_ctx *qedi;
624 qedi = qedi_conn->qedi;
626 rval = qedi_iscsi_update_conn(qedi, qedi_conn);
628 iscsi_conn_printk(KERN_ALERT, conn,
629 "conn_start: FW offload conn failed.\n");
634 spin_lock(&qedi_conn->tmf_work_lock);
635 qedi_conn->fw_cleanup_works = 0;
636 qedi_conn->ep_disconnect_starting = false;
637 spin_unlock(&qedi_conn->tmf_work_lock);
639 qedi_conn->abrt_conn = 0;
641 rval = iscsi_conn_start(cls_conn);
643 iscsi_conn_printk(KERN_ALERT, conn,
644 "iscsi_conn_start: FW offload conn failed!!\n");
651 static void qedi_conn_destroy(struct iscsi_cls_conn *cls_conn)
653 struct iscsi_conn *conn = cls_conn->dd_data;
654 struct qedi_conn *qedi_conn = conn->dd_data;
655 struct Scsi_Host *shost;
656 struct qedi_ctx *qedi;
658 shost = iscsi_session_to_shost(iscsi_conn_to_session(cls_conn));
659 qedi = iscsi_host_priv(shost);
661 qedi_conn_free_login_resources(qedi, qedi_conn);
662 iscsi_conn_teardown(cls_conn);
665 static int qedi_ep_get_param(struct iscsi_endpoint *ep,
666 enum iscsi_param param, char *buf)
668 struct qedi_endpoint *qedi_ep = ep->dd_data;
675 case ISCSI_PARAM_CONN_PORT:
676 len = sprintf(buf, "%hu\n", qedi_ep->dst_port);
678 case ISCSI_PARAM_CONN_ADDRESS:
679 if (qedi_ep->ip_type == TCP_IPV4)
680 len = sprintf(buf, "%pI4\n", qedi_ep->dst_addr);
682 len = sprintf(buf, "%pI6\n", qedi_ep->dst_addr);
691 static int qedi_host_get_param(struct Scsi_Host *shost,
692 enum iscsi_host_param param, char *buf)
694 struct qedi_ctx *qedi;
697 qedi = iscsi_host_priv(shost);
700 case ISCSI_HOST_PARAM_HWADDRESS:
701 len = sysfs_format_mac(buf, qedi->mac, 6);
703 case ISCSI_HOST_PARAM_NETDEV_NAME:
704 len = sprintf(buf, "host%d\n", shost->host_no);
706 case ISCSI_HOST_PARAM_IPADDRESS:
707 if (qedi->ip_type == TCP_IPV4)
708 len = sprintf(buf, "%pI4\n", qedi->src_ip);
710 len = sprintf(buf, "%pI6\n", qedi->src_ip);
713 return iscsi_host_get_param(shost, param, buf);
719 static void qedi_conn_get_stats(struct iscsi_cls_conn *cls_conn,
720 struct iscsi_stats *stats)
722 struct iscsi_conn *conn = cls_conn->dd_data;
723 struct qed_iscsi_stats iscsi_stats;
724 struct Scsi_Host *shost;
725 struct qedi_ctx *qedi;
727 shost = iscsi_session_to_shost(iscsi_conn_to_session(cls_conn));
728 qedi = iscsi_host_priv(shost);
729 qedi_ops->get_stats(qedi->cdev, &iscsi_stats);
731 conn->txdata_octets = iscsi_stats.iscsi_tx_bytes_cnt;
732 conn->rxdata_octets = iscsi_stats.iscsi_rx_bytes_cnt;
733 conn->dataout_pdus_cnt = (uint32_t)iscsi_stats.iscsi_tx_data_pdu_cnt;
734 conn->datain_pdus_cnt = (uint32_t)iscsi_stats.iscsi_rx_data_pdu_cnt;
735 conn->r2t_pdus_cnt = (uint32_t)iscsi_stats.iscsi_rx_r2t_pdu_cnt;
737 stats->txdata_octets = conn->txdata_octets;
738 stats->rxdata_octets = conn->rxdata_octets;
739 stats->scsicmd_pdus = conn->scsicmd_pdus_cnt;
740 stats->dataout_pdus = conn->dataout_pdus_cnt;
741 stats->scsirsp_pdus = conn->scsirsp_pdus_cnt;
742 stats->datain_pdus = conn->datain_pdus_cnt;
743 stats->r2t_pdus = conn->r2t_pdus_cnt;
744 stats->tmfcmd_pdus = conn->tmfcmd_pdus_cnt;
745 stats->tmfrsp_pdus = conn->tmfrsp_pdus_cnt;
746 stats->digest_err = 0;
747 stats->timeout_err = 0;
748 strcpy(stats->custom[0].desc, "eh_abort_cnt");
749 stats->custom[0].value = conn->eh_abort_cnt;
750 stats->custom_length = 1;
753 static void qedi_iscsi_prep_generic_pdu_bd(struct qedi_conn *qedi_conn)
755 struct scsi_sge *bd_tbl;
757 bd_tbl = (struct scsi_sge *)qedi_conn->gen_pdu.req_bd_tbl;
759 bd_tbl->sge_addr.hi =
760 (u32)((u64)qedi_conn->gen_pdu.req_dma_addr >> 32);
761 bd_tbl->sge_addr.lo = (u32)qedi_conn->gen_pdu.req_dma_addr;
762 bd_tbl->sge_len = qedi_conn->gen_pdu.req_wr_ptr -
763 qedi_conn->gen_pdu.req_buf;
764 bd_tbl = (struct scsi_sge *)qedi_conn->gen_pdu.resp_bd_tbl;
765 bd_tbl->sge_addr.hi =
766 (u32)((u64)qedi_conn->gen_pdu.resp_dma_addr >> 32);
767 bd_tbl->sge_addr.lo = (u32)qedi_conn->gen_pdu.resp_dma_addr;
768 bd_tbl->sge_len = ISCSI_DEF_MAX_RECV_SEG_LEN;
771 static int qedi_iscsi_send_generic_request(struct iscsi_task *task)
773 struct qedi_cmd *cmd = task->dd_data;
774 struct qedi_conn *qedi_conn = cmd->conn;
779 qedi_iscsi_prep_generic_pdu_bd(qedi_conn);
780 switch (task->hdr->opcode & ISCSI_OPCODE_MASK) {
782 qedi_send_iscsi_login(qedi_conn, task);
784 case ISCSI_OP_NOOP_OUT:
785 data_len = qedi_conn->gen_pdu.req_buf_size;
786 buf = qedi_conn->gen_pdu.req_buf;
788 rc = qedi_send_iscsi_nopout(qedi_conn, task,
791 rc = qedi_send_iscsi_nopout(qedi_conn, task,
794 case ISCSI_OP_LOGOUT:
795 rc = qedi_send_iscsi_logout(qedi_conn, task);
797 case ISCSI_OP_SCSI_TMFUNC:
798 rc = qedi_send_iscsi_tmf(qedi_conn, task);
801 rc = qedi_send_iscsi_text(qedi_conn, task);
804 iscsi_conn_printk(KERN_ALERT, qedi_conn->cls_conn->dd_data,
805 "unsupported op 0x%x\n", task->hdr->opcode);
811 static int qedi_mtask_xmit(struct iscsi_conn *conn, struct iscsi_task *task)
813 struct qedi_conn *qedi_conn = conn->dd_data;
814 struct qedi_cmd *cmd = task->dd_data;
816 memset(qedi_conn->gen_pdu.req_buf, 0, ISCSI_DEF_MAX_RECV_SEG_LEN);
818 qedi_conn->gen_pdu.req_buf_size = task->data_count;
820 if (task->data_count) {
821 memcpy(qedi_conn->gen_pdu.req_buf, task->data,
823 qedi_conn->gen_pdu.req_wr_ptr =
824 qedi_conn->gen_pdu.req_buf + task->data_count;
827 cmd->conn = conn->dd_data;
828 return qedi_iscsi_send_generic_request(task);
831 static int qedi_task_xmit(struct iscsi_task *task)
833 struct iscsi_conn *conn = task->conn;
834 struct qedi_conn *qedi_conn = conn->dd_data;
835 struct qedi_cmd *cmd = task->dd_data;
836 struct scsi_cmnd *sc = task->sc;
838 /* Clear now so in cleanup_task we know it didn't make it */
839 cmd->scsi_cmd = NULL;
840 cmd->task_id = U16_MAX;
842 if (test_bit(QEDI_IN_SHUTDOWN, &qedi_conn->qedi->flags))
845 if (test_bit(QEDI_BLOCK_IO, &qedi_conn->qedi->flags))
850 cmd->use_slowpath = false;
851 cmd->conn = qedi_conn;
853 cmd->io_cmd_in_list = false;
854 INIT_LIST_HEAD(&cmd->io_cmd);
857 return qedi_mtask_xmit(conn, task);
860 return qedi_iscsi_send_ioreq(task);
863 static void qedi_offload_work(struct work_struct *work)
865 struct qedi_endpoint *qedi_ep =
866 container_of(work, struct qedi_endpoint, offload_work);
867 struct qedi_ctx *qedi;
868 int wait_delay = 5 * HZ;
871 qedi = qedi_ep->qedi;
873 ret = qedi_iscsi_offload_conn(qedi_ep);
875 QEDI_ERR(&qedi->dbg_ctx,
876 "offload error: iscsi_cid=%u, qedi_ep=%p, ret=%d\n",
877 qedi_ep->iscsi_cid, qedi_ep, ret);
878 qedi_ep->state = EP_STATE_OFLDCONN_FAILED;
882 ret = wait_event_interruptible_timeout(qedi_ep->tcp_ofld_wait,
884 EP_STATE_OFLDCONN_COMPL),
886 if (ret <= 0 || qedi_ep->state != EP_STATE_OFLDCONN_COMPL) {
887 qedi_ep->state = EP_STATE_OFLDCONN_FAILED;
888 QEDI_ERR(&qedi->dbg_ctx,
889 "Offload conn TIMEOUT iscsi_cid=%u, qedi_ep=%p\n",
890 qedi_ep->iscsi_cid, qedi_ep);
894 static struct iscsi_endpoint *
895 qedi_ep_connect(struct Scsi_Host *shost, struct sockaddr *dst_addr,
898 struct qedi_ctx *qedi;
899 struct iscsi_endpoint *ep;
900 struct qedi_endpoint *qedi_ep;
901 struct sockaddr_in *addr;
902 struct sockaddr_in6 *addr6;
903 struct iscsi_path path_req;
904 u32 msg_type = ISCSI_KEVENT_IF_DOWN;
905 u32 iscsi_cid = QEDI_CID_RESERVED;
912 QEDI_ERR(NULL, "shost is NULL\n");
916 if (qedi_do_not_recover) {
921 qedi = iscsi_host_priv(shost);
923 if (test_bit(QEDI_IN_OFFLINE, &qedi->flags) ||
924 test_bit(QEDI_IN_RECOVERY, &qedi->flags)) {
929 if (atomic_read(&qedi->link_state) != QEDI_LINK_UP) {
930 QEDI_WARN(&qedi->dbg_ctx, "qedi link down\n");
931 return ERR_PTR(-ENXIO);
934 ep = iscsi_create_endpoint(sizeof(struct qedi_endpoint));
936 QEDI_ERR(&qedi->dbg_ctx, "endpoint create fail\n");
940 qedi_ep = ep->dd_data;
941 memset(qedi_ep, 0, sizeof(struct qedi_endpoint));
942 INIT_WORK(&qedi_ep->offload_work, qedi_offload_work);
943 qedi_ep->state = EP_STATE_IDLE;
944 qedi_ep->iscsi_cid = (u32)-1;
945 qedi_ep->qedi = qedi;
947 if (dst_addr->sa_family == AF_INET) {
948 addr = (struct sockaddr_in *)dst_addr;
949 memcpy(qedi_ep->dst_addr, &addr->sin_addr.s_addr,
950 sizeof(struct in_addr));
951 qedi_ep->dst_port = ntohs(addr->sin_port);
952 qedi_ep->ip_type = TCP_IPV4;
953 QEDI_INFO(&qedi->dbg_ctx, QEDI_LOG_CONN,
954 "dst_addr=%pI4, dst_port=%u\n",
955 qedi_ep->dst_addr, qedi_ep->dst_port);
956 } else if (dst_addr->sa_family == AF_INET6) {
957 addr6 = (struct sockaddr_in6 *)dst_addr;
958 memcpy(qedi_ep->dst_addr, &addr6->sin6_addr,
959 sizeof(struct in6_addr));
960 qedi_ep->dst_port = ntohs(addr6->sin6_port);
961 qedi_ep->ip_type = TCP_IPV6;
962 QEDI_INFO(&qedi->dbg_ctx, QEDI_LOG_CONN,
963 "dst_addr=%pI6, dst_port=%u\n",
964 qedi_ep->dst_addr, qedi_ep->dst_port);
966 QEDI_ERR(&qedi->dbg_ctx, "Invalid endpoint\n");
969 ret = qedi_alloc_sq(qedi, qedi_ep);
973 ret = qedi_ops->acquire_conn(qedi->cdev, &qedi_ep->handle,
974 &qedi_ep->fw_cid, &qedi_ep->p_doorbell);
977 QEDI_ERR(&qedi->dbg_ctx, "Could not acquire connection\n");
982 iscsi_cid = qedi_ep->handle;
983 qedi_ep->iscsi_cid = iscsi_cid;
985 init_waitqueue_head(&qedi_ep->ofld_wait);
986 init_waitqueue_head(&qedi_ep->tcp_ofld_wait);
987 qedi_ep->state = EP_STATE_OFLDCONN_START;
988 qedi->ep_tbl[iscsi_cid] = qedi_ep;
990 buf = (char *)&path_req;
991 len = sizeof(path_req);
992 memset(&path_req, 0, len);
994 msg_type = ISCSI_KEVENT_PATH_REQ;
995 path_req.handle = (u64)qedi_ep->iscsi_cid;
996 path_req.pmtu = qedi->ll2_mtu;
997 qedi_ep->pmtu = qedi->ll2_mtu;
998 if (qedi_ep->ip_type == TCP_IPV4) {
999 memcpy(&path_req.dst.v4_addr, &qedi_ep->dst_addr,
1000 sizeof(struct in_addr));
1001 path_req.ip_addr_len = 4;
1003 memcpy(&path_req.dst.v6_addr, &qedi_ep->dst_addr,
1004 sizeof(struct in6_addr));
1005 path_req.ip_addr_len = 16;
1008 ret = iscsi_offload_mesg(shost, &qedi_iscsi_transport, msg_type, buf,
1011 QEDI_ERR(&qedi->dbg_ctx,
1012 "iscsi_offload_mesg() failed for cid=0x%x ret=%d\n",
1017 atomic_inc(&qedi->num_offloads);
1021 qedi->ep_tbl[iscsi_cid] = NULL;
1022 tmp = qedi_ops->release_conn(qedi->cdev, qedi_ep->handle);
1024 QEDI_WARN(&qedi->dbg_ctx, "release_conn returned %d\n",
1027 qedi_free_sq(qedi, qedi_ep);
1029 iscsi_destroy_endpoint(ep);
1030 return ERR_PTR(ret);
1033 static int qedi_ep_poll(struct iscsi_endpoint *ep, int timeout_ms)
1035 struct qedi_endpoint *qedi_ep;
1038 if (qedi_do_not_recover)
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)
1047 if (qedi_ep->state == EP_STATE_OFLDCONN_COMPL)
1050 ret = wait_event_interruptible_timeout(qedi_ep->ofld_wait,
1051 QEDI_OFLD_WAIT_STATE(qedi_ep),
1052 msecs_to_jiffies(timeout_ms));
1054 if (qedi_ep->state == EP_STATE_OFLDCONN_FAILED)
1065 static void qedi_cleanup_active_cmd_list(struct qedi_conn *qedi_conn)
1067 struct qedi_cmd *cmd, *cmd_tmp;
1069 spin_lock(&qedi_conn->list_lock);
1070 list_for_each_entry_safe(cmd, cmd_tmp, &qedi_conn->active_cmd_list,
1072 list_del_init(&cmd->io_cmd);
1073 qedi_conn->active_cmd_count--;
1075 spin_unlock(&qedi_conn->list_lock);
1078 static void qedi_ep_disconnect(struct iscsi_endpoint *ep)
1080 struct qedi_endpoint *qedi_ep;
1081 struct qedi_conn *qedi_conn = NULL;
1082 struct qedi_ctx *qedi;
1087 wait_delay = 60 * HZ + DEF_MAX_RT_TIME;
1088 qedi_ep = ep->dd_data;
1089 qedi = qedi_ep->qedi;
1091 flush_work(&qedi_ep->offload_work);
1093 if (qedi_ep->state == EP_STATE_OFLDCONN_START)
1094 goto ep_exit_recover;
1096 if (qedi_ep->conn) {
1097 qedi_conn = qedi_ep->conn;
1098 abrt_conn = qedi_conn->abrt_conn;
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);
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);
1110 spin_lock(&qedi_conn->tmf_work_lock);
1112 spin_unlock(&qedi_conn->tmf_work_lock);
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;
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;
1129 if (qedi_do_not_recover)
1130 goto ep_exit_recover;
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:
1138 case EP_STATE_OFLDCONN_COMPL:
1139 if (unlikely(!qedi_conn))
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,
1150 if (!qedi_conn->active_cmd_count)
1156 qedi_clearsq(qedi, qedi_conn, NULL);
1163 wait_delay += qedi->pf_params.iscsi_pf_params.two_msl_timer;
1165 qedi_ep->state = EP_STATE_DISCONN_START;
1167 if (test_bit(QEDI_IN_SHUTDOWN, &qedi->flags) ||
1168 test_bit(QEDI_IN_RECOVERY, &qedi->flags))
1169 goto ep_release_conn;
1171 /* Delete doorbell from doorbell recovery mechanism */
1172 ret = qedi_ops->common->db_recovery_del(qedi->cdev,
1173 qedi_ep->p_doorbell,
1176 ret = qedi_ops->destroy_conn(qedi->cdev, qedi_ep->handle, abrt_conn);
1178 QEDI_WARN(&qedi->dbg_ctx,
1179 "destroy_conn failed returned %d\n", ret);
1181 ret = wait_event_interruptible_timeout(
1182 qedi_ep->tcp_ofld_wait,
1184 EP_STATE_DISCONN_START),
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);
1194 ret = qedi_ops->release_conn(qedi->cdev, qedi_ep->handle);
1196 QEDI_WARN(&qedi->dbg_ctx,
1197 "release_conn returned %d, cid=0x%x\n",
1198 ret, qedi_ep->iscsi_cid);
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);
1207 qedi_conn->ep = NULL;
1209 qedi_ep->conn = NULL;
1210 qedi_ep->qedi = NULL;
1211 atomic_dec(&qedi->num_offloads);
1213 iscsi_destroy_endpoint(ep);
1216 static int qedi_data_avail(struct qedi_ctx *qedi, u16 vlanid)
1218 struct qed_dev *cdev = qedi->cdev;
1219 struct qedi_uio_dev *udev;
1220 struct qedi_uio_ctrl *uctrl;
1221 struct sk_buff *skb;
1227 QEDI_ERR(&qedi->dbg_ctx, "udev is NULL.\n");
1231 uctrl = (struct qedi_uio_ctrl *)udev->uctrl;
1233 QEDI_ERR(&qedi->dbg_ctx, "uctlr is NULL.\n");
1237 len = uctrl->host_tx_pkt_len;
1239 QEDI_ERR(&qedi->dbg_ctx, "Invalid len %u\n", len);
1243 skb = alloc_skb(len, GFP_ATOMIC);
1245 QEDI_ERR(&qedi->dbg_ctx, "alloc_skb failed\n");
1250 memcpy(skb->data, udev->tx_pkt, len);
1251 skb->ip_summed = CHECKSUM_NONE;
1254 __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), vlanid);
1256 rc = qedi_ops->ll2->start_xmit(cdev, skb, 0);
1258 QEDI_ERR(&qedi->dbg_ctx, "ll2 start_xmit returned %d\n",
1263 uctrl->host_tx_pkt_len = 0;
1264 uctrl->hw_tx_cons++;
1269 static int qedi_set_path(struct Scsi_Host *shost, struct iscsi_path *path_data)
1271 struct qedi_ctx *qedi;
1272 struct qedi_endpoint *qedi_ep;
1279 QEDI_ERR(NULL, "shost is NULL\n");
1283 if (strcmp(shost->hostt->proc_name, "qedi")) {
1285 QEDI_ERR(NULL, "shost %s is invalid\n",
1286 shost->hostt->proc_name);
1290 qedi = iscsi_host_priv(shost);
1291 if (path_data->handle == QEDI_PATH_HANDLE) {
1292 ret = qedi_data_avail(qedi, path_data->vlan_id);
1296 iscsi_cid = (u32)path_data->handle;
1297 if (iscsi_cid >= qedi->max_active_conns) {
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);
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;
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]);
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);
1327 if (path_data->pmtu != qedi->ll2_mtu) {
1328 if (path_data->pmtu > JUMBO_MTU) {
1330 QEDI_ERR(NULL, "Invalid MTU %u\n", path_data->pmtu);
1334 qedi_reset_host_mtu(qedi, path_data->pmtu);
1335 qedi_ep->pmtu = qedi->ll2_mtu;
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))
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",
1358 qedi_ep->src_port = port_id;
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;
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);
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;
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);
1384 queue_work(qedi->offload_thread, &qedi_ep->offload_work);
1392 static umode_t qedi_attr_is_visible(int param_type, int param)
1394 switch (param_type) {
1395 case ISCSI_HOST_PARAM:
1397 case ISCSI_HOST_PARAM_NETDEV_NAME:
1398 case ISCSI_HOST_PARAM_HWADDRESS:
1399 case ISCSI_HOST_PARAM_IPADDRESS:
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:
1449 static void qedi_cleanup_task(struct iscsi_task *task)
1451 struct qedi_cmd *cmd;
1453 if (task->state == ISCSI_TASK_PENDING) {
1454 QEDI_INFO(NULL, QEDI_LOG_IO, "Returning ref_cnt=%d\n",
1455 refcount_read(&task->refcount));
1460 qedi_iscsi_unmap_sg_list(task->dd_data);
1462 cmd = task->dd_data;
1463 if (cmd->task_id != U16_MAX)
1464 qedi_clear_task_idx(iscsi_host_priv(task->conn->session->host),
1467 cmd->task_id = U16_MAX;
1468 cmd->scsi_cmd = NULL;
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,
1501 void qedi_start_conn_recovery(struct qedi_ctx *qedi,
1502 struct qedi_conn *qedi_conn)
1504 struct iscsi_cls_session *cls_sess;
1505 struct iscsi_cls_conn *cls_conn;
1506 struct iscsi_conn *conn;
1508 cls_conn = qedi_conn->cls_conn;
1509 conn = cls_conn->dd_data;
1510 cls_sess = iscsi_conn_to_session(cls_conn);
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);
1522 static const struct {
1523 enum iscsi_error_types error_code;
1525 } qedi_iscsi_error[] = {
1526 { ISCSI_STATUS_NONE,
1529 { ISCSI_CONN_ERROR_TASK_CID_MISMATCH,
1532 { ISCSI_CONN_ERROR_TASK_NOT_VALID,
1535 { ISCSI_CONN_ERROR_RQ_RING_IS_FULL,
1538 { ISCSI_CONN_ERROR_CMDQ_RING_IS_FULL,
1541 { ISCSI_CONN_ERROR_HQE_CACHING_FAILED,
1542 "sge caching failed"
1544 { ISCSI_CONN_ERROR_HEADER_DIGEST_ERROR,
1547 { ISCSI_CONN_ERROR_LOCAL_COMPLETION_ERROR,
1550 { ISCSI_CONN_ERROR_DATA_OVERRUN,
1553 { ISCSI_CONN_ERROR_OUT_OF_SGES_ERROR,
1556 { ISCSI_CONN_ERROR_TCP_IP_FRAGMENT_ERROR,
1557 "tcp ip fragment error"
1559 { ISCSI_CONN_ERROR_PROTOCOL_ERR_AHS_LEN,
1560 "AHS len protocol error"
1562 { ISCSI_CONN_ERROR_PROTOCOL_ERR_ITT_OUT_OF_RANGE,
1563 "itt out of range error"
1565 { ISCSI_CONN_ERROR_PROTOCOL_ERR_DATA_SEG_LEN_EXCEEDS_PDU_SIZE,
1566 "data seg more than pdu size"
1568 { ISCSI_CONN_ERROR_PROTOCOL_ERR_INVALID_OPCODE,
1571 { ISCSI_CONN_ERROR_PROTOCOL_ERR_INVALID_OPCODE_BEFORE_UPDATE,
1572 "invalid opcode before update"
1574 { ISCSI_CONN_ERROR_UNVALID_NOPIN_DSL,
1577 { ISCSI_CONN_ERROR_PROTOCOL_ERR_R2T_CARRIES_NO_DATA,
1578 "r2t carries no data"
1580 { ISCSI_CONN_ERROR_PROTOCOL_ERR_DATA_SN,
1583 { ISCSI_CONN_ERROR_PROTOCOL_ERR_DATA_IN_TTT,
1586 { ISCSI_CONN_ERROR_PROTOCOL_ERR_R2T_TTT,
1589 { ISCSI_CONN_ERROR_PROTOCOL_ERR_R2T_BUFFER_OFFSET,
1590 "buffer offset error"
1592 { ISCSI_CONN_ERROR_PROTOCOL_ERR_BUFFER_OFFSET_OOO,
1595 { ISCSI_CONN_ERROR_PROTOCOL_ERR_R2T_SN,
1598 { ISCSI_CONN_ERROR_PROTOCOL_ERR_DESIRED_DATA_TRNS_LEN_0,
1599 "data xer len error"
1601 { ISCSI_CONN_ERROR_PROTOCOL_ERR_DESIRED_DATA_TRNS_LEN_1,
1602 "data xer len1 error"
1604 { ISCSI_CONN_ERROR_PROTOCOL_ERR_DESIRED_DATA_TRNS_LEN_2,
1605 "data xer len2 error"
1607 { ISCSI_CONN_ERROR_PROTOCOL_ERR_LUN,
1608 "protocol lun error"
1610 { ISCSI_CONN_ERROR_PROTOCOL_ERR_F_BIT_ZERO,
1613 { ISCSI_CONN_ERROR_PROTOCOL_ERR_EXP_STAT_SN,
1616 { ISCSI_CONN_ERROR_PROTOCOL_ERR_DSL_NOT_ZERO,
1617 "dsl not zero error"
1619 { ISCSI_CONN_ERROR_PROTOCOL_ERR_INVALID_DSL,
1622 { ISCSI_CONN_ERROR_PROTOCOL_ERR_DATA_SEG_LEN_TOO_BIG,
1623 "data seg len too big"
1625 { ISCSI_CONN_ERROR_PROTOCOL_ERR_OUTSTANDING_R2T_COUNT,
1626 "outstanding r2t count error"
1628 { ISCSI_CONN_ERROR_SENSE_DATA_LENGTH,
1629 "sense datalen error"
1633 static char *qedi_get_iscsi_error(enum iscsi_error_types err_code)
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;
1647 void qedi_process_iscsi_error(struct qedi_endpoint *ep,
1648 struct iscsi_eqe_data *data)
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";
1656 int need_recovery = 0;
1663 qedi_conn = ep->conn;
1669 QEDI_ERR(&qedi->dbg_ctx, "async event iscsi error:0x%x\n",
1674 message = warn_notice;
1677 message = error_notice;
1680 msg = qedi_get_iscsi_error(data->error_code);
1686 iscsi_conn_printk(KERN_ALERT,
1687 qedi_conn->cls_conn->dd_data,
1688 "qedi: %s - %s\n", message, msg);
1691 qedi_start_conn_recovery(qedi_conn->qedi, qedi_conn);
1694 void qedi_process_tcp_error(struct qedi_endpoint *ep,
1695 struct iscsi_eqe_data *data)
1697 struct qedi_conn *qedi_conn;
1702 qedi_conn = ep->conn;
1706 QEDI_ERR(&ep->qedi->dbg_ctx, "async event TCP error:0x%x\n",
1709 qedi_start_conn_recovery(qedi_conn->qedi, qedi_conn);