Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1 | /** |
Jayamohan Kallickal | 255fa9a | 2011-03-25 14:23:57 -0700 | [diff] [blame] | 2 | * Copyright (C) 2005 - 2011 Emulex |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3 | * All rights reserved. |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or |
| 6 | * modify it under the terms of the GNU General Public License version 2 |
| 7 | * as published by the Free Software Foundation. The full GNU General |
| 8 | * Public License is included in this distribution in the file called COPYING. |
| 9 | * |
Jayamohan Kallickal | 255fa9a | 2011-03-25 14:23:57 -0700 | [diff] [blame] | 10 | * Written by: Jayamohan Kallickal (jayamohan.kallickal@emulex.com) |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 11 | * |
| 12 | * Contact Information: |
Jayamohan Kallickal | 255fa9a | 2011-03-25 14:23:57 -0700 | [diff] [blame] | 13 | * linux-drivers@emulex.com |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 14 | * |
Jayamohan Kallickal | 255fa9a | 2011-03-25 14:23:57 -0700 | [diff] [blame] | 15 | * Emulex |
| 16 | * 3333 Susan Street |
| 17 | * Costa Mesa, CA 92626 |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 18 | */ |
| 19 | |
| 20 | #include "be_mgmt.h" |
| 21 | #include "be_iscsi.h" |
Jayamohan Kallickal | c7acc5b | 2010-07-22 04:29:18 +0530 | [diff] [blame] | 22 | #include <scsi/scsi_transport_iscsi.h> |
| 23 | |
| 24 | unsigned int beiscsi_get_boot_target(struct beiscsi_hba *phba) |
| 25 | { |
| 26 | struct be_ctrl_info *ctrl = &phba->ctrl; |
| 27 | struct be_mcc_wrb *wrb; |
| 28 | struct be_cmd_req_get_mac_addr *req; |
| 29 | unsigned int tag = 0; |
| 30 | |
| 31 | SE_DEBUG(DBG_LVL_8, "In bescsi_get_boot_target\n"); |
| 32 | spin_lock(&ctrl->mbox_lock); |
| 33 | tag = alloc_mcc_tag(phba); |
| 34 | if (!tag) { |
| 35 | spin_unlock(&ctrl->mbox_lock); |
| 36 | return tag; |
| 37 | } |
| 38 | |
| 39 | wrb = wrb_from_mccq(phba); |
| 40 | req = embedded_payload(wrb); |
| 41 | wrb->tag0 |= tag; |
| 42 | be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0); |
| 43 | be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI_INI, |
| 44 | OPCODE_ISCSI_INI_BOOT_GET_BOOT_TARGET, |
| 45 | sizeof(*req)); |
| 46 | |
| 47 | be_mcc_notify(phba); |
| 48 | spin_unlock(&ctrl->mbox_lock); |
| 49 | return tag; |
| 50 | } |
| 51 | |
| 52 | unsigned int beiscsi_get_session_info(struct beiscsi_hba *phba, |
| 53 | u32 boot_session_handle, |
| 54 | struct be_dma_mem *nonemb_cmd) |
| 55 | { |
| 56 | struct be_ctrl_info *ctrl = &phba->ctrl; |
| 57 | struct be_mcc_wrb *wrb; |
| 58 | unsigned int tag = 0; |
| 59 | struct be_cmd_req_get_session *req; |
| 60 | struct be_cmd_resp_get_session *resp; |
| 61 | struct be_sge *sge; |
| 62 | |
| 63 | SE_DEBUG(DBG_LVL_8, "In beiscsi_get_session_info\n"); |
| 64 | spin_lock(&ctrl->mbox_lock); |
| 65 | tag = alloc_mcc_tag(phba); |
| 66 | if (!tag) { |
| 67 | spin_unlock(&ctrl->mbox_lock); |
| 68 | return tag; |
| 69 | } |
| 70 | |
| 71 | nonemb_cmd->size = sizeof(*resp); |
| 72 | req = nonemb_cmd->va; |
| 73 | memset(req, 0, sizeof(*req)); |
| 74 | wrb = wrb_from_mccq(phba); |
| 75 | sge = nonembedded_sgl(wrb); |
| 76 | wrb->tag0 |= tag; |
| 77 | |
| 78 | |
| 79 | wrb->tag0 |= tag; |
| 80 | be_wrb_hdr_prepare(wrb, sizeof(*req), false, 1); |
| 81 | be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI_INI, |
| 82 | OPCODE_ISCSI_INI_SESSION_GET_A_SESSION, |
| 83 | sizeof(*resp)); |
| 84 | req->session_handle = boot_session_handle; |
| 85 | sge->pa_hi = cpu_to_le32(upper_32_bits(nonemb_cmd->dma)); |
| 86 | sge->pa_lo = cpu_to_le32(nonemb_cmd->dma & 0xFFFFFFFF); |
| 87 | sge->len = cpu_to_le32(nonemb_cmd->size); |
| 88 | |
| 89 | be_mcc_notify(phba); |
| 90 | spin_unlock(&ctrl->mbox_lock); |
| 91 | return tag; |
| 92 | } |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 93 | |
Jayamohan Kallickal | 03a1231 | 2010-07-22 04:17:16 +0530 | [diff] [blame] | 94 | int mgmt_get_fw_config(struct be_ctrl_info *ctrl, |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 95 | struct beiscsi_hba *phba) |
| 96 | { |
| 97 | struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem); |
| 98 | struct be_fw_cfg *req = embedded_payload(wrb); |
| 99 | int status = 0; |
| 100 | |
| 101 | spin_lock(&ctrl->mbox_lock); |
| 102 | memset(wrb, 0, sizeof(*wrb)); |
| 103 | |
| 104 | be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0); |
| 105 | |
| 106 | be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON, |
| 107 | OPCODE_COMMON_QUERY_FIRMWARE_CONFIG, sizeof(*req)); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 108 | status = be_mbox_notify(ctrl); |
| 109 | if (!status) { |
| 110 | struct be_fw_cfg *pfw_cfg; |
| 111 | pfw_cfg = req; |
| 112 | phba->fw_config.phys_port = pfw_cfg->phys_port; |
| 113 | phba->fw_config.iscsi_icd_start = |
| 114 | pfw_cfg->ulp[0].icd_base; |
| 115 | phba->fw_config.iscsi_icd_count = |
| 116 | pfw_cfg->ulp[0].icd_count; |
| 117 | phba->fw_config.iscsi_cid_start = |
| 118 | pfw_cfg->ulp[0].sq_base; |
| 119 | phba->fw_config.iscsi_cid_count = |
| 120 | pfw_cfg->ulp[0].sq_count; |
Jayamohan Kallickal | 7da5087 | 2010-01-05 05:04:12 +0530 | [diff] [blame] | 121 | if (phba->fw_config.iscsi_cid_count > (BE2_MAX_SESSIONS / 2)) { |
Jayamohan Kallickal | a3babda | 2010-01-07 01:51:44 +0530 | [diff] [blame] | 122 | SE_DEBUG(DBG_LVL_8, |
Jayamohan Kallickal | 3cbb7a7 | 2010-07-22 04:27:47 +0530 | [diff] [blame] | 123 | "FW reported MAX CXNS as %d\t" |
Jayamohan Kallickal | a3babda | 2010-01-07 01:51:44 +0530 | [diff] [blame] | 124 | "Max Supported = %d.\n", |
| 125 | phba->fw_config.iscsi_cid_count, |
| 126 | BE2_MAX_SESSIONS); |
| 127 | phba->fw_config.iscsi_cid_count = BE2_MAX_SESSIONS / 2; |
Jayamohan Kallickal | 7da5087 | 2010-01-05 05:04:12 +0530 | [diff] [blame] | 128 | } |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 129 | } else { |
| 130 | shost_printk(KERN_WARNING, phba->shost, |
Jayamohan Kallickal | 457ff3b | 2010-07-22 04:16:00 +0530 | [diff] [blame] | 131 | "Failed in mgmt_get_fw_config\n"); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 132 | } |
| 133 | |
| 134 | spin_unlock(&ctrl->mbox_lock); |
| 135 | return status; |
| 136 | } |
| 137 | |
Jayamohan Kallickal | 03a1231 | 2010-07-22 04:17:16 +0530 | [diff] [blame] | 138 | int mgmt_check_supported_fw(struct be_ctrl_info *ctrl, |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 139 | struct beiscsi_hba *phba) |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 140 | { |
| 141 | struct be_dma_mem nonemb_cmd; |
| 142 | struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem); |
| 143 | struct be_mgmt_controller_attributes *req; |
| 144 | struct be_sge *sge = nonembedded_sgl(wrb); |
| 145 | int status = 0; |
| 146 | |
| 147 | nonemb_cmd.va = pci_alloc_consistent(ctrl->pdev, |
| 148 | sizeof(struct be_mgmt_controller_attributes), |
| 149 | &nonemb_cmd.dma); |
| 150 | if (nonemb_cmd.va == NULL) { |
| 151 | SE_DEBUG(DBG_LVL_1, |
| 152 | "Failed to allocate memory for mgmt_check_supported_fw" |
| 153 | "\n"); |
Jayamohan Kallickal | d3ad2bb | 2010-07-22 04:16:38 +0530 | [diff] [blame] | 154 | return -ENOMEM; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 155 | } |
| 156 | nonemb_cmd.size = sizeof(struct be_mgmt_controller_attributes); |
| 157 | req = nonemb_cmd.va; |
Jayamohan Kallickal | f98c96b | 2010-02-11 05:11:15 +0530 | [diff] [blame] | 158 | memset(req, 0, sizeof(*req)); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 159 | spin_lock(&ctrl->mbox_lock); |
| 160 | memset(wrb, 0, sizeof(*wrb)); |
| 161 | be_wrb_hdr_prepare(wrb, sizeof(*req), false, 1); |
| 162 | be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON, |
| 163 | OPCODE_COMMON_GET_CNTL_ATTRIBUTES, sizeof(*req)); |
| 164 | sge->pa_hi = cpu_to_le32(upper_32_bits(nonemb_cmd.dma)); |
| 165 | sge->pa_lo = cpu_to_le32(nonemb_cmd.dma & 0xFFFFFFFF); |
| 166 | sge->len = cpu_to_le32(nonemb_cmd.size); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 167 | status = be_mbox_notify(ctrl); |
| 168 | if (!status) { |
| 169 | struct be_mgmt_controller_attributes_resp *resp = nonemb_cmd.va; |
| 170 | SE_DEBUG(DBG_LVL_8, "Firmware version of CMD: %s\n", |
| 171 | resp->params.hba_attribs.flashrom_version_string); |
| 172 | SE_DEBUG(DBG_LVL_8, "Firmware version is : %s\n", |
| 173 | resp->params.hba_attribs.firmware_version_string); |
| 174 | SE_DEBUG(DBG_LVL_8, |
| 175 | "Developer Build, not performing version check...\n"); |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 176 | phba->fw_config.iscsi_features = |
| 177 | resp->params.hba_attribs.iscsi_features; |
| 178 | SE_DEBUG(DBG_LVL_8, " phba->fw_config.iscsi_features = %d\n", |
| 179 | phba->fw_config.iscsi_features); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 180 | } else |
| 181 | SE_DEBUG(DBG_LVL_1, " Failed in mgmt_check_supported_fw\n"); |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 182 | spin_unlock(&ctrl->mbox_lock); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 183 | if (nonemb_cmd.va) |
| 184 | pci_free_consistent(ctrl->pdev, nonemb_cmd.size, |
| 185 | nonemb_cmd.va, nonemb_cmd.dma); |
| 186 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 187 | return status; |
| 188 | } |
| 189 | |
Jayamohan Kallickal | 03a1231 | 2010-07-22 04:17:16 +0530 | [diff] [blame] | 190 | int mgmt_epfw_cleanup(struct beiscsi_hba *phba, unsigned short chute) |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 191 | { |
| 192 | struct be_ctrl_info *ctrl = &phba->ctrl; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 193 | struct be_mcc_wrb *wrb = wrb_from_mccq(phba); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 194 | struct iscsi_cleanup_req *req = embedded_payload(wrb); |
| 195 | int status = 0; |
| 196 | |
| 197 | spin_lock(&ctrl->mbox_lock); |
| 198 | memset(wrb, 0, sizeof(*wrb)); |
| 199 | |
| 200 | be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0); |
| 201 | be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI, |
| 202 | OPCODE_COMMON_ISCSI_CLEANUP, sizeof(*req)); |
| 203 | |
| 204 | req->chute = chute; |
Jayamohan Kallickal | 069adc7 | 2011-04-29 14:30:07 -0500 | [diff] [blame] | 205 | req->hdr_ring_id = cpu_to_le16(HWI_GET_DEF_HDRQ_ID(phba)); |
| 206 | req->data_ring_id = cpu_to_le16(HWI_GET_DEF_BUFQ_ID(phba)); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 207 | |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 208 | status = be_mcc_notify_wait(phba); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 209 | if (status) |
| 210 | shost_printk(KERN_WARNING, phba->shost, |
| 211 | " mgmt_epfw_cleanup , FAILED\n"); |
| 212 | spin_unlock(&ctrl->mbox_lock); |
| 213 | return status; |
| 214 | } |
| 215 | |
Jayamohan Kallickal | 03a1231 | 2010-07-22 04:17:16 +0530 | [diff] [blame] | 216 | unsigned int mgmt_invalidate_icds(struct beiscsi_hba *phba, |
Jayamohan Kallickal | 4183122 | 2010-02-20 08:02:39 +0530 | [diff] [blame] | 217 | struct invalidate_command_table *inv_tbl, |
Jayamohan Kallickal | 3cbb7a7 | 2010-07-22 04:27:47 +0530 | [diff] [blame] | 218 | unsigned int num_invalidate, unsigned int cid, |
| 219 | struct be_dma_mem *nonemb_cmd) |
| 220 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 221 | { |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 222 | struct be_ctrl_info *ctrl = &phba->ctrl; |
Jayamohan Kallickal | 756d29c | 2010-01-05 05:10:46 +0530 | [diff] [blame] | 223 | struct be_mcc_wrb *wrb; |
| 224 | struct be_sge *sge; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 225 | struct invalidate_commands_params_in *req; |
Jayamohan Kallickal | 4183122 | 2010-02-20 08:02:39 +0530 | [diff] [blame] | 226 | unsigned int i, tag = 0; |
Jayamohan Kallickal | 756d29c | 2010-01-05 05:10:46 +0530 | [diff] [blame] | 227 | |
| 228 | spin_lock(&ctrl->mbox_lock); |
| 229 | tag = alloc_mcc_tag(phba); |
| 230 | if (!tag) { |
| 231 | spin_unlock(&ctrl->mbox_lock); |
| 232 | return tag; |
| 233 | } |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 234 | |
Jayamohan Kallickal | 3cbb7a7 | 2010-07-22 04:27:47 +0530 | [diff] [blame] | 235 | req = nonemb_cmd->va; |
Jayamohan Kallickal | f98c96b | 2010-02-11 05:11:15 +0530 | [diff] [blame] | 236 | memset(req, 0, sizeof(*req)); |
Jayamohan Kallickal | 756d29c | 2010-01-05 05:10:46 +0530 | [diff] [blame] | 237 | wrb = wrb_from_mccq(phba); |
| 238 | sge = nonembedded_sgl(wrb); |
| 239 | wrb->tag0 |= tag; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 240 | |
| 241 | be_wrb_hdr_prepare(wrb, sizeof(*req), false, 1); |
| 242 | be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI, |
| 243 | OPCODE_COMMON_ISCSI_ERROR_RECOVERY_INVALIDATE_COMMANDS, |
| 244 | sizeof(*req)); |
| 245 | req->ref_handle = 0; |
| 246 | req->cleanup_type = CMD_ISCSI_COMMAND_INVALIDATE; |
Jayamohan Kallickal | 4183122 | 2010-02-20 08:02:39 +0530 | [diff] [blame] | 247 | for (i = 0; i < num_invalidate; i++) { |
| 248 | req->table[i].icd = inv_tbl->icd; |
| 249 | req->table[i].cid = inv_tbl->cid; |
| 250 | req->icd_count++; |
| 251 | inv_tbl++; |
| 252 | } |
Jayamohan Kallickal | 3cbb7a7 | 2010-07-22 04:27:47 +0530 | [diff] [blame] | 253 | sge->pa_hi = cpu_to_le32(upper_32_bits(nonemb_cmd->dma)); |
| 254 | sge->pa_lo = cpu_to_le32(nonemb_cmd->dma & 0xFFFFFFFF); |
| 255 | sge->len = cpu_to_le32(nonemb_cmd->size); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 256 | |
Jayamohan Kallickal | 756d29c | 2010-01-05 05:10:46 +0530 | [diff] [blame] | 257 | be_mcc_notify(phba); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 258 | spin_unlock(&ctrl->mbox_lock); |
Jayamohan Kallickal | 756d29c | 2010-01-05 05:10:46 +0530 | [diff] [blame] | 259 | return tag; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 260 | } |
| 261 | |
Jayamohan Kallickal | 03a1231 | 2010-07-22 04:17:16 +0530 | [diff] [blame] | 262 | unsigned int mgmt_invalidate_connection(struct beiscsi_hba *phba, |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 263 | struct beiscsi_endpoint *beiscsi_ep, |
| 264 | unsigned short cid, |
| 265 | unsigned short issue_reset, |
| 266 | unsigned short savecfg_flag) |
| 267 | { |
| 268 | struct be_ctrl_info *ctrl = &phba->ctrl; |
Jayamohan Kallickal | 756d29c | 2010-01-05 05:10:46 +0530 | [diff] [blame] | 269 | struct be_mcc_wrb *wrb; |
| 270 | struct iscsi_invalidate_connection_params_in *req; |
| 271 | unsigned int tag = 0; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 272 | |
| 273 | spin_lock(&ctrl->mbox_lock); |
Jayamohan Kallickal | 756d29c | 2010-01-05 05:10:46 +0530 | [diff] [blame] | 274 | tag = alloc_mcc_tag(phba); |
| 275 | if (!tag) { |
| 276 | spin_unlock(&ctrl->mbox_lock); |
| 277 | return tag; |
| 278 | } |
| 279 | wrb = wrb_from_mccq(phba); |
| 280 | wrb->tag0 |= tag; |
| 281 | req = embedded_payload(wrb); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 282 | |
| 283 | be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0); |
| 284 | be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI_INI, |
| 285 | OPCODE_ISCSI_INI_DRIVER_INVALIDATE_CONNECTION, |
| 286 | sizeof(*req)); |
| 287 | req->session_handle = beiscsi_ep->fw_handle; |
| 288 | req->cid = cid; |
| 289 | if (issue_reset) |
| 290 | req->cleanup_type = CMD_ISCSI_CONNECTION_ISSUE_TCP_RST; |
| 291 | else |
| 292 | req->cleanup_type = CMD_ISCSI_CONNECTION_INVALIDATE; |
| 293 | req->save_cfg = savecfg_flag; |
Jayamohan Kallickal | 756d29c | 2010-01-05 05:10:46 +0530 | [diff] [blame] | 294 | be_mcc_notify(phba); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 295 | spin_unlock(&ctrl->mbox_lock); |
Jayamohan Kallickal | 756d29c | 2010-01-05 05:10:46 +0530 | [diff] [blame] | 296 | return tag; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 297 | } |
| 298 | |
Jayamohan Kallickal | 03a1231 | 2010-07-22 04:17:16 +0530 | [diff] [blame] | 299 | unsigned int mgmt_upload_connection(struct beiscsi_hba *phba, |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 300 | unsigned short cid, unsigned int upload_flag) |
| 301 | { |
| 302 | struct be_ctrl_info *ctrl = &phba->ctrl; |
Jayamohan Kallickal | 756d29c | 2010-01-05 05:10:46 +0530 | [diff] [blame] | 303 | struct be_mcc_wrb *wrb; |
| 304 | struct tcp_upload_params_in *req; |
| 305 | unsigned int tag = 0; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 306 | |
| 307 | spin_lock(&ctrl->mbox_lock); |
Jayamohan Kallickal | 756d29c | 2010-01-05 05:10:46 +0530 | [diff] [blame] | 308 | tag = alloc_mcc_tag(phba); |
| 309 | if (!tag) { |
| 310 | spin_unlock(&ctrl->mbox_lock); |
| 311 | return tag; |
| 312 | } |
| 313 | wrb = wrb_from_mccq(phba); |
| 314 | req = embedded_payload(wrb); |
| 315 | wrb->tag0 |= tag; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 316 | |
| 317 | be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0); |
| 318 | be_cmd_hdr_prepare(&req->hdr, CMD_COMMON_TCP_UPLOAD, |
| 319 | OPCODE_COMMON_TCP_UPLOAD, sizeof(*req)); |
| 320 | req->id = (unsigned short)cid; |
| 321 | req->upload_type = (unsigned char)upload_flag; |
Jayamohan Kallickal | 756d29c | 2010-01-05 05:10:46 +0530 | [diff] [blame] | 322 | be_mcc_notify(phba); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 323 | spin_unlock(&ctrl->mbox_lock); |
Jayamohan Kallickal | 756d29c | 2010-01-05 05:10:46 +0530 | [diff] [blame] | 324 | return tag; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 325 | } |
| 326 | |
| 327 | int mgmt_open_connection(struct beiscsi_hba *phba, |
| 328 | struct sockaddr *dst_addr, |
Jayamohan Kallickal | 3cbb7a7 | 2010-07-22 04:27:47 +0530 | [diff] [blame] | 329 | struct beiscsi_endpoint *beiscsi_ep, |
| 330 | struct be_dma_mem *nonemb_cmd) |
| 331 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 332 | { |
| 333 | struct hwi_controller *phwi_ctrlr; |
| 334 | struct hwi_context_memory *phwi_context; |
| 335 | struct sockaddr_in *daddr_in = (struct sockaddr_in *)dst_addr; |
| 336 | struct sockaddr_in6 *daddr_in6 = (struct sockaddr_in6 *)dst_addr; |
| 337 | struct be_ctrl_info *ctrl = &phba->ctrl; |
Jayamohan Kallickal | 756d29c | 2010-01-05 05:10:46 +0530 | [diff] [blame] | 338 | struct be_mcc_wrb *wrb; |
| 339 | struct tcp_connect_and_offload_in *req; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 340 | unsigned short def_hdr_id; |
| 341 | unsigned short def_data_id; |
| 342 | struct phys_addr template_address = { 0, 0 }; |
| 343 | struct phys_addr *ptemplate_address; |
Jayamohan Kallickal | 756d29c | 2010-01-05 05:10:46 +0530 | [diff] [blame] | 344 | unsigned int tag = 0; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 345 | unsigned int i; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 346 | unsigned short cid = beiscsi_ep->ep_cid; |
Jayamohan Kallickal | 3cbb7a7 | 2010-07-22 04:27:47 +0530 | [diff] [blame] | 347 | struct be_sge *sge; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 348 | |
| 349 | phwi_ctrlr = phba->phwi_ctrlr; |
| 350 | phwi_context = phwi_ctrlr->phwi_ctxt; |
| 351 | def_hdr_id = (unsigned short)HWI_GET_DEF_HDRQ_ID(phba); |
| 352 | def_data_id = (unsigned short)HWI_GET_DEF_BUFQ_ID(phba); |
| 353 | |
| 354 | ptemplate_address = &template_address; |
| 355 | ISCSI_GET_PDU_TEMPLATE_ADDRESS(phba, ptemplate_address); |
| 356 | spin_lock(&ctrl->mbox_lock); |
Jayamohan Kallickal | 756d29c | 2010-01-05 05:10:46 +0530 | [diff] [blame] | 357 | tag = alloc_mcc_tag(phba); |
| 358 | if (!tag) { |
| 359 | spin_unlock(&ctrl->mbox_lock); |
| 360 | return tag; |
| 361 | } |
| 362 | wrb = wrb_from_mccq(phba); |
Jayamohan Kallickal | 3cbb7a7 | 2010-07-22 04:27:47 +0530 | [diff] [blame] | 363 | memset(wrb, 0, sizeof(*wrb)); |
| 364 | sge = nonembedded_sgl(wrb); |
| 365 | |
| 366 | req = nonemb_cmd->va; |
| 367 | memset(req, 0, sizeof(*req)); |
Jayamohan Kallickal | 756d29c | 2010-01-05 05:10:46 +0530 | [diff] [blame] | 368 | wrb->tag0 |= tag; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 369 | |
Jayamohan Kallickal | b15d05b | 2010-08-12 23:36:06 +0530 | [diff] [blame] | 370 | be_wrb_hdr_prepare(wrb, sizeof(*req), false, 1); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 371 | be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI, |
| 372 | OPCODE_COMMON_ISCSI_TCP_CONNECT_AND_OFFLOAD, |
| 373 | sizeof(*req)); |
| 374 | if (dst_addr->sa_family == PF_INET) { |
| 375 | __be32 s_addr = daddr_in->sin_addr.s_addr; |
| 376 | req->ip_address.ip_type = BE2_IPV4; |
| 377 | req->ip_address.ip_address[0] = s_addr & 0x000000ff; |
| 378 | req->ip_address.ip_address[1] = (s_addr & 0x0000ff00) >> 8; |
| 379 | req->ip_address.ip_address[2] = (s_addr & 0x00ff0000) >> 16; |
| 380 | req->ip_address.ip_address[3] = (s_addr & 0xff000000) >> 24; |
| 381 | req->tcp_port = ntohs(daddr_in->sin_port); |
| 382 | beiscsi_ep->dst_addr = daddr_in->sin_addr.s_addr; |
| 383 | beiscsi_ep->dst_tcpport = ntohs(daddr_in->sin_port); |
| 384 | beiscsi_ep->ip_type = BE2_IPV4; |
| 385 | } else if (dst_addr->sa_family == PF_INET6) { |
| 386 | req->ip_address.ip_type = BE2_IPV6; |
| 387 | memcpy(&req->ip_address.ip_address, |
| 388 | &daddr_in6->sin6_addr.in6_u.u6_addr8, 16); |
| 389 | req->tcp_port = ntohs(daddr_in6->sin6_port); |
| 390 | beiscsi_ep->dst_tcpport = ntohs(daddr_in6->sin6_port); |
| 391 | memcpy(&beiscsi_ep->dst6_addr, |
| 392 | &daddr_in6->sin6_addr.in6_u.u6_addr8, 16); |
| 393 | beiscsi_ep->ip_type = BE2_IPV6; |
| 394 | } else{ |
| 395 | shost_printk(KERN_ERR, phba->shost, "unknown addr family %d\n", |
| 396 | dst_addr->sa_family); |
| 397 | spin_unlock(&ctrl->mbox_lock); |
Jayamohan Kallickal | 5db3f33 | 2010-07-22 04:24:22 +0530 | [diff] [blame] | 398 | free_mcc_tag(&phba->ctrl, tag); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 399 | return -EINVAL; |
| 400 | |
| 401 | } |
| 402 | req->cid = cid; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 403 | i = phba->nxt_cqid++; |
| 404 | if (phba->nxt_cqid == phba->num_cpus) |
| 405 | phba->nxt_cqid = 0; |
| 406 | req->cq_id = phwi_context->be_cq[i].id; |
Jayamohan Kallickal | 457ff3b | 2010-07-22 04:16:00 +0530 | [diff] [blame] | 407 | SE_DEBUG(DBG_LVL_8, "i=%d cq_id=%d\n", i, req->cq_id); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 408 | req->defq_id = def_hdr_id; |
| 409 | req->hdr_ring_id = def_hdr_id; |
| 410 | req->data_ring_id = def_data_id; |
| 411 | req->do_offload = 1; |
| 412 | req->dataout_template_pa.lo = ptemplate_address->lo; |
| 413 | req->dataout_template_pa.hi = ptemplate_address->hi; |
Jayamohan Kallickal | 3cbb7a7 | 2010-07-22 04:27:47 +0530 | [diff] [blame] | 414 | sge->pa_hi = cpu_to_le32(upper_32_bits(nonemb_cmd->dma)); |
| 415 | sge->pa_lo = cpu_to_le32(nonemb_cmd->dma & 0xFFFFFFFF); |
| 416 | sge->len = cpu_to_le32(nonemb_cmd->size); |
Jayamohan Kallickal | 756d29c | 2010-01-05 05:10:46 +0530 | [diff] [blame] | 417 | be_mcc_notify(phba); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 418 | spin_unlock(&ctrl->mbox_lock); |
Jayamohan Kallickal | 756d29c | 2010-01-05 05:10:46 +0530 | [diff] [blame] | 419 | return tag; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 420 | } |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 421 | |
Jayamohan Kallickal | 756d29c | 2010-01-05 05:10:46 +0530 | [diff] [blame] | 422 | unsigned int be_cmd_get_mac_addr(struct beiscsi_hba *phba) |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 423 | { |
| 424 | struct be_ctrl_info *ctrl = &phba->ctrl; |
Jayamohan Kallickal | 756d29c | 2010-01-05 05:10:46 +0530 | [diff] [blame] | 425 | struct be_mcc_wrb *wrb; |
| 426 | struct be_cmd_req_get_mac_addr *req; |
| 427 | unsigned int tag = 0; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 428 | |
| 429 | SE_DEBUG(DBG_LVL_8, "In be_cmd_get_mac_addr\n"); |
| 430 | spin_lock(&ctrl->mbox_lock); |
Jayamohan Kallickal | 756d29c | 2010-01-05 05:10:46 +0530 | [diff] [blame] | 431 | tag = alloc_mcc_tag(phba); |
| 432 | if (!tag) { |
| 433 | spin_unlock(&ctrl->mbox_lock); |
| 434 | return tag; |
| 435 | } |
| 436 | |
| 437 | wrb = wrb_from_mccq(phba); |
| 438 | req = embedded_payload(wrb); |
| 439 | wrb->tag0 |= tag; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 440 | be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0); |
| 441 | be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI, |
| 442 | OPCODE_COMMON_ISCSI_NTWK_GET_NIC_CONFIG, |
| 443 | sizeof(*req)); |
| 444 | |
Jayamohan Kallickal | 756d29c | 2010-01-05 05:10:46 +0530 | [diff] [blame] | 445 | be_mcc_notify(phba); |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 446 | spin_unlock(&ctrl->mbox_lock); |
Jayamohan Kallickal | 756d29c | 2010-01-05 05:10:46 +0530 | [diff] [blame] | 447 | return tag; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 448 | } |
| 449 | |