1 // SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause)
2 /* QLogic qed NIC Driver
3 * Copyright (c) 2015-2017 QLogic Corporation
4 * Copyright (c) 2019-2020 Marvell International Ltd.
7 #include <linux/types.h>
8 #include <asm/byteorder.h>
10 #include <linux/delay.h>
11 #include <linux/dma-mapping.h>
12 #include <linux/etherdevice.h>
13 #include <linux/interrupt.h>
14 #include <linux/kernel.h>
15 #include <linux/log2.h>
16 #include <linux/module.h>
17 #include <linux/pci.h>
18 #include <linux/slab.h>
19 #include <linux/stddef.h>
20 #include <linux/string.h>
21 #include <linux/workqueue.h>
22 #include <linux/errno.h>
23 #include <linux/list.h>
24 #include <linux/spinlock.h>
25 #include <linux/qed/qed_iscsi_if.h>
28 #include "qed_dev_api.h"
32 #include "qed_iscsi.h"
36 #include "qed_sriov.h"
37 #include "qed_reg_addr.h"
39 struct qed_iscsi_conn
{
40 struct list_head list_entry
;
51 dma_addr_t sq_pbl_addr
;
52 struct qed_chain r2tq
;
56 struct tcp_upload_params
*tcp_upload_params_virt_addr
;
57 dma_addr_t tcp_upload_params_phys_addr
;
58 struct scsi_terminate_extra_params
*queue_cnts_virt_addr
;
59 dma_addr_t queue_cnts_phys_addr
;
60 dma_addr_t syn_phy_addr
;
62 u16 syn_ip_payload_length
;
104 u16 da_timeout_value
;
110 u32 max_recv_pdu_length
;
111 u32 max_send_pdu_length
;
112 u32 first_seq_length
;
117 u8 abortive_dsconnect
;
120 static int qed_iscsi_async_event(struct qed_hwfn
*p_hwfn
, u8 fw_event_code
,
121 __le16 echo
, union event_ring_data
*data
,
124 if (p_hwfn
->p_iscsi_info
->event_cb
) {
125 struct qed_iscsi_info
*p_iscsi
= p_hwfn
->p_iscsi_info
;
127 return p_iscsi
->event_cb(p_iscsi
->event_context
,
128 fw_event_code
, data
);
130 DP_NOTICE(p_hwfn
, "iSCSI async completion is not set\n");
136 qed_sp_iscsi_func_start(struct qed_hwfn
*p_hwfn
,
137 enum spq_mode comp_mode
,
138 struct qed_spq_comp_cb
*p_comp_addr
,
139 void *event_context
, iscsi_event_cb_t async_event_cb
)
141 struct iscsi_init_ramrod_params
*p_ramrod
= NULL
;
142 struct scsi_init_func_queues
*p_queue
= NULL
;
143 struct qed_iscsi_pf_params
*p_params
= NULL
;
144 struct iscsi_spe_func_init
*p_init
= NULL
;
145 struct qed_spq_entry
*p_ent
= NULL
;
146 struct qed_sp_init_data init_data
;
153 memset(&init_data
, 0, sizeof(init_data
));
154 init_data
.cid
= qed_spq_get_cid(p_hwfn
);
155 init_data
.opaque_fid
= p_hwfn
->hw_info
.opaque_fid
;
156 init_data
.comp_mode
= comp_mode
;
157 init_data
.p_comp_data
= p_comp_addr
;
159 rc
= qed_sp_init_request(p_hwfn
, &p_ent
,
160 ISCSI_RAMROD_CMD_ID_INIT_FUNC
,
161 PROTOCOLID_ISCSI
, &init_data
);
165 p_ramrod
= &p_ent
->ramrod
.iscsi_init
;
166 p_init
= &p_ramrod
->iscsi_init_spe
;
167 p_params
= &p_hwfn
->pf_params
.iscsi_pf_params
;
168 p_queue
= &p_init
->q_params
;
171 if (p_params
->num_queues
> p_hwfn
->hw_info
.feat_num
[QED_ISCSI_CQ
]) {
173 "Cannot satisfy CQ amount. Queues requested %d, CQs available %d. Aborting function start\n",
174 p_params
->num_queues
,
175 p_hwfn
->hw_info
.feat_num
[QED_ISCSI_CQ
]);
176 qed_sp_destroy_request(p_hwfn
, p_ent
);
180 val
= p_params
->half_way_close_timeout
;
181 p_init
->half_way_close_timeout
= cpu_to_le16(val
);
182 p_init
->num_sq_pages_in_ring
= p_params
->num_sq_pages_in_ring
;
183 p_init
->num_r2tq_pages_in_ring
= p_params
->num_r2tq_pages_in_ring
;
184 p_init
->num_uhq_pages_in_ring
= p_params
->num_uhq_pages_in_ring
;
185 p_init
->ll2_rx_queue_id
=
186 p_hwfn
->hw_info
.resc_start
[QED_LL2_RAM_QUEUE
] +
187 p_params
->ll2_ooo_queue_id
;
189 p_init
->func_params
.log_page_size
= p_params
->log_page_size
;
190 val
= p_params
->num_tasks
;
191 p_init
->func_params
.num_tasks
= cpu_to_le16(val
);
192 p_init
->debug_mode
.flags
= p_params
->debug_mode
;
194 DMA_REGPAIR_LE(p_queue
->glbl_q_params_addr
,
195 p_params
->glbl_q_params_addr
);
197 val
= p_params
->cq_num_entries
;
198 p_queue
->cq_num_entries
= cpu_to_le16(val
);
199 val
= p_params
->cmdq_num_entries
;
200 p_queue
->cmdq_num_entries
= cpu_to_le16(val
);
201 p_queue
->num_queues
= p_params
->num_queues
;
202 dval
= (u8
)p_hwfn
->hw_info
.resc_start
[QED_CMDQS_CQS
];
203 p_queue
->queue_relative_offset
= (u8
)dval
;
204 p_queue
->cq_sb_pi
= p_params
->gl_rq_pi
;
205 p_queue
->cmdq_sb_pi
= p_params
->gl_cmd_pi
;
207 for (i
= 0; i
< p_params
->num_queues
; i
++) {
208 val
= qed_get_igu_sb_id(p_hwfn
, i
);
209 p_queue
->cq_cmdq_sb_num_arr
[i
] = cpu_to_le16(val
);
212 p_queue
->bdq_resource_id
= (u8
)RESC_START(p_hwfn
, QED_BDQ
);
214 DMA_REGPAIR_LE(p_queue
->bdq_pbl_base_address
[BDQ_ID_RQ
],
215 p_params
->bdq_pbl_base_addr
[BDQ_ID_RQ
]);
216 p_queue
->bdq_pbl_num_entries
[BDQ_ID_RQ
] =
217 p_params
->bdq_pbl_num_entries
[BDQ_ID_RQ
];
218 val
= p_params
->bdq_xoff_threshold
[BDQ_ID_RQ
];
219 p_queue
->bdq_xoff_threshold
[BDQ_ID_RQ
] = cpu_to_le16(val
);
220 val
= p_params
->bdq_xon_threshold
[BDQ_ID_RQ
];
221 p_queue
->bdq_xon_threshold
[BDQ_ID_RQ
] = cpu_to_le16(val
);
223 DMA_REGPAIR_LE(p_queue
->bdq_pbl_base_address
[BDQ_ID_IMM_DATA
],
224 p_params
->bdq_pbl_base_addr
[BDQ_ID_IMM_DATA
]);
225 p_queue
->bdq_pbl_num_entries
[BDQ_ID_IMM_DATA
] =
226 p_params
->bdq_pbl_num_entries
[BDQ_ID_IMM_DATA
];
227 val
= p_params
->bdq_xoff_threshold
[BDQ_ID_IMM_DATA
];
228 p_queue
->bdq_xoff_threshold
[BDQ_ID_IMM_DATA
] = cpu_to_le16(val
);
229 val
= p_params
->bdq_xon_threshold
[BDQ_ID_IMM_DATA
];
230 p_queue
->bdq_xon_threshold
[BDQ_ID_IMM_DATA
] = cpu_to_le16(val
);
231 val
= p_params
->rq_buffer_size
;
232 p_queue
->rq_buffer_size
= cpu_to_le16(val
);
233 if (p_params
->is_target
) {
234 SET_FIELD(p_queue
->q_validity
,
235 SCSI_INIT_FUNC_QUEUES_RQ_VALID
, 1);
236 if (p_queue
->bdq_pbl_num_entries
[BDQ_ID_IMM_DATA
])
237 SET_FIELD(p_queue
->q_validity
,
238 SCSI_INIT_FUNC_QUEUES_IMM_DATA_VALID
, 1);
239 SET_FIELD(p_queue
->q_validity
,
240 SCSI_INIT_FUNC_QUEUES_CMD_VALID
, 1);
242 SET_FIELD(p_queue
->q_validity
,
243 SCSI_INIT_FUNC_QUEUES_RQ_VALID
, 1);
245 p_ramrod
->tcp_init
.two_msl_timer
= cpu_to_le32(p_params
->two_msl_timer
);
246 val
= p_params
->tx_sws_timer
;
247 p_ramrod
->tcp_init
.tx_sws_timer
= cpu_to_le16(val
);
248 p_ramrod
->tcp_init
.max_fin_rt
= p_params
->max_fin_rt
;
250 p_hwfn
->p_iscsi_info
->event_context
= event_context
;
251 p_hwfn
->p_iscsi_info
->event_cb
= async_event_cb
;
253 qed_spq_register_async_cb(p_hwfn
, PROTOCOLID_ISCSI
,
254 qed_iscsi_async_event
);
256 return qed_spq_post(p_hwfn
, p_ent
, NULL
);
259 static int qed_sp_iscsi_conn_offload(struct qed_hwfn
*p_hwfn
,
260 struct qed_iscsi_conn
*p_conn
,
261 enum spq_mode comp_mode
,
262 struct qed_spq_comp_cb
*p_comp_addr
)
264 struct iscsi_spe_conn_offload
*p_ramrod
= NULL
;
265 struct tcp_offload_params_opt2
*p_tcp2
= NULL
;
266 struct tcp_offload_params
*p_tcp
= NULL
;
267 struct qed_spq_entry
*p_ent
= NULL
;
268 struct qed_sp_init_data init_data
;
269 dma_addr_t r2tq_pbl_addr
;
270 dma_addr_t xhq_pbl_addr
;
271 dma_addr_t uhq_pbl_addr
;
281 memset(&init_data
, 0, sizeof(init_data
));
282 init_data
.cid
= p_conn
->icid
;
283 init_data
.opaque_fid
= p_hwfn
->hw_info
.opaque_fid
;
284 init_data
.comp_mode
= comp_mode
;
285 init_data
.p_comp_data
= p_comp_addr
;
287 rc
= qed_sp_init_request(p_hwfn
, &p_ent
,
288 ISCSI_RAMROD_CMD_ID_OFFLOAD_CONN
,
289 PROTOCOLID_ISCSI
, &init_data
);
293 p_ramrod
= &p_ent
->ramrod
.iscsi_conn_offload
;
295 /* Transmission PQ is the first of the PF */
296 physical_q
= qed_get_cm_pq_idx(p_hwfn
, PQ_FLAGS_OFLD
);
297 p_conn
->physical_q0
= physical_q
;
298 p_ramrod
->iscsi
.physical_q0
= cpu_to_le16(physical_q
);
300 /* iSCSI Pure-ACK PQ */
301 physical_q
= qed_get_cm_pq_idx(p_hwfn
, PQ_FLAGS_ACK
);
302 p_conn
->physical_q1
= physical_q
;
303 p_ramrod
->iscsi
.physical_q1
= cpu_to_le16(physical_q
);
305 p_ramrod
->conn_id
= cpu_to_le16(p_conn
->conn_id
);
307 DMA_REGPAIR_LE(p_ramrod
->iscsi
.sq_pbl_addr
, p_conn
->sq_pbl_addr
);
309 r2tq_pbl_addr
= qed_chain_get_pbl_phys(&p_conn
->r2tq
);
310 DMA_REGPAIR_LE(p_ramrod
->iscsi
.r2tq_pbl_addr
, r2tq_pbl_addr
);
312 xhq_pbl_addr
= qed_chain_get_pbl_phys(&p_conn
->xhq
);
313 DMA_REGPAIR_LE(p_ramrod
->iscsi
.xhq_pbl_addr
, xhq_pbl_addr
);
315 uhq_pbl_addr
= qed_chain_get_pbl_phys(&p_conn
->uhq
);
316 DMA_REGPAIR_LE(p_ramrod
->iscsi
.uhq_pbl_addr
, uhq_pbl_addr
);
318 p_ramrod
->iscsi
.initial_ack
= cpu_to_le32(p_conn
->initial_ack
);
319 p_ramrod
->iscsi
.flags
= p_conn
->offl_flags
;
320 p_ramrod
->iscsi
.default_cq
= p_conn
->default_cq
;
321 p_ramrod
->iscsi
.stat_sn
= cpu_to_le32(p_conn
->stat_sn
);
323 if (!GET_FIELD(p_ramrod
->iscsi
.flags
,
324 ISCSI_CONN_OFFLOAD_PARAMS_TCP_ON_CHIP_1B
)) {
325 p_tcp
= &p_ramrod
->tcp
;
327 p
= (u16
*)p_conn
->local_mac
;
328 tmp
= cpu_to_le16(get_unaligned_be16(p
));
329 p_tcp
->local_mac_addr_hi
= tmp
;
330 tmp
= cpu_to_le16(get_unaligned_be16(p
+ 1));
331 p_tcp
->local_mac_addr_mid
= tmp
;
332 tmp
= cpu_to_le16(get_unaligned_be16(p
+ 2));
333 p_tcp
->local_mac_addr_lo
= tmp
;
335 p
= (u16
*)p_conn
->remote_mac
;
336 tmp
= cpu_to_le16(get_unaligned_be16(p
));
337 p_tcp
->remote_mac_addr_hi
= tmp
;
338 tmp
= cpu_to_le16(get_unaligned_be16(p
+ 1));
339 p_tcp
->remote_mac_addr_mid
= tmp
;
340 tmp
= cpu_to_le16(get_unaligned_be16(p
+ 2));
341 p_tcp
->remote_mac_addr_lo
= tmp
;
343 p_tcp
->vlan_id
= cpu_to_le16(p_conn
->vlan_id
);
345 p_tcp
->flags
= cpu_to_le16(p_conn
->tcp_flags
);
346 p_tcp
->ip_version
= p_conn
->ip_version
;
347 for (i
= 0; i
< 4; i
++) {
348 dval
= p_conn
->remote_ip
[i
];
349 p_tcp
->remote_ip
[i
] = cpu_to_le32(dval
);
350 dval
= p_conn
->local_ip
[i
];
351 p_tcp
->local_ip
[i
] = cpu_to_le32(dval
);
353 p_tcp
->ka_max_probe_cnt
= p_conn
->ka_max_probe_cnt
;
354 p_tcp
->dup_ack_theshold
= p_conn
->dup_ack_theshold
;
356 p_tcp
->rcv_next
= cpu_to_le32(p_conn
->rcv_next
);
357 p_tcp
->snd_una
= cpu_to_le32(p_conn
->snd_una
);
358 p_tcp
->snd_next
= cpu_to_le32(p_conn
->snd_next
);
359 p_tcp
->snd_max
= cpu_to_le32(p_conn
->snd_max
);
360 p_tcp
->snd_wnd
= cpu_to_le32(p_conn
->snd_wnd
);
361 p_tcp
->rcv_wnd
= cpu_to_le32(p_conn
->rcv_wnd
);
362 p_tcp
->snd_wl1
= cpu_to_le32(p_conn
->snd_wl1
);
363 p_tcp
->cwnd
= cpu_to_le32(p_conn
->cwnd
);
364 p_tcp
->ss_thresh
= cpu_to_le32(p_conn
->ss_thresh
);
365 p_tcp
->srtt
= cpu_to_le16(p_conn
->srtt
);
366 p_tcp
->rtt_var
= cpu_to_le16(p_conn
->rtt_var
);
367 p_tcp
->ts_recent
= cpu_to_le32(p_conn
->ts_recent
);
368 p_tcp
->ts_recent_age
= cpu_to_le32(p_conn
->ts_recent_age
);
369 p_tcp
->total_rt
= cpu_to_le32(p_conn
->total_rt
);
370 dval
= p_conn
->ka_timeout_delta
;
371 p_tcp
->ka_timeout_delta
= cpu_to_le32(dval
);
372 dval
= p_conn
->rt_timeout_delta
;
373 p_tcp
->rt_timeout_delta
= cpu_to_le32(dval
);
374 p_tcp
->dup_ack_cnt
= p_conn
->dup_ack_cnt
;
375 p_tcp
->snd_wnd_probe_cnt
= p_conn
->snd_wnd_probe_cnt
;
376 p_tcp
->ka_probe_cnt
= p_conn
->ka_probe_cnt
;
377 p_tcp
->rt_cnt
= p_conn
->rt_cnt
;
378 p_tcp
->flow_label
= cpu_to_le32(p_conn
->flow_label
);
379 p_tcp
->ka_timeout
= cpu_to_le32(p_conn
->ka_timeout
);
380 p_tcp
->ka_interval
= cpu_to_le32(p_conn
->ka_interval
);
381 p_tcp
->max_rt_time
= cpu_to_le32(p_conn
->max_rt_time
);
382 dval
= p_conn
->initial_rcv_wnd
;
383 p_tcp
->initial_rcv_wnd
= cpu_to_le32(dval
);
384 p_tcp
->ttl
= p_conn
->ttl
;
385 p_tcp
->tos_or_tc
= p_conn
->tos_or_tc
;
386 p_tcp
->remote_port
= cpu_to_le16(p_conn
->remote_port
);
387 p_tcp
->local_port
= cpu_to_le16(p_conn
->local_port
);
388 p_tcp
->mss
= cpu_to_le16(p_conn
->mss
);
389 p_tcp
->snd_wnd_scale
= p_conn
->snd_wnd_scale
;
390 p_tcp
->rcv_wnd_scale
= p_conn
->rcv_wnd_scale
;
391 wval
= p_conn
->da_timeout_value
;
392 p_tcp
->da_timeout_value
= cpu_to_le16(wval
);
393 p_tcp
->ack_frequency
= p_conn
->ack_frequency
;
394 p_tcp
->connect_mode
= p_conn
->connect_mode
;
397 &((struct iscsi_spe_conn_offload_option2
*)p_ramrod
)->tcp
;
399 p
= (u16
*)p_conn
->local_mac
;
400 tmp
= cpu_to_le16(get_unaligned_be16(p
));
401 p_tcp2
->local_mac_addr_hi
= tmp
;
402 tmp
= cpu_to_le16(get_unaligned_be16(p
+ 1));
403 p_tcp2
->local_mac_addr_mid
= tmp
;
404 tmp
= cpu_to_le16(get_unaligned_be16(p
+ 2));
405 p_tcp2
->local_mac_addr_lo
= tmp
;
407 p
= (u16
*)p_conn
->remote_mac
;
408 tmp
= cpu_to_le16(get_unaligned_be16(p
));
409 p_tcp2
->remote_mac_addr_hi
= tmp
;
410 tmp
= cpu_to_le16(get_unaligned_be16(p
+ 1));
411 p_tcp2
->remote_mac_addr_mid
= tmp
;
412 tmp
= cpu_to_le16(get_unaligned_be16(p
+ 2));
413 p_tcp2
->remote_mac_addr_lo
= tmp
;
415 p_tcp2
->vlan_id
= cpu_to_le16(p_conn
->vlan_id
);
416 p_tcp2
->flags
= cpu_to_le16(p_conn
->tcp_flags
);
418 p_tcp2
->ip_version
= p_conn
->ip_version
;
419 for (i
= 0; i
< 4; i
++) {
420 dval
= p_conn
->remote_ip
[i
];
421 p_tcp2
->remote_ip
[i
] = cpu_to_le32(dval
);
422 dval
= p_conn
->local_ip
[i
];
423 p_tcp2
->local_ip
[i
] = cpu_to_le32(dval
);
426 p_tcp2
->flow_label
= cpu_to_le32(p_conn
->flow_label
);
427 p_tcp2
->ttl
= p_conn
->ttl
;
428 p_tcp2
->tos_or_tc
= p_conn
->tos_or_tc
;
429 p_tcp2
->remote_port
= cpu_to_le16(p_conn
->remote_port
);
430 p_tcp2
->local_port
= cpu_to_le16(p_conn
->local_port
);
431 p_tcp2
->mss
= cpu_to_le16(p_conn
->mss
);
432 p_tcp2
->rcv_wnd_scale
= p_conn
->rcv_wnd_scale
;
433 p_tcp2
->connect_mode
= p_conn
->connect_mode
;
434 wval
= p_conn
->syn_ip_payload_length
;
435 p_tcp2
->syn_ip_payload_length
= cpu_to_le16(wval
);
436 p_tcp2
->syn_phy_addr_lo
= DMA_LO_LE(p_conn
->syn_phy_addr
);
437 p_tcp2
->syn_phy_addr_hi
= DMA_HI_LE(p_conn
->syn_phy_addr
);
438 p_tcp2
->cwnd
= cpu_to_le32(p_conn
->cwnd
);
439 p_tcp2
->ka_max_probe_cnt
= p_conn
->ka_probe_cnt
;
440 p_tcp2
->ka_timeout
= cpu_to_le32(p_conn
->ka_timeout
);
441 p_tcp2
->max_rt_time
= cpu_to_le32(p_conn
->max_rt_time
);
442 p_tcp2
->ka_interval
= cpu_to_le32(p_conn
->ka_interval
);
445 return qed_spq_post(p_hwfn
, p_ent
, NULL
);
448 static int qed_sp_iscsi_conn_update(struct qed_hwfn
*p_hwfn
,
449 struct qed_iscsi_conn
*p_conn
,
450 enum spq_mode comp_mode
,
451 struct qed_spq_comp_cb
*p_comp_addr
)
453 struct iscsi_conn_update_ramrod_params
*p_ramrod
= NULL
;
454 struct qed_spq_entry
*p_ent
= NULL
;
455 struct qed_sp_init_data init_data
;
460 memset(&init_data
, 0, sizeof(init_data
));
461 init_data
.cid
= p_conn
->icid
;
462 init_data
.opaque_fid
= p_hwfn
->hw_info
.opaque_fid
;
463 init_data
.comp_mode
= comp_mode
;
464 init_data
.p_comp_data
= p_comp_addr
;
466 rc
= qed_sp_init_request(p_hwfn
, &p_ent
,
467 ISCSI_RAMROD_CMD_ID_UPDATE_CONN
,
468 PROTOCOLID_ISCSI
, &init_data
);
472 p_ramrod
= &p_ent
->ramrod
.iscsi_conn_update
;
474 p_ramrod
->conn_id
= cpu_to_le16(p_conn
->conn_id
);
475 p_ramrod
->flags
= p_conn
->update_flag
;
476 p_ramrod
->max_seq_size
= cpu_to_le32(p_conn
->max_seq_size
);
477 dval
= p_conn
->max_recv_pdu_length
;
478 p_ramrod
->max_recv_pdu_length
= cpu_to_le32(dval
);
479 dval
= p_conn
->max_send_pdu_length
;
480 p_ramrod
->max_send_pdu_length
= cpu_to_le32(dval
);
481 dval
= p_conn
->first_seq_length
;
482 p_ramrod
->first_seq_length
= cpu_to_le32(dval
);
483 p_ramrod
->exp_stat_sn
= cpu_to_le32(p_conn
->exp_stat_sn
);
485 return qed_spq_post(p_hwfn
, p_ent
, NULL
);
489 qed_sp_iscsi_mac_update(struct qed_hwfn
*p_hwfn
,
490 struct qed_iscsi_conn
*p_conn
,
491 enum spq_mode comp_mode
,
492 struct qed_spq_comp_cb
*p_comp_addr
)
494 struct iscsi_spe_conn_mac_update
*p_ramrod
= NULL
;
495 struct qed_spq_entry
*p_ent
= NULL
;
496 struct qed_sp_init_data init_data
;
501 memset(&init_data
, 0, sizeof(init_data
));
502 init_data
.cid
= p_conn
->icid
;
503 init_data
.opaque_fid
= p_hwfn
->hw_info
.opaque_fid
;
504 init_data
.comp_mode
= comp_mode
;
505 init_data
.p_comp_data
= p_comp_addr
;
507 rc
= qed_sp_init_request(p_hwfn
, &p_ent
,
508 ISCSI_RAMROD_CMD_ID_MAC_UPDATE
,
509 PROTOCOLID_ISCSI
, &init_data
);
513 p_ramrod
= &p_ent
->ramrod
.iscsi_conn_mac_update
;
515 p_ramrod
->conn_id
= cpu_to_le16(p_conn
->conn_id
);
516 ucval
= p_conn
->remote_mac
[1];
517 ((u8
*)(&p_ramrod
->remote_mac_addr_hi
))[0] = ucval
;
518 ucval
= p_conn
->remote_mac
[0];
519 ((u8
*)(&p_ramrod
->remote_mac_addr_hi
))[1] = ucval
;
520 ucval
= p_conn
->remote_mac
[3];
521 ((u8
*)(&p_ramrod
->remote_mac_addr_mid
))[0] = ucval
;
522 ucval
= p_conn
->remote_mac
[2];
523 ((u8
*)(&p_ramrod
->remote_mac_addr_mid
))[1] = ucval
;
524 ucval
= p_conn
->remote_mac
[5];
525 ((u8
*)(&p_ramrod
->remote_mac_addr_lo
))[0] = ucval
;
526 ucval
= p_conn
->remote_mac
[4];
527 ((u8
*)(&p_ramrod
->remote_mac_addr_lo
))[1] = ucval
;
529 return qed_spq_post(p_hwfn
, p_ent
, NULL
);
532 static int qed_sp_iscsi_conn_terminate(struct qed_hwfn
*p_hwfn
,
533 struct qed_iscsi_conn
*p_conn
,
534 enum spq_mode comp_mode
,
535 struct qed_spq_comp_cb
*p_comp_addr
)
537 struct iscsi_spe_conn_termination
*p_ramrod
= NULL
;
538 struct qed_spq_entry
*p_ent
= NULL
;
539 struct qed_sp_init_data init_data
;
543 memset(&init_data
, 0, sizeof(init_data
));
544 init_data
.cid
= p_conn
->icid
;
545 init_data
.opaque_fid
= p_hwfn
->hw_info
.opaque_fid
;
546 init_data
.comp_mode
= comp_mode
;
547 init_data
.p_comp_data
= p_comp_addr
;
549 rc
= qed_sp_init_request(p_hwfn
, &p_ent
,
550 ISCSI_RAMROD_CMD_ID_TERMINATION_CONN
,
551 PROTOCOLID_ISCSI
, &init_data
);
555 p_ramrod
= &p_ent
->ramrod
.iscsi_conn_terminate
;
557 p_ramrod
->conn_id
= cpu_to_le16(p_conn
->conn_id
);
558 p_ramrod
->abortive
= p_conn
->abortive_dsconnect
;
560 DMA_REGPAIR_LE(p_ramrod
->query_params_addr
,
561 p_conn
->tcp_upload_params_phys_addr
);
562 DMA_REGPAIR_LE(p_ramrod
->queue_cnts_addr
, p_conn
->queue_cnts_phys_addr
);
564 return qed_spq_post(p_hwfn
, p_ent
, NULL
);
567 static int qed_sp_iscsi_conn_clear_sq(struct qed_hwfn
*p_hwfn
,
568 struct qed_iscsi_conn
*p_conn
,
569 enum spq_mode comp_mode
,
570 struct qed_spq_comp_cb
*p_comp_addr
)
572 struct qed_spq_entry
*p_ent
= NULL
;
573 struct qed_sp_init_data init_data
;
577 memset(&init_data
, 0, sizeof(init_data
));
578 init_data
.cid
= p_conn
->icid
;
579 init_data
.opaque_fid
= p_hwfn
->hw_info
.opaque_fid
;
580 init_data
.comp_mode
= comp_mode
;
581 init_data
.p_comp_data
= p_comp_addr
;
583 rc
= qed_sp_init_request(p_hwfn
, &p_ent
,
584 ISCSI_RAMROD_CMD_ID_CLEAR_SQ
,
585 PROTOCOLID_ISCSI
, &init_data
);
589 return qed_spq_post(p_hwfn
, p_ent
, NULL
);
592 static int qed_sp_iscsi_func_stop(struct qed_hwfn
*p_hwfn
,
593 enum spq_mode comp_mode
,
594 struct qed_spq_comp_cb
*p_comp_addr
)
596 struct qed_spq_entry
*p_ent
= NULL
;
597 struct qed_sp_init_data init_data
;
601 memset(&init_data
, 0, sizeof(init_data
));
602 init_data
.cid
= qed_spq_get_cid(p_hwfn
);
603 init_data
.opaque_fid
= p_hwfn
->hw_info
.opaque_fid
;
604 init_data
.comp_mode
= comp_mode
;
605 init_data
.p_comp_data
= p_comp_addr
;
607 rc
= qed_sp_init_request(p_hwfn
, &p_ent
,
608 ISCSI_RAMROD_CMD_ID_DESTROY_FUNC
,
609 PROTOCOLID_ISCSI
, &init_data
);
613 rc
= qed_spq_post(p_hwfn
, p_ent
, NULL
);
615 qed_spq_unregister_async_cb(p_hwfn
, PROTOCOLID_ISCSI
);
619 static void __iomem
*qed_iscsi_get_db_addr(struct qed_hwfn
*p_hwfn
, u32 cid
)
621 return (u8 __iomem
*)p_hwfn
->doorbells
+
622 qed_db_addr(cid
, DQ_DEMS_LEGACY
);
625 static void __iomem
*qed_iscsi_get_primary_bdq_prod(struct qed_hwfn
*p_hwfn
,
628 if (RESC_NUM(p_hwfn
, QED_BDQ
)) {
629 return (u8 __iomem
*)p_hwfn
->regview
+
630 GTT_BAR0_MAP_REG_MSDM_RAM
+
631 MSTORM_SCSI_BDQ_EXT_PROD_OFFSET(RESC_START(p_hwfn
,
635 DP_NOTICE(p_hwfn
, "BDQ is not allocated!\n");
640 static void __iomem
*qed_iscsi_get_secondary_bdq_prod(struct qed_hwfn
*p_hwfn
,
643 if (RESC_NUM(p_hwfn
, QED_BDQ
)) {
644 return (u8 __iomem
*)p_hwfn
->regview
+
645 GTT_BAR0_MAP_REG_TSDM_RAM
+
646 TSTORM_SCSI_BDQ_EXT_PROD_OFFSET(RESC_START(p_hwfn
,
650 DP_NOTICE(p_hwfn
, "BDQ is not allocated!\n");
655 static int qed_iscsi_setup_connection(struct qed_iscsi_conn
*p_conn
)
657 if (!p_conn
->queue_cnts_virt_addr
)
659 memset(p_conn
->queue_cnts_virt_addr
, 0,
660 sizeof(*p_conn
->queue_cnts_virt_addr
));
662 if (!p_conn
->tcp_upload_params_virt_addr
)
664 memset(p_conn
->tcp_upload_params_virt_addr
, 0,
665 sizeof(*p_conn
->tcp_upload_params_virt_addr
));
667 if (!p_conn
->r2tq
.p_virt_addr
)
669 qed_chain_pbl_zero_mem(&p_conn
->r2tq
);
671 if (!p_conn
->uhq
.p_virt_addr
)
673 qed_chain_pbl_zero_mem(&p_conn
->uhq
);
675 if (!p_conn
->xhq
.p_virt_addr
)
677 qed_chain_pbl_zero_mem(&p_conn
->xhq
);
684 static int qed_iscsi_allocate_connection(struct qed_hwfn
*p_hwfn
,
685 struct qed_iscsi_conn
**p_out_conn
)
687 struct scsi_terminate_extra_params
*p_q_cnts
= NULL
;
688 struct qed_iscsi_pf_params
*p_params
= NULL
;
689 struct qed_chain_init_params params
= {
690 .mode
= QED_CHAIN_MODE_PBL
,
691 .intended_use
= QED_CHAIN_USE_TO_CONSUME_PRODUCE
,
692 .cnt_type
= QED_CHAIN_CNT_TYPE_U16
,
694 struct tcp_upload_params
*p_tcp
= NULL
;
695 struct qed_iscsi_conn
*p_conn
= NULL
;
698 /* Try finding a free connection that can be used */
699 spin_lock_bh(&p_hwfn
->p_iscsi_info
->lock
);
700 if (!list_empty(&p_hwfn
->p_iscsi_info
->free_list
))
701 p_conn
= list_first_entry(&p_hwfn
->p_iscsi_info
->free_list
,
702 struct qed_iscsi_conn
, list_entry
);
704 list_del(&p_conn
->list_entry
);
705 spin_unlock_bh(&p_hwfn
->p_iscsi_info
->lock
);
706 *p_out_conn
= p_conn
;
709 spin_unlock_bh(&p_hwfn
->p_iscsi_info
->lock
);
711 /* Need to allocate a new connection */
712 p_params
= &p_hwfn
->pf_params
.iscsi_pf_params
;
714 p_conn
= kzalloc(sizeof(*p_conn
), GFP_KERNEL
);
718 p_q_cnts
= dma_alloc_coherent(&p_hwfn
->cdev
->pdev
->dev
,
720 &p_conn
->queue_cnts_phys_addr
,
723 goto nomem_queue_cnts_param
;
724 p_conn
->queue_cnts_virt_addr
= p_q_cnts
;
726 p_tcp
= dma_alloc_coherent(&p_hwfn
->cdev
->pdev
->dev
,
728 &p_conn
->tcp_upload_params_phys_addr
,
731 goto nomem_upload_param
;
732 p_conn
->tcp_upload_params_virt_addr
= p_tcp
;
734 params
.num_elems
= p_params
->num_r2tq_pages_in_ring
*
735 QED_CHAIN_PAGE_SIZE
/ sizeof(struct iscsi_wqe
);
736 params
.elem_size
= sizeof(struct iscsi_wqe
);
738 rc
= qed_chain_alloc(p_hwfn
->cdev
, &p_conn
->r2tq
, ¶ms
);
742 params
.num_elems
= p_params
->num_uhq_pages_in_ring
*
743 QED_CHAIN_PAGE_SIZE
/ sizeof(struct iscsi_uhqe
);
744 params
.elem_size
= sizeof(struct iscsi_uhqe
);
746 rc
= qed_chain_alloc(p_hwfn
->cdev
, &p_conn
->uhq
, ¶ms
);
750 params
.elem_size
= sizeof(struct iscsi_xhqe
);
752 rc
= qed_chain_alloc(p_hwfn
->cdev
, &p_conn
->xhq
, ¶ms
);
756 p_conn
->free_on_delete
= true;
757 *p_out_conn
= p_conn
;
761 qed_chain_free(p_hwfn
->cdev
, &p_conn
->uhq
);
763 qed_chain_free(p_hwfn
->cdev
, &p_conn
->r2tq
);
765 dma_free_coherent(&p_hwfn
->cdev
->pdev
->dev
,
766 sizeof(struct tcp_upload_params
),
767 p_conn
->tcp_upload_params_virt_addr
,
768 p_conn
->tcp_upload_params_phys_addr
);
770 dma_free_coherent(&p_hwfn
->cdev
->pdev
->dev
,
771 sizeof(struct scsi_terminate_extra_params
),
772 p_conn
->queue_cnts_virt_addr
,
773 p_conn
->queue_cnts_phys_addr
);
774 nomem_queue_cnts_param
:
780 static int qed_iscsi_acquire_connection(struct qed_hwfn
*p_hwfn
,
781 struct qed_iscsi_conn
*p_in_conn
,
782 struct qed_iscsi_conn
**p_out_conn
)
784 struct qed_iscsi_conn
*p_conn
= NULL
;
788 spin_lock_bh(&p_hwfn
->p_iscsi_info
->lock
);
789 rc
= qed_cxt_acquire_cid(p_hwfn
, PROTOCOLID_ISCSI
, &icid
);
790 spin_unlock_bh(&p_hwfn
->p_iscsi_info
->lock
);
794 /* Use input connection or allocate a new one */
798 rc
= qed_iscsi_allocate_connection(p_hwfn
, &p_conn
);
801 rc
= qed_iscsi_setup_connection(p_conn
);
804 spin_lock_bh(&p_hwfn
->p_iscsi_info
->lock
);
805 qed_cxt_release_cid(p_hwfn
, icid
);
806 spin_unlock_bh(&p_hwfn
->p_iscsi_info
->lock
);
811 p_conn
->conn_id
= (u16
)icid
;
812 p_conn
->fw_cid
= (p_hwfn
->hw_info
.opaque_fid
<< 16) | icid
;
814 *p_out_conn
= p_conn
;
819 static void qed_iscsi_release_connection(struct qed_hwfn
*p_hwfn
,
820 struct qed_iscsi_conn
*p_conn
)
822 spin_lock_bh(&p_hwfn
->p_iscsi_info
->lock
);
823 list_add_tail(&p_conn
->list_entry
, &p_hwfn
->p_iscsi_info
->free_list
);
824 qed_cxt_release_cid(p_hwfn
, p_conn
->icid
);
825 spin_unlock_bh(&p_hwfn
->p_iscsi_info
->lock
);
828 static void qed_iscsi_free_connection(struct qed_hwfn
*p_hwfn
,
829 struct qed_iscsi_conn
*p_conn
)
831 qed_chain_free(p_hwfn
->cdev
, &p_conn
->xhq
);
832 qed_chain_free(p_hwfn
->cdev
, &p_conn
->uhq
);
833 qed_chain_free(p_hwfn
->cdev
, &p_conn
->r2tq
);
834 dma_free_coherent(&p_hwfn
->cdev
->pdev
->dev
,
835 sizeof(struct tcp_upload_params
),
836 p_conn
->tcp_upload_params_virt_addr
,
837 p_conn
->tcp_upload_params_phys_addr
);
838 dma_free_coherent(&p_hwfn
->cdev
->pdev
->dev
,
839 sizeof(struct scsi_terminate_extra_params
),
840 p_conn
->queue_cnts_virt_addr
,
841 p_conn
->queue_cnts_phys_addr
);
845 int qed_iscsi_alloc(struct qed_hwfn
*p_hwfn
)
847 struct qed_iscsi_info
*p_iscsi_info
;
849 p_iscsi_info
= kzalloc(sizeof(*p_iscsi_info
), GFP_KERNEL
);
853 INIT_LIST_HEAD(&p_iscsi_info
->free_list
);
855 p_hwfn
->p_iscsi_info
= p_iscsi_info
;
859 void qed_iscsi_setup(struct qed_hwfn
*p_hwfn
)
861 spin_lock_init(&p_hwfn
->p_iscsi_info
->lock
);
864 void qed_iscsi_free(struct qed_hwfn
*p_hwfn
)
866 struct qed_iscsi_conn
*p_conn
= NULL
;
868 if (!p_hwfn
->p_iscsi_info
)
871 while (!list_empty(&p_hwfn
->p_iscsi_info
->free_list
)) {
872 p_conn
= list_first_entry(&p_hwfn
->p_iscsi_info
->free_list
,
873 struct qed_iscsi_conn
, list_entry
);
875 list_del(&p_conn
->list_entry
);
876 qed_iscsi_free_connection(p_hwfn
, p_conn
);
880 kfree(p_hwfn
->p_iscsi_info
);
881 p_hwfn
->p_iscsi_info
= NULL
;
884 static void _qed_iscsi_get_tstats(struct qed_hwfn
*p_hwfn
,
885 struct qed_ptt
*p_ptt
,
886 struct qed_iscsi_stats
*p_stats
)
888 struct tstorm_iscsi_stats_drv tstats
;
891 memset(&tstats
, 0, sizeof(tstats
));
892 tstats_addr
= BAR0_MAP_REG_TSDM_RAM
+
893 TSTORM_ISCSI_RX_STATS_OFFSET(p_hwfn
->rel_pf_id
);
894 qed_memcpy_from(p_hwfn
, p_ptt
, &tstats
, tstats_addr
, sizeof(tstats
));
896 p_stats
->iscsi_rx_bytes_cnt
=
897 HILO_64_REGPAIR(tstats
.iscsi_rx_bytes_cnt
);
898 p_stats
->iscsi_rx_packet_cnt
=
899 HILO_64_REGPAIR(tstats
.iscsi_rx_packet_cnt
);
900 p_stats
->iscsi_rx_new_ooo_isle_events_cnt
=
901 HILO_64_REGPAIR(tstats
.iscsi_rx_new_ooo_isle_events_cnt
);
902 p_stats
->iscsi_cmdq_threshold_cnt
=
903 le32_to_cpu(tstats
.iscsi_cmdq_threshold_cnt
);
904 p_stats
->iscsi_rq_threshold_cnt
=
905 le32_to_cpu(tstats
.iscsi_rq_threshold_cnt
);
906 p_stats
->iscsi_immq_threshold_cnt
=
907 le32_to_cpu(tstats
.iscsi_immq_threshold_cnt
);
910 static void _qed_iscsi_get_mstats(struct qed_hwfn
*p_hwfn
,
911 struct qed_ptt
*p_ptt
,
912 struct qed_iscsi_stats
*p_stats
)
914 struct mstorm_iscsi_stats_drv mstats
;
917 memset(&mstats
, 0, sizeof(mstats
));
918 mstats_addr
= BAR0_MAP_REG_MSDM_RAM
+
919 MSTORM_ISCSI_RX_STATS_OFFSET(p_hwfn
->rel_pf_id
);
920 qed_memcpy_from(p_hwfn
, p_ptt
, &mstats
, mstats_addr
, sizeof(mstats
));
922 p_stats
->iscsi_rx_dropped_pdus_task_not_valid
=
923 HILO_64_REGPAIR(mstats
.iscsi_rx_dropped_pdus_task_not_valid
);
926 static void _qed_iscsi_get_ustats(struct qed_hwfn
*p_hwfn
,
927 struct qed_ptt
*p_ptt
,
928 struct qed_iscsi_stats
*p_stats
)
930 struct ustorm_iscsi_stats_drv ustats
;
933 memset(&ustats
, 0, sizeof(ustats
));
934 ustats_addr
= BAR0_MAP_REG_USDM_RAM
+
935 USTORM_ISCSI_RX_STATS_OFFSET(p_hwfn
->rel_pf_id
);
936 qed_memcpy_from(p_hwfn
, p_ptt
, &ustats
, ustats_addr
, sizeof(ustats
));
938 p_stats
->iscsi_rx_data_pdu_cnt
=
939 HILO_64_REGPAIR(ustats
.iscsi_rx_data_pdu_cnt
);
940 p_stats
->iscsi_rx_r2t_pdu_cnt
=
941 HILO_64_REGPAIR(ustats
.iscsi_rx_r2t_pdu_cnt
);
942 p_stats
->iscsi_rx_total_pdu_cnt
=
943 HILO_64_REGPAIR(ustats
.iscsi_rx_total_pdu_cnt
);
946 static void _qed_iscsi_get_xstats(struct qed_hwfn
*p_hwfn
,
947 struct qed_ptt
*p_ptt
,
948 struct qed_iscsi_stats
*p_stats
)
950 struct xstorm_iscsi_stats_drv xstats
;
953 memset(&xstats
, 0, sizeof(xstats
));
954 xstats_addr
= BAR0_MAP_REG_XSDM_RAM
+
955 XSTORM_ISCSI_TX_STATS_OFFSET(p_hwfn
->rel_pf_id
);
956 qed_memcpy_from(p_hwfn
, p_ptt
, &xstats
, xstats_addr
, sizeof(xstats
));
958 p_stats
->iscsi_tx_go_to_slow_start_event_cnt
=
959 HILO_64_REGPAIR(xstats
.iscsi_tx_go_to_slow_start_event_cnt
);
960 p_stats
->iscsi_tx_fast_retransmit_event_cnt
=
961 HILO_64_REGPAIR(xstats
.iscsi_tx_fast_retransmit_event_cnt
);
964 static void _qed_iscsi_get_ystats(struct qed_hwfn
*p_hwfn
,
965 struct qed_ptt
*p_ptt
,
966 struct qed_iscsi_stats
*p_stats
)
968 struct ystorm_iscsi_stats_drv ystats
;
971 memset(&ystats
, 0, sizeof(ystats
));
972 ystats_addr
= BAR0_MAP_REG_YSDM_RAM
+
973 YSTORM_ISCSI_TX_STATS_OFFSET(p_hwfn
->rel_pf_id
);
974 qed_memcpy_from(p_hwfn
, p_ptt
, &ystats
, ystats_addr
, sizeof(ystats
));
976 p_stats
->iscsi_tx_data_pdu_cnt
=
977 HILO_64_REGPAIR(ystats
.iscsi_tx_data_pdu_cnt
);
978 p_stats
->iscsi_tx_r2t_pdu_cnt
=
979 HILO_64_REGPAIR(ystats
.iscsi_tx_r2t_pdu_cnt
);
980 p_stats
->iscsi_tx_total_pdu_cnt
=
981 HILO_64_REGPAIR(ystats
.iscsi_tx_total_pdu_cnt
);
984 static void _qed_iscsi_get_pstats(struct qed_hwfn
*p_hwfn
,
985 struct qed_ptt
*p_ptt
,
986 struct qed_iscsi_stats
*p_stats
)
988 struct pstorm_iscsi_stats_drv pstats
;
991 memset(&pstats
, 0, sizeof(pstats
));
992 pstats_addr
= BAR0_MAP_REG_PSDM_RAM
+
993 PSTORM_ISCSI_TX_STATS_OFFSET(p_hwfn
->rel_pf_id
);
994 qed_memcpy_from(p_hwfn
, p_ptt
, &pstats
, pstats_addr
, sizeof(pstats
));
996 p_stats
->iscsi_tx_bytes_cnt
=
997 HILO_64_REGPAIR(pstats
.iscsi_tx_bytes_cnt
);
998 p_stats
->iscsi_tx_packet_cnt
=
999 HILO_64_REGPAIR(pstats
.iscsi_tx_packet_cnt
);
1002 static int qed_iscsi_get_stats(struct qed_hwfn
*p_hwfn
,
1003 struct qed_iscsi_stats
*stats
)
1005 struct qed_ptt
*p_ptt
;
1007 memset(stats
, 0, sizeof(*stats
));
1009 p_ptt
= qed_ptt_acquire(p_hwfn
);
1011 DP_ERR(p_hwfn
, "Failed to acquire ptt\n");
1015 _qed_iscsi_get_tstats(p_hwfn
, p_ptt
, stats
);
1016 _qed_iscsi_get_mstats(p_hwfn
, p_ptt
, stats
);
1017 _qed_iscsi_get_ustats(p_hwfn
, p_ptt
, stats
);
1019 _qed_iscsi_get_xstats(p_hwfn
, p_ptt
, stats
);
1020 _qed_iscsi_get_ystats(p_hwfn
, p_ptt
, stats
);
1021 _qed_iscsi_get_pstats(p_hwfn
, p_ptt
, stats
);
1023 qed_ptt_release(p_hwfn
, p_ptt
);
1028 struct qed_hash_iscsi_con
{
1029 struct hlist_node node
;
1030 struct qed_iscsi_conn
*con
;
1033 static int qed_fill_iscsi_dev_info(struct qed_dev
*cdev
,
1034 struct qed_dev_iscsi_info
*info
)
1036 struct qed_hwfn
*hwfn
= QED_AFFIN_HWFN(cdev
);
1040 memset(info
, 0, sizeof(*info
));
1041 rc
= qed_fill_dev_info(cdev
, &info
->common
);
1043 info
->primary_dbq_rq_addr
=
1044 qed_iscsi_get_primary_bdq_prod(hwfn
, BDQ_ID_RQ
);
1045 info
->secondary_bdq_rq_addr
=
1046 qed_iscsi_get_secondary_bdq_prod(hwfn
, BDQ_ID_RQ
);
1048 info
->num_cqs
= FEAT_NUM(hwfn
, QED_ISCSI_CQ
);
1053 static void qed_register_iscsi_ops(struct qed_dev
*cdev
,
1054 struct qed_iscsi_cb_ops
*ops
, void *cookie
)
1056 cdev
->protocol_ops
.iscsi
= ops
;
1057 cdev
->ops_cookie
= cookie
;
1060 static struct qed_hash_iscsi_con
*qed_iscsi_get_hash(struct qed_dev
*cdev
,
1063 struct qed_hash_iscsi_con
*hash_con
= NULL
;
1065 if (!(cdev
->flags
& QED_FLAG_STORAGE_STARTED
))
1068 hash_for_each_possible(cdev
->connections
, hash_con
, node
, handle
) {
1069 if (hash_con
->con
->icid
== handle
)
1073 if (!hash_con
|| (hash_con
->con
->icid
!= handle
))
1079 static int qed_iscsi_stop(struct qed_dev
*cdev
)
1083 if (!(cdev
->flags
& QED_FLAG_STORAGE_STARTED
)) {
1084 DP_NOTICE(cdev
, "iscsi already stopped\n");
1088 if (!hash_empty(cdev
->connections
)) {
1090 "Can't stop iscsi - not all connections were returned\n");
1094 /* Stop the iscsi */
1095 rc
= qed_sp_iscsi_func_stop(QED_AFFIN_HWFN(cdev
), QED_SPQ_MODE_EBLOCK
,
1097 cdev
->flags
&= ~QED_FLAG_STORAGE_STARTED
;
1102 static int qed_iscsi_start(struct qed_dev
*cdev
,
1103 struct qed_iscsi_tid
*tasks
,
1104 void *event_context
,
1105 iscsi_event_cb_t async_event_cb
)
1108 struct qed_tid_mem
*tid_info
;
1110 if (cdev
->flags
& QED_FLAG_STORAGE_STARTED
) {
1111 DP_NOTICE(cdev
, "iscsi already started;\n");
1115 rc
= qed_sp_iscsi_func_start(QED_AFFIN_HWFN(cdev
), QED_SPQ_MODE_EBLOCK
,
1116 NULL
, event_context
, async_event_cb
);
1118 DP_NOTICE(cdev
, "Failed to start iscsi\n");
1122 cdev
->flags
|= QED_FLAG_STORAGE_STARTED
;
1123 hash_init(cdev
->connections
);
1128 tid_info
= kzalloc(sizeof(*tid_info
), GFP_KERNEL
);
1131 qed_iscsi_stop(cdev
);
1135 rc
= qed_cxt_get_tid_mem_info(QED_AFFIN_HWFN(cdev
), tid_info
);
1137 DP_NOTICE(cdev
, "Failed to gather task information\n");
1138 qed_iscsi_stop(cdev
);
1143 /* Fill task information */
1144 tasks
->size
= tid_info
->tid_size
;
1145 tasks
->num_tids_per_block
= tid_info
->num_tids_per_block
;
1146 memcpy(tasks
->blocks
, tid_info
->blocks
,
1147 MAX_TID_BLOCKS_ISCSI
* sizeof(u8
*));
1154 static int qed_iscsi_acquire_conn(struct qed_dev
*cdev
,
1156 u32
*fw_cid
, void __iomem
**p_doorbell
)
1158 struct qed_hash_iscsi_con
*hash_con
;
1161 /* Allocate a hashed connection */
1162 hash_con
= kzalloc(sizeof(*hash_con
), GFP_ATOMIC
);
1166 /* Acquire the connection */
1167 rc
= qed_iscsi_acquire_connection(QED_AFFIN_HWFN(cdev
), NULL
,
1170 DP_NOTICE(cdev
, "Failed to acquire Connection\n");
1175 /* Added the connection to hash table */
1176 *handle
= hash_con
->con
->icid
;
1177 *fw_cid
= hash_con
->con
->fw_cid
;
1178 hash_add(cdev
->connections
, &hash_con
->node
, *handle
);
1181 *p_doorbell
= qed_iscsi_get_db_addr(QED_AFFIN_HWFN(cdev
),
1187 static int qed_iscsi_release_conn(struct qed_dev
*cdev
, u32 handle
)
1189 struct qed_hash_iscsi_con
*hash_con
;
1191 hash_con
= qed_iscsi_get_hash(cdev
, handle
);
1193 DP_NOTICE(cdev
, "Failed to find connection for handle %d\n",
1198 hlist_del(&hash_con
->node
);
1199 qed_iscsi_release_connection(QED_AFFIN_HWFN(cdev
), hash_con
->con
);
1205 static int qed_iscsi_offload_conn(struct qed_dev
*cdev
,
1207 struct qed_iscsi_params_offload
*conn_info
)
1209 struct qed_hash_iscsi_con
*hash_con
;
1210 struct qed_iscsi_conn
*con
;
1212 hash_con
= qed_iscsi_get_hash(cdev
, handle
);
1214 DP_NOTICE(cdev
, "Failed to find connection for handle %d\n",
1219 /* Update the connection with information from the params */
1220 con
= hash_con
->con
;
1222 ether_addr_copy(con
->local_mac
, conn_info
->src
.mac
);
1223 ether_addr_copy(con
->remote_mac
, conn_info
->dst
.mac
);
1224 memcpy(con
->local_ip
, conn_info
->src
.ip
, sizeof(con
->local_ip
));
1225 memcpy(con
->remote_ip
, conn_info
->dst
.ip
, sizeof(con
->remote_ip
));
1226 con
->local_port
= conn_info
->src
.port
;
1227 con
->remote_port
= conn_info
->dst
.port
;
1229 con
->layer_code
= conn_info
->layer_code
;
1230 con
->sq_pbl_addr
= conn_info
->sq_pbl_addr
;
1231 con
->initial_ack
= conn_info
->initial_ack
;
1232 con
->vlan_id
= conn_info
->vlan_id
;
1233 con
->tcp_flags
= conn_info
->tcp_flags
;
1234 con
->ip_version
= conn_info
->ip_version
;
1235 con
->default_cq
= conn_info
->default_cq
;
1236 con
->ka_max_probe_cnt
= conn_info
->ka_max_probe_cnt
;
1237 con
->dup_ack_theshold
= conn_info
->dup_ack_theshold
;
1238 con
->rcv_next
= conn_info
->rcv_next
;
1239 con
->snd_una
= conn_info
->snd_una
;
1240 con
->snd_next
= conn_info
->snd_next
;
1241 con
->snd_max
= conn_info
->snd_max
;
1242 con
->snd_wnd
= conn_info
->snd_wnd
;
1243 con
->rcv_wnd
= conn_info
->rcv_wnd
;
1244 con
->snd_wl1
= conn_info
->snd_wl1
;
1245 con
->cwnd
= conn_info
->cwnd
;
1246 con
->ss_thresh
= conn_info
->ss_thresh
;
1247 con
->srtt
= conn_info
->srtt
;
1248 con
->rtt_var
= conn_info
->rtt_var
;
1249 con
->ts_recent
= conn_info
->ts_recent
;
1250 con
->ts_recent_age
= conn_info
->ts_recent_age
;
1251 con
->total_rt
= conn_info
->total_rt
;
1252 con
->ka_timeout_delta
= conn_info
->ka_timeout_delta
;
1253 con
->rt_timeout_delta
= conn_info
->rt_timeout_delta
;
1254 con
->dup_ack_cnt
= conn_info
->dup_ack_cnt
;
1255 con
->snd_wnd_probe_cnt
= conn_info
->snd_wnd_probe_cnt
;
1256 con
->ka_probe_cnt
= conn_info
->ka_probe_cnt
;
1257 con
->rt_cnt
= conn_info
->rt_cnt
;
1258 con
->flow_label
= conn_info
->flow_label
;
1259 con
->ka_timeout
= conn_info
->ka_timeout
;
1260 con
->ka_interval
= conn_info
->ka_interval
;
1261 con
->max_rt_time
= conn_info
->max_rt_time
;
1262 con
->initial_rcv_wnd
= conn_info
->initial_rcv_wnd
;
1263 con
->ttl
= conn_info
->ttl
;
1264 con
->tos_or_tc
= conn_info
->tos_or_tc
;
1265 con
->remote_port
= conn_info
->remote_port
;
1266 con
->local_port
= conn_info
->local_port
;
1267 con
->mss
= conn_info
->mss
;
1268 con
->snd_wnd_scale
= conn_info
->snd_wnd_scale
;
1269 con
->rcv_wnd_scale
= conn_info
->rcv_wnd_scale
;
1270 con
->da_timeout_value
= conn_info
->da_timeout_value
;
1271 con
->ack_frequency
= conn_info
->ack_frequency
;
1273 /* Set default values on other connection fields */
1274 con
->offl_flags
= 0x1;
1276 return qed_sp_iscsi_conn_offload(QED_AFFIN_HWFN(cdev
), con
,
1277 QED_SPQ_MODE_EBLOCK
, NULL
);
1280 static int qed_iscsi_update_conn(struct qed_dev
*cdev
,
1282 struct qed_iscsi_params_update
*conn_info
)
1284 struct qed_hash_iscsi_con
*hash_con
;
1285 struct qed_iscsi_conn
*con
;
1287 hash_con
= qed_iscsi_get_hash(cdev
, handle
);
1289 DP_NOTICE(cdev
, "Failed to find connection for handle %d\n",
1294 /* Update the connection with information from the params */
1295 con
= hash_con
->con
;
1296 con
->update_flag
= conn_info
->update_flag
;
1297 con
->max_seq_size
= conn_info
->max_seq_size
;
1298 con
->max_recv_pdu_length
= conn_info
->max_recv_pdu_length
;
1299 con
->max_send_pdu_length
= conn_info
->max_send_pdu_length
;
1300 con
->first_seq_length
= conn_info
->first_seq_length
;
1301 con
->exp_stat_sn
= conn_info
->exp_stat_sn
;
1303 return qed_sp_iscsi_conn_update(QED_AFFIN_HWFN(cdev
), con
,
1304 QED_SPQ_MODE_EBLOCK
, NULL
);
1307 static int qed_iscsi_clear_conn_sq(struct qed_dev
*cdev
, u32 handle
)
1309 struct qed_hash_iscsi_con
*hash_con
;
1311 hash_con
= qed_iscsi_get_hash(cdev
, handle
);
1313 DP_NOTICE(cdev
, "Failed to find connection for handle %d\n",
1318 return qed_sp_iscsi_conn_clear_sq(QED_AFFIN_HWFN(cdev
), hash_con
->con
,
1319 QED_SPQ_MODE_EBLOCK
, NULL
);
1322 static int qed_iscsi_destroy_conn(struct qed_dev
*cdev
,
1323 u32 handle
, u8 abrt_conn
)
1325 struct qed_hash_iscsi_con
*hash_con
;
1327 hash_con
= qed_iscsi_get_hash(cdev
, handle
);
1329 DP_NOTICE(cdev
, "Failed to find connection for handle %d\n",
1334 hash_con
->con
->abortive_dsconnect
= abrt_conn
;
1336 return qed_sp_iscsi_conn_terminate(QED_AFFIN_HWFN(cdev
), hash_con
->con
,
1337 QED_SPQ_MODE_EBLOCK
, NULL
);
1340 static int qed_iscsi_stats(struct qed_dev
*cdev
, struct qed_iscsi_stats
*stats
)
1342 return qed_iscsi_get_stats(QED_AFFIN_HWFN(cdev
), stats
);
1345 static int qed_iscsi_change_mac(struct qed_dev
*cdev
,
1346 u32 handle
, const u8
*mac
)
1348 struct qed_hash_iscsi_con
*hash_con
;
1350 hash_con
= qed_iscsi_get_hash(cdev
, handle
);
1352 DP_NOTICE(cdev
, "Failed to find connection for handle %d\n",
1357 return qed_sp_iscsi_mac_update(QED_AFFIN_HWFN(cdev
), hash_con
->con
,
1358 QED_SPQ_MODE_EBLOCK
, NULL
);
1361 void qed_get_protocol_stats_iscsi(struct qed_dev
*cdev
,
1362 struct qed_mcp_iscsi_stats
*stats
)
1364 struct qed_iscsi_stats proto_stats
;
1366 /* Retrieve FW statistics */
1367 memset(&proto_stats
, 0, sizeof(proto_stats
));
1368 if (qed_iscsi_stats(cdev
, &proto_stats
)) {
1369 DP_VERBOSE(cdev
, QED_MSG_STORAGE
,
1370 "Failed to collect ISCSI statistics\n");
1374 /* Translate FW statistics into struct */
1375 stats
->rx_pdus
= proto_stats
.iscsi_rx_total_pdu_cnt
;
1376 stats
->tx_pdus
= proto_stats
.iscsi_tx_total_pdu_cnt
;
1377 stats
->rx_bytes
= proto_stats
.iscsi_rx_bytes_cnt
;
1378 stats
->tx_bytes
= proto_stats
.iscsi_tx_bytes_cnt
;
1381 static const struct qed_iscsi_ops qed_iscsi_ops_pass
= {
1382 .common
= &qed_common_ops_pass
,
1383 .ll2
= &qed_ll2_ops_pass
,
1384 .fill_dev_info
= &qed_fill_iscsi_dev_info
,
1385 .register_ops
= &qed_register_iscsi_ops
,
1386 .start
= &qed_iscsi_start
,
1387 .stop
= &qed_iscsi_stop
,
1388 .acquire_conn
= &qed_iscsi_acquire_conn
,
1389 .release_conn
= &qed_iscsi_release_conn
,
1390 .offload_conn
= &qed_iscsi_offload_conn
,
1391 .update_conn
= &qed_iscsi_update_conn
,
1392 .destroy_conn
= &qed_iscsi_destroy_conn
,
1393 .clear_sq
= &qed_iscsi_clear_conn_sq
,
1394 .get_stats
= &qed_iscsi_stats
,
1395 .change_mac
= &qed_iscsi_change_mac
,
1398 const struct qed_iscsi_ops
*qed_get_iscsi_ops(void)
1400 return &qed_iscsi_ops_pass
;
1402 EXPORT_SYMBOL(qed_get_iscsi_ops
);
1404 void qed_put_iscsi_ops(void)
1407 EXPORT_SYMBOL(qed_put_iscsi_ops
);