blob: 6ab563e1999e404fd3a6ffbb5d1c40f48576e987 [file] [log] [blame]
Yuval Mintzfc831822016-12-01 00:21:06 -08001/* QLogic qed NIC Driver
Mintz, Yuvale8f1cb52017-01-01 13:57:00 +02002 * Copyright (c) 2015-2017 QLogic Corporation
Yuval Mintzfc831822016-12-01 00:21:06 -08003 *
Mintz, Yuvale8f1cb52017-01-01 13:57:00 +02004 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU
6 * General Public License (GPL) Version 2, available from the file
7 * COPYING in the main directory of this source tree, or the
8 * OpenIB.org BSD license below:
9 *
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
12 * conditions are met:
13 *
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
16 * disclaimer.
17 *
18 * - Redistributions in binary form must reproduce the above
19 * copyright notice, this list of conditions and the following
20 * disclaimer in the documentation and /or other materials
21 * provided with the distribution.
22 *
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30 * SOFTWARE.
Yuval Mintzfc831822016-12-01 00:21:06 -080031 */
32
33#include <linux/types.h>
34#include <asm/byteorder.h>
35#include <asm/param.h>
36#include <linux/delay.h>
37#include <linux/dma-mapping.h>
38#include <linux/etherdevice.h>
39#include <linux/interrupt.h>
40#include <linux/kernel.h>
41#include <linux/log2.h>
42#include <linux/module.h>
43#include <linux/pci.h>
44#include <linux/slab.h>
45#include <linux/stddef.h>
46#include <linux/string.h>
Yuval Mintzfc831822016-12-01 00:21:06 -080047#include <linux/workqueue.h>
48#include <linux/errno.h>
49#include <linux/list.h>
50#include <linux/spinlock.h>
51#include <linux/qed/qed_iscsi_if.h>
52#include "qed.h"
53#include "qed_cxt.h"
54#include "qed_dev_api.h"
55#include "qed_hsi.h"
56#include "qed_hw.h"
57#include "qed_int.h"
58#include "qed_iscsi.h"
59#include "qed_ll2.h"
60#include "qed_mcp.h"
61#include "qed_sp.h"
62#include "qed_sriov.h"
63#include "qed_reg_addr.h"
64
65struct qed_iscsi_conn {
66 struct list_head list_entry;
67 bool free_on_delete;
68
69 u16 conn_id;
70 u32 icid;
71 u32 fw_cid;
72
73 u8 layer_code;
74 u8 offl_flags;
75 u8 connect_mode;
76 u32 initial_ack;
77 dma_addr_t sq_pbl_addr;
78 struct qed_chain r2tq;
79 struct qed_chain xhq;
80 struct qed_chain uhq;
81
82 struct tcp_upload_params *tcp_upload_params_virt_addr;
83 dma_addr_t tcp_upload_params_phys_addr;
84 struct scsi_terminate_extra_params *queue_cnts_virt_addr;
85 dma_addr_t queue_cnts_phys_addr;
86 dma_addr_t syn_phy_addr;
87
88 u16 syn_ip_payload_length;
89 u8 local_mac[6];
90 u8 remote_mac[6];
91 u16 vlan_id;
92 u8 tcp_flags;
93 u8 ip_version;
94 u32 remote_ip[4];
95 u32 local_ip[4];
96 u8 ka_max_probe_cnt;
97 u8 dup_ack_theshold;
98 u32 rcv_next;
99 u32 snd_una;
100 u32 snd_next;
101 u32 snd_max;
102 u32 snd_wnd;
103 u32 rcv_wnd;
104 u32 snd_wl1;
105 u32 cwnd;
106 u32 ss_thresh;
107 u16 srtt;
108 u16 rtt_var;
109 u32 ts_time;
110 u32 ts_recent;
111 u32 ts_recent_age;
112 u32 total_rt;
113 u32 ka_timeout_delta;
114 u32 rt_timeout_delta;
115 u8 dup_ack_cnt;
116 u8 snd_wnd_probe_cnt;
117 u8 ka_probe_cnt;
118 u8 rt_cnt;
119 u32 flow_label;
120 u32 ka_timeout;
121 u32 ka_interval;
122 u32 max_rt_time;
123 u32 initial_rcv_wnd;
124 u8 ttl;
125 u8 tos_or_tc;
126 u16 remote_port;
127 u16 local_port;
128 u16 mss;
129 u8 snd_wnd_scale;
130 u8 rcv_wnd_scale;
131 u32 ts_ticks_per_second;
132 u16 da_timeout_value;
133 u8 ack_frequency;
134
135 u8 update_flag;
136 u8 default_cq;
137 u32 max_seq_size;
138 u32 max_recv_pdu_length;
139 u32 max_send_pdu_length;
140 u32 first_seq_length;
141 u32 exp_stat_sn;
142 u32 stat_sn;
143 u16 physical_q0;
144 u16 physical_q1;
145 u8 abortive_dsconnect;
146};
147
148static int
149qed_sp_iscsi_func_start(struct qed_hwfn *p_hwfn,
150 enum spq_mode comp_mode,
151 struct qed_spq_comp_cb *p_comp_addr,
152 void *event_context, iscsi_event_cb_t async_event_cb)
153{
154 struct iscsi_init_ramrod_params *p_ramrod = NULL;
155 struct scsi_init_func_queues *p_queue = NULL;
156 struct qed_iscsi_pf_params *p_params = NULL;
157 struct iscsi_spe_func_init *p_init = NULL;
158 struct qed_spq_entry *p_ent = NULL;
159 struct qed_sp_init_data init_data;
160 int rc = 0;
161 u32 dval;
162 u16 val;
163 u8 i;
164
165 /* Get SPQ entry */
166 memset(&init_data, 0, sizeof(init_data));
167 init_data.cid = qed_spq_get_cid(p_hwfn);
168 init_data.opaque_fid = p_hwfn->hw_info.opaque_fid;
169 init_data.comp_mode = comp_mode;
170 init_data.p_comp_data = p_comp_addr;
171
172 rc = qed_sp_init_request(p_hwfn, &p_ent,
173 ISCSI_RAMROD_CMD_ID_INIT_FUNC,
174 PROTOCOLID_ISCSI, &init_data);
175 if (rc)
176 return rc;
177
178 p_ramrod = &p_ent->ramrod.iscsi_init;
179 p_init = &p_ramrod->iscsi_init_spe;
180 p_params = &p_hwfn->pf_params.iscsi_pf_params;
181 p_queue = &p_init->q_params;
182
Mintz, Yuval08737a32017-04-06 15:58:33 +0300183 /* Sanity */
184 if (p_params->num_queues > p_hwfn->hw_info.feat_num[QED_ISCSI_CQ]) {
185 DP_ERR(p_hwfn,
186 "Cannot satisfy CQ amount. Queues requested %d, CQs available %d. Aborting function start\n",
187 p_params->num_queues,
188 p_hwfn->hw_info.resc_num[QED_ISCSI_CQ]);
189 return -EINVAL;
190 }
191
Yuval Mintzfc831822016-12-01 00:21:06 -0800192 SET_FIELD(p_init->hdr.flags,
193 ISCSI_SLOW_PATH_HDR_LAYER_CODE, ISCSI_SLOW_PATH_LAYER_CODE);
194 p_init->hdr.op_code = ISCSI_RAMROD_CMD_ID_INIT_FUNC;
195
196 val = p_params->half_way_close_timeout;
197 p_init->half_way_close_timeout = cpu_to_le16(val);
198 p_init->num_sq_pages_in_ring = p_params->num_sq_pages_in_ring;
199 p_init->num_r2tq_pages_in_ring = p_params->num_r2tq_pages_in_ring;
200 p_init->num_uhq_pages_in_ring = p_params->num_uhq_pages_in_ring;
Mintz, Yuval6b116b12017-03-14 15:26:04 +0200201 p_init->ooo_enable = p_params->ooo_enable;
202 p_init->ll2_rx_queue_id = p_hwfn->hw_info.resc_start[QED_LL2_QUEUE] +
203 p_params->ll2_ooo_queue_id;
Yuval Mintzfc831822016-12-01 00:21:06 -0800204 p_init->func_params.log_page_size = p_params->log_page_size;
205 val = p_params->num_tasks;
206 p_init->func_params.num_tasks = cpu_to_le16(val);
207 p_init->debug_mode.flags = p_params->debug_mode;
208
209 DMA_REGPAIR_LE(p_queue->glbl_q_params_addr,
210 p_params->glbl_q_params_addr);
211
212 val = p_params->cq_num_entries;
213 p_queue->cq_num_entries = cpu_to_le16(val);
214 val = p_params->cmdq_num_entries;
215 p_queue->cmdq_num_entries = cpu_to_le16(val);
216 p_queue->num_queues = p_params->num_queues;
217 dval = (u8)p_hwfn->hw_info.resc_start[QED_CMDQS_CQS];
218 p_queue->queue_relative_offset = (u8)dval;
219 p_queue->cq_sb_pi = p_params->gl_rq_pi;
220 p_queue->cmdq_sb_pi = p_params->gl_cmd_pi;
221
222 for (i = 0; i < p_params->num_queues; i++) {
223 val = p_hwfn->sbs_info[i]->igu_sb_id;
224 p_queue->cq_cmdq_sb_num_arr[i] = cpu_to_le16(val);
225 }
226
Mintz, Yuvald0d40a72017-03-28 15:12:56 +0300227 p_queue->bdq_resource_id = (u8)RESC_START(p_hwfn, QED_BDQ);
Yuval Mintzfc831822016-12-01 00:21:06 -0800228
229 DMA_REGPAIR_LE(p_queue->bdq_pbl_base_address[BDQ_ID_RQ],
230 p_params->bdq_pbl_base_addr[BDQ_ID_RQ]);
231 p_queue->bdq_pbl_num_entries[BDQ_ID_RQ] =
232 p_params->bdq_pbl_num_entries[BDQ_ID_RQ];
233 val = p_params->bdq_xoff_threshold[BDQ_ID_RQ];
234 p_queue->bdq_xoff_threshold[BDQ_ID_RQ] = cpu_to_le16(val);
235 val = p_params->bdq_xon_threshold[BDQ_ID_RQ];
236 p_queue->bdq_xon_threshold[BDQ_ID_RQ] = cpu_to_le16(val);
237
238 DMA_REGPAIR_LE(p_queue->bdq_pbl_base_address[BDQ_ID_IMM_DATA],
239 p_params->bdq_pbl_base_addr[BDQ_ID_IMM_DATA]);
240 p_queue->bdq_pbl_num_entries[BDQ_ID_IMM_DATA] =
241 p_params->bdq_pbl_num_entries[BDQ_ID_IMM_DATA];
242 val = p_params->bdq_xoff_threshold[BDQ_ID_IMM_DATA];
243 p_queue->bdq_xoff_threshold[BDQ_ID_IMM_DATA] = cpu_to_le16(val);
244 val = p_params->bdq_xon_threshold[BDQ_ID_IMM_DATA];
245 p_queue->bdq_xon_threshold[BDQ_ID_IMM_DATA] = cpu_to_le16(val);
246 val = p_params->rq_buffer_size;
247 p_queue->rq_buffer_size = cpu_to_le16(val);
248 if (p_params->is_target) {
249 SET_FIELD(p_queue->q_validity,
250 SCSI_INIT_FUNC_QUEUES_RQ_VALID, 1);
251 if (p_queue->bdq_pbl_num_entries[BDQ_ID_IMM_DATA])
252 SET_FIELD(p_queue->q_validity,
253 SCSI_INIT_FUNC_QUEUES_IMM_DATA_VALID, 1);
254 SET_FIELD(p_queue->q_validity,
255 SCSI_INIT_FUNC_QUEUES_CMD_VALID, 1);
256 } else {
257 SET_FIELD(p_queue->q_validity,
258 SCSI_INIT_FUNC_QUEUES_RQ_VALID, 1);
259 }
260 p_ramrod->tcp_init.two_msl_timer = cpu_to_le32(p_params->two_msl_timer);
261 val = p_params->tx_sws_timer;
262 p_ramrod->tcp_init.tx_sws_timer = cpu_to_le16(val);
263 p_ramrod->tcp_init.maxfinrt = p_params->max_fin_rt;
264
265 p_hwfn->p_iscsi_info->event_context = event_context;
266 p_hwfn->p_iscsi_info->event_cb = async_event_cb;
267
268 return qed_spq_post(p_hwfn, p_ent, NULL);
269}
270
271static int qed_sp_iscsi_conn_offload(struct qed_hwfn *p_hwfn,
272 struct qed_iscsi_conn *p_conn,
273 enum spq_mode comp_mode,
274 struct qed_spq_comp_cb *p_comp_addr)
275{
276 struct iscsi_spe_conn_offload *p_ramrod = NULL;
277 struct tcp_offload_params_opt2 *p_tcp2 = NULL;
278 struct tcp_offload_params *p_tcp = NULL;
279 struct qed_spq_entry *p_ent = NULL;
280 struct qed_sp_init_data init_data;
Yuval Mintzfc831822016-12-01 00:21:06 -0800281 dma_addr_t r2tq_pbl_addr;
282 dma_addr_t xhq_pbl_addr;
283 dma_addr_t uhq_pbl_addr;
Ariel Eliorb5a9ee72017-04-03 12:21:09 +0300284 u16 physical_q;
Yuval Mintzfc831822016-12-01 00:21:06 -0800285 int rc = 0;
286 u32 dval;
287 u16 wval;
288 u8 i;
289 u16 *p;
290
291 /* Get SPQ entry */
292 memset(&init_data, 0, sizeof(init_data));
293 init_data.cid = p_conn->icid;
294 init_data.opaque_fid = p_hwfn->hw_info.opaque_fid;
295 init_data.comp_mode = comp_mode;
296 init_data.p_comp_data = p_comp_addr;
297
298 rc = qed_sp_init_request(p_hwfn, &p_ent,
299 ISCSI_RAMROD_CMD_ID_OFFLOAD_CONN,
300 PROTOCOLID_ISCSI, &init_data);
301 if (rc)
302 return rc;
303
304 p_ramrod = &p_ent->ramrod.iscsi_conn_offload;
305
306 /* Transmission PQ is the first of the PF */
Ariel Eliorb5a9ee72017-04-03 12:21:09 +0300307 physical_q = qed_get_cm_pq_idx(p_hwfn, PQ_FLAGS_OFLD);
308 p_conn->physical_q0 = cpu_to_le16(physical_q);
309 p_ramrod->iscsi.physical_q0 = cpu_to_le16(physical_q);
Yuval Mintzfc831822016-12-01 00:21:06 -0800310
311 /* iSCSI Pure-ACK PQ */
Ariel Eliorb5a9ee72017-04-03 12:21:09 +0300312 physical_q = qed_get_cm_pq_idx(p_hwfn, PQ_FLAGS_ACK);
313 p_conn->physical_q1 = cpu_to_le16(physical_q);
314 p_ramrod->iscsi.physical_q1 = cpu_to_le16(physical_q);
Yuval Mintzfc831822016-12-01 00:21:06 -0800315
316 p_ramrod->hdr.op_code = ISCSI_RAMROD_CMD_ID_OFFLOAD_CONN;
317 SET_FIELD(p_ramrod->hdr.flags, ISCSI_SLOW_PATH_HDR_LAYER_CODE,
318 p_conn->layer_code);
319
320 p_ramrod->conn_id = cpu_to_le16(p_conn->conn_id);
321 p_ramrod->fw_cid = cpu_to_le32(p_conn->icid);
322
323 DMA_REGPAIR_LE(p_ramrod->iscsi.sq_pbl_addr, p_conn->sq_pbl_addr);
324
325 r2tq_pbl_addr = qed_chain_get_pbl_phys(&p_conn->r2tq);
326 DMA_REGPAIR_LE(p_ramrod->iscsi.r2tq_pbl_addr, r2tq_pbl_addr);
327
328 xhq_pbl_addr = qed_chain_get_pbl_phys(&p_conn->xhq);
329 DMA_REGPAIR_LE(p_ramrod->iscsi.xhq_pbl_addr, xhq_pbl_addr);
330
331 uhq_pbl_addr = qed_chain_get_pbl_phys(&p_conn->uhq);
332 DMA_REGPAIR_LE(p_ramrod->iscsi.uhq_pbl_addr, uhq_pbl_addr);
333
334 p_ramrod->iscsi.initial_ack = cpu_to_le32(p_conn->initial_ack);
335 p_ramrod->iscsi.flags = p_conn->offl_flags;
336 p_ramrod->iscsi.default_cq = p_conn->default_cq;
337 p_ramrod->iscsi.stat_sn = cpu_to_le32(p_conn->stat_sn);
338
339 if (!GET_FIELD(p_ramrod->iscsi.flags,
340 ISCSI_CONN_OFFLOAD_PARAMS_TCP_ON_CHIP_1B)) {
341 p_tcp = &p_ramrod->tcp;
342
343 p = (u16 *)p_conn->local_mac;
344 p_tcp->local_mac_addr_hi = swab16(get_unaligned(p));
345 p_tcp->local_mac_addr_mid = swab16(get_unaligned(p + 1));
346 p_tcp->local_mac_addr_lo = swab16(get_unaligned(p + 2));
347
348 p = (u16 *)p_conn->remote_mac;
349 p_tcp->remote_mac_addr_hi = swab16(get_unaligned(p));
350 p_tcp->remote_mac_addr_mid = swab16(get_unaligned(p + 1));
351 p_tcp->remote_mac_addr_lo = swab16(get_unaligned(p + 2));
352
353 p_tcp->vlan_id = cpu_to_le16(p_conn->vlan_id);
354
355 p_tcp->flags = p_conn->tcp_flags;
356 p_tcp->ip_version = p_conn->ip_version;
357 for (i = 0; i < 4; i++) {
358 dval = p_conn->remote_ip[i];
359 p_tcp->remote_ip[i] = cpu_to_le32(dval);
360 dval = p_conn->local_ip[i];
361 p_tcp->local_ip[i] = cpu_to_le32(dval);
362 }
363 p_tcp->ka_max_probe_cnt = p_conn->ka_max_probe_cnt;
364 p_tcp->dup_ack_theshold = p_conn->dup_ack_theshold;
365
366 p_tcp->rcv_next = cpu_to_le32(p_conn->rcv_next);
367 p_tcp->snd_una = cpu_to_le32(p_conn->snd_una);
368 p_tcp->snd_next = cpu_to_le32(p_conn->snd_next);
369 p_tcp->snd_max = cpu_to_le32(p_conn->snd_max);
370 p_tcp->snd_wnd = cpu_to_le32(p_conn->snd_wnd);
371 p_tcp->rcv_wnd = cpu_to_le32(p_conn->rcv_wnd);
372 p_tcp->snd_wl1 = cpu_to_le32(p_conn->snd_wl1);
373 p_tcp->cwnd = cpu_to_le32(p_conn->cwnd);
374 p_tcp->ss_thresh = cpu_to_le32(p_conn->ss_thresh);
375 p_tcp->srtt = cpu_to_le16(p_conn->srtt);
376 p_tcp->rtt_var = cpu_to_le16(p_conn->rtt_var);
Yuval Mintzfc831822016-12-01 00:21:06 -0800377 p_tcp->ts_recent = cpu_to_le32(p_conn->ts_recent);
378 p_tcp->ts_recent_age = cpu_to_le32(p_conn->ts_recent_age);
379 p_tcp->total_rt = cpu_to_le32(p_conn->total_rt);
380 dval = p_conn->ka_timeout_delta;
381 p_tcp->ka_timeout_delta = cpu_to_le32(dval);
382 dval = p_conn->rt_timeout_delta;
383 p_tcp->rt_timeout_delta = cpu_to_le32(dval);
384 p_tcp->dup_ack_cnt = p_conn->dup_ack_cnt;
385 p_tcp->snd_wnd_probe_cnt = p_conn->snd_wnd_probe_cnt;
386 p_tcp->ka_probe_cnt = p_conn->ka_probe_cnt;
387 p_tcp->rt_cnt = p_conn->rt_cnt;
388 p_tcp->flow_label = cpu_to_le32(p_conn->flow_label);
389 p_tcp->ka_timeout = cpu_to_le32(p_conn->ka_timeout);
390 p_tcp->ka_interval = cpu_to_le32(p_conn->ka_interval);
391 p_tcp->max_rt_time = cpu_to_le32(p_conn->max_rt_time);
392 dval = p_conn->initial_rcv_wnd;
393 p_tcp->initial_rcv_wnd = cpu_to_le32(dval);
394 p_tcp->ttl = p_conn->ttl;
395 p_tcp->tos_or_tc = p_conn->tos_or_tc;
396 p_tcp->remote_port = cpu_to_le16(p_conn->remote_port);
397 p_tcp->local_port = cpu_to_le16(p_conn->local_port);
398 p_tcp->mss = cpu_to_le16(p_conn->mss);
399 p_tcp->snd_wnd_scale = p_conn->snd_wnd_scale;
400 p_tcp->rcv_wnd_scale = p_conn->rcv_wnd_scale;
Yuval Mintzfc831822016-12-01 00:21:06 -0800401 wval = p_conn->da_timeout_value;
402 p_tcp->da_timeout_value = cpu_to_le16(wval);
403 p_tcp->ack_frequency = p_conn->ack_frequency;
404 p_tcp->connect_mode = p_conn->connect_mode;
405 } else {
406 p_tcp2 =
407 &((struct iscsi_spe_conn_offload_option2 *)p_ramrod)->tcp;
408
409 p = (u16 *)p_conn->local_mac;
410 p_tcp2->local_mac_addr_hi = swab16(get_unaligned(p));
411 p_tcp2->local_mac_addr_mid = swab16(get_unaligned(p + 1));
412 p_tcp2->local_mac_addr_lo = swab16(get_unaligned(p + 2));
413
414 p = (u16 *)p_conn->remote_mac;
415 p_tcp2->remote_mac_addr_hi = swab16(get_unaligned(p));
416 p_tcp2->remote_mac_addr_mid = swab16(get_unaligned(p + 1));
417 p_tcp2->remote_mac_addr_lo = swab16(get_unaligned(p + 2));
418
419 p_tcp2->vlan_id = cpu_to_le16(p_conn->vlan_id);
420 p_tcp2->flags = p_conn->tcp_flags;
421
422 p_tcp2->ip_version = p_conn->ip_version;
423 for (i = 0; i < 4; i++) {
424 dval = p_conn->remote_ip[i];
425 p_tcp2->remote_ip[i] = cpu_to_le32(dval);
426 dval = p_conn->local_ip[i];
427 p_tcp2->local_ip[i] = cpu_to_le32(dval);
428 }
429
430 p_tcp2->flow_label = cpu_to_le32(p_conn->flow_label);
431 p_tcp2->ttl = p_conn->ttl;
432 p_tcp2->tos_or_tc = p_conn->tos_or_tc;
433 p_tcp2->remote_port = cpu_to_le16(p_conn->remote_port);
434 p_tcp2->local_port = cpu_to_le16(p_conn->local_port);
435 p_tcp2->mss = cpu_to_le16(p_conn->mss);
436 p_tcp2->rcv_wnd_scale = p_conn->rcv_wnd_scale;
437 p_tcp2->connect_mode = p_conn->connect_mode;
438 wval = p_conn->syn_ip_payload_length;
439 p_tcp2->syn_ip_payload_length = cpu_to_le16(wval);
440 p_tcp2->syn_phy_addr_lo = DMA_LO_LE(p_conn->syn_phy_addr);
441 p_tcp2->syn_phy_addr_hi = DMA_HI_LE(p_conn->syn_phy_addr);
442 }
443
444 return qed_spq_post(p_hwfn, p_ent, NULL);
445}
446
447static int qed_sp_iscsi_conn_update(struct qed_hwfn *p_hwfn,
448 struct qed_iscsi_conn *p_conn,
449 enum spq_mode comp_mode,
450 struct qed_spq_comp_cb *p_comp_addr)
451{
452 struct iscsi_conn_update_ramrod_params *p_ramrod = NULL;
453 struct qed_spq_entry *p_ent = NULL;
454 struct qed_sp_init_data init_data;
455 int rc = -EINVAL;
456 u32 dval;
457
458 /* Get SPQ entry */
459 memset(&init_data, 0, sizeof(init_data));
460 init_data.cid = p_conn->icid;
461 init_data.opaque_fid = p_hwfn->hw_info.opaque_fid;
462 init_data.comp_mode = comp_mode;
463 init_data.p_comp_data = p_comp_addr;
464
465 rc = qed_sp_init_request(p_hwfn, &p_ent,
466 ISCSI_RAMROD_CMD_ID_UPDATE_CONN,
467 PROTOCOLID_ISCSI, &init_data);
468 if (rc)
469 return rc;
470
471 p_ramrod = &p_ent->ramrod.iscsi_conn_update;
472 p_ramrod->hdr.op_code = ISCSI_RAMROD_CMD_ID_UPDATE_CONN;
473 SET_FIELD(p_ramrod->hdr.flags,
474 ISCSI_SLOW_PATH_HDR_LAYER_CODE, p_conn->layer_code);
475
476 p_ramrod->conn_id = cpu_to_le16(p_conn->conn_id);
477 p_ramrod->fw_cid = cpu_to_le32(p_conn->icid);
478 p_ramrod->flags = p_conn->update_flag;
479 p_ramrod->max_seq_size = cpu_to_le32(p_conn->max_seq_size);
480 dval = p_conn->max_recv_pdu_length;
481 p_ramrod->max_recv_pdu_length = cpu_to_le32(dval);
482 dval = p_conn->max_send_pdu_length;
483 p_ramrod->max_send_pdu_length = cpu_to_le32(dval);
484 dval = p_conn->first_seq_length;
485 p_ramrod->first_seq_length = cpu_to_le32(dval);
486 p_ramrod->exp_stat_sn = cpu_to_le32(p_conn->exp_stat_sn);
487
488 return qed_spq_post(p_hwfn, p_ent, NULL);
489}
490
491static int qed_sp_iscsi_conn_terminate(struct qed_hwfn *p_hwfn,
492 struct qed_iscsi_conn *p_conn,
493 enum spq_mode comp_mode,
494 struct qed_spq_comp_cb *p_comp_addr)
495{
496 struct iscsi_spe_conn_termination *p_ramrod = NULL;
497 struct qed_spq_entry *p_ent = NULL;
498 struct qed_sp_init_data init_data;
499 int rc = -EINVAL;
500
501 /* Get SPQ entry */
502 memset(&init_data, 0, sizeof(init_data));
503 init_data.cid = p_conn->icid;
504 init_data.opaque_fid = p_hwfn->hw_info.opaque_fid;
505 init_data.comp_mode = comp_mode;
506 init_data.p_comp_data = p_comp_addr;
507
508 rc = qed_sp_init_request(p_hwfn, &p_ent,
509 ISCSI_RAMROD_CMD_ID_TERMINATION_CONN,
510 PROTOCOLID_ISCSI, &init_data);
511 if (rc)
512 return rc;
513
514 p_ramrod = &p_ent->ramrod.iscsi_conn_terminate;
515 p_ramrod->hdr.op_code = ISCSI_RAMROD_CMD_ID_TERMINATION_CONN;
516 SET_FIELD(p_ramrod->hdr.flags,
517 ISCSI_SLOW_PATH_HDR_LAYER_CODE, p_conn->layer_code);
518
519 p_ramrod->conn_id = cpu_to_le16(p_conn->conn_id);
520 p_ramrod->fw_cid = cpu_to_le32(p_conn->icid);
521 p_ramrod->abortive = p_conn->abortive_dsconnect;
522
523 DMA_REGPAIR_LE(p_ramrod->query_params_addr,
524 p_conn->tcp_upload_params_phys_addr);
525 DMA_REGPAIR_LE(p_ramrod->queue_cnts_addr, p_conn->queue_cnts_phys_addr);
526
527 return qed_spq_post(p_hwfn, p_ent, NULL);
528}
529
530static int qed_sp_iscsi_conn_clear_sq(struct qed_hwfn *p_hwfn,
531 struct qed_iscsi_conn *p_conn,
532 enum spq_mode comp_mode,
533 struct qed_spq_comp_cb *p_comp_addr)
534{
535 struct iscsi_slow_path_hdr *p_ramrod = NULL;
536 struct qed_spq_entry *p_ent = NULL;
537 struct qed_sp_init_data init_data;
538 int rc = -EINVAL;
539
540 /* Get SPQ entry */
541 memset(&init_data, 0, sizeof(init_data));
542 init_data.cid = p_conn->icid;
543 init_data.opaque_fid = p_hwfn->hw_info.opaque_fid;
544 init_data.comp_mode = comp_mode;
545 init_data.p_comp_data = p_comp_addr;
546
547 rc = qed_sp_init_request(p_hwfn, &p_ent,
548 ISCSI_RAMROD_CMD_ID_CLEAR_SQ,
549 PROTOCOLID_ISCSI, &init_data);
550 if (rc)
551 return rc;
552
553 p_ramrod = &p_ent->ramrod.iscsi_empty;
554 p_ramrod->op_code = ISCSI_RAMROD_CMD_ID_CLEAR_SQ;
555 SET_FIELD(p_ramrod->flags,
556 ISCSI_SLOW_PATH_HDR_LAYER_CODE, p_conn->layer_code);
557
558 return qed_spq_post(p_hwfn, p_ent, NULL);
559}
560
561static int qed_sp_iscsi_func_stop(struct qed_hwfn *p_hwfn,
562 enum spq_mode comp_mode,
563 struct qed_spq_comp_cb *p_comp_addr)
564{
565 struct iscsi_spe_func_dstry *p_ramrod = NULL;
566 struct qed_spq_entry *p_ent = NULL;
567 struct qed_sp_init_data init_data;
568 int rc = 0;
569
570 /* Get SPQ entry */
571 memset(&init_data, 0, sizeof(init_data));
572 init_data.cid = qed_spq_get_cid(p_hwfn);
573 init_data.opaque_fid = p_hwfn->hw_info.opaque_fid;
574 init_data.comp_mode = comp_mode;
575 init_data.p_comp_data = p_comp_addr;
576
577 rc = qed_sp_init_request(p_hwfn, &p_ent,
578 ISCSI_RAMROD_CMD_ID_DESTROY_FUNC,
579 PROTOCOLID_ISCSI, &init_data);
580 if (rc)
581 return rc;
582
583 p_ramrod = &p_ent->ramrod.iscsi_destroy;
584 p_ramrod->hdr.op_code = ISCSI_RAMROD_CMD_ID_DESTROY_FUNC;
585
586 return qed_spq_post(p_hwfn, p_ent, NULL);
587}
588
589static void __iomem *qed_iscsi_get_db_addr(struct qed_hwfn *p_hwfn, u32 cid)
590{
591 return (u8 __iomem *)p_hwfn->doorbells +
592 qed_db_addr(cid, DQ_DEMS_LEGACY);
593}
594
595static void __iomem *qed_iscsi_get_primary_bdq_prod(struct qed_hwfn *p_hwfn,
596 u8 bdq_id)
597{
Mintz, Yuvald0d40a72017-03-28 15:12:56 +0300598 if (RESC_NUM(p_hwfn, QED_BDQ)) {
599 return (u8 __iomem *)p_hwfn->regview +
600 GTT_BAR0_MAP_REG_MSDM_RAM +
601 MSTORM_SCSI_BDQ_EXT_PROD_OFFSET(RESC_START(p_hwfn,
602 QED_BDQ),
603 bdq_id);
604 } else {
605 DP_NOTICE(p_hwfn, "BDQ is not allocated!\n");
606 return NULL;
607 }
Yuval Mintzfc831822016-12-01 00:21:06 -0800608}
609
610static void __iomem *qed_iscsi_get_secondary_bdq_prod(struct qed_hwfn *p_hwfn,
611 u8 bdq_id)
612{
Mintz, Yuvald0d40a72017-03-28 15:12:56 +0300613 if (RESC_NUM(p_hwfn, QED_BDQ)) {
614 return (u8 __iomem *)p_hwfn->regview +
615 GTT_BAR0_MAP_REG_TSDM_RAM +
616 TSTORM_SCSI_BDQ_EXT_PROD_OFFSET(RESC_START(p_hwfn,
617 QED_BDQ),
618 bdq_id);
619 } else {
620 DP_NOTICE(p_hwfn, "BDQ is not allocated!\n");
621 return NULL;
622 }
Yuval Mintzfc831822016-12-01 00:21:06 -0800623}
624
625static int qed_iscsi_setup_connection(struct qed_hwfn *p_hwfn,
626 struct qed_iscsi_conn *p_conn)
627{
628 if (!p_conn->queue_cnts_virt_addr)
629 goto nomem;
630 memset(p_conn->queue_cnts_virt_addr, 0,
631 sizeof(*p_conn->queue_cnts_virt_addr));
632
633 if (!p_conn->tcp_upload_params_virt_addr)
634 goto nomem;
635 memset(p_conn->tcp_upload_params_virt_addr, 0,
636 sizeof(*p_conn->tcp_upload_params_virt_addr));
637
638 if (!p_conn->r2tq.p_virt_addr)
639 goto nomem;
640 qed_chain_pbl_zero_mem(&p_conn->r2tq);
641
642 if (!p_conn->uhq.p_virt_addr)
643 goto nomem;
644 qed_chain_pbl_zero_mem(&p_conn->uhq);
645
646 if (!p_conn->xhq.p_virt_addr)
647 goto nomem;
648 qed_chain_pbl_zero_mem(&p_conn->xhq);
649
650 return 0;
651nomem:
652 return -ENOMEM;
653}
654
655static int qed_iscsi_allocate_connection(struct qed_hwfn *p_hwfn,
656 struct qed_iscsi_conn **p_out_conn)
657{
658 u16 uhq_num_elements = 0, xhq_num_elements = 0, r2tq_num_elements = 0;
659 struct scsi_terminate_extra_params *p_q_cnts = NULL;
660 struct qed_iscsi_pf_params *p_params = NULL;
661 struct tcp_upload_params *p_tcp = NULL;
662 struct qed_iscsi_conn *p_conn = NULL;
663 int rc = 0;
664
665 /* Try finding a free connection that can be used */
666 spin_lock_bh(&p_hwfn->p_iscsi_info->lock);
667 if (!list_empty(&p_hwfn->p_iscsi_info->free_list))
668 p_conn = list_first_entry(&p_hwfn->p_iscsi_info->free_list,
669 struct qed_iscsi_conn, list_entry);
670 if (p_conn) {
671 list_del(&p_conn->list_entry);
672 spin_unlock_bh(&p_hwfn->p_iscsi_info->lock);
673 *p_out_conn = p_conn;
674 return 0;
675 }
676 spin_unlock_bh(&p_hwfn->p_iscsi_info->lock);
677
678 /* Need to allocate a new connection */
679 p_params = &p_hwfn->pf_params.iscsi_pf_params;
680
681 p_conn = kzalloc(sizeof(*p_conn), GFP_KERNEL);
682 if (!p_conn)
683 return -ENOMEM;
684
685 p_q_cnts = dma_alloc_coherent(&p_hwfn->cdev->pdev->dev,
686 sizeof(*p_q_cnts),
687 &p_conn->queue_cnts_phys_addr,
688 GFP_KERNEL);
689 if (!p_q_cnts)
690 goto nomem_queue_cnts_param;
691 p_conn->queue_cnts_virt_addr = p_q_cnts;
692
693 p_tcp = dma_alloc_coherent(&p_hwfn->cdev->pdev->dev,
694 sizeof(*p_tcp),
695 &p_conn->tcp_upload_params_phys_addr,
696 GFP_KERNEL);
697 if (!p_tcp)
698 goto nomem_upload_param;
699 p_conn->tcp_upload_params_virt_addr = p_tcp;
700
701 r2tq_num_elements = p_params->num_r2tq_pages_in_ring *
702 QED_CHAIN_PAGE_SIZE / 0x80;
703 rc = qed_chain_alloc(p_hwfn->cdev,
704 QED_CHAIN_USE_TO_CONSUME_PRODUCE,
705 QED_CHAIN_MODE_PBL,
706 QED_CHAIN_CNT_TYPE_U16,
707 r2tq_num_elements, 0x80, &p_conn->r2tq);
708 if (rc)
709 goto nomem_r2tq;
710
711 uhq_num_elements = p_params->num_uhq_pages_in_ring *
712 QED_CHAIN_PAGE_SIZE / sizeof(struct iscsi_uhqe);
713 rc = qed_chain_alloc(p_hwfn->cdev,
714 QED_CHAIN_USE_TO_CONSUME_PRODUCE,
715 QED_CHAIN_MODE_PBL,
716 QED_CHAIN_CNT_TYPE_U16,
717 uhq_num_elements,
718 sizeof(struct iscsi_uhqe), &p_conn->uhq);
719 if (rc)
720 goto nomem_uhq;
721
722 xhq_num_elements = uhq_num_elements;
723 rc = qed_chain_alloc(p_hwfn->cdev,
724 QED_CHAIN_USE_TO_CONSUME_PRODUCE,
725 QED_CHAIN_MODE_PBL,
726 QED_CHAIN_CNT_TYPE_U16,
727 xhq_num_elements,
728 sizeof(struct iscsi_xhqe), &p_conn->xhq);
729 if (rc)
730 goto nomem;
731
732 p_conn->free_on_delete = true;
733 *p_out_conn = p_conn;
734 return 0;
735
736nomem:
737 qed_chain_free(p_hwfn->cdev, &p_conn->uhq);
738nomem_uhq:
739 qed_chain_free(p_hwfn->cdev, &p_conn->r2tq);
740nomem_r2tq:
741 dma_free_coherent(&p_hwfn->cdev->pdev->dev,
742 sizeof(struct tcp_upload_params),
743 p_conn->tcp_upload_params_virt_addr,
744 p_conn->tcp_upload_params_phys_addr);
745nomem_upload_param:
746 dma_free_coherent(&p_hwfn->cdev->pdev->dev,
747 sizeof(struct scsi_terminate_extra_params),
748 p_conn->queue_cnts_virt_addr,
749 p_conn->queue_cnts_phys_addr);
750nomem_queue_cnts_param:
751 kfree(p_conn);
752
753 return -ENOMEM;
754}
755
756static int qed_iscsi_acquire_connection(struct qed_hwfn *p_hwfn,
757 struct qed_iscsi_conn *p_in_conn,
758 struct qed_iscsi_conn **p_out_conn)
759{
760 struct qed_iscsi_conn *p_conn = NULL;
761 int rc = 0;
762 u32 icid;
763
764 spin_lock_bh(&p_hwfn->p_iscsi_info->lock);
765 rc = qed_cxt_acquire_cid(p_hwfn, PROTOCOLID_ISCSI, &icid);
766 spin_unlock_bh(&p_hwfn->p_iscsi_info->lock);
767 if (rc)
768 return rc;
769
770 /* Use input connection or allocate a new one */
771 if (p_in_conn)
772 p_conn = p_in_conn;
773 else
774 rc = qed_iscsi_allocate_connection(p_hwfn, &p_conn);
775
776 if (!rc)
777 rc = qed_iscsi_setup_connection(p_hwfn, p_conn);
778
779 if (rc) {
780 spin_lock_bh(&p_hwfn->p_iscsi_info->lock);
781 qed_cxt_release_cid(p_hwfn, icid);
782 spin_unlock_bh(&p_hwfn->p_iscsi_info->lock);
783 return rc;
784 }
785
786 p_conn->icid = icid;
787 p_conn->conn_id = (u16)icid;
788 p_conn->fw_cid = (p_hwfn->hw_info.opaque_fid << 16) | icid;
789
790 *p_out_conn = p_conn;
791
792 return rc;
793}
794
795static void qed_iscsi_release_connection(struct qed_hwfn *p_hwfn,
796 struct qed_iscsi_conn *p_conn)
797{
798 spin_lock_bh(&p_hwfn->p_iscsi_info->lock);
799 list_add_tail(&p_conn->list_entry, &p_hwfn->p_iscsi_info->free_list);
800 qed_cxt_release_cid(p_hwfn, p_conn->icid);
801 spin_unlock_bh(&p_hwfn->p_iscsi_info->lock);
802}
803
Mintz, Yuval4621ceb2017-03-14 15:26:01 +0200804void qed_iscsi_free_connection(struct qed_hwfn *p_hwfn,
805 struct qed_iscsi_conn *p_conn)
806{
807 qed_chain_free(p_hwfn->cdev, &p_conn->xhq);
808 qed_chain_free(p_hwfn->cdev, &p_conn->uhq);
809 qed_chain_free(p_hwfn->cdev, &p_conn->r2tq);
810 dma_free_coherent(&p_hwfn->cdev->pdev->dev,
811 sizeof(struct tcp_upload_params),
812 p_conn->tcp_upload_params_virt_addr,
813 p_conn->tcp_upload_params_phys_addr);
814 dma_free_coherent(&p_hwfn->cdev->pdev->dev,
815 sizeof(struct scsi_terminate_extra_params),
816 p_conn->queue_cnts_virt_addr,
817 p_conn->queue_cnts_phys_addr);
818 kfree(p_conn);
819}
820
Tomer Tayar3587cb82017-05-21 12:10:56 +0300821int qed_iscsi_alloc(struct qed_hwfn *p_hwfn)
Yuval Mintzfc831822016-12-01 00:21:06 -0800822{
823 struct qed_iscsi_info *p_iscsi_info;
824
825 p_iscsi_info = kzalloc(sizeof(*p_iscsi_info), GFP_KERNEL);
826 if (!p_iscsi_info)
Tomer Tayar3587cb82017-05-21 12:10:56 +0300827 return -ENOMEM;
Yuval Mintzfc831822016-12-01 00:21:06 -0800828
829 INIT_LIST_HEAD(&p_iscsi_info->free_list);
Tomer Tayar3587cb82017-05-21 12:10:56 +0300830
831 p_hwfn->p_iscsi_info = p_iscsi_info;
832 return 0;
Yuval Mintzfc831822016-12-01 00:21:06 -0800833}
834
Tomer Tayar3587cb82017-05-21 12:10:56 +0300835void qed_iscsi_setup(struct qed_hwfn *p_hwfn)
Yuval Mintzfc831822016-12-01 00:21:06 -0800836{
Tomer Tayar3587cb82017-05-21 12:10:56 +0300837 spin_lock_init(&p_hwfn->p_iscsi_info->lock);
Yuval Mintzfc831822016-12-01 00:21:06 -0800838}
839
Tomer Tayar3587cb82017-05-21 12:10:56 +0300840void qed_iscsi_free(struct qed_hwfn *p_hwfn)
Yuval Mintzfc831822016-12-01 00:21:06 -0800841{
Mintz, Yuval4621ceb2017-03-14 15:26:01 +0200842 struct qed_iscsi_conn *p_conn = NULL;
843
Tomer Tayar3587cb82017-05-21 12:10:56 +0300844 if (!p_hwfn->p_iscsi_info)
845 return;
846
Mintz, Yuval4621ceb2017-03-14 15:26:01 +0200847 while (!list_empty(&p_hwfn->p_iscsi_info->free_list)) {
848 p_conn = list_first_entry(&p_hwfn->p_iscsi_info->free_list,
849 struct qed_iscsi_conn, list_entry);
850 if (p_conn) {
851 list_del(&p_conn->list_entry);
852 qed_iscsi_free_connection(p_hwfn, p_conn);
853 }
854 }
855
Tomer Tayar3587cb82017-05-21 12:10:56 +0300856 kfree(p_hwfn->p_iscsi_info);
857 p_hwfn->p_iscsi_info = NULL;
Yuval Mintzfc831822016-12-01 00:21:06 -0800858}
859
860static void _qed_iscsi_get_tstats(struct qed_hwfn *p_hwfn,
861 struct qed_ptt *p_ptt,
862 struct qed_iscsi_stats *p_stats)
863{
864 struct tstorm_iscsi_stats_drv tstats;
865 u32 tstats_addr;
866
867 memset(&tstats, 0, sizeof(tstats));
868 tstats_addr = BAR0_MAP_REG_TSDM_RAM +
869 TSTORM_ISCSI_RX_STATS_OFFSET(p_hwfn->rel_pf_id);
870 qed_memcpy_from(p_hwfn, p_ptt, &tstats, tstats_addr, sizeof(tstats));
871
872 p_stats->iscsi_rx_bytes_cnt =
873 HILO_64_REGPAIR(tstats.iscsi_rx_bytes_cnt);
874 p_stats->iscsi_rx_packet_cnt =
875 HILO_64_REGPAIR(tstats.iscsi_rx_packet_cnt);
Mintz, Yuval3ddc48d2017-04-06 15:58:32 +0300876 p_stats->iscsi_rx_new_ooo_isle_events_cnt =
877 HILO_64_REGPAIR(tstats.iscsi_rx_new_ooo_isle_events_cnt);
Yuval Mintzfc831822016-12-01 00:21:06 -0800878 p_stats->iscsi_cmdq_threshold_cnt =
879 le32_to_cpu(tstats.iscsi_cmdq_threshold_cnt);
880 p_stats->iscsi_rq_threshold_cnt =
881 le32_to_cpu(tstats.iscsi_rq_threshold_cnt);
882 p_stats->iscsi_immq_threshold_cnt =
883 le32_to_cpu(tstats.iscsi_immq_threshold_cnt);
884}
885
886static void _qed_iscsi_get_mstats(struct qed_hwfn *p_hwfn,
887 struct qed_ptt *p_ptt,
888 struct qed_iscsi_stats *p_stats)
889{
890 struct mstorm_iscsi_stats_drv mstats;
891 u32 mstats_addr;
892
893 memset(&mstats, 0, sizeof(mstats));
894 mstats_addr = BAR0_MAP_REG_MSDM_RAM +
895 MSTORM_ISCSI_RX_STATS_OFFSET(p_hwfn->rel_pf_id);
896 qed_memcpy_from(p_hwfn, p_ptt, &mstats, mstats_addr, sizeof(mstats));
897
898 p_stats->iscsi_rx_dropped_pdus_task_not_valid =
899 HILO_64_REGPAIR(mstats.iscsi_rx_dropped_pdus_task_not_valid);
900}
901
902static void _qed_iscsi_get_ustats(struct qed_hwfn *p_hwfn,
903 struct qed_ptt *p_ptt,
904 struct qed_iscsi_stats *p_stats)
905{
906 struct ustorm_iscsi_stats_drv ustats;
907 u32 ustats_addr;
908
909 memset(&ustats, 0, sizeof(ustats));
910 ustats_addr = BAR0_MAP_REG_USDM_RAM +
911 USTORM_ISCSI_RX_STATS_OFFSET(p_hwfn->rel_pf_id);
912 qed_memcpy_from(p_hwfn, p_ptt, &ustats, ustats_addr, sizeof(ustats));
913
914 p_stats->iscsi_rx_data_pdu_cnt =
915 HILO_64_REGPAIR(ustats.iscsi_rx_data_pdu_cnt);
916 p_stats->iscsi_rx_r2t_pdu_cnt =
917 HILO_64_REGPAIR(ustats.iscsi_rx_r2t_pdu_cnt);
918 p_stats->iscsi_rx_total_pdu_cnt =
919 HILO_64_REGPAIR(ustats.iscsi_rx_total_pdu_cnt);
920}
921
922static void _qed_iscsi_get_xstats(struct qed_hwfn *p_hwfn,
923 struct qed_ptt *p_ptt,
924 struct qed_iscsi_stats *p_stats)
925{
926 struct xstorm_iscsi_stats_drv xstats;
927 u32 xstats_addr;
928
929 memset(&xstats, 0, sizeof(xstats));
930 xstats_addr = BAR0_MAP_REG_XSDM_RAM +
931 XSTORM_ISCSI_TX_STATS_OFFSET(p_hwfn->rel_pf_id);
932 qed_memcpy_from(p_hwfn, p_ptt, &xstats, xstats_addr, sizeof(xstats));
933
934 p_stats->iscsi_tx_go_to_slow_start_event_cnt =
935 HILO_64_REGPAIR(xstats.iscsi_tx_go_to_slow_start_event_cnt);
936 p_stats->iscsi_tx_fast_retransmit_event_cnt =
937 HILO_64_REGPAIR(xstats.iscsi_tx_fast_retransmit_event_cnt);
938}
939
940static void _qed_iscsi_get_ystats(struct qed_hwfn *p_hwfn,
941 struct qed_ptt *p_ptt,
942 struct qed_iscsi_stats *p_stats)
943{
944 struct ystorm_iscsi_stats_drv ystats;
945 u32 ystats_addr;
946
947 memset(&ystats, 0, sizeof(ystats));
948 ystats_addr = BAR0_MAP_REG_YSDM_RAM +
949 YSTORM_ISCSI_TX_STATS_OFFSET(p_hwfn->rel_pf_id);
950 qed_memcpy_from(p_hwfn, p_ptt, &ystats, ystats_addr, sizeof(ystats));
951
952 p_stats->iscsi_tx_data_pdu_cnt =
953 HILO_64_REGPAIR(ystats.iscsi_tx_data_pdu_cnt);
954 p_stats->iscsi_tx_r2t_pdu_cnt =
955 HILO_64_REGPAIR(ystats.iscsi_tx_r2t_pdu_cnt);
956 p_stats->iscsi_tx_total_pdu_cnt =
957 HILO_64_REGPAIR(ystats.iscsi_tx_total_pdu_cnt);
958}
959
960static void _qed_iscsi_get_pstats(struct qed_hwfn *p_hwfn,
961 struct qed_ptt *p_ptt,
962 struct qed_iscsi_stats *p_stats)
963{
964 struct pstorm_iscsi_stats_drv pstats;
965 u32 pstats_addr;
966
967 memset(&pstats, 0, sizeof(pstats));
968 pstats_addr = BAR0_MAP_REG_PSDM_RAM +
969 PSTORM_ISCSI_TX_STATS_OFFSET(p_hwfn->rel_pf_id);
970 qed_memcpy_from(p_hwfn, p_ptt, &pstats, pstats_addr, sizeof(pstats));
971
972 p_stats->iscsi_tx_bytes_cnt =
973 HILO_64_REGPAIR(pstats.iscsi_tx_bytes_cnt);
974 p_stats->iscsi_tx_packet_cnt =
975 HILO_64_REGPAIR(pstats.iscsi_tx_packet_cnt);
976}
977
978static int qed_iscsi_get_stats(struct qed_hwfn *p_hwfn,
979 struct qed_iscsi_stats *stats)
980{
981 struct qed_ptt *p_ptt;
982
983 memset(stats, 0, sizeof(*stats));
984
985 p_ptt = qed_ptt_acquire(p_hwfn);
986 if (!p_ptt) {
987 DP_ERR(p_hwfn, "Failed to acquire ptt\n");
988 return -EAGAIN;
989 }
990
991 _qed_iscsi_get_tstats(p_hwfn, p_ptt, stats);
992 _qed_iscsi_get_mstats(p_hwfn, p_ptt, stats);
993 _qed_iscsi_get_ustats(p_hwfn, p_ptt, stats);
994
995 _qed_iscsi_get_xstats(p_hwfn, p_ptt, stats);
996 _qed_iscsi_get_ystats(p_hwfn, p_ptt, stats);
997 _qed_iscsi_get_pstats(p_hwfn, p_ptt, stats);
998
999 qed_ptt_release(p_hwfn, p_ptt);
1000
1001 return 0;
1002}
1003
1004struct qed_hash_iscsi_con {
1005 struct hlist_node node;
1006 struct qed_iscsi_conn *con;
1007};
1008
1009static int qed_fill_iscsi_dev_info(struct qed_dev *cdev,
1010 struct qed_dev_iscsi_info *info)
1011{
1012 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1013
1014 int rc;
1015
1016 memset(info, 0, sizeof(*info));
1017 rc = qed_fill_dev_info(cdev, &info->common);
1018
1019 info->primary_dbq_rq_addr =
1020 qed_iscsi_get_primary_bdq_prod(hwfn, BDQ_ID_RQ);
1021 info->secondary_bdq_rq_addr =
1022 qed_iscsi_get_secondary_bdq_prod(hwfn, BDQ_ID_RQ);
1023
Mintz, Yuval08737a32017-04-06 15:58:33 +03001024 info->num_cqs = FEAT_NUM(hwfn, QED_ISCSI_CQ);
1025
Yuval Mintzfc831822016-12-01 00:21:06 -08001026 return rc;
1027}
1028
1029static void qed_register_iscsi_ops(struct qed_dev *cdev,
1030 struct qed_iscsi_cb_ops *ops, void *cookie)
1031{
1032 cdev->protocol_ops.iscsi = ops;
1033 cdev->ops_cookie = cookie;
1034}
1035
1036static struct qed_hash_iscsi_con *qed_iscsi_get_hash(struct qed_dev *cdev,
1037 u32 handle)
1038{
1039 struct qed_hash_iscsi_con *hash_con = NULL;
1040
1041 if (!(cdev->flags & QED_FLAG_STORAGE_STARTED))
1042 return NULL;
1043
1044 hash_for_each_possible(cdev->connections, hash_con, node, handle) {
1045 if (hash_con->con->icid == handle)
1046 break;
1047 }
1048
1049 if (!hash_con || (hash_con->con->icid != handle))
1050 return NULL;
1051
1052 return hash_con;
1053}
1054
1055static int qed_iscsi_stop(struct qed_dev *cdev)
1056{
1057 int rc;
1058
1059 if (!(cdev->flags & QED_FLAG_STORAGE_STARTED)) {
1060 DP_NOTICE(cdev, "iscsi already stopped\n");
1061 return 0;
1062 }
1063
1064 if (!hash_empty(cdev->connections)) {
1065 DP_NOTICE(cdev,
1066 "Can't stop iscsi - not all connections were returned\n");
1067 return -EINVAL;
1068 }
1069
1070 /* Stop the iscsi */
1071 rc = qed_sp_iscsi_func_stop(QED_LEADING_HWFN(cdev),
1072 QED_SPQ_MODE_EBLOCK, NULL);
1073 cdev->flags &= ~QED_FLAG_STORAGE_STARTED;
1074
1075 return rc;
1076}
1077
1078static int qed_iscsi_start(struct qed_dev *cdev,
1079 struct qed_iscsi_tid *tasks,
1080 void *event_context,
1081 iscsi_event_cb_t async_event_cb)
1082{
1083 int rc;
1084 struct qed_tid_mem *tid_info;
1085
1086 if (cdev->flags & QED_FLAG_STORAGE_STARTED) {
1087 DP_NOTICE(cdev, "iscsi already started;\n");
1088 return 0;
1089 }
1090
1091 rc = qed_sp_iscsi_func_start(QED_LEADING_HWFN(cdev),
1092 QED_SPQ_MODE_EBLOCK, NULL, event_context,
1093 async_event_cb);
1094 if (rc) {
1095 DP_NOTICE(cdev, "Failed to start iscsi\n");
1096 return rc;
1097 }
1098
1099 cdev->flags |= QED_FLAG_STORAGE_STARTED;
1100 hash_init(cdev->connections);
1101
1102 if (!tasks)
1103 return 0;
1104
1105 tid_info = kzalloc(sizeof(*tid_info), GFP_KERNEL);
1106
1107 if (!tid_info) {
1108 qed_iscsi_stop(cdev);
1109 return -ENOMEM;
1110 }
1111
1112 rc = qed_cxt_get_tid_mem_info(QED_LEADING_HWFN(cdev),
1113 tid_info);
1114 if (rc) {
1115 DP_NOTICE(cdev, "Failed to gather task information\n");
1116 qed_iscsi_stop(cdev);
1117 kfree(tid_info);
1118 return rc;
1119 }
1120
1121 /* Fill task information */
1122 tasks->size = tid_info->tid_size;
1123 tasks->num_tids_per_block = tid_info->num_tids_per_block;
1124 memcpy(tasks->blocks, tid_info->blocks,
1125 MAX_TID_BLOCKS_ISCSI * sizeof(u8 *));
1126
1127 kfree(tid_info);
1128
1129 return 0;
1130}
1131
1132static int qed_iscsi_acquire_conn(struct qed_dev *cdev,
1133 u32 *handle,
1134 u32 *fw_cid, void __iomem **p_doorbell)
1135{
1136 struct qed_hash_iscsi_con *hash_con;
1137 int rc;
1138
1139 /* Allocate a hashed connection */
1140 hash_con = kzalloc(sizeof(*hash_con), GFP_ATOMIC);
1141 if (!hash_con)
1142 return -ENOMEM;
1143
1144 /* Acquire the connection */
1145 rc = qed_iscsi_acquire_connection(QED_LEADING_HWFN(cdev), NULL,
1146 &hash_con->con);
1147 if (rc) {
1148 DP_NOTICE(cdev, "Failed to acquire Connection\n");
1149 kfree(hash_con);
1150 return rc;
1151 }
1152
1153 /* Added the connection to hash table */
1154 *handle = hash_con->con->icid;
1155 *fw_cid = hash_con->con->fw_cid;
1156 hash_add(cdev->connections, &hash_con->node, *handle);
1157
1158 if (p_doorbell)
1159 *p_doorbell = qed_iscsi_get_db_addr(QED_LEADING_HWFN(cdev),
1160 *handle);
1161
1162 return 0;
1163}
1164
1165static int qed_iscsi_release_conn(struct qed_dev *cdev, u32 handle)
1166{
1167 struct qed_hash_iscsi_con *hash_con;
1168
1169 hash_con = qed_iscsi_get_hash(cdev, handle);
1170 if (!hash_con) {
1171 DP_NOTICE(cdev, "Failed to find connection for handle %d\n",
1172 handle);
1173 return -EINVAL;
1174 }
1175
1176 hlist_del(&hash_con->node);
1177 qed_iscsi_release_connection(QED_LEADING_HWFN(cdev), hash_con->con);
1178 kfree(hash_con);
1179
1180 return 0;
1181}
1182
1183static int qed_iscsi_offload_conn(struct qed_dev *cdev,
1184 u32 handle,
1185 struct qed_iscsi_params_offload *conn_info)
1186{
1187 struct qed_hash_iscsi_con *hash_con;
1188 struct qed_iscsi_conn *con;
1189
1190 hash_con = qed_iscsi_get_hash(cdev, handle);
1191 if (!hash_con) {
1192 DP_NOTICE(cdev, "Failed to find connection for handle %d\n",
1193 handle);
1194 return -EINVAL;
1195 }
1196
1197 /* Update the connection with information from the params */
1198 con = hash_con->con;
1199
1200 ether_addr_copy(con->local_mac, conn_info->src.mac);
1201 ether_addr_copy(con->remote_mac, conn_info->dst.mac);
1202 memcpy(con->local_ip, conn_info->src.ip, sizeof(con->local_ip));
1203 memcpy(con->remote_ip, conn_info->dst.ip, sizeof(con->remote_ip));
1204 con->local_port = conn_info->src.port;
1205 con->remote_port = conn_info->dst.port;
1206
1207 con->layer_code = conn_info->layer_code;
1208 con->sq_pbl_addr = conn_info->sq_pbl_addr;
1209 con->initial_ack = conn_info->initial_ack;
1210 con->vlan_id = conn_info->vlan_id;
1211 con->tcp_flags = conn_info->tcp_flags;
1212 con->ip_version = conn_info->ip_version;
1213 con->default_cq = conn_info->default_cq;
1214 con->ka_max_probe_cnt = conn_info->ka_max_probe_cnt;
1215 con->dup_ack_theshold = conn_info->dup_ack_theshold;
1216 con->rcv_next = conn_info->rcv_next;
1217 con->snd_una = conn_info->snd_una;
1218 con->snd_next = conn_info->snd_next;
1219 con->snd_max = conn_info->snd_max;
1220 con->snd_wnd = conn_info->snd_wnd;
1221 con->rcv_wnd = conn_info->rcv_wnd;
1222 con->snd_wl1 = conn_info->snd_wl1;
1223 con->cwnd = conn_info->cwnd;
1224 con->ss_thresh = conn_info->ss_thresh;
1225 con->srtt = conn_info->srtt;
1226 con->rtt_var = conn_info->rtt_var;
1227 con->ts_time = conn_info->ts_time;
1228 con->ts_recent = conn_info->ts_recent;
1229 con->ts_recent_age = conn_info->ts_recent_age;
1230 con->total_rt = conn_info->total_rt;
1231 con->ka_timeout_delta = conn_info->ka_timeout_delta;
1232 con->rt_timeout_delta = conn_info->rt_timeout_delta;
1233 con->dup_ack_cnt = conn_info->dup_ack_cnt;
1234 con->snd_wnd_probe_cnt = conn_info->snd_wnd_probe_cnt;
1235 con->ka_probe_cnt = conn_info->ka_probe_cnt;
1236 con->rt_cnt = conn_info->rt_cnt;
1237 con->flow_label = conn_info->flow_label;
1238 con->ka_timeout = conn_info->ka_timeout;
1239 con->ka_interval = conn_info->ka_interval;
1240 con->max_rt_time = conn_info->max_rt_time;
1241 con->initial_rcv_wnd = conn_info->initial_rcv_wnd;
1242 con->ttl = conn_info->ttl;
1243 con->tos_or_tc = conn_info->tos_or_tc;
1244 con->remote_port = conn_info->remote_port;
1245 con->local_port = conn_info->local_port;
1246 con->mss = conn_info->mss;
1247 con->snd_wnd_scale = conn_info->snd_wnd_scale;
1248 con->rcv_wnd_scale = conn_info->rcv_wnd_scale;
1249 con->ts_ticks_per_second = conn_info->ts_ticks_per_second;
1250 con->da_timeout_value = conn_info->da_timeout_value;
1251 con->ack_frequency = conn_info->ack_frequency;
1252
1253 /* Set default values on other connection fields */
1254 con->offl_flags = 0x1;
1255
1256 return qed_sp_iscsi_conn_offload(QED_LEADING_HWFN(cdev), con,
1257 QED_SPQ_MODE_EBLOCK, NULL);
1258}
1259
1260static int qed_iscsi_update_conn(struct qed_dev *cdev,
1261 u32 handle,
1262 struct qed_iscsi_params_update *conn_info)
1263{
1264 struct qed_hash_iscsi_con *hash_con;
1265 struct qed_iscsi_conn *con;
1266
1267 hash_con = qed_iscsi_get_hash(cdev, handle);
1268 if (!hash_con) {
1269 DP_NOTICE(cdev, "Failed to find connection for handle %d\n",
1270 handle);
1271 return -EINVAL;
1272 }
1273
1274 /* Update the connection with information from the params */
1275 con = hash_con->con;
1276 con->update_flag = conn_info->update_flag;
1277 con->max_seq_size = conn_info->max_seq_size;
1278 con->max_recv_pdu_length = conn_info->max_recv_pdu_length;
1279 con->max_send_pdu_length = conn_info->max_send_pdu_length;
1280 con->first_seq_length = conn_info->first_seq_length;
1281 con->exp_stat_sn = conn_info->exp_stat_sn;
1282
1283 return qed_sp_iscsi_conn_update(QED_LEADING_HWFN(cdev), con,
1284 QED_SPQ_MODE_EBLOCK, NULL);
1285}
1286
1287static int qed_iscsi_clear_conn_sq(struct qed_dev *cdev, u32 handle)
1288{
1289 struct qed_hash_iscsi_con *hash_con;
1290
1291 hash_con = qed_iscsi_get_hash(cdev, handle);
1292 if (!hash_con) {
1293 DP_NOTICE(cdev, "Failed to find connection for handle %d\n",
1294 handle);
1295 return -EINVAL;
1296 }
1297
1298 return qed_sp_iscsi_conn_clear_sq(QED_LEADING_HWFN(cdev),
1299 hash_con->con,
1300 QED_SPQ_MODE_EBLOCK, NULL);
1301}
1302
1303static int qed_iscsi_destroy_conn(struct qed_dev *cdev,
1304 u32 handle, u8 abrt_conn)
1305{
1306 struct qed_hash_iscsi_con *hash_con;
1307
1308 hash_con = qed_iscsi_get_hash(cdev, handle);
1309 if (!hash_con) {
1310 DP_NOTICE(cdev, "Failed to find connection for handle %d\n",
1311 handle);
1312 return -EINVAL;
1313 }
1314
1315 hash_con->con->abortive_dsconnect = abrt_conn;
1316
1317 return qed_sp_iscsi_conn_terminate(QED_LEADING_HWFN(cdev),
1318 hash_con->con,
1319 QED_SPQ_MODE_EBLOCK, NULL);
1320}
1321
1322static int qed_iscsi_stats(struct qed_dev *cdev, struct qed_iscsi_stats *stats)
1323{
1324 return qed_iscsi_get_stats(QED_LEADING_HWFN(cdev), stats);
1325}
1326
Mintz, Yuval2f2b2612017-04-06 15:58:34 +03001327void qed_get_protocol_stats_iscsi(struct qed_dev *cdev,
1328 struct qed_mcp_iscsi_stats *stats)
1329{
1330 struct qed_iscsi_stats proto_stats;
1331
1332 /* Retrieve FW statistics */
1333 memset(&proto_stats, 0, sizeof(proto_stats));
1334 if (qed_iscsi_stats(cdev, &proto_stats)) {
1335 DP_VERBOSE(cdev, QED_MSG_STORAGE,
1336 "Failed to collect ISCSI statistics\n");
1337 return;
1338 }
1339
1340 /* Translate FW statistics into struct */
1341 stats->rx_pdus = proto_stats.iscsi_rx_total_pdu_cnt;
1342 stats->tx_pdus = proto_stats.iscsi_tx_total_pdu_cnt;
1343 stats->rx_bytes = proto_stats.iscsi_rx_bytes_cnt;
1344 stats->tx_bytes = proto_stats.iscsi_tx_bytes_cnt;
1345}
1346
Yuval Mintzfc831822016-12-01 00:21:06 -08001347static const struct qed_iscsi_ops qed_iscsi_ops_pass = {
1348 .common = &qed_common_ops_pass,
1349 .ll2 = &qed_ll2_ops_pass,
1350 .fill_dev_info = &qed_fill_iscsi_dev_info,
1351 .register_ops = &qed_register_iscsi_ops,
1352 .start = &qed_iscsi_start,
1353 .stop = &qed_iscsi_stop,
1354 .acquire_conn = &qed_iscsi_acquire_conn,
1355 .release_conn = &qed_iscsi_release_conn,
1356 .offload_conn = &qed_iscsi_offload_conn,
1357 .update_conn = &qed_iscsi_update_conn,
1358 .destroy_conn = &qed_iscsi_destroy_conn,
1359 .clear_sq = &qed_iscsi_clear_conn_sq,
1360 .get_stats = &qed_iscsi_stats,
1361};
1362
Arnd Bergmann7729bad2016-12-16 09:47:41 +01001363const struct qed_iscsi_ops *qed_get_iscsi_ops(void)
Yuval Mintzfc831822016-12-01 00:21:06 -08001364{
1365 return &qed_iscsi_ops_pass;
1366}
1367EXPORT_SYMBOL(qed_get_iscsi_ops);
1368
1369void qed_put_iscsi_ops(void)
1370{
1371}
1372EXPORT_SYMBOL(qed_put_iscsi_ops);