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_attrs
= qedi_shost_attrs
,
64 static void qedi_conn_free_login_resources(struct qedi_ctx
*qedi
,
65 struct qedi_conn
*qedi_conn
)
67 if (qedi_conn
->gen_pdu
.resp_bd_tbl
) {
68 dma_free_coherent(&qedi
->pdev
->dev
, QEDI_PAGE_SIZE
,
69 qedi_conn
->gen_pdu
.resp_bd_tbl
,
70 qedi_conn
->gen_pdu
.resp_bd_dma
);
71 qedi_conn
->gen_pdu
.resp_bd_tbl
= NULL
;
74 if (qedi_conn
->gen_pdu
.req_bd_tbl
) {
75 dma_free_coherent(&qedi
->pdev
->dev
, QEDI_PAGE_SIZE
,
76 qedi_conn
->gen_pdu
.req_bd_tbl
,
77 qedi_conn
->gen_pdu
.req_bd_dma
);
78 qedi_conn
->gen_pdu
.req_bd_tbl
= NULL
;
81 if (qedi_conn
->gen_pdu
.resp_buf
) {
82 dma_free_coherent(&qedi
->pdev
->dev
,
83 ISCSI_DEF_MAX_RECV_SEG_LEN
,
84 qedi_conn
->gen_pdu
.resp_buf
,
85 qedi_conn
->gen_pdu
.resp_dma_addr
);
86 qedi_conn
->gen_pdu
.resp_buf
= NULL
;
89 if (qedi_conn
->gen_pdu
.req_buf
) {
90 dma_free_coherent(&qedi
->pdev
->dev
,
91 ISCSI_DEF_MAX_RECV_SEG_LEN
,
92 qedi_conn
->gen_pdu
.req_buf
,
93 qedi_conn
->gen_pdu
.req_dma_addr
);
94 qedi_conn
->gen_pdu
.req_buf
= NULL
;
98 static int qedi_conn_alloc_login_resources(struct qedi_ctx
*qedi
,
99 struct qedi_conn
*qedi_conn
)
101 qedi_conn
->gen_pdu
.req_buf
=
102 dma_alloc_coherent(&qedi
->pdev
->dev
,
103 ISCSI_DEF_MAX_RECV_SEG_LEN
,
104 &qedi_conn
->gen_pdu
.req_dma_addr
,
106 if (!qedi_conn
->gen_pdu
.req_buf
)
107 goto login_req_buf_failure
;
109 qedi_conn
->gen_pdu
.req_buf_size
= 0;
110 qedi_conn
->gen_pdu
.req_wr_ptr
= qedi_conn
->gen_pdu
.req_buf
;
112 qedi_conn
->gen_pdu
.resp_buf
=
113 dma_alloc_coherent(&qedi
->pdev
->dev
,
114 ISCSI_DEF_MAX_RECV_SEG_LEN
,
115 &qedi_conn
->gen_pdu
.resp_dma_addr
,
117 if (!qedi_conn
->gen_pdu
.resp_buf
)
118 goto login_resp_buf_failure
;
120 qedi_conn
->gen_pdu
.resp_buf_size
= ISCSI_DEF_MAX_RECV_SEG_LEN
;
121 qedi_conn
->gen_pdu
.resp_wr_ptr
= qedi_conn
->gen_pdu
.resp_buf
;
123 qedi_conn
->gen_pdu
.req_bd_tbl
=
124 dma_alloc_coherent(&qedi
->pdev
->dev
, QEDI_PAGE_SIZE
,
125 &qedi_conn
->gen_pdu
.req_bd_dma
, GFP_KERNEL
);
126 if (!qedi_conn
->gen_pdu
.req_bd_tbl
)
127 goto login_req_bd_tbl_failure
;
129 qedi_conn
->gen_pdu
.resp_bd_tbl
=
130 dma_alloc_coherent(&qedi
->pdev
->dev
, QEDI_PAGE_SIZE
,
131 &qedi_conn
->gen_pdu
.resp_bd_dma
,
133 if (!qedi_conn
->gen_pdu
.resp_bd_tbl
)
134 goto login_resp_bd_tbl_failure
;
136 QEDI_INFO(&qedi
->dbg_ctx
, QEDI_LOG_SESS
,
137 "Allocation successful, cid=0x%x\n",
138 qedi_conn
->iscsi_conn_id
);
141 login_resp_bd_tbl_failure
:
142 dma_free_coherent(&qedi
->pdev
->dev
, QEDI_PAGE_SIZE
,
143 qedi_conn
->gen_pdu
.req_bd_tbl
,
144 qedi_conn
->gen_pdu
.req_bd_dma
);
145 qedi_conn
->gen_pdu
.req_bd_tbl
= NULL
;
147 login_req_bd_tbl_failure
:
148 dma_free_coherent(&qedi
->pdev
->dev
, ISCSI_DEF_MAX_RECV_SEG_LEN
,
149 qedi_conn
->gen_pdu
.resp_buf
,
150 qedi_conn
->gen_pdu
.resp_dma_addr
);
151 qedi_conn
->gen_pdu
.resp_buf
= NULL
;
152 login_resp_buf_failure
:
153 dma_free_coherent(&qedi
->pdev
->dev
, ISCSI_DEF_MAX_RECV_SEG_LEN
,
154 qedi_conn
->gen_pdu
.req_buf
,
155 qedi_conn
->gen_pdu
.req_dma_addr
);
156 qedi_conn
->gen_pdu
.req_buf
= NULL
;
157 login_req_buf_failure
:
158 iscsi_conn_printk(KERN_ERR
, qedi_conn
->cls_conn
->dd_data
,
159 "login resource alloc failed!!\n");
163 static void qedi_destroy_cmd_pool(struct qedi_ctx
*qedi
,
164 struct iscsi_session
*session
)
168 for (i
= 0; i
< session
->cmds_max
; i
++) {
169 struct iscsi_task
*task
= session
->cmds
[i
];
170 struct qedi_cmd
*cmd
= task
->dd_data
;
172 if (cmd
->io_tbl
.sge_tbl
)
173 dma_free_coherent(&qedi
->pdev
->dev
,
174 QEDI_ISCSI_MAX_BDS_PER_CMD
*
175 sizeof(struct scsi_sge
),
177 cmd
->io_tbl
.sge_tbl_dma
);
179 if (cmd
->sense_buffer
)
180 dma_free_coherent(&qedi
->pdev
->dev
,
181 SCSI_SENSE_BUFFERSIZE
,
183 cmd
->sense_buffer_dma
);
187 static int qedi_alloc_sget(struct qedi_ctx
*qedi
, struct iscsi_session
*session
,
188 struct qedi_cmd
*cmd
)
190 struct qedi_io_bdt
*io
= &cmd
->io_tbl
;
191 struct scsi_sge
*sge
;
193 io
->sge_tbl
= dma_alloc_coherent(&qedi
->pdev
->dev
,
194 QEDI_ISCSI_MAX_BDS_PER_CMD
*
196 &io
->sge_tbl_dma
, GFP_KERNEL
);
198 iscsi_session_printk(KERN_ERR
, session
,
199 "Could not allocate BD table.\n");
207 static int qedi_setup_cmd_pool(struct qedi_ctx
*qedi
,
208 struct iscsi_session
*session
)
212 for (i
= 0; i
< session
->cmds_max
; i
++) {
213 struct iscsi_task
*task
= session
->cmds
[i
];
214 struct qedi_cmd
*cmd
= task
->dd_data
;
216 task
->hdr
= &cmd
->hdr
;
217 task
->hdr_max
= sizeof(struct iscsi_hdr
);
219 if (qedi_alloc_sget(qedi
, session
, cmd
))
222 cmd
->sense_buffer
= dma_alloc_coherent(&qedi
->pdev
->dev
,
223 SCSI_SENSE_BUFFERSIZE
,
224 &cmd
->sense_buffer_dma
,
226 if (!cmd
->sense_buffer
)
233 qedi_destroy_cmd_pool(qedi
, session
);
237 static struct iscsi_cls_session
*
238 qedi_session_create(struct iscsi_endpoint
*ep
, u16 cmds_max
,
239 u16 qdepth
, uint32_t initial_cmdsn
)
241 struct Scsi_Host
*shost
;
242 struct iscsi_cls_session
*cls_session
;
243 struct qedi_ctx
*qedi
;
244 struct qedi_endpoint
*qedi_ep
;
249 qedi_ep
= ep
->dd_data
;
250 shost
= qedi_ep
->qedi
->shost
;
251 qedi
= iscsi_host_priv(shost
);
253 if (cmds_max
> qedi
->max_sqes
)
254 cmds_max
= qedi
->max_sqes
;
255 else if (cmds_max
< QEDI_SQ_WQES_MIN
)
256 cmds_max
= QEDI_SQ_WQES_MIN
;
258 cls_session
= iscsi_session_setup(&qedi_iscsi_transport
, shost
,
259 cmds_max
, 0, sizeof(struct qedi_cmd
),
260 initial_cmdsn
, ISCSI_MAX_TARGET
);
262 QEDI_ERR(&qedi
->dbg_ctx
,
263 "Failed to setup session for ep=%p\n", qedi_ep
);
267 if (qedi_setup_cmd_pool(qedi
, cls_session
->dd_data
)) {
268 QEDI_ERR(&qedi
->dbg_ctx
,
269 "Failed to setup cmd pool for ep=%p\n", qedi_ep
);
270 goto session_teardown
;
276 iscsi_session_teardown(cls_session
);
280 static void qedi_session_destroy(struct iscsi_cls_session
*cls_session
)
282 struct iscsi_session
*session
= cls_session
->dd_data
;
283 struct Scsi_Host
*shost
= iscsi_session_to_shost(cls_session
);
284 struct qedi_ctx
*qedi
= iscsi_host_priv(shost
);
286 qedi_destroy_cmd_pool(qedi
, session
);
287 iscsi_session_teardown(cls_session
);
290 static struct iscsi_cls_conn
*
291 qedi_conn_create(struct iscsi_cls_session
*cls_session
, uint32_t cid
)
293 struct Scsi_Host
*shost
= iscsi_session_to_shost(cls_session
);
294 struct qedi_ctx
*qedi
= iscsi_host_priv(shost
);
295 struct iscsi_cls_conn
*cls_conn
;
296 struct qedi_conn
*qedi_conn
;
297 struct iscsi_conn
*conn
;
299 cls_conn
= iscsi_conn_setup(cls_session
, sizeof(*qedi_conn
),
302 QEDI_ERR(&qedi
->dbg_ctx
,
303 "conn_new: iscsi conn setup failed, cid=0x%x, cls_sess=%p!\n",
308 conn
= cls_conn
->dd_data
;
309 qedi_conn
= conn
->dd_data
;
310 qedi_conn
->cls_conn
= cls_conn
;
311 qedi_conn
->qedi
= qedi
;
312 qedi_conn
->ep
= NULL
;
313 qedi_conn
->active_cmd_count
= 0;
314 INIT_LIST_HEAD(&qedi_conn
->active_cmd_list
);
315 spin_lock_init(&qedi_conn
->list_lock
);
317 if (qedi_conn_alloc_login_resources(qedi
, qedi_conn
)) {
318 iscsi_conn_printk(KERN_ALERT
, conn
,
319 "conn_new: login resc alloc failed, cid=0x%x, cls_sess=%p!!\n",
327 iscsi_conn_teardown(cls_conn
);
331 void qedi_mark_device_missing(struct iscsi_cls_session
*cls_session
)
333 iscsi_block_session(cls_session
);
336 void qedi_mark_device_available(struct iscsi_cls_session
*cls_session
)
338 iscsi_unblock_session(cls_session
);
341 static int qedi_bind_conn_to_iscsi_cid(struct qedi_ctx
*qedi
,
342 struct qedi_conn
*qedi_conn
)
344 u32 iscsi_cid
= qedi_conn
->iscsi_conn_id
;
346 if (qedi
->cid_que
.conn_cid_tbl
[iscsi_cid
]) {
347 iscsi_conn_printk(KERN_ALERT
, qedi_conn
->cls_conn
->dd_data
,
348 "conn bind - entry #%d not free\n",
353 qedi
->cid_que
.conn_cid_tbl
[iscsi_cid
] = qedi_conn
;
357 struct qedi_conn
*qedi_get_conn_from_id(struct qedi_ctx
*qedi
, u32 iscsi_cid
)
359 if (!qedi
->cid_que
.conn_cid_tbl
) {
360 QEDI_ERR(&qedi
->dbg_ctx
, "missing conn<->cid table\n");
363 } else if (iscsi_cid
>= qedi
->max_active_conns
) {
364 QEDI_ERR(&qedi
->dbg_ctx
, "wrong cid #%d\n", iscsi_cid
);
367 return qedi
->cid_que
.conn_cid_tbl
[iscsi_cid
];
370 static int qedi_conn_bind(struct iscsi_cls_session
*cls_session
,
371 struct iscsi_cls_conn
*cls_conn
,
372 u64 transport_fd
, int is_leading
)
374 struct iscsi_conn
*conn
= cls_conn
->dd_data
;
375 struct qedi_conn
*qedi_conn
= conn
->dd_data
;
376 struct Scsi_Host
*shost
= iscsi_session_to_shost(cls_session
);
377 struct qedi_ctx
*qedi
= iscsi_host_priv(shost
);
378 struct qedi_endpoint
*qedi_ep
;
379 struct iscsi_endpoint
*ep
;
381 ep
= iscsi_lookup_endpoint(transport_fd
);
385 qedi_ep
= ep
->dd_data
;
386 if ((qedi_ep
->state
== EP_STATE_TCP_FIN_RCVD
) ||
387 (qedi_ep
->state
== EP_STATE_TCP_RST_RCVD
))
390 if (iscsi_conn_bind(cls_session
, cls_conn
, is_leading
))
393 qedi_ep
->conn
= qedi_conn
;
394 qedi_conn
->ep
= qedi_ep
;
395 qedi_conn
->iscsi_conn_id
= qedi_ep
->iscsi_cid
;
396 qedi_conn
->fw_cid
= qedi_ep
->fw_cid
;
397 qedi_conn
->cmd_cleanup_req
= 0;
398 qedi_conn
->cmd_cleanup_cmpl
= 0;
400 if (qedi_bind_conn_to_iscsi_cid(qedi
, qedi_conn
))
403 spin_lock_init(&qedi_conn
->tmf_work_lock
);
404 INIT_LIST_HEAD(&qedi_conn
->tmf_work_list
);
405 init_waitqueue_head(&qedi_conn
->wait_queue
);
409 static int qedi_iscsi_update_conn(struct qedi_ctx
*qedi
,
410 struct qedi_conn
*qedi_conn
)
412 struct qed_iscsi_params_update
*conn_info
;
413 struct iscsi_cls_conn
*cls_conn
= qedi_conn
->cls_conn
;
414 struct iscsi_conn
*conn
= cls_conn
->dd_data
;
415 struct qedi_endpoint
*qedi_ep
;
418 qedi_ep
= qedi_conn
->ep
;
420 conn_info
= kzalloc(sizeof(*conn_info
), GFP_KERNEL
);
422 QEDI_ERR(&qedi
->dbg_ctx
, "memory alloc failed\n");
426 conn_info
->update_flag
= 0;
428 if (conn
->hdrdgst_en
)
429 SET_FIELD(conn_info
->update_flag
,
430 ISCSI_CONN_UPDATE_RAMROD_PARAMS_HD_EN
, true);
431 if (conn
->datadgst_en
)
432 SET_FIELD(conn_info
->update_flag
,
433 ISCSI_CONN_UPDATE_RAMROD_PARAMS_DD_EN
, true);
434 if (conn
->session
->initial_r2t_en
)
435 SET_FIELD(conn_info
->update_flag
,
436 ISCSI_CONN_UPDATE_RAMROD_PARAMS_INITIAL_R2T
,
438 if (conn
->session
->imm_data_en
)
439 SET_FIELD(conn_info
->update_flag
,
440 ISCSI_CONN_UPDATE_RAMROD_PARAMS_IMMEDIATE_DATA
,
443 conn_info
->max_seq_size
= conn
->session
->max_burst
;
444 conn_info
->max_recv_pdu_length
= conn
->max_recv_dlength
;
445 conn_info
->max_send_pdu_length
= conn
->max_xmit_dlength
;
446 conn_info
->first_seq_length
= conn
->session
->first_burst
;
447 conn_info
->exp_stat_sn
= conn
->exp_statsn
;
449 rval
= qedi_ops
->update_conn(qedi
->cdev
, qedi_ep
->handle
,
453 QEDI_ERR(&qedi
->dbg_ctx
, "Could not update connection\n");
460 static u16
qedi_calc_mss(u16 pmtu
, u8 is_ipv6
, u8 tcp_ts_en
, u8 vlan_en
)
463 u16 hdrs
= TCP_HDR_LEN
;
466 hdrs
+= IPV6_HDR_LEN
;
468 hdrs
+= IPV4_HDR_LEN
;
478 static int qedi_iscsi_offload_conn(struct qedi_endpoint
*qedi_ep
)
480 struct qedi_ctx
*qedi
= qedi_ep
->qedi
;
481 struct qed_iscsi_params_offload
*conn_info
;
485 conn_info
= kzalloc(sizeof(*conn_info
), GFP_KERNEL
);
487 QEDI_ERR(&qedi
->dbg_ctx
,
488 "Failed to allocate memory ep=%p\n", qedi_ep
);
492 ether_addr_copy(conn_info
->src
.mac
, qedi_ep
->src_mac
);
493 ether_addr_copy(conn_info
->dst
.mac
, qedi_ep
->dst_mac
);
495 conn_info
->src
.ip
[0] = ntohl(qedi_ep
->src_addr
[0]);
496 conn_info
->dst
.ip
[0] = ntohl(qedi_ep
->dst_addr
[0]);
498 if (qedi_ep
->ip_type
== TCP_IPV4
) {
499 conn_info
->ip_version
= 0;
500 QEDI_INFO(&qedi
->dbg_ctx
, QEDI_LOG_CONN
,
501 "After ntohl: src_addr=%pI4, dst_addr=%pI4\n",
502 qedi_ep
->src_addr
, qedi_ep
->dst_addr
);
504 for (i
= 1; i
< 4; i
++) {
505 conn_info
->src
.ip
[i
] = ntohl(qedi_ep
->src_addr
[i
]);
506 conn_info
->dst
.ip
[i
] = ntohl(qedi_ep
->dst_addr
[i
]);
509 conn_info
->ip_version
= 1;
510 QEDI_INFO(&qedi
->dbg_ctx
, QEDI_LOG_CONN
,
511 "After ntohl: src_addr=%pI6, dst_addr=%pI6\n",
512 qedi_ep
->src_addr
, qedi_ep
->dst_addr
);
515 conn_info
->src
.port
= qedi_ep
->src_port
;
516 conn_info
->dst
.port
= qedi_ep
->dst_port
;
518 conn_info
->layer_code
= ISCSI_SLOW_PATH_LAYER_CODE
;
519 conn_info
->sq_pbl_addr
= qedi_ep
->sq_pbl_dma
;
520 conn_info
->vlan_id
= qedi_ep
->vlan_id
;
522 SET_FIELD(conn_info
->tcp_flags
, TCP_OFFLOAD_PARAMS_TS_EN
, 1);
523 SET_FIELD(conn_info
->tcp_flags
, TCP_OFFLOAD_PARAMS_DA_EN
, 1);
524 SET_FIELD(conn_info
->tcp_flags
, TCP_OFFLOAD_PARAMS_DA_CNT_EN
, 1);
525 SET_FIELD(conn_info
->tcp_flags
, TCP_OFFLOAD_PARAMS_KA_EN
, 1);
527 conn_info
->default_cq
= (qedi_ep
->fw_cid
% qedi
->num_queues
);
529 conn_info
->ka_max_probe_cnt
= DEF_KA_MAX_PROBE_COUNT
;
530 conn_info
->dup_ack_theshold
= 3;
531 conn_info
->rcv_wnd
= 65535;
533 conn_info
->ss_thresh
= 65535;
534 conn_info
->srtt
= 300;
535 conn_info
->rtt_var
= 150;
536 conn_info
->flow_label
= 0;
537 conn_info
->ka_timeout
= DEF_KA_TIMEOUT
;
538 conn_info
->ka_interval
= DEF_KA_INTERVAL
;
539 conn_info
->max_rt_time
= DEF_MAX_RT_TIME
;
540 conn_info
->ttl
= DEF_TTL
;
541 conn_info
->tos_or_tc
= DEF_TOS
;
542 conn_info
->remote_port
= qedi_ep
->dst_port
;
543 conn_info
->local_port
= qedi_ep
->src_port
;
545 conn_info
->mss
= qedi_calc_mss(qedi_ep
->pmtu
,
546 (qedi_ep
->ip_type
== TCP_IPV6
),
547 1, (qedi_ep
->vlan_id
!= 0));
549 conn_info
->cwnd
= DEF_MAX_CWND
* conn_info
->mss
;
550 conn_info
->rcv_wnd_scale
= 4;
551 conn_info
->da_timeout_value
= 200;
552 conn_info
->ack_frequency
= 2;
554 QEDI_INFO(&qedi
->dbg_ctx
, QEDI_LOG_INFO
,
555 "Default cq index [%d], mss [%d]\n",
556 conn_info
->default_cq
, conn_info
->mss
);
558 rval
= qedi_ops
->offload_conn(qedi
->cdev
, qedi_ep
->handle
, conn_info
);
560 QEDI_ERR(&qedi
->dbg_ctx
, "offload_conn returned %d, ep=%p\n",
567 static int qedi_conn_start(struct iscsi_cls_conn
*cls_conn
)
569 struct iscsi_conn
*conn
= cls_conn
->dd_data
;
570 struct qedi_conn
*qedi_conn
= conn
->dd_data
;
571 struct qedi_ctx
*qedi
;
574 qedi
= qedi_conn
->qedi
;
576 rval
= qedi_iscsi_update_conn(qedi
, qedi_conn
);
578 iscsi_conn_printk(KERN_ALERT
, conn
,
579 "conn_start: FW offload conn failed.\n");
584 clear_bit(QEDI_CONN_FW_CLEANUP
, &qedi_conn
->flags
);
585 qedi_conn
->abrt_conn
= 0;
587 rval
= iscsi_conn_start(cls_conn
);
589 iscsi_conn_printk(KERN_ALERT
, conn
,
590 "iscsi_conn_start: FW offload conn failed!!\n");
597 static void qedi_conn_destroy(struct iscsi_cls_conn
*cls_conn
)
599 struct iscsi_conn
*conn
= cls_conn
->dd_data
;
600 struct qedi_conn
*qedi_conn
= conn
->dd_data
;
601 struct Scsi_Host
*shost
;
602 struct qedi_ctx
*qedi
;
604 shost
= iscsi_session_to_shost(iscsi_conn_to_session(cls_conn
));
605 qedi
= iscsi_host_priv(shost
);
607 qedi_conn_free_login_resources(qedi
, qedi_conn
);
608 iscsi_conn_teardown(cls_conn
);
611 static int qedi_ep_get_param(struct iscsi_endpoint
*ep
,
612 enum iscsi_param param
, char *buf
)
614 struct qedi_endpoint
*qedi_ep
= ep
->dd_data
;
621 case ISCSI_PARAM_CONN_PORT
:
622 len
= sprintf(buf
, "%hu\n", qedi_ep
->dst_port
);
624 case ISCSI_PARAM_CONN_ADDRESS
:
625 if (qedi_ep
->ip_type
== TCP_IPV4
)
626 len
= sprintf(buf
, "%pI4\n", qedi_ep
->dst_addr
);
628 len
= sprintf(buf
, "%pI6\n", qedi_ep
->dst_addr
);
637 static int qedi_host_get_param(struct Scsi_Host
*shost
,
638 enum iscsi_host_param param
, char *buf
)
640 struct qedi_ctx
*qedi
;
643 qedi
= iscsi_host_priv(shost
);
646 case ISCSI_HOST_PARAM_HWADDRESS
:
647 len
= sysfs_format_mac(buf
, qedi
->mac
, 6);
649 case ISCSI_HOST_PARAM_NETDEV_NAME
:
650 len
= sprintf(buf
, "host%d\n", shost
->host_no
);
652 case ISCSI_HOST_PARAM_IPADDRESS
:
653 if (qedi
->ip_type
== TCP_IPV4
)
654 len
= sprintf(buf
, "%pI4\n", qedi
->src_ip
);
656 len
= sprintf(buf
, "%pI6\n", qedi
->src_ip
);
659 return iscsi_host_get_param(shost
, param
, buf
);
665 static void qedi_conn_get_stats(struct iscsi_cls_conn
*cls_conn
,
666 struct iscsi_stats
*stats
)
668 struct iscsi_conn
*conn
= cls_conn
->dd_data
;
669 struct qed_iscsi_stats iscsi_stats
;
670 struct Scsi_Host
*shost
;
671 struct qedi_ctx
*qedi
;
673 shost
= iscsi_session_to_shost(iscsi_conn_to_session(cls_conn
));
674 qedi
= iscsi_host_priv(shost
);
675 qedi_ops
->get_stats(qedi
->cdev
, &iscsi_stats
);
677 conn
->txdata_octets
= iscsi_stats
.iscsi_tx_bytes_cnt
;
678 conn
->rxdata_octets
= iscsi_stats
.iscsi_rx_bytes_cnt
;
679 conn
->dataout_pdus_cnt
= (uint32_t)iscsi_stats
.iscsi_tx_data_pdu_cnt
;
680 conn
->datain_pdus_cnt
= (uint32_t)iscsi_stats
.iscsi_rx_data_pdu_cnt
;
681 conn
->r2t_pdus_cnt
= (uint32_t)iscsi_stats
.iscsi_rx_r2t_pdu_cnt
;
683 stats
->txdata_octets
= conn
->txdata_octets
;
684 stats
->rxdata_octets
= conn
->rxdata_octets
;
685 stats
->scsicmd_pdus
= conn
->scsicmd_pdus_cnt
;
686 stats
->dataout_pdus
= conn
->dataout_pdus_cnt
;
687 stats
->scsirsp_pdus
= conn
->scsirsp_pdus_cnt
;
688 stats
->datain_pdus
= conn
->datain_pdus_cnt
;
689 stats
->r2t_pdus
= conn
->r2t_pdus_cnt
;
690 stats
->tmfcmd_pdus
= conn
->tmfcmd_pdus_cnt
;
691 stats
->tmfrsp_pdus
= conn
->tmfrsp_pdus_cnt
;
692 stats
->digest_err
= 0;
693 stats
->timeout_err
= 0;
694 strcpy(stats
->custom
[0].desc
, "eh_abort_cnt");
695 stats
->custom
[0].value
= conn
->eh_abort_cnt
;
696 stats
->custom_length
= 1;
699 static void qedi_iscsi_prep_generic_pdu_bd(struct qedi_conn
*qedi_conn
)
701 struct scsi_sge
*bd_tbl
;
703 bd_tbl
= (struct scsi_sge
*)qedi_conn
->gen_pdu
.req_bd_tbl
;
705 bd_tbl
->sge_addr
.hi
=
706 (u32
)((u64
)qedi_conn
->gen_pdu
.req_dma_addr
>> 32);
707 bd_tbl
->sge_addr
.lo
= (u32
)qedi_conn
->gen_pdu
.req_dma_addr
;
708 bd_tbl
->sge_len
= qedi_conn
->gen_pdu
.req_wr_ptr
-
709 qedi_conn
->gen_pdu
.req_buf
;
710 bd_tbl
= (struct scsi_sge
*)qedi_conn
->gen_pdu
.resp_bd_tbl
;
711 bd_tbl
->sge_addr
.hi
=
712 (u32
)((u64
)qedi_conn
->gen_pdu
.resp_dma_addr
>> 32);
713 bd_tbl
->sge_addr
.lo
= (u32
)qedi_conn
->gen_pdu
.resp_dma_addr
;
714 bd_tbl
->sge_len
= ISCSI_DEF_MAX_RECV_SEG_LEN
;
717 static int qedi_iscsi_send_generic_request(struct iscsi_task
*task
)
719 struct qedi_cmd
*cmd
= task
->dd_data
;
720 struct qedi_conn
*qedi_conn
= cmd
->conn
;
725 qedi_iscsi_prep_generic_pdu_bd(qedi_conn
);
726 switch (task
->hdr
->opcode
& ISCSI_OPCODE_MASK
) {
728 qedi_send_iscsi_login(qedi_conn
, task
);
730 case ISCSI_OP_NOOP_OUT
:
731 data_len
= qedi_conn
->gen_pdu
.req_buf_size
;
732 buf
= qedi_conn
->gen_pdu
.req_buf
;
734 rc
= qedi_send_iscsi_nopout(qedi_conn
, task
,
737 rc
= qedi_send_iscsi_nopout(qedi_conn
, task
,
740 case ISCSI_OP_LOGOUT
:
741 rc
= qedi_send_iscsi_logout(qedi_conn
, task
);
743 case ISCSI_OP_SCSI_TMFUNC
:
744 rc
= qedi_iscsi_abort_work(qedi_conn
, task
);
747 rc
= qedi_send_iscsi_text(qedi_conn
, task
);
750 iscsi_conn_printk(KERN_ALERT
, qedi_conn
->cls_conn
->dd_data
,
751 "unsupported op 0x%x\n", task
->hdr
->opcode
);
757 static int qedi_mtask_xmit(struct iscsi_conn
*conn
, struct iscsi_task
*task
)
759 struct qedi_conn
*qedi_conn
= conn
->dd_data
;
760 struct qedi_cmd
*cmd
= task
->dd_data
;
762 memset(qedi_conn
->gen_pdu
.req_buf
, 0, ISCSI_DEF_MAX_RECV_SEG_LEN
);
764 qedi_conn
->gen_pdu
.req_buf_size
= task
->data_count
;
766 if (task
->data_count
) {
767 memcpy(qedi_conn
->gen_pdu
.req_buf
, task
->data
,
769 qedi_conn
->gen_pdu
.req_wr_ptr
=
770 qedi_conn
->gen_pdu
.req_buf
+ task
->data_count
;
773 cmd
->conn
= conn
->dd_data
;
774 cmd
->scsi_cmd
= NULL
;
775 return qedi_iscsi_send_generic_request(task
);
778 static int qedi_task_xmit(struct iscsi_task
*task
)
780 struct iscsi_conn
*conn
= task
->conn
;
781 struct qedi_conn
*qedi_conn
= conn
->dd_data
;
782 struct qedi_cmd
*cmd
= task
->dd_data
;
783 struct scsi_cmnd
*sc
= task
->sc
;
787 cmd
->use_slowpath
= false;
788 cmd
->conn
= qedi_conn
;
790 cmd
->io_cmd_in_list
= false;
791 INIT_LIST_HEAD(&cmd
->io_cmd
);
794 return qedi_mtask_xmit(conn
, task
);
797 return qedi_iscsi_send_ioreq(task
);
800 static struct iscsi_endpoint
*
801 qedi_ep_connect(struct Scsi_Host
*shost
, struct sockaddr
*dst_addr
,
804 struct qedi_ctx
*qedi
;
805 struct iscsi_endpoint
*ep
;
806 struct qedi_endpoint
*qedi_ep
;
807 struct sockaddr_in
*addr
;
808 struct sockaddr_in6
*addr6
;
809 struct iscsi_path path_req
;
810 u32 msg_type
= ISCSI_KEVENT_IF_DOWN
;
811 u32 iscsi_cid
= QEDI_CID_RESERVED
;
818 QEDI_ERR(NULL
, "shost is NULL\n");
822 if (qedi_do_not_recover
) {
827 qedi
= iscsi_host_priv(shost
);
829 if (test_bit(QEDI_IN_OFFLINE
, &qedi
->flags
) ||
830 test_bit(QEDI_IN_RECOVERY
, &qedi
->flags
)) {
835 ep
= iscsi_create_endpoint(sizeof(struct qedi_endpoint
));
837 QEDI_ERR(&qedi
->dbg_ctx
, "endpoint create fail\n");
841 qedi_ep
= ep
->dd_data
;
842 memset(qedi_ep
, 0, sizeof(struct qedi_endpoint
));
843 qedi_ep
->state
= EP_STATE_IDLE
;
844 qedi_ep
->iscsi_cid
= (u32
)-1;
845 qedi_ep
->qedi
= qedi
;
847 if (dst_addr
->sa_family
== AF_INET
) {
848 addr
= (struct sockaddr_in
*)dst_addr
;
849 memcpy(qedi_ep
->dst_addr
, &addr
->sin_addr
.s_addr
,
850 sizeof(struct in_addr
));
851 qedi_ep
->dst_port
= ntohs(addr
->sin_port
);
852 qedi_ep
->ip_type
= TCP_IPV4
;
853 QEDI_INFO(&qedi
->dbg_ctx
, QEDI_LOG_CONN
,
854 "dst_addr=%pI4, dst_port=%u\n",
855 qedi_ep
->dst_addr
, qedi_ep
->dst_port
);
856 } else if (dst_addr
->sa_family
== AF_INET6
) {
857 addr6
= (struct sockaddr_in6
*)dst_addr
;
858 memcpy(qedi_ep
->dst_addr
, &addr6
->sin6_addr
,
859 sizeof(struct in6_addr
));
860 qedi_ep
->dst_port
= ntohs(addr6
->sin6_port
);
861 qedi_ep
->ip_type
= TCP_IPV6
;
862 QEDI_INFO(&qedi
->dbg_ctx
, QEDI_LOG_CONN
,
863 "dst_addr=%pI6, dst_port=%u\n",
864 qedi_ep
->dst_addr
, qedi_ep
->dst_port
);
866 QEDI_ERR(&qedi
->dbg_ctx
, "Invalid endpoint\n");
869 if (atomic_read(&qedi
->link_state
) != QEDI_LINK_UP
) {
870 QEDI_WARN(&qedi
->dbg_ctx
, "qedi link down\n");
875 ret
= qedi_alloc_sq(qedi
, qedi_ep
);
879 ret
= qedi_ops
->acquire_conn(qedi
->cdev
, &qedi_ep
->handle
,
880 &qedi_ep
->fw_cid
, &qedi_ep
->p_doorbell
);
883 QEDI_ERR(&qedi
->dbg_ctx
, "Could not acquire connection\n");
888 iscsi_cid
= qedi_ep
->handle
;
889 qedi_ep
->iscsi_cid
= iscsi_cid
;
891 init_waitqueue_head(&qedi_ep
->ofld_wait
);
892 init_waitqueue_head(&qedi_ep
->tcp_ofld_wait
);
893 qedi_ep
->state
= EP_STATE_OFLDCONN_START
;
894 qedi
->ep_tbl
[iscsi_cid
] = qedi_ep
;
896 buf
= (char *)&path_req
;
897 len
= sizeof(path_req
);
898 memset(&path_req
, 0, len
);
900 msg_type
= ISCSI_KEVENT_PATH_REQ
;
901 path_req
.handle
= (u64
)qedi_ep
->iscsi_cid
;
902 path_req
.pmtu
= qedi
->ll2_mtu
;
903 qedi_ep
->pmtu
= qedi
->ll2_mtu
;
904 if (qedi_ep
->ip_type
== TCP_IPV4
) {
905 memcpy(&path_req
.dst
.v4_addr
, &qedi_ep
->dst_addr
,
906 sizeof(struct in_addr
));
907 path_req
.ip_addr_len
= 4;
909 memcpy(&path_req
.dst
.v6_addr
, &qedi_ep
->dst_addr
,
910 sizeof(struct in6_addr
));
911 path_req
.ip_addr_len
= 16;
914 ret
= iscsi_offload_mesg(shost
, &qedi_iscsi_transport
, msg_type
, buf
,
917 QEDI_ERR(&qedi
->dbg_ctx
,
918 "iscsi_offload_mesg() failed for cid=0x%x ret=%d\n",
923 atomic_inc(&qedi
->num_offloads
);
927 qedi
->ep_tbl
[iscsi_cid
] = NULL
;
928 tmp
= qedi_ops
->release_conn(qedi
->cdev
, qedi_ep
->handle
);
930 QEDI_WARN(&qedi
->dbg_ctx
, "release_conn returned %d\n",
933 qedi_free_sq(qedi
, qedi_ep
);
935 iscsi_destroy_endpoint(ep
);
939 static int qedi_ep_poll(struct iscsi_endpoint
*ep
, int timeout_ms
)
941 struct qedi_endpoint
*qedi_ep
;
944 if (qedi_do_not_recover
)
947 qedi_ep
= ep
->dd_data
;
948 if (qedi_ep
->state
== EP_STATE_IDLE
||
949 qedi_ep
->state
== EP_STATE_OFLDCONN_NONE
||
950 qedi_ep
->state
== EP_STATE_OFLDCONN_FAILED
)
953 if (qedi_ep
->state
== EP_STATE_OFLDCONN_COMPL
)
956 ret
= wait_event_interruptible_timeout(qedi_ep
->ofld_wait
,
957 QEDI_OFLD_WAIT_STATE(qedi_ep
),
958 msecs_to_jiffies(timeout_ms
));
960 if (qedi_ep
->state
== EP_STATE_OFLDCONN_FAILED
)
971 static void qedi_cleanup_active_cmd_list(struct qedi_conn
*qedi_conn
)
973 struct qedi_cmd
*cmd
, *cmd_tmp
;
975 list_for_each_entry_safe(cmd
, cmd_tmp
, &qedi_conn
->active_cmd_list
,
977 list_del_init(&cmd
->io_cmd
);
978 qedi_conn
->active_cmd_count
--;
982 static void qedi_ep_disconnect(struct iscsi_endpoint
*ep
)
984 struct qedi_endpoint
*qedi_ep
;
985 struct qedi_conn
*qedi_conn
= NULL
;
986 struct iscsi_conn
*conn
= NULL
;
987 struct qedi_ctx
*qedi
;
993 wait_delay
= 60 * HZ
+ DEF_MAX_RT_TIME
;
994 qedi_ep
= ep
->dd_data
;
995 qedi
= qedi_ep
->qedi
;
997 if (qedi_ep
->state
== EP_STATE_OFLDCONN_START
)
998 goto ep_exit_recover
;
1000 flush_work(&qedi_ep
->offload_work
);
1002 if (qedi_ep
->conn
) {
1003 qedi_conn
= qedi_ep
->conn
;
1004 conn
= qedi_conn
->cls_conn
->dd_data
;
1005 iscsi_suspend_queue(conn
);
1006 abrt_conn
= qedi_conn
->abrt_conn
;
1009 if (!test_bit(QEDI_CONN_FW_CLEANUP
,
1010 &qedi_conn
->flags
)) {
1016 if (test_bit(QEDI_IN_RECOVERY
, &qedi
->flags
)) {
1017 if (qedi_do_not_recover
) {
1018 QEDI_INFO(&qedi
->dbg_ctx
, QEDI_LOG_INFO
,
1019 "Do not recover cid=0x%x\n",
1020 qedi_ep
->iscsi_cid
);
1021 goto ep_exit_recover
;
1023 QEDI_INFO(&qedi
->dbg_ctx
, QEDI_LOG_INFO
,
1024 "Reset recovery cid=0x%x, qedi_ep=%p, state=0x%x\n",
1025 qedi_ep
->iscsi_cid
, qedi_ep
, qedi_ep
->state
);
1026 qedi_cleanup_active_cmd_list(qedi_conn
);
1027 goto ep_release_conn
;
1031 if (qedi_do_not_recover
)
1032 goto ep_exit_recover
;
1034 switch (qedi_ep
->state
) {
1035 case EP_STATE_OFLDCONN_START
:
1036 case EP_STATE_OFLDCONN_NONE
:
1037 goto ep_release_conn
;
1038 case EP_STATE_OFLDCONN_FAILED
:
1040 case EP_STATE_OFLDCONN_COMPL
:
1041 if (unlikely(!qedi_conn
))
1044 QEDI_INFO(&qedi
->dbg_ctx
, QEDI_LOG_INFO
,
1045 "Active cmd count=%d, abrt_conn=%d, ep state=0x%x, cid=0x%x, qedi_conn=%p\n",
1046 qedi_conn
->active_cmd_count
, abrt_conn
,
1052 if (!qedi_conn
->active_cmd_count
)
1058 qedi_clearsq(qedi
, qedi_conn
, NULL
);
1064 qedi_ep
->state
= EP_STATE_DISCONN_START
;
1065 ret
= qedi_ops
->destroy_conn(qedi
->cdev
, qedi_ep
->handle
, abrt_conn
);
1067 QEDI_WARN(&qedi
->dbg_ctx
,
1068 "destroy_conn failed returned %d\n", ret
);
1070 ret
= wait_event_interruptible_timeout(
1071 qedi_ep
->tcp_ofld_wait
,
1073 EP_STATE_DISCONN_START
),
1075 if ((ret
<= 0) || (qedi_ep
->state
== EP_STATE_DISCONN_START
)) {
1076 QEDI_WARN(&qedi
->dbg_ctx
,
1077 "Destroy conn timedout or interrupted, ret=%d, delay=%d, cid=0x%x\n",
1078 ret
, wait_delay
, qedi_ep
->iscsi_cid
);
1083 ret
= qedi_ops
->release_conn(qedi
->cdev
, qedi_ep
->handle
);
1085 QEDI_WARN(&qedi
->dbg_ctx
,
1086 "release_conn returned %d, cid=0x%x\n",
1087 ret
, qedi_ep
->iscsi_cid
);
1089 qedi_ep
->state
= EP_STATE_IDLE
;
1090 qedi
->ep_tbl
[qedi_ep
->iscsi_cid
] = NULL
;
1091 qedi
->cid_que
.conn_cid_tbl
[qedi_ep
->iscsi_cid
] = NULL
;
1092 qedi_free_id(&qedi
->lcl_port_tbl
, qedi_ep
->src_port
);
1093 qedi_free_sq(qedi
, qedi_ep
);
1096 qedi_conn
->ep
= NULL
;
1098 qedi_ep
->conn
= NULL
;
1099 qedi_ep
->qedi
= NULL
;
1100 atomic_dec(&qedi
->num_offloads
);
1102 iscsi_destroy_endpoint(ep
);
1105 static int qedi_data_avail(struct qedi_ctx
*qedi
, u16 vlanid
)
1107 struct qed_dev
*cdev
= qedi
->cdev
;
1108 struct qedi_uio_dev
*udev
;
1109 struct qedi_uio_ctrl
*uctrl
;
1110 struct sk_buff
*skb
;
1116 QEDI_ERR(&qedi
->dbg_ctx
, "udev is NULL.\n");
1120 uctrl
= (struct qedi_uio_ctrl
*)udev
->uctrl
;
1122 QEDI_ERR(&qedi
->dbg_ctx
, "uctlr is NULL.\n");
1126 len
= uctrl
->host_tx_pkt_len
;
1128 QEDI_ERR(&qedi
->dbg_ctx
, "Invalid len %u\n", len
);
1132 skb
= alloc_skb(len
, GFP_ATOMIC
);
1134 QEDI_ERR(&qedi
->dbg_ctx
, "alloc_skb failed\n");
1139 memcpy(skb
->data
, udev
->tx_pkt
, len
);
1140 skb
->ip_summed
= CHECKSUM_NONE
;
1143 __vlan_hwaccel_put_tag(skb
, htons(ETH_P_8021Q
), vlanid
);
1145 rc
= qedi_ops
->ll2
->start_xmit(cdev
, skb
, 0);
1147 QEDI_ERR(&qedi
->dbg_ctx
, "ll2 start_xmit returned %d\n",
1152 uctrl
->host_tx_pkt_len
= 0;
1153 uctrl
->hw_tx_cons
++;
1158 static void qedi_offload_work(struct work_struct
*work
)
1160 struct qedi_endpoint
*qedi_ep
=
1161 container_of(work
, struct qedi_endpoint
, offload_work
);
1162 struct qedi_ctx
*qedi
;
1163 int wait_delay
= 5 * HZ
;
1166 qedi
= qedi_ep
->qedi
;
1168 ret
= qedi_iscsi_offload_conn(qedi_ep
);
1170 QEDI_ERR(&qedi
->dbg_ctx
,
1171 "offload error: iscsi_cid=%u, qedi_ep=%p, ret=%d\n",
1172 qedi_ep
->iscsi_cid
, qedi_ep
, ret
);
1173 qedi_ep
->state
= EP_STATE_OFLDCONN_FAILED
;
1177 ret
= wait_event_interruptible_timeout(qedi_ep
->tcp_ofld_wait
,
1179 EP_STATE_OFLDCONN_COMPL
),
1181 if ((ret
<= 0) || (qedi_ep
->state
!= EP_STATE_OFLDCONN_COMPL
)) {
1182 qedi_ep
->state
= EP_STATE_OFLDCONN_FAILED
;
1183 QEDI_ERR(&qedi
->dbg_ctx
,
1184 "Offload conn TIMEOUT iscsi_cid=%u, qedi_ep=%p\n",
1185 qedi_ep
->iscsi_cid
, qedi_ep
);
1189 static int qedi_set_path(struct Scsi_Host
*shost
, struct iscsi_path
*path_data
)
1191 struct qedi_ctx
*qedi
;
1192 struct qedi_endpoint
*qedi_ep
;
1199 QEDI_ERR(NULL
, "shost is NULL\n");
1203 if (strcmp(shost
->hostt
->proc_name
, "qedi")) {
1205 QEDI_ERR(NULL
, "shost %s is invalid\n",
1206 shost
->hostt
->proc_name
);
1210 qedi
= iscsi_host_priv(shost
);
1211 if (path_data
->handle
== QEDI_PATH_HANDLE
) {
1212 ret
= qedi_data_avail(qedi
, path_data
->vlan_id
);
1216 iscsi_cid
= (u32
)path_data
->handle
;
1217 qedi_ep
= qedi
->ep_tbl
[iscsi_cid
];
1218 QEDI_INFO(&qedi
->dbg_ctx
, QEDI_LOG_INFO
,
1219 "iscsi_cid=0x%x, qedi_ep=%p\n", iscsi_cid
, qedi_ep
);
1225 if (!is_valid_ether_addr(&path_data
->mac_addr
[0])) {
1226 QEDI_NOTICE(&qedi
->dbg_ctx
, "dst mac NOT VALID\n");
1227 qedi_ep
->state
= EP_STATE_OFLDCONN_NONE
;
1232 ether_addr_copy(&qedi_ep
->src_mac
[0], &qedi
->mac
[0]);
1233 ether_addr_copy(&qedi_ep
->dst_mac
[0], &path_data
->mac_addr
[0]);
1235 qedi_ep
->vlan_id
= path_data
->vlan_id
;
1236 if (path_data
->pmtu
< DEF_PATH_MTU
) {
1237 qedi_ep
->pmtu
= qedi
->ll2_mtu
;
1238 QEDI_INFO(&qedi
->dbg_ctx
, QEDI_LOG_INFO
,
1239 "MTU cannot be %u, using default MTU %u\n",
1240 path_data
->pmtu
, qedi_ep
->pmtu
);
1243 if (path_data
->pmtu
!= qedi
->ll2_mtu
) {
1244 if (path_data
->pmtu
> JUMBO_MTU
) {
1246 QEDI_ERR(NULL
, "Invalid MTU %u\n", path_data
->pmtu
);
1250 qedi_reset_host_mtu(qedi
, path_data
->pmtu
);
1251 qedi_ep
->pmtu
= qedi
->ll2_mtu
;
1254 port_id
= qedi_ep
->src_port
;
1255 if (port_id
>= QEDI_LOCAL_PORT_MIN
&&
1256 port_id
< QEDI_LOCAL_PORT_MAX
) {
1257 if (qedi_alloc_id(&qedi
->lcl_port_tbl
, port_id
))
1264 port_id
= qedi_alloc_new_id(&qedi
->lcl_port_tbl
);
1265 if (port_id
== QEDI_LOCAL_PORT_INVALID
) {
1266 QEDI_ERR(&qedi
->dbg_ctx
,
1267 "Failed to allocate port id for iscsi_cid=0x%x\n",
1274 qedi_ep
->src_port
= port_id
;
1276 if (qedi_ep
->ip_type
== TCP_IPV4
) {
1277 memcpy(&qedi_ep
->src_addr
[0], &path_data
->src
.v4_addr
,
1278 sizeof(struct in_addr
));
1279 memcpy(&qedi
->src_ip
[0], &path_data
->src
.v4_addr
,
1280 sizeof(struct in_addr
));
1281 qedi
->ip_type
= TCP_IPV4
;
1283 QEDI_INFO(&qedi
->dbg_ctx
, QEDI_LOG_CONN
,
1284 "src addr:port=%pI4:%u, dst addr:port=%pI4:%u\n",
1285 qedi_ep
->src_addr
, qedi_ep
->src_port
,
1286 qedi_ep
->dst_addr
, qedi_ep
->dst_port
);
1288 memcpy(&qedi_ep
->src_addr
[0], &path_data
->src
.v6_addr
,
1289 sizeof(struct in6_addr
));
1290 memcpy(&qedi
->src_ip
[0], &path_data
->src
.v6_addr
,
1291 sizeof(struct in6_addr
));
1292 qedi
->ip_type
= TCP_IPV6
;
1294 QEDI_INFO(&qedi
->dbg_ctx
, QEDI_LOG_CONN
,
1295 "src addr:port=%pI6:%u, dst addr:port=%pI6:%u\n",
1296 qedi_ep
->src_addr
, qedi_ep
->src_port
,
1297 qedi_ep
->dst_addr
, qedi_ep
->dst_port
);
1300 INIT_WORK(&qedi_ep
->offload_work
, qedi_offload_work
);
1301 queue_work(qedi
->offload_thread
, &qedi_ep
->offload_work
);
1309 static umode_t
qedi_attr_is_visible(int param_type
, int param
)
1311 switch (param_type
) {
1312 case ISCSI_HOST_PARAM
:
1314 case ISCSI_HOST_PARAM_NETDEV_NAME
:
1315 case ISCSI_HOST_PARAM_HWADDRESS
:
1316 case ISCSI_HOST_PARAM_IPADDRESS
:
1323 case ISCSI_PARAM_MAX_RECV_DLENGTH
:
1324 case ISCSI_PARAM_MAX_XMIT_DLENGTH
:
1325 case ISCSI_PARAM_HDRDGST_EN
:
1326 case ISCSI_PARAM_DATADGST_EN
:
1327 case ISCSI_PARAM_CONN_ADDRESS
:
1328 case ISCSI_PARAM_CONN_PORT
:
1329 case ISCSI_PARAM_EXP_STATSN
:
1330 case ISCSI_PARAM_PERSISTENT_ADDRESS
:
1331 case ISCSI_PARAM_PERSISTENT_PORT
:
1332 case ISCSI_PARAM_PING_TMO
:
1333 case ISCSI_PARAM_RECV_TMO
:
1334 case ISCSI_PARAM_INITIAL_R2T_EN
:
1335 case ISCSI_PARAM_MAX_R2T
:
1336 case ISCSI_PARAM_IMM_DATA_EN
:
1337 case ISCSI_PARAM_FIRST_BURST
:
1338 case ISCSI_PARAM_MAX_BURST
:
1339 case ISCSI_PARAM_PDU_INORDER_EN
:
1340 case ISCSI_PARAM_DATASEQ_INORDER_EN
:
1341 case ISCSI_PARAM_ERL
:
1342 case ISCSI_PARAM_TARGET_NAME
:
1343 case ISCSI_PARAM_TPGT
:
1344 case ISCSI_PARAM_USERNAME
:
1345 case ISCSI_PARAM_PASSWORD
:
1346 case ISCSI_PARAM_USERNAME_IN
:
1347 case ISCSI_PARAM_PASSWORD_IN
:
1348 case ISCSI_PARAM_FAST_ABORT
:
1349 case ISCSI_PARAM_ABORT_TMO
:
1350 case ISCSI_PARAM_LU_RESET_TMO
:
1351 case ISCSI_PARAM_TGT_RESET_TMO
:
1352 case ISCSI_PARAM_IFACE_NAME
:
1353 case ISCSI_PARAM_INITIATOR_NAME
:
1354 case ISCSI_PARAM_BOOT_ROOT
:
1355 case ISCSI_PARAM_BOOT_NIC
:
1356 case ISCSI_PARAM_BOOT_TARGET
:
1366 static void qedi_cleanup_task(struct iscsi_task
*task
)
1368 if (!task
->sc
|| task
->state
== ISCSI_TASK_PENDING
) {
1369 QEDI_INFO(NULL
, QEDI_LOG_IO
, "Returning ref_cnt=%d\n",
1370 refcount_read(&task
->refcount
));
1374 qedi_iscsi_unmap_sg_list(task
->dd_data
);
1377 struct iscsi_transport qedi_iscsi_transport
= {
1378 .owner
= THIS_MODULE
,
1379 .name
= QEDI_MODULE_NAME
,
1380 .caps
= CAP_RECOVERY_L0
| CAP_HDRDGST
| CAP_MULTI_R2T
| CAP_DATADGST
|
1381 CAP_DATA_PATH_OFFLOAD
| CAP_TEXT_NEGO
,
1382 .create_session
= qedi_session_create
,
1383 .destroy_session
= qedi_session_destroy
,
1384 .create_conn
= qedi_conn_create
,
1385 .bind_conn
= qedi_conn_bind
,
1386 .start_conn
= qedi_conn_start
,
1387 .stop_conn
= iscsi_conn_stop
,
1388 .destroy_conn
= qedi_conn_destroy
,
1389 .set_param
= iscsi_set_param
,
1390 .get_ep_param
= qedi_ep_get_param
,
1391 .get_conn_param
= iscsi_conn_get_param
,
1392 .get_session_param
= iscsi_session_get_param
,
1393 .get_host_param
= qedi_host_get_param
,
1394 .send_pdu
= iscsi_conn_send_pdu
,
1395 .get_stats
= qedi_conn_get_stats
,
1396 .xmit_task
= qedi_task_xmit
,
1397 .cleanup_task
= qedi_cleanup_task
,
1398 .session_recovery_timedout
= iscsi_session_recovery_timedout
,
1399 .ep_connect
= qedi_ep_connect
,
1400 .ep_poll
= qedi_ep_poll
,
1401 .ep_disconnect
= qedi_ep_disconnect
,
1402 .set_path
= qedi_set_path
,
1403 .attr_is_visible
= qedi_attr_is_visible
,
1406 void qedi_start_conn_recovery(struct qedi_ctx
*qedi
,
1407 struct qedi_conn
*qedi_conn
)
1409 struct iscsi_cls_session
*cls_sess
;
1410 struct iscsi_cls_conn
*cls_conn
;
1411 struct iscsi_conn
*conn
;
1413 cls_conn
= qedi_conn
->cls_conn
;
1414 conn
= cls_conn
->dd_data
;
1415 cls_sess
= iscsi_conn_to_session(cls_conn
);
1417 if (iscsi_is_session_online(cls_sess
)) {
1418 qedi_conn
->abrt_conn
= 1;
1419 QEDI_ERR(&qedi
->dbg_ctx
,
1420 "Failing connection, state=0x%x, cid=0x%x\n",
1421 conn
->session
->state
, qedi_conn
->iscsi_conn_id
);
1422 iscsi_conn_failure(qedi_conn
->cls_conn
->dd_data
,
1423 ISCSI_ERR_CONN_FAILED
);
1427 static const struct {
1428 enum iscsi_error_types error_code
;
1430 } qedi_iscsi_error
[] = {
1431 { ISCSI_STATUS_NONE
,
1434 { ISCSI_CONN_ERROR_TASK_CID_MISMATCH
,
1437 { ISCSI_CONN_ERROR_TASK_NOT_VALID
,
1440 { ISCSI_CONN_ERROR_RQ_RING_IS_FULL
,
1443 { ISCSI_CONN_ERROR_CMDQ_RING_IS_FULL
,
1446 { ISCSI_CONN_ERROR_HQE_CACHING_FAILED
,
1447 "sge caching failed"
1449 { ISCSI_CONN_ERROR_HEADER_DIGEST_ERROR
,
1452 { ISCSI_CONN_ERROR_LOCAL_COMPLETION_ERROR
,
1455 { ISCSI_CONN_ERROR_DATA_OVERRUN
,
1458 { ISCSI_CONN_ERROR_OUT_OF_SGES_ERROR
,
1461 { ISCSI_CONN_ERROR_TCP_IP_FRAGMENT_ERROR
,
1462 "tcp ip fragment error"
1464 { ISCSI_CONN_ERROR_PROTOCOL_ERR_AHS_LEN
,
1465 "AHS len protocol error"
1467 { ISCSI_CONN_ERROR_PROTOCOL_ERR_ITT_OUT_OF_RANGE
,
1468 "itt out of range error"
1470 { ISCSI_CONN_ERROR_PROTOCOL_ERR_DATA_SEG_LEN_EXCEEDS_PDU_SIZE
,
1471 "data seg more than pdu size"
1473 { ISCSI_CONN_ERROR_PROTOCOL_ERR_INVALID_OPCODE
,
1476 { ISCSI_CONN_ERROR_PROTOCOL_ERR_INVALID_OPCODE_BEFORE_UPDATE
,
1477 "invalid opcode before update"
1479 { ISCSI_CONN_ERROR_UNVALID_NOPIN_DSL
,
1482 { ISCSI_CONN_ERROR_PROTOCOL_ERR_R2T_CARRIES_NO_DATA
,
1483 "r2t carries no data"
1485 { ISCSI_CONN_ERROR_PROTOCOL_ERR_DATA_SN
,
1488 { ISCSI_CONN_ERROR_PROTOCOL_ERR_DATA_IN_TTT
,
1491 { ISCSI_CONN_ERROR_PROTOCOL_ERR_R2T_TTT
,
1494 { ISCSI_CONN_ERROR_PROTOCOL_ERR_R2T_BUFFER_OFFSET
,
1495 "buffer offset error"
1497 { ISCSI_CONN_ERROR_PROTOCOL_ERR_BUFFER_OFFSET_OOO
,
1500 { ISCSI_CONN_ERROR_PROTOCOL_ERR_R2T_SN
,
1503 { ISCSI_CONN_ERROR_PROTOCOL_ERR_DESIRED_DATA_TRNS_LEN_0
,
1504 "data xer len error"
1506 { ISCSI_CONN_ERROR_PROTOCOL_ERR_DESIRED_DATA_TRNS_LEN_1
,
1507 "data xer len1 error"
1509 { ISCSI_CONN_ERROR_PROTOCOL_ERR_DESIRED_DATA_TRNS_LEN_2
,
1510 "data xer len2 error"
1512 { ISCSI_CONN_ERROR_PROTOCOL_ERR_LUN
,
1513 "protocol lun error"
1515 { ISCSI_CONN_ERROR_PROTOCOL_ERR_F_BIT_ZERO
,
1518 { ISCSI_CONN_ERROR_PROTOCOL_ERR_EXP_STAT_SN
,
1521 { ISCSI_CONN_ERROR_PROTOCOL_ERR_DSL_NOT_ZERO
,
1522 "dsl not zero error"
1524 { ISCSI_CONN_ERROR_PROTOCOL_ERR_INVALID_DSL
,
1527 { ISCSI_CONN_ERROR_PROTOCOL_ERR_DATA_SEG_LEN_TOO_BIG
,
1528 "data seg len too big"
1530 { ISCSI_CONN_ERROR_PROTOCOL_ERR_OUTSTANDING_R2T_COUNT
,
1531 "outstanding r2t count error"
1533 { ISCSI_CONN_ERROR_SENSE_DATA_LENGTH
,
1534 "sense datalen error"
1538 char *qedi_get_iscsi_error(enum iscsi_error_types err_code
)
1543 for (i
= 0; i
< ARRAY_SIZE(qedi_iscsi_error
); i
++) {
1544 if (qedi_iscsi_error
[i
].error_code
== err_code
) {
1545 msg
= qedi_iscsi_error
[i
].err_string
;
1552 void qedi_process_iscsi_error(struct qedi_endpoint
*ep
,
1553 struct iscsi_eqe_data
*data
)
1555 struct qedi_conn
*qedi_conn
;
1556 struct qedi_ctx
*qedi
;
1557 char warn_notice
[] = "iscsi_warning";
1558 char error_notice
[] = "iscsi_error";
1559 char unknown_msg
[] = "Unknown error";
1561 int need_recovery
= 0;
1568 qedi_conn
= ep
->conn
;
1574 QEDI_ERR(&qedi
->dbg_ctx
, "async event iscsi error:0x%x\n",
1579 message
= warn_notice
;
1582 message
= error_notice
;
1585 msg
= qedi_get_iscsi_error(data
->error_code
);
1591 iscsi_conn_printk(KERN_ALERT
,
1592 qedi_conn
->cls_conn
->dd_data
,
1593 "qedi: %s - %s\n", message
, msg
);
1596 qedi_start_conn_recovery(qedi_conn
->qedi
, qedi_conn
);
1599 void qedi_process_tcp_error(struct qedi_endpoint
*ep
,
1600 struct iscsi_eqe_data
*data
)
1602 struct qedi_conn
*qedi_conn
;
1607 qedi_conn
= ep
->conn
;
1611 QEDI_ERR(&ep
->qedi
->dbg_ctx
, "async event TCP error:0x%x\n",
1614 qedi_start_conn_recovery(qedi_conn
->qedi
, qedi_conn
);