Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 1 | /* |
| 2 | * QLogic Fibre Channel HBA Driver |
Andrew Vasquez | 07e264b | 2011-03-30 11:46:23 -0700 | [diff] [blame] | 3 | * Copyright (c) 2003-2011 QLogic Corporation |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 4 | * |
| 5 | * See LICENSE.qla2xxx for copyright and licensing details. |
| 6 | */ |
| 7 | #include "qla_def.h" |
| 8 | |
| 9 | #include <linux/kthread.h> |
| 10 | #include <linux/vmalloc.h> |
| 11 | #include <linux/delay.h> |
| 12 | |
| 13 | /* BSG support for ELS/CT pass through */ |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame^] | 14 | void |
| 15 | qla2x00_bsg_job_done(void *data, void *ptr, int res) |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 16 | { |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame^] | 17 | srb_t *sp = (srb_t *)ptr; |
| 18 | struct scsi_qla_host *vha = (scsi_qla_host_t *)data; |
| 19 | struct fc_bsg_job *bsg_job = sp->u.bsg_job; |
| 20 | |
| 21 | bsg_job->reply->result = res; |
| 22 | bsg_job->job_done(bsg_job); |
| 23 | sp->free(vha, sp); |
| 24 | } |
| 25 | |
| 26 | void |
| 27 | qla2x00_bsg_sp_free(void *data, void *ptr) |
| 28 | { |
| 29 | srb_t *sp = (srb_t *)ptr; |
| 30 | struct scsi_qla_host *vha = (scsi_qla_host_t *)data; |
| 31 | struct fc_bsg_job *bsg_job = sp->u.bsg_job; |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 32 | struct qla_hw_data *ha = vha->hw; |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 33 | |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame^] | 34 | dma_unmap_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list, |
| 35 | bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE); |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 36 | |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame^] | 37 | dma_unmap_sg(&ha->pdev->dev, bsg_job->reply_payload.sg_list, |
| 38 | bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE); |
| 39 | |
| 40 | if (sp->type == SRB_CT_CMD || |
| 41 | sp->type == SRB_ELS_CMD_HST) |
| 42 | kfree(sp->fcport); |
| 43 | mempool_free(sp, vha->hw->srb_mempool); |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 44 | } |
| 45 | |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 46 | int |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 47 | qla24xx_fcp_prio_cfg_valid(scsi_qla_host_t *vha, |
| 48 | struct qla_fcp_prio_cfg *pri_cfg, uint8_t flag) |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 49 | { |
| 50 | int i, ret, num_valid; |
| 51 | uint8_t *bcode; |
| 52 | struct qla_fcp_prio_entry *pri_entry; |
Madhuranath Iyengar | 2f0f3f4 | 2010-07-23 15:28:24 +0500 | [diff] [blame] | 53 | uint32_t *bcode_val_ptr, bcode_val; |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 54 | |
| 55 | ret = 1; |
| 56 | num_valid = 0; |
| 57 | bcode = (uint8_t *)pri_cfg; |
Madhuranath Iyengar | 2f0f3f4 | 2010-07-23 15:28:24 +0500 | [diff] [blame] | 58 | bcode_val_ptr = (uint32_t *)pri_cfg; |
| 59 | bcode_val = (uint32_t)(*bcode_val_ptr); |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 60 | |
Madhuranath Iyengar | 2f0f3f4 | 2010-07-23 15:28:24 +0500 | [diff] [blame] | 61 | if (bcode_val == 0xFFFFFFFF) { |
| 62 | /* No FCP Priority config data in flash */ |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 63 | ql_dbg(ql_dbg_user, vha, 0x7051, |
| 64 | "No FCP Priority config data.\n"); |
Madhuranath Iyengar | 2f0f3f4 | 2010-07-23 15:28:24 +0500 | [diff] [blame] | 65 | return 0; |
| 66 | } |
| 67 | |
| 68 | if (bcode[0] != 'H' || bcode[1] != 'Q' || bcode[2] != 'O' || |
| 69 | bcode[3] != 'S') { |
| 70 | /* Invalid FCP priority data header*/ |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 71 | ql_dbg(ql_dbg_user, vha, 0x7052, |
| 72 | "Invalid FCP Priority data header. bcode=0x%x.\n", |
| 73 | bcode_val); |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 74 | return 0; |
| 75 | } |
| 76 | if (flag != 1) |
| 77 | return ret; |
| 78 | |
| 79 | pri_entry = &pri_cfg->entry[0]; |
| 80 | for (i = 0; i < pri_cfg->num_entries; i++) { |
| 81 | if (pri_entry->flags & FCP_PRIO_ENTRY_TAG_VALID) |
| 82 | num_valid++; |
| 83 | pri_entry++; |
| 84 | } |
| 85 | |
Madhuranath Iyengar | 2f0f3f4 | 2010-07-23 15:28:24 +0500 | [diff] [blame] | 86 | if (num_valid == 0) { |
| 87 | /* No valid FCP priority data entries */ |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 88 | ql_dbg(ql_dbg_user, vha, 0x7053, |
| 89 | "No valid FCP Priority data entries.\n"); |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 90 | ret = 0; |
Madhuranath Iyengar | 2f0f3f4 | 2010-07-23 15:28:24 +0500 | [diff] [blame] | 91 | } else { |
| 92 | /* FCP priority data is valid */ |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 93 | ql_dbg(ql_dbg_user, vha, 0x7054, |
| 94 | "Valid FCP priority data. num entries = %d.\n", |
| 95 | num_valid); |
Madhuranath Iyengar | 2f0f3f4 | 2010-07-23 15:28:24 +0500 | [diff] [blame] | 96 | } |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 97 | |
| 98 | return ret; |
| 99 | } |
| 100 | |
| 101 | static int |
| 102 | qla24xx_proc_fcp_prio_cfg_cmd(struct fc_bsg_job *bsg_job) |
| 103 | { |
| 104 | struct Scsi_Host *host = bsg_job->shost; |
| 105 | scsi_qla_host_t *vha = shost_priv(host); |
| 106 | struct qla_hw_data *ha = vha->hw; |
| 107 | int ret = 0; |
| 108 | uint32_t len; |
| 109 | uint32_t oper; |
| 110 | |
| 111 | bsg_job->reply->reply_payload_rcv_len = 0; |
| 112 | |
Saurav Kashyap | a00f629 | 2011-11-18 09:03:19 -0800 | [diff] [blame] | 113 | if (!(IS_QLA24XX_TYPE(ha) || IS_QLA25XX(ha) || IS_QLA82XX(ha))) { |
Madhuranath Iyengar | 2f0f3f4 | 2010-07-23 15:28:24 +0500 | [diff] [blame] | 114 | ret = -EINVAL; |
| 115 | goto exit_fcp_prio_cfg; |
| 116 | } |
| 117 | |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 118 | /* Get the sub command */ |
| 119 | oper = bsg_job->request->rqst_data.h_vendor.vendor_cmd[1]; |
| 120 | |
| 121 | /* Only set config is allowed if config memory is not allocated */ |
| 122 | if (!ha->fcp_prio_cfg && (oper != QLFC_FCP_PRIO_SET_CONFIG)) { |
| 123 | ret = -EINVAL; |
| 124 | goto exit_fcp_prio_cfg; |
| 125 | } |
| 126 | switch (oper) { |
| 127 | case QLFC_FCP_PRIO_DISABLE: |
| 128 | if (ha->flags.fcp_prio_enabled) { |
| 129 | ha->flags.fcp_prio_enabled = 0; |
| 130 | ha->fcp_prio_cfg->attributes &= |
| 131 | ~FCP_PRIO_ATTR_ENABLE; |
| 132 | qla24xx_update_all_fcp_prio(vha); |
| 133 | bsg_job->reply->result = DID_OK; |
| 134 | } else { |
| 135 | ret = -EINVAL; |
| 136 | bsg_job->reply->result = (DID_ERROR << 16); |
| 137 | goto exit_fcp_prio_cfg; |
| 138 | } |
| 139 | break; |
| 140 | |
| 141 | case QLFC_FCP_PRIO_ENABLE: |
| 142 | if (!ha->flags.fcp_prio_enabled) { |
| 143 | if (ha->fcp_prio_cfg) { |
| 144 | ha->flags.fcp_prio_enabled = 1; |
| 145 | ha->fcp_prio_cfg->attributes |= |
| 146 | FCP_PRIO_ATTR_ENABLE; |
| 147 | qla24xx_update_all_fcp_prio(vha); |
| 148 | bsg_job->reply->result = DID_OK; |
| 149 | } else { |
| 150 | ret = -EINVAL; |
| 151 | bsg_job->reply->result = (DID_ERROR << 16); |
| 152 | goto exit_fcp_prio_cfg; |
| 153 | } |
| 154 | } |
| 155 | break; |
| 156 | |
| 157 | case QLFC_FCP_PRIO_GET_CONFIG: |
| 158 | len = bsg_job->reply_payload.payload_len; |
| 159 | if (!len || len > FCP_PRIO_CFG_SIZE) { |
| 160 | ret = -EINVAL; |
| 161 | bsg_job->reply->result = (DID_ERROR << 16); |
| 162 | goto exit_fcp_prio_cfg; |
| 163 | } |
| 164 | |
| 165 | bsg_job->reply->result = DID_OK; |
| 166 | bsg_job->reply->reply_payload_rcv_len = |
| 167 | sg_copy_from_buffer( |
| 168 | bsg_job->reply_payload.sg_list, |
| 169 | bsg_job->reply_payload.sg_cnt, ha->fcp_prio_cfg, |
| 170 | len); |
| 171 | |
| 172 | break; |
| 173 | |
| 174 | case QLFC_FCP_PRIO_SET_CONFIG: |
| 175 | len = bsg_job->request_payload.payload_len; |
| 176 | if (!len || len > FCP_PRIO_CFG_SIZE) { |
| 177 | bsg_job->reply->result = (DID_ERROR << 16); |
| 178 | ret = -EINVAL; |
| 179 | goto exit_fcp_prio_cfg; |
| 180 | } |
| 181 | |
| 182 | if (!ha->fcp_prio_cfg) { |
| 183 | ha->fcp_prio_cfg = vmalloc(FCP_PRIO_CFG_SIZE); |
| 184 | if (!ha->fcp_prio_cfg) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 185 | ql_log(ql_log_warn, vha, 0x7050, |
| 186 | "Unable to allocate memory for fcp prio " |
| 187 | "config data (%x).\n", FCP_PRIO_CFG_SIZE); |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 188 | bsg_job->reply->result = (DID_ERROR << 16); |
| 189 | ret = -ENOMEM; |
| 190 | goto exit_fcp_prio_cfg; |
| 191 | } |
| 192 | } |
| 193 | |
| 194 | memset(ha->fcp_prio_cfg, 0, FCP_PRIO_CFG_SIZE); |
| 195 | sg_copy_to_buffer(bsg_job->request_payload.sg_list, |
| 196 | bsg_job->request_payload.sg_cnt, ha->fcp_prio_cfg, |
| 197 | FCP_PRIO_CFG_SIZE); |
| 198 | |
| 199 | /* validate fcp priority data */ |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 200 | |
| 201 | if (!qla24xx_fcp_prio_cfg_valid(vha, |
| 202 | (struct qla_fcp_prio_cfg *) ha->fcp_prio_cfg, 1)) { |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 203 | bsg_job->reply->result = (DID_ERROR << 16); |
| 204 | ret = -EINVAL; |
| 205 | /* If buffer was invalidatic int |
| 206 | * fcp_prio_cfg is of no use |
| 207 | */ |
| 208 | vfree(ha->fcp_prio_cfg); |
| 209 | ha->fcp_prio_cfg = NULL; |
| 210 | goto exit_fcp_prio_cfg; |
| 211 | } |
| 212 | |
| 213 | ha->flags.fcp_prio_enabled = 0; |
| 214 | if (ha->fcp_prio_cfg->attributes & FCP_PRIO_ATTR_ENABLE) |
| 215 | ha->flags.fcp_prio_enabled = 1; |
| 216 | qla24xx_update_all_fcp_prio(vha); |
| 217 | bsg_job->reply->result = DID_OK; |
| 218 | break; |
| 219 | default: |
| 220 | ret = -EINVAL; |
| 221 | break; |
| 222 | } |
| 223 | exit_fcp_prio_cfg: |
| 224 | bsg_job->job_done(bsg_job); |
| 225 | return ret; |
| 226 | } |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame^] | 227 | |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 228 | static int |
| 229 | qla2x00_process_els(struct fc_bsg_job *bsg_job) |
| 230 | { |
| 231 | struct fc_rport *rport; |
Harish Zunjarrao | 08f71e0 | 2010-07-23 15:28:33 +0500 | [diff] [blame] | 232 | fc_port_t *fcport = NULL; |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 233 | struct Scsi_Host *host; |
| 234 | scsi_qla_host_t *vha; |
| 235 | struct qla_hw_data *ha; |
| 236 | srb_t *sp; |
| 237 | const char *type; |
| 238 | int req_sg_cnt, rsp_sg_cnt; |
| 239 | int rval = (DRIVER_ERROR << 16); |
| 240 | uint16_t nextlid = 0; |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 241 | |
Harish Zunjarrao | 08f71e0 | 2010-07-23 15:28:33 +0500 | [diff] [blame] | 242 | if (bsg_job->request->msgcode == FC_BSG_RPT_ELS) { |
| 243 | rport = bsg_job->rport; |
| 244 | fcport = *(fc_port_t **) rport->dd_data; |
| 245 | host = rport_to_shost(rport); |
| 246 | vha = shost_priv(host); |
| 247 | ha = vha->hw; |
| 248 | type = "FC_BSG_RPT_ELS"; |
| 249 | } else { |
| 250 | host = bsg_job->shost; |
| 251 | vha = shost_priv(host); |
| 252 | ha = vha->hw; |
| 253 | type = "FC_BSG_HST_ELS_NOLOGIN"; |
| 254 | } |
| 255 | |
| 256 | /* pass through is supported only for ISP 4Gb or higher */ |
| 257 | if (!IS_FWI2_CAPABLE(ha)) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 258 | ql_dbg(ql_dbg_user, vha, 0x7001, |
| 259 | "ELS passthru not supported for ISP23xx based adapters.\n"); |
Harish Zunjarrao | 08f71e0 | 2010-07-23 15:28:33 +0500 | [diff] [blame] | 260 | rval = -EPERM; |
| 261 | goto done; |
| 262 | } |
| 263 | |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 264 | /* Multiple SG's are not supported for ELS requests */ |
| 265 | if (bsg_job->request_payload.sg_cnt > 1 || |
| 266 | bsg_job->reply_payload.sg_cnt > 1) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 267 | ql_dbg(ql_dbg_user, vha, 0x7002, |
| 268 | "Multiple SG's are not suppored for ELS requests, " |
| 269 | "request_sg_cnt=%x reply_sg_cnt=%x.\n", |
| 270 | bsg_job->request_payload.sg_cnt, |
| 271 | bsg_job->reply_payload.sg_cnt); |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 272 | rval = -EPERM; |
| 273 | goto done; |
| 274 | } |
| 275 | |
| 276 | /* ELS request for rport */ |
| 277 | if (bsg_job->request->msgcode == FC_BSG_RPT_ELS) { |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 278 | /* make sure the rport is logged in, |
| 279 | * if not perform fabric login |
| 280 | */ |
| 281 | if (qla2x00_fabric_login(vha, fcport, &nextlid)) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 282 | ql_dbg(ql_dbg_user, vha, 0x7003, |
| 283 | "Failed to login port %06X for ELS passthru.\n", |
| 284 | fcport->d_id.b24); |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 285 | rval = -EIO; |
| 286 | goto done; |
| 287 | } |
| 288 | } else { |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 289 | /* Allocate a dummy fcport structure, since functions |
| 290 | * preparing the IOCB and mailbox command retrieves port |
| 291 | * specific information from fcport structure. For Host based |
| 292 | * ELS commands there will be no fcport structure allocated |
| 293 | */ |
| 294 | fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL); |
| 295 | if (!fcport) { |
| 296 | rval = -ENOMEM; |
| 297 | goto done; |
| 298 | } |
| 299 | |
| 300 | /* Initialize all required fields of fcport */ |
| 301 | fcport->vha = vha; |
| 302 | fcport->vp_idx = vha->vp_idx; |
| 303 | fcport->d_id.b.al_pa = |
| 304 | bsg_job->request->rqst_data.h_els.port_id[0]; |
| 305 | fcport->d_id.b.area = |
| 306 | bsg_job->request->rqst_data.h_els.port_id[1]; |
| 307 | fcport->d_id.b.domain = |
| 308 | bsg_job->request->rqst_data.h_els.port_id[2]; |
| 309 | fcport->loop_id = |
| 310 | (fcport->d_id.b.al_pa == 0xFD) ? |
| 311 | NPH_FABRIC_CONTROLLER : NPH_F_PORT; |
| 312 | } |
| 313 | |
| 314 | if (!vha->flags.online) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 315 | ql_log(ql_log_warn, vha, 0x7005, "Host not online.\n"); |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 316 | rval = -EIO; |
| 317 | goto done; |
| 318 | } |
| 319 | |
| 320 | req_sg_cnt = |
| 321 | dma_map_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list, |
| 322 | bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE); |
| 323 | if (!req_sg_cnt) { |
| 324 | rval = -ENOMEM; |
| 325 | goto done_free_fcport; |
| 326 | } |
Andrew Vasquez | 6c452a4 | 2010-03-19 17:04:02 -0700 | [diff] [blame] | 327 | |
| 328 | rsp_sg_cnt = dma_map_sg(&ha->pdev->dev, bsg_job->reply_payload.sg_list, |
| 329 | bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE); |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 330 | if (!rsp_sg_cnt) { |
| 331 | rval = -ENOMEM; |
| 332 | goto done_free_fcport; |
| 333 | } |
| 334 | |
| 335 | if ((req_sg_cnt != bsg_job->request_payload.sg_cnt) || |
Andrew Vasquez | 6c452a4 | 2010-03-19 17:04:02 -0700 | [diff] [blame] | 336 | (rsp_sg_cnt != bsg_job->reply_payload.sg_cnt)) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 337 | ql_log(ql_log_warn, vha, 0x7008, |
| 338 | "dma mapping resulted in different sg counts, " |
| 339 | "request_sg_cnt: %x dma_request_sg_cnt:%x reply_sg_cnt:%x " |
| 340 | "dma_reply_sg_cnt:%x.\n", bsg_job->request_payload.sg_cnt, |
| 341 | req_sg_cnt, bsg_job->reply_payload.sg_cnt, rsp_sg_cnt); |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 342 | rval = -EAGAIN; |
| 343 | goto done_unmap_sg; |
| 344 | } |
| 345 | |
| 346 | /* Alloc SRB structure */ |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame^] | 347 | sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL); |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 348 | if (!sp) { |
| 349 | rval = -ENOMEM; |
Andrew Vasquez | 6c452a4 | 2010-03-19 17:04:02 -0700 | [diff] [blame] | 350 | goto done_unmap_sg; |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 351 | } |
| 352 | |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame^] | 353 | sp->type = |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 354 | (bsg_job->request->msgcode == FC_BSG_RPT_ELS ? |
| 355 | SRB_ELS_CMD_RPT : SRB_ELS_CMD_HST); |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame^] | 356 | sp->name = |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 357 | (bsg_job->request->msgcode == FC_BSG_RPT_ELS ? |
| 358 | "bsg_els_rpt" : "bsg_els_hst"); |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame^] | 359 | sp->u.bsg_job = bsg_job; |
| 360 | sp->free = qla2x00_bsg_sp_free; |
| 361 | sp->done = qla2x00_bsg_job_done; |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 362 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 363 | ql_dbg(ql_dbg_user, vha, 0x700a, |
| 364 | "bsg rqst type: %s els type: %x - loop-id=%x " |
| 365 | "portid=%-2x%02x%02x.\n", type, |
| 366 | bsg_job->request->rqst_data.h_els.command_code, fcport->loop_id, |
| 367 | fcport->d_id.b.domain, fcport->d_id.b.area, fcport->d_id.b.al_pa); |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 368 | |
| 369 | rval = qla2x00_start_sp(sp); |
| 370 | if (rval != QLA_SUCCESS) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 371 | ql_log(ql_log_warn, vha, 0x700e, |
| 372 | "qla2x00_start_sp failed = %d\n", rval); |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 373 | mempool_free(sp, ha->srb_mempool); |
| 374 | rval = -EIO; |
| 375 | goto done_unmap_sg; |
| 376 | } |
| 377 | return rval; |
| 378 | |
| 379 | done_unmap_sg: |
| 380 | dma_unmap_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list, |
| 381 | bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE); |
| 382 | dma_unmap_sg(&ha->pdev->dev, bsg_job->reply_payload.sg_list, |
| 383 | bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE); |
| 384 | goto done_free_fcport; |
| 385 | |
| 386 | done_free_fcport: |
| 387 | if (bsg_job->request->msgcode == FC_BSG_HST_ELS_NOLOGIN) |
| 388 | kfree(fcport); |
| 389 | done: |
| 390 | return rval; |
| 391 | } |
| 392 | |
Andrew Vasquez | 5780790 | 2011-11-18 09:03:20 -0800 | [diff] [blame] | 393 | inline uint16_t |
| 394 | qla24xx_calc_ct_iocbs(uint16_t dsds) |
| 395 | { |
| 396 | uint16_t iocbs; |
| 397 | |
| 398 | iocbs = 1; |
| 399 | if (dsds > 2) { |
| 400 | iocbs += (dsds - 2) / 5; |
| 401 | if ((dsds - 2) % 5) |
| 402 | iocbs++; |
| 403 | } |
| 404 | return iocbs; |
| 405 | } |
| 406 | |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 407 | static int |
| 408 | qla2x00_process_ct(struct fc_bsg_job *bsg_job) |
| 409 | { |
| 410 | srb_t *sp; |
| 411 | struct Scsi_Host *host = bsg_job->shost; |
| 412 | scsi_qla_host_t *vha = shost_priv(host); |
| 413 | struct qla_hw_data *ha = vha->hw; |
| 414 | int rval = (DRIVER_ERROR << 16); |
| 415 | int req_sg_cnt, rsp_sg_cnt; |
| 416 | uint16_t loop_id; |
| 417 | struct fc_port *fcport; |
| 418 | char *type = "FC_BSG_HST_CT"; |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 419 | |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 420 | req_sg_cnt = |
| 421 | dma_map_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list, |
| 422 | bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE); |
Andrew Vasquez | 6c452a4 | 2010-03-19 17:04:02 -0700 | [diff] [blame] | 423 | if (!req_sg_cnt) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 424 | ql_log(ql_log_warn, vha, 0x700f, |
| 425 | "dma_map_sg return %d for request\n", req_sg_cnt); |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 426 | rval = -ENOMEM; |
| 427 | goto done; |
| 428 | } |
| 429 | |
| 430 | rsp_sg_cnt = dma_map_sg(&ha->pdev->dev, bsg_job->reply_payload.sg_list, |
| 431 | bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE); |
| 432 | if (!rsp_sg_cnt) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 433 | ql_log(ql_log_warn, vha, 0x7010, |
| 434 | "dma_map_sg return %d for reply\n", rsp_sg_cnt); |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 435 | rval = -ENOMEM; |
| 436 | goto done; |
| 437 | } |
| 438 | |
| 439 | if ((req_sg_cnt != bsg_job->request_payload.sg_cnt) || |
Andrew Vasquez | 6c452a4 | 2010-03-19 17:04:02 -0700 | [diff] [blame] | 440 | (rsp_sg_cnt != bsg_job->reply_payload.sg_cnt)) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 441 | ql_log(ql_log_warn, vha, 0x7011, |
| 442 | "request_sg_cnt: %x dma_request_sg_cnt: %x reply_sg_cnt:%x " |
| 443 | "dma_reply_sg_cnt: %x\n", bsg_job->request_payload.sg_cnt, |
| 444 | req_sg_cnt, bsg_job->reply_payload.sg_cnt, rsp_sg_cnt); |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 445 | rval = -EAGAIN; |
Andrew Vasquez | 6c452a4 | 2010-03-19 17:04:02 -0700 | [diff] [blame] | 446 | goto done_unmap_sg; |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 447 | } |
| 448 | |
| 449 | if (!vha->flags.online) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 450 | ql_log(ql_log_warn, vha, 0x7012, |
| 451 | "Host is not online.\n"); |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 452 | rval = -EIO; |
| 453 | goto done_unmap_sg; |
| 454 | } |
| 455 | |
| 456 | loop_id = |
| 457 | (bsg_job->request->rqst_data.h_ct.preamble_word1 & 0xFF000000) |
| 458 | >> 24; |
| 459 | switch (loop_id) { |
Andrew Vasquez | 6c452a4 | 2010-03-19 17:04:02 -0700 | [diff] [blame] | 460 | case 0xFC: |
| 461 | loop_id = cpu_to_le16(NPH_SNS); |
| 462 | break; |
| 463 | case 0xFA: |
| 464 | loop_id = vha->mgmt_svr_loop_id; |
| 465 | break; |
| 466 | default: |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 467 | ql_dbg(ql_dbg_user, vha, 0x7013, |
| 468 | "Unknown loop id: %x.\n", loop_id); |
Andrew Vasquez | 6c452a4 | 2010-03-19 17:04:02 -0700 | [diff] [blame] | 469 | rval = -EINVAL; |
| 470 | goto done_unmap_sg; |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 471 | } |
| 472 | |
| 473 | /* Allocate a dummy fcport structure, since functions preparing the |
| 474 | * IOCB and mailbox command retrieves port specific information |
| 475 | * from fcport structure. For Host based ELS commands there will be |
| 476 | * no fcport structure allocated |
| 477 | */ |
| 478 | fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL); |
Andrew Vasquez | 6c452a4 | 2010-03-19 17:04:02 -0700 | [diff] [blame] | 479 | if (!fcport) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 480 | ql_log(ql_log_warn, vha, 0x7014, |
| 481 | "Failed to allocate fcport.\n"); |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 482 | rval = -ENOMEM; |
Andrew Vasquez | 6c452a4 | 2010-03-19 17:04:02 -0700 | [diff] [blame] | 483 | goto done_unmap_sg; |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 484 | } |
| 485 | |
| 486 | /* Initialize all required fields of fcport */ |
| 487 | fcport->vha = vha; |
| 488 | fcport->vp_idx = vha->vp_idx; |
| 489 | fcport->d_id.b.al_pa = bsg_job->request->rqst_data.h_ct.port_id[0]; |
| 490 | fcport->d_id.b.area = bsg_job->request->rqst_data.h_ct.port_id[1]; |
| 491 | fcport->d_id.b.domain = bsg_job->request->rqst_data.h_ct.port_id[2]; |
| 492 | fcport->loop_id = loop_id; |
| 493 | |
| 494 | /* Alloc SRB structure */ |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame^] | 495 | sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL); |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 496 | if (!sp) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 497 | ql_log(ql_log_warn, vha, 0x7015, |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame^] | 498 | "qla2x00_get_sp failed.\n"); |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 499 | rval = -ENOMEM; |
| 500 | goto done_free_fcport; |
| 501 | } |
| 502 | |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame^] | 503 | sp->type = SRB_CT_CMD; |
| 504 | sp->name = "bsg_ct"; |
| 505 | sp->iocbs = qla24xx_calc_ct_iocbs(req_sg_cnt + rsp_sg_cnt); |
| 506 | sp->u.bsg_job = bsg_job; |
| 507 | sp->free = qla2x00_bsg_sp_free; |
| 508 | sp->done = qla2x00_bsg_job_done; |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 509 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 510 | ql_dbg(ql_dbg_user, vha, 0x7016, |
| 511 | "bsg rqst type: %s else type: %x - " |
| 512 | "loop-id=%x portid=%02x%02x%02x.\n", type, |
| 513 | (bsg_job->request->rqst_data.h_ct.preamble_word2 >> 16), |
| 514 | fcport->loop_id, fcport->d_id.b.domain, fcport->d_id.b.area, |
| 515 | fcport->d_id.b.al_pa); |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 516 | |
| 517 | rval = qla2x00_start_sp(sp); |
| 518 | if (rval != QLA_SUCCESS) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 519 | ql_log(ql_log_warn, vha, 0x7017, |
| 520 | "qla2x00_start_sp failed=%d.\n", rval); |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 521 | mempool_free(sp, ha->srb_mempool); |
| 522 | rval = -EIO; |
| 523 | goto done_free_fcport; |
| 524 | } |
| 525 | return rval; |
| 526 | |
| 527 | done_free_fcport: |
| 528 | kfree(fcport); |
| 529 | done_unmap_sg: |
| 530 | dma_unmap_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list, |
| 531 | bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE); |
| 532 | dma_unmap_sg(&ha->pdev->dev, bsg_job->reply_payload.sg_list, |
| 533 | bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE); |
| 534 | done: |
| 535 | return rval; |
| 536 | } |
| 537 | |
Sarang Radke | 23f2ebd | 2010-05-28 15:08:21 -0700 | [diff] [blame] | 538 | /* Set the port configuration to enable the |
| 539 | * internal loopback on ISP81XX |
| 540 | */ |
| 541 | static inline int |
| 542 | qla81xx_set_internal_loopback(scsi_qla_host_t *vha, uint16_t *config, |
| 543 | uint16_t *new_config) |
| 544 | { |
| 545 | int ret = 0; |
| 546 | int rval = 0; |
| 547 | struct qla_hw_data *ha = vha->hw; |
| 548 | |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 549 | if (!IS_QLA81XX(ha) && !IS_QLA83XX(ha)) |
Sarang Radke | 23f2ebd | 2010-05-28 15:08:21 -0700 | [diff] [blame] | 550 | goto done_set_internal; |
| 551 | |
| 552 | new_config[0] = config[0] | (ENABLE_INTERNAL_LOOPBACK << 1); |
| 553 | memcpy(&new_config[1], &config[1], sizeof(uint16_t) * 3) ; |
| 554 | |
| 555 | ha->notify_dcbx_comp = 1; |
| 556 | ret = qla81xx_set_port_config(vha, new_config); |
| 557 | if (ret != QLA_SUCCESS) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 558 | ql_log(ql_log_warn, vha, 0x7021, |
| 559 | "set port config failed.\n"); |
Sarang Radke | 23f2ebd | 2010-05-28 15:08:21 -0700 | [diff] [blame] | 560 | ha->notify_dcbx_comp = 0; |
| 561 | rval = -EINVAL; |
| 562 | goto done_set_internal; |
| 563 | } |
| 564 | |
| 565 | /* Wait for DCBX complete event */ |
| 566 | if (!wait_for_completion_timeout(&ha->dcbx_comp, (20 * HZ))) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 567 | ql_dbg(ql_dbg_user, vha, 0x7022, |
| 568 | "State change notification not received.\n"); |
Sarang Radke | 23f2ebd | 2010-05-28 15:08:21 -0700 | [diff] [blame] | 569 | } else |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 570 | ql_dbg(ql_dbg_user, vha, 0x7023, |
| 571 | "State change received.\n"); |
Sarang Radke | 23f2ebd | 2010-05-28 15:08:21 -0700 | [diff] [blame] | 572 | |
| 573 | ha->notify_dcbx_comp = 0; |
| 574 | |
| 575 | done_set_internal: |
| 576 | return rval; |
| 577 | } |
| 578 | |
| 579 | /* Set the port configuration to disable the |
| 580 | * internal loopback on ISP81XX |
| 581 | */ |
| 582 | static inline int |
| 583 | qla81xx_reset_internal_loopback(scsi_qla_host_t *vha, uint16_t *config, |
| 584 | int wait) |
| 585 | { |
| 586 | int ret = 0; |
| 587 | int rval = 0; |
| 588 | uint16_t new_config[4]; |
| 589 | struct qla_hw_data *ha = vha->hw; |
| 590 | |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 591 | if (!IS_QLA81XX(ha) && !IS_QLA83XX(ha)) |
Sarang Radke | 23f2ebd | 2010-05-28 15:08:21 -0700 | [diff] [blame] | 592 | goto done_reset_internal; |
| 593 | |
| 594 | memset(new_config, 0 , sizeof(new_config)); |
| 595 | if ((config[0] & INTERNAL_LOOPBACK_MASK) >> 1 == |
| 596 | ENABLE_INTERNAL_LOOPBACK) { |
| 597 | new_config[0] = config[0] & ~INTERNAL_LOOPBACK_MASK; |
| 598 | memcpy(&new_config[1], &config[1], sizeof(uint16_t) * 3) ; |
| 599 | |
| 600 | ha->notify_dcbx_comp = wait; |
| 601 | ret = qla81xx_set_port_config(vha, new_config); |
| 602 | if (ret != QLA_SUCCESS) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 603 | ql_log(ql_log_warn, vha, 0x7025, |
| 604 | "Set port config failed.\n"); |
Sarang Radke | 23f2ebd | 2010-05-28 15:08:21 -0700 | [diff] [blame] | 605 | ha->notify_dcbx_comp = 0; |
| 606 | rval = -EINVAL; |
| 607 | goto done_reset_internal; |
| 608 | } |
| 609 | |
| 610 | /* Wait for DCBX complete event */ |
| 611 | if (wait && !wait_for_completion_timeout(&ha->dcbx_comp, |
| 612 | (20 * HZ))) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 613 | ql_dbg(ql_dbg_user, vha, 0x7026, |
| 614 | "State change notification not received.\n"); |
Sarang Radke | 23f2ebd | 2010-05-28 15:08:21 -0700 | [diff] [blame] | 615 | ha->notify_dcbx_comp = 0; |
| 616 | rval = -EINVAL; |
| 617 | goto done_reset_internal; |
| 618 | } else |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 619 | ql_dbg(ql_dbg_user, vha, 0x7027, |
| 620 | "State change received.\n"); |
Sarang Radke | 23f2ebd | 2010-05-28 15:08:21 -0700 | [diff] [blame] | 621 | |
| 622 | ha->notify_dcbx_comp = 0; |
| 623 | } |
| 624 | done_reset_internal: |
| 625 | return rval; |
| 626 | } |
| 627 | |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 628 | static int |
| 629 | qla2x00_process_loopback(struct fc_bsg_job *bsg_job) |
| 630 | { |
| 631 | struct Scsi_Host *host = bsg_job->shost; |
| 632 | scsi_qla_host_t *vha = shost_priv(host); |
| 633 | struct qla_hw_data *ha = vha->hw; |
| 634 | int rval; |
| 635 | uint8_t command_sent; |
| 636 | char *type; |
| 637 | struct msg_echo_lb elreq; |
| 638 | uint16_t response[MAILBOX_REGISTER_COUNT]; |
Sarang Radke | 23f2ebd | 2010-05-28 15:08:21 -0700 | [diff] [blame] | 639 | uint16_t config[4], new_config[4]; |
Andrew Vasquez | 6c452a4 | 2010-03-19 17:04:02 -0700 | [diff] [blame] | 640 | uint8_t *fw_sts_ptr; |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 641 | uint8_t *req_data = NULL; |
| 642 | dma_addr_t req_data_dma; |
| 643 | uint32_t req_data_len; |
| 644 | uint8_t *rsp_data = NULL; |
| 645 | dma_addr_t rsp_data_dma; |
| 646 | uint32_t rsp_data_len; |
| 647 | |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 648 | if (!vha->flags.online) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 649 | ql_log(ql_log_warn, vha, 0x7019, "Host is not online.\n"); |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 650 | return -EIO; |
| 651 | } |
| 652 | |
| 653 | elreq.req_sg_cnt = dma_map_sg(&ha->pdev->dev, |
| 654 | bsg_job->request_payload.sg_list, bsg_job->request_payload.sg_cnt, |
| 655 | DMA_TO_DEVICE); |
| 656 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 657 | if (!elreq.req_sg_cnt) { |
| 658 | ql_log(ql_log_warn, vha, 0x701a, |
| 659 | "dma_map_sg returned %d for request.\n", elreq.req_sg_cnt); |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 660 | return -ENOMEM; |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 661 | } |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 662 | |
| 663 | elreq.rsp_sg_cnt = dma_map_sg(&ha->pdev->dev, |
| 664 | bsg_job->reply_payload.sg_list, bsg_job->reply_payload.sg_cnt, |
| 665 | DMA_FROM_DEVICE); |
| 666 | |
| 667 | if (!elreq.rsp_sg_cnt) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 668 | ql_log(ql_log_warn, vha, 0x701b, |
| 669 | "dma_map_sg returned %d for reply.\n", elreq.rsp_sg_cnt); |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 670 | rval = -ENOMEM; |
| 671 | goto done_unmap_req_sg; |
Andrew Vasquez | 6c452a4 | 2010-03-19 17:04:02 -0700 | [diff] [blame] | 672 | } |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 673 | |
| 674 | if ((elreq.req_sg_cnt != bsg_job->request_payload.sg_cnt) || |
| 675 | (elreq.rsp_sg_cnt != bsg_job->reply_payload.sg_cnt)) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 676 | ql_log(ql_log_warn, vha, 0x701c, |
| 677 | "dma mapping resulted in different sg counts, " |
| 678 | "request_sg_cnt: %x dma_request_sg_cnt: %x " |
| 679 | "reply_sg_cnt: %x dma_reply_sg_cnt: %x.\n", |
| 680 | bsg_job->request_payload.sg_cnt, elreq.req_sg_cnt, |
| 681 | bsg_job->reply_payload.sg_cnt, elreq.rsp_sg_cnt); |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 682 | rval = -EAGAIN; |
| 683 | goto done_unmap_sg; |
| 684 | } |
| 685 | req_data_len = rsp_data_len = bsg_job->request_payload.payload_len; |
| 686 | req_data = dma_alloc_coherent(&ha->pdev->dev, req_data_len, |
| 687 | &req_data_dma, GFP_KERNEL); |
| 688 | if (!req_data) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 689 | ql_log(ql_log_warn, vha, 0x701d, |
| 690 | "dma alloc failed for req_data.\n"); |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 691 | rval = -ENOMEM; |
| 692 | goto done_unmap_sg; |
| 693 | } |
| 694 | |
| 695 | rsp_data = dma_alloc_coherent(&ha->pdev->dev, rsp_data_len, |
| 696 | &rsp_data_dma, GFP_KERNEL); |
| 697 | if (!rsp_data) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 698 | ql_log(ql_log_warn, vha, 0x7004, |
| 699 | "dma alloc failed for rsp_data.\n"); |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 700 | rval = -ENOMEM; |
| 701 | goto done_free_dma_req; |
| 702 | } |
| 703 | |
| 704 | /* Copy the request buffer in req_data now */ |
| 705 | sg_copy_to_buffer(bsg_job->request_payload.sg_list, |
| 706 | bsg_job->request_payload.sg_cnt, req_data, req_data_len); |
| 707 | |
| 708 | elreq.send_dma = req_data_dma; |
| 709 | elreq.rcv_dma = rsp_data_dma; |
| 710 | elreq.transfer_size = req_data_len; |
| 711 | |
| 712 | elreq.options = bsg_job->request->rqst_data.h_vendor.vendor_cmd[1]; |
| 713 | |
Sarang Radke | 23f2ebd | 2010-05-28 15:08:21 -0700 | [diff] [blame] | 714 | if ((ha->current_topology == ISP_CFG_F || |
Saurav Kashyap | 491118d | 2011-08-16 11:31:50 -0700 | [diff] [blame] | 715 | (atomic_read(&vha->loop_state) == LOOP_DOWN) || |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 716 | ((IS_QLA81XX(ha) || IS_QLA83XX(ha)) && |
Sarang Radke | 23f2ebd | 2010-05-28 15:08:21 -0700 | [diff] [blame] | 717 | le32_to_cpu(*(uint32_t *)req_data) == ELS_OPCODE_BYTE |
| 718 | && req_data_len == MAX_ELS_FRAME_PAYLOAD)) && |
| 719 | elreq.options == EXTERNAL_LOOPBACK) { |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 720 | type = "FC_BSG_HST_VENDOR_ECHO_DIAG"; |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 721 | ql_dbg(ql_dbg_user, vha, 0x701e, |
| 722 | "BSG request type: %s.\n", type); |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 723 | command_sent = INT_DEF_LB_ECHO_CMD; |
| 724 | rval = qla2x00_echo_test(vha, &elreq, response); |
Sarang Radke | 23f2ebd | 2010-05-28 15:08:21 -0700 | [diff] [blame] | 725 | } else { |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 726 | if (IS_QLA81XX(ha) || IS_QLA8031(ha)) { |
Sarang Radke | 23f2ebd | 2010-05-28 15:08:21 -0700 | [diff] [blame] | 727 | memset(config, 0, sizeof(config)); |
| 728 | memset(new_config, 0, sizeof(new_config)); |
| 729 | if (qla81xx_get_port_config(vha, config)) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 730 | ql_log(ql_log_warn, vha, 0x701f, |
| 731 | "Get port config failed.\n"); |
Sarang Radke | 23f2ebd | 2010-05-28 15:08:21 -0700 | [diff] [blame] | 732 | bsg_job->reply->reply_payload_rcv_len = 0; |
| 733 | bsg_job->reply->result = (DID_ERROR << 16); |
| 734 | rval = -EPERM; |
| 735 | goto done_free_dma_req; |
| 736 | } |
| 737 | |
| 738 | if (elreq.options != EXTERNAL_LOOPBACK) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 739 | ql_dbg(ql_dbg_user, vha, 0x7020, |
| 740 | "Internal: curent port config = %x\n", |
| 741 | config[0]); |
Sarang Radke | 23f2ebd | 2010-05-28 15:08:21 -0700 | [diff] [blame] | 742 | if (qla81xx_set_internal_loopback(vha, config, |
| 743 | new_config)) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 744 | ql_log(ql_log_warn, vha, 0x7024, |
| 745 | "Internal loopback failed.\n"); |
Sarang Radke | 23f2ebd | 2010-05-28 15:08:21 -0700 | [diff] [blame] | 746 | bsg_job->reply->reply_payload_rcv_len = |
| 747 | 0; |
| 748 | bsg_job->reply->result = |
| 749 | (DID_ERROR << 16); |
| 750 | rval = -EPERM; |
| 751 | goto done_free_dma_req; |
| 752 | } |
| 753 | } else { |
| 754 | /* For external loopback to work |
| 755 | * ensure internal loopback is disabled |
| 756 | */ |
| 757 | if (qla81xx_reset_internal_loopback(vha, |
| 758 | config, 1)) { |
| 759 | bsg_job->reply->reply_payload_rcv_len = |
| 760 | 0; |
| 761 | bsg_job->reply->result = |
| 762 | (DID_ERROR << 16); |
| 763 | rval = -EPERM; |
| 764 | goto done_free_dma_req; |
| 765 | } |
| 766 | } |
| 767 | |
| 768 | type = "FC_BSG_HST_VENDOR_LOOPBACK"; |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 769 | ql_dbg(ql_dbg_user, vha, 0x7028, |
| 770 | "BSG request type: %s.\n", type); |
Sarang Radke | 23f2ebd | 2010-05-28 15:08:21 -0700 | [diff] [blame] | 771 | |
| 772 | command_sent = INT_DEF_LB_LOOPBACK_CMD; |
| 773 | rval = qla2x00_loopback_test(vha, &elreq, response); |
| 774 | |
Joe Carnuccio | 4052bd5 | 2010-12-21 16:00:17 -0800 | [diff] [blame] | 775 | if (new_config[0]) { |
Sarang Radke | 23f2ebd | 2010-05-28 15:08:21 -0700 | [diff] [blame] | 776 | /* Revert back to original port config |
| 777 | * Also clear internal loopback |
| 778 | */ |
| 779 | qla81xx_reset_internal_loopback(vha, |
| 780 | new_config, 0); |
| 781 | } |
| 782 | |
| 783 | if (response[0] == MBS_COMMAND_ERROR && |
| 784 | response[1] == MBS_LB_RESET) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 785 | ql_log(ql_log_warn, vha, 0x7029, |
| 786 | "MBX command error, Aborting ISP.\n"); |
Sarang Radke | 23f2ebd | 2010-05-28 15:08:21 -0700 | [diff] [blame] | 787 | set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags); |
| 788 | qla2xxx_wake_dpc(vha); |
| 789 | qla2x00_wait_for_chip_reset(vha); |
| 790 | /* Also reset the MPI */ |
| 791 | if (qla81xx_restart_mpi_firmware(vha) != |
| 792 | QLA_SUCCESS) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 793 | ql_log(ql_log_warn, vha, 0x702a, |
| 794 | "MPI reset failed.\n"); |
Sarang Radke | 23f2ebd | 2010-05-28 15:08:21 -0700 | [diff] [blame] | 795 | } |
| 796 | |
| 797 | bsg_job->reply->reply_payload_rcv_len = 0; |
| 798 | bsg_job->reply->result = (DID_ERROR << 16); |
| 799 | rval = -EIO; |
| 800 | goto done_free_dma_req; |
| 801 | } |
| 802 | } else { |
| 803 | type = "FC_BSG_HST_VENDOR_LOOPBACK"; |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 804 | ql_dbg(ql_dbg_user, vha, 0x702b, |
| 805 | "BSG request type: %s.\n", type); |
Sarang Radke | 23f2ebd | 2010-05-28 15:08:21 -0700 | [diff] [blame] | 806 | command_sent = INT_DEF_LB_LOOPBACK_CMD; |
| 807 | rval = qla2x00_loopback_test(vha, &elreq, response); |
| 808 | } |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 809 | } |
| 810 | |
| 811 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 812 | ql_log(ql_log_warn, vha, 0x702c, |
| 813 | "Vendor request %s failed.\n", type); |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 814 | |
| 815 | fw_sts_ptr = ((uint8_t *)bsg_job->req->sense) + |
Andrew Vasquez | 6c452a4 | 2010-03-19 17:04:02 -0700 | [diff] [blame] | 816 | sizeof(struct fc_bsg_reply); |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 817 | |
| 818 | memcpy(fw_sts_ptr, response, sizeof(response)); |
| 819 | fw_sts_ptr += sizeof(response); |
Andrew Vasquez | 6c452a4 | 2010-03-19 17:04:02 -0700 | [diff] [blame] | 820 | *fw_sts_ptr = command_sent; |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 821 | rval = 0; |
| 822 | bsg_job->reply->reply_payload_rcv_len = 0; |
| 823 | bsg_job->reply->result = (DID_ERROR << 16); |
| 824 | } else { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 825 | ql_dbg(ql_dbg_user, vha, 0x702d, |
| 826 | "Vendor request %s completed.\n", type); |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 827 | |
| 828 | bsg_job->reply_len = sizeof(struct fc_bsg_reply) + |
| 829 | sizeof(response) + sizeof(uint8_t); |
| 830 | bsg_job->reply->reply_payload_rcv_len = |
| 831 | bsg_job->reply_payload.payload_len; |
| 832 | fw_sts_ptr = ((uint8_t *)bsg_job->req->sense) + |
| 833 | sizeof(struct fc_bsg_reply); |
| 834 | memcpy(fw_sts_ptr, response, sizeof(response)); |
| 835 | fw_sts_ptr += sizeof(response); |
| 836 | *fw_sts_ptr = command_sent; |
| 837 | bsg_job->reply->result = DID_OK; |
| 838 | sg_copy_from_buffer(bsg_job->reply_payload.sg_list, |
| 839 | bsg_job->reply_payload.sg_cnt, rsp_data, |
| 840 | rsp_data_len); |
| 841 | } |
| 842 | bsg_job->job_done(bsg_job); |
| 843 | |
| 844 | dma_free_coherent(&ha->pdev->dev, rsp_data_len, |
| 845 | rsp_data, rsp_data_dma); |
| 846 | done_free_dma_req: |
| 847 | dma_free_coherent(&ha->pdev->dev, req_data_len, |
| 848 | req_data, req_data_dma); |
| 849 | done_unmap_sg: |
| 850 | dma_unmap_sg(&ha->pdev->dev, |
| 851 | bsg_job->reply_payload.sg_list, |
| 852 | bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE); |
| 853 | done_unmap_req_sg: |
| 854 | dma_unmap_sg(&ha->pdev->dev, |
| 855 | bsg_job->request_payload.sg_list, |
| 856 | bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE); |
Andrew Vasquez | 6c452a4 | 2010-03-19 17:04:02 -0700 | [diff] [blame] | 857 | return rval; |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 858 | } |
| 859 | |
| 860 | static int |
| 861 | qla84xx_reset(struct fc_bsg_job *bsg_job) |
| 862 | { |
| 863 | struct Scsi_Host *host = bsg_job->shost; |
| 864 | scsi_qla_host_t *vha = shost_priv(host); |
| 865 | struct qla_hw_data *ha = vha->hw; |
| 866 | int rval = 0; |
| 867 | uint32_t flag; |
| 868 | |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 869 | if (!IS_QLA84XX(ha)) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 870 | ql_dbg(ql_dbg_user, vha, 0x702f, "Not 84xx, exiting.\n"); |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 871 | return -EINVAL; |
| 872 | } |
| 873 | |
| 874 | flag = bsg_job->request->rqst_data.h_vendor.vendor_cmd[1]; |
| 875 | |
| 876 | rval = qla84xx_reset_chip(vha, flag == A84_ISSUE_RESET_DIAG_FW); |
| 877 | |
| 878 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 879 | ql_log(ql_log_warn, vha, 0x7030, |
| 880 | "Vendor request 84xx reset failed.\n"); |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 881 | rval = bsg_job->reply->reply_payload_rcv_len = 0; |
| 882 | bsg_job->reply->result = (DID_ERROR << 16); |
| 883 | |
| 884 | } else { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 885 | ql_dbg(ql_dbg_user, vha, 0x7031, |
| 886 | "Vendor request 84xx reset completed.\n"); |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 887 | bsg_job->reply->result = DID_OK; |
| 888 | } |
| 889 | |
| 890 | bsg_job->job_done(bsg_job); |
| 891 | return rval; |
| 892 | } |
| 893 | |
| 894 | static int |
| 895 | qla84xx_updatefw(struct fc_bsg_job *bsg_job) |
| 896 | { |
| 897 | struct Scsi_Host *host = bsg_job->shost; |
| 898 | scsi_qla_host_t *vha = shost_priv(host); |
| 899 | struct qla_hw_data *ha = vha->hw; |
| 900 | struct verify_chip_entry_84xx *mn = NULL; |
| 901 | dma_addr_t mn_dma, fw_dma; |
| 902 | void *fw_buf = NULL; |
| 903 | int rval = 0; |
| 904 | uint32_t sg_cnt; |
| 905 | uint32_t data_len; |
| 906 | uint16_t options; |
| 907 | uint32_t flag; |
| 908 | uint32_t fw_ver; |
| 909 | |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 910 | if (!IS_QLA84XX(ha)) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 911 | ql_dbg(ql_dbg_user, vha, 0x7032, |
| 912 | "Not 84xx, exiting.\n"); |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 913 | return -EINVAL; |
| 914 | } |
| 915 | |
| 916 | sg_cnt = dma_map_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list, |
| 917 | bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE); |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 918 | if (!sg_cnt) { |
| 919 | ql_log(ql_log_warn, vha, 0x7033, |
| 920 | "dma_map_sg returned %d for request.\n", sg_cnt); |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 921 | return -ENOMEM; |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 922 | } |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 923 | |
| 924 | if (sg_cnt != bsg_job->request_payload.sg_cnt) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 925 | ql_log(ql_log_warn, vha, 0x7034, |
| 926 | "DMA mapping resulted in different sg counts, " |
| 927 | "request_sg_cnt: %x dma_request_sg_cnt: %x.\n", |
| 928 | bsg_job->request_payload.sg_cnt, sg_cnt); |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 929 | rval = -EAGAIN; |
| 930 | goto done_unmap_sg; |
| 931 | } |
| 932 | |
| 933 | data_len = bsg_job->request_payload.payload_len; |
| 934 | fw_buf = dma_alloc_coherent(&ha->pdev->dev, data_len, |
| 935 | &fw_dma, GFP_KERNEL); |
| 936 | if (!fw_buf) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 937 | ql_log(ql_log_warn, vha, 0x7035, |
| 938 | "DMA alloc failed for fw_buf.\n"); |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 939 | rval = -ENOMEM; |
| 940 | goto done_unmap_sg; |
| 941 | } |
| 942 | |
| 943 | sg_copy_to_buffer(bsg_job->request_payload.sg_list, |
| 944 | bsg_job->request_payload.sg_cnt, fw_buf, data_len); |
| 945 | |
| 946 | mn = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &mn_dma); |
| 947 | if (!mn) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 948 | ql_log(ql_log_warn, vha, 0x7036, |
| 949 | "DMA alloc failed for fw buffer.\n"); |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 950 | rval = -ENOMEM; |
| 951 | goto done_free_fw_buf; |
| 952 | } |
| 953 | |
| 954 | flag = bsg_job->request->rqst_data.h_vendor.vendor_cmd[1]; |
| 955 | fw_ver = le32_to_cpu(*((uint32_t *)((uint32_t *)fw_buf + 2))); |
| 956 | |
| 957 | memset(mn, 0, sizeof(struct access_chip_84xx)); |
| 958 | mn->entry_type = VERIFY_CHIP_IOCB_TYPE; |
| 959 | mn->entry_count = 1; |
| 960 | |
| 961 | options = VCO_FORCE_UPDATE | VCO_END_OF_DATA; |
| 962 | if (flag == A84_ISSUE_UPDATE_DIAGFW_CMD) |
| 963 | options |= VCO_DIAG_FW; |
| 964 | |
| 965 | mn->options = cpu_to_le16(options); |
| 966 | mn->fw_ver = cpu_to_le32(fw_ver); |
| 967 | mn->fw_size = cpu_to_le32(data_len); |
| 968 | mn->fw_seq_size = cpu_to_le32(data_len); |
| 969 | mn->dseg_address[0] = cpu_to_le32(LSD(fw_dma)); |
| 970 | mn->dseg_address[1] = cpu_to_le32(MSD(fw_dma)); |
| 971 | mn->dseg_length = cpu_to_le32(data_len); |
| 972 | mn->data_seg_cnt = cpu_to_le16(1); |
| 973 | |
| 974 | rval = qla2x00_issue_iocb_timeout(vha, mn, mn_dma, 0, 120); |
| 975 | |
| 976 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 977 | ql_log(ql_log_warn, vha, 0x7037, |
| 978 | "Vendor request 84xx updatefw failed.\n"); |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 979 | |
| 980 | rval = bsg_job->reply->reply_payload_rcv_len = 0; |
| 981 | bsg_job->reply->result = (DID_ERROR << 16); |
| 982 | |
| 983 | } else { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 984 | ql_dbg(ql_dbg_user, vha, 0x7038, |
| 985 | "Vendor request 84xx updatefw completed.\n"); |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 986 | |
| 987 | bsg_job->reply_len = sizeof(struct fc_bsg_reply); |
| 988 | bsg_job->reply->result = DID_OK; |
| 989 | } |
| 990 | |
| 991 | bsg_job->job_done(bsg_job); |
| 992 | dma_pool_free(ha->s_dma_pool, mn, mn_dma); |
| 993 | |
| 994 | done_free_fw_buf: |
| 995 | dma_free_coherent(&ha->pdev->dev, data_len, fw_buf, fw_dma); |
| 996 | |
| 997 | done_unmap_sg: |
| 998 | dma_unmap_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list, |
| 999 | bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE); |
| 1000 | |
| 1001 | return rval; |
| 1002 | } |
| 1003 | |
| 1004 | static int |
| 1005 | qla84xx_mgmt_cmd(struct fc_bsg_job *bsg_job) |
| 1006 | { |
| 1007 | struct Scsi_Host *host = bsg_job->shost; |
| 1008 | scsi_qla_host_t *vha = shost_priv(host); |
| 1009 | struct qla_hw_data *ha = vha->hw; |
| 1010 | struct access_chip_84xx *mn = NULL; |
| 1011 | dma_addr_t mn_dma, mgmt_dma; |
| 1012 | void *mgmt_b = NULL; |
| 1013 | int rval = 0; |
| 1014 | struct qla_bsg_a84_mgmt *ql84_mgmt; |
| 1015 | uint32_t sg_cnt; |
Harish Zunjarrao | d545908 | 2010-03-19 17:04:00 -0700 | [diff] [blame] | 1016 | uint32_t data_len = 0; |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 1017 | uint32_t dma_direction = DMA_NONE; |
| 1018 | |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 1019 | if (!IS_QLA84XX(ha)) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1020 | ql_log(ql_log_warn, vha, 0x703a, |
| 1021 | "Not 84xx, exiting.\n"); |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 1022 | return -EINVAL; |
| 1023 | } |
| 1024 | |
| 1025 | ql84_mgmt = (struct qla_bsg_a84_mgmt *)((char *)bsg_job->request + |
| 1026 | sizeof(struct fc_bsg_request)); |
| 1027 | if (!ql84_mgmt) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1028 | ql_log(ql_log_warn, vha, 0x703b, |
| 1029 | "MGMT header not provided, exiting.\n"); |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 1030 | return -EINVAL; |
| 1031 | } |
| 1032 | |
| 1033 | mn = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &mn_dma); |
| 1034 | if (!mn) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1035 | ql_log(ql_log_warn, vha, 0x703c, |
| 1036 | "DMA alloc failed for fw buffer.\n"); |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 1037 | return -ENOMEM; |
| 1038 | } |
| 1039 | |
| 1040 | memset(mn, 0, sizeof(struct access_chip_84xx)); |
| 1041 | mn->entry_type = ACCESS_CHIP_IOCB_TYPE; |
| 1042 | mn->entry_count = 1; |
| 1043 | |
| 1044 | switch (ql84_mgmt->mgmt.cmd) { |
| 1045 | case QLA84_MGMT_READ_MEM: |
| 1046 | case QLA84_MGMT_GET_INFO: |
| 1047 | sg_cnt = dma_map_sg(&ha->pdev->dev, |
| 1048 | bsg_job->reply_payload.sg_list, |
| 1049 | bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE); |
| 1050 | if (!sg_cnt) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1051 | ql_log(ql_log_warn, vha, 0x703d, |
| 1052 | "dma_map_sg returned %d for reply.\n", sg_cnt); |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 1053 | rval = -ENOMEM; |
| 1054 | goto exit_mgmt; |
| 1055 | } |
| 1056 | |
| 1057 | dma_direction = DMA_FROM_DEVICE; |
| 1058 | |
| 1059 | if (sg_cnt != bsg_job->reply_payload.sg_cnt) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1060 | ql_log(ql_log_warn, vha, 0x703e, |
| 1061 | "DMA mapping resulted in different sg counts, " |
| 1062 | "reply_sg_cnt: %x dma_reply_sg_cnt: %x.\n", |
| 1063 | bsg_job->reply_payload.sg_cnt, sg_cnt); |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 1064 | rval = -EAGAIN; |
| 1065 | goto done_unmap_sg; |
| 1066 | } |
| 1067 | |
| 1068 | data_len = bsg_job->reply_payload.payload_len; |
| 1069 | |
| 1070 | mgmt_b = dma_alloc_coherent(&ha->pdev->dev, data_len, |
| 1071 | &mgmt_dma, GFP_KERNEL); |
| 1072 | if (!mgmt_b) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1073 | ql_log(ql_log_warn, vha, 0x703f, |
| 1074 | "DMA alloc failed for mgmt_b.\n"); |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 1075 | rval = -ENOMEM; |
| 1076 | goto done_unmap_sg; |
| 1077 | } |
| 1078 | |
| 1079 | if (ql84_mgmt->mgmt.cmd == QLA84_MGMT_READ_MEM) { |
| 1080 | mn->options = cpu_to_le16(ACO_DUMP_MEMORY); |
| 1081 | mn->parameter1 = |
| 1082 | cpu_to_le32( |
| 1083 | ql84_mgmt->mgmt.mgmtp.u.mem.start_addr); |
| 1084 | |
| 1085 | } else if (ql84_mgmt->mgmt.cmd == QLA84_MGMT_GET_INFO) { |
| 1086 | mn->options = cpu_to_le16(ACO_REQUEST_INFO); |
| 1087 | mn->parameter1 = |
| 1088 | cpu_to_le32(ql84_mgmt->mgmt.mgmtp.u.info.type); |
| 1089 | |
| 1090 | mn->parameter2 = |
| 1091 | cpu_to_le32( |
| 1092 | ql84_mgmt->mgmt.mgmtp.u.info.context); |
| 1093 | } |
| 1094 | break; |
| 1095 | |
| 1096 | case QLA84_MGMT_WRITE_MEM: |
| 1097 | sg_cnt = dma_map_sg(&ha->pdev->dev, |
| 1098 | bsg_job->request_payload.sg_list, |
| 1099 | bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE); |
| 1100 | |
| 1101 | if (!sg_cnt) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1102 | ql_log(ql_log_warn, vha, 0x7040, |
| 1103 | "dma_map_sg returned %d.\n", sg_cnt); |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 1104 | rval = -ENOMEM; |
| 1105 | goto exit_mgmt; |
| 1106 | } |
| 1107 | |
| 1108 | dma_direction = DMA_TO_DEVICE; |
| 1109 | |
| 1110 | if (sg_cnt != bsg_job->request_payload.sg_cnt) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1111 | ql_log(ql_log_warn, vha, 0x7041, |
| 1112 | "DMA mapping resulted in different sg counts, " |
| 1113 | "request_sg_cnt: %x dma_request_sg_cnt: %x.\n", |
| 1114 | bsg_job->request_payload.sg_cnt, sg_cnt); |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 1115 | rval = -EAGAIN; |
| 1116 | goto done_unmap_sg; |
| 1117 | } |
| 1118 | |
| 1119 | data_len = bsg_job->request_payload.payload_len; |
| 1120 | mgmt_b = dma_alloc_coherent(&ha->pdev->dev, data_len, |
| 1121 | &mgmt_dma, GFP_KERNEL); |
| 1122 | if (!mgmt_b) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1123 | ql_log(ql_log_warn, vha, 0x7042, |
| 1124 | "DMA alloc failed for mgmt_b.\n"); |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 1125 | rval = -ENOMEM; |
| 1126 | goto done_unmap_sg; |
| 1127 | } |
| 1128 | |
| 1129 | sg_copy_to_buffer(bsg_job->request_payload.sg_list, |
| 1130 | bsg_job->request_payload.sg_cnt, mgmt_b, data_len); |
| 1131 | |
| 1132 | mn->options = cpu_to_le16(ACO_LOAD_MEMORY); |
| 1133 | mn->parameter1 = |
| 1134 | cpu_to_le32(ql84_mgmt->mgmt.mgmtp.u.mem.start_addr); |
| 1135 | break; |
| 1136 | |
| 1137 | case QLA84_MGMT_CHNG_CONFIG: |
| 1138 | mn->options = cpu_to_le16(ACO_CHANGE_CONFIG_PARAM); |
| 1139 | mn->parameter1 = |
| 1140 | cpu_to_le32(ql84_mgmt->mgmt.mgmtp.u.config.id); |
| 1141 | |
| 1142 | mn->parameter2 = |
| 1143 | cpu_to_le32(ql84_mgmt->mgmt.mgmtp.u.config.param0); |
| 1144 | |
| 1145 | mn->parameter3 = |
| 1146 | cpu_to_le32(ql84_mgmt->mgmt.mgmtp.u.config.param1); |
| 1147 | break; |
| 1148 | |
| 1149 | default: |
| 1150 | rval = -EIO; |
| 1151 | goto exit_mgmt; |
| 1152 | } |
| 1153 | |
| 1154 | if (ql84_mgmt->mgmt.cmd != QLA84_MGMT_CHNG_CONFIG) { |
| 1155 | mn->total_byte_cnt = cpu_to_le32(ql84_mgmt->mgmt.len); |
| 1156 | mn->dseg_count = cpu_to_le16(1); |
| 1157 | mn->dseg_address[0] = cpu_to_le32(LSD(mgmt_dma)); |
| 1158 | mn->dseg_address[1] = cpu_to_le32(MSD(mgmt_dma)); |
| 1159 | mn->dseg_length = cpu_to_le32(ql84_mgmt->mgmt.len); |
| 1160 | } |
| 1161 | |
| 1162 | rval = qla2x00_issue_iocb(vha, mn, mn_dma, 0); |
| 1163 | |
| 1164 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1165 | ql_log(ql_log_warn, vha, 0x7043, |
| 1166 | "Vendor request 84xx mgmt failed.\n"); |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 1167 | |
| 1168 | rval = bsg_job->reply->reply_payload_rcv_len = 0; |
| 1169 | bsg_job->reply->result = (DID_ERROR << 16); |
| 1170 | |
| 1171 | } else { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1172 | ql_dbg(ql_dbg_user, vha, 0x7044, |
| 1173 | "Vendor request 84xx mgmt completed.\n"); |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 1174 | |
| 1175 | bsg_job->reply_len = sizeof(struct fc_bsg_reply); |
| 1176 | bsg_job->reply->result = DID_OK; |
| 1177 | |
| 1178 | if ((ql84_mgmt->mgmt.cmd == QLA84_MGMT_READ_MEM) || |
| 1179 | (ql84_mgmt->mgmt.cmd == QLA84_MGMT_GET_INFO)) { |
| 1180 | bsg_job->reply->reply_payload_rcv_len = |
| 1181 | bsg_job->reply_payload.payload_len; |
| 1182 | |
| 1183 | sg_copy_from_buffer(bsg_job->reply_payload.sg_list, |
Andrew Vasquez | 6c452a4 | 2010-03-19 17:04:02 -0700 | [diff] [blame] | 1184 | bsg_job->reply_payload.sg_cnt, mgmt_b, |
| 1185 | data_len); |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 1186 | } |
| 1187 | } |
| 1188 | |
| 1189 | bsg_job->job_done(bsg_job); |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 1190 | |
| 1191 | done_unmap_sg: |
Harish Zunjarrao | d545908 | 2010-03-19 17:04:00 -0700 | [diff] [blame] | 1192 | if (mgmt_b) |
| 1193 | dma_free_coherent(&ha->pdev->dev, data_len, mgmt_b, mgmt_dma); |
| 1194 | |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 1195 | if (dma_direction == DMA_TO_DEVICE) |
| 1196 | dma_unmap_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list, |
| 1197 | bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE); |
| 1198 | else if (dma_direction == DMA_FROM_DEVICE) |
| 1199 | dma_unmap_sg(&ha->pdev->dev, bsg_job->reply_payload.sg_list, |
| 1200 | bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE); |
| 1201 | |
| 1202 | exit_mgmt: |
| 1203 | dma_pool_free(ha->s_dma_pool, mn, mn_dma); |
| 1204 | |
| 1205 | return rval; |
| 1206 | } |
| 1207 | |
| 1208 | static int |
| 1209 | qla24xx_iidma(struct fc_bsg_job *bsg_job) |
| 1210 | { |
| 1211 | struct Scsi_Host *host = bsg_job->shost; |
| 1212 | scsi_qla_host_t *vha = shost_priv(host); |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 1213 | int rval = 0; |
| 1214 | struct qla_port_param *port_param = NULL; |
| 1215 | fc_port_t *fcport = NULL; |
| 1216 | uint16_t mb[MAILBOX_REGISTER_COUNT]; |
| 1217 | uint8_t *rsp_ptr = NULL; |
| 1218 | |
| 1219 | bsg_job->reply->reply_payload_rcv_len = 0; |
| 1220 | |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 1221 | if (!IS_IIDMA_CAPABLE(vha->hw)) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1222 | ql_log(ql_log_info, vha, 0x7046, "iiDMA not supported.\n"); |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 1223 | return -EINVAL; |
| 1224 | } |
| 1225 | |
| 1226 | port_param = (struct qla_port_param *)((char *)bsg_job->request + |
| 1227 | sizeof(struct fc_bsg_request)); |
| 1228 | if (!port_param) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1229 | ql_log(ql_log_warn, vha, 0x7047, |
| 1230 | "port_param header not provided.\n"); |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 1231 | return -EINVAL; |
| 1232 | } |
| 1233 | |
| 1234 | if (port_param->fc_scsi_addr.dest_type != EXT_DEF_TYPE_WWPN) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1235 | ql_log(ql_log_warn, vha, 0x7048, |
| 1236 | "Invalid destination type.\n"); |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 1237 | return -EINVAL; |
| 1238 | } |
| 1239 | |
| 1240 | list_for_each_entry(fcport, &vha->vp_fcports, list) { |
| 1241 | if (fcport->port_type != FCT_TARGET) |
| 1242 | continue; |
| 1243 | |
| 1244 | if (memcmp(port_param->fc_scsi_addr.dest_addr.wwpn, |
| 1245 | fcport->port_name, sizeof(fcport->port_name))) |
| 1246 | continue; |
| 1247 | break; |
| 1248 | } |
| 1249 | |
| 1250 | if (!fcport) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1251 | ql_log(ql_log_warn, vha, 0x7049, |
| 1252 | "Failed to find port.\n"); |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 1253 | return -EINVAL; |
| 1254 | } |
| 1255 | |
Giridhar Malavali | c9afb9a | 2010-09-03 15:20:48 -0700 | [diff] [blame] | 1256 | if (atomic_read(&fcport->state) != FCS_ONLINE) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1257 | ql_log(ql_log_warn, vha, 0x704a, |
| 1258 | "Port is not online.\n"); |
Madhuranath Iyengar | 17cf2c5 | 2010-07-23 15:28:22 +0500 | [diff] [blame] | 1259 | return -EINVAL; |
| 1260 | } |
| 1261 | |
Madhuranath Iyengar | 9a15eb4 | 2010-07-23 15:28:31 +0500 | [diff] [blame] | 1262 | if (fcport->flags & FCF_LOGIN_NEEDED) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1263 | ql_log(ql_log_warn, vha, 0x704b, |
| 1264 | "Remote port not logged in flags = 0x%x.\n", fcport->flags); |
Madhuranath Iyengar | 9a15eb4 | 2010-07-23 15:28:31 +0500 | [diff] [blame] | 1265 | return -EINVAL; |
| 1266 | } |
| 1267 | |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 1268 | if (port_param->mode) |
| 1269 | rval = qla2x00_set_idma_speed(vha, fcport->loop_id, |
| 1270 | port_param->speed, mb); |
| 1271 | else |
| 1272 | rval = qla2x00_get_idma_speed(vha, fcport->loop_id, |
| 1273 | &port_param->speed, mb); |
| 1274 | |
| 1275 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1276 | ql_log(ql_log_warn, vha, 0x704c, |
| 1277 | "iIDMA cmd failed for %02x%02x%02x%02x%02x%02x%02x%02x -- " |
| 1278 | "%04x %x %04x %04x.\n", fcport->port_name[0], |
| 1279 | fcport->port_name[1], fcport->port_name[2], |
| 1280 | fcport->port_name[3], fcport->port_name[4], |
| 1281 | fcport->port_name[5], fcport->port_name[6], |
| 1282 | fcport->port_name[7], rval, fcport->fp_speed, mb[0], mb[1]); |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 1283 | rval = 0; |
| 1284 | bsg_job->reply->result = (DID_ERROR << 16); |
| 1285 | |
| 1286 | } else { |
| 1287 | if (!port_param->mode) { |
| 1288 | bsg_job->reply_len = sizeof(struct fc_bsg_reply) + |
| 1289 | sizeof(struct qla_port_param); |
| 1290 | |
| 1291 | rsp_ptr = ((uint8_t *)bsg_job->reply) + |
| 1292 | sizeof(struct fc_bsg_reply); |
| 1293 | |
| 1294 | memcpy(rsp_ptr, port_param, |
| 1295 | sizeof(struct qla_port_param)); |
| 1296 | } |
| 1297 | |
| 1298 | bsg_job->reply->result = DID_OK; |
| 1299 | } |
| 1300 | |
| 1301 | bsg_job->job_done(bsg_job); |
| 1302 | return rval; |
| 1303 | } |
| 1304 | |
| 1305 | static int |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1306 | qla2x00_optrom_setup(struct fc_bsg_job *bsg_job, scsi_qla_host_t *vha, |
Harish Zunjarrao | f19af16 | 2010-10-15 11:27:43 -0700 | [diff] [blame] | 1307 | uint8_t is_update) |
| 1308 | { |
| 1309 | uint32_t start = 0; |
| 1310 | int valid = 0; |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1311 | struct qla_hw_data *ha = vha->hw; |
Harish Zunjarrao | f19af16 | 2010-10-15 11:27:43 -0700 | [diff] [blame] | 1312 | |
| 1313 | bsg_job->reply->reply_payload_rcv_len = 0; |
| 1314 | |
| 1315 | if (unlikely(pci_channel_offline(ha->pdev))) |
| 1316 | return -EINVAL; |
| 1317 | |
| 1318 | start = bsg_job->request->rqst_data.h_vendor.vendor_cmd[1]; |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1319 | if (start > ha->optrom_size) { |
| 1320 | ql_log(ql_log_warn, vha, 0x7055, |
| 1321 | "start %d > optrom_size %d.\n", start, ha->optrom_size); |
Harish Zunjarrao | f19af16 | 2010-10-15 11:27:43 -0700 | [diff] [blame] | 1322 | return -EINVAL; |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1323 | } |
Harish Zunjarrao | f19af16 | 2010-10-15 11:27:43 -0700 | [diff] [blame] | 1324 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1325 | if (ha->optrom_state != QLA_SWAITING) { |
| 1326 | ql_log(ql_log_info, vha, 0x7056, |
| 1327 | "optrom_state %d.\n", ha->optrom_state); |
Harish Zunjarrao | f19af16 | 2010-10-15 11:27:43 -0700 | [diff] [blame] | 1328 | return -EBUSY; |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1329 | } |
Harish Zunjarrao | f19af16 | 2010-10-15 11:27:43 -0700 | [diff] [blame] | 1330 | |
| 1331 | ha->optrom_region_start = start; |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1332 | ql_dbg(ql_dbg_user, vha, 0x7057, "is_update=%d.\n", is_update); |
Harish Zunjarrao | f19af16 | 2010-10-15 11:27:43 -0700 | [diff] [blame] | 1333 | if (is_update) { |
| 1334 | if (ha->optrom_size == OPTROM_SIZE_2300 && start == 0) |
| 1335 | valid = 1; |
| 1336 | else if (start == (ha->flt_region_boot * 4) || |
| 1337 | start == (ha->flt_region_fw * 4)) |
| 1338 | valid = 1; |
| 1339 | else if (IS_QLA24XX_TYPE(ha) || IS_QLA25XX(ha) || |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 1340 | IS_CNA_CAPABLE(ha) || IS_QLA2031(ha)) |
Harish Zunjarrao | f19af16 | 2010-10-15 11:27:43 -0700 | [diff] [blame] | 1341 | valid = 1; |
| 1342 | if (!valid) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1343 | ql_log(ql_log_warn, vha, 0x7058, |
| 1344 | "Invalid start region 0x%x/0x%x.\n", start, |
| 1345 | bsg_job->request_payload.payload_len); |
Harish Zunjarrao | f19af16 | 2010-10-15 11:27:43 -0700 | [diff] [blame] | 1346 | return -EINVAL; |
| 1347 | } |
| 1348 | |
| 1349 | ha->optrom_region_size = start + |
| 1350 | bsg_job->request_payload.payload_len > ha->optrom_size ? |
| 1351 | ha->optrom_size - start : |
| 1352 | bsg_job->request_payload.payload_len; |
| 1353 | ha->optrom_state = QLA_SWRITING; |
| 1354 | } else { |
| 1355 | ha->optrom_region_size = start + |
| 1356 | bsg_job->reply_payload.payload_len > ha->optrom_size ? |
| 1357 | ha->optrom_size - start : |
| 1358 | bsg_job->reply_payload.payload_len; |
| 1359 | ha->optrom_state = QLA_SREADING; |
| 1360 | } |
| 1361 | |
| 1362 | ha->optrom_buffer = vmalloc(ha->optrom_region_size); |
| 1363 | if (!ha->optrom_buffer) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1364 | ql_log(ql_log_warn, vha, 0x7059, |
Harish Zunjarrao | f19af16 | 2010-10-15 11:27:43 -0700 | [diff] [blame] | 1365 | "Read: Unable to allocate memory for optrom retrieval " |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1366 | "(%x)\n", ha->optrom_region_size); |
Harish Zunjarrao | f19af16 | 2010-10-15 11:27:43 -0700 | [diff] [blame] | 1367 | |
| 1368 | ha->optrom_state = QLA_SWAITING; |
| 1369 | return -ENOMEM; |
| 1370 | } |
| 1371 | |
| 1372 | memset(ha->optrom_buffer, 0, ha->optrom_region_size); |
| 1373 | return 0; |
| 1374 | } |
| 1375 | |
| 1376 | static int |
| 1377 | qla2x00_read_optrom(struct fc_bsg_job *bsg_job) |
| 1378 | { |
| 1379 | struct Scsi_Host *host = bsg_job->shost; |
| 1380 | scsi_qla_host_t *vha = shost_priv(host); |
| 1381 | struct qla_hw_data *ha = vha->hw; |
| 1382 | int rval = 0; |
| 1383 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1384 | rval = qla2x00_optrom_setup(bsg_job, vha, 0); |
Harish Zunjarrao | f19af16 | 2010-10-15 11:27:43 -0700 | [diff] [blame] | 1385 | if (rval) |
| 1386 | return rval; |
| 1387 | |
| 1388 | ha->isp_ops->read_optrom(vha, ha->optrom_buffer, |
| 1389 | ha->optrom_region_start, ha->optrom_region_size); |
| 1390 | |
| 1391 | sg_copy_from_buffer(bsg_job->reply_payload.sg_list, |
| 1392 | bsg_job->reply_payload.sg_cnt, ha->optrom_buffer, |
| 1393 | ha->optrom_region_size); |
| 1394 | |
| 1395 | bsg_job->reply->reply_payload_rcv_len = ha->optrom_region_size; |
| 1396 | bsg_job->reply->result = DID_OK; |
| 1397 | vfree(ha->optrom_buffer); |
| 1398 | ha->optrom_buffer = NULL; |
| 1399 | ha->optrom_state = QLA_SWAITING; |
| 1400 | bsg_job->job_done(bsg_job); |
| 1401 | return rval; |
| 1402 | } |
| 1403 | |
| 1404 | static int |
| 1405 | qla2x00_update_optrom(struct fc_bsg_job *bsg_job) |
| 1406 | { |
| 1407 | struct Scsi_Host *host = bsg_job->shost; |
| 1408 | scsi_qla_host_t *vha = shost_priv(host); |
| 1409 | struct qla_hw_data *ha = vha->hw; |
| 1410 | int rval = 0; |
| 1411 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1412 | rval = qla2x00_optrom_setup(bsg_job, vha, 1); |
Harish Zunjarrao | f19af16 | 2010-10-15 11:27:43 -0700 | [diff] [blame] | 1413 | if (rval) |
| 1414 | return rval; |
| 1415 | |
| 1416 | sg_copy_to_buffer(bsg_job->request_payload.sg_list, |
| 1417 | bsg_job->request_payload.sg_cnt, ha->optrom_buffer, |
| 1418 | ha->optrom_region_size); |
| 1419 | |
| 1420 | ha->isp_ops->write_optrom(vha, ha->optrom_buffer, |
| 1421 | ha->optrom_region_start, ha->optrom_region_size); |
| 1422 | |
| 1423 | bsg_job->reply->result = DID_OK; |
| 1424 | vfree(ha->optrom_buffer); |
| 1425 | ha->optrom_buffer = NULL; |
| 1426 | ha->optrom_state = QLA_SWAITING; |
| 1427 | bsg_job->job_done(bsg_job); |
| 1428 | return rval; |
| 1429 | } |
| 1430 | |
| 1431 | static int |
Joe Carnuccio | 697a4bc | 2011-08-16 11:31:52 -0700 | [diff] [blame] | 1432 | qla2x00_update_fru_versions(struct fc_bsg_job *bsg_job) |
| 1433 | { |
| 1434 | struct Scsi_Host *host = bsg_job->shost; |
| 1435 | scsi_qla_host_t *vha = shost_priv(host); |
| 1436 | struct qla_hw_data *ha = vha->hw; |
| 1437 | int rval = 0; |
| 1438 | uint8_t bsg[DMA_POOL_SIZE]; |
| 1439 | struct qla_image_version_list *list = (void *)bsg; |
| 1440 | struct qla_image_version *image; |
| 1441 | uint32_t count; |
| 1442 | dma_addr_t sfp_dma; |
| 1443 | void *sfp = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &sfp_dma); |
| 1444 | if (!sfp) { |
| 1445 | bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] = |
| 1446 | EXT_STATUS_NO_MEMORY; |
| 1447 | goto done; |
| 1448 | } |
| 1449 | |
| 1450 | sg_copy_to_buffer(bsg_job->request_payload.sg_list, |
| 1451 | bsg_job->request_payload.sg_cnt, list, sizeof(bsg)); |
| 1452 | |
| 1453 | image = list->version; |
| 1454 | count = list->count; |
| 1455 | while (count--) { |
| 1456 | memcpy(sfp, &image->field_info, sizeof(image->field_info)); |
| 1457 | rval = qla2x00_write_sfp(vha, sfp_dma, sfp, |
| 1458 | image->field_address.device, image->field_address.offset, |
| 1459 | sizeof(image->field_info), image->field_address.option); |
| 1460 | if (rval) { |
| 1461 | bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] = |
| 1462 | EXT_STATUS_MAILBOX; |
| 1463 | goto dealloc; |
| 1464 | } |
| 1465 | image++; |
| 1466 | } |
| 1467 | |
| 1468 | bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] = 0; |
| 1469 | |
| 1470 | dealloc: |
| 1471 | dma_pool_free(ha->s_dma_pool, sfp, sfp_dma); |
| 1472 | |
| 1473 | done: |
| 1474 | bsg_job->reply_len = sizeof(struct fc_bsg_reply); |
| 1475 | bsg_job->reply->result = DID_OK << 16; |
| 1476 | bsg_job->job_done(bsg_job); |
| 1477 | |
| 1478 | return 0; |
| 1479 | } |
| 1480 | |
| 1481 | static int |
| 1482 | qla2x00_read_fru_status(struct fc_bsg_job *bsg_job) |
| 1483 | { |
| 1484 | struct Scsi_Host *host = bsg_job->shost; |
| 1485 | scsi_qla_host_t *vha = shost_priv(host); |
| 1486 | struct qla_hw_data *ha = vha->hw; |
| 1487 | int rval = 0; |
| 1488 | uint8_t bsg[DMA_POOL_SIZE]; |
| 1489 | struct qla_status_reg *sr = (void *)bsg; |
| 1490 | dma_addr_t sfp_dma; |
| 1491 | uint8_t *sfp = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &sfp_dma); |
| 1492 | if (!sfp) { |
| 1493 | bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] = |
| 1494 | EXT_STATUS_NO_MEMORY; |
| 1495 | goto done; |
| 1496 | } |
| 1497 | |
| 1498 | sg_copy_to_buffer(bsg_job->request_payload.sg_list, |
| 1499 | bsg_job->request_payload.sg_cnt, sr, sizeof(*sr)); |
| 1500 | |
| 1501 | rval = qla2x00_read_sfp(vha, sfp_dma, sfp, |
| 1502 | sr->field_address.device, sr->field_address.offset, |
| 1503 | sizeof(sr->status_reg), sr->field_address.option); |
| 1504 | sr->status_reg = *sfp; |
| 1505 | |
| 1506 | if (rval) { |
| 1507 | bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] = |
| 1508 | EXT_STATUS_MAILBOX; |
| 1509 | goto dealloc; |
| 1510 | } |
| 1511 | |
| 1512 | sg_copy_from_buffer(bsg_job->reply_payload.sg_list, |
| 1513 | bsg_job->reply_payload.sg_cnt, sr, sizeof(*sr)); |
| 1514 | |
| 1515 | bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] = 0; |
| 1516 | |
| 1517 | dealloc: |
| 1518 | dma_pool_free(ha->s_dma_pool, sfp, sfp_dma); |
| 1519 | |
| 1520 | done: |
| 1521 | bsg_job->reply_len = sizeof(struct fc_bsg_reply); |
| 1522 | bsg_job->reply->reply_payload_rcv_len = sizeof(*sr); |
| 1523 | bsg_job->reply->result = DID_OK << 16; |
| 1524 | bsg_job->job_done(bsg_job); |
| 1525 | |
| 1526 | return 0; |
| 1527 | } |
| 1528 | |
| 1529 | static int |
| 1530 | qla2x00_write_fru_status(struct fc_bsg_job *bsg_job) |
| 1531 | { |
| 1532 | struct Scsi_Host *host = bsg_job->shost; |
| 1533 | scsi_qla_host_t *vha = shost_priv(host); |
| 1534 | struct qla_hw_data *ha = vha->hw; |
| 1535 | int rval = 0; |
| 1536 | uint8_t bsg[DMA_POOL_SIZE]; |
| 1537 | struct qla_status_reg *sr = (void *)bsg; |
| 1538 | dma_addr_t sfp_dma; |
| 1539 | uint8_t *sfp = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &sfp_dma); |
| 1540 | if (!sfp) { |
| 1541 | bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] = |
| 1542 | EXT_STATUS_NO_MEMORY; |
| 1543 | goto done; |
| 1544 | } |
| 1545 | |
| 1546 | sg_copy_to_buffer(bsg_job->request_payload.sg_list, |
| 1547 | bsg_job->request_payload.sg_cnt, sr, sizeof(*sr)); |
| 1548 | |
| 1549 | *sfp = sr->status_reg; |
| 1550 | rval = qla2x00_write_sfp(vha, sfp_dma, sfp, |
| 1551 | sr->field_address.device, sr->field_address.offset, |
| 1552 | sizeof(sr->status_reg), sr->field_address.option); |
| 1553 | |
| 1554 | if (rval) { |
| 1555 | bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] = |
| 1556 | EXT_STATUS_MAILBOX; |
| 1557 | goto dealloc; |
| 1558 | } |
| 1559 | |
| 1560 | bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] = 0; |
| 1561 | |
| 1562 | dealloc: |
| 1563 | dma_pool_free(ha->s_dma_pool, sfp, sfp_dma); |
| 1564 | |
| 1565 | done: |
| 1566 | bsg_job->reply_len = sizeof(struct fc_bsg_reply); |
| 1567 | bsg_job->reply->result = DID_OK << 16; |
| 1568 | bsg_job->job_done(bsg_job); |
| 1569 | |
| 1570 | return 0; |
| 1571 | } |
| 1572 | |
| 1573 | static int |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 1574 | qla2x00_process_vendor_specific(struct fc_bsg_job *bsg_job) |
| 1575 | { |
| 1576 | switch (bsg_job->request->rqst_data.h_vendor.vendor_cmd[0]) { |
| 1577 | case QL_VND_LOOPBACK: |
| 1578 | return qla2x00_process_loopback(bsg_job); |
| 1579 | |
| 1580 | case QL_VND_A84_RESET: |
| 1581 | return qla84xx_reset(bsg_job); |
| 1582 | |
| 1583 | case QL_VND_A84_UPDATE_FW: |
| 1584 | return qla84xx_updatefw(bsg_job); |
| 1585 | |
| 1586 | case QL_VND_A84_MGMT_CMD: |
| 1587 | return qla84xx_mgmt_cmd(bsg_job); |
| 1588 | |
| 1589 | case QL_VND_IIDMA: |
| 1590 | return qla24xx_iidma(bsg_job); |
| 1591 | |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 1592 | case QL_VND_FCP_PRIO_CFG_CMD: |
| 1593 | return qla24xx_proc_fcp_prio_cfg_cmd(bsg_job); |
| 1594 | |
Harish Zunjarrao | f19af16 | 2010-10-15 11:27:43 -0700 | [diff] [blame] | 1595 | case QL_VND_READ_FLASH: |
| 1596 | return qla2x00_read_optrom(bsg_job); |
| 1597 | |
| 1598 | case QL_VND_UPDATE_FLASH: |
| 1599 | return qla2x00_update_optrom(bsg_job); |
| 1600 | |
Joe Carnuccio | 697a4bc | 2011-08-16 11:31:52 -0700 | [diff] [blame] | 1601 | case QL_VND_SET_FRU_VERSION: |
| 1602 | return qla2x00_update_fru_versions(bsg_job); |
| 1603 | |
| 1604 | case QL_VND_READ_FRU_STATUS: |
| 1605 | return qla2x00_read_fru_status(bsg_job); |
| 1606 | |
| 1607 | case QL_VND_WRITE_FRU_STATUS: |
| 1608 | return qla2x00_write_fru_status(bsg_job); |
| 1609 | |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 1610 | default: |
| 1611 | bsg_job->reply->result = (DID_ERROR << 16); |
| 1612 | bsg_job->job_done(bsg_job); |
| 1613 | return -ENOSYS; |
| 1614 | } |
| 1615 | } |
| 1616 | |
| 1617 | int |
| 1618 | qla24xx_bsg_request(struct fc_bsg_job *bsg_job) |
| 1619 | { |
| 1620 | int ret = -EINVAL; |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1621 | struct fc_rport *rport; |
| 1622 | fc_port_t *fcport = NULL; |
| 1623 | struct Scsi_Host *host; |
| 1624 | scsi_qla_host_t *vha; |
| 1625 | |
| 1626 | if (bsg_job->request->msgcode == FC_BSG_RPT_ELS) { |
| 1627 | rport = bsg_job->rport; |
| 1628 | fcport = *(fc_port_t **) rport->dd_data; |
| 1629 | host = rport_to_shost(rport); |
| 1630 | vha = shost_priv(host); |
| 1631 | } else { |
| 1632 | host = bsg_job->shost; |
| 1633 | vha = shost_priv(host); |
| 1634 | } |
| 1635 | |
Andrew Vasquez | d051a5aa | 2012-02-09 11:14:05 -0800 | [diff] [blame] | 1636 | if (qla2x00_reset_active(vha)) { |
| 1637 | ql_dbg(ql_dbg_user, vha, 0x709f, |
| 1638 | "BSG: ISP abort active/needed -- cmd=%d.\n", |
| 1639 | bsg_job->request->msgcode); |
| 1640 | bsg_job->reply->result = (DID_ERROR << 16); |
| 1641 | bsg_job->job_done(bsg_job); |
| 1642 | return -EBUSY; |
| 1643 | } |
| 1644 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1645 | ql_dbg(ql_dbg_user, vha, 0x7000, |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 1646 | "Entered %s msgcode=0x%x.\n", __func__, bsg_job->request->msgcode); |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 1647 | |
| 1648 | switch (bsg_job->request->msgcode) { |
| 1649 | case FC_BSG_RPT_ELS: |
| 1650 | case FC_BSG_HST_ELS_NOLOGIN: |
| 1651 | ret = qla2x00_process_els(bsg_job); |
| 1652 | break; |
| 1653 | case FC_BSG_HST_CT: |
| 1654 | ret = qla2x00_process_ct(bsg_job); |
| 1655 | break; |
| 1656 | case FC_BSG_HST_VENDOR: |
| 1657 | ret = qla2x00_process_vendor_specific(bsg_job); |
| 1658 | break; |
| 1659 | case FC_BSG_HST_ADD_RPORT: |
| 1660 | case FC_BSG_HST_DEL_RPORT: |
| 1661 | case FC_BSG_RPT_CT: |
| 1662 | default: |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1663 | ql_log(ql_log_warn, vha, 0x705a, "Unsupported BSG request.\n"); |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 1664 | break; |
Andrew Vasquez | 6c452a4 | 2010-03-19 17:04:02 -0700 | [diff] [blame] | 1665 | } |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 1666 | return ret; |
| 1667 | } |
| 1668 | |
| 1669 | int |
| 1670 | qla24xx_bsg_timeout(struct fc_bsg_job *bsg_job) |
| 1671 | { |
| 1672 | scsi_qla_host_t *vha = shost_priv(bsg_job->shost); |
| 1673 | struct qla_hw_data *ha = vha->hw; |
| 1674 | srb_t *sp; |
| 1675 | int cnt, que; |
| 1676 | unsigned long flags; |
| 1677 | struct req_que *req; |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 1678 | |
| 1679 | /* find the bsg job from the active list of commands */ |
| 1680 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 1681 | for (que = 0; que < ha->max_req_queues; que++) { |
| 1682 | req = ha->req_q_map[que]; |
| 1683 | if (!req) |
| 1684 | continue; |
| 1685 | |
Andrew Vasquez | 6c452a4 | 2010-03-19 17:04:02 -0700 | [diff] [blame] | 1686 | for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) { |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 1687 | sp = req->outstanding_cmds[cnt]; |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 1688 | if (sp) { |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame^] | 1689 | if (((sp->type == SRB_CT_CMD) || |
| 1690 | (sp->type == SRB_ELS_CMD_HST)) |
| 1691 | && (sp->u.bsg_job == bsg_job)) { |
Giridhar Malavali | 900a36e | 2010-12-21 16:00:26 -0800 | [diff] [blame] | 1692 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 1693 | if (ha->isp_ops->abort_command(sp)) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1694 | ql_log(ql_log_warn, vha, 0x7089, |
| 1695 | "mbx abort_command " |
| 1696 | "failed.\n"); |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 1697 | bsg_job->req->errors = |
| 1698 | bsg_job->reply->result = -EIO; |
| 1699 | } else { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1700 | ql_dbg(ql_dbg_user, vha, 0x708a, |
| 1701 | "mbx abort_command " |
| 1702 | "success.\n"); |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 1703 | bsg_job->req->errors = |
| 1704 | bsg_job->reply->result = 0; |
| 1705 | } |
Giridhar Malavali | 900a36e | 2010-12-21 16:00:26 -0800 | [diff] [blame] | 1706 | spin_lock_irqsave(&ha->hardware_lock, flags); |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 1707 | goto done; |
| 1708 | } |
| 1709 | } |
| 1710 | } |
| 1711 | } |
| 1712 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1713 | ql_log(ql_log_info, vha, 0x708b, "SRB not found to abort.\n"); |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 1714 | bsg_job->req->errors = bsg_job->reply->result = -ENXIO; |
| 1715 | return 0; |
| 1716 | |
| 1717 | done: |
| 1718 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 1719 | if (bsg_job->request->msgcode == FC_BSG_HST_CT) |
| 1720 | kfree(sp->fcport); |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 1721 | mempool_free(sp, ha->srb_mempool); |
| 1722 | return 0; |
| 1723 | } |