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