Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 1 | /* |
| 2 | * QLogic Fibre Channel HBA Driver |
Chad Dupuis | 46152ce | 2012-08-22 14:21:08 -0400 | [diff] [blame] | 3 | * Copyright (c) 2003-2012 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; |
Chad Dupuis | b00ee7d | 2013-02-08 01:57:50 -0500 | [diff] [blame] | 30 | struct scsi_qla_host *vha = sp->fcport->vha; |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 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 | 8ae6d9c | 2013-03-28 08:21:23 -0400 | [diff] [blame] | 33 | struct qla_mt_iocb_rqst_fx00 *piocb_rqst; |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 34 | |
Giridhar Malavali | 8ae6d9c | 2013-03-28 08:21:23 -0400 | [diff] [blame] | 35 | if (sp->type == SRB_FXIOCB_BCMD) { |
| 36 | piocb_rqst = (struct qla_mt_iocb_rqst_fx00 *) |
| 37 | &bsg_job->request->rqst_data.h_vendor.vendor_cmd[1]; |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 38 | |
Giridhar Malavali | 8ae6d9c | 2013-03-28 08:21:23 -0400 | [diff] [blame] | 39 | if (piocb_rqst->flags & SRB_FXDISC_REQ_DMA_VALID) |
| 40 | dma_unmap_sg(&ha->pdev->dev, |
| 41 | bsg_job->request_payload.sg_list, |
| 42 | bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE); |
| 43 | |
| 44 | if (piocb_rqst->flags & SRB_FXDISC_RESP_DMA_VALID) |
| 45 | dma_unmap_sg(&ha->pdev->dev, |
| 46 | bsg_job->reply_payload.sg_list, |
| 47 | bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE); |
| 48 | } else { |
| 49 | dma_unmap_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list, |
| 50 | bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE); |
| 51 | |
| 52 | dma_unmap_sg(&ha->pdev->dev, bsg_job->reply_payload.sg_list, |
| 53 | bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE); |
| 54 | } |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 55 | |
| 56 | if (sp->type == SRB_CT_CMD || |
Giridhar Malavali | 8ae6d9c | 2013-03-28 08:21:23 -0400 | [diff] [blame] | 57 | sp->type == SRB_FXIOCB_BCMD || |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 58 | sp->type == SRB_ELS_CMD_HST) |
| 59 | kfree(sp->fcport); |
Chad Dupuis | b00ee7d | 2013-02-08 01:57:50 -0500 | [diff] [blame] | 60 | qla2x00_rel_sp(vha, sp); |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 61 | } |
| 62 | |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 63 | int |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 64 | qla24xx_fcp_prio_cfg_valid(scsi_qla_host_t *vha, |
| 65 | struct qla_fcp_prio_cfg *pri_cfg, uint8_t flag) |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 66 | { |
| 67 | int i, ret, num_valid; |
| 68 | uint8_t *bcode; |
| 69 | struct qla_fcp_prio_entry *pri_entry; |
Madhuranath Iyengar | 2f0f3f4 | 2010-07-23 15:28:24 +0500 | [diff] [blame] | 70 | uint32_t *bcode_val_ptr, bcode_val; |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 71 | |
| 72 | ret = 1; |
| 73 | num_valid = 0; |
| 74 | bcode = (uint8_t *)pri_cfg; |
Madhuranath Iyengar | 2f0f3f4 | 2010-07-23 15:28:24 +0500 | [diff] [blame] | 75 | bcode_val_ptr = (uint32_t *)pri_cfg; |
| 76 | bcode_val = (uint32_t)(*bcode_val_ptr); |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 77 | |
Madhuranath Iyengar | 2f0f3f4 | 2010-07-23 15:28:24 +0500 | [diff] [blame] | 78 | if (bcode_val == 0xFFFFFFFF) { |
| 79 | /* No FCP Priority config data in flash */ |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 80 | ql_dbg(ql_dbg_user, vha, 0x7051, |
| 81 | "No FCP Priority config data.\n"); |
Madhuranath Iyengar | 2f0f3f4 | 2010-07-23 15:28:24 +0500 | [diff] [blame] | 82 | return 0; |
| 83 | } |
| 84 | |
| 85 | if (bcode[0] != 'H' || bcode[1] != 'Q' || bcode[2] != 'O' || |
| 86 | bcode[3] != 'S') { |
| 87 | /* Invalid FCP priority data header*/ |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 88 | ql_dbg(ql_dbg_user, vha, 0x7052, |
| 89 | "Invalid FCP Priority data header. bcode=0x%x.\n", |
| 90 | bcode_val); |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 91 | return 0; |
| 92 | } |
| 93 | if (flag != 1) |
| 94 | return ret; |
| 95 | |
| 96 | pri_entry = &pri_cfg->entry[0]; |
| 97 | for (i = 0; i < pri_cfg->num_entries; i++) { |
| 98 | if (pri_entry->flags & FCP_PRIO_ENTRY_TAG_VALID) |
| 99 | num_valid++; |
| 100 | pri_entry++; |
| 101 | } |
| 102 | |
Madhuranath Iyengar | 2f0f3f4 | 2010-07-23 15:28:24 +0500 | [diff] [blame] | 103 | if (num_valid == 0) { |
| 104 | /* No valid FCP priority data entries */ |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 105 | ql_dbg(ql_dbg_user, vha, 0x7053, |
| 106 | "No valid FCP Priority data entries.\n"); |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 107 | ret = 0; |
Madhuranath Iyengar | 2f0f3f4 | 2010-07-23 15:28:24 +0500 | [diff] [blame] | 108 | } else { |
| 109 | /* FCP priority data is valid */ |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 110 | ql_dbg(ql_dbg_user, vha, 0x7054, |
| 111 | "Valid FCP priority data. num entries = %d.\n", |
| 112 | num_valid); |
Madhuranath Iyengar | 2f0f3f4 | 2010-07-23 15:28:24 +0500 | [diff] [blame] | 113 | } |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 114 | |
| 115 | return ret; |
| 116 | } |
| 117 | |
| 118 | static int |
| 119 | qla24xx_proc_fcp_prio_cfg_cmd(struct fc_bsg_job *bsg_job) |
| 120 | { |
| 121 | struct Scsi_Host *host = bsg_job->shost; |
| 122 | scsi_qla_host_t *vha = shost_priv(host); |
| 123 | struct qla_hw_data *ha = vha->hw; |
| 124 | int ret = 0; |
| 125 | uint32_t len; |
| 126 | uint32_t oper; |
| 127 | |
Atul Deshmukh | 7ec0eff | 2013-08-27 01:37:28 -0400 | [diff] [blame^] | 128 | if (!(IS_QLA24XX_TYPE(ha) || IS_QLA25XX(ha) || IS_P3P_TYPE(ha))) { |
Madhuranath Iyengar | 2f0f3f4 | 2010-07-23 15:28:24 +0500 | [diff] [blame] | 129 | ret = -EINVAL; |
| 130 | goto exit_fcp_prio_cfg; |
| 131 | } |
| 132 | |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 133 | /* Get the sub command */ |
| 134 | oper = bsg_job->request->rqst_data.h_vendor.vendor_cmd[1]; |
| 135 | |
| 136 | /* Only set config is allowed if config memory is not allocated */ |
| 137 | if (!ha->fcp_prio_cfg && (oper != QLFC_FCP_PRIO_SET_CONFIG)) { |
| 138 | ret = -EINVAL; |
| 139 | goto exit_fcp_prio_cfg; |
| 140 | } |
| 141 | switch (oper) { |
| 142 | case QLFC_FCP_PRIO_DISABLE: |
| 143 | if (ha->flags.fcp_prio_enabled) { |
| 144 | ha->flags.fcp_prio_enabled = 0; |
| 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 | break; |
| 155 | |
| 156 | case QLFC_FCP_PRIO_ENABLE: |
| 157 | if (!ha->flags.fcp_prio_enabled) { |
| 158 | if (ha->fcp_prio_cfg) { |
| 159 | ha->flags.fcp_prio_enabled = 1; |
| 160 | ha->fcp_prio_cfg->attributes |= |
| 161 | FCP_PRIO_ATTR_ENABLE; |
| 162 | qla24xx_update_all_fcp_prio(vha); |
| 163 | bsg_job->reply->result = DID_OK; |
| 164 | } else { |
| 165 | ret = -EINVAL; |
| 166 | bsg_job->reply->result = (DID_ERROR << 16); |
| 167 | goto exit_fcp_prio_cfg; |
| 168 | } |
| 169 | } |
| 170 | break; |
| 171 | |
| 172 | case QLFC_FCP_PRIO_GET_CONFIG: |
| 173 | len = bsg_job->reply_payload.payload_len; |
| 174 | if (!len || len > FCP_PRIO_CFG_SIZE) { |
| 175 | ret = -EINVAL; |
| 176 | bsg_job->reply->result = (DID_ERROR << 16); |
| 177 | goto exit_fcp_prio_cfg; |
| 178 | } |
| 179 | |
| 180 | bsg_job->reply->result = DID_OK; |
| 181 | bsg_job->reply->reply_payload_rcv_len = |
| 182 | sg_copy_from_buffer( |
| 183 | bsg_job->reply_payload.sg_list, |
| 184 | bsg_job->reply_payload.sg_cnt, ha->fcp_prio_cfg, |
| 185 | len); |
| 186 | |
| 187 | break; |
| 188 | |
| 189 | case QLFC_FCP_PRIO_SET_CONFIG: |
| 190 | len = bsg_job->request_payload.payload_len; |
| 191 | if (!len || len > FCP_PRIO_CFG_SIZE) { |
| 192 | bsg_job->reply->result = (DID_ERROR << 16); |
| 193 | ret = -EINVAL; |
| 194 | goto exit_fcp_prio_cfg; |
| 195 | } |
| 196 | |
| 197 | if (!ha->fcp_prio_cfg) { |
| 198 | ha->fcp_prio_cfg = vmalloc(FCP_PRIO_CFG_SIZE); |
| 199 | if (!ha->fcp_prio_cfg) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 200 | ql_log(ql_log_warn, vha, 0x7050, |
| 201 | "Unable to allocate memory for fcp prio " |
| 202 | "config data (%x).\n", FCP_PRIO_CFG_SIZE); |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 203 | bsg_job->reply->result = (DID_ERROR << 16); |
| 204 | ret = -ENOMEM; |
| 205 | goto exit_fcp_prio_cfg; |
| 206 | } |
| 207 | } |
| 208 | |
| 209 | memset(ha->fcp_prio_cfg, 0, FCP_PRIO_CFG_SIZE); |
| 210 | sg_copy_to_buffer(bsg_job->request_payload.sg_list, |
| 211 | bsg_job->request_payload.sg_cnt, ha->fcp_prio_cfg, |
| 212 | FCP_PRIO_CFG_SIZE); |
| 213 | |
| 214 | /* validate fcp priority data */ |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 215 | |
| 216 | if (!qla24xx_fcp_prio_cfg_valid(vha, |
| 217 | (struct qla_fcp_prio_cfg *) ha->fcp_prio_cfg, 1)) { |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 218 | bsg_job->reply->result = (DID_ERROR << 16); |
| 219 | ret = -EINVAL; |
| 220 | /* If buffer was invalidatic int |
| 221 | * fcp_prio_cfg is of no use |
| 222 | */ |
| 223 | vfree(ha->fcp_prio_cfg); |
| 224 | ha->fcp_prio_cfg = NULL; |
| 225 | goto exit_fcp_prio_cfg; |
| 226 | } |
| 227 | |
| 228 | ha->flags.fcp_prio_enabled = 0; |
| 229 | if (ha->fcp_prio_cfg->attributes & FCP_PRIO_ATTR_ENABLE) |
| 230 | ha->flags.fcp_prio_enabled = 1; |
| 231 | qla24xx_update_all_fcp_prio(vha); |
| 232 | bsg_job->reply->result = DID_OK; |
| 233 | break; |
| 234 | default: |
| 235 | ret = -EINVAL; |
| 236 | break; |
| 237 | } |
| 238 | exit_fcp_prio_cfg: |
Armen Baloyan | 63ea923 | 2012-11-21 02:39:53 -0500 | [diff] [blame] | 239 | if (!ret) |
| 240 | bsg_job->job_done(bsg_job); |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 241 | return ret; |
| 242 | } |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 243 | |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 244 | static int |
| 245 | qla2x00_process_els(struct fc_bsg_job *bsg_job) |
| 246 | { |
| 247 | struct fc_rport *rport; |
Harish Zunjarrao | 08f71e0 | 2010-07-23 15:28:33 +0500 | [diff] [blame] | 248 | fc_port_t *fcport = NULL; |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 249 | struct Scsi_Host *host; |
| 250 | scsi_qla_host_t *vha; |
| 251 | struct qla_hw_data *ha; |
| 252 | srb_t *sp; |
| 253 | const char *type; |
| 254 | int req_sg_cnt, rsp_sg_cnt; |
| 255 | int rval = (DRIVER_ERROR << 16); |
| 256 | uint16_t nextlid = 0; |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 257 | |
Harish Zunjarrao | 08f71e0 | 2010-07-23 15:28:33 +0500 | [diff] [blame] | 258 | if (bsg_job->request->msgcode == FC_BSG_RPT_ELS) { |
| 259 | rport = bsg_job->rport; |
| 260 | fcport = *(fc_port_t **) rport->dd_data; |
| 261 | host = rport_to_shost(rport); |
| 262 | vha = shost_priv(host); |
| 263 | ha = vha->hw; |
| 264 | type = "FC_BSG_RPT_ELS"; |
| 265 | } else { |
| 266 | host = bsg_job->shost; |
| 267 | vha = shost_priv(host); |
| 268 | ha = vha->hw; |
| 269 | type = "FC_BSG_HST_ELS_NOLOGIN"; |
| 270 | } |
| 271 | |
Bart Van Assche | 8c0eb59 | 2013-06-25 11:27:31 -0400 | [diff] [blame] | 272 | if (!vha->flags.online) { |
| 273 | ql_log(ql_log_warn, vha, 0x7005, "Host not online.\n"); |
| 274 | rval = -EIO; |
| 275 | goto done; |
| 276 | } |
| 277 | |
Harish Zunjarrao | 08f71e0 | 2010-07-23 15:28:33 +0500 | [diff] [blame] | 278 | /* pass through is supported only for ISP 4Gb or higher */ |
| 279 | if (!IS_FWI2_CAPABLE(ha)) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 280 | ql_dbg(ql_dbg_user, vha, 0x7001, |
| 281 | "ELS passthru not supported for ISP23xx based adapters.\n"); |
Harish Zunjarrao | 08f71e0 | 2010-07-23 15:28:33 +0500 | [diff] [blame] | 282 | rval = -EPERM; |
| 283 | goto done; |
| 284 | } |
| 285 | |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 286 | /* Multiple SG's are not supported for ELS requests */ |
| 287 | if (bsg_job->request_payload.sg_cnt > 1 || |
| 288 | bsg_job->reply_payload.sg_cnt > 1) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 289 | ql_dbg(ql_dbg_user, vha, 0x7002, |
| 290 | "Multiple SG's are not suppored for ELS requests, " |
| 291 | "request_sg_cnt=%x reply_sg_cnt=%x.\n", |
| 292 | bsg_job->request_payload.sg_cnt, |
| 293 | bsg_job->reply_payload.sg_cnt); |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 294 | rval = -EPERM; |
| 295 | goto done; |
| 296 | } |
| 297 | |
| 298 | /* ELS request for rport */ |
| 299 | if (bsg_job->request->msgcode == FC_BSG_RPT_ELS) { |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 300 | /* make sure the rport is logged in, |
| 301 | * if not perform fabric login |
| 302 | */ |
| 303 | if (qla2x00_fabric_login(vha, fcport, &nextlid)) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 304 | ql_dbg(ql_dbg_user, vha, 0x7003, |
| 305 | "Failed to login port %06X for ELS passthru.\n", |
| 306 | fcport->d_id.b24); |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 307 | rval = -EIO; |
| 308 | goto done; |
| 309 | } |
| 310 | } else { |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 311 | /* Allocate a dummy fcport structure, since functions |
| 312 | * preparing the IOCB and mailbox command retrieves port |
| 313 | * specific information from fcport structure. For Host based |
| 314 | * ELS commands there will be no fcport structure allocated |
| 315 | */ |
| 316 | fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL); |
| 317 | if (!fcport) { |
| 318 | rval = -ENOMEM; |
| 319 | goto done; |
| 320 | } |
| 321 | |
| 322 | /* Initialize all required fields of fcport */ |
| 323 | fcport->vha = vha; |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 324 | fcport->d_id.b.al_pa = |
| 325 | bsg_job->request->rqst_data.h_els.port_id[0]; |
| 326 | fcport->d_id.b.area = |
| 327 | bsg_job->request->rqst_data.h_els.port_id[1]; |
| 328 | fcport->d_id.b.domain = |
| 329 | bsg_job->request->rqst_data.h_els.port_id[2]; |
| 330 | fcport->loop_id = |
| 331 | (fcport->d_id.b.al_pa == 0xFD) ? |
| 332 | NPH_FABRIC_CONTROLLER : NPH_F_PORT; |
| 333 | } |
| 334 | |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 335 | req_sg_cnt = |
| 336 | dma_map_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list, |
| 337 | bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE); |
| 338 | if (!req_sg_cnt) { |
| 339 | rval = -ENOMEM; |
| 340 | goto done_free_fcport; |
| 341 | } |
Andrew Vasquez | 6c452a4 | 2010-03-19 17:04:02 -0700 | [diff] [blame] | 342 | |
| 343 | rsp_sg_cnt = dma_map_sg(&ha->pdev->dev, bsg_job->reply_payload.sg_list, |
| 344 | bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE); |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 345 | if (!rsp_sg_cnt) { |
| 346 | rval = -ENOMEM; |
| 347 | goto done_free_fcport; |
| 348 | } |
| 349 | |
| 350 | if ((req_sg_cnt != bsg_job->request_payload.sg_cnt) || |
Andrew Vasquez | 6c452a4 | 2010-03-19 17:04:02 -0700 | [diff] [blame] | 351 | (rsp_sg_cnt != bsg_job->reply_payload.sg_cnt)) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 352 | ql_log(ql_log_warn, vha, 0x7008, |
| 353 | "dma mapping resulted in different sg counts, " |
| 354 | "request_sg_cnt: %x dma_request_sg_cnt:%x reply_sg_cnt:%x " |
| 355 | "dma_reply_sg_cnt:%x.\n", bsg_job->request_payload.sg_cnt, |
| 356 | req_sg_cnt, bsg_job->reply_payload.sg_cnt, rsp_sg_cnt); |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 357 | rval = -EAGAIN; |
| 358 | goto done_unmap_sg; |
| 359 | } |
| 360 | |
| 361 | /* Alloc SRB structure */ |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 362 | sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL); |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 363 | if (!sp) { |
| 364 | rval = -ENOMEM; |
Andrew Vasquez | 6c452a4 | 2010-03-19 17:04:02 -0700 | [diff] [blame] | 365 | goto done_unmap_sg; |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 366 | } |
| 367 | |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 368 | sp->type = |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 369 | (bsg_job->request->msgcode == FC_BSG_RPT_ELS ? |
| 370 | SRB_ELS_CMD_RPT : SRB_ELS_CMD_HST); |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 371 | sp->name = |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 372 | (bsg_job->request->msgcode == FC_BSG_RPT_ELS ? |
| 373 | "bsg_els_rpt" : "bsg_els_hst"); |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 374 | sp->u.bsg_job = bsg_job; |
| 375 | sp->free = qla2x00_bsg_sp_free; |
| 376 | sp->done = qla2x00_bsg_job_done; |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 377 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 378 | ql_dbg(ql_dbg_user, vha, 0x700a, |
| 379 | "bsg rqst type: %s els type: %x - loop-id=%x " |
| 380 | "portid=%-2x%02x%02x.\n", type, |
| 381 | bsg_job->request->rqst_data.h_els.command_code, fcport->loop_id, |
| 382 | 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] | 383 | |
| 384 | rval = qla2x00_start_sp(sp); |
| 385 | if (rval != QLA_SUCCESS) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 386 | ql_log(ql_log_warn, vha, 0x700e, |
| 387 | "qla2x00_start_sp failed = %d\n", rval); |
Chad Dupuis | b00ee7d | 2013-02-08 01:57:50 -0500 | [diff] [blame] | 388 | qla2x00_rel_sp(vha, sp); |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 389 | rval = -EIO; |
| 390 | goto done_unmap_sg; |
| 391 | } |
| 392 | return rval; |
| 393 | |
| 394 | done_unmap_sg: |
| 395 | dma_unmap_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list, |
| 396 | bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE); |
| 397 | dma_unmap_sg(&ha->pdev->dev, bsg_job->reply_payload.sg_list, |
| 398 | bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE); |
| 399 | goto done_free_fcport; |
| 400 | |
| 401 | done_free_fcport: |
Bart Van Assche | 8c0eb59 | 2013-06-25 11:27:31 -0400 | [diff] [blame] | 402 | if (bsg_job->request->msgcode == FC_BSG_RPT_ELS) |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 403 | kfree(fcport); |
| 404 | done: |
| 405 | return rval; |
| 406 | } |
| 407 | |
Andrew Vasquez | 5780790 | 2011-11-18 09:03:20 -0800 | [diff] [blame] | 408 | inline uint16_t |
| 409 | qla24xx_calc_ct_iocbs(uint16_t dsds) |
| 410 | { |
| 411 | uint16_t iocbs; |
| 412 | |
| 413 | iocbs = 1; |
| 414 | if (dsds > 2) { |
| 415 | iocbs += (dsds - 2) / 5; |
| 416 | if ((dsds - 2) % 5) |
| 417 | iocbs++; |
| 418 | } |
| 419 | return iocbs; |
| 420 | } |
| 421 | |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 422 | static int |
| 423 | qla2x00_process_ct(struct fc_bsg_job *bsg_job) |
| 424 | { |
| 425 | srb_t *sp; |
| 426 | struct Scsi_Host *host = bsg_job->shost; |
| 427 | scsi_qla_host_t *vha = shost_priv(host); |
| 428 | struct qla_hw_data *ha = vha->hw; |
| 429 | int rval = (DRIVER_ERROR << 16); |
| 430 | int req_sg_cnt, rsp_sg_cnt; |
| 431 | uint16_t loop_id; |
| 432 | struct fc_port *fcport; |
| 433 | char *type = "FC_BSG_HST_CT"; |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 434 | |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 435 | req_sg_cnt = |
| 436 | dma_map_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list, |
| 437 | bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE); |
Andrew Vasquez | 6c452a4 | 2010-03-19 17:04:02 -0700 | [diff] [blame] | 438 | if (!req_sg_cnt) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 439 | ql_log(ql_log_warn, vha, 0x700f, |
| 440 | "dma_map_sg return %d for request\n", req_sg_cnt); |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 441 | rval = -ENOMEM; |
| 442 | goto done; |
| 443 | } |
| 444 | |
| 445 | rsp_sg_cnt = dma_map_sg(&ha->pdev->dev, bsg_job->reply_payload.sg_list, |
| 446 | bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE); |
| 447 | if (!rsp_sg_cnt) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 448 | ql_log(ql_log_warn, vha, 0x7010, |
| 449 | "dma_map_sg return %d for reply\n", rsp_sg_cnt); |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 450 | rval = -ENOMEM; |
| 451 | goto done; |
| 452 | } |
| 453 | |
| 454 | if ((req_sg_cnt != bsg_job->request_payload.sg_cnt) || |
Andrew Vasquez | 6c452a4 | 2010-03-19 17:04:02 -0700 | [diff] [blame] | 455 | (rsp_sg_cnt != bsg_job->reply_payload.sg_cnt)) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 456 | ql_log(ql_log_warn, vha, 0x7011, |
| 457 | "request_sg_cnt: %x dma_request_sg_cnt: %x reply_sg_cnt:%x " |
| 458 | "dma_reply_sg_cnt: %x\n", bsg_job->request_payload.sg_cnt, |
| 459 | req_sg_cnt, bsg_job->reply_payload.sg_cnt, rsp_sg_cnt); |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 460 | rval = -EAGAIN; |
Andrew Vasquez | 6c452a4 | 2010-03-19 17:04:02 -0700 | [diff] [blame] | 461 | goto done_unmap_sg; |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 462 | } |
| 463 | |
| 464 | if (!vha->flags.online) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 465 | ql_log(ql_log_warn, vha, 0x7012, |
| 466 | "Host is not online.\n"); |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 467 | rval = -EIO; |
| 468 | goto done_unmap_sg; |
| 469 | } |
| 470 | |
| 471 | loop_id = |
| 472 | (bsg_job->request->rqst_data.h_ct.preamble_word1 & 0xFF000000) |
| 473 | >> 24; |
| 474 | switch (loop_id) { |
Andrew Vasquez | 6c452a4 | 2010-03-19 17:04:02 -0700 | [diff] [blame] | 475 | case 0xFC: |
| 476 | loop_id = cpu_to_le16(NPH_SNS); |
| 477 | break; |
| 478 | case 0xFA: |
| 479 | loop_id = vha->mgmt_svr_loop_id; |
| 480 | break; |
| 481 | default: |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 482 | ql_dbg(ql_dbg_user, vha, 0x7013, |
| 483 | "Unknown loop id: %x.\n", loop_id); |
Andrew Vasquez | 6c452a4 | 2010-03-19 17:04:02 -0700 | [diff] [blame] | 484 | rval = -EINVAL; |
| 485 | goto done_unmap_sg; |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 486 | } |
| 487 | |
| 488 | /* Allocate a dummy fcport structure, since functions preparing the |
| 489 | * IOCB and mailbox command retrieves port specific information |
| 490 | * from fcport structure. For Host based ELS commands there will be |
| 491 | * no fcport structure allocated |
| 492 | */ |
| 493 | fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL); |
Andrew Vasquez | 6c452a4 | 2010-03-19 17:04:02 -0700 | [diff] [blame] | 494 | if (!fcport) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 495 | ql_log(ql_log_warn, vha, 0x7014, |
| 496 | "Failed to allocate fcport.\n"); |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 497 | rval = -ENOMEM; |
Andrew Vasquez | 6c452a4 | 2010-03-19 17:04:02 -0700 | [diff] [blame] | 498 | goto done_unmap_sg; |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 499 | } |
| 500 | |
| 501 | /* Initialize all required fields of fcport */ |
| 502 | fcport->vha = vha; |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 503 | fcport->d_id.b.al_pa = bsg_job->request->rqst_data.h_ct.port_id[0]; |
| 504 | fcport->d_id.b.area = bsg_job->request->rqst_data.h_ct.port_id[1]; |
| 505 | fcport->d_id.b.domain = bsg_job->request->rqst_data.h_ct.port_id[2]; |
| 506 | fcport->loop_id = loop_id; |
| 507 | |
| 508 | /* Alloc SRB structure */ |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 509 | sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL); |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 510 | if (!sp) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 511 | ql_log(ql_log_warn, vha, 0x7015, |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 512 | "qla2x00_get_sp failed.\n"); |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 513 | rval = -ENOMEM; |
| 514 | goto done_free_fcport; |
| 515 | } |
| 516 | |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 517 | sp->type = SRB_CT_CMD; |
| 518 | sp->name = "bsg_ct"; |
| 519 | sp->iocbs = qla24xx_calc_ct_iocbs(req_sg_cnt + rsp_sg_cnt); |
| 520 | sp->u.bsg_job = bsg_job; |
| 521 | sp->free = qla2x00_bsg_sp_free; |
| 522 | sp->done = qla2x00_bsg_job_done; |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 523 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 524 | ql_dbg(ql_dbg_user, vha, 0x7016, |
| 525 | "bsg rqst type: %s else type: %x - " |
| 526 | "loop-id=%x portid=%02x%02x%02x.\n", type, |
| 527 | (bsg_job->request->rqst_data.h_ct.preamble_word2 >> 16), |
| 528 | fcport->loop_id, fcport->d_id.b.domain, fcport->d_id.b.area, |
| 529 | fcport->d_id.b.al_pa); |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 530 | |
| 531 | rval = qla2x00_start_sp(sp); |
| 532 | if (rval != QLA_SUCCESS) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 533 | ql_log(ql_log_warn, vha, 0x7017, |
| 534 | "qla2x00_start_sp failed=%d.\n", rval); |
Chad Dupuis | b00ee7d | 2013-02-08 01:57:50 -0500 | [diff] [blame] | 535 | qla2x00_rel_sp(vha, sp); |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 536 | rval = -EIO; |
| 537 | goto done_free_fcport; |
| 538 | } |
| 539 | return rval; |
| 540 | |
| 541 | done_free_fcport: |
| 542 | kfree(fcport); |
| 543 | done_unmap_sg: |
| 544 | dma_unmap_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list, |
| 545 | bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE); |
| 546 | dma_unmap_sg(&ha->pdev->dev, bsg_job->reply_payload.sg_list, |
| 547 | bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE); |
| 548 | done: |
| 549 | return rval; |
| 550 | } |
Sarang Radke | 23f2ebd | 2010-05-28 15:08:21 -0700 | [diff] [blame] | 551 | |
Chad Dupuis | 8fcd6b8 | 2012-08-22 14:21:06 -0400 | [diff] [blame] | 552 | /* Disable loopback mode */ |
Sarang Radke | 23f2ebd | 2010-05-28 15:08:21 -0700 | [diff] [blame] | 553 | static inline int |
Chad Dupuis | 8fcd6b8 | 2012-08-22 14:21:06 -0400 | [diff] [blame] | 554 | qla81xx_reset_loopback_mode(scsi_qla_host_t *vha, uint16_t *config, |
Chad Dupuis | f356bef | 2013-02-08 01:58:04 -0500 | [diff] [blame] | 555 | int wait, int wait2) |
Sarang Radke | 23f2ebd | 2010-05-28 15:08:21 -0700 | [diff] [blame] | 556 | { |
| 557 | int ret = 0; |
| 558 | int rval = 0; |
| 559 | uint16_t new_config[4]; |
| 560 | struct qla_hw_data *ha = vha->hw; |
| 561 | |
Atul Deshmukh | 7ec0eff | 2013-08-27 01:37:28 -0400 | [diff] [blame^] | 562 | if (!IS_QLA81XX(ha) && !IS_QLA8031(ha) && !IS_QLA8044(ha)) |
Sarang Radke | 23f2ebd | 2010-05-28 15:08:21 -0700 | [diff] [blame] | 563 | goto done_reset_internal; |
| 564 | |
| 565 | memset(new_config, 0 , sizeof(new_config)); |
| 566 | if ((config[0] & INTERNAL_LOOPBACK_MASK) >> 1 == |
Chad Dupuis | 8fcd6b8 | 2012-08-22 14:21:06 -0400 | [diff] [blame] | 567 | ENABLE_INTERNAL_LOOPBACK || |
| 568 | (config[0] & INTERNAL_LOOPBACK_MASK) >> 1 == |
| 569 | ENABLE_EXTERNAL_LOOPBACK) { |
Sarang Radke | 23f2ebd | 2010-05-28 15:08:21 -0700 | [diff] [blame] | 570 | new_config[0] = config[0] & ~INTERNAL_LOOPBACK_MASK; |
Chad Dupuis | 8fcd6b8 | 2012-08-22 14:21:06 -0400 | [diff] [blame] | 571 | ql_dbg(ql_dbg_user, vha, 0x70bf, "new_config[0]=%02x\n", |
| 572 | (new_config[0] & INTERNAL_LOOPBACK_MASK)); |
Sarang Radke | 23f2ebd | 2010-05-28 15:08:21 -0700 | [diff] [blame] | 573 | memcpy(&new_config[1], &config[1], sizeof(uint16_t) * 3) ; |
| 574 | |
| 575 | ha->notify_dcbx_comp = wait; |
Chad Dupuis | f356bef | 2013-02-08 01:58:04 -0500 | [diff] [blame] | 576 | ha->notify_lb_portup_comp = wait2; |
| 577 | |
Sarang Radke | 23f2ebd | 2010-05-28 15:08:21 -0700 | [diff] [blame] | 578 | ret = qla81xx_set_port_config(vha, new_config); |
| 579 | if (ret != QLA_SUCCESS) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 580 | ql_log(ql_log_warn, vha, 0x7025, |
| 581 | "Set port config failed.\n"); |
Sarang Radke | 23f2ebd | 2010-05-28 15:08:21 -0700 | [diff] [blame] | 582 | ha->notify_dcbx_comp = 0; |
Chad Dupuis | f356bef | 2013-02-08 01:58:04 -0500 | [diff] [blame] | 583 | ha->notify_lb_portup_comp = 0; |
Sarang Radke | 23f2ebd | 2010-05-28 15:08:21 -0700 | [diff] [blame] | 584 | rval = -EINVAL; |
| 585 | goto done_reset_internal; |
| 586 | } |
| 587 | |
| 588 | /* Wait for DCBX complete event */ |
| 589 | if (wait && !wait_for_completion_timeout(&ha->dcbx_comp, |
Chad Dupuis | f356bef | 2013-02-08 01:58:04 -0500 | [diff] [blame] | 590 | (DCBX_COMP_TIMEOUT * HZ))) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 591 | ql_dbg(ql_dbg_user, vha, 0x7026, |
Chad Dupuis | f356bef | 2013-02-08 01:58:04 -0500 | [diff] [blame] | 592 | "DCBX completion not received.\n"); |
Sarang Radke | 23f2ebd | 2010-05-28 15:08:21 -0700 | [diff] [blame] | 593 | ha->notify_dcbx_comp = 0; |
Chad Dupuis | f356bef | 2013-02-08 01:58:04 -0500 | [diff] [blame] | 594 | ha->notify_lb_portup_comp = 0; |
Sarang Radke | 23f2ebd | 2010-05-28 15:08:21 -0700 | [diff] [blame] | 595 | rval = -EINVAL; |
| 596 | goto done_reset_internal; |
| 597 | } else |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 598 | ql_dbg(ql_dbg_user, vha, 0x7027, |
Chad Dupuis | f356bef | 2013-02-08 01:58:04 -0500 | [diff] [blame] | 599 | "DCBX completion received.\n"); |
| 600 | |
| 601 | if (wait2 && |
| 602 | !wait_for_completion_timeout(&ha->lb_portup_comp, |
| 603 | (LB_PORTUP_COMP_TIMEOUT * HZ))) { |
| 604 | ql_dbg(ql_dbg_user, vha, 0x70c5, |
| 605 | "Port up completion not received.\n"); |
| 606 | ha->notify_lb_portup_comp = 0; |
| 607 | rval = -EINVAL; |
| 608 | goto done_reset_internal; |
| 609 | } else |
| 610 | ql_dbg(ql_dbg_user, vha, 0x70c6, |
| 611 | "Port up completion received.\n"); |
Sarang Radke | 23f2ebd | 2010-05-28 15:08:21 -0700 | [diff] [blame] | 612 | |
| 613 | ha->notify_dcbx_comp = 0; |
Chad Dupuis | f356bef | 2013-02-08 01:58:04 -0500 | [diff] [blame] | 614 | ha->notify_lb_portup_comp = 0; |
Sarang Radke | 23f2ebd | 2010-05-28 15:08:21 -0700 | [diff] [blame] | 615 | } |
| 616 | done_reset_internal: |
| 617 | return rval; |
| 618 | } |
| 619 | |
Chad Dupuis | 67b2a31 | 2013-02-08 01:57:51 -0500 | [diff] [blame] | 620 | /* |
| 621 | * Set the port configuration to enable the internal or external loopback |
| 622 | * depending on the loopback mode. |
| 623 | */ |
| 624 | static inline int |
| 625 | qla81xx_set_loopback_mode(scsi_qla_host_t *vha, uint16_t *config, |
| 626 | uint16_t *new_config, uint16_t mode) |
| 627 | { |
| 628 | int ret = 0; |
| 629 | int rval = 0; |
| 630 | struct qla_hw_data *ha = vha->hw; |
| 631 | |
Atul Deshmukh | 7ec0eff | 2013-08-27 01:37:28 -0400 | [diff] [blame^] | 632 | if (!IS_QLA81XX(ha) && !IS_QLA8031(ha) && !IS_QLA8044(ha)) |
Chad Dupuis | 67b2a31 | 2013-02-08 01:57:51 -0500 | [diff] [blame] | 633 | goto done_set_internal; |
| 634 | |
| 635 | if (mode == INTERNAL_LOOPBACK) |
| 636 | new_config[0] = config[0] | (ENABLE_INTERNAL_LOOPBACK << 1); |
| 637 | else if (mode == EXTERNAL_LOOPBACK) |
| 638 | new_config[0] = config[0] | (ENABLE_EXTERNAL_LOOPBACK << 1); |
| 639 | ql_dbg(ql_dbg_user, vha, 0x70be, |
| 640 | "new_config[0]=%02x\n", (new_config[0] & INTERNAL_LOOPBACK_MASK)); |
| 641 | |
| 642 | memcpy(&new_config[1], &config[1], sizeof(uint16_t) * 3); |
| 643 | |
| 644 | ha->notify_dcbx_comp = 1; |
| 645 | ret = qla81xx_set_port_config(vha, new_config); |
| 646 | if (ret != QLA_SUCCESS) { |
| 647 | ql_log(ql_log_warn, vha, 0x7021, |
| 648 | "set port config failed.\n"); |
| 649 | ha->notify_dcbx_comp = 0; |
| 650 | rval = -EINVAL; |
| 651 | goto done_set_internal; |
| 652 | } |
| 653 | |
| 654 | /* Wait for DCBX complete event */ |
Chad Dupuis | f356bef | 2013-02-08 01:58:04 -0500 | [diff] [blame] | 655 | if (!wait_for_completion_timeout(&ha->dcbx_comp, |
| 656 | (DCBX_COMP_TIMEOUT * HZ))) { |
Chad Dupuis | 67b2a31 | 2013-02-08 01:57:51 -0500 | [diff] [blame] | 657 | ql_dbg(ql_dbg_user, vha, 0x7022, |
Chad Dupuis | f356bef | 2013-02-08 01:58:04 -0500 | [diff] [blame] | 658 | "DCBX completion not received.\n"); |
| 659 | ret = qla81xx_reset_loopback_mode(vha, new_config, 0, 0); |
Chad Dupuis | 67b2a31 | 2013-02-08 01:57:51 -0500 | [diff] [blame] | 660 | /* |
| 661 | * If the reset of the loopback mode doesn't work take a FCoE |
| 662 | * dump and reset the chip. |
| 663 | */ |
| 664 | if (ret) { |
| 665 | ha->isp_ops->fw_dump(vha, 0); |
| 666 | set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags); |
| 667 | } |
| 668 | rval = -EINVAL; |
| 669 | } else { |
| 670 | if (ha->flags.idc_compl_status) { |
| 671 | ql_dbg(ql_dbg_user, vha, 0x70c3, |
| 672 | "Bad status in IDC Completion AEN\n"); |
| 673 | rval = -EINVAL; |
| 674 | ha->flags.idc_compl_status = 0; |
| 675 | } else |
| 676 | ql_dbg(ql_dbg_user, vha, 0x7023, |
Chad Dupuis | f356bef | 2013-02-08 01:58:04 -0500 | [diff] [blame] | 677 | "DCBX completion received.\n"); |
Chad Dupuis | 67b2a31 | 2013-02-08 01:57:51 -0500 | [diff] [blame] | 678 | } |
| 679 | |
| 680 | ha->notify_dcbx_comp = 0; |
| 681 | |
| 682 | done_set_internal: |
| 683 | return rval; |
| 684 | } |
| 685 | |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 686 | static int |
| 687 | qla2x00_process_loopback(struct fc_bsg_job *bsg_job) |
| 688 | { |
| 689 | struct Scsi_Host *host = bsg_job->shost; |
| 690 | scsi_qla_host_t *vha = shost_priv(host); |
| 691 | struct qla_hw_data *ha = vha->hw; |
| 692 | int rval; |
| 693 | uint8_t command_sent; |
| 694 | char *type; |
| 695 | struct msg_echo_lb elreq; |
| 696 | uint16_t response[MAILBOX_REGISTER_COUNT]; |
Sarang Radke | 23f2ebd | 2010-05-28 15:08:21 -0700 | [diff] [blame] | 697 | uint16_t config[4], new_config[4]; |
Andrew Vasquez | 6c452a4 | 2010-03-19 17:04:02 -0700 | [diff] [blame] | 698 | uint8_t *fw_sts_ptr; |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 699 | uint8_t *req_data = NULL; |
| 700 | dma_addr_t req_data_dma; |
| 701 | uint32_t req_data_len; |
| 702 | uint8_t *rsp_data = NULL; |
| 703 | dma_addr_t rsp_data_dma; |
| 704 | uint32_t rsp_data_len; |
| 705 | |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 706 | if (!vha->flags.online) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 707 | ql_log(ql_log_warn, vha, 0x7019, "Host is not online.\n"); |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 708 | return -EIO; |
| 709 | } |
| 710 | |
| 711 | elreq.req_sg_cnt = dma_map_sg(&ha->pdev->dev, |
| 712 | bsg_job->request_payload.sg_list, bsg_job->request_payload.sg_cnt, |
| 713 | DMA_TO_DEVICE); |
| 714 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 715 | if (!elreq.req_sg_cnt) { |
| 716 | ql_log(ql_log_warn, vha, 0x701a, |
| 717 | "dma_map_sg returned %d for request.\n", elreq.req_sg_cnt); |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 718 | return -ENOMEM; |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 719 | } |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 720 | |
| 721 | elreq.rsp_sg_cnt = dma_map_sg(&ha->pdev->dev, |
| 722 | bsg_job->reply_payload.sg_list, bsg_job->reply_payload.sg_cnt, |
| 723 | DMA_FROM_DEVICE); |
| 724 | |
| 725 | if (!elreq.rsp_sg_cnt) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 726 | ql_log(ql_log_warn, vha, 0x701b, |
| 727 | "dma_map_sg returned %d for reply.\n", elreq.rsp_sg_cnt); |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 728 | rval = -ENOMEM; |
| 729 | goto done_unmap_req_sg; |
Andrew Vasquez | 6c452a4 | 2010-03-19 17:04:02 -0700 | [diff] [blame] | 730 | } |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 731 | |
| 732 | if ((elreq.req_sg_cnt != bsg_job->request_payload.sg_cnt) || |
| 733 | (elreq.rsp_sg_cnt != bsg_job->reply_payload.sg_cnt)) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 734 | ql_log(ql_log_warn, vha, 0x701c, |
| 735 | "dma mapping resulted in different sg counts, " |
| 736 | "request_sg_cnt: %x dma_request_sg_cnt: %x " |
| 737 | "reply_sg_cnt: %x dma_reply_sg_cnt: %x.\n", |
| 738 | bsg_job->request_payload.sg_cnt, elreq.req_sg_cnt, |
| 739 | bsg_job->reply_payload.sg_cnt, elreq.rsp_sg_cnt); |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 740 | rval = -EAGAIN; |
| 741 | goto done_unmap_sg; |
| 742 | } |
| 743 | req_data_len = rsp_data_len = bsg_job->request_payload.payload_len; |
| 744 | req_data = dma_alloc_coherent(&ha->pdev->dev, req_data_len, |
| 745 | &req_data_dma, GFP_KERNEL); |
| 746 | if (!req_data) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 747 | ql_log(ql_log_warn, vha, 0x701d, |
| 748 | "dma alloc failed for req_data.\n"); |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 749 | rval = -ENOMEM; |
| 750 | goto done_unmap_sg; |
| 751 | } |
| 752 | |
| 753 | rsp_data = dma_alloc_coherent(&ha->pdev->dev, rsp_data_len, |
| 754 | &rsp_data_dma, GFP_KERNEL); |
| 755 | if (!rsp_data) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 756 | ql_log(ql_log_warn, vha, 0x7004, |
| 757 | "dma alloc failed for rsp_data.\n"); |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 758 | rval = -ENOMEM; |
| 759 | goto done_free_dma_req; |
| 760 | } |
| 761 | |
| 762 | /* Copy the request buffer in req_data now */ |
| 763 | sg_copy_to_buffer(bsg_job->request_payload.sg_list, |
| 764 | bsg_job->request_payload.sg_cnt, req_data, req_data_len); |
| 765 | |
| 766 | elreq.send_dma = req_data_dma; |
| 767 | elreq.rcv_dma = rsp_data_dma; |
| 768 | elreq.transfer_size = req_data_len; |
| 769 | |
| 770 | elreq.options = bsg_job->request->rqst_data.h_vendor.vendor_cmd[1]; |
Joe Carnuccio | 1b98b42 | 2013-03-28 08:21:26 -0400 | [diff] [blame] | 771 | elreq.iteration_count = |
| 772 | bsg_job->request->rqst_data.h_vendor.vendor_cmd[2]; |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 773 | |
Chad Dupuis | 8fcd6b8 | 2012-08-22 14:21:06 -0400 | [diff] [blame] | 774 | if (atomic_read(&vha->loop_state) == LOOP_READY && |
| 775 | (ha->current_topology == ISP_CFG_F || |
Atul Deshmukh | 7ec0eff | 2013-08-27 01:37:28 -0400 | [diff] [blame^] | 776 | ((IS_QLA81XX(ha) || IS_QLA8031(ha) || IS_QLA8044(ha)) && |
Sarang Radke | 23f2ebd | 2010-05-28 15:08:21 -0700 | [diff] [blame] | 777 | le32_to_cpu(*(uint32_t *)req_data) == ELS_OPCODE_BYTE |
| 778 | && req_data_len == MAX_ELS_FRAME_PAYLOAD)) && |
| 779 | elreq.options == EXTERNAL_LOOPBACK) { |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 780 | type = "FC_BSG_HST_VENDOR_ECHO_DIAG"; |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 781 | ql_dbg(ql_dbg_user, vha, 0x701e, |
| 782 | "BSG request type: %s.\n", type); |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 783 | command_sent = INT_DEF_LB_ECHO_CMD; |
| 784 | rval = qla2x00_echo_test(vha, &elreq, response); |
Sarang Radke | 23f2ebd | 2010-05-28 15:08:21 -0700 | [diff] [blame] | 785 | } else { |
Atul Deshmukh | 7ec0eff | 2013-08-27 01:37:28 -0400 | [diff] [blame^] | 786 | if (IS_QLA81XX(ha) || IS_QLA8031(ha) || IS_QLA8044(ha)) { |
Sarang Radke | 23f2ebd | 2010-05-28 15:08:21 -0700 | [diff] [blame] | 787 | memset(config, 0, sizeof(config)); |
| 788 | memset(new_config, 0, sizeof(new_config)); |
Chad Dupuis | f356bef | 2013-02-08 01:58:04 -0500 | [diff] [blame] | 789 | |
Sarang Radke | 23f2ebd | 2010-05-28 15:08:21 -0700 | [diff] [blame] | 790 | if (qla81xx_get_port_config(vha, config)) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 791 | ql_log(ql_log_warn, vha, 0x701f, |
| 792 | "Get port config failed.\n"); |
Sarang Radke | 23f2ebd | 2010-05-28 15:08:21 -0700 | [diff] [blame] | 793 | rval = -EPERM; |
Steve Hodgson | 9bceab4 | 2012-11-21 02:39:56 -0500 | [diff] [blame] | 794 | goto done_free_dma_rsp; |
Sarang Radke | 23f2ebd | 2010-05-28 15:08:21 -0700 | [diff] [blame] | 795 | } |
| 796 | |
Chad Dupuis | 1bcc46c | 2013-02-08 01:57:46 -0500 | [diff] [blame] | 797 | if ((config[0] & INTERNAL_LOOPBACK_MASK) != 0) { |
| 798 | ql_dbg(ql_dbg_user, vha, 0x70c4, |
| 799 | "Loopback operation already in " |
| 800 | "progress.\n"); |
| 801 | rval = -EAGAIN; |
| 802 | goto done_free_dma_rsp; |
| 803 | } |
| 804 | |
Chad Dupuis | 8fcd6b8 | 2012-08-22 14:21:06 -0400 | [diff] [blame] | 805 | ql_dbg(ql_dbg_user, vha, 0x70c0, |
| 806 | "elreq.options=%04x\n", elreq.options); |
| 807 | |
| 808 | if (elreq.options == EXTERNAL_LOOPBACK) |
Atul Deshmukh | 7ec0eff | 2013-08-27 01:37:28 -0400 | [diff] [blame^] | 809 | if (IS_QLA8031(ha) || IS_QLA8044(ha)) |
Chad Dupuis | 8fcd6b8 | 2012-08-22 14:21:06 -0400 | [diff] [blame] | 810 | rval = qla81xx_set_loopback_mode(vha, |
| 811 | config, new_config, elreq.options); |
| 812 | else |
| 813 | rval = qla81xx_reset_loopback_mode(vha, |
Chad Dupuis | f356bef | 2013-02-08 01:58:04 -0500 | [diff] [blame] | 814 | config, 1, 0); |
Chad Dupuis | 8fcd6b8 | 2012-08-22 14:21:06 -0400 | [diff] [blame] | 815 | else |
| 816 | rval = qla81xx_set_loopback_mode(vha, config, |
| 817 | new_config, elreq.options); |
| 818 | |
| 819 | if (rval) { |
Chad Dupuis | 8fcd6b8 | 2012-08-22 14:21:06 -0400 | [diff] [blame] | 820 | rval = -EPERM; |
Steve Hodgson | 9bceab4 | 2012-11-21 02:39:56 -0500 | [diff] [blame] | 821 | goto done_free_dma_rsp; |
Sarang Radke | 23f2ebd | 2010-05-28 15:08:21 -0700 | [diff] [blame] | 822 | } |
| 823 | |
| 824 | type = "FC_BSG_HST_VENDOR_LOOPBACK"; |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 825 | ql_dbg(ql_dbg_user, vha, 0x7028, |
| 826 | "BSG request type: %s.\n", type); |
Sarang Radke | 23f2ebd | 2010-05-28 15:08:21 -0700 | [diff] [blame] | 827 | |
| 828 | command_sent = INT_DEF_LB_LOOPBACK_CMD; |
| 829 | rval = qla2x00_loopback_test(vha, &elreq, response); |
| 830 | |
Chad Dupuis | 992357c | 2013-02-08 01:57:52 -0500 | [diff] [blame] | 831 | if (response[0] == MBS_COMMAND_ERROR && |
| 832 | response[1] == MBS_LB_RESET) { |
| 833 | ql_log(ql_log_warn, vha, 0x7029, |
| 834 | "MBX command error, Aborting ISP.\n"); |
| 835 | set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags); |
| 836 | qla2xxx_wake_dpc(vha); |
| 837 | qla2x00_wait_for_chip_reset(vha); |
| 838 | /* Also reset the MPI */ |
| 839 | if (IS_QLA81XX(ha)) { |
| 840 | if (qla81xx_restart_mpi_firmware(vha) != |
| 841 | QLA_SUCCESS) { |
| 842 | ql_log(ql_log_warn, vha, 0x702a, |
| 843 | "MPI reset failed.\n"); |
| 844 | } |
| 845 | } |
| 846 | |
| 847 | rval = -EIO; |
| 848 | goto done_free_dma_rsp; |
| 849 | } |
| 850 | |
Joe Carnuccio | 4052bd5 | 2010-12-21 16:00:17 -0800 | [diff] [blame] | 851 | if (new_config[0]) { |
Chad Dupuis | 67b2a31 | 2013-02-08 01:57:51 -0500 | [diff] [blame] | 852 | int ret; |
| 853 | |
Sarang Radke | 23f2ebd | 2010-05-28 15:08:21 -0700 | [diff] [blame] | 854 | /* Revert back to original port config |
| 855 | * Also clear internal loopback |
| 856 | */ |
Chad Dupuis | 67b2a31 | 2013-02-08 01:57:51 -0500 | [diff] [blame] | 857 | ret = qla81xx_reset_loopback_mode(vha, |
Chad Dupuis | f356bef | 2013-02-08 01:58:04 -0500 | [diff] [blame] | 858 | new_config, 0, 1); |
Chad Dupuis | 67b2a31 | 2013-02-08 01:57:51 -0500 | [diff] [blame] | 859 | if (ret) { |
| 860 | /* |
| 861 | * If the reset of the loopback mode |
| 862 | * doesn't work take FCoE dump and then |
| 863 | * reset the chip. |
| 864 | */ |
| 865 | ha->isp_ops->fw_dump(vha, 0); |
| 866 | set_bit(ISP_ABORT_NEEDED, |
| 867 | &vha->dpc_flags); |
| 868 | } |
| 869 | |
Sarang Radke | 23f2ebd | 2010-05-28 15:08:21 -0700 | [diff] [blame] | 870 | } |
| 871 | |
Sarang Radke | 23f2ebd | 2010-05-28 15:08:21 -0700 | [diff] [blame] | 872 | } else { |
| 873 | type = "FC_BSG_HST_VENDOR_LOOPBACK"; |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 874 | ql_dbg(ql_dbg_user, vha, 0x702b, |
| 875 | "BSG request type: %s.\n", type); |
Sarang Radke | 23f2ebd | 2010-05-28 15:08:21 -0700 | [diff] [blame] | 876 | command_sent = INT_DEF_LB_LOOPBACK_CMD; |
| 877 | rval = qla2x00_loopback_test(vha, &elreq, response); |
| 878 | } |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 879 | } |
| 880 | |
| 881 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 882 | ql_log(ql_log_warn, vha, 0x702c, |
| 883 | "Vendor request %s failed.\n", type); |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 884 | |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 885 | rval = 0; |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 886 | bsg_job->reply->result = (DID_ERROR << 16); |
Armen Baloyan | 63ea923 | 2012-11-21 02:39:53 -0500 | [diff] [blame] | 887 | bsg_job->reply->reply_payload_rcv_len = 0; |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 888 | } else { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 889 | ql_dbg(ql_dbg_user, vha, 0x702d, |
| 890 | "Vendor request %s completed.\n", type); |
Armen Baloyan | 63ea923 | 2012-11-21 02:39:53 -0500 | [diff] [blame] | 891 | bsg_job->reply->result = (DID_OK << 16); |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 892 | sg_copy_from_buffer(bsg_job->reply_payload.sg_list, |
| 893 | bsg_job->reply_payload.sg_cnt, rsp_data, |
| 894 | rsp_data_len); |
| 895 | } |
Armen Baloyan | 63ea923 | 2012-11-21 02:39:53 -0500 | [diff] [blame] | 896 | |
| 897 | bsg_job->reply_len = sizeof(struct fc_bsg_reply) + |
| 898 | sizeof(response) + sizeof(uint8_t); |
| 899 | fw_sts_ptr = ((uint8_t *)bsg_job->req->sense) + |
| 900 | sizeof(struct fc_bsg_reply); |
| 901 | memcpy(fw_sts_ptr, response, sizeof(response)); |
| 902 | fw_sts_ptr += sizeof(response); |
| 903 | *fw_sts_ptr = command_sent; |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 904 | |
Steve Hodgson | 9bceab4 | 2012-11-21 02:39:56 -0500 | [diff] [blame] | 905 | done_free_dma_rsp: |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 906 | dma_free_coherent(&ha->pdev->dev, rsp_data_len, |
| 907 | rsp_data, rsp_data_dma); |
| 908 | done_free_dma_req: |
| 909 | dma_free_coherent(&ha->pdev->dev, req_data_len, |
| 910 | req_data, req_data_dma); |
| 911 | done_unmap_sg: |
| 912 | dma_unmap_sg(&ha->pdev->dev, |
| 913 | bsg_job->reply_payload.sg_list, |
| 914 | bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE); |
| 915 | done_unmap_req_sg: |
| 916 | dma_unmap_sg(&ha->pdev->dev, |
| 917 | bsg_job->request_payload.sg_list, |
| 918 | bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE); |
Armen Baloyan | 63ea923 | 2012-11-21 02:39:53 -0500 | [diff] [blame] | 919 | if (!rval) |
| 920 | bsg_job->job_done(bsg_job); |
Andrew Vasquez | 6c452a4 | 2010-03-19 17:04:02 -0700 | [diff] [blame] | 921 | return rval; |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 922 | } |
| 923 | |
| 924 | static int |
| 925 | qla84xx_reset(struct fc_bsg_job *bsg_job) |
| 926 | { |
| 927 | struct Scsi_Host *host = bsg_job->shost; |
| 928 | scsi_qla_host_t *vha = shost_priv(host); |
| 929 | struct qla_hw_data *ha = vha->hw; |
| 930 | int rval = 0; |
| 931 | uint32_t flag; |
| 932 | |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 933 | if (!IS_QLA84XX(ha)) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 934 | ql_dbg(ql_dbg_user, vha, 0x702f, "Not 84xx, exiting.\n"); |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 935 | return -EINVAL; |
| 936 | } |
| 937 | |
| 938 | flag = bsg_job->request->rqst_data.h_vendor.vendor_cmd[1]; |
| 939 | |
| 940 | rval = qla84xx_reset_chip(vha, flag == A84_ISSUE_RESET_DIAG_FW); |
| 941 | |
| 942 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 943 | ql_log(ql_log_warn, vha, 0x7030, |
| 944 | "Vendor request 84xx reset failed.\n"); |
Armen Baloyan | 63ea923 | 2012-11-21 02:39:53 -0500 | [diff] [blame] | 945 | rval = (DID_ERROR << 16); |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 946 | |
| 947 | } else { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 948 | ql_dbg(ql_dbg_user, vha, 0x7031, |
| 949 | "Vendor request 84xx reset completed.\n"); |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 950 | bsg_job->reply->result = DID_OK; |
Armen Baloyan | 63ea923 | 2012-11-21 02:39:53 -0500 | [diff] [blame] | 951 | bsg_job->job_done(bsg_job); |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 952 | } |
| 953 | |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 954 | return rval; |
| 955 | } |
| 956 | |
| 957 | static int |
| 958 | qla84xx_updatefw(struct fc_bsg_job *bsg_job) |
| 959 | { |
| 960 | struct Scsi_Host *host = bsg_job->shost; |
| 961 | scsi_qla_host_t *vha = shost_priv(host); |
| 962 | struct qla_hw_data *ha = vha->hw; |
| 963 | struct verify_chip_entry_84xx *mn = NULL; |
| 964 | dma_addr_t mn_dma, fw_dma; |
| 965 | void *fw_buf = NULL; |
| 966 | int rval = 0; |
| 967 | uint32_t sg_cnt; |
| 968 | uint32_t data_len; |
| 969 | uint16_t options; |
| 970 | uint32_t flag; |
| 971 | uint32_t fw_ver; |
| 972 | |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 973 | if (!IS_QLA84XX(ha)) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 974 | ql_dbg(ql_dbg_user, vha, 0x7032, |
| 975 | "Not 84xx, exiting.\n"); |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 976 | return -EINVAL; |
| 977 | } |
| 978 | |
| 979 | sg_cnt = dma_map_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list, |
| 980 | bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE); |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 981 | if (!sg_cnt) { |
| 982 | ql_log(ql_log_warn, vha, 0x7033, |
| 983 | "dma_map_sg returned %d for request.\n", sg_cnt); |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 984 | return -ENOMEM; |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 985 | } |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 986 | |
| 987 | if (sg_cnt != bsg_job->request_payload.sg_cnt) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 988 | ql_log(ql_log_warn, vha, 0x7034, |
| 989 | "DMA mapping resulted in different sg counts, " |
| 990 | "request_sg_cnt: %x dma_request_sg_cnt: %x.\n", |
| 991 | bsg_job->request_payload.sg_cnt, sg_cnt); |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 992 | rval = -EAGAIN; |
| 993 | goto done_unmap_sg; |
| 994 | } |
| 995 | |
| 996 | data_len = bsg_job->request_payload.payload_len; |
| 997 | fw_buf = dma_alloc_coherent(&ha->pdev->dev, data_len, |
| 998 | &fw_dma, GFP_KERNEL); |
| 999 | if (!fw_buf) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1000 | ql_log(ql_log_warn, vha, 0x7035, |
| 1001 | "DMA alloc failed for fw_buf.\n"); |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 1002 | rval = -ENOMEM; |
| 1003 | goto done_unmap_sg; |
| 1004 | } |
| 1005 | |
| 1006 | sg_copy_to_buffer(bsg_job->request_payload.sg_list, |
| 1007 | bsg_job->request_payload.sg_cnt, fw_buf, data_len); |
| 1008 | |
| 1009 | mn = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &mn_dma); |
| 1010 | if (!mn) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1011 | ql_log(ql_log_warn, vha, 0x7036, |
| 1012 | "DMA alloc failed for fw buffer.\n"); |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 1013 | rval = -ENOMEM; |
| 1014 | goto done_free_fw_buf; |
| 1015 | } |
| 1016 | |
| 1017 | flag = bsg_job->request->rqst_data.h_vendor.vendor_cmd[1]; |
| 1018 | fw_ver = le32_to_cpu(*((uint32_t *)((uint32_t *)fw_buf + 2))); |
| 1019 | |
| 1020 | memset(mn, 0, sizeof(struct access_chip_84xx)); |
| 1021 | mn->entry_type = VERIFY_CHIP_IOCB_TYPE; |
| 1022 | mn->entry_count = 1; |
| 1023 | |
| 1024 | options = VCO_FORCE_UPDATE | VCO_END_OF_DATA; |
| 1025 | if (flag == A84_ISSUE_UPDATE_DIAGFW_CMD) |
| 1026 | options |= VCO_DIAG_FW; |
| 1027 | |
| 1028 | mn->options = cpu_to_le16(options); |
| 1029 | mn->fw_ver = cpu_to_le32(fw_ver); |
| 1030 | mn->fw_size = cpu_to_le32(data_len); |
| 1031 | mn->fw_seq_size = cpu_to_le32(data_len); |
| 1032 | mn->dseg_address[0] = cpu_to_le32(LSD(fw_dma)); |
| 1033 | mn->dseg_address[1] = cpu_to_le32(MSD(fw_dma)); |
| 1034 | mn->dseg_length = cpu_to_le32(data_len); |
| 1035 | mn->data_seg_cnt = cpu_to_le16(1); |
| 1036 | |
| 1037 | rval = qla2x00_issue_iocb_timeout(vha, mn, mn_dma, 0, 120); |
| 1038 | |
| 1039 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1040 | ql_log(ql_log_warn, vha, 0x7037, |
| 1041 | "Vendor request 84xx updatefw failed.\n"); |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 1042 | |
Armen Baloyan | 63ea923 | 2012-11-21 02:39:53 -0500 | [diff] [blame] | 1043 | rval = (DID_ERROR << 16); |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 1044 | } else { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1045 | ql_dbg(ql_dbg_user, vha, 0x7038, |
| 1046 | "Vendor request 84xx updatefw completed.\n"); |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 1047 | |
| 1048 | bsg_job->reply_len = sizeof(struct fc_bsg_reply); |
| 1049 | bsg_job->reply->result = DID_OK; |
| 1050 | } |
| 1051 | |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 1052 | dma_pool_free(ha->s_dma_pool, mn, mn_dma); |
| 1053 | |
| 1054 | done_free_fw_buf: |
| 1055 | dma_free_coherent(&ha->pdev->dev, data_len, fw_buf, fw_dma); |
| 1056 | |
| 1057 | done_unmap_sg: |
| 1058 | dma_unmap_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list, |
| 1059 | bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE); |
| 1060 | |
Armen Baloyan | 63ea923 | 2012-11-21 02:39:53 -0500 | [diff] [blame] | 1061 | if (!rval) |
| 1062 | bsg_job->job_done(bsg_job); |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 1063 | return rval; |
| 1064 | } |
| 1065 | |
| 1066 | static int |
| 1067 | qla84xx_mgmt_cmd(struct fc_bsg_job *bsg_job) |
| 1068 | { |
| 1069 | struct Scsi_Host *host = bsg_job->shost; |
| 1070 | scsi_qla_host_t *vha = shost_priv(host); |
| 1071 | struct qla_hw_data *ha = vha->hw; |
| 1072 | struct access_chip_84xx *mn = NULL; |
| 1073 | dma_addr_t mn_dma, mgmt_dma; |
| 1074 | void *mgmt_b = NULL; |
| 1075 | int rval = 0; |
| 1076 | struct qla_bsg_a84_mgmt *ql84_mgmt; |
| 1077 | uint32_t sg_cnt; |
Harish Zunjarrao | d545908 | 2010-03-19 17:04:00 -0700 | [diff] [blame] | 1078 | uint32_t data_len = 0; |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 1079 | uint32_t dma_direction = DMA_NONE; |
| 1080 | |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 1081 | if (!IS_QLA84XX(ha)) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1082 | ql_log(ql_log_warn, vha, 0x703a, |
| 1083 | "Not 84xx, exiting.\n"); |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 1084 | return -EINVAL; |
| 1085 | } |
| 1086 | |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 1087 | mn = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &mn_dma); |
| 1088 | if (!mn) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1089 | ql_log(ql_log_warn, vha, 0x703c, |
| 1090 | "DMA alloc failed for fw buffer.\n"); |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 1091 | return -ENOMEM; |
| 1092 | } |
| 1093 | |
| 1094 | memset(mn, 0, sizeof(struct access_chip_84xx)); |
| 1095 | mn->entry_type = ACCESS_CHIP_IOCB_TYPE; |
| 1096 | mn->entry_count = 1; |
Bart Van Assche | a44c72f | 2013-06-25 11:27:23 -0400 | [diff] [blame] | 1097 | ql84_mgmt = (void *)bsg_job->request + sizeof(struct fc_bsg_request); |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 1098 | switch (ql84_mgmt->mgmt.cmd) { |
| 1099 | case QLA84_MGMT_READ_MEM: |
| 1100 | case QLA84_MGMT_GET_INFO: |
| 1101 | sg_cnt = dma_map_sg(&ha->pdev->dev, |
| 1102 | bsg_job->reply_payload.sg_list, |
| 1103 | bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE); |
| 1104 | if (!sg_cnt) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1105 | ql_log(ql_log_warn, vha, 0x703d, |
| 1106 | "dma_map_sg returned %d for reply.\n", sg_cnt); |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 1107 | rval = -ENOMEM; |
| 1108 | goto exit_mgmt; |
| 1109 | } |
| 1110 | |
| 1111 | dma_direction = DMA_FROM_DEVICE; |
| 1112 | |
| 1113 | if (sg_cnt != bsg_job->reply_payload.sg_cnt) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1114 | ql_log(ql_log_warn, vha, 0x703e, |
| 1115 | "DMA mapping resulted in different sg counts, " |
| 1116 | "reply_sg_cnt: %x dma_reply_sg_cnt: %x.\n", |
| 1117 | bsg_job->reply_payload.sg_cnt, sg_cnt); |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 1118 | rval = -EAGAIN; |
| 1119 | goto done_unmap_sg; |
| 1120 | } |
| 1121 | |
| 1122 | data_len = bsg_job->reply_payload.payload_len; |
| 1123 | |
| 1124 | mgmt_b = dma_alloc_coherent(&ha->pdev->dev, data_len, |
| 1125 | &mgmt_dma, GFP_KERNEL); |
| 1126 | if (!mgmt_b) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1127 | ql_log(ql_log_warn, vha, 0x703f, |
| 1128 | "DMA alloc failed for mgmt_b.\n"); |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 1129 | rval = -ENOMEM; |
| 1130 | goto done_unmap_sg; |
| 1131 | } |
| 1132 | |
| 1133 | if (ql84_mgmt->mgmt.cmd == QLA84_MGMT_READ_MEM) { |
| 1134 | mn->options = cpu_to_le16(ACO_DUMP_MEMORY); |
| 1135 | mn->parameter1 = |
| 1136 | cpu_to_le32( |
| 1137 | ql84_mgmt->mgmt.mgmtp.u.mem.start_addr); |
| 1138 | |
| 1139 | } else if (ql84_mgmt->mgmt.cmd == QLA84_MGMT_GET_INFO) { |
| 1140 | mn->options = cpu_to_le16(ACO_REQUEST_INFO); |
| 1141 | mn->parameter1 = |
| 1142 | cpu_to_le32(ql84_mgmt->mgmt.mgmtp.u.info.type); |
| 1143 | |
| 1144 | mn->parameter2 = |
| 1145 | cpu_to_le32( |
| 1146 | ql84_mgmt->mgmt.mgmtp.u.info.context); |
| 1147 | } |
| 1148 | break; |
| 1149 | |
| 1150 | case QLA84_MGMT_WRITE_MEM: |
| 1151 | sg_cnt = dma_map_sg(&ha->pdev->dev, |
| 1152 | bsg_job->request_payload.sg_list, |
| 1153 | bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE); |
| 1154 | |
| 1155 | if (!sg_cnt) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1156 | ql_log(ql_log_warn, vha, 0x7040, |
| 1157 | "dma_map_sg returned %d.\n", sg_cnt); |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 1158 | rval = -ENOMEM; |
| 1159 | goto exit_mgmt; |
| 1160 | } |
| 1161 | |
| 1162 | dma_direction = DMA_TO_DEVICE; |
| 1163 | |
| 1164 | if (sg_cnt != bsg_job->request_payload.sg_cnt) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1165 | ql_log(ql_log_warn, vha, 0x7041, |
| 1166 | "DMA mapping resulted in different sg counts, " |
| 1167 | "request_sg_cnt: %x dma_request_sg_cnt: %x.\n", |
| 1168 | bsg_job->request_payload.sg_cnt, sg_cnt); |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 1169 | rval = -EAGAIN; |
| 1170 | goto done_unmap_sg; |
| 1171 | } |
| 1172 | |
| 1173 | data_len = bsg_job->request_payload.payload_len; |
| 1174 | mgmt_b = dma_alloc_coherent(&ha->pdev->dev, data_len, |
| 1175 | &mgmt_dma, GFP_KERNEL); |
| 1176 | if (!mgmt_b) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1177 | ql_log(ql_log_warn, vha, 0x7042, |
| 1178 | "DMA alloc failed for mgmt_b.\n"); |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 1179 | rval = -ENOMEM; |
| 1180 | goto done_unmap_sg; |
| 1181 | } |
| 1182 | |
| 1183 | sg_copy_to_buffer(bsg_job->request_payload.sg_list, |
| 1184 | bsg_job->request_payload.sg_cnt, mgmt_b, data_len); |
| 1185 | |
| 1186 | mn->options = cpu_to_le16(ACO_LOAD_MEMORY); |
| 1187 | mn->parameter1 = |
| 1188 | cpu_to_le32(ql84_mgmt->mgmt.mgmtp.u.mem.start_addr); |
| 1189 | break; |
| 1190 | |
| 1191 | case QLA84_MGMT_CHNG_CONFIG: |
| 1192 | mn->options = cpu_to_le16(ACO_CHANGE_CONFIG_PARAM); |
| 1193 | mn->parameter1 = |
| 1194 | cpu_to_le32(ql84_mgmt->mgmt.mgmtp.u.config.id); |
| 1195 | |
| 1196 | mn->parameter2 = |
| 1197 | cpu_to_le32(ql84_mgmt->mgmt.mgmtp.u.config.param0); |
| 1198 | |
| 1199 | mn->parameter3 = |
| 1200 | cpu_to_le32(ql84_mgmt->mgmt.mgmtp.u.config.param1); |
| 1201 | break; |
| 1202 | |
| 1203 | default: |
| 1204 | rval = -EIO; |
| 1205 | goto exit_mgmt; |
| 1206 | } |
| 1207 | |
| 1208 | if (ql84_mgmt->mgmt.cmd != QLA84_MGMT_CHNG_CONFIG) { |
| 1209 | mn->total_byte_cnt = cpu_to_le32(ql84_mgmt->mgmt.len); |
| 1210 | mn->dseg_count = cpu_to_le16(1); |
| 1211 | mn->dseg_address[0] = cpu_to_le32(LSD(mgmt_dma)); |
| 1212 | mn->dseg_address[1] = cpu_to_le32(MSD(mgmt_dma)); |
| 1213 | mn->dseg_length = cpu_to_le32(ql84_mgmt->mgmt.len); |
| 1214 | } |
| 1215 | |
| 1216 | rval = qla2x00_issue_iocb(vha, mn, mn_dma, 0); |
| 1217 | |
| 1218 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1219 | ql_log(ql_log_warn, vha, 0x7043, |
| 1220 | "Vendor request 84xx mgmt failed.\n"); |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 1221 | |
Armen Baloyan | 63ea923 | 2012-11-21 02:39:53 -0500 | [diff] [blame] | 1222 | rval = (DID_ERROR << 16); |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 1223 | |
| 1224 | } else { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1225 | ql_dbg(ql_dbg_user, vha, 0x7044, |
| 1226 | "Vendor request 84xx mgmt completed.\n"); |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 1227 | |
| 1228 | bsg_job->reply_len = sizeof(struct fc_bsg_reply); |
| 1229 | bsg_job->reply->result = DID_OK; |
| 1230 | |
| 1231 | if ((ql84_mgmt->mgmt.cmd == QLA84_MGMT_READ_MEM) || |
| 1232 | (ql84_mgmt->mgmt.cmd == QLA84_MGMT_GET_INFO)) { |
| 1233 | bsg_job->reply->reply_payload_rcv_len = |
| 1234 | bsg_job->reply_payload.payload_len; |
| 1235 | |
| 1236 | sg_copy_from_buffer(bsg_job->reply_payload.sg_list, |
Andrew Vasquez | 6c452a4 | 2010-03-19 17:04:02 -0700 | [diff] [blame] | 1237 | bsg_job->reply_payload.sg_cnt, mgmt_b, |
| 1238 | data_len); |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 1239 | } |
| 1240 | } |
| 1241 | |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 1242 | done_unmap_sg: |
Harish Zunjarrao | d545908 | 2010-03-19 17:04:00 -0700 | [diff] [blame] | 1243 | if (mgmt_b) |
| 1244 | dma_free_coherent(&ha->pdev->dev, data_len, mgmt_b, mgmt_dma); |
| 1245 | |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 1246 | if (dma_direction == DMA_TO_DEVICE) |
| 1247 | dma_unmap_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list, |
| 1248 | bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE); |
| 1249 | else if (dma_direction == DMA_FROM_DEVICE) |
| 1250 | dma_unmap_sg(&ha->pdev->dev, bsg_job->reply_payload.sg_list, |
| 1251 | bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE); |
| 1252 | |
| 1253 | exit_mgmt: |
| 1254 | dma_pool_free(ha->s_dma_pool, mn, mn_dma); |
| 1255 | |
Armen Baloyan | 63ea923 | 2012-11-21 02:39:53 -0500 | [diff] [blame] | 1256 | if (!rval) |
| 1257 | bsg_job->job_done(bsg_job); |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 1258 | return rval; |
| 1259 | } |
| 1260 | |
| 1261 | static int |
| 1262 | qla24xx_iidma(struct fc_bsg_job *bsg_job) |
| 1263 | { |
| 1264 | struct Scsi_Host *host = bsg_job->shost; |
| 1265 | scsi_qla_host_t *vha = shost_priv(host); |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 1266 | int rval = 0; |
| 1267 | struct qla_port_param *port_param = NULL; |
| 1268 | fc_port_t *fcport = NULL; |
| 1269 | uint16_t mb[MAILBOX_REGISTER_COUNT]; |
| 1270 | uint8_t *rsp_ptr = NULL; |
| 1271 | |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 1272 | if (!IS_IIDMA_CAPABLE(vha->hw)) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1273 | ql_log(ql_log_info, vha, 0x7046, "iiDMA not supported.\n"); |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 1274 | return -EINVAL; |
| 1275 | } |
| 1276 | |
Bart Van Assche | 090fc2e | 2013-06-25 11:27:22 -0400 | [diff] [blame] | 1277 | port_param = (void *)bsg_job->request + sizeof(struct fc_bsg_request); |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 1278 | if (port_param->fc_scsi_addr.dest_type != EXT_DEF_TYPE_WWPN) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1279 | ql_log(ql_log_warn, vha, 0x7048, |
| 1280 | "Invalid destination type.\n"); |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 1281 | return -EINVAL; |
| 1282 | } |
| 1283 | |
| 1284 | list_for_each_entry(fcport, &vha->vp_fcports, list) { |
| 1285 | if (fcport->port_type != FCT_TARGET) |
| 1286 | continue; |
| 1287 | |
| 1288 | if (memcmp(port_param->fc_scsi_addr.dest_addr.wwpn, |
| 1289 | fcport->port_name, sizeof(fcport->port_name))) |
| 1290 | continue; |
| 1291 | break; |
| 1292 | } |
| 1293 | |
| 1294 | if (!fcport) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1295 | ql_log(ql_log_warn, vha, 0x7049, |
| 1296 | "Failed to find port.\n"); |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 1297 | return -EINVAL; |
| 1298 | } |
| 1299 | |
Giridhar Malavali | c9afb9a | 2010-09-03 15:20:48 -0700 | [diff] [blame] | 1300 | if (atomic_read(&fcport->state) != FCS_ONLINE) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1301 | ql_log(ql_log_warn, vha, 0x704a, |
| 1302 | "Port is not online.\n"); |
Madhuranath Iyengar | 17cf2c5 | 2010-07-23 15:28:22 +0500 | [diff] [blame] | 1303 | return -EINVAL; |
| 1304 | } |
| 1305 | |
Madhuranath Iyengar | 9a15eb4 | 2010-07-23 15:28:31 +0500 | [diff] [blame] | 1306 | if (fcport->flags & FCF_LOGIN_NEEDED) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1307 | ql_log(ql_log_warn, vha, 0x704b, |
| 1308 | "Remote port not logged in flags = 0x%x.\n", fcport->flags); |
Madhuranath Iyengar | 9a15eb4 | 2010-07-23 15:28:31 +0500 | [diff] [blame] | 1309 | return -EINVAL; |
| 1310 | } |
| 1311 | |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 1312 | if (port_param->mode) |
| 1313 | rval = qla2x00_set_idma_speed(vha, fcport->loop_id, |
| 1314 | port_param->speed, mb); |
| 1315 | else |
| 1316 | rval = qla2x00_get_idma_speed(vha, fcport->loop_id, |
| 1317 | &port_param->speed, mb); |
| 1318 | |
| 1319 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1320 | ql_log(ql_log_warn, vha, 0x704c, |
Oleksandr Khoshaba | 7b83355 | 2013-08-27 01:37:27 -0400 | [diff] [blame] | 1321 | "iIDMA cmd failed for %8phN -- " |
| 1322 | "%04x %x %04x %04x.\n", fcport->port_name, |
| 1323 | rval, fcport->fp_speed, mb[0], mb[1]); |
Armen Baloyan | 63ea923 | 2012-11-21 02:39:53 -0500 | [diff] [blame] | 1324 | rval = (DID_ERROR << 16); |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 1325 | } else { |
| 1326 | if (!port_param->mode) { |
| 1327 | bsg_job->reply_len = sizeof(struct fc_bsg_reply) + |
| 1328 | sizeof(struct qla_port_param); |
| 1329 | |
| 1330 | rsp_ptr = ((uint8_t *)bsg_job->reply) + |
| 1331 | sizeof(struct fc_bsg_reply); |
| 1332 | |
| 1333 | memcpy(rsp_ptr, port_param, |
| 1334 | sizeof(struct qla_port_param)); |
| 1335 | } |
| 1336 | |
| 1337 | bsg_job->reply->result = DID_OK; |
Armen Baloyan | 63ea923 | 2012-11-21 02:39:53 -0500 | [diff] [blame] | 1338 | bsg_job->job_done(bsg_job); |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 1339 | } |
| 1340 | |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 1341 | return rval; |
| 1342 | } |
| 1343 | |
| 1344 | static int |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1345 | 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] | 1346 | uint8_t is_update) |
| 1347 | { |
| 1348 | uint32_t start = 0; |
| 1349 | int valid = 0; |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1350 | struct qla_hw_data *ha = vha->hw; |
Harish Zunjarrao | f19af16 | 2010-10-15 11:27:43 -0700 | [diff] [blame] | 1351 | |
Harish Zunjarrao | f19af16 | 2010-10-15 11:27:43 -0700 | [diff] [blame] | 1352 | if (unlikely(pci_channel_offline(ha->pdev))) |
| 1353 | return -EINVAL; |
| 1354 | |
| 1355 | start = bsg_job->request->rqst_data.h_vendor.vendor_cmd[1]; |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1356 | if (start > ha->optrom_size) { |
| 1357 | ql_log(ql_log_warn, vha, 0x7055, |
| 1358 | "start %d > optrom_size %d.\n", start, ha->optrom_size); |
Harish Zunjarrao | f19af16 | 2010-10-15 11:27:43 -0700 | [diff] [blame] | 1359 | return -EINVAL; |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1360 | } |
Harish Zunjarrao | f19af16 | 2010-10-15 11:27:43 -0700 | [diff] [blame] | 1361 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1362 | if (ha->optrom_state != QLA_SWAITING) { |
| 1363 | ql_log(ql_log_info, vha, 0x7056, |
| 1364 | "optrom_state %d.\n", ha->optrom_state); |
Harish Zunjarrao | f19af16 | 2010-10-15 11:27:43 -0700 | [diff] [blame] | 1365 | return -EBUSY; |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1366 | } |
Harish Zunjarrao | f19af16 | 2010-10-15 11:27:43 -0700 | [diff] [blame] | 1367 | |
| 1368 | ha->optrom_region_start = start; |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1369 | 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] | 1370 | if (is_update) { |
| 1371 | if (ha->optrom_size == OPTROM_SIZE_2300 && start == 0) |
| 1372 | valid = 1; |
| 1373 | else if (start == (ha->flt_region_boot * 4) || |
| 1374 | start == (ha->flt_region_fw * 4)) |
| 1375 | valid = 1; |
| 1376 | else if (IS_QLA24XX_TYPE(ha) || IS_QLA25XX(ha) || |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 1377 | IS_CNA_CAPABLE(ha) || IS_QLA2031(ha)) |
Harish Zunjarrao | f19af16 | 2010-10-15 11:27:43 -0700 | [diff] [blame] | 1378 | valid = 1; |
| 1379 | if (!valid) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1380 | ql_log(ql_log_warn, vha, 0x7058, |
| 1381 | "Invalid start region 0x%x/0x%x.\n", start, |
| 1382 | bsg_job->request_payload.payload_len); |
Harish Zunjarrao | f19af16 | 2010-10-15 11:27:43 -0700 | [diff] [blame] | 1383 | return -EINVAL; |
| 1384 | } |
| 1385 | |
| 1386 | ha->optrom_region_size = start + |
| 1387 | bsg_job->request_payload.payload_len > ha->optrom_size ? |
| 1388 | ha->optrom_size - start : |
| 1389 | bsg_job->request_payload.payload_len; |
| 1390 | ha->optrom_state = QLA_SWRITING; |
| 1391 | } else { |
| 1392 | ha->optrom_region_size = start + |
| 1393 | bsg_job->reply_payload.payload_len > ha->optrom_size ? |
| 1394 | ha->optrom_size - start : |
| 1395 | bsg_job->reply_payload.payload_len; |
| 1396 | ha->optrom_state = QLA_SREADING; |
| 1397 | } |
| 1398 | |
| 1399 | ha->optrom_buffer = vmalloc(ha->optrom_region_size); |
| 1400 | if (!ha->optrom_buffer) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1401 | ql_log(ql_log_warn, vha, 0x7059, |
Harish Zunjarrao | f19af16 | 2010-10-15 11:27:43 -0700 | [diff] [blame] | 1402 | "Read: Unable to allocate memory for optrom retrieval " |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1403 | "(%x)\n", ha->optrom_region_size); |
Harish Zunjarrao | f19af16 | 2010-10-15 11:27:43 -0700 | [diff] [blame] | 1404 | |
| 1405 | ha->optrom_state = QLA_SWAITING; |
| 1406 | return -ENOMEM; |
| 1407 | } |
| 1408 | |
| 1409 | memset(ha->optrom_buffer, 0, ha->optrom_region_size); |
| 1410 | return 0; |
| 1411 | } |
| 1412 | |
| 1413 | static int |
| 1414 | qla2x00_read_optrom(struct fc_bsg_job *bsg_job) |
| 1415 | { |
| 1416 | struct Scsi_Host *host = bsg_job->shost; |
| 1417 | scsi_qla_host_t *vha = shost_priv(host); |
| 1418 | struct qla_hw_data *ha = vha->hw; |
| 1419 | int rval = 0; |
| 1420 | |
Santosh Vernekar | 7d613ac | 2012-08-22 14:21:03 -0400 | [diff] [blame] | 1421 | if (ha->flags.nic_core_reset_hdlr_active) |
Giridhar Malavali | a49393f | 2012-04-25 07:26:14 -0700 | [diff] [blame] | 1422 | return -EBUSY; |
| 1423 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1424 | rval = qla2x00_optrom_setup(bsg_job, vha, 0); |
Harish Zunjarrao | f19af16 | 2010-10-15 11:27:43 -0700 | [diff] [blame] | 1425 | if (rval) |
| 1426 | return rval; |
| 1427 | |
| 1428 | ha->isp_ops->read_optrom(vha, ha->optrom_buffer, |
| 1429 | ha->optrom_region_start, ha->optrom_region_size); |
| 1430 | |
| 1431 | sg_copy_from_buffer(bsg_job->reply_payload.sg_list, |
| 1432 | bsg_job->reply_payload.sg_cnt, ha->optrom_buffer, |
| 1433 | ha->optrom_region_size); |
| 1434 | |
| 1435 | bsg_job->reply->reply_payload_rcv_len = ha->optrom_region_size; |
| 1436 | bsg_job->reply->result = DID_OK; |
| 1437 | vfree(ha->optrom_buffer); |
| 1438 | ha->optrom_buffer = NULL; |
| 1439 | ha->optrom_state = QLA_SWAITING; |
| 1440 | bsg_job->job_done(bsg_job); |
| 1441 | return rval; |
| 1442 | } |
| 1443 | |
| 1444 | static int |
| 1445 | qla2x00_update_optrom(struct fc_bsg_job *bsg_job) |
| 1446 | { |
| 1447 | struct Scsi_Host *host = bsg_job->shost; |
| 1448 | scsi_qla_host_t *vha = shost_priv(host); |
| 1449 | struct qla_hw_data *ha = vha->hw; |
| 1450 | int rval = 0; |
| 1451 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1452 | rval = qla2x00_optrom_setup(bsg_job, vha, 1); |
Harish Zunjarrao | f19af16 | 2010-10-15 11:27:43 -0700 | [diff] [blame] | 1453 | if (rval) |
| 1454 | return rval; |
| 1455 | |
Giridhar Malavali | b6d0d9d | 2012-05-15 14:34:25 -0400 | [diff] [blame] | 1456 | /* Set the isp82xx_no_md_cap not to capture minidump */ |
| 1457 | ha->flags.isp82xx_no_md_cap = 1; |
| 1458 | |
Harish Zunjarrao | f19af16 | 2010-10-15 11:27:43 -0700 | [diff] [blame] | 1459 | sg_copy_to_buffer(bsg_job->request_payload.sg_list, |
| 1460 | bsg_job->request_payload.sg_cnt, ha->optrom_buffer, |
| 1461 | ha->optrom_region_size); |
| 1462 | |
| 1463 | ha->isp_ops->write_optrom(vha, ha->optrom_buffer, |
| 1464 | ha->optrom_region_start, ha->optrom_region_size); |
| 1465 | |
| 1466 | bsg_job->reply->result = DID_OK; |
| 1467 | vfree(ha->optrom_buffer); |
| 1468 | ha->optrom_buffer = NULL; |
| 1469 | ha->optrom_state = QLA_SWAITING; |
| 1470 | bsg_job->job_done(bsg_job); |
| 1471 | return rval; |
| 1472 | } |
| 1473 | |
| 1474 | static int |
Joe Carnuccio | 697a4bc | 2011-08-16 11:31:52 -0700 | [diff] [blame] | 1475 | qla2x00_update_fru_versions(struct fc_bsg_job *bsg_job) |
| 1476 | { |
| 1477 | struct Scsi_Host *host = bsg_job->shost; |
| 1478 | scsi_qla_host_t *vha = shost_priv(host); |
| 1479 | struct qla_hw_data *ha = vha->hw; |
| 1480 | int rval = 0; |
| 1481 | uint8_t bsg[DMA_POOL_SIZE]; |
| 1482 | struct qla_image_version_list *list = (void *)bsg; |
| 1483 | struct qla_image_version *image; |
| 1484 | uint32_t count; |
| 1485 | dma_addr_t sfp_dma; |
| 1486 | void *sfp = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &sfp_dma); |
| 1487 | if (!sfp) { |
| 1488 | bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] = |
| 1489 | EXT_STATUS_NO_MEMORY; |
| 1490 | goto done; |
| 1491 | } |
| 1492 | |
| 1493 | sg_copy_to_buffer(bsg_job->request_payload.sg_list, |
| 1494 | bsg_job->request_payload.sg_cnt, list, sizeof(bsg)); |
| 1495 | |
| 1496 | image = list->version; |
| 1497 | count = list->count; |
| 1498 | while (count--) { |
| 1499 | memcpy(sfp, &image->field_info, sizeof(image->field_info)); |
| 1500 | rval = qla2x00_write_sfp(vha, sfp_dma, sfp, |
| 1501 | image->field_address.device, image->field_address.offset, |
| 1502 | sizeof(image->field_info), image->field_address.option); |
| 1503 | if (rval) { |
| 1504 | bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] = |
| 1505 | EXT_STATUS_MAILBOX; |
| 1506 | goto dealloc; |
| 1507 | } |
| 1508 | image++; |
| 1509 | } |
| 1510 | |
| 1511 | bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] = 0; |
| 1512 | |
| 1513 | dealloc: |
| 1514 | dma_pool_free(ha->s_dma_pool, sfp, sfp_dma); |
| 1515 | |
| 1516 | done: |
| 1517 | bsg_job->reply_len = sizeof(struct fc_bsg_reply); |
| 1518 | bsg_job->reply->result = DID_OK << 16; |
| 1519 | bsg_job->job_done(bsg_job); |
| 1520 | |
| 1521 | return 0; |
| 1522 | } |
| 1523 | |
| 1524 | static int |
| 1525 | qla2x00_read_fru_status(struct fc_bsg_job *bsg_job) |
| 1526 | { |
| 1527 | struct Scsi_Host *host = bsg_job->shost; |
| 1528 | scsi_qla_host_t *vha = shost_priv(host); |
| 1529 | struct qla_hw_data *ha = vha->hw; |
| 1530 | int rval = 0; |
| 1531 | uint8_t bsg[DMA_POOL_SIZE]; |
| 1532 | struct qla_status_reg *sr = (void *)bsg; |
| 1533 | dma_addr_t sfp_dma; |
| 1534 | uint8_t *sfp = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &sfp_dma); |
| 1535 | if (!sfp) { |
| 1536 | bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] = |
| 1537 | EXT_STATUS_NO_MEMORY; |
| 1538 | goto done; |
| 1539 | } |
| 1540 | |
| 1541 | sg_copy_to_buffer(bsg_job->request_payload.sg_list, |
| 1542 | bsg_job->request_payload.sg_cnt, sr, sizeof(*sr)); |
| 1543 | |
| 1544 | rval = qla2x00_read_sfp(vha, sfp_dma, sfp, |
| 1545 | sr->field_address.device, sr->field_address.offset, |
| 1546 | sizeof(sr->status_reg), sr->field_address.option); |
| 1547 | sr->status_reg = *sfp; |
| 1548 | |
| 1549 | if (rval) { |
| 1550 | bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] = |
| 1551 | EXT_STATUS_MAILBOX; |
| 1552 | goto dealloc; |
| 1553 | } |
| 1554 | |
| 1555 | sg_copy_from_buffer(bsg_job->reply_payload.sg_list, |
| 1556 | bsg_job->reply_payload.sg_cnt, sr, sizeof(*sr)); |
| 1557 | |
| 1558 | bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] = 0; |
| 1559 | |
| 1560 | dealloc: |
| 1561 | dma_pool_free(ha->s_dma_pool, sfp, sfp_dma); |
| 1562 | |
| 1563 | done: |
| 1564 | bsg_job->reply_len = sizeof(struct fc_bsg_reply); |
| 1565 | bsg_job->reply->reply_payload_rcv_len = sizeof(*sr); |
| 1566 | bsg_job->reply->result = DID_OK << 16; |
| 1567 | bsg_job->job_done(bsg_job); |
| 1568 | |
| 1569 | return 0; |
| 1570 | } |
| 1571 | |
| 1572 | static int |
| 1573 | qla2x00_write_fru_status(struct fc_bsg_job *bsg_job) |
| 1574 | { |
| 1575 | struct Scsi_Host *host = bsg_job->shost; |
| 1576 | scsi_qla_host_t *vha = shost_priv(host); |
| 1577 | struct qla_hw_data *ha = vha->hw; |
| 1578 | int rval = 0; |
| 1579 | uint8_t bsg[DMA_POOL_SIZE]; |
| 1580 | struct qla_status_reg *sr = (void *)bsg; |
| 1581 | dma_addr_t sfp_dma; |
| 1582 | uint8_t *sfp = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &sfp_dma); |
| 1583 | if (!sfp) { |
| 1584 | bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] = |
| 1585 | EXT_STATUS_NO_MEMORY; |
| 1586 | goto done; |
| 1587 | } |
| 1588 | |
| 1589 | sg_copy_to_buffer(bsg_job->request_payload.sg_list, |
| 1590 | bsg_job->request_payload.sg_cnt, sr, sizeof(*sr)); |
| 1591 | |
| 1592 | *sfp = sr->status_reg; |
| 1593 | rval = qla2x00_write_sfp(vha, sfp_dma, sfp, |
| 1594 | sr->field_address.device, sr->field_address.offset, |
| 1595 | sizeof(sr->status_reg), sr->field_address.option); |
| 1596 | |
| 1597 | if (rval) { |
| 1598 | bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] = |
| 1599 | EXT_STATUS_MAILBOX; |
| 1600 | goto dealloc; |
| 1601 | } |
| 1602 | |
| 1603 | bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] = 0; |
| 1604 | |
| 1605 | dealloc: |
| 1606 | dma_pool_free(ha->s_dma_pool, sfp, sfp_dma); |
| 1607 | |
| 1608 | done: |
| 1609 | bsg_job->reply_len = sizeof(struct fc_bsg_reply); |
| 1610 | bsg_job->reply->result = DID_OK << 16; |
| 1611 | bsg_job->job_done(bsg_job); |
| 1612 | |
| 1613 | return 0; |
| 1614 | } |
| 1615 | |
| 1616 | static int |
Joe Carnuccio | 9ebb5d9 | 2012-08-22 14:20:56 -0400 | [diff] [blame] | 1617 | qla2x00_write_i2c(struct fc_bsg_job *bsg_job) |
| 1618 | { |
| 1619 | struct Scsi_Host *host = bsg_job->shost; |
| 1620 | scsi_qla_host_t *vha = shost_priv(host); |
| 1621 | struct qla_hw_data *ha = vha->hw; |
| 1622 | int rval = 0; |
| 1623 | uint8_t bsg[DMA_POOL_SIZE]; |
| 1624 | struct qla_i2c_access *i2c = (void *)bsg; |
| 1625 | dma_addr_t sfp_dma; |
| 1626 | uint8_t *sfp = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &sfp_dma); |
| 1627 | if (!sfp) { |
| 1628 | bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] = |
| 1629 | EXT_STATUS_NO_MEMORY; |
| 1630 | goto done; |
| 1631 | } |
| 1632 | |
| 1633 | sg_copy_to_buffer(bsg_job->request_payload.sg_list, |
| 1634 | bsg_job->request_payload.sg_cnt, i2c, sizeof(*i2c)); |
| 1635 | |
| 1636 | memcpy(sfp, i2c->buffer, i2c->length); |
| 1637 | rval = qla2x00_write_sfp(vha, sfp_dma, sfp, |
| 1638 | i2c->device, i2c->offset, i2c->length, i2c->option); |
| 1639 | |
| 1640 | if (rval) { |
| 1641 | bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] = |
| 1642 | EXT_STATUS_MAILBOX; |
| 1643 | goto dealloc; |
| 1644 | } |
| 1645 | |
| 1646 | bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] = 0; |
| 1647 | |
| 1648 | dealloc: |
| 1649 | dma_pool_free(ha->s_dma_pool, sfp, sfp_dma); |
| 1650 | |
| 1651 | done: |
| 1652 | bsg_job->reply_len = sizeof(struct fc_bsg_reply); |
| 1653 | bsg_job->reply->result = DID_OK << 16; |
| 1654 | bsg_job->job_done(bsg_job); |
| 1655 | |
| 1656 | return 0; |
| 1657 | } |
| 1658 | |
| 1659 | static int |
| 1660 | qla2x00_read_i2c(struct fc_bsg_job *bsg_job) |
| 1661 | { |
| 1662 | struct Scsi_Host *host = bsg_job->shost; |
| 1663 | scsi_qla_host_t *vha = shost_priv(host); |
| 1664 | struct qla_hw_data *ha = vha->hw; |
| 1665 | int rval = 0; |
| 1666 | uint8_t bsg[DMA_POOL_SIZE]; |
| 1667 | struct qla_i2c_access *i2c = (void *)bsg; |
| 1668 | dma_addr_t sfp_dma; |
| 1669 | uint8_t *sfp = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &sfp_dma); |
| 1670 | if (!sfp) { |
| 1671 | bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] = |
| 1672 | EXT_STATUS_NO_MEMORY; |
| 1673 | goto done; |
| 1674 | } |
| 1675 | |
| 1676 | sg_copy_to_buffer(bsg_job->request_payload.sg_list, |
| 1677 | bsg_job->request_payload.sg_cnt, i2c, sizeof(*i2c)); |
| 1678 | |
| 1679 | rval = qla2x00_read_sfp(vha, sfp_dma, sfp, |
| 1680 | i2c->device, i2c->offset, i2c->length, i2c->option); |
| 1681 | |
| 1682 | if (rval) { |
| 1683 | bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] = |
| 1684 | EXT_STATUS_MAILBOX; |
| 1685 | goto dealloc; |
| 1686 | } |
| 1687 | |
| 1688 | memcpy(i2c->buffer, sfp, i2c->length); |
| 1689 | sg_copy_from_buffer(bsg_job->reply_payload.sg_list, |
| 1690 | bsg_job->reply_payload.sg_cnt, i2c, sizeof(*i2c)); |
| 1691 | |
| 1692 | bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] = 0; |
| 1693 | |
| 1694 | dealloc: |
| 1695 | dma_pool_free(ha->s_dma_pool, sfp, sfp_dma); |
| 1696 | |
| 1697 | done: |
| 1698 | bsg_job->reply_len = sizeof(struct fc_bsg_reply); |
| 1699 | bsg_job->reply->reply_payload_rcv_len = sizeof(*i2c); |
| 1700 | bsg_job->reply->result = DID_OK << 16; |
| 1701 | bsg_job->job_done(bsg_job); |
| 1702 | |
| 1703 | return 0; |
| 1704 | } |
| 1705 | |
| 1706 | static int |
Saurav Kashyap | a9b6f72 | 2012-08-22 14:21:01 -0400 | [diff] [blame] | 1707 | qla24xx_process_bidir_cmd(struct fc_bsg_job *bsg_job) |
| 1708 | { |
| 1709 | struct Scsi_Host *host = bsg_job->shost; |
| 1710 | scsi_qla_host_t *vha = shost_priv(host); |
| 1711 | struct qla_hw_data *ha = vha->hw; |
| 1712 | uint16_t thread_id; |
| 1713 | uint32_t rval = EXT_STATUS_OK; |
| 1714 | uint16_t req_sg_cnt = 0; |
| 1715 | uint16_t rsp_sg_cnt = 0; |
| 1716 | uint16_t nextlid = 0; |
| 1717 | uint32_t tot_dsds; |
| 1718 | srb_t *sp = NULL; |
| 1719 | uint32_t req_data_len = 0; |
| 1720 | uint32_t rsp_data_len = 0; |
| 1721 | |
| 1722 | /* Check the type of the adapter */ |
| 1723 | if (!IS_BIDI_CAPABLE(ha)) { |
| 1724 | ql_log(ql_log_warn, vha, 0x70a0, |
| 1725 | "This adapter is not supported\n"); |
| 1726 | rval = EXT_STATUS_NOT_SUPPORTED; |
| 1727 | goto done; |
| 1728 | } |
| 1729 | |
| 1730 | if (test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags) || |
| 1731 | test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags) || |
| 1732 | test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) { |
| 1733 | rval = EXT_STATUS_BUSY; |
| 1734 | goto done; |
| 1735 | } |
| 1736 | |
| 1737 | /* Check if host is online */ |
| 1738 | if (!vha->flags.online) { |
| 1739 | ql_log(ql_log_warn, vha, 0x70a1, |
| 1740 | "Host is not online\n"); |
| 1741 | rval = EXT_STATUS_DEVICE_OFFLINE; |
| 1742 | goto done; |
| 1743 | } |
| 1744 | |
| 1745 | /* Check if cable is plugged in or not */ |
| 1746 | if (vha->device_flags & DFLG_NO_CABLE) { |
| 1747 | ql_log(ql_log_warn, vha, 0x70a2, |
| 1748 | "Cable is unplugged...\n"); |
| 1749 | rval = EXT_STATUS_INVALID_CFG; |
| 1750 | goto done; |
| 1751 | } |
| 1752 | |
| 1753 | /* Check if the switch is connected or not */ |
| 1754 | if (ha->current_topology != ISP_CFG_F) { |
| 1755 | ql_log(ql_log_warn, vha, 0x70a3, |
| 1756 | "Host is not connected to the switch\n"); |
| 1757 | rval = EXT_STATUS_INVALID_CFG; |
| 1758 | goto done; |
| 1759 | } |
| 1760 | |
| 1761 | /* Check if operating mode is P2P */ |
| 1762 | if (ha->operating_mode != P2P) { |
| 1763 | ql_log(ql_log_warn, vha, 0x70a4, |
| 1764 | "Host is operating mode is not P2p\n"); |
| 1765 | rval = EXT_STATUS_INVALID_CFG; |
| 1766 | goto done; |
| 1767 | } |
| 1768 | |
| 1769 | thread_id = bsg_job->request->rqst_data.h_vendor.vendor_cmd[1]; |
| 1770 | |
| 1771 | mutex_lock(&ha->selflogin_lock); |
| 1772 | if (vha->self_login_loop_id == 0) { |
| 1773 | /* Initialize all required fields of fcport */ |
| 1774 | vha->bidir_fcport.vha = vha; |
| 1775 | vha->bidir_fcport.d_id.b.al_pa = vha->d_id.b.al_pa; |
| 1776 | vha->bidir_fcport.d_id.b.area = vha->d_id.b.area; |
| 1777 | vha->bidir_fcport.d_id.b.domain = vha->d_id.b.domain; |
| 1778 | vha->bidir_fcport.loop_id = vha->loop_id; |
| 1779 | |
| 1780 | if (qla2x00_fabric_login(vha, &(vha->bidir_fcport), &nextlid)) { |
| 1781 | ql_log(ql_log_warn, vha, 0x70a7, |
| 1782 | "Failed to login port %06X for bidirectional IOCB\n", |
| 1783 | vha->bidir_fcport.d_id.b24); |
| 1784 | mutex_unlock(&ha->selflogin_lock); |
| 1785 | rval = EXT_STATUS_MAILBOX; |
| 1786 | goto done; |
| 1787 | } |
| 1788 | vha->self_login_loop_id = nextlid - 1; |
| 1789 | |
| 1790 | } |
| 1791 | /* Assign the self login loop id to fcport */ |
| 1792 | mutex_unlock(&ha->selflogin_lock); |
| 1793 | |
| 1794 | vha->bidir_fcport.loop_id = vha->self_login_loop_id; |
| 1795 | |
| 1796 | req_sg_cnt = dma_map_sg(&ha->pdev->dev, |
| 1797 | bsg_job->request_payload.sg_list, |
| 1798 | bsg_job->request_payload.sg_cnt, |
| 1799 | DMA_TO_DEVICE); |
| 1800 | |
| 1801 | if (!req_sg_cnt) { |
| 1802 | rval = EXT_STATUS_NO_MEMORY; |
| 1803 | goto done; |
| 1804 | } |
| 1805 | |
| 1806 | rsp_sg_cnt = dma_map_sg(&ha->pdev->dev, |
| 1807 | bsg_job->reply_payload.sg_list, bsg_job->reply_payload.sg_cnt, |
| 1808 | DMA_FROM_DEVICE); |
| 1809 | |
| 1810 | if (!rsp_sg_cnt) { |
| 1811 | rval = EXT_STATUS_NO_MEMORY; |
| 1812 | goto done_unmap_req_sg; |
| 1813 | } |
| 1814 | |
| 1815 | if ((req_sg_cnt != bsg_job->request_payload.sg_cnt) || |
| 1816 | (rsp_sg_cnt != bsg_job->reply_payload.sg_cnt)) { |
| 1817 | ql_dbg(ql_dbg_user, vha, 0x70a9, |
| 1818 | "Dma mapping resulted in different sg counts " |
| 1819 | "[request_sg_cnt: %x dma_request_sg_cnt: %x reply_sg_cnt: " |
| 1820 | "%x dma_reply_sg_cnt: %x]\n", |
| 1821 | bsg_job->request_payload.sg_cnt, req_sg_cnt, |
| 1822 | bsg_job->reply_payload.sg_cnt, rsp_sg_cnt); |
| 1823 | rval = EXT_STATUS_NO_MEMORY; |
| 1824 | goto done_unmap_sg; |
| 1825 | } |
| 1826 | |
| 1827 | if (req_data_len != rsp_data_len) { |
| 1828 | rval = EXT_STATUS_BUSY; |
| 1829 | ql_log(ql_log_warn, vha, 0x70aa, |
| 1830 | "req_data_len != rsp_data_len\n"); |
| 1831 | goto done_unmap_sg; |
| 1832 | } |
| 1833 | |
| 1834 | req_data_len = bsg_job->request_payload.payload_len; |
| 1835 | rsp_data_len = bsg_job->reply_payload.payload_len; |
| 1836 | |
| 1837 | |
| 1838 | /* Alloc SRB structure */ |
| 1839 | sp = qla2x00_get_sp(vha, &(vha->bidir_fcport), GFP_KERNEL); |
| 1840 | if (!sp) { |
| 1841 | ql_dbg(ql_dbg_user, vha, 0x70ac, |
| 1842 | "Alloc SRB structure failed\n"); |
| 1843 | rval = EXT_STATUS_NO_MEMORY; |
| 1844 | goto done_unmap_sg; |
| 1845 | } |
| 1846 | |
| 1847 | /*Populate srb->ctx with bidir ctx*/ |
| 1848 | sp->u.bsg_job = bsg_job; |
| 1849 | sp->free = qla2x00_bsg_sp_free; |
| 1850 | sp->type = SRB_BIDI_CMD; |
| 1851 | sp->done = qla2x00_bsg_job_done; |
| 1852 | |
| 1853 | /* Add the read and write sg count */ |
| 1854 | tot_dsds = rsp_sg_cnt + req_sg_cnt; |
| 1855 | |
| 1856 | rval = qla2x00_start_bidir(sp, vha, tot_dsds); |
| 1857 | if (rval != EXT_STATUS_OK) |
| 1858 | goto done_free_srb; |
| 1859 | /* the bsg request will be completed in the interrupt handler */ |
| 1860 | return rval; |
| 1861 | |
| 1862 | done_free_srb: |
| 1863 | mempool_free(sp, ha->srb_mempool); |
| 1864 | done_unmap_sg: |
| 1865 | dma_unmap_sg(&ha->pdev->dev, |
| 1866 | bsg_job->reply_payload.sg_list, |
| 1867 | bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE); |
| 1868 | done_unmap_req_sg: |
| 1869 | dma_unmap_sg(&ha->pdev->dev, |
| 1870 | bsg_job->request_payload.sg_list, |
| 1871 | bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE); |
| 1872 | done: |
| 1873 | |
| 1874 | /* Return an error vendor specific response |
| 1875 | * and complete the bsg request |
| 1876 | */ |
| 1877 | bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] = rval; |
| 1878 | bsg_job->reply_len = sizeof(struct fc_bsg_reply); |
| 1879 | bsg_job->reply->reply_payload_rcv_len = 0; |
| 1880 | bsg_job->reply->result = (DID_OK) << 16; |
| 1881 | bsg_job->job_done(bsg_job); |
| 1882 | /* Always retrun success, vendor rsp carries correct status */ |
| 1883 | return 0; |
| 1884 | } |
| 1885 | |
| 1886 | static int |
Giridhar Malavali | 8ae6d9c | 2013-03-28 08:21:23 -0400 | [diff] [blame] | 1887 | qlafx00_mgmt_cmd(struct fc_bsg_job *bsg_job) |
| 1888 | { |
| 1889 | struct Scsi_Host *host = bsg_job->shost; |
| 1890 | scsi_qla_host_t *vha = shost_priv(host); |
| 1891 | struct qla_hw_data *ha = vha->hw; |
| 1892 | int rval = (DRIVER_ERROR << 16); |
| 1893 | struct qla_mt_iocb_rqst_fx00 *piocb_rqst; |
| 1894 | srb_t *sp; |
| 1895 | int req_sg_cnt = 0, rsp_sg_cnt = 0; |
| 1896 | struct fc_port *fcport; |
| 1897 | char *type = "FC_BSG_HST_FX_MGMT"; |
| 1898 | |
| 1899 | /* Copy the IOCB specific information */ |
| 1900 | piocb_rqst = (struct qla_mt_iocb_rqst_fx00 *) |
| 1901 | &bsg_job->request->rqst_data.h_vendor.vendor_cmd[1]; |
| 1902 | |
| 1903 | /* Dump the vendor information */ |
| 1904 | ql_dump_buffer(ql_dbg_user + ql_dbg_verbose , vha, 0x70cf, |
| 1905 | (uint8_t *)piocb_rqst, sizeof(struct qla_mt_iocb_rqst_fx00)); |
| 1906 | |
| 1907 | if (!vha->flags.online) { |
| 1908 | ql_log(ql_log_warn, vha, 0x70d0, |
| 1909 | "Host is not online.\n"); |
| 1910 | rval = -EIO; |
| 1911 | goto done; |
| 1912 | } |
| 1913 | |
| 1914 | if (piocb_rqst->flags & SRB_FXDISC_REQ_DMA_VALID) { |
| 1915 | req_sg_cnt = dma_map_sg(&ha->pdev->dev, |
| 1916 | bsg_job->request_payload.sg_list, |
| 1917 | bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE); |
| 1918 | if (!req_sg_cnt) { |
| 1919 | ql_log(ql_log_warn, vha, 0x70c7, |
| 1920 | "dma_map_sg return %d for request\n", req_sg_cnt); |
| 1921 | rval = -ENOMEM; |
| 1922 | goto done; |
| 1923 | } |
| 1924 | } |
| 1925 | |
| 1926 | if (piocb_rqst->flags & SRB_FXDISC_RESP_DMA_VALID) { |
| 1927 | rsp_sg_cnt = dma_map_sg(&ha->pdev->dev, |
| 1928 | bsg_job->reply_payload.sg_list, |
| 1929 | bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE); |
| 1930 | if (!rsp_sg_cnt) { |
| 1931 | ql_log(ql_log_warn, vha, 0x70c8, |
| 1932 | "dma_map_sg return %d for reply\n", rsp_sg_cnt); |
| 1933 | rval = -ENOMEM; |
| 1934 | goto done_unmap_req_sg; |
| 1935 | } |
| 1936 | } |
| 1937 | |
| 1938 | ql_dbg(ql_dbg_user, vha, 0x70c9, |
| 1939 | "request_sg_cnt: %x dma_request_sg_cnt: %x reply_sg_cnt:%x " |
| 1940 | "dma_reply_sg_cnt: %x\n", bsg_job->request_payload.sg_cnt, |
| 1941 | req_sg_cnt, bsg_job->reply_payload.sg_cnt, rsp_sg_cnt); |
| 1942 | |
| 1943 | /* Allocate a dummy fcport structure, since functions preparing the |
| 1944 | * IOCB and mailbox command retrieves port specific information |
| 1945 | * from fcport structure. For Host based ELS commands there will be |
| 1946 | * no fcport structure allocated |
| 1947 | */ |
| 1948 | fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL); |
| 1949 | if (!fcport) { |
| 1950 | ql_log(ql_log_warn, vha, 0x70ca, |
| 1951 | "Failed to allocate fcport.\n"); |
| 1952 | rval = -ENOMEM; |
| 1953 | goto done_unmap_rsp_sg; |
| 1954 | } |
| 1955 | |
| 1956 | /* Alloc SRB structure */ |
| 1957 | sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL); |
| 1958 | if (!sp) { |
| 1959 | ql_log(ql_log_warn, vha, 0x70cb, |
| 1960 | "qla2x00_get_sp failed.\n"); |
| 1961 | rval = -ENOMEM; |
| 1962 | goto done_free_fcport; |
| 1963 | } |
| 1964 | |
| 1965 | /* Initialize all required fields of fcport */ |
| 1966 | fcport->vha = vha; |
| 1967 | fcport->loop_id = piocb_rqst->dataword; |
| 1968 | |
| 1969 | sp->type = SRB_FXIOCB_BCMD; |
| 1970 | sp->name = "bsg_fx_mgmt"; |
| 1971 | sp->iocbs = qla24xx_calc_ct_iocbs(req_sg_cnt + rsp_sg_cnt); |
| 1972 | sp->u.bsg_job = bsg_job; |
| 1973 | sp->free = qla2x00_bsg_sp_free; |
| 1974 | sp->done = qla2x00_bsg_job_done; |
| 1975 | |
| 1976 | ql_dbg(ql_dbg_user, vha, 0x70cc, |
| 1977 | "bsg rqst type: %s fx_mgmt_type: %x id=%x\n", |
| 1978 | type, piocb_rqst->func_type, fcport->loop_id); |
| 1979 | |
| 1980 | rval = qla2x00_start_sp(sp); |
| 1981 | if (rval != QLA_SUCCESS) { |
| 1982 | ql_log(ql_log_warn, vha, 0x70cd, |
| 1983 | "qla2x00_start_sp failed=%d.\n", rval); |
| 1984 | mempool_free(sp, ha->srb_mempool); |
| 1985 | rval = -EIO; |
| 1986 | goto done_free_fcport; |
| 1987 | } |
| 1988 | return rval; |
| 1989 | |
| 1990 | done_free_fcport: |
| 1991 | kfree(fcport); |
| 1992 | |
| 1993 | done_unmap_rsp_sg: |
| 1994 | if (piocb_rqst->flags & SRB_FXDISC_RESP_DMA_VALID) |
| 1995 | dma_unmap_sg(&ha->pdev->dev, |
| 1996 | bsg_job->reply_payload.sg_list, |
| 1997 | bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE); |
| 1998 | done_unmap_req_sg: |
| 1999 | if (piocb_rqst->flags & SRB_FXDISC_REQ_DMA_VALID) |
| 2000 | dma_unmap_sg(&ha->pdev->dev, |
| 2001 | bsg_job->request_payload.sg_list, |
| 2002 | bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE); |
| 2003 | |
| 2004 | done: |
| 2005 | return rval; |
| 2006 | } |
| 2007 | |
| 2008 | static int |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 2009 | qla2x00_process_vendor_specific(struct fc_bsg_job *bsg_job) |
| 2010 | { |
| 2011 | switch (bsg_job->request->rqst_data.h_vendor.vendor_cmd[0]) { |
| 2012 | case QL_VND_LOOPBACK: |
| 2013 | return qla2x00_process_loopback(bsg_job); |
| 2014 | |
| 2015 | case QL_VND_A84_RESET: |
| 2016 | return qla84xx_reset(bsg_job); |
| 2017 | |
| 2018 | case QL_VND_A84_UPDATE_FW: |
| 2019 | return qla84xx_updatefw(bsg_job); |
| 2020 | |
| 2021 | case QL_VND_A84_MGMT_CMD: |
| 2022 | return qla84xx_mgmt_cmd(bsg_job); |
| 2023 | |
| 2024 | case QL_VND_IIDMA: |
| 2025 | return qla24xx_iidma(bsg_job); |
| 2026 | |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 2027 | case QL_VND_FCP_PRIO_CFG_CMD: |
| 2028 | return qla24xx_proc_fcp_prio_cfg_cmd(bsg_job); |
| 2029 | |
Harish Zunjarrao | f19af16 | 2010-10-15 11:27:43 -0700 | [diff] [blame] | 2030 | case QL_VND_READ_FLASH: |
| 2031 | return qla2x00_read_optrom(bsg_job); |
| 2032 | |
| 2033 | case QL_VND_UPDATE_FLASH: |
| 2034 | return qla2x00_update_optrom(bsg_job); |
| 2035 | |
Joe Carnuccio | 697a4bc | 2011-08-16 11:31:52 -0700 | [diff] [blame] | 2036 | case QL_VND_SET_FRU_VERSION: |
| 2037 | return qla2x00_update_fru_versions(bsg_job); |
| 2038 | |
| 2039 | case QL_VND_READ_FRU_STATUS: |
| 2040 | return qla2x00_read_fru_status(bsg_job); |
| 2041 | |
| 2042 | case QL_VND_WRITE_FRU_STATUS: |
| 2043 | return qla2x00_write_fru_status(bsg_job); |
| 2044 | |
Joe Carnuccio | 9ebb5d9 | 2012-08-22 14:20:56 -0400 | [diff] [blame] | 2045 | case QL_VND_WRITE_I2C: |
| 2046 | return qla2x00_write_i2c(bsg_job); |
| 2047 | |
| 2048 | case QL_VND_READ_I2C: |
| 2049 | return qla2x00_read_i2c(bsg_job); |
| 2050 | |
Saurav Kashyap | a9b6f72 | 2012-08-22 14:21:01 -0400 | [diff] [blame] | 2051 | case QL_VND_DIAG_IO_CMD: |
| 2052 | return qla24xx_process_bidir_cmd(bsg_job); |
| 2053 | |
Giridhar Malavali | 8ae6d9c | 2013-03-28 08:21:23 -0400 | [diff] [blame] | 2054 | case QL_VND_FX00_MGMT_CMD: |
| 2055 | return qlafx00_mgmt_cmd(bsg_job); |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 2056 | default: |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 2057 | return -ENOSYS; |
| 2058 | } |
| 2059 | } |
| 2060 | |
| 2061 | int |
| 2062 | qla24xx_bsg_request(struct fc_bsg_job *bsg_job) |
| 2063 | { |
| 2064 | int ret = -EINVAL; |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2065 | struct fc_rport *rport; |
| 2066 | fc_port_t *fcport = NULL; |
| 2067 | struct Scsi_Host *host; |
| 2068 | scsi_qla_host_t *vha; |
| 2069 | |
Andrew Vasquez | b7bfbe1 | 2012-02-09 11:15:44 -0800 | [diff] [blame] | 2070 | /* In case no data transferred. */ |
| 2071 | bsg_job->reply->reply_payload_rcv_len = 0; |
| 2072 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2073 | if (bsg_job->request->msgcode == FC_BSG_RPT_ELS) { |
| 2074 | rport = bsg_job->rport; |
| 2075 | fcport = *(fc_port_t **) rport->dd_data; |
| 2076 | host = rport_to_shost(rport); |
| 2077 | vha = shost_priv(host); |
| 2078 | } else { |
| 2079 | host = bsg_job->shost; |
| 2080 | vha = shost_priv(host); |
| 2081 | } |
| 2082 | |
Andrew Vasquez | d051a5aa | 2012-02-09 11:14:05 -0800 | [diff] [blame] | 2083 | if (qla2x00_reset_active(vha)) { |
| 2084 | ql_dbg(ql_dbg_user, vha, 0x709f, |
| 2085 | "BSG: ISP abort active/needed -- cmd=%d.\n", |
| 2086 | bsg_job->request->msgcode); |
Andrew Vasquez | d051a5aa | 2012-02-09 11:14:05 -0800 | [diff] [blame] | 2087 | return -EBUSY; |
| 2088 | } |
| 2089 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2090 | ql_dbg(ql_dbg_user, vha, 0x7000, |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 2091 | "Entered %s msgcode=0x%x.\n", __func__, bsg_job->request->msgcode); |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 2092 | |
| 2093 | switch (bsg_job->request->msgcode) { |
| 2094 | case FC_BSG_RPT_ELS: |
| 2095 | case FC_BSG_HST_ELS_NOLOGIN: |
| 2096 | ret = qla2x00_process_els(bsg_job); |
| 2097 | break; |
| 2098 | case FC_BSG_HST_CT: |
| 2099 | ret = qla2x00_process_ct(bsg_job); |
| 2100 | break; |
| 2101 | case FC_BSG_HST_VENDOR: |
| 2102 | ret = qla2x00_process_vendor_specific(bsg_job); |
| 2103 | break; |
| 2104 | case FC_BSG_HST_ADD_RPORT: |
| 2105 | case FC_BSG_HST_DEL_RPORT: |
| 2106 | case FC_BSG_RPT_CT: |
| 2107 | default: |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2108 | ql_log(ql_log_warn, vha, 0x705a, "Unsupported BSG request.\n"); |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 2109 | break; |
Andrew Vasquez | 6c452a4 | 2010-03-19 17:04:02 -0700 | [diff] [blame] | 2110 | } |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 2111 | return ret; |
| 2112 | } |
| 2113 | |
| 2114 | int |
| 2115 | qla24xx_bsg_timeout(struct fc_bsg_job *bsg_job) |
| 2116 | { |
| 2117 | scsi_qla_host_t *vha = shost_priv(bsg_job->shost); |
| 2118 | struct qla_hw_data *ha = vha->hw; |
| 2119 | srb_t *sp; |
| 2120 | int cnt, que; |
| 2121 | unsigned long flags; |
| 2122 | struct req_que *req; |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 2123 | |
| 2124 | /* find the bsg job from the active list of commands */ |
| 2125 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 2126 | for (que = 0; que < ha->max_req_queues; que++) { |
| 2127 | req = ha->req_q_map[que]; |
| 2128 | if (!req) |
| 2129 | continue; |
| 2130 | |
Chad Dupuis | 8d93f55 | 2013-01-30 03:34:37 -0500 | [diff] [blame] | 2131 | for (cnt = 1; cnt < req->num_outstanding_cmds; cnt++) { |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 2132 | sp = req->outstanding_cmds[cnt]; |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 2133 | if (sp) { |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 2134 | if (((sp->type == SRB_CT_CMD) || |
Giridhar Malavali | 8ae6d9c | 2013-03-28 08:21:23 -0400 | [diff] [blame] | 2135 | (sp->type == SRB_ELS_CMD_HST) || |
| 2136 | (sp->type == SRB_FXIOCB_BCMD)) |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 2137 | && (sp->u.bsg_job == bsg_job)) { |
Giridhar Malavali | 8edf3ed | 2013-06-25 11:27:17 -0400 | [diff] [blame] | 2138 | req->outstanding_cmds[cnt] = NULL; |
Giridhar Malavali | 900a36e | 2010-12-21 16:00:26 -0800 | [diff] [blame] | 2139 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 2140 | if (ha->isp_ops->abort_command(sp)) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2141 | ql_log(ql_log_warn, vha, 0x7089, |
| 2142 | "mbx abort_command " |
| 2143 | "failed.\n"); |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 2144 | bsg_job->req->errors = |
| 2145 | bsg_job->reply->result = -EIO; |
| 2146 | } else { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2147 | ql_dbg(ql_dbg_user, vha, 0x708a, |
| 2148 | "mbx abort_command " |
| 2149 | "success.\n"); |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 2150 | bsg_job->req->errors = |
| 2151 | bsg_job->reply->result = 0; |
| 2152 | } |
Giridhar Malavali | 900a36e | 2010-12-21 16:00:26 -0800 | [diff] [blame] | 2153 | spin_lock_irqsave(&ha->hardware_lock, flags); |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 2154 | goto done; |
| 2155 | } |
| 2156 | } |
| 2157 | } |
| 2158 | } |
| 2159 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2160 | 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] | 2161 | bsg_job->req->errors = bsg_job->reply->result = -ENXIO; |
| 2162 | return 0; |
| 2163 | |
| 2164 | done: |
| 2165 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
Giridhar Malavali | 8edf3ed | 2013-06-25 11:27:17 -0400 | [diff] [blame] | 2166 | sp->free(vha, sp); |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 2167 | return 0; |
| 2168 | } |