18c2ecf20Sopenharmony_ci/* 28c2ecf20Sopenharmony_ci * This file is part of the Emulex Linux Device Driver for Enterprise iSCSI 38c2ecf20Sopenharmony_ci * Host Bus Adapters. Refer to the README file included with this package 48c2ecf20Sopenharmony_ci * for driver version and adapter compatibility. 58c2ecf20Sopenharmony_ci * 68c2ecf20Sopenharmony_ci * Copyright (c) 2018 Broadcom. All Rights Reserved. 78c2ecf20Sopenharmony_ci * The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. 88c2ecf20Sopenharmony_ci * 98c2ecf20Sopenharmony_ci * This program is free software; you can redistribute it and/or modify it 108c2ecf20Sopenharmony_ci * under the terms of version 2 of the GNU General Public License as published 118c2ecf20Sopenharmony_ci * by the Free Software Foundation. 128c2ecf20Sopenharmony_ci * 138c2ecf20Sopenharmony_ci * This program is distributed in the hope that it will be useful. ALL EXPRESS 148c2ecf20Sopenharmony_ci * OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY 158c2ecf20Sopenharmony_ci * IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, 168c2ecf20Sopenharmony_ci * OR NON-INFRINGEMENT, ARE DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH 178c2ecf20Sopenharmony_ci * DISCLAIMERS ARE HELD TO BE LEGALLY INVALID. 188c2ecf20Sopenharmony_ci * See the GNU General Public License for more details, a copy of which 198c2ecf20Sopenharmony_ci * can be found in the file COPYING included with this package. 208c2ecf20Sopenharmony_ci * 218c2ecf20Sopenharmony_ci * Contact Information: 228c2ecf20Sopenharmony_ci * linux-drivers@broadcom.com 238c2ecf20Sopenharmony_ci * 248c2ecf20Sopenharmony_ci */ 258c2ecf20Sopenharmony_ci 268c2ecf20Sopenharmony_ci#include <linux/bsg-lib.h> 278c2ecf20Sopenharmony_ci#include <scsi/scsi_transport_iscsi.h> 288c2ecf20Sopenharmony_ci#include <scsi/scsi_bsg_iscsi.h> 298c2ecf20Sopenharmony_ci#include "be_mgmt.h" 308c2ecf20Sopenharmony_ci#include "be_iscsi.h" 318c2ecf20Sopenharmony_ci#include "be_main.h" 328c2ecf20Sopenharmony_ci 338c2ecf20Sopenharmony_ciunsigned int mgmt_vendor_specific_fw_cmd(struct be_ctrl_info *ctrl, 348c2ecf20Sopenharmony_ci struct beiscsi_hba *phba, 358c2ecf20Sopenharmony_ci struct bsg_job *job, 368c2ecf20Sopenharmony_ci struct be_dma_mem *nonemb_cmd) 378c2ecf20Sopenharmony_ci{ 388c2ecf20Sopenharmony_ci struct be_mcc_wrb *wrb; 398c2ecf20Sopenharmony_ci struct be_sge *mcc_sge; 408c2ecf20Sopenharmony_ci unsigned int tag = 0; 418c2ecf20Sopenharmony_ci struct iscsi_bsg_request *bsg_req = job->request; 428c2ecf20Sopenharmony_ci struct be_bsg_vendor_cmd *req = nonemb_cmd->va; 438c2ecf20Sopenharmony_ci unsigned short region, sector_size, sector, offset; 448c2ecf20Sopenharmony_ci 458c2ecf20Sopenharmony_ci nonemb_cmd->size = job->request_payload.payload_len; 468c2ecf20Sopenharmony_ci memset(nonemb_cmd->va, 0, nonemb_cmd->size); 478c2ecf20Sopenharmony_ci region = bsg_req->rqst_data.h_vendor.vendor_cmd[1]; 488c2ecf20Sopenharmony_ci sector_size = bsg_req->rqst_data.h_vendor.vendor_cmd[2]; 498c2ecf20Sopenharmony_ci sector = bsg_req->rqst_data.h_vendor.vendor_cmd[3]; 508c2ecf20Sopenharmony_ci offset = bsg_req->rqst_data.h_vendor.vendor_cmd[4]; 518c2ecf20Sopenharmony_ci req->region = region; 528c2ecf20Sopenharmony_ci req->sector = sector; 538c2ecf20Sopenharmony_ci req->offset = offset; 548c2ecf20Sopenharmony_ci 558c2ecf20Sopenharmony_ci if (mutex_lock_interruptible(&ctrl->mbox_lock)) 568c2ecf20Sopenharmony_ci return 0; 578c2ecf20Sopenharmony_ci switch (bsg_req->rqst_data.h_vendor.vendor_cmd[0]) { 588c2ecf20Sopenharmony_ci case BEISCSI_WRITE_FLASH: 598c2ecf20Sopenharmony_ci offset = sector * sector_size + offset; 608c2ecf20Sopenharmony_ci be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI, 618c2ecf20Sopenharmony_ci OPCODE_COMMON_WRITE_FLASH, sizeof(*req)); 628c2ecf20Sopenharmony_ci sg_copy_to_buffer(job->request_payload.sg_list, 638c2ecf20Sopenharmony_ci job->request_payload.sg_cnt, 648c2ecf20Sopenharmony_ci nonemb_cmd->va + offset, job->request_len); 658c2ecf20Sopenharmony_ci break; 668c2ecf20Sopenharmony_ci case BEISCSI_READ_FLASH: 678c2ecf20Sopenharmony_ci be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI, 688c2ecf20Sopenharmony_ci OPCODE_COMMON_READ_FLASH, sizeof(*req)); 698c2ecf20Sopenharmony_ci break; 708c2ecf20Sopenharmony_ci default: 718c2ecf20Sopenharmony_ci beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_CONFIG, 728c2ecf20Sopenharmony_ci "BG_%d : Unsupported cmd = 0x%x\n\n", 738c2ecf20Sopenharmony_ci bsg_req->rqst_data.h_vendor.vendor_cmd[0]); 748c2ecf20Sopenharmony_ci 758c2ecf20Sopenharmony_ci mutex_unlock(&ctrl->mbox_lock); 768c2ecf20Sopenharmony_ci return -EPERM; 778c2ecf20Sopenharmony_ci } 788c2ecf20Sopenharmony_ci 798c2ecf20Sopenharmony_ci wrb = alloc_mcc_wrb(phba, &tag); 808c2ecf20Sopenharmony_ci if (!wrb) { 818c2ecf20Sopenharmony_ci mutex_unlock(&ctrl->mbox_lock); 828c2ecf20Sopenharmony_ci return 0; 838c2ecf20Sopenharmony_ci } 848c2ecf20Sopenharmony_ci 858c2ecf20Sopenharmony_ci mcc_sge = nonembedded_sgl(wrb); 868c2ecf20Sopenharmony_ci be_wrb_hdr_prepare(wrb, nonemb_cmd->size, false, 878c2ecf20Sopenharmony_ci job->request_payload.sg_cnt); 888c2ecf20Sopenharmony_ci mcc_sge->pa_hi = cpu_to_le32(upper_32_bits(nonemb_cmd->dma)); 898c2ecf20Sopenharmony_ci mcc_sge->pa_lo = cpu_to_le32(nonemb_cmd->dma & 0xFFFFFFFF); 908c2ecf20Sopenharmony_ci mcc_sge->len = cpu_to_le32(nonemb_cmd->size); 918c2ecf20Sopenharmony_ci 928c2ecf20Sopenharmony_ci be_mcc_notify(phba, tag); 938c2ecf20Sopenharmony_ci 948c2ecf20Sopenharmony_ci mutex_unlock(&ctrl->mbox_lock); 958c2ecf20Sopenharmony_ci return tag; 968c2ecf20Sopenharmony_ci} 978c2ecf20Sopenharmony_ci 988c2ecf20Sopenharmony_ci/** 998c2ecf20Sopenharmony_ci * mgmt_open_connection()- Establish a TCP CXN 1008c2ecf20Sopenharmony_ci * @phba: driver priv structure 1018c2ecf20Sopenharmony_ci * @dst_addr: Destination Address 1028c2ecf20Sopenharmony_ci * @beiscsi_ep: ptr to device endpoint struct 1038c2ecf20Sopenharmony_ci * @nonemb_cmd: ptr to memory allocated for command 1048c2ecf20Sopenharmony_ci * 1058c2ecf20Sopenharmony_ci * return 1068c2ecf20Sopenharmony_ci * Success: Tag number of the MBX Command issued 1078c2ecf20Sopenharmony_ci * Failure: Error code 1088c2ecf20Sopenharmony_ci **/ 1098c2ecf20Sopenharmony_ciint mgmt_open_connection(struct beiscsi_hba *phba, 1108c2ecf20Sopenharmony_ci struct sockaddr *dst_addr, 1118c2ecf20Sopenharmony_ci struct beiscsi_endpoint *beiscsi_ep, 1128c2ecf20Sopenharmony_ci struct be_dma_mem *nonemb_cmd) 1138c2ecf20Sopenharmony_ci{ 1148c2ecf20Sopenharmony_ci struct hwi_controller *phwi_ctrlr; 1158c2ecf20Sopenharmony_ci struct hwi_context_memory *phwi_context; 1168c2ecf20Sopenharmony_ci struct sockaddr_in *daddr_in = (struct sockaddr_in *)dst_addr; 1178c2ecf20Sopenharmony_ci struct sockaddr_in6 *daddr_in6 = (struct sockaddr_in6 *)dst_addr; 1188c2ecf20Sopenharmony_ci struct be_ctrl_info *ctrl = &phba->ctrl; 1198c2ecf20Sopenharmony_ci struct be_mcc_wrb *wrb; 1208c2ecf20Sopenharmony_ci struct tcp_connect_and_offload_in_v1 *req; 1218c2ecf20Sopenharmony_ci unsigned short def_hdr_id; 1228c2ecf20Sopenharmony_ci unsigned short def_data_id; 1238c2ecf20Sopenharmony_ci struct phys_addr template_address = { 0, 0 }; 1248c2ecf20Sopenharmony_ci struct phys_addr *ptemplate_address; 1258c2ecf20Sopenharmony_ci unsigned int tag = 0; 1268c2ecf20Sopenharmony_ci unsigned int i, ulp_num; 1278c2ecf20Sopenharmony_ci unsigned short cid = beiscsi_ep->ep_cid; 1288c2ecf20Sopenharmony_ci struct be_sge *sge; 1298c2ecf20Sopenharmony_ci 1308c2ecf20Sopenharmony_ci if (dst_addr->sa_family != PF_INET && dst_addr->sa_family != PF_INET6) { 1318c2ecf20Sopenharmony_ci beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG, 1328c2ecf20Sopenharmony_ci "BG_%d : unknown addr family %d\n", 1338c2ecf20Sopenharmony_ci dst_addr->sa_family); 1348c2ecf20Sopenharmony_ci return 0; 1358c2ecf20Sopenharmony_ci } 1368c2ecf20Sopenharmony_ci 1378c2ecf20Sopenharmony_ci phwi_ctrlr = phba->phwi_ctrlr; 1388c2ecf20Sopenharmony_ci phwi_context = phwi_ctrlr->phwi_ctxt; 1398c2ecf20Sopenharmony_ci 1408c2ecf20Sopenharmony_ci ulp_num = phwi_ctrlr->wrb_context[BE_GET_CRI_FROM_CID(cid)].ulp_num; 1418c2ecf20Sopenharmony_ci 1428c2ecf20Sopenharmony_ci def_hdr_id = (unsigned short)HWI_GET_DEF_HDRQ_ID(phba, ulp_num); 1438c2ecf20Sopenharmony_ci def_data_id = (unsigned short)HWI_GET_DEF_BUFQ_ID(phba, ulp_num); 1448c2ecf20Sopenharmony_ci 1458c2ecf20Sopenharmony_ci ptemplate_address = &template_address; 1468c2ecf20Sopenharmony_ci ISCSI_GET_PDU_TEMPLATE_ADDRESS(phba, ptemplate_address); 1478c2ecf20Sopenharmony_ci if (mutex_lock_interruptible(&ctrl->mbox_lock)) 1488c2ecf20Sopenharmony_ci return 0; 1498c2ecf20Sopenharmony_ci wrb = alloc_mcc_wrb(phba, &tag); 1508c2ecf20Sopenharmony_ci if (!wrb) { 1518c2ecf20Sopenharmony_ci mutex_unlock(&ctrl->mbox_lock); 1528c2ecf20Sopenharmony_ci return 0; 1538c2ecf20Sopenharmony_ci } 1548c2ecf20Sopenharmony_ci 1558c2ecf20Sopenharmony_ci sge = nonembedded_sgl(wrb); 1568c2ecf20Sopenharmony_ci req = nonemb_cmd->va; 1578c2ecf20Sopenharmony_ci memset(req, 0, sizeof(*req)); 1588c2ecf20Sopenharmony_ci 1598c2ecf20Sopenharmony_ci be_wrb_hdr_prepare(wrb, nonemb_cmd->size, false, 1); 1608c2ecf20Sopenharmony_ci be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI, 1618c2ecf20Sopenharmony_ci OPCODE_COMMON_ISCSI_TCP_CONNECT_AND_OFFLOAD, 1628c2ecf20Sopenharmony_ci nonemb_cmd->size); 1638c2ecf20Sopenharmony_ci if (dst_addr->sa_family == PF_INET) { 1648c2ecf20Sopenharmony_ci __be32 s_addr = daddr_in->sin_addr.s_addr; 1658c2ecf20Sopenharmony_ci req->ip_address.ip_type = BEISCSI_IP_TYPE_V4; 1668c2ecf20Sopenharmony_ci req->ip_address.addr[0] = s_addr & 0x000000ff; 1678c2ecf20Sopenharmony_ci req->ip_address.addr[1] = (s_addr & 0x0000ff00) >> 8; 1688c2ecf20Sopenharmony_ci req->ip_address.addr[2] = (s_addr & 0x00ff0000) >> 16; 1698c2ecf20Sopenharmony_ci req->ip_address.addr[3] = (s_addr & 0xff000000) >> 24; 1708c2ecf20Sopenharmony_ci req->tcp_port = ntohs(daddr_in->sin_port); 1718c2ecf20Sopenharmony_ci beiscsi_ep->dst_addr = daddr_in->sin_addr.s_addr; 1728c2ecf20Sopenharmony_ci beiscsi_ep->dst_tcpport = ntohs(daddr_in->sin_port); 1738c2ecf20Sopenharmony_ci beiscsi_ep->ip_type = BEISCSI_IP_TYPE_V4; 1748c2ecf20Sopenharmony_ci } else { 1758c2ecf20Sopenharmony_ci /* else its PF_INET6 family */ 1768c2ecf20Sopenharmony_ci req->ip_address.ip_type = BEISCSI_IP_TYPE_V6; 1778c2ecf20Sopenharmony_ci memcpy(&req->ip_address.addr, 1788c2ecf20Sopenharmony_ci &daddr_in6->sin6_addr.in6_u.u6_addr8, 16); 1798c2ecf20Sopenharmony_ci req->tcp_port = ntohs(daddr_in6->sin6_port); 1808c2ecf20Sopenharmony_ci beiscsi_ep->dst_tcpport = ntohs(daddr_in6->sin6_port); 1818c2ecf20Sopenharmony_ci memcpy(&beiscsi_ep->dst6_addr, 1828c2ecf20Sopenharmony_ci &daddr_in6->sin6_addr.in6_u.u6_addr8, 16); 1838c2ecf20Sopenharmony_ci beiscsi_ep->ip_type = BEISCSI_IP_TYPE_V6; 1848c2ecf20Sopenharmony_ci } 1858c2ecf20Sopenharmony_ci req->cid = cid; 1868c2ecf20Sopenharmony_ci i = phba->nxt_cqid++; 1878c2ecf20Sopenharmony_ci if (phba->nxt_cqid == phba->num_cpus) 1888c2ecf20Sopenharmony_ci phba->nxt_cqid = 0; 1898c2ecf20Sopenharmony_ci req->cq_id = phwi_context->be_cq[i].id; 1908c2ecf20Sopenharmony_ci beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_CONFIG, 1918c2ecf20Sopenharmony_ci "BG_%d : i=%d cq_id=%d\n", i, req->cq_id); 1928c2ecf20Sopenharmony_ci req->defq_id = def_hdr_id; 1938c2ecf20Sopenharmony_ci req->hdr_ring_id = def_hdr_id; 1948c2ecf20Sopenharmony_ci req->data_ring_id = def_data_id; 1958c2ecf20Sopenharmony_ci req->do_offload = 1; 1968c2ecf20Sopenharmony_ci req->dataout_template_pa.lo = ptemplate_address->lo; 1978c2ecf20Sopenharmony_ci req->dataout_template_pa.hi = ptemplate_address->hi; 1988c2ecf20Sopenharmony_ci sge->pa_hi = cpu_to_le32(upper_32_bits(nonemb_cmd->dma)); 1998c2ecf20Sopenharmony_ci sge->pa_lo = cpu_to_le32(nonemb_cmd->dma & 0xFFFFFFFF); 2008c2ecf20Sopenharmony_ci sge->len = cpu_to_le32(nonemb_cmd->size); 2018c2ecf20Sopenharmony_ci 2028c2ecf20Sopenharmony_ci if (!is_chip_be2_be3r(phba)) { 2038c2ecf20Sopenharmony_ci req->hdr.version = MBX_CMD_VER1; 2048c2ecf20Sopenharmony_ci req->tcp_window_size = 0x8000; 2058c2ecf20Sopenharmony_ci req->tcp_window_scale_count = 2; 2068c2ecf20Sopenharmony_ci } 2078c2ecf20Sopenharmony_ci 2088c2ecf20Sopenharmony_ci be_mcc_notify(phba, tag); 2098c2ecf20Sopenharmony_ci mutex_unlock(&ctrl->mbox_lock); 2108c2ecf20Sopenharmony_ci return tag; 2118c2ecf20Sopenharmony_ci} 2128c2ecf20Sopenharmony_ci 2138c2ecf20Sopenharmony_ci/** 2148c2ecf20Sopenharmony_ci * beiscsi_exec_nemb_cmd()- execute non-embedded MBX cmd 2158c2ecf20Sopenharmony_ci * @phba: driver priv structure 2168c2ecf20Sopenharmony_ci * @nonemb_cmd: DMA address of the MBX command to be issued 2178c2ecf20Sopenharmony_ci * @cbfn: callback func on MCC completion 2188c2ecf20Sopenharmony_ci * @resp_buf: buffer to copy the MBX cmd response 2198c2ecf20Sopenharmony_ci * @resp_buf_len: response length to be copied 2208c2ecf20Sopenharmony_ci * 2218c2ecf20Sopenharmony_ci **/ 2228c2ecf20Sopenharmony_cistatic int beiscsi_exec_nemb_cmd(struct beiscsi_hba *phba, 2238c2ecf20Sopenharmony_ci struct be_dma_mem *nonemb_cmd, 2248c2ecf20Sopenharmony_ci void (*cbfn)(struct beiscsi_hba *, 2258c2ecf20Sopenharmony_ci unsigned int), 2268c2ecf20Sopenharmony_ci void *resp_buf, u32 resp_buf_len) 2278c2ecf20Sopenharmony_ci{ 2288c2ecf20Sopenharmony_ci struct be_ctrl_info *ctrl = &phba->ctrl; 2298c2ecf20Sopenharmony_ci struct be_mcc_wrb *wrb; 2308c2ecf20Sopenharmony_ci struct be_sge *sge; 2318c2ecf20Sopenharmony_ci unsigned int tag; 2328c2ecf20Sopenharmony_ci int rc = 0; 2338c2ecf20Sopenharmony_ci 2348c2ecf20Sopenharmony_ci mutex_lock(&ctrl->mbox_lock); 2358c2ecf20Sopenharmony_ci wrb = alloc_mcc_wrb(phba, &tag); 2368c2ecf20Sopenharmony_ci if (!wrb) { 2378c2ecf20Sopenharmony_ci mutex_unlock(&ctrl->mbox_lock); 2388c2ecf20Sopenharmony_ci rc = -ENOMEM; 2398c2ecf20Sopenharmony_ci goto free_cmd; 2408c2ecf20Sopenharmony_ci } 2418c2ecf20Sopenharmony_ci 2428c2ecf20Sopenharmony_ci sge = nonembedded_sgl(wrb); 2438c2ecf20Sopenharmony_ci be_wrb_hdr_prepare(wrb, nonemb_cmd->size, false, 1); 2448c2ecf20Sopenharmony_ci sge->pa_hi = cpu_to_le32(upper_32_bits(nonemb_cmd->dma)); 2458c2ecf20Sopenharmony_ci sge->pa_lo = cpu_to_le32(lower_32_bits(nonemb_cmd->dma)); 2468c2ecf20Sopenharmony_ci sge->len = cpu_to_le32(nonemb_cmd->size); 2478c2ecf20Sopenharmony_ci 2488c2ecf20Sopenharmony_ci if (cbfn) { 2498c2ecf20Sopenharmony_ci struct be_dma_mem *tag_mem; 2508c2ecf20Sopenharmony_ci 2518c2ecf20Sopenharmony_ci set_bit(MCC_TAG_STATE_ASYNC, &ctrl->ptag_state[tag].tag_state); 2528c2ecf20Sopenharmony_ci ctrl->ptag_state[tag].cbfn = cbfn; 2538c2ecf20Sopenharmony_ci tag_mem = &phba->ctrl.ptag_state[tag].tag_mem_state; 2548c2ecf20Sopenharmony_ci 2558c2ecf20Sopenharmony_ci /* store DMA mem to be freed in callback */ 2568c2ecf20Sopenharmony_ci tag_mem->size = nonemb_cmd->size; 2578c2ecf20Sopenharmony_ci tag_mem->va = nonemb_cmd->va; 2588c2ecf20Sopenharmony_ci tag_mem->dma = nonemb_cmd->dma; 2598c2ecf20Sopenharmony_ci } 2608c2ecf20Sopenharmony_ci be_mcc_notify(phba, tag); 2618c2ecf20Sopenharmony_ci mutex_unlock(&ctrl->mbox_lock); 2628c2ecf20Sopenharmony_ci 2638c2ecf20Sopenharmony_ci /* with cbfn set, its async cmd, don't wait */ 2648c2ecf20Sopenharmony_ci if (cbfn) 2658c2ecf20Sopenharmony_ci return 0; 2668c2ecf20Sopenharmony_ci 2678c2ecf20Sopenharmony_ci rc = beiscsi_mccq_compl_wait(phba, tag, NULL, nonemb_cmd); 2688c2ecf20Sopenharmony_ci 2698c2ecf20Sopenharmony_ci /* copy the response, if any */ 2708c2ecf20Sopenharmony_ci if (resp_buf) 2718c2ecf20Sopenharmony_ci memcpy(resp_buf, nonemb_cmd->va, resp_buf_len); 2728c2ecf20Sopenharmony_ci /** 2738c2ecf20Sopenharmony_ci * This is special case of NTWK_GET_IF_INFO where the size of 2748c2ecf20Sopenharmony_ci * response is not known. beiscsi_if_get_info checks the return 2758c2ecf20Sopenharmony_ci * value to free DMA buffer. 2768c2ecf20Sopenharmony_ci */ 2778c2ecf20Sopenharmony_ci if (rc == -EAGAIN) 2788c2ecf20Sopenharmony_ci return rc; 2798c2ecf20Sopenharmony_ci 2808c2ecf20Sopenharmony_ci /** 2818c2ecf20Sopenharmony_ci * If FW is busy that is driver timed out, DMA buffer is saved with 2828c2ecf20Sopenharmony_ci * the tag, only when the cmd completes this buffer is freed. 2838c2ecf20Sopenharmony_ci */ 2848c2ecf20Sopenharmony_ci if (rc == -EBUSY) 2858c2ecf20Sopenharmony_ci return rc; 2868c2ecf20Sopenharmony_ci 2878c2ecf20Sopenharmony_cifree_cmd: 2888c2ecf20Sopenharmony_ci dma_free_coherent(&ctrl->pdev->dev, nonemb_cmd->size, 2898c2ecf20Sopenharmony_ci nonemb_cmd->va, nonemb_cmd->dma); 2908c2ecf20Sopenharmony_ci return rc; 2918c2ecf20Sopenharmony_ci} 2928c2ecf20Sopenharmony_ci 2938c2ecf20Sopenharmony_cistatic int beiscsi_prep_nemb_cmd(struct beiscsi_hba *phba, 2948c2ecf20Sopenharmony_ci struct be_dma_mem *cmd, 2958c2ecf20Sopenharmony_ci u8 subsystem, u8 opcode, u32 size) 2968c2ecf20Sopenharmony_ci{ 2978c2ecf20Sopenharmony_ci cmd->va = dma_alloc_coherent(&phba->ctrl.pdev->dev, size, &cmd->dma, 2988c2ecf20Sopenharmony_ci GFP_KERNEL); 2998c2ecf20Sopenharmony_ci if (!cmd->va) { 3008c2ecf20Sopenharmony_ci beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG, 3018c2ecf20Sopenharmony_ci "BG_%d : Failed to allocate memory for if info\n"); 3028c2ecf20Sopenharmony_ci return -ENOMEM; 3038c2ecf20Sopenharmony_ci } 3048c2ecf20Sopenharmony_ci cmd->size = size; 3058c2ecf20Sopenharmony_ci be_cmd_hdr_prepare(cmd->va, subsystem, opcode, size); 3068c2ecf20Sopenharmony_ci beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_CONFIG, 3078c2ecf20Sopenharmony_ci "BG_%d : subsystem %u cmd %u size %u\n", 3088c2ecf20Sopenharmony_ci subsystem, opcode, size); 3098c2ecf20Sopenharmony_ci return 0; 3108c2ecf20Sopenharmony_ci} 3118c2ecf20Sopenharmony_ci 3128c2ecf20Sopenharmony_cistatic void __beiscsi_eq_delay_compl(struct beiscsi_hba *phba, unsigned int tag) 3138c2ecf20Sopenharmony_ci{ 3148c2ecf20Sopenharmony_ci struct be_dma_mem *tag_mem; 3158c2ecf20Sopenharmony_ci 3168c2ecf20Sopenharmony_ci /* status is ignored */ 3178c2ecf20Sopenharmony_ci __beiscsi_mcc_compl_status(phba, tag, NULL, NULL); 3188c2ecf20Sopenharmony_ci tag_mem = &phba->ctrl.ptag_state[tag].tag_mem_state; 3198c2ecf20Sopenharmony_ci if (tag_mem->size) { 3208c2ecf20Sopenharmony_ci dma_free_coherent(&phba->pcidev->dev, tag_mem->size, 3218c2ecf20Sopenharmony_ci tag_mem->va, tag_mem->dma); 3228c2ecf20Sopenharmony_ci tag_mem->size = 0; 3238c2ecf20Sopenharmony_ci } 3248c2ecf20Sopenharmony_ci} 3258c2ecf20Sopenharmony_ci 3268c2ecf20Sopenharmony_ciint beiscsi_modify_eq_delay(struct beiscsi_hba *phba, 3278c2ecf20Sopenharmony_ci struct be_set_eqd *set_eqd, int num) 3288c2ecf20Sopenharmony_ci{ 3298c2ecf20Sopenharmony_ci struct be_cmd_req_modify_eq_delay *req; 3308c2ecf20Sopenharmony_ci struct be_dma_mem nonemb_cmd; 3318c2ecf20Sopenharmony_ci int i, rc; 3328c2ecf20Sopenharmony_ci 3338c2ecf20Sopenharmony_ci rc = beiscsi_prep_nemb_cmd(phba, &nonemb_cmd, CMD_SUBSYSTEM_COMMON, 3348c2ecf20Sopenharmony_ci OPCODE_COMMON_MODIFY_EQ_DELAY, sizeof(*req)); 3358c2ecf20Sopenharmony_ci if (rc) 3368c2ecf20Sopenharmony_ci return rc; 3378c2ecf20Sopenharmony_ci 3388c2ecf20Sopenharmony_ci req = nonemb_cmd.va; 3398c2ecf20Sopenharmony_ci req->num_eq = cpu_to_le32(num); 3408c2ecf20Sopenharmony_ci for (i = 0; i < num; i++) { 3418c2ecf20Sopenharmony_ci req->delay[i].eq_id = cpu_to_le32(set_eqd[i].eq_id); 3428c2ecf20Sopenharmony_ci req->delay[i].phase = 0; 3438c2ecf20Sopenharmony_ci req->delay[i].delay_multiplier = 3448c2ecf20Sopenharmony_ci cpu_to_le32(set_eqd[i].delay_multiplier); 3458c2ecf20Sopenharmony_ci } 3468c2ecf20Sopenharmony_ci 3478c2ecf20Sopenharmony_ci return beiscsi_exec_nemb_cmd(phba, &nonemb_cmd, 3488c2ecf20Sopenharmony_ci __beiscsi_eq_delay_compl, NULL, 0); 3498c2ecf20Sopenharmony_ci} 3508c2ecf20Sopenharmony_ci 3518c2ecf20Sopenharmony_ci/** 3528c2ecf20Sopenharmony_ci * beiscsi_get_initiator_name - read initiator name from flash 3538c2ecf20Sopenharmony_ci * @phba: device priv structure 3548c2ecf20Sopenharmony_ci * @name: buffer pointer 3558c2ecf20Sopenharmony_ci * @cfg: fetch user configured 3568c2ecf20Sopenharmony_ci * 3578c2ecf20Sopenharmony_ci */ 3588c2ecf20Sopenharmony_ciint beiscsi_get_initiator_name(struct beiscsi_hba *phba, char *name, bool cfg) 3598c2ecf20Sopenharmony_ci{ 3608c2ecf20Sopenharmony_ci struct be_dma_mem nonemb_cmd; 3618c2ecf20Sopenharmony_ci struct be_cmd_hba_name resp; 3628c2ecf20Sopenharmony_ci struct be_cmd_hba_name *req; 3638c2ecf20Sopenharmony_ci int rc; 3648c2ecf20Sopenharmony_ci 3658c2ecf20Sopenharmony_ci rc = beiscsi_prep_nemb_cmd(phba, &nonemb_cmd, CMD_SUBSYSTEM_ISCSI_INI, 3668c2ecf20Sopenharmony_ci OPCODE_ISCSI_INI_CFG_GET_HBA_NAME, sizeof(resp)); 3678c2ecf20Sopenharmony_ci if (rc) 3688c2ecf20Sopenharmony_ci return rc; 3698c2ecf20Sopenharmony_ci 3708c2ecf20Sopenharmony_ci req = nonemb_cmd.va; 3718c2ecf20Sopenharmony_ci if (cfg) 3728c2ecf20Sopenharmony_ci req->hdr.version = 1; 3738c2ecf20Sopenharmony_ci rc = beiscsi_exec_nemb_cmd(phba, &nonemb_cmd, NULL, 3748c2ecf20Sopenharmony_ci &resp, sizeof(resp)); 3758c2ecf20Sopenharmony_ci if (rc) { 3768c2ecf20Sopenharmony_ci beiscsi_log(phba, KERN_ERR, 3778c2ecf20Sopenharmony_ci BEISCSI_LOG_CONFIG | BEISCSI_LOG_MBOX, 3788c2ecf20Sopenharmony_ci "BS_%d : Initiator Name MBX Failed\n"); 3798c2ecf20Sopenharmony_ci return rc; 3808c2ecf20Sopenharmony_ci } 3818c2ecf20Sopenharmony_ci rc = sprintf(name, "%s\n", resp.initiator_name); 3828c2ecf20Sopenharmony_ci return rc; 3838c2ecf20Sopenharmony_ci} 3848c2ecf20Sopenharmony_ci 3858c2ecf20Sopenharmony_ciunsigned int beiscsi_if_get_handle(struct beiscsi_hba *phba) 3868c2ecf20Sopenharmony_ci{ 3878c2ecf20Sopenharmony_ci struct be_ctrl_info *ctrl = &phba->ctrl; 3888c2ecf20Sopenharmony_ci struct be_mcc_wrb *wrb; 3898c2ecf20Sopenharmony_ci struct be_cmd_get_all_if_id_req *req; 3908c2ecf20Sopenharmony_ci struct be_cmd_get_all_if_id_req *pbe_allid; 3918c2ecf20Sopenharmony_ci unsigned int tag; 3928c2ecf20Sopenharmony_ci int status = 0; 3938c2ecf20Sopenharmony_ci 3948c2ecf20Sopenharmony_ci if (mutex_lock_interruptible(&ctrl->mbox_lock)) 3958c2ecf20Sopenharmony_ci return -EINTR; 3968c2ecf20Sopenharmony_ci wrb = alloc_mcc_wrb(phba, &tag); 3978c2ecf20Sopenharmony_ci if (!wrb) { 3988c2ecf20Sopenharmony_ci mutex_unlock(&ctrl->mbox_lock); 3998c2ecf20Sopenharmony_ci return -ENOMEM; 4008c2ecf20Sopenharmony_ci } 4018c2ecf20Sopenharmony_ci 4028c2ecf20Sopenharmony_ci req = embedded_payload(wrb); 4038c2ecf20Sopenharmony_ci be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0); 4048c2ecf20Sopenharmony_ci be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI, 4058c2ecf20Sopenharmony_ci OPCODE_COMMON_ISCSI_NTWK_GET_ALL_IF_ID, 4068c2ecf20Sopenharmony_ci sizeof(*req)); 4078c2ecf20Sopenharmony_ci be_mcc_notify(phba, tag); 4088c2ecf20Sopenharmony_ci mutex_unlock(&ctrl->mbox_lock); 4098c2ecf20Sopenharmony_ci 4108c2ecf20Sopenharmony_ci status = beiscsi_mccq_compl_wait(phba, tag, &wrb, NULL); 4118c2ecf20Sopenharmony_ci if (status) { 4128c2ecf20Sopenharmony_ci beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_CONFIG, 4138c2ecf20Sopenharmony_ci "BG_%d : %s failed: %d\n", __func__, status); 4148c2ecf20Sopenharmony_ci return -EBUSY; 4158c2ecf20Sopenharmony_ci } 4168c2ecf20Sopenharmony_ci 4178c2ecf20Sopenharmony_ci pbe_allid = embedded_payload(wrb); 4188c2ecf20Sopenharmony_ci /* we now support only one interface per function */ 4198c2ecf20Sopenharmony_ci phba->interface_handle = pbe_allid->if_hndl_list[0]; 4208c2ecf20Sopenharmony_ci 4218c2ecf20Sopenharmony_ci return status; 4228c2ecf20Sopenharmony_ci} 4238c2ecf20Sopenharmony_ci 4248c2ecf20Sopenharmony_cistatic inline bool beiscsi_if_zero_ip(u8 *ip, u32 ip_type) 4258c2ecf20Sopenharmony_ci{ 4268c2ecf20Sopenharmony_ci u32 len; 4278c2ecf20Sopenharmony_ci 4288c2ecf20Sopenharmony_ci len = (ip_type < BEISCSI_IP_TYPE_V6) ? IP_V4_LEN : IP_V6_LEN; 4298c2ecf20Sopenharmony_ci while (len && !ip[len - 1]) 4308c2ecf20Sopenharmony_ci len--; 4318c2ecf20Sopenharmony_ci return (len == 0); 4328c2ecf20Sopenharmony_ci} 4338c2ecf20Sopenharmony_ci 4348c2ecf20Sopenharmony_cistatic int beiscsi_if_mod_gw(struct beiscsi_hba *phba, 4358c2ecf20Sopenharmony_ci u32 action, u32 ip_type, u8 *gw) 4368c2ecf20Sopenharmony_ci{ 4378c2ecf20Sopenharmony_ci struct be_cmd_set_def_gateway_req *req; 4388c2ecf20Sopenharmony_ci struct be_dma_mem nonemb_cmd; 4398c2ecf20Sopenharmony_ci int rt_val; 4408c2ecf20Sopenharmony_ci 4418c2ecf20Sopenharmony_ci rt_val = beiscsi_prep_nemb_cmd(phba, &nonemb_cmd, CMD_SUBSYSTEM_ISCSI, 4428c2ecf20Sopenharmony_ci OPCODE_COMMON_ISCSI_NTWK_MODIFY_DEFAULT_GATEWAY, 4438c2ecf20Sopenharmony_ci sizeof(*req)); 4448c2ecf20Sopenharmony_ci if (rt_val) 4458c2ecf20Sopenharmony_ci return rt_val; 4468c2ecf20Sopenharmony_ci 4478c2ecf20Sopenharmony_ci req = nonemb_cmd.va; 4488c2ecf20Sopenharmony_ci req->action = action; 4498c2ecf20Sopenharmony_ci req->ip_addr.ip_type = ip_type; 4508c2ecf20Sopenharmony_ci memcpy(req->ip_addr.addr, gw, 4518c2ecf20Sopenharmony_ci (ip_type < BEISCSI_IP_TYPE_V6) ? IP_V4_LEN : IP_V6_LEN); 4528c2ecf20Sopenharmony_ci return beiscsi_exec_nemb_cmd(phba, &nonemb_cmd, NULL, NULL, 0); 4538c2ecf20Sopenharmony_ci} 4548c2ecf20Sopenharmony_ci 4558c2ecf20Sopenharmony_ciint beiscsi_if_set_gw(struct beiscsi_hba *phba, u32 ip_type, u8 *gw) 4568c2ecf20Sopenharmony_ci{ 4578c2ecf20Sopenharmony_ci struct be_cmd_get_def_gateway_resp gw_resp; 4588c2ecf20Sopenharmony_ci int rt_val; 4598c2ecf20Sopenharmony_ci 4608c2ecf20Sopenharmony_ci memset(&gw_resp, 0, sizeof(gw_resp)); 4618c2ecf20Sopenharmony_ci rt_val = beiscsi_if_get_gw(phba, ip_type, &gw_resp); 4628c2ecf20Sopenharmony_ci if (rt_val) { 4638c2ecf20Sopenharmony_ci beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_CONFIG, 4648c2ecf20Sopenharmony_ci "BG_%d : Failed to Get Gateway Addr\n"); 4658c2ecf20Sopenharmony_ci return rt_val; 4668c2ecf20Sopenharmony_ci } 4678c2ecf20Sopenharmony_ci 4688c2ecf20Sopenharmony_ci if (!beiscsi_if_zero_ip(gw_resp.ip_addr.addr, ip_type)) { 4698c2ecf20Sopenharmony_ci rt_val = beiscsi_if_mod_gw(phba, IP_ACTION_DEL, ip_type, 4708c2ecf20Sopenharmony_ci gw_resp.ip_addr.addr); 4718c2ecf20Sopenharmony_ci if (rt_val) { 4728c2ecf20Sopenharmony_ci beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_CONFIG, 4738c2ecf20Sopenharmony_ci "BG_%d : Failed to clear Gateway Addr Set\n"); 4748c2ecf20Sopenharmony_ci return rt_val; 4758c2ecf20Sopenharmony_ci } 4768c2ecf20Sopenharmony_ci } 4778c2ecf20Sopenharmony_ci 4788c2ecf20Sopenharmony_ci rt_val = beiscsi_if_mod_gw(phba, IP_ACTION_ADD, ip_type, gw); 4798c2ecf20Sopenharmony_ci if (rt_val) 4808c2ecf20Sopenharmony_ci beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_CONFIG, 4818c2ecf20Sopenharmony_ci "BG_%d : Failed to Set Gateway Addr\n"); 4828c2ecf20Sopenharmony_ci 4838c2ecf20Sopenharmony_ci return rt_val; 4848c2ecf20Sopenharmony_ci} 4858c2ecf20Sopenharmony_ci 4868c2ecf20Sopenharmony_ciint beiscsi_if_get_gw(struct beiscsi_hba *phba, u32 ip_type, 4878c2ecf20Sopenharmony_ci struct be_cmd_get_def_gateway_resp *resp) 4888c2ecf20Sopenharmony_ci{ 4898c2ecf20Sopenharmony_ci struct be_cmd_get_def_gateway_req *req; 4908c2ecf20Sopenharmony_ci struct be_dma_mem nonemb_cmd; 4918c2ecf20Sopenharmony_ci int rc; 4928c2ecf20Sopenharmony_ci 4938c2ecf20Sopenharmony_ci rc = beiscsi_prep_nemb_cmd(phba, &nonemb_cmd, CMD_SUBSYSTEM_ISCSI, 4948c2ecf20Sopenharmony_ci OPCODE_COMMON_ISCSI_NTWK_GET_DEFAULT_GATEWAY, 4958c2ecf20Sopenharmony_ci sizeof(*resp)); 4968c2ecf20Sopenharmony_ci if (rc) 4978c2ecf20Sopenharmony_ci return rc; 4988c2ecf20Sopenharmony_ci 4998c2ecf20Sopenharmony_ci req = nonemb_cmd.va; 5008c2ecf20Sopenharmony_ci req->ip_type = ip_type; 5018c2ecf20Sopenharmony_ci 5028c2ecf20Sopenharmony_ci return beiscsi_exec_nemb_cmd(phba, &nonemb_cmd, NULL, 5038c2ecf20Sopenharmony_ci resp, sizeof(*resp)); 5048c2ecf20Sopenharmony_ci} 5058c2ecf20Sopenharmony_ci 5068c2ecf20Sopenharmony_cistatic int 5078c2ecf20Sopenharmony_cibeiscsi_if_clr_ip(struct beiscsi_hba *phba, 5088c2ecf20Sopenharmony_ci struct be_cmd_get_if_info_resp *if_info) 5098c2ecf20Sopenharmony_ci{ 5108c2ecf20Sopenharmony_ci struct be_cmd_set_ip_addr_req *req; 5118c2ecf20Sopenharmony_ci struct be_dma_mem nonemb_cmd; 5128c2ecf20Sopenharmony_ci int rc; 5138c2ecf20Sopenharmony_ci 5148c2ecf20Sopenharmony_ci rc = beiscsi_prep_nemb_cmd(phba, &nonemb_cmd, CMD_SUBSYSTEM_ISCSI, 5158c2ecf20Sopenharmony_ci OPCODE_COMMON_ISCSI_NTWK_MODIFY_IP_ADDR, 5168c2ecf20Sopenharmony_ci sizeof(*req)); 5178c2ecf20Sopenharmony_ci if (rc) 5188c2ecf20Sopenharmony_ci return rc; 5198c2ecf20Sopenharmony_ci 5208c2ecf20Sopenharmony_ci req = nonemb_cmd.va; 5218c2ecf20Sopenharmony_ci req->ip_params.record_entry_count = 1; 5228c2ecf20Sopenharmony_ci req->ip_params.ip_record.action = IP_ACTION_DEL; 5238c2ecf20Sopenharmony_ci req->ip_params.ip_record.interface_hndl = 5248c2ecf20Sopenharmony_ci phba->interface_handle; 5258c2ecf20Sopenharmony_ci req->ip_params.ip_record.ip_addr.size_of_structure = 5268c2ecf20Sopenharmony_ci sizeof(struct be_ip_addr_subnet_format); 5278c2ecf20Sopenharmony_ci req->ip_params.ip_record.ip_addr.ip_type = if_info->ip_addr.ip_type; 5288c2ecf20Sopenharmony_ci memcpy(req->ip_params.ip_record.ip_addr.addr, 5298c2ecf20Sopenharmony_ci if_info->ip_addr.addr, 5308c2ecf20Sopenharmony_ci sizeof(if_info->ip_addr.addr)); 5318c2ecf20Sopenharmony_ci memcpy(req->ip_params.ip_record.ip_addr.subnet_mask, 5328c2ecf20Sopenharmony_ci if_info->ip_addr.subnet_mask, 5338c2ecf20Sopenharmony_ci sizeof(if_info->ip_addr.subnet_mask)); 5348c2ecf20Sopenharmony_ci rc = beiscsi_exec_nemb_cmd(phba, &nonemb_cmd, NULL, NULL, 0); 5358c2ecf20Sopenharmony_ci if (rc < 0 || req->ip_params.ip_record.status) { 5368c2ecf20Sopenharmony_ci beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_CONFIG, 5378c2ecf20Sopenharmony_ci "BG_%d : failed to clear IP: rc %d status %d\n", 5388c2ecf20Sopenharmony_ci rc, req->ip_params.ip_record.status); 5398c2ecf20Sopenharmony_ci } 5408c2ecf20Sopenharmony_ci return rc; 5418c2ecf20Sopenharmony_ci} 5428c2ecf20Sopenharmony_ci 5438c2ecf20Sopenharmony_cistatic int 5448c2ecf20Sopenharmony_cibeiscsi_if_set_ip(struct beiscsi_hba *phba, u8 *ip, 5458c2ecf20Sopenharmony_ci u8 *subnet, u32 ip_type) 5468c2ecf20Sopenharmony_ci{ 5478c2ecf20Sopenharmony_ci struct be_cmd_set_ip_addr_req *req; 5488c2ecf20Sopenharmony_ci struct be_dma_mem nonemb_cmd; 5498c2ecf20Sopenharmony_ci uint32_t ip_len; 5508c2ecf20Sopenharmony_ci int rc; 5518c2ecf20Sopenharmony_ci 5528c2ecf20Sopenharmony_ci rc = beiscsi_prep_nemb_cmd(phba, &nonemb_cmd, CMD_SUBSYSTEM_ISCSI, 5538c2ecf20Sopenharmony_ci OPCODE_COMMON_ISCSI_NTWK_MODIFY_IP_ADDR, 5548c2ecf20Sopenharmony_ci sizeof(*req)); 5558c2ecf20Sopenharmony_ci if (rc) 5568c2ecf20Sopenharmony_ci return rc; 5578c2ecf20Sopenharmony_ci 5588c2ecf20Sopenharmony_ci req = nonemb_cmd.va; 5598c2ecf20Sopenharmony_ci req->ip_params.record_entry_count = 1; 5608c2ecf20Sopenharmony_ci req->ip_params.ip_record.action = IP_ACTION_ADD; 5618c2ecf20Sopenharmony_ci req->ip_params.ip_record.interface_hndl = 5628c2ecf20Sopenharmony_ci phba->interface_handle; 5638c2ecf20Sopenharmony_ci req->ip_params.ip_record.ip_addr.size_of_structure = 5648c2ecf20Sopenharmony_ci sizeof(struct be_ip_addr_subnet_format); 5658c2ecf20Sopenharmony_ci req->ip_params.ip_record.ip_addr.ip_type = ip_type; 5668c2ecf20Sopenharmony_ci ip_len = (ip_type < BEISCSI_IP_TYPE_V6) ? IP_V4_LEN : IP_V6_LEN; 5678c2ecf20Sopenharmony_ci memcpy(req->ip_params.ip_record.ip_addr.addr, ip, ip_len); 5688c2ecf20Sopenharmony_ci if (subnet) 5698c2ecf20Sopenharmony_ci memcpy(req->ip_params.ip_record.ip_addr.subnet_mask, 5708c2ecf20Sopenharmony_ci subnet, ip_len); 5718c2ecf20Sopenharmony_ci 5728c2ecf20Sopenharmony_ci rc = beiscsi_exec_nemb_cmd(phba, &nonemb_cmd, NULL, NULL, 0); 5738c2ecf20Sopenharmony_ci /** 5748c2ecf20Sopenharmony_ci * In some cases, host needs to look into individual record status 5758c2ecf20Sopenharmony_ci * even though FW reported success for that IOCTL. 5768c2ecf20Sopenharmony_ci */ 5778c2ecf20Sopenharmony_ci if (rc < 0 || req->ip_params.ip_record.status) { 5788c2ecf20Sopenharmony_ci __beiscsi_log(phba, KERN_ERR, 5798c2ecf20Sopenharmony_ci "BG_%d : failed to set IP: rc %d status %d\n", 5808c2ecf20Sopenharmony_ci rc, req->ip_params.ip_record.status); 5818c2ecf20Sopenharmony_ci if (req->ip_params.ip_record.status) 5828c2ecf20Sopenharmony_ci rc = -EINVAL; 5838c2ecf20Sopenharmony_ci } 5848c2ecf20Sopenharmony_ci return rc; 5858c2ecf20Sopenharmony_ci} 5868c2ecf20Sopenharmony_ci 5878c2ecf20Sopenharmony_ciint beiscsi_if_en_static(struct beiscsi_hba *phba, u32 ip_type, 5888c2ecf20Sopenharmony_ci u8 *ip, u8 *subnet) 5898c2ecf20Sopenharmony_ci{ 5908c2ecf20Sopenharmony_ci struct be_cmd_get_if_info_resp *if_info; 5918c2ecf20Sopenharmony_ci struct be_cmd_rel_dhcp_req *reldhcp; 5928c2ecf20Sopenharmony_ci struct be_dma_mem nonemb_cmd; 5938c2ecf20Sopenharmony_ci int rc; 5948c2ecf20Sopenharmony_ci 5958c2ecf20Sopenharmony_ci rc = beiscsi_if_get_info(phba, ip_type, &if_info); 5968c2ecf20Sopenharmony_ci if (rc) 5978c2ecf20Sopenharmony_ci return rc; 5988c2ecf20Sopenharmony_ci 5998c2ecf20Sopenharmony_ci if (if_info->dhcp_state) { 6008c2ecf20Sopenharmony_ci rc = beiscsi_prep_nemb_cmd(phba, &nonemb_cmd, 6018c2ecf20Sopenharmony_ci CMD_SUBSYSTEM_ISCSI, 6028c2ecf20Sopenharmony_ci OPCODE_COMMON_ISCSI_NTWK_REL_STATELESS_IP_ADDR, 6038c2ecf20Sopenharmony_ci sizeof(*reldhcp)); 6048c2ecf20Sopenharmony_ci if (rc) 6058c2ecf20Sopenharmony_ci goto exit; 6068c2ecf20Sopenharmony_ci 6078c2ecf20Sopenharmony_ci reldhcp = nonemb_cmd.va; 6088c2ecf20Sopenharmony_ci reldhcp->interface_hndl = phba->interface_handle; 6098c2ecf20Sopenharmony_ci reldhcp->ip_type = ip_type; 6108c2ecf20Sopenharmony_ci rc = beiscsi_exec_nemb_cmd(phba, &nonemb_cmd, NULL, NULL, 0); 6118c2ecf20Sopenharmony_ci if (rc < 0) { 6128c2ecf20Sopenharmony_ci beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_CONFIG, 6138c2ecf20Sopenharmony_ci "BG_%d : failed to release existing DHCP: %d\n", 6148c2ecf20Sopenharmony_ci rc); 6158c2ecf20Sopenharmony_ci goto exit; 6168c2ecf20Sopenharmony_ci } 6178c2ecf20Sopenharmony_ci } 6188c2ecf20Sopenharmony_ci 6198c2ecf20Sopenharmony_ci /* first delete any IP set */ 6208c2ecf20Sopenharmony_ci if (!beiscsi_if_zero_ip(if_info->ip_addr.addr, ip_type)) { 6218c2ecf20Sopenharmony_ci rc = beiscsi_if_clr_ip(phba, if_info); 6228c2ecf20Sopenharmony_ci if (rc) 6238c2ecf20Sopenharmony_ci goto exit; 6248c2ecf20Sopenharmony_ci } 6258c2ecf20Sopenharmony_ci 6268c2ecf20Sopenharmony_ci /* if ip == NULL then this is called just to release DHCP IP */ 6278c2ecf20Sopenharmony_ci if (ip) 6288c2ecf20Sopenharmony_ci rc = beiscsi_if_set_ip(phba, ip, subnet, ip_type); 6298c2ecf20Sopenharmony_ciexit: 6308c2ecf20Sopenharmony_ci kfree(if_info); 6318c2ecf20Sopenharmony_ci return rc; 6328c2ecf20Sopenharmony_ci} 6338c2ecf20Sopenharmony_ci 6348c2ecf20Sopenharmony_ciint beiscsi_if_en_dhcp(struct beiscsi_hba *phba, u32 ip_type) 6358c2ecf20Sopenharmony_ci{ 6368c2ecf20Sopenharmony_ci struct be_cmd_get_def_gateway_resp gw_resp; 6378c2ecf20Sopenharmony_ci struct be_cmd_get_if_info_resp *if_info; 6388c2ecf20Sopenharmony_ci struct be_cmd_set_dhcp_req *dhcpreq; 6398c2ecf20Sopenharmony_ci struct be_dma_mem nonemb_cmd; 6408c2ecf20Sopenharmony_ci u8 *gw; 6418c2ecf20Sopenharmony_ci int rc; 6428c2ecf20Sopenharmony_ci 6438c2ecf20Sopenharmony_ci rc = beiscsi_if_get_info(phba, ip_type, &if_info); 6448c2ecf20Sopenharmony_ci if (rc) 6458c2ecf20Sopenharmony_ci return rc; 6468c2ecf20Sopenharmony_ci 6478c2ecf20Sopenharmony_ci if (if_info->dhcp_state) { 6488c2ecf20Sopenharmony_ci beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_CONFIG, 6498c2ecf20Sopenharmony_ci "BG_%d : DHCP Already Enabled\n"); 6508c2ecf20Sopenharmony_ci goto exit; 6518c2ecf20Sopenharmony_ci } 6528c2ecf20Sopenharmony_ci 6538c2ecf20Sopenharmony_ci /* first delete any IP set */ 6548c2ecf20Sopenharmony_ci if (!beiscsi_if_zero_ip(if_info->ip_addr.addr, ip_type)) { 6558c2ecf20Sopenharmony_ci rc = beiscsi_if_clr_ip(phba, if_info); 6568c2ecf20Sopenharmony_ci if (rc) 6578c2ecf20Sopenharmony_ci goto exit; 6588c2ecf20Sopenharmony_ci } 6598c2ecf20Sopenharmony_ci 6608c2ecf20Sopenharmony_ci /* delete gateway settings if mode change is to DHCP */ 6618c2ecf20Sopenharmony_ci memset(&gw_resp, 0, sizeof(gw_resp)); 6628c2ecf20Sopenharmony_ci /* use ip_type provided in if_info */ 6638c2ecf20Sopenharmony_ci rc = beiscsi_if_get_gw(phba, if_info->ip_addr.ip_type, &gw_resp); 6648c2ecf20Sopenharmony_ci if (rc) { 6658c2ecf20Sopenharmony_ci beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_CONFIG, 6668c2ecf20Sopenharmony_ci "BG_%d : Failed to Get Gateway Addr\n"); 6678c2ecf20Sopenharmony_ci goto exit; 6688c2ecf20Sopenharmony_ci } 6698c2ecf20Sopenharmony_ci gw = (u8 *)&gw_resp.ip_addr.addr; 6708c2ecf20Sopenharmony_ci if (!beiscsi_if_zero_ip(gw, if_info->ip_addr.ip_type)) { 6718c2ecf20Sopenharmony_ci rc = beiscsi_if_mod_gw(phba, IP_ACTION_DEL, 6728c2ecf20Sopenharmony_ci if_info->ip_addr.ip_type, gw); 6738c2ecf20Sopenharmony_ci if (rc) { 6748c2ecf20Sopenharmony_ci beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_CONFIG, 6758c2ecf20Sopenharmony_ci "BG_%d : Failed to clear Gateway Addr Set\n"); 6768c2ecf20Sopenharmony_ci goto exit; 6778c2ecf20Sopenharmony_ci } 6788c2ecf20Sopenharmony_ci } 6798c2ecf20Sopenharmony_ci 6808c2ecf20Sopenharmony_ci rc = beiscsi_prep_nemb_cmd(phba, &nonemb_cmd, CMD_SUBSYSTEM_ISCSI, 6818c2ecf20Sopenharmony_ci OPCODE_COMMON_ISCSI_NTWK_CONFIG_STATELESS_IP_ADDR, 6828c2ecf20Sopenharmony_ci sizeof(*dhcpreq)); 6838c2ecf20Sopenharmony_ci if (rc) 6848c2ecf20Sopenharmony_ci goto exit; 6858c2ecf20Sopenharmony_ci 6868c2ecf20Sopenharmony_ci dhcpreq = nonemb_cmd.va; 6878c2ecf20Sopenharmony_ci dhcpreq->flags = 1; /* 1 - blocking; 0 - non-blocking */ 6888c2ecf20Sopenharmony_ci dhcpreq->retry_count = 1; 6898c2ecf20Sopenharmony_ci dhcpreq->interface_hndl = phba->interface_handle; 6908c2ecf20Sopenharmony_ci dhcpreq->ip_type = ip_type; 6918c2ecf20Sopenharmony_ci rc = beiscsi_exec_nemb_cmd(phba, &nonemb_cmd, NULL, NULL, 0); 6928c2ecf20Sopenharmony_ci 6938c2ecf20Sopenharmony_ciexit: 6948c2ecf20Sopenharmony_ci kfree(if_info); 6958c2ecf20Sopenharmony_ci return rc; 6968c2ecf20Sopenharmony_ci} 6978c2ecf20Sopenharmony_ci 6988c2ecf20Sopenharmony_ci/** 6998c2ecf20Sopenharmony_ci * beiscsi_if_set_vlan()- Issue and wait for CMD completion 7008c2ecf20Sopenharmony_ci * @phba: device private structure instance 7018c2ecf20Sopenharmony_ci * @vlan_tag: VLAN tag 7028c2ecf20Sopenharmony_ci * 7038c2ecf20Sopenharmony_ci * Issue the MBX Cmd and wait for the completion of the 7048c2ecf20Sopenharmony_ci * command. 7058c2ecf20Sopenharmony_ci * 7068c2ecf20Sopenharmony_ci * returns 7078c2ecf20Sopenharmony_ci * Success: 0 7088c2ecf20Sopenharmony_ci * Failure: Non-Xero Value 7098c2ecf20Sopenharmony_ci **/ 7108c2ecf20Sopenharmony_ciint beiscsi_if_set_vlan(struct beiscsi_hba *phba, uint16_t vlan_tag) 7118c2ecf20Sopenharmony_ci{ 7128c2ecf20Sopenharmony_ci int rc; 7138c2ecf20Sopenharmony_ci unsigned int tag; 7148c2ecf20Sopenharmony_ci 7158c2ecf20Sopenharmony_ci tag = be_cmd_set_vlan(phba, vlan_tag); 7168c2ecf20Sopenharmony_ci if (!tag) { 7178c2ecf20Sopenharmony_ci beiscsi_log(phba, KERN_ERR, 7188c2ecf20Sopenharmony_ci (BEISCSI_LOG_CONFIG | BEISCSI_LOG_MBOX), 7198c2ecf20Sopenharmony_ci "BG_%d : VLAN Setting Failed\n"); 7208c2ecf20Sopenharmony_ci return -EBUSY; 7218c2ecf20Sopenharmony_ci } 7228c2ecf20Sopenharmony_ci 7238c2ecf20Sopenharmony_ci rc = beiscsi_mccq_compl_wait(phba, tag, NULL, NULL); 7248c2ecf20Sopenharmony_ci if (rc) { 7258c2ecf20Sopenharmony_ci beiscsi_log(phba, KERN_ERR, 7268c2ecf20Sopenharmony_ci (BEISCSI_LOG_CONFIG | BEISCSI_LOG_MBOX), 7278c2ecf20Sopenharmony_ci "BS_%d : VLAN MBX Cmd Failed\n"); 7288c2ecf20Sopenharmony_ci return rc; 7298c2ecf20Sopenharmony_ci } 7308c2ecf20Sopenharmony_ci return rc; 7318c2ecf20Sopenharmony_ci} 7328c2ecf20Sopenharmony_ci 7338c2ecf20Sopenharmony_ci 7348c2ecf20Sopenharmony_ciint beiscsi_if_get_info(struct beiscsi_hba *phba, int ip_type, 7358c2ecf20Sopenharmony_ci struct be_cmd_get_if_info_resp **if_info) 7368c2ecf20Sopenharmony_ci{ 7378c2ecf20Sopenharmony_ci struct be_cmd_get_if_info_req *req; 7388c2ecf20Sopenharmony_ci struct be_dma_mem nonemb_cmd; 7398c2ecf20Sopenharmony_ci uint32_t ioctl_size = sizeof(struct be_cmd_get_if_info_resp); 7408c2ecf20Sopenharmony_ci int rc; 7418c2ecf20Sopenharmony_ci 7428c2ecf20Sopenharmony_ci rc = beiscsi_if_get_handle(phba); 7438c2ecf20Sopenharmony_ci if (rc) 7448c2ecf20Sopenharmony_ci return rc; 7458c2ecf20Sopenharmony_ci 7468c2ecf20Sopenharmony_ci do { 7478c2ecf20Sopenharmony_ci rc = beiscsi_prep_nemb_cmd(phba, &nonemb_cmd, 7488c2ecf20Sopenharmony_ci CMD_SUBSYSTEM_ISCSI, 7498c2ecf20Sopenharmony_ci OPCODE_COMMON_ISCSI_NTWK_GET_IF_INFO, 7508c2ecf20Sopenharmony_ci ioctl_size); 7518c2ecf20Sopenharmony_ci if (rc) 7528c2ecf20Sopenharmony_ci return rc; 7538c2ecf20Sopenharmony_ci 7548c2ecf20Sopenharmony_ci req = nonemb_cmd.va; 7558c2ecf20Sopenharmony_ci req->interface_hndl = phba->interface_handle; 7568c2ecf20Sopenharmony_ci req->ip_type = ip_type; 7578c2ecf20Sopenharmony_ci 7588c2ecf20Sopenharmony_ci /* Allocate memory for if_info */ 7598c2ecf20Sopenharmony_ci *if_info = kzalloc(ioctl_size, GFP_KERNEL); 7608c2ecf20Sopenharmony_ci if (!*if_info) { 7618c2ecf20Sopenharmony_ci beiscsi_log(phba, KERN_ERR, 7628c2ecf20Sopenharmony_ci BEISCSI_LOG_INIT | BEISCSI_LOG_CONFIG, 7638c2ecf20Sopenharmony_ci "BG_%d : Memory Allocation Failure\n"); 7648c2ecf20Sopenharmony_ci 7658c2ecf20Sopenharmony_ci /* Free the DMA memory for the IOCTL issuing */ 7668c2ecf20Sopenharmony_ci dma_free_coherent(&phba->ctrl.pdev->dev, 7678c2ecf20Sopenharmony_ci nonemb_cmd.size, 7688c2ecf20Sopenharmony_ci nonemb_cmd.va, 7698c2ecf20Sopenharmony_ci nonemb_cmd.dma); 7708c2ecf20Sopenharmony_ci return -ENOMEM; 7718c2ecf20Sopenharmony_ci } 7728c2ecf20Sopenharmony_ci 7738c2ecf20Sopenharmony_ci rc = beiscsi_exec_nemb_cmd(phba, &nonemb_cmd, NULL, *if_info, 7748c2ecf20Sopenharmony_ci ioctl_size); 7758c2ecf20Sopenharmony_ci 7768c2ecf20Sopenharmony_ci /* Check if the error is because of Insufficent_Buffer */ 7778c2ecf20Sopenharmony_ci if (rc == -EAGAIN) { 7788c2ecf20Sopenharmony_ci 7798c2ecf20Sopenharmony_ci /* Get the new memory size */ 7808c2ecf20Sopenharmony_ci ioctl_size = ((struct be_cmd_resp_hdr *) 7818c2ecf20Sopenharmony_ci nonemb_cmd.va)->actual_resp_len; 7828c2ecf20Sopenharmony_ci ioctl_size += sizeof(struct be_cmd_req_hdr); 7838c2ecf20Sopenharmony_ci 7848c2ecf20Sopenharmony_ci /* Free the previous allocated DMA memory */ 7858c2ecf20Sopenharmony_ci dma_free_coherent(&phba->ctrl.pdev->dev, nonemb_cmd.size, 7868c2ecf20Sopenharmony_ci nonemb_cmd.va, 7878c2ecf20Sopenharmony_ci nonemb_cmd.dma); 7888c2ecf20Sopenharmony_ci 7898c2ecf20Sopenharmony_ci /* Free the virtual memory */ 7908c2ecf20Sopenharmony_ci kfree(*if_info); 7918c2ecf20Sopenharmony_ci } else 7928c2ecf20Sopenharmony_ci break; 7938c2ecf20Sopenharmony_ci } while (true); 7948c2ecf20Sopenharmony_ci return rc; 7958c2ecf20Sopenharmony_ci} 7968c2ecf20Sopenharmony_ci 7978c2ecf20Sopenharmony_ciint mgmt_get_nic_conf(struct beiscsi_hba *phba, 7988c2ecf20Sopenharmony_ci struct be_cmd_get_nic_conf_resp *nic) 7998c2ecf20Sopenharmony_ci{ 8008c2ecf20Sopenharmony_ci struct be_dma_mem nonemb_cmd; 8018c2ecf20Sopenharmony_ci int rc; 8028c2ecf20Sopenharmony_ci 8038c2ecf20Sopenharmony_ci rc = beiscsi_prep_nemb_cmd(phba, &nonemb_cmd, CMD_SUBSYSTEM_ISCSI, 8048c2ecf20Sopenharmony_ci OPCODE_COMMON_ISCSI_NTWK_GET_NIC_CONFIG, 8058c2ecf20Sopenharmony_ci sizeof(*nic)); 8068c2ecf20Sopenharmony_ci if (rc) 8078c2ecf20Sopenharmony_ci return rc; 8088c2ecf20Sopenharmony_ci 8098c2ecf20Sopenharmony_ci return beiscsi_exec_nemb_cmd(phba, &nonemb_cmd, NULL, 8108c2ecf20Sopenharmony_ci nic, sizeof(*nic)); 8118c2ecf20Sopenharmony_ci} 8128c2ecf20Sopenharmony_ci 8138c2ecf20Sopenharmony_cistatic void beiscsi_boot_process_compl(struct beiscsi_hba *phba, 8148c2ecf20Sopenharmony_ci unsigned int tag) 8158c2ecf20Sopenharmony_ci{ 8168c2ecf20Sopenharmony_ci struct be_cmd_get_boot_target_resp *boot_resp; 8178c2ecf20Sopenharmony_ci struct be_cmd_resp_logout_fw_sess *logo_resp; 8188c2ecf20Sopenharmony_ci struct be_cmd_get_session_resp *sess_resp; 8198c2ecf20Sopenharmony_ci struct be_mcc_wrb *wrb; 8208c2ecf20Sopenharmony_ci struct boot_struct *bs; 8218c2ecf20Sopenharmony_ci int boot_work, status; 8228c2ecf20Sopenharmony_ci 8238c2ecf20Sopenharmony_ci if (!test_bit(BEISCSI_HBA_BOOT_WORK, &phba->state)) { 8248c2ecf20Sopenharmony_ci __beiscsi_log(phba, KERN_ERR, 8258c2ecf20Sopenharmony_ci "BG_%d : %s no boot work %lx\n", 8268c2ecf20Sopenharmony_ci __func__, phba->state); 8278c2ecf20Sopenharmony_ci return; 8288c2ecf20Sopenharmony_ci } 8298c2ecf20Sopenharmony_ci 8308c2ecf20Sopenharmony_ci if (phba->boot_struct.tag != tag) { 8318c2ecf20Sopenharmony_ci __beiscsi_log(phba, KERN_ERR, 8328c2ecf20Sopenharmony_ci "BG_%d : %s tag mismatch %d:%d\n", 8338c2ecf20Sopenharmony_ci __func__, tag, phba->boot_struct.tag); 8348c2ecf20Sopenharmony_ci return; 8358c2ecf20Sopenharmony_ci } 8368c2ecf20Sopenharmony_ci bs = &phba->boot_struct; 8378c2ecf20Sopenharmony_ci boot_work = 1; 8388c2ecf20Sopenharmony_ci status = 0; 8398c2ecf20Sopenharmony_ci switch (bs->action) { 8408c2ecf20Sopenharmony_ci case BEISCSI_BOOT_REOPEN_SESS: 8418c2ecf20Sopenharmony_ci status = __beiscsi_mcc_compl_status(phba, tag, NULL, NULL); 8428c2ecf20Sopenharmony_ci if (!status) 8438c2ecf20Sopenharmony_ci bs->action = BEISCSI_BOOT_GET_SHANDLE; 8448c2ecf20Sopenharmony_ci else 8458c2ecf20Sopenharmony_ci bs->retry--; 8468c2ecf20Sopenharmony_ci break; 8478c2ecf20Sopenharmony_ci case BEISCSI_BOOT_GET_SHANDLE: 8488c2ecf20Sopenharmony_ci status = __beiscsi_mcc_compl_status(phba, tag, &wrb, NULL); 8498c2ecf20Sopenharmony_ci if (!status) { 8508c2ecf20Sopenharmony_ci boot_resp = embedded_payload(wrb); 8518c2ecf20Sopenharmony_ci bs->s_handle = boot_resp->boot_session_handle; 8528c2ecf20Sopenharmony_ci } 8538c2ecf20Sopenharmony_ci if (bs->s_handle == BE_BOOT_INVALID_SHANDLE) { 8548c2ecf20Sopenharmony_ci bs->action = BEISCSI_BOOT_REOPEN_SESS; 8558c2ecf20Sopenharmony_ci bs->retry--; 8568c2ecf20Sopenharmony_ci } else { 8578c2ecf20Sopenharmony_ci bs->action = BEISCSI_BOOT_GET_SINFO; 8588c2ecf20Sopenharmony_ci } 8598c2ecf20Sopenharmony_ci break; 8608c2ecf20Sopenharmony_ci case BEISCSI_BOOT_GET_SINFO: 8618c2ecf20Sopenharmony_ci status = __beiscsi_mcc_compl_status(phba, tag, NULL, 8628c2ecf20Sopenharmony_ci &bs->nonemb_cmd); 8638c2ecf20Sopenharmony_ci if (!status) { 8648c2ecf20Sopenharmony_ci sess_resp = bs->nonemb_cmd.va; 8658c2ecf20Sopenharmony_ci memcpy(&bs->boot_sess, &sess_resp->session_info, 8668c2ecf20Sopenharmony_ci sizeof(struct mgmt_session_info)); 8678c2ecf20Sopenharmony_ci bs->action = BEISCSI_BOOT_LOGOUT_SESS; 8688c2ecf20Sopenharmony_ci } else { 8698c2ecf20Sopenharmony_ci __beiscsi_log(phba, KERN_ERR, 8708c2ecf20Sopenharmony_ci "BG_%d : get boot session info error : 0x%x\n", 8718c2ecf20Sopenharmony_ci status); 8728c2ecf20Sopenharmony_ci boot_work = 0; 8738c2ecf20Sopenharmony_ci } 8748c2ecf20Sopenharmony_ci dma_free_coherent(&phba->ctrl.pdev->dev, bs->nonemb_cmd.size, 8758c2ecf20Sopenharmony_ci bs->nonemb_cmd.va, bs->nonemb_cmd.dma); 8768c2ecf20Sopenharmony_ci bs->nonemb_cmd.va = NULL; 8778c2ecf20Sopenharmony_ci break; 8788c2ecf20Sopenharmony_ci case BEISCSI_BOOT_LOGOUT_SESS: 8798c2ecf20Sopenharmony_ci status = __beiscsi_mcc_compl_status(phba, tag, &wrb, NULL); 8808c2ecf20Sopenharmony_ci if (!status) { 8818c2ecf20Sopenharmony_ci logo_resp = embedded_payload(wrb); 8828c2ecf20Sopenharmony_ci if (logo_resp->session_status != BE_SESS_STATUS_CLOSE) { 8838c2ecf20Sopenharmony_ci __beiscsi_log(phba, KERN_ERR, 8848c2ecf20Sopenharmony_ci "BG_%d : FW boot session logout error : 0x%x\n", 8858c2ecf20Sopenharmony_ci logo_resp->session_status); 8868c2ecf20Sopenharmony_ci } 8878c2ecf20Sopenharmony_ci } 8888c2ecf20Sopenharmony_ci /* continue to create boot_kset even if logout failed? */ 8898c2ecf20Sopenharmony_ci bs->action = BEISCSI_BOOT_CREATE_KSET; 8908c2ecf20Sopenharmony_ci break; 8918c2ecf20Sopenharmony_ci default: 8928c2ecf20Sopenharmony_ci break; 8938c2ecf20Sopenharmony_ci } 8948c2ecf20Sopenharmony_ci 8958c2ecf20Sopenharmony_ci /* clear the tag so no other completion matches this tag */ 8968c2ecf20Sopenharmony_ci bs->tag = 0; 8978c2ecf20Sopenharmony_ci if (!bs->retry) { 8988c2ecf20Sopenharmony_ci boot_work = 0; 8998c2ecf20Sopenharmony_ci __beiscsi_log(phba, KERN_ERR, 9008c2ecf20Sopenharmony_ci "BG_%d : failed to setup boot target: status %d action %d\n", 9018c2ecf20Sopenharmony_ci status, bs->action); 9028c2ecf20Sopenharmony_ci } 9038c2ecf20Sopenharmony_ci if (!boot_work) { 9048c2ecf20Sopenharmony_ci /* wait for next event to start boot_work */ 9058c2ecf20Sopenharmony_ci clear_bit(BEISCSI_HBA_BOOT_WORK, &phba->state); 9068c2ecf20Sopenharmony_ci return; 9078c2ecf20Sopenharmony_ci } 9088c2ecf20Sopenharmony_ci schedule_work(&phba->boot_work); 9098c2ecf20Sopenharmony_ci} 9108c2ecf20Sopenharmony_ci 9118c2ecf20Sopenharmony_ci/** 9128c2ecf20Sopenharmony_ci * beiscsi_boot_logout_sess()- Logout from boot FW session 9138c2ecf20Sopenharmony_ci * @phba: Device priv structure instance 9148c2ecf20Sopenharmony_ci * 9158c2ecf20Sopenharmony_ci * return 9168c2ecf20Sopenharmony_ci * the TAG used for MBOX Command 9178c2ecf20Sopenharmony_ci * 9188c2ecf20Sopenharmony_ci */ 9198c2ecf20Sopenharmony_ciunsigned int beiscsi_boot_logout_sess(struct beiscsi_hba *phba) 9208c2ecf20Sopenharmony_ci{ 9218c2ecf20Sopenharmony_ci struct be_ctrl_info *ctrl = &phba->ctrl; 9228c2ecf20Sopenharmony_ci struct be_mcc_wrb *wrb; 9238c2ecf20Sopenharmony_ci struct be_cmd_req_logout_fw_sess *req; 9248c2ecf20Sopenharmony_ci unsigned int tag; 9258c2ecf20Sopenharmony_ci 9268c2ecf20Sopenharmony_ci mutex_lock(&ctrl->mbox_lock); 9278c2ecf20Sopenharmony_ci wrb = alloc_mcc_wrb(phba, &tag); 9288c2ecf20Sopenharmony_ci if (!wrb) { 9298c2ecf20Sopenharmony_ci mutex_unlock(&ctrl->mbox_lock); 9308c2ecf20Sopenharmony_ci return 0; 9318c2ecf20Sopenharmony_ci } 9328c2ecf20Sopenharmony_ci 9338c2ecf20Sopenharmony_ci req = embedded_payload(wrb); 9348c2ecf20Sopenharmony_ci be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0); 9358c2ecf20Sopenharmony_ci be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI_INI, 9368c2ecf20Sopenharmony_ci OPCODE_ISCSI_INI_SESSION_LOGOUT_TARGET, 9378c2ecf20Sopenharmony_ci sizeof(struct be_cmd_req_logout_fw_sess)); 9388c2ecf20Sopenharmony_ci /* Use the session handle copied into boot_sess */ 9398c2ecf20Sopenharmony_ci req->session_handle = phba->boot_struct.boot_sess.session_handle; 9408c2ecf20Sopenharmony_ci 9418c2ecf20Sopenharmony_ci phba->boot_struct.tag = tag; 9428c2ecf20Sopenharmony_ci set_bit(MCC_TAG_STATE_ASYNC, &ctrl->ptag_state[tag].tag_state); 9438c2ecf20Sopenharmony_ci ctrl->ptag_state[tag].cbfn = beiscsi_boot_process_compl; 9448c2ecf20Sopenharmony_ci 9458c2ecf20Sopenharmony_ci be_mcc_notify(phba, tag); 9468c2ecf20Sopenharmony_ci mutex_unlock(&ctrl->mbox_lock); 9478c2ecf20Sopenharmony_ci 9488c2ecf20Sopenharmony_ci return tag; 9498c2ecf20Sopenharmony_ci} 9508c2ecf20Sopenharmony_ci/** 9518c2ecf20Sopenharmony_ci * beiscsi_boot_reopen_sess()- Reopen boot session 9528c2ecf20Sopenharmony_ci * @phba: Device priv structure instance 9538c2ecf20Sopenharmony_ci * 9548c2ecf20Sopenharmony_ci * return 9558c2ecf20Sopenharmony_ci * the TAG used for MBOX Command 9568c2ecf20Sopenharmony_ci * 9578c2ecf20Sopenharmony_ci **/ 9588c2ecf20Sopenharmony_ciunsigned int beiscsi_boot_reopen_sess(struct beiscsi_hba *phba) 9598c2ecf20Sopenharmony_ci{ 9608c2ecf20Sopenharmony_ci struct be_ctrl_info *ctrl = &phba->ctrl; 9618c2ecf20Sopenharmony_ci struct be_mcc_wrb *wrb; 9628c2ecf20Sopenharmony_ci struct be_cmd_reopen_session_req *req; 9638c2ecf20Sopenharmony_ci unsigned int tag; 9648c2ecf20Sopenharmony_ci 9658c2ecf20Sopenharmony_ci mutex_lock(&ctrl->mbox_lock); 9668c2ecf20Sopenharmony_ci wrb = alloc_mcc_wrb(phba, &tag); 9678c2ecf20Sopenharmony_ci if (!wrb) { 9688c2ecf20Sopenharmony_ci mutex_unlock(&ctrl->mbox_lock); 9698c2ecf20Sopenharmony_ci return 0; 9708c2ecf20Sopenharmony_ci } 9718c2ecf20Sopenharmony_ci 9728c2ecf20Sopenharmony_ci req = embedded_payload(wrb); 9738c2ecf20Sopenharmony_ci be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0); 9748c2ecf20Sopenharmony_ci be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI_INI, 9758c2ecf20Sopenharmony_ci OPCODE_ISCSI_INI_DRIVER_REOPEN_ALL_SESSIONS, 9768c2ecf20Sopenharmony_ci sizeof(struct be_cmd_reopen_session_resp)); 9778c2ecf20Sopenharmony_ci req->reopen_type = BE_REOPEN_BOOT_SESSIONS; 9788c2ecf20Sopenharmony_ci req->session_handle = BE_BOOT_INVALID_SHANDLE; 9798c2ecf20Sopenharmony_ci 9808c2ecf20Sopenharmony_ci phba->boot_struct.tag = tag; 9818c2ecf20Sopenharmony_ci set_bit(MCC_TAG_STATE_ASYNC, &ctrl->ptag_state[tag].tag_state); 9828c2ecf20Sopenharmony_ci ctrl->ptag_state[tag].cbfn = beiscsi_boot_process_compl; 9838c2ecf20Sopenharmony_ci 9848c2ecf20Sopenharmony_ci be_mcc_notify(phba, tag); 9858c2ecf20Sopenharmony_ci mutex_unlock(&ctrl->mbox_lock); 9868c2ecf20Sopenharmony_ci return tag; 9878c2ecf20Sopenharmony_ci} 9888c2ecf20Sopenharmony_ci 9898c2ecf20Sopenharmony_ci 9908c2ecf20Sopenharmony_ci/** 9918c2ecf20Sopenharmony_ci * beiscsi_boot_get_sinfo()- Get boot session info 9928c2ecf20Sopenharmony_ci * @phba: device priv structure instance 9938c2ecf20Sopenharmony_ci * 9948c2ecf20Sopenharmony_ci * Fetches the boot_struct.s_handle info from FW. 9958c2ecf20Sopenharmony_ci * return 9968c2ecf20Sopenharmony_ci * the TAG used for MBOX Command 9978c2ecf20Sopenharmony_ci * 9988c2ecf20Sopenharmony_ci **/ 9998c2ecf20Sopenharmony_ciunsigned int beiscsi_boot_get_sinfo(struct beiscsi_hba *phba) 10008c2ecf20Sopenharmony_ci{ 10018c2ecf20Sopenharmony_ci struct be_ctrl_info *ctrl = &phba->ctrl; 10028c2ecf20Sopenharmony_ci struct be_cmd_get_session_req *req; 10038c2ecf20Sopenharmony_ci struct be_dma_mem *nonemb_cmd; 10048c2ecf20Sopenharmony_ci struct be_mcc_wrb *wrb; 10058c2ecf20Sopenharmony_ci struct be_sge *sge; 10068c2ecf20Sopenharmony_ci unsigned int tag; 10078c2ecf20Sopenharmony_ci 10088c2ecf20Sopenharmony_ci mutex_lock(&ctrl->mbox_lock); 10098c2ecf20Sopenharmony_ci wrb = alloc_mcc_wrb(phba, &tag); 10108c2ecf20Sopenharmony_ci if (!wrb) { 10118c2ecf20Sopenharmony_ci mutex_unlock(&ctrl->mbox_lock); 10128c2ecf20Sopenharmony_ci return 0; 10138c2ecf20Sopenharmony_ci } 10148c2ecf20Sopenharmony_ci 10158c2ecf20Sopenharmony_ci nonemb_cmd = &phba->boot_struct.nonemb_cmd; 10168c2ecf20Sopenharmony_ci nonemb_cmd->size = sizeof(struct be_cmd_get_session_resp); 10178c2ecf20Sopenharmony_ci nonemb_cmd->va = dma_alloc_coherent(&phba->ctrl.pdev->dev, 10188c2ecf20Sopenharmony_ci nonemb_cmd->size, 10198c2ecf20Sopenharmony_ci &nonemb_cmd->dma, 10208c2ecf20Sopenharmony_ci GFP_KERNEL); 10218c2ecf20Sopenharmony_ci if (!nonemb_cmd->va) { 10228c2ecf20Sopenharmony_ci mutex_unlock(&ctrl->mbox_lock); 10238c2ecf20Sopenharmony_ci return 0; 10248c2ecf20Sopenharmony_ci } 10258c2ecf20Sopenharmony_ci 10268c2ecf20Sopenharmony_ci req = nonemb_cmd->va; 10278c2ecf20Sopenharmony_ci memset(req, 0, sizeof(*req)); 10288c2ecf20Sopenharmony_ci sge = nonembedded_sgl(wrb); 10298c2ecf20Sopenharmony_ci be_wrb_hdr_prepare(wrb, sizeof(*req), false, 1); 10308c2ecf20Sopenharmony_ci be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI_INI, 10318c2ecf20Sopenharmony_ci OPCODE_ISCSI_INI_SESSION_GET_A_SESSION, 10328c2ecf20Sopenharmony_ci sizeof(struct be_cmd_get_session_resp)); 10338c2ecf20Sopenharmony_ci req->session_handle = phba->boot_struct.s_handle; 10348c2ecf20Sopenharmony_ci sge->pa_hi = cpu_to_le32(upper_32_bits(nonemb_cmd->dma)); 10358c2ecf20Sopenharmony_ci sge->pa_lo = cpu_to_le32(nonemb_cmd->dma & 0xFFFFFFFF); 10368c2ecf20Sopenharmony_ci sge->len = cpu_to_le32(nonemb_cmd->size); 10378c2ecf20Sopenharmony_ci 10388c2ecf20Sopenharmony_ci phba->boot_struct.tag = tag; 10398c2ecf20Sopenharmony_ci set_bit(MCC_TAG_STATE_ASYNC, &ctrl->ptag_state[tag].tag_state); 10408c2ecf20Sopenharmony_ci ctrl->ptag_state[tag].cbfn = beiscsi_boot_process_compl; 10418c2ecf20Sopenharmony_ci 10428c2ecf20Sopenharmony_ci be_mcc_notify(phba, tag); 10438c2ecf20Sopenharmony_ci mutex_unlock(&ctrl->mbox_lock); 10448c2ecf20Sopenharmony_ci return tag; 10458c2ecf20Sopenharmony_ci} 10468c2ecf20Sopenharmony_ci 10478c2ecf20Sopenharmony_ciunsigned int __beiscsi_boot_get_shandle(struct beiscsi_hba *phba, int async) 10488c2ecf20Sopenharmony_ci{ 10498c2ecf20Sopenharmony_ci struct be_ctrl_info *ctrl = &phba->ctrl; 10508c2ecf20Sopenharmony_ci struct be_mcc_wrb *wrb; 10518c2ecf20Sopenharmony_ci struct be_cmd_get_boot_target_req *req; 10528c2ecf20Sopenharmony_ci unsigned int tag; 10538c2ecf20Sopenharmony_ci 10548c2ecf20Sopenharmony_ci mutex_lock(&ctrl->mbox_lock); 10558c2ecf20Sopenharmony_ci wrb = alloc_mcc_wrb(phba, &tag); 10568c2ecf20Sopenharmony_ci if (!wrb) { 10578c2ecf20Sopenharmony_ci mutex_unlock(&ctrl->mbox_lock); 10588c2ecf20Sopenharmony_ci return 0; 10598c2ecf20Sopenharmony_ci } 10608c2ecf20Sopenharmony_ci 10618c2ecf20Sopenharmony_ci req = embedded_payload(wrb); 10628c2ecf20Sopenharmony_ci be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0); 10638c2ecf20Sopenharmony_ci be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI_INI, 10648c2ecf20Sopenharmony_ci OPCODE_ISCSI_INI_BOOT_GET_BOOT_TARGET, 10658c2ecf20Sopenharmony_ci sizeof(struct be_cmd_get_boot_target_resp)); 10668c2ecf20Sopenharmony_ci 10678c2ecf20Sopenharmony_ci if (async) { 10688c2ecf20Sopenharmony_ci phba->boot_struct.tag = tag; 10698c2ecf20Sopenharmony_ci set_bit(MCC_TAG_STATE_ASYNC, &ctrl->ptag_state[tag].tag_state); 10708c2ecf20Sopenharmony_ci ctrl->ptag_state[tag].cbfn = beiscsi_boot_process_compl; 10718c2ecf20Sopenharmony_ci } 10728c2ecf20Sopenharmony_ci 10738c2ecf20Sopenharmony_ci be_mcc_notify(phba, tag); 10748c2ecf20Sopenharmony_ci mutex_unlock(&ctrl->mbox_lock); 10758c2ecf20Sopenharmony_ci return tag; 10768c2ecf20Sopenharmony_ci} 10778c2ecf20Sopenharmony_ci 10788c2ecf20Sopenharmony_ci/** 10798c2ecf20Sopenharmony_ci * beiscsi_boot_get_shandle()- Get boot session handle 10808c2ecf20Sopenharmony_ci * @phba: device priv structure instance 10818c2ecf20Sopenharmony_ci * @s_handle: session handle returned for boot session. 10828c2ecf20Sopenharmony_ci * 10838c2ecf20Sopenharmony_ci * return 10848c2ecf20Sopenharmony_ci * Success: 1 10858c2ecf20Sopenharmony_ci * Failure: negative 10868c2ecf20Sopenharmony_ci * 10878c2ecf20Sopenharmony_ci **/ 10888c2ecf20Sopenharmony_ciint beiscsi_boot_get_shandle(struct beiscsi_hba *phba, unsigned int *s_handle) 10898c2ecf20Sopenharmony_ci{ 10908c2ecf20Sopenharmony_ci struct be_cmd_get_boot_target_resp *boot_resp; 10918c2ecf20Sopenharmony_ci struct be_mcc_wrb *wrb; 10928c2ecf20Sopenharmony_ci unsigned int tag; 10938c2ecf20Sopenharmony_ci int rc; 10948c2ecf20Sopenharmony_ci 10958c2ecf20Sopenharmony_ci *s_handle = BE_BOOT_INVALID_SHANDLE; 10968c2ecf20Sopenharmony_ci /* get configured boot session count and handle */ 10978c2ecf20Sopenharmony_ci tag = __beiscsi_boot_get_shandle(phba, 0); 10988c2ecf20Sopenharmony_ci if (!tag) { 10998c2ecf20Sopenharmony_ci beiscsi_log(phba, KERN_ERR, 11008c2ecf20Sopenharmony_ci BEISCSI_LOG_CONFIG | BEISCSI_LOG_INIT, 11018c2ecf20Sopenharmony_ci "BG_%d : Getting Boot Target Info Failed\n"); 11028c2ecf20Sopenharmony_ci return -EAGAIN; 11038c2ecf20Sopenharmony_ci } 11048c2ecf20Sopenharmony_ci 11058c2ecf20Sopenharmony_ci rc = beiscsi_mccq_compl_wait(phba, tag, &wrb, NULL); 11068c2ecf20Sopenharmony_ci if (rc) { 11078c2ecf20Sopenharmony_ci beiscsi_log(phba, KERN_ERR, 11088c2ecf20Sopenharmony_ci BEISCSI_LOG_INIT | BEISCSI_LOG_CONFIG, 11098c2ecf20Sopenharmony_ci "BG_%d : MBX CMD get_boot_target Failed\n"); 11108c2ecf20Sopenharmony_ci return -EBUSY; 11118c2ecf20Sopenharmony_ci } 11128c2ecf20Sopenharmony_ci 11138c2ecf20Sopenharmony_ci boot_resp = embedded_payload(wrb); 11148c2ecf20Sopenharmony_ci /* check if there are any boot targets configured */ 11158c2ecf20Sopenharmony_ci if (!boot_resp->boot_session_count) { 11168c2ecf20Sopenharmony_ci __beiscsi_log(phba, KERN_INFO, 11178c2ecf20Sopenharmony_ci "BG_%d : No boot targets configured\n"); 11188c2ecf20Sopenharmony_ci return -ENXIO; 11198c2ecf20Sopenharmony_ci } 11208c2ecf20Sopenharmony_ci 11218c2ecf20Sopenharmony_ci /* only if FW has logged in to the boot target, s_handle is valid */ 11228c2ecf20Sopenharmony_ci *s_handle = boot_resp->boot_session_handle; 11238c2ecf20Sopenharmony_ci return 1; 11248c2ecf20Sopenharmony_ci} 11258c2ecf20Sopenharmony_ci 11268c2ecf20Sopenharmony_ci/** 11278c2ecf20Sopenharmony_ci * beiscsi_drvr_ver_disp()- Display the driver Name and Version 11288c2ecf20Sopenharmony_ci * @dev: ptr to device not used. 11298c2ecf20Sopenharmony_ci * @attr: device attribute, not used. 11308c2ecf20Sopenharmony_ci * @buf: contains formatted text driver name and version 11318c2ecf20Sopenharmony_ci * 11328c2ecf20Sopenharmony_ci * return 11338c2ecf20Sopenharmony_ci * size of the formatted string 11348c2ecf20Sopenharmony_ci **/ 11358c2ecf20Sopenharmony_cissize_t 11368c2ecf20Sopenharmony_cibeiscsi_drvr_ver_disp(struct device *dev, struct device_attribute *attr, 11378c2ecf20Sopenharmony_ci char *buf) 11388c2ecf20Sopenharmony_ci{ 11398c2ecf20Sopenharmony_ci return snprintf(buf, PAGE_SIZE, BE_NAME "\n"); 11408c2ecf20Sopenharmony_ci} 11418c2ecf20Sopenharmony_ci 11428c2ecf20Sopenharmony_ci/** 11438c2ecf20Sopenharmony_ci * beiscsi_fw_ver_disp()- Display Firmware Version 11448c2ecf20Sopenharmony_ci * @dev: ptr to device not used. 11458c2ecf20Sopenharmony_ci * @attr: device attribute, not used. 11468c2ecf20Sopenharmony_ci * @buf: contains formatted text Firmware version 11478c2ecf20Sopenharmony_ci * 11488c2ecf20Sopenharmony_ci * return 11498c2ecf20Sopenharmony_ci * size of the formatted string 11508c2ecf20Sopenharmony_ci **/ 11518c2ecf20Sopenharmony_cissize_t 11528c2ecf20Sopenharmony_cibeiscsi_fw_ver_disp(struct device *dev, struct device_attribute *attr, 11538c2ecf20Sopenharmony_ci char *buf) 11548c2ecf20Sopenharmony_ci{ 11558c2ecf20Sopenharmony_ci struct Scsi_Host *shost = class_to_shost(dev); 11568c2ecf20Sopenharmony_ci struct beiscsi_hba *phba = iscsi_host_priv(shost); 11578c2ecf20Sopenharmony_ci 11588c2ecf20Sopenharmony_ci return snprintf(buf, PAGE_SIZE, "%s\n", phba->fw_ver_str); 11598c2ecf20Sopenharmony_ci} 11608c2ecf20Sopenharmony_ci 11618c2ecf20Sopenharmony_ci/** 11628c2ecf20Sopenharmony_ci * beiscsi_active_session_disp()- Display Sessions Active 11638c2ecf20Sopenharmony_ci * @dev: ptr to device not used. 11648c2ecf20Sopenharmony_ci * @attr: device attribute, not used. 11658c2ecf20Sopenharmony_ci * @buf: contains formatted text Session Count 11668c2ecf20Sopenharmony_ci * 11678c2ecf20Sopenharmony_ci * return 11688c2ecf20Sopenharmony_ci * size of the formatted string 11698c2ecf20Sopenharmony_ci **/ 11708c2ecf20Sopenharmony_cissize_t 11718c2ecf20Sopenharmony_cibeiscsi_active_session_disp(struct device *dev, struct device_attribute *attr, 11728c2ecf20Sopenharmony_ci char *buf) 11738c2ecf20Sopenharmony_ci{ 11748c2ecf20Sopenharmony_ci struct Scsi_Host *shost = class_to_shost(dev); 11758c2ecf20Sopenharmony_ci struct beiscsi_hba *phba = iscsi_host_priv(shost); 11768c2ecf20Sopenharmony_ci uint16_t avlbl_cids = 0, ulp_num, len = 0, total_cids = 0; 11778c2ecf20Sopenharmony_ci 11788c2ecf20Sopenharmony_ci for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++) { 11798c2ecf20Sopenharmony_ci if (test_bit(ulp_num, (void *)&phba->fw_config.ulp_supported)) { 11808c2ecf20Sopenharmony_ci avlbl_cids = BEISCSI_ULP_AVLBL_CID(phba, ulp_num); 11818c2ecf20Sopenharmony_ci total_cids = BEISCSI_GET_CID_COUNT(phba, ulp_num); 11828c2ecf20Sopenharmony_ci len += scnprintf(buf+len, PAGE_SIZE - len, 11838c2ecf20Sopenharmony_ci "ULP%d : %d\n", ulp_num, 11848c2ecf20Sopenharmony_ci (total_cids - avlbl_cids)); 11858c2ecf20Sopenharmony_ci } else 11868c2ecf20Sopenharmony_ci len += scnprintf(buf+len, PAGE_SIZE - len, 11878c2ecf20Sopenharmony_ci "ULP%d : %d\n", ulp_num, 0); 11888c2ecf20Sopenharmony_ci } 11898c2ecf20Sopenharmony_ci 11908c2ecf20Sopenharmony_ci return len; 11918c2ecf20Sopenharmony_ci} 11928c2ecf20Sopenharmony_ci 11938c2ecf20Sopenharmony_ci/** 11948c2ecf20Sopenharmony_ci * beiscsi_free_session_disp()- Display Avaliable Session 11958c2ecf20Sopenharmony_ci * @dev: ptr to device not used. 11968c2ecf20Sopenharmony_ci * @attr: device attribute, not used. 11978c2ecf20Sopenharmony_ci * @buf: contains formatted text Session Count 11988c2ecf20Sopenharmony_ci * 11998c2ecf20Sopenharmony_ci * return 12008c2ecf20Sopenharmony_ci * size of the formatted string 12018c2ecf20Sopenharmony_ci **/ 12028c2ecf20Sopenharmony_cissize_t 12038c2ecf20Sopenharmony_cibeiscsi_free_session_disp(struct device *dev, struct device_attribute *attr, 12048c2ecf20Sopenharmony_ci char *buf) 12058c2ecf20Sopenharmony_ci{ 12068c2ecf20Sopenharmony_ci struct Scsi_Host *shost = class_to_shost(dev); 12078c2ecf20Sopenharmony_ci struct beiscsi_hba *phba = iscsi_host_priv(shost); 12088c2ecf20Sopenharmony_ci uint16_t ulp_num, len = 0; 12098c2ecf20Sopenharmony_ci 12108c2ecf20Sopenharmony_ci for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++) { 12118c2ecf20Sopenharmony_ci if (test_bit(ulp_num, (void *)&phba->fw_config.ulp_supported)) 12128c2ecf20Sopenharmony_ci len += scnprintf(buf+len, PAGE_SIZE - len, 12138c2ecf20Sopenharmony_ci "ULP%d : %d\n", ulp_num, 12148c2ecf20Sopenharmony_ci BEISCSI_ULP_AVLBL_CID(phba, ulp_num)); 12158c2ecf20Sopenharmony_ci else 12168c2ecf20Sopenharmony_ci len += scnprintf(buf+len, PAGE_SIZE - len, 12178c2ecf20Sopenharmony_ci "ULP%d : %d\n", ulp_num, 0); 12188c2ecf20Sopenharmony_ci } 12198c2ecf20Sopenharmony_ci 12208c2ecf20Sopenharmony_ci return len; 12218c2ecf20Sopenharmony_ci} 12228c2ecf20Sopenharmony_ci 12238c2ecf20Sopenharmony_ci/** 12248c2ecf20Sopenharmony_ci * beiscsi_adap_family_disp()- Display adapter family. 12258c2ecf20Sopenharmony_ci * @dev: ptr to device to get priv structure 12268c2ecf20Sopenharmony_ci * @attr: device attribute, not used. 12278c2ecf20Sopenharmony_ci * @buf: contains formatted text driver name and version 12288c2ecf20Sopenharmony_ci * 12298c2ecf20Sopenharmony_ci * return 12308c2ecf20Sopenharmony_ci * size of the formatted string 12318c2ecf20Sopenharmony_ci **/ 12328c2ecf20Sopenharmony_cissize_t 12338c2ecf20Sopenharmony_cibeiscsi_adap_family_disp(struct device *dev, struct device_attribute *attr, 12348c2ecf20Sopenharmony_ci char *buf) 12358c2ecf20Sopenharmony_ci{ 12368c2ecf20Sopenharmony_ci uint16_t dev_id = 0; 12378c2ecf20Sopenharmony_ci struct Scsi_Host *shost = class_to_shost(dev); 12388c2ecf20Sopenharmony_ci struct beiscsi_hba *phba = iscsi_host_priv(shost); 12398c2ecf20Sopenharmony_ci 12408c2ecf20Sopenharmony_ci dev_id = phba->pcidev->device; 12418c2ecf20Sopenharmony_ci switch (dev_id) { 12428c2ecf20Sopenharmony_ci case BE_DEVICE_ID1: 12438c2ecf20Sopenharmony_ci case OC_DEVICE_ID1: 12448c2ecf20Sopenharmony_ci case OC_DEVICE_ID2: 12458c2ecf20Sopenharmony_ci return snprintf(buf, PAGE_SIZE, 12468c2ecf20Sopenharmony_ci "Obsolete/Unsupported BE2 Adapter Family\n"); 12478c2ecf20Sopenharmony_ci break; 12488c2ecf20Sopenharmony_ci case BE_DEVICE_ID2: 12498c2ecf20Sopenharmony_ci case OC_DEVICE_ID3: 12508c2ecf20Sopenharmony_ci return snprintf(buf, PAGE_SIZE, "BE3-R Adapter Family\n"); 12518c2ecf20Sopenharmony_ci break; 12528c2ecf20Sopenharmony_ci case OC_SKH_ID1: 12538c2ecf20Sopenharmony_ci return snprintf(buf, PAGE_SIZE, "Skyhawk-R Adapter Family\n"); 12548c2ecf20Sopenharmony_ci break; 12558c2ecf20Sopenharmony_ci default: 12568c2ecf20Sopenharmony_ci return snprintf(buf, PAGE_SIZE, 12578c2ecf20Sopenharmony_ci "Unknown Adapter Family: 0x%x\n", dev_id); 12588c2ecf20Sopenharmony_ci break; 12598c2ecf20Sopenharmony_ci } 12608c2ecf20Sopenharmony_ci} 12618c2ecf20Sopenharmony_ci 12628c2ecf20Sopenharmony_ci/** 12638c2ecf20Sopenharmony_ci * beiscsi_phys_port()- Display Physical Port Identifier 12648c2ecf20Sopenharmony_ci * @dev: ptr to device not used. 12658c2ecf20Sopenharmony_ci * @attr: device attribute, not used. 12668c2ecf20Sopenharmony_ci * @buf: contains formatted text port identifier 12678c2ecf20Sopenharmony_ci * 12688c2ecf20Sopenharmony_ci * return 12698c2ecf20Sopenharmony_ci * size of the formatted string 12708c2ecf20Sopenharmony_ci **/ 12718c2ecf20Sopenharmony_cissize_t 12728c2ecf20Sopenharmony_cibeiscsi_phys_port_disp(struct device *dev, struct device_attribute *attr, 12738c2ecf20Sopenharmony_ci char *buf) 12748c2ecf20Sopenharmony_ci{ 12758c2ecf20Sopenharmony_ci struct Scsi_Host *shost = class_to_shost(dev); 12768c2ecf20Sopenharmony_ci struct beiscsi_hba *phba = iscsi_host_priv(shost); 12778c2ecf20Sopenharmony_ci 12788c2ecf20Sopenharmony_ci return snprintf(buf, PAGE_SIZE, "Port Identifier : %u\n", 12798c2ecf20Sopenharmony_ci phba->fw_config.phys_port); 12808c2ecf20Sopenharmony_ci} 12818c2ecf20Sopenharmony_ci 12828c2ecf20Sopenharmony_civoid beiscsi_offload_cxn_v0(struct beiscsi_offload_params *params, 12838c2ecf20Sopenharmony_ci struct wrb_handle *pwrb_handle, 12848c2ecf20Sopenharmony_ci struct be_mem_descriptor *mem_descr, 12858c2ecf20Sopenharmony_ci struct hwi_wrb_context *pwrb_context) 12868c2ecf20Sopenharmony_ci{ 12878c2ecf20Sopenharmony_ci struct iscsi_wrb *pwrb = pwrb_handle->pwrb; 12888c2ecf20Sopenharmony_ci 12898c2ecf20Sopenharmony_ci AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb, 12908c2ecf20Sopenharmony_ci max_send_data_segment_length, pwrb, 12918c2ecf20Sopenharmony_ci params->dw[offsetof(struct amap_beiscsi_offload_params, 12928c2ecf20Sopenharmony_ci max_send_data_segment_length) / 32]); 12938c2ecf20Sopenharmony_ci AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb, type, pwrb, 12948c2ecf20Sopenharmony_ci BE_TGT_CTX_UPDT_CMD); 12958c2ecf20Sopenharmony_ci AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb, 12968c2ecf20Sopenharmony_ci first_burst_length, 12978c2ecf20Sopenharmony_ci pwrb, 12988c2ecf20Sopenharmony_ci params->dw[offsetof(struct amap_beiscsi_offload_params, 12998c2ecf20Sopenharmony_ci first_burst_length) / 32]); 13008c2ecf20Sopenharmony_ci AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb, erl, pwrb, 13018c2ecf20Sopenharmony_ci (params->dw[offsetof(struct amap_beiscsi_offload_params, 13028c2ecf20Sopenharmony_ci erl) / 32] & OFFLD_PARAMS_ERL)); 13038c2ecf20Sopenharmony_ci AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb, dde, pwrb, 13048c2ecf20Sopenharmony_ci (params->dw[offsetof(struct amap_beiscsi_offload_params, 13058c2ecf20Sopenharmony_ci dde) / 32] & OFFLD_PARAMS_DDE) >> 2); 13068c2ecf20Sopenharmony_ci AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb, hde, pwrb, 13078c2ecf20Sopenharmony_ci (params->dw[offsetof(struct amap_beiscsi_offload_params, 13088c2ecf20Sopenharmony_ci hde) / 32] & OFFLD_PARAMS_HDE) >> 3); 13098c2ecf20Sopenharmony_ci AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb, ir2t, pwrb, 13108c2ecf20Sopenharmony_ci (params->dw[offsetof(struct amap_beiscsi_offload_params, 13118c2ecf20Sopenharmony_ci ir2t) / 32] & OFFLD_PARAMS_IR2T) >> 4); 13128c2ecf20Sopenharmony_ci AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb, imd, pwrb, 13138c2ecf20Sopenharmony_ci (params->dw[offsetof(struct amap_beiscsi_offload_params, 13148c2ecf20Sopenharmony_ci imd) / 32] & OFFLD_PARAMS_IMD) >> 5); 13158c2ecf20Sopenharmony_ci AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb, stat_sn, 13168c2ecf20Sopenharmony_ci pwrb, 13178c2ecf20Sopenharmony_ci (params->dw[offsetof(struct amap_beiscsi_offload_params, 13188c2ecf20Sopenharmony_ci exp_statsn) / 32] + 1)); 13198c2ecf20Sopenharmony_ci AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb, wrb_idx, 13208c2ecf20Sopenharmony_ci pwrb, pwrb_handle->wrb_index); 13218c2ecf20Sopenharmony_ci 13228c2ecf20Sopenharmony_ci AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb, 13238c2ecf20Sopenharmony_ci max_burst_length, pwrb, params->dw[offsetof 13248c2ecf20Sopenharmony_ci (struct amap_beiscsi_offload_params, 13258c2ecf20Sopenharmony_ci max_burst_length) / 32]); 13268c2ecf20Sopenharmony_ci 13278c2ecf20Sopenharmony_ci AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb, ptr2nextwrb, 13288c2ecf20Sopenharmony_ci pwrb, pwrb_handle->wrb_index); 13298c2ecf20Sopenharmony_ci if (pwrb_context->plast_wrb) 13308c2ecf20Sopenharmony_ci AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb, 13318c2ecf20Sopenharmony_ci ptr2nextwrb, 13328c2ecf20Sopenharmony_ci pwrb_context->plast_wrb, 13338c2ecf20Sopenharmony_ci pwrb_handle->wrb_index); 13348c2ecf20Sopenharmony_ci pwrb_context->plast_wrb = pwrb; 13358c2ecf20Sopenharmony_ci 13368c2ecf20Sopenharmony_ci AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb, 13378c2ecf20Sopenharmony_ci session_state, pwrb, 0); 13388c2ecf20Sopenharmony_ci AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb, compltonack, 13398c2ecf20Sopenharmony_ci pwrb, 1); 13408c2ecf20Sopenharmony_ci AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb, notpredblq, 13418c2ecf20Sopenharmony_ci pwrb, 0); 13428c2ecf20Sopenharmony_ci AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb, mode, pwrb, 13438c2ecf20Sopenharmony_ci 0); 13448c2ecf20Sopenharmony_ci 13458c2ecf20Sopenharmony_ci mem_descr += ISCSI_MEM_GLOBAL_HEADER; 13468c2ecf20Sopenharmony_ci AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb, 13478c2ecf20Sopenharmony_ci pad_buffer_addr_hi, pwrb, 13488c2ecf20Sopenharmony_ci mem_descr->mem_array[0].bus_address.u.a32.address_hi); 13498c2ecf20Sopenharmony_ci AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb, 13508c2ecf20Sopenharmony_ci pad_buffer_addr_lo, pwrb, 13518c2ecf20Sopenharmony_ci mem_descr->mem_array[0].bus_address.u.a32.address_lo); 13528c2ecf20Sopenharmony_ci} 13538c2ecf20Sopenharmony_ci 13548c2ecf20Sopenharmony_civoid beiscsi_offload_cxn_v2(struct beiscsi_offload_params *params, 13558c2ecf20Sopenharmony_ci struct wrb_handle *pwrb_handle, 13568c2ecf20Sopenharmony_ci struct hwi_wrb_context *pwrb_context) 13578c2ecf20Sopenharmony_ci{ 13588c2ecf20Sopenharmony_ci struct iscsi_wrb *pwrb = pwrb_handle->pwrb; 13598c2ecf20Sopenharmony_ci 13608c2ecf20Sopenharmony_ci AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb_v2, 13618c2ecf20Sopenharmony_ci max_burst_length, pwrb, params->dw[offsetof 13628c2ecf20Sopenharmony_ci (struct amap_beiscsi_offload_params, 13638c2ecf20Sopenharmony_ci max_burst_length) / 32]); 13648c2ecf20Sopenharmony_ci AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb_v2, 13658c2ecf20Sopenharmony_ci type, pwrb, 13668c2ecf20Sopenharmony_ci BE_TGT_CTX_UPDT_CMD); 13678c2ecf20Sopenharmony_ci AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb_v2, 13688c2ecf20Sopenharmony_ci ptr2nextwrb, 13698c2ecf20Sopenharmony_ci pwrb, pwrb_handle->wrb_index); 13708c2ecf20Sopenharmony_ci if (pwrb_context->plast_wrb) 13718c2ecf20Sopenharmony_ci AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb_v2, 13728c2ecf20Sopenharmony_ci ptr2nextwrb, 13738c2ecf20Sopenharmony_ci pwrb_context->plast_wrb, 13748c2ecf20Sopenharmony_ci pwrb_handle->wrb_index); 13758c2ecf20Sopenharmony_ci pwrb_context->plast_wrb = pwrb; 13768c2ecf20Sopenharmony_ci 13778c2ecf20Sopenharmony_ci AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb_v2, wrb_idx, 13788c2ecf20Sopenharmony_ci pwrb, pwrb_handle->wrb_index); 13798c2ecf20Sopenharmony_ci AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb_v2, 13808c2ecf20Sopenharmony_ci max_send_data_segment_length, pwrb, 13818c2ecf20Sopenharmony_ci params->dw[offsetof(struct amap_beiscsi_offload_params, 13828c2ecf20Sopenharmony_ci max_send_data_segment_length) / 32]); 13838c2ecf20Sopenharmony_ci AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb_v2, 13848c2ecf20Sopenharmony_ci first_burst_length, pwrb, 13858c2ecf20Sopenharmony_ci params->dw[offsetof(struct amap_beiscsi_offload_params, 13868c2ecf20Sopenharmony_ci first_burst_length) / 32]); 13878c2ecf20Sopenharmony_ci AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb_v2, 13888c2ecf20Sopenharmony_ci max_recv_dataseg_len, pwrb, 13898c2ecf20Sopenharmony_ci params->dw[offsetof(struct amap_beiscsi_offload_params, 13908c2ecf20Sopenharmony_ci max_recv_data_segment_length) / 32]); 13918c2ecf20Sopenharmony_ci AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb_v2, 13928c2ecf20Sopenharmony_ci max_cxns, pwrb, BEISCSI_MAX_CXNS); 13938c2ecf20Sopenharmony_ci AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb_v2, erl, pwrb, 13948c2ecf20Sopenharmony_ci (params->dw[offsetof(struct amap_beiscsi_offload_params, 13958c2ecf20Sopenharmony_ci erl) / 32] & OFFLD_PARAMS_ERL)); 13968c2ecf20Sopenharmony_ci AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb_v2, dde, pwrb, 13978c2ecf20Sopenharmony_ci (params->dw[offsetof(struct amap_beiscsi_offload_params, 13988c2ecf20Sopenharmony_ci dde) / 32] & OFFLD_PARAMS_DDE) >> 2); 13998c2ecf20Sopenharmony_ci AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb_v2, hde, pwrb, 14008c2ecf20Sopenharmony_ci (params->dw[offsetof(struct amap_beiscsi_offload_params, 14018c2ecf20Sopenharmony_ci hde) / 32] & OFFLD_PARAMS_HDE) >> 3); 14028c2ecf20Sopenharmony_ci AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb_v2, 14038c2ecf20Sopenharmony_ci ir2t, pwrb, 14048c2ecf20Sopenharmony_ci (params->dw[offsetof(struct amap_beiscsi_offload_params, 14058c2ecf20Sopenharmony_ci ir2t) / 32] & OFFLD_PARAMS_IR2T) >> 4); 14068c2ecf20Sopenharmony_ci AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb_v2, imd, pwrb, 14078c2ecf20Sopenharmony_ci (params->dw[offsetof(struct amap_beiscsi_offload_params, 14088c2ecf20Sopenharmony_ci imd) / 32] & OFFLD_PARAMS_IMD) >> 5); 14098c2ecf20Sopenharmony_ci AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb_v2, 14108c2ecf20Sopenharmony_ci data_seq_inorder, 14118c2ecf20Sopenharmony_ci pwrb, 14128c2ecf20Sopenharmony_ci (params->dw[offsetof(struct amap_beiscsi_offload_params, 14138c2ecf20Sopenharmony_ci data_seq_inorder) / 32] & 14148c2ecf20Sopenharmony_ci OFFLD_PARAMS_DATA_SEQ_INORDER) >> 6); 14158c2ecf20Sopenharmony_ci AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb_v2, 14168c2ecf20Sopenharmony_ci pdu_seq_inorder, 14178c2ecf20Sopenharmony_ci pwrb, 14188c2ecf20Sopenharmony_ci (params->dw[offsetof(struct amap_beiscsi_offload_params, 14198c2ecf20Sopenharmony_ci pdu_seq_inorder) / 32] & 14208c2ecf20Sopenharmony_ci OFFLD_PARAMS_PDU_SEQ_INORDER) >> 7); 14218c2ecf20Sopenharmony_ci AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb_v2, max_r2t, 14228c2ecf20Sopenharmony_ci pwrb, 14238c2ecf20Sopenharmony_ci (params->dw[offsetof(struct amap_beiscsi_offload_params, 14248c2ecf20Sopenharmony_ci max_r2t) / 32] & 14258c2ecf20Sopenharmony_ci OFFLD_PARAMS_MAX_R2T) >> 8); 14268c2ecf20Sopenharmony_ci AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb_v2, stat_sn, 14278c2ecf20Sopenharmony_ci pwrb, 14288c2ecf20Sopenharmony_ci (params->dw[offsetof(struct amap_beiscsi_offload_params, 14298c2ecf20Sopenharmony_ci exp_statsn) / 32] + 1)); 14308c2ecf20Sopenharmony_ci} 14318c2ecf20Sopenharmony_ci 14328c2ecf20Sopenharmony_ciunsigned int beiscsi_invalidate_cxn(struct beiscsi_hba *phba, 14338c2ecf20Sopenharmony_ci struct beiscsi_endpoint *beiscsi_ep) 14348c2ecf20Sopenharmony_ci{ 14358c2ecf20Sopenharmony_ci struct be_invalidate_connection_params_in *req; 14368c2ecf20Sopenharmony_ci struct be_ctrl_info *ctrl = &phba->ctrl; 14378c2ecf20Sopenharmony_ci struct be_mcc_wrb *wrb; 14388c2ecf20Sopenharmony_ci unsigned int tag = 0; 14398c2ecf20Sopenharmony_ci 14408c2ecf20Sopenharmony_ci mutex_lock(&ctrl->mbox_lock); 14418c2ecf20Sopenharmony_ci wrb = alloc_mcc_wrb(phba, &tag); 14428c2ecf20Sopenharmony_ci if (!wrb) { 14438c2ecf20Sopenharmony_ci mutex_unlock(&ctrl->mbox_lock); 14448c2ecf20Sopenharmony_ci return 0; 14458c2ecf20Sopenharmony_ci } 14468c2ecf20Sopenharmony_ci 14478c2ecf20Sopenharmony_ci req = embedded_payload(wrb); 14488c2ecf20Sopenharmony_ci be_wrb_hdr_prepare(wrb, sizeof(union be_invalidate_connection_params), 14498c2ecf20Sopenharmony_ci true, 0); 14508c2ecf20Sopenharmony_ci be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI_INI, 14518c2ecf20Sopenharmony_ci OPCODE_ISCSI_INI_DRIVER_INVALIDATE_CONNECTION, 14528c2ecf20Sopenharmony_ci sizeof(*req)); 14538c2ecf20Sopenharmony_ci req->session_handle = beiscsi_ep->fw_handle; 14548c2ecf20Sopenharmony_ci req->cid = beiscsi_ep->ep_cid; 14558c2ecf20Sopenharmony_ci if (beiscsi_ep->conn) 14568c2ecf20Sopenharmony_ci req->cleanup_type = BE_CLEANUP_TYPE_INVALIDATE; 14578c2ecf20Sopenharmony_ci else 14588c2ecf20Sopenharmony_ci req->cleanup_type = BE_CLEANUP_TYPE_ISSUE_TCP_RST; 14598c2ecf20Sopenharmony_ci /** 14608c2ecf20Sopenharmony_ci * 0 - non-persistent targets 14618c2ecf20Sopenharmony_ci * 1 - save session info on flash 14628c2ecf20Sopenharmony_ci */ 14638c2ecf20Sopenharmony_ci req->save_cfg = 0; 14648c2ecf20Sopenharmony_ci be_mcc_notify(phba, tag); 14658c2ecf20Sopenharmony_ci mutex_unlock(&ctrl->mbox_lock); 14668c2ecf20Sopenharmony_ci return tag; 14678c2ecf20Sopenharmony_ci} 14688c2ecf20Sopenharmony_ci 14698c2ecf20Sopenharmony_ciunsigned int beiscsi_upload_cxn(struct beiscsi_hba *phba, 14708c2ecf20Sopenharmony_ci struct beiscsi_endpoint *beiscsi_ep) 14718c2ecf20Sopenharmony_ci{ 14728c2ecf20Sopenharmony_ci struct be_ctrl_info *ctrl = &phba->ctrl; 14738c2ecf20Sopenharmony_ci struct be_mcc_wrb *wrb; 14748c2ecf20Sopenharmony_ci struct be_tcp_upload_params_in *req; 14758c2ecf20Sopenharmony_ci unsigned int tag; 14768c2ecf20Sopenharmony_ci 14778c2ecf20Sopenharmony_ci mutex_lock(&ctrl->mbox_lock); 14788c2ecf20Sopenharmony_ci wrb = alloc_mcc_wrb(phba, &tag); 14798c2ecf20Sopenharmony_ci if (!wrb) { 14808c2ecf20Sopenharmony_ci mutex_unlock(&ctrl->mbox_lock); 14818c2ecf20Sopenharmony_ci return 0; 14828c2ecf20Sopenharmony_ci } 14838c2ecf20Sopenharmony_ci 14848c2ecf20Sopenharmony_ci req = embedded_payload(wrb); 14858c2ecf20Sopenharmony_ci be_wrb_hdr_prepare(wrb, sizeof(union be_tcp_upload_params), true, 0); 14868c2ecf20Sopenharmony_ci be_cmd_hdr_prepare(&req->hdr, CMD_COMMON_TCP_UPLOAD, 14878c2ecf20Sopenharmony_ci OPCODE_COMMON_TCP_UPLOAD, sizeof(*req)); 14888c2ecf20Sopenharmony_ci req->id = beiscsi_ep->ep_cid; 14898c2ecf20Sopenharmony_ci if (beiscsi_ep->conn) 14908c2ecf20Sopenharmony_ci req->upload_type = BE_UPLOAD_TYPE_GRACEFUL; 14918c2ecf20Sopenharmony_ci else 14928c2ecf20Sopenharmony_ci req->upload_type = BE_UPLOAD_TYPE_ABORT; 14938c2ecf20Sopenharmony_ci be_mcc_notify(phba, tag); 14948c2ecf20Sopenharmony_ci mutex_unlock(&ctrl->mbox_lock); 14958c2ecf20Sopenharmony_ci return tag; 14968c2ecf20Sopenharmony_ci} 14978c2ecf20Sopenharmony_ci 14988c2ecf20Sopenharmony_ciint beiscsi_mgmt_invalidate_icds(struct beiscsi_hba *phba, 14998c2ecf20Sopenharmony_ci struct invldt_cmd_tbl *inv_tbl, 15008c2ecf20Sopenharmony_ci unsigned int nents) 15018c2ecf20Sopenharmony_ci{ 15028c2ecf20Sopenharmony_ci struct be_ctrl_info *ctrl = &phba->ctrl; 15038c2ecf20Sopenharmony_ci struct invldt_cmds_params_in *req; 15048c2ecf20Sopenharmony_ci struct be_dma_mem nonemb_cmd; 15058c2ecf20Sopenharmony_ci struct be_mcc_wrb *wrb; 15068c2ecf20Sopenharmony_ci unsigned int i, tag; 15078c2ecf20Sopenharmony_ci struct be_sge *sge; 15088c2ecf20Sopenharmony_ci int rc; 15098c2ecf20Sopenharmony_ci 15108c2ecf20Sopenharmony_ci if (!nents || nents > BE_INVLDT_CMD_TBL_SZ) 15118c2ecf20Sopenharmony_ci return -EINVAL; 15128c2ecf20Sopenharmony_ci 15138c2ecf20Sopenharmony_ci nonemb_cmd.size = sizeof(union be_invldt_cmds_params); 15148c2ecf20Sopenharmony_ci nonemb_cmd.va = dma_alloc_coherent(&phba->ctrl.pdev->dev, 15158c2ecf20Sopenharmony_ci nonemb_cmd.size, &nonemb_cmd.dma, 15168c2ecf20Sopenharmony_ci GFP_KERNEL); 15178c2ecf20Sopenharmony_ci if (!nonemb_cmd.va) { 15188c2ecf20Sopenharmony_ci beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_EH, 15198c2ecf20Sopenharmony_ci "BM_%d : invldt_cmds_params alloc failed\n"); 15208c2ecf20Sopenharmony_ci return -ENOMEM; 15218c2ecf20Sopenharmony_ci } 15228c2ecf20Sopenharmony_ci 15238c2ecf20Sopenharmony_ci mutex_lock(&ctrl->mbox_lock); 15248c2ecf20Sopenharmony_ci wrb = alloc_mcc_wrb(phba, &tag); 15258c2ecf20Sopenharmony_ci if (!wrb) { 15268c2ecf20Sopenharmony_ci mutex_unlock(&ctrl->mbox_lock); 15278c2ecf20Sopenharmony_ci dma_free_coherent(&phba->ctrl.pdev->dev, nonemb_cmd.size, 15288c2ecf20Sopenharmony_ci nonemb_cmd.va, nonemb_cmd.dma); 15298c2ecf20Sopenharmony_ci return -ENOMEM; 15308c2ecf20Sopenharmony_ci } 15318c2ecf20Sopenharmony_ci 15328c2ecf20Sopenharmony_ci req = nonemb_cmd.va; 15338c2ecf20Sopenharmony_ci be_wrb_hdr_prepare(wrb, nonemb_cmd.size, false, 1); 15348c2ecf20Sopenharmony_ci be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI, 15358c2ecf20Sopenharmony_ci OPCODE_COMMON_ISCSI_ERROR_RECOVERY_INVALIDATE_COMMANDS, 15368c2ecf20Sopenharmony_ci sizeof(*req)); 15378c2ecf20Sopenharmony_ci req->ref_handle = 0; 15388c2ecf20Sopenharmony_ci req->cleanup_type = CMD_ISCSI_COMMAND_INVALIDATE; 15398c2ecf20Sopenharmony_ci for (i = 0; i < nents; i++) { 15408c2ecf20Sopenharmony_ci req->table[i].icd = inv_tbl[i].icd; 15418c2ecf20Sopenharmony_ci req->table[i].cid = inv_tbl[i].cid; 15428c2ecf20Sopenharmony_ci req->icd_count++; 15438c2ecf20Sopenharmony_ci } 15448c2ecf20Sopenharmony_ci sge = nonembedded_sgl(wrb); 15458c2ecf20Sopenharmony_ci sge->pa_hi = cpu_to_le32(upper_32_bits(nonemb_cmd.dma)); 15468c2ecf20Sopenharmony_ci sge->pa_lo = cpu_to_le32(lower_32_bits(nonemb_cmd.dma)); 15478c2ecf20Sopenharmony_ci sge->len = cpu_to_le32(nonemb_cmd.size); 15488c2ecf20Sopenharmony_ci 15498c2ecf20Sopenharmony_ci be_mcc_notify(phba, tag); 15508c2ecf20Sopenharmony_ci mutex_unlock(&ctrl->mbox_lock); 15518c2ecf20Sopenharmony_ci 15528c2ecf20Sopenharmony_ci rc = beiscsi_mccq_compl_wait(phba, tag, NULL, &nonemb_cmd); 15538c2ecf20Sopenharmony_ci if (rc != -EBUSY) 15548c2ecf20Sopenharmony_ci dma_free_coherent(&phba->ctrl.pdev->dev, nonemb_cmd.size, 15558c2ecf20Sopenharmony_ci nonemb_cmd.va, nonemb_cmd.dma); 15568c2ecf20Sopenharmony_ci return rc; 15578c2ecf20Sopenharmony_ci} 1558