blob: 1bf8061ff8032fae46854f84d85946ea55c6072a [file] [log] [blame]
Johannes Thumshirncd21c602016-11-17 10:31:14 +01001 /*
Giridhar Malavali6e980162010-03-19 17:03:58 -07002 * QLogic Fibre Channel HBA Driver
Armen Baloyanbd21eaf2014-04-11 16:54:24 -04003 * Copyright (c) 2003-2014 QLogic Corporation
Giridhar Malavali6e980162010-03-19 17:03:58 -07004 *
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>
Johannes Thumshirn75cc8cf2016-11-17 10:31:19 +010012#include <linux/bsg-lib.h>
Giridhar Malavali6e980162010-03-19 17:03:58 -070013
14/* BSG support for ELS/CT pass through */
Giridhar Malavali9ba56b92012-02-09 11:15:36 -080015void
16qla2x00_bsg_job_done(void *data, void *ptr, int res)
Giridhar Malavali6e980162010-03-19 17:03:58 -070017{
Giridhar Malavali9ba56b92012-02-09 11:15:36 -080018 srb_t *sp = (srb_t *)ptr;
19 struct scsi_qla_host *vha = (scsi_qla_host_t *)data;
Johannes Thumshirn75cc8cf2016-11-17 10:31:19 +010020 struct bsg_job *bsg_job = sp->u.bsg_job;
Johannes Thumshirn01e0e152016-11-17 10:31:12 +010021 struct fc_bsg_reply *bsg_reply = bsg_job->reply;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -080022
Johannes Thumshirn01e0e152016-11-17 10:31:12 +010023 bsg_reply->result = res;
Johannes Thumshirn06548162016-11-17 10:31:22 +010024 bsg_job_done(bsg_job, bsg_reply->result,
Johannes Thumshirn1abaede2016-11-17 10:31:13 +010025 bsg_reply->reply_payload_rcv_len);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -080026 sp->free(vha, sp);
27}
28
29void
30qla2x00_bsg_sp_free(void *data, void *ptr)
31{
32 srb_t *sp = (srb_t *)ptr;
Chad Dupuisb00ee7d2013-02-08 01:57:50 -050033 struct scsi_qla_host *vha = sp->fcport->vha;
Johannes Thumshirn75cc8cf2016-11-17 10:31:19 +010034 struct bsg_job *bsg_job = sp->u.bsg_job;
Johannes Thumshirn01e0e152016-11-17 10:31:12 +010035 struct fc_bsg_request *bsg_request = bsg_job->request;
36
Giridhar Malavali6e980162010-03-19 17:03:58 -070037 struct qla_hw_data *ha = vha->hw;
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -040038 struct qla_mt_iocb_rqst_fx00 *piocb_rqst;
Giridhar Malavali6e980162010-03-19 17:03:58 -070039
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -040040 if (sp->type == SRB_FXIOCB_BCMD) {
41 piocb_rqst = (struct qla_mt_iocb_rqst_fx00 *)
Johannes Thumshirn01e0e152016-11-17 10:31:12 +010042 &bsg_request->rqst_data.h_vendor.vendor_cmd[1];
Giridhar Malavali6e980162010-03-19 17:03:58 -070043
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -040044 if (piocb_rqst->flags & SRB_FXDISC_REQ_DMA_VALID)
45 dma_unmap_sg(&ha->pdev->dev,
46 bsg_job->request_payload.sg_list,
47 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
48
49 if (piocb_rqst->flags & SRB_FXDISC_RESP_DMA_VALID)
50 dma_unmap_sg(&ha->pdev->dev,
51 bsg_job->reply_payload.sg_list,
52 bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
53 } else {
54 dma_unmap_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
55 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
56
57 dma_unmap_sg(&ha->pdev->dev, bsg_job->reply_payload.sg_list,
58 bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
59 }
Giridhar Malavali9ba56b92012-02-09 11:15:36 -080060
61 if (sp->type == SRB_CT_CMD ||
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -040062 sp->type == SRB_FXIOCB_BCMD ||
Giridhar Malavali9ba56b92012-02-09 11:15:36 -080063 sp->type == SRB_ELS_CMD_HST)
64 kfree(sp->fcport);
Chad Dupuisb00ee7d2013-02-08 01:57:50 -050065 qla2x00_rel_sp(vha, sp);
Giridhar Malavali6e980162010-03-19 17:03:58 -070066}
67
Sarang Radke09ff7012010-03-19 17:03:59 -070068int
Saurav Kashyap7c3df132011-07-14 12:00:13 -070069qla24xx_fcp_prio_cfg_valid(scsi_qla_host_t *vha,
70 struct qla_fcp_prio_cfg *pri_cfg, uint8_t flag)
Sarang Radke09ff7012010-03-19 17:03:59 -070071{
72 int i, ret, num_valid;
73 uint8_t *bcode;
74 struct qla_fcp_prio_entry *pri_entry;
Madhuranath Iyengar2f0f3f42010-07-23 15:28:24 +050075 uint32_t *bcode_val_ptr, bcode_val;
Sarang Radke09ff7012010-03-19 17:03:59 -070076
77 ret = 1;
78 num_valid = 0;
79 bcode = (uint8_t *)pri_cfg;
Madhuranath Iyengar2f0f3f42010-07-23 15:28:24 +050080 bcode_val_ptr = (uint32_t *)pri_cfg;
81 bcode_val = (uint32_t)(*bcode_val_ptr);
Sarang Radke09ff7012010-03-19 17:03:59 -070082
Madhuranath Iyengar2f0f3f42010-07-23 15:28:24 +050083 if (bcode_val == 0xFFFFFFFF) {
84 /* No FCP Priority config data in flash */
Saurav Kashyap7c3df132011-07-14 12:00:13 -070085 ql_dbg(ql_dbg_user, vha, 0x7051,
86 "No FCP Priority config data.\n");
Madhuranath Iyengar2f0f3f42010-07-23 15:28:24 +050087 return 0;
88 }
89
90 if (bcode[0] != 'H' || bcode[1] != 'Q' || bcode[2] != 'O' ||
91 bcode[3] != 'S') {
92 /* Invalid FCP priority data header*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -070093 ql_dbg(ql_dbg_user, vha, 0x7052,
94 "Invalid FCP Priority data header. bcode=0x%x.\n",
95 bcode_val);
Sarang Radke09ff7012010-03-19 17:03:59 -070096 return 0;
97 }
98 if (flag != 1)
99 return ret;
100
101 pri_entry = &pri_cfg->entry[0];
102 for (i = 0; i < pri_cfg->num_entries; i++) {
103 if (pri_entry->flags & FCP_PRIO_ENTRY_TAG_VALID)
104 num_valid++;
105 pri_entry++;
106 }
107
Madhuranath Iyengar2f0f3f42010-07-23 15:28:24 +0500108 if (num_valid == 0) {
109 /* No valid FCP priority data entries */
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700110 ql_dbg(ql_dbg_user, vha, 0x7053,
111 "No valid FCP Priority data entries.\n");
Sarang Radke09ff7012010-03-19 17:03:59 -0700112 ret = 0;
Madhuranath Iyengar2f0f3f42010-07-23 15:28:24 +0500113 } else {
114 /* FCP priority data is valid */
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700115 ql_dbg(ql_dbg_user, vha, 0x7054,
116 "Valid FCP priority data. num entries = %d.\n",
117 num_valid);
Madhuranath Iyengar2f0f3f42010-07-23 15:28:24 +0500118 }
Sarang Radke09ff7012010-03-19 17:03:59 -0700119
120 return ret;
121}
122
123static int
Johannes Thumshirn75cc8cf2016-11-17 10:31:19 +0100124qla24xx_proc_fcp_prio_cfg_cmd(struct bsg_job *bsg_job)
Sarang Radke09ff7012010-03-19 17:03:59 -0700125{
Johannes Thumshirncd21c602016-11-17 10:31:14 +0100126 struct Scsi_Host *host = fc_bsg_to_shost(bsg_job);
Johannes Thumshirn01e0e152016-11-17 10:31:12 +0100127 struct fc_bsg_request *bsg_request = bsg_job->request;
128 struct fc_bsg_reply *bsg_reply = bsg_job->reply;
Sarang Radke09ff7012010-03-19 17:03:59 -0700129 scsi_qla_host_t *vha = shost_priv(host);
130 struct qla_hw_data *ha = vha->hw;
131 int ret = 0;
132 uint32_t len;
133 uint32_t oper;
134
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -0400135 if (!(IS_QLA24XX_TYPE(ha) || IS_QLA25XX(ha) || IS_P3P_TYPE(ha))) {
Madhuranath Iyengar2f0f3f42010-07-23 15:28:24 +0500136 ret = -EINVAL;
137 goto exit_fcp_prio_cfg;
138 }
139
Sarang Radke09ff7012010-03-19 17:03:59 -0700140 /* Get the sub command */
Johannes Thumshirn01e0e152016-11-17 10:31:12 +0100141 oper = bsg_request->rqst_data.h_vendor.vendor_cmd[1];
Sarang Radke09ff7012010-03-19 17:03:59 -0700142
143 /* Only set config is allowed if config memory is not allocated */
144 if (!ha->fcp_prio_cfg && (oper != QLFC_FCP_PRIO_SET_CONFIG)) {
145 ret = -EINVAL;
146 goto exit_fcp_prio_cfg;
147 }
148 switch (oper) {
149 case QLFC_FCP_PRIO_DISABLE:
150 if (ha->flags.fcp_prio_enabled) {
151 ha->flags.fcp_prio_enabled = 0;
152 ha->fcp_prio_cfg->attributes &=
153 ~FCP_PRIO_ATTR_ENABLE;
154 qla24xx_update_all_fcp_prio(vha);
Johannes Thumshirn01e0e152016-11-17 10:31:12 +0100155 bsg_reply->result = DID_OK;
Sarang Radke09ff7012010-03-19 17:03:59 -0700156 } else {
157 ret = -EINVAL;
Johannes Thumshirn01e0e152016-11-17 10:31:12 +0100158 bsg_reply->result = (DID_ERROR << 16);
Sarang Radke09ff7012010-03-19 17:03:59 -0700159 goto exit_fcp_prio_cfg;
160 }
161 break;
162
163 case QLFC_FCP_PRIO_ENABLE:
164 if (!ha->flags.fcp_prio_enabled) {
165 if (ha->fcp_prio_cfg) {
166 ha->flags.fcp_prio_enabled = 1;
167 ha->fcp_prio_cfg->attributes |=
168 FCP_PRIO_ATTR_ENABLE;
169 qla24xx_update_all_fcp_prio(vha);
Johannes Thumshirn01e0e152016-11-17 10:31:12 +0100170 bsg_reply->result = DID_OK;
Sarang Radke09ff7012010-03-19 17:03:59 -0700171 } else {
172 ret = -EINVAL;
Johannes Thumshirn01e0e152016-11-17 10:31:12 +0100173 bsg_reply->result = (DID_ERROR << 16);
Sarang Radke09ff7012010-03-19 17:03:59 -0700174 goto exit_fcp_prio_cfg;
175 }
176 }
177 break;
178
179 case QLFC_FCP_PRIO_GET_CONFIG:
180 len = bsg_job->reply_payload.payload_len;
181 if (!len || len > FCP_PRIO_CFG_SIZE) {
182 ret = -EINVAL;
Johannes Thumshirn01e0e152016-11-17 10:31:12 +0100183 bsg_reply->result = (DID_ERROR << 16);
Sarang Radke09ff7012010-03-19 17:03:59 -0700184 goto exit_fcp_prio_cfg;
185 }
186
Johannes Thumshirn01e0e152016-11-17 10:31:12 +0100187 bsg_reply->result = DID_OK;
188 bsg_reply->reply_payload_rcv_len =
Sarang Radke09ff7012010-03-19 17:03:59 -0700189 sg_copy_from_buffer(
190 bsg_job->reply_payload.sg_list,
191 bsg_job->reply_payload.sg_cnt, ha->fcp_prio_cfg,
192 len);
193
194 break;
195
196 case QLFC_FCP_PRIO_SET_CONFIG:
197 len = bsg_job->request_payload.payload_len;
198 if (!len || len > FCP_PRIO_CFG_SIZE) {
Johannes Thumshirn01e0e152016-11-17 10:31:12 +0100199 bsg_reply->result = (DID_ERROR << 16);
Sarang Radke09ff7012010-03-19 17:03:59 -0700200 ret = -EINVAL;
201 goto exit_fcp_prio_cfg;
202 }
203
204 if (!ha->fcp_prio_cfg) {
205 ha->fcp_prio_cfg = vmalloc(FCP_PRIO_CFG_SIZE);
206 if (!ha->fcp_prio_cfg) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700207 ql_log(ql_log_warn, vha, 0x7050,
208 "Unable to allocate memory for fcp prio "
209 "config data (%x).\n", FCP_PRIO_CFG_SIZE);
Johannes Thumshirn01e0e152016-11-17 10:31:12 +0100210 bsg_reply->result = (DID_ERROR << 16);
Sarang Radke09ff7012010-03-19 17:03:59 -0700211 ret = -ENOMEM;
212 goto exit_fcp_prio_cfg;
213 }
214 }
215
216 memset(ha->fcp_prio_cfg, 0, FCP_PRIO_CFG_SIZE);
217 sg_copy_to_buffer(bsg_job->request_payload.sg_list,
218 bsg_job->request_payload.sg_cnt, ha->fcp_prio_cfg,
219 FCP_PRIO_CFG_SIZE);
220
221 /* validate fcp priority data */
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700222
223 if (!qla24xx_fcp_prio_cfg_valid(vha,
224 (struct qla_fcp_prio_cfg *) ha->fcp_prio_cfg, 1)) {
Johannes Thumshirn01e0e152016-11-17 10:31:12 +0100225 bsg_reply->result = (DID_ERROR << 16);
Sarang Radke09ff7012010-03-19 17:03:59 -0700226 ret = -EINVAL;
227 /* If buffer was invalidatic int
228 * fcp_prio_cfg is of no use
229 */
230 vfree(ha->fcp_prio_cfg);
231 ha->fcp_prio_cfg = NULL;
232 goto exit_fcp_prio_cfg;
233 }
234
235 ha->flags.fcp_prio_enabled = 0;
236 if (ha->fcp_prio_cfg->attributes & FCP_PRIO_ATTR_ENABLE)
237 ha->flags.fcp_prio_enabled = 1;
238 qla24xx_update_all_fcp_prio(vha);
Johannes Thumshirn01e0e152016-11-17 10:31:12 +0100239 bsg_reply->result = DID_OK;
Sarang Radke09ff7012010-03-19 17:03:59 -0700240 break;
241 default:
242 ret = -EINVAL;
243 break;
244 }
245exit_fcp_prio_cfg:
Armen Baloyan63ea9232012-11-21 02:39:53 -0500246 if (!ret)
Johannes Thumshirn06548162016-11-17 10:31:22 +0100247 bsg_job_done(bsg_job, bsg_reply->result,
Johannes Thumshirn1abaede2016-11-17 10:31:13 +0100248 bsg_reply->reply_payload_rcv_len);
Sarang Radke09ff7012010-03-19 17:03:59 -0700249 return ret;
250}
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800251
Giridhar Malavali6e980162010-03-19 17:03:58 -0700252static int
Johannes Thumshirn75cc8cf2016-11-17 10:31:19 +0100253qla2x00_process_els(struct bsg_job *bsg_job)
Giridhar Malavali6e980162010-03-19 17:03:58 -0700254{
Johannes Thumshirn01e0e152016-11-17 10:31:12 +0100255 struct fc_bsg_request *bsg_request = bsg_job->request;
Giridhar Malavali6e980162010-03-19 17:03:58 -0700256 struct fc_rport *rport;
Harish Zunjarrao08f71e02010-07-23 15:28:33 +0500257 fc_port_t *fcport = NULL;
Giridhar Malavali6e980162010-03-19 17:03:58 -0700258 struct Scsi_Host *host;
259 scsi_qla_host_t *vha;
260 struct qla_hw_data *ha;
261 srb_t *sp;
262 const char *type;
263 int req_sg_cnt, rsp_sg_cnt;
264 int rval = (DRIVER_ERROR << 16);
265 uint16_t nextlid = 0;
Giridhar Malavali6e980162010-03-19 17:03:58 -0700266
Johannes Thumshirn01e0e152016-11-17 10:31:12 +0100267 if (bsg_request->msgcode == FC_BSG_RPT_ELS) {
Johannes Thumshirn1d69b122016-11-17 10:31:15 +0100268 rport = fc_bsg_to_rport(bsg_job);
Harish Zunjarrao08f71e02010-07-23 15:28:33 +0500269 fcport = *(fc_port_t **) rport->dd_data;
270 host = rport_to_shost(rport);
271 vha = shost_priv(host);
272 ha = vha->hw;
273 type = "FC_BSG_RPT_ELS";
274 } else {
Johannes Thumshirncd21c602016-11-17 10:31:14 +0100275 host = fc_bsg_to_shost(bsg_job);
Harish Zunjarrao08f71e02010-07-23 15:28:33 +0500276 vha = shost_priv(host);
277 ha = vha->hw;
278 type = "FC_BSG_HST_ELS_NOLOGIN";
279 }
280
Bart Van Assche8c0eb592013-06-25 11:27:31 -0400281 if (!vha->flags.online) {
282 ql_log(ql_log_warn, vha, 0x7005, "Host not online.\n");
283 rval = -EIO;
284 goto done;
285 }
286
Harish Zunjarrao08f71e02010-07-23 15:28:33 +0500287 /* pass through is supported only for ISP 4Gb or higher */
288 if (!IS_FWI2_CAPABLE(ha)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700289 ql_dbg(ql_dbg_user, vha, 0x7001,
290 "ELS passthru not supported for ISP23xx based adapters.\n");
Harish Zunjarrao08f71e02010-07-23 15:28:33 +0500291 rval = -EPERM;
292 goto done;
293 }
294
Giridhar Malavali6e980162010-03-19 17:03:58 -0700295 /* Multiple SG's are not supported for ELS requests */
296 if (bsg_job->request_payload.sg_cnt > 1 ||
297 bsg_job->reply_payload.sg_cnt > 1) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700298 ql_dbg(ql_dbg_user, vha, 0x7002,
299 "Multiple SG's are not suppored for ELS requests, "
300 "request_sg_cnt=%x reply_sg_cnt=%x.\n",
301 bsg_job->request_payload.sg_cnt,
302 bsg_job->reply_payload.sg_cnt);
Giridhar Malavali6e980162010-03-19 17:03:58 -0700303 rval = -EPERM;
304 goto done;
305 }
306
307 /* ELS request for rport */
Johannes Thumshirn01e0e152016-11-17 10:31:12 +0100308 if (bsg_request->msgcode == FC_BSG_RPT_ELS) {
Giridhar Malavali6e980162010-03-19 17:03:58 -0700309 /* make sure the rport is logged in,
310 * if not perform fabric login
311 */
312 if (qla2x00_fabric_login(vha, fcport, &nextlid)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700313 ql_dbg(ql_dbg_user, vha, 0x7003,
314 "Failed to login port %06X for ELS passthru.\n",
315 fcport->d_id.b24);
Giridhar Malavali6e980162010-03-19 17:03:58 -0700316 rval = -EIO;
317 goto done;
318 }
319 } else {
Giridhar Malavali6e980162010-03-19 17:03:58 -0700320 /* Allocate a dummy fcport structure, since functions
321 * preparing the IOCB and mailbox command retrieves port
322 * specific information from fcport structure. For Host based
323 * ELS commands there will be no fcport structure allocated
324 */
325 fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
326 if (!fcport) {
327 rval = -ENOMEM;
328 goto done;
329 }
330
331 /* Initialize all required fields of fcport */
332 fcport->vha = vha;
Giridhar Malavali6e980162010-03-19 17:03:58 -0700333 fcport->d_id.b.al_pa =
Johannes Thumshirn01e0e152016-11-17 10:31:12 +0100334 bsg_request->rqst_data.h_els.port_id[0];
Giridhar Malavali6e980162010-03-19 17:03:58 -0700335 fcport->d_id.b.area =
Johannes Thumshirn01e0e152016-11-17 10:31:12 +0100336 bsg_request->rqst_data.h_els.port_id[1];
Giridhar Malavali6e980162010-03-19 17:03:58 -0700337 fcport->d_id.b.domain =
Johannes Thumshirn01e0e152016-11-17 10:31:12 +0100338 bsg_request->rqst_data.h_els.port_id[2];
Giridhar Malavali6e980162010-03-19 17:03:58 -0700339 fcport->loop_id =
340 (fcport->d_id.b.al_pa == 0xFD) ?
341 NPH_FABRIC_CONTROLLER : NPH_F_PORT;
342 }
343
Giridhar Malavali6e980162010-03-19 17:03:58 -0700344 req_sg_cnt =
345 dma_map_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
346 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
347 if (!req_sg_cnt) {
348 rval = -ENOMEM;
349 goto done_free_fcport;
350 }
Andrew Vasquez6c452a42010-03-19 17:04:02 -0700351
352 rsp_sg_cnt = dma_map_sg(&ha->pdev->dev, bsg_job->reply_payload.sg_list,
353 bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
Giridhar Malavali6e980162010-03-19 17:03:58 -0700354 if (!rsp_sg_cnt) {
355 rval = -ENOMEM;
356 goto done_free_fcport;
357 }
358
359 if ((req_sg_cnt != bsg_job->request_payload.sg_cnt) ||
Andrew Vasquez6c452a42010-03-19 17:04:02 -0700360 (rsp_sg_cnt != bsg_job->reply_payload.sg_cnt)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700361 ql_log(ql_log_warn, vha, 0x7008,
362 "dma mapping resulted in different sg counts, "
363 "request_sg_cnt: %x dma_request_sg_cnt:%x reply_sg_cnt:%x "
364 "dma_reply_sg_cnt:%x.\n", bsg_job->request_payload.sg_cnt,
365 req_sg_cnt, bsg_job->reply_payload.sg_cnt, rsp_sg_cnt);
Giridhar Malavali6e980162010-03-19 17:03:58 -0700366 rval = -EAGAIN;
367 goto done_unmap_sg;
368 }
369
370 /* Alloc SRB structure */
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800371 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
Giridhar Malavali6e980162010-03-19 17:03:58 -0700372 if (!sp) {
373 rval = -ENOMEM;
Andrew Vasquez6c452a42010-03-19 17:04:02 -0700374 goto done_unmap_sg;
Giridhar Malavali6e980162010-03-19 17:03:58 -0700375 }
376
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800377 sp->type =
Johannes Thumshirn01e0e152016-11-17 10:31:12 +0100378 (bsg_request->msgcode == FC_BSG_RPT_ELS ?
379 SRB_ELS_CMD_RPT : SRB_ELS_CMD_HST);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800380 sp->name =
Johannes Thumshirn01e0e152016-11-17 10:31:12 +0100381 (bsg_request->msgcode == FC_BSG_RPT_ELS ?
382 "bsg_els_rpt" : "bsg_els_hst");
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800383 sp->u.bsg_job = bsg_job;
384 sp->free = qla2x00_bsg_sp_free;
385 sp->done = qla2x00_bsg_job_done;
Giridhar Malavali6e980162010-03-19 17:03:58 -0700386
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700387 ql_dbg(ql_dbg_user, vha, 0x700a,
388 "bsg rqst type: %s els type: %x - loop-id=%x "
389 "portid=%-2x%02x%02x.\n", type,
Johannes Thumshirn01e0e152016-11-17 10:31:12 +0100390 bsg_request->rqst_data.h_els.command_code, fcport->loop_id,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700391 fcport->d_id.b.domain, fcport->d_id.b.area, fcport->d_id.b.al_pa);
Giridhar Malavali6e980162010-03-19 17:03:58 -0700392
393 rval = qla2x00_start_sp(sp);
394 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700395 ql_log(ql_log_warn, vha, 0x700e,
396 "qla2x00_start_sp failed = %d\n", rval);
Chad Dupuisb00ee7d2013-02-08 01:57:50 -0500397 qla2x00_rel_sp(vha, sp);
Giridhar Malavali6e980162010-03-19 17:03:58 -0700398 rval = -EIO;
399 goto done_unmap_sg;
400 }
401 return rval;
402
403done_unmap_sg:
404 dma_unmap_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
405 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
406 dma_unmap_sg(&ha->pdev->dev, bsg_job->reply_payload.sg_list,
407 bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
408 goto done_free_fcport;
409
410done_free_fcport:
Johannes Thumshirn01e0e152016-11-17 10:31:12 +0100411 if (bsg_request->msgcode == FC_BSG_RPT_ELS)
Giridhar Malavali6e980162010-03-19 17:03:58 -0700412 kfree(fcport);
413done:
414 return rval;
415}
416
Bart Van Assche2374dd22015-07-09 07:23:02 -0700417static inline uint16_t
Andrew Vasquez57807902011-11-18 09:03:20 -0800418qla24xx_calc_ct_iocbs(uint16_t dsds)
419{
420 uint16_t iocbs;
421
422 iocbs = 1;
423 if (dsds > 2) {
424 iocbs += (dsds - 2) / 5;
425 if ((dsds - 2) % 5)
426 iocbs++;
427 }
428 return iocbs;
429}
430
Giridhar Malavali6e980162010-03-19 17:03:58 -0700431static int
Johannes Thumshirn75cc8cf2016-11-17 10:31:19 +0100432qla2x00_process_ct(struct bsg_job *bsg_job)
Giridhar Malavali6e980162010-03-19 17:03:58 -0700433{
434 srb_t *sp;
Johannes Thumshirn01e0e152016-11-17 10:31:12 +0100435 struct fc_bsg_request *bsg_request = bsg_job->request;
Johannes Thumshirncd21c602016-11-17 10:31:14 +0100436 struct Scsi_Host *host = fc_bsg_to_shost(bsg_job);
Giridhar Malavali6e980162010-03-19 17:03:58 -0700437 scsi_qla_host_t *vha = shost_priv(host);
438 struct qla_hw_data *ha = vha->hw;
439 int rval = (DRIVER_ERROR << 16);
440 int req_sg_cnt, rsp_sg_cnt;
441 uint16_t loop_id;
442 struct fc_port *fcport;
443 char *type = "FC_BSG_HST_CT";
Giridhar Malavali6e980162010-03-19 17:03:58 -0700444
Giridhar Malavali6e980162010-03-19 17:03:58 -0700445 req_sg_cnt =
446 dma_map_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
447 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
Andrew Vasquez6c452a42010-03-19 17:04:02 -0700448 if (!req_sg_cnt) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700449 ql_log(ql_log_warn, vha, 0x700f,
450 "dma_map_sg return %d for request\n", req_sg_cnt);
Giridhar Malavali6e980162010-03-19 17:03:58 -0700451 rval = -ENOMEM;
452 goto done;
453 }
454
455 rsp_sg_cnt = dma_map_sg(&ha->pdev->dev, bsg_job->reply_payload.sg_list,
456 bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
457 if (!rsp_sg_cnt) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700458 ql_log(ql_log_warn, vha, 0x7010,
459 "dma_map_sg return %d for reply\n", rsp_sg_cnt);
Giridhar Malavali6e980162010-03-19 17:03:58 -0700460 rval = -ENOMEM;
461 goto done;
462 }
463
464 if ((req_sg_cnt != bsg_job->request_payload.sg_cnt) ||
Andrew Vasquez6c452a42010-03-19 17:04:02 -0700465 (rsp_sg_cnt != bsg_job->reply_payload.sg_cnt)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700466 ql_log(ql_log_warn, vha, 0x7011,
467 "request_sg_cnt: %x dma_request_sg_cnt: %x reply_sg_cnt:%x "
468 "dma_reply_sg_cnt: %x\n", bsg_job->request_payload.sg_cnt,
469 req_sg_cnt, bsg_job->reply_payload.sg_cnt, rsp_sg_cnt);
Giridhar Malavali6e980162010-03-19 17:03:58 -0700470 rval = -EAGAIN;
Andrew Vasquez6c452a42010-03-19 17:04:02 -0700471 goto done_unmap_sg;
Giridhar Malavali6e980162010-03-19 17:03:58 -0700472 }
473
474 if (!vha->flags.online) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700475 ql_log(ql_log_warn, vha, 0x7012,
476 "Host is not online.\n");
Giridhar Malavali6e980162010-03-19 17:03:58 -0700477 rval = -EIO;
478 goto done_unmap_sg;
479 }
480
481 loop_id =
Johannes Thumshirn01e0e152016-11-17 10:31:12 +0100482 (bsg_request->rqst_data.h_ct.preamble_word1 & 0xFF000000)
Giridhar Malavali6e980162010-03-19 17:03:58 -0700483 >> 24;
484 switch (loop_id) {
Andrew Vasquez6c452a42010-03-19 17:04:02 -0700485 case 0xFC:
486 loop_id = cpu_to_le16(NPH_SNS);
487 break;
488 case 0xFA:
489 loop_id = vha->mgmt_svr_loop_id;
490 break;
491 default:
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700492 ql_dbg(ql_dbg_user, vha, 0x7013,
493 "Unknown loop id: %x.\n", loop_id);
Andrew Vasquez6c452a42010-03-19 17:04:02 -0700494 rval = -EINVAL;
495 goto done_unmap_sg;
Giridhar Malavali6e980162010-03-19 17:03:58 -0700496 }
497
498 /* Allocate a dummy fcport structure, since functions preparing the
499 * IOCB and mailbox command retrieves port specific information
500 * from fcport structure. For Host based ELS commands there will be
501 * no fcport structure allocated
502 */
503 fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Andrew Vasquez6c452a42010-03-19 17:04:02 -0700504 if (!fcport) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700505 ql_log(ql_log_warn, vha, 0x7014,
506 "Failed to allocate fcport.\n");
Giridhar Malavali6e980162010-03-19 17:03:58 -0700507 rval = -ENOMEM;
Andrew Vasquez6c452a42010-03-19 17:04:02 -0700508 goto done_unmap_sg;
Giridhar Malavali6e980162010-03-19 17:03:58 -0700509 }
510
511 /* Initialize all required fields of fcport */
512 fcport->vha = vha;
Johannes Thumshirn01e0e152016-11-17 10:31:12 +0100513 fcport->d_id.b.al_pa = bsg_request->rqst_data.h_ct.port_id[0];
514 fcport->d_id.b.area = bsg_request->rqst_data.h_ct.port_id[1];
515 fcport->d_id.b.domain = bsg_request->rqst_data.h_ct.port_id[2];
Giridhar Malavali6e980162010-03-19 17:03:58 -0700516 fcport->loop_id = loop_id;
517
518 /* Alloc SRB structure */
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800519 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
Giridhar Malavali6e980162010-03-19 17:03:58 -0700520 if (!sp) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700521 ql_log(ql_log_warn, vha, 0x7015,
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800522 "qla2x00_get_sp failed.\n");
Giridhar Malavali6e980162010-03-19 17:03:58 -0700523 rval = -ENOMEM;
524 goto done_free_fcport;
525 }
526
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800527 sp->type = SRB_CT_CMD;
528 sp->name = "bsg_ct";
529 sp->iocbs = qla24xx_calc_ct_iocbs(req_sg_cnt + rsp_sg_cnt);
530 sp->u.bsg_job = bsg_job;
531 sp->free = qla2x00_bsg_sp_free;
532 sp->done = qla2x00_bsg_job_done;
Giridhar Malavali6e980162010-03-19 17:03:58 -0700533
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700534 ql_dbg(ql_dbg_user, vha, 0x7016,
535 "bsg rqst type: %s else type: %x - "
536 "loop-id=%x portid=%02x%02x%02x.\n", type,
Johannes Thumshirn01e0e152016-11-17 10:31:12 +0100537 (bsg_request->rqst_data.h_ct.preamble_word2 >> 16),
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700538 fcport->loop_id, fcport->d_id.b.domain, fcport->d_id.b.area,
539 fcport->d_id.b.al_pa);
Giridhar Malavali6e980162010-03-19 17:03:58 -0700540
541 rval = qla2x00_start_sp(sp);
542 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700543 ql_log(ql_log_warn, vha, 0x7017,
544 "qla2x00_start_sp failed=%d.\n", rval);
Chad Dupuisb00ee7d2013-02-08 01:57:50 -0500545 qla2x00_rel_sp(vha, sp);
Giridhar Malavali6e980162010-03-19 17:03:58 -0700546 rval = -EIO;
547 goto done_free_fcport;
548 }
549 return rval;
550
551done_free_fcport:
552 kfree(fcport);
553done_unmap_sg:
554 dma_unmap_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
555 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
556 dma_unmap_sg(&ha->pdev->dev, bsg_job->reply_payload.sg_list,
557 bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
558done:
559 return rval;
560}
Sarang Radke23f2ebd2010-05-28 15:08:21 -0700561
Chad Dupuis8fcd6b82012-08-22 14:21:06 -0400562/* Disable loopback mode */
Sarang Radke23f2ebd2010-05-28 15:08:21 -0700563static inline int
Chad Dupuis8fcd6b82012-08-22 14:21:06 -0400564qla81xx_reset_loopback_mode(scsi_qla_host_t *vha, uint16_t *config,
Chad Dupuisf356bef2013-02-08 01:58:04 -0500565 int wait, int wait2)
Sarang Radke23f2ebd2010-05-28 15:08:21 -0700566{
567 int ret = 0;
568 int rval = 0;
569 uint16_t new_config[4];
570 struct qla_hw_data *ha = vha->hw;
571
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -0400572 if (!IS_QLA81XX(ha) && !IS_QLA8031(ha) && !IS_QLA8044(ha))
Sarang Radke23f2ebd2010-05-28 15:08:21 -0700573 goto done_reset_internal;
574
575 memset(new_config, 0 , sizeof(new_config));
576 if ((config[0] & INTERNAL_LOOPBACK_MASK) >> 1 ==
Chad Dupuis8fcd6b82012-08-22 14:21:06 -0400577 ENABLE_INTERNAL_LOOPBACK ||
578 (config[0] & INTERNAL_LOOPBACK_MASK) >> 1 ==
579 ENABLE_EXTERNAL_LOOPBACK) {
Sarang Radke23f2ebd2010-05-28 15:08:21 -0700580 new_config[0] = config[0] & ~INTERNAL_LOOPBACK_MASK;
Chad Dupuis8fcd6b82012-08-22 14:21:06 -0400581 ql_dbg(ql_dbg_user, vha, 0x70bf, "new_config[0]=%02x\n",
582 (new_config[0] & INTERNAL_LOOPBACK_MASK));
Sarang Radke23f2ebd2010-05-28 15:08:21 -0700583 memcpy(&new_config[1], &config[1], sizeof(uint16_t) * 3) ;
584
585 ha->notify_dcbx_comp = wait;
Chad Dupuisf356bef2013-02-08 01:58:04 -0500586 ha->notify_lb_portup_comp = wait2;
587
Sarang Radke23f2ebd2010-05-28 15:08:21 -0700588 ret = qla81xx_set_port_config(vha, new_config);
589 if (ret != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700590 ql_log(ql_log_warn, vha, 0x7025,
591 "Set port config failed.\n");
Sarang Radke23f2ebd2010-05-28 15:08:21 -0700592 ha->notify_dcbx_comp = 0;
Chad Dupuisf356bef2013-02-08 01:58:04 -0500593 ha->notify_lb_portup_comp = 0;
Sarang Radke23f2ebd2010-05-28 15:08:21 -0700594 rval = -EINVAL;
595 goto done_reset_internal;
596 }
597
598 /* Wait for DCBX complete event */
599 if (wait && !wait_for_completion_timeout(&ha->dcbx_comp,
Chad Dupuisf356bef2013-02-08 01:58:04 -0500600 (DCBX_COMP_TIMEOUT * HZ))) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700601 ql_dbg(ql_dbg_user, vha, 0x7026,
Chad Dupuisf356bef2013-02-08 01:58:04 -0500602 "DCBX completion not received.\n");
Sarang Radke23f2ebd2010-05-28 15:08:21 -0700603 ha->notify_dcbx_comp = 0;
Chad Dupuisf356bef2013-02-08 01:58:04 -0500604 ha->notify_lb_portup_comp = 0;
Sarang Radke23f2ebd2010-05-28 15:08:21 -0700605 rval = -EINVAL;
606 goto done_reset_internal;
607 } else
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700608 ql_dbg(ql_dbg_user, vha, 0x7027,
Chad Dupuisf356bef2013-02-08 01:58:04 -0500609 "DCBX completion received.\n");
610
611 if (wait2 &&
612 !wait_for_completion_timeout(&ha->lb_portup_comp,
613 (LB_PORTUP_COMP_TIMEOUT * HZ))) {
614 ql_dbg(ql_dbg_user, vha, 0x70c5,
615 "Port up completion not received.\n");
616 ha->notify_lb_portup_comp = 0;
617 rval = -EINVAL;
618 goto done_reset_internal;
619 } else
620 ql_dbg(ql_dbg_user, vha, 0x70c6,
621 "Port up completion received.\n");
Sarang Radke23f2ebd2010-05-28 15:08:21 -0700622
623 ha->notify_dcbx_comp = 0;
Chad Dupuisf356bef2013-02-08 01:58:04 -0500624 ha->notify_lb_portup_comp = 0;
Sarang Radke23f2ebd2010-05-28 15:08:21 -0700625 }
626done_reset_internal:
627 return rval;
628}
629
Chad Dupuis67b2a312013-02-08 01:57:51 -0500630/*
631 * Set the port configuration to enable the internal or external loopback
632 * depending on the loopback mode.
633 */
634static inline int
635qla81xx_set_loopback_mode(scsi_qla_host_t *vha, uint16_t *config,
636 uint16_t *new_config, uint16_t mode)
637{
638 int ret = 0;
639 int rval = 0;
Santosh Vernekar454073c2013-08-27 01:37:48 -0400640 unsigned long rem_tmo = 0, current_tmo = 0;
Chad Dupuis67b2a312013-02-08 01:57:51 -0500641 struct qla_hw_data *ha = vha->hw;
642
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -0400643 if (!IS_QLA81XX(ha) && !IS_QLA8031(ha) && !IS_QLA8044(ha))
Chad Dupuis67b2a312013-02-08 01:57:51 -0500644 goto done_set_internal;
645
646 if (mode == INTERNAL_LOOPBACK)
647 new_config[0] = config[0] | (ENABLE_INTERNAL_LOOPBACK << 1);
648 else if (mode == EXTERNAL_LOOPBACK)
649 new_config[0] = config[0] | (ENABLE_EXTERNAL_LOOPBACK << 1);
650 ql_dbg(ql_dbg_user, vha, 0x70be,
651 "new_config[0]=%02x\n", (new_config[0] & INTERNAL_LOOPBACK_MASK));
652
653 memcpy(&new_config[1], &config[1], sizeof(uint16_t) * 3);
654
655 ha->notify_dcbx_comp = 1;
656 ret = qla81xx_set_port_config(vha, new_config);
657 if (ret != QLA_SUCCESS) {
658 ql_log(ql_log_warn, vha, 0x7021,
659 "set port config failed.\n");
660 ha->notify_dcbx_comp = 0;
661 rval = -EINVAL;
662 goto done_set_internal;
663 }
664
665 /* Wait for DCBX complete event */
Santosh Vernekar454073c2013-08-27 01:37:48 -0400666 current_tmo = DCBX_COMP_TIMEOUT * HZ;
667 while (1) {
668 rem_tmo = wait_for_completion_timeout(&ha->dcbx_comp,
669 current_tmo);
670 if (!ha->idc_extend_tmo || rem_tmo) {
671 ha->idc_extend_tmo = 0;
672 break;
673 }
674 current_tmo = ha->idc_extend_tmo * HZ;
675 ha->idc_extend_tmo = 0;
676 }
677
678 if (!rem_tmo) {
Chad Dupuis67b2a312013-02-08 01:57:51 -0500679 ql_dbg(ql_dbg_user, vha, 0x7022,
Chad Dupuisf356bef2013-02-08 01:58:04 -0500680 "DCBX completion not received.\n");
681 ret = qla81xx_reset_loopback_mode(vha, new_config, 0, 0);
Chad Dupuis67b2a312013-02-08 01:57:51 -0500682 /*
683 * If the reset of the loopback mode doesn't work take a FCoE
684 * dump and reset the chip.
685 */
686 if (ret) {
687 ha->isp_ops->fw_dump(vha, 0);
688 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
689 }
690 rval = -EINVAL;
691 } else {
692 if (ha->flags.idc_compl_status) {
693 ql_dbg(ql_dbg_user, vha, 0x70c3,
694 "Bad status in IDC Completion AEN\n");
695 rval = -EINVAL;
696 ha->flags.idc_compl_status = 0;
697 } else
698 ql_dbg(ql_dbg_user, vha, 0x7023,
Chad Dupuisf356bef2013-02-08 01:58:04 -0500699 "DCBX completion received.\n");
Chad Dupuis67b2a312013-02-08 01:57:51 -0500700 }
701
702 ha->notify_dcbx_comp = 0;
Santosh Vernekar454073c2013-08-27 01:37:48 -0400703 ha->idc_extend_tmo = 0;
Chad Dupuis67b2a312013-02-08 01:57:51 -0500704
705done_set_internal:
706 return rval;
707}
708
Giridhar Malavali6e980162010-03-19 17:03:58 -0700709static int
Johannes Thumshirn75cc8cf2016-11-17 10:31:19 +0100710qla2x00_process_loopback(struct bsg_job *bsg_job)
Giridhar Malavali6e980162010-03-19 17:03:58 -0700711{
Johannes Thumshirn01e0e152016-11-17 10:31:12 +0100712 struct fc_bsg_request *bsg_request = bsg_job->request;
713 struct fc_bsg_reply *bsg_reply = bsg_job->reply;
Johannes Thumshirncd21c602016-11-17 10:31:14 +0100714 struct Scsi_Host *host = fc_bsg_to_shost(bsg_job);
Giridhar Malavali6e980162010-03-19 17:03:58 -0700715 scsi_qla_host_t *vha = shost_priv(host);
716 struct qla_hw_data *ha = vha->hw;
717 int rval;
718 uint8_t command_sent;
719 char *type;
720 struct msg_echo_lb elreq;
721 uint16_t response[MAILBOX_REGISTER_COUNT];
Sarang Radke23f2ebd2010-05-28 15:08:21 -0700722 uint16_t config[4], new_config[4];
Andrew Vasquez6c452a42010-03-19 17:04:02 -0700723 uint8_t *fw_sts_ptr;
Giridhar Malavali6e980162010-03-19 17:03:58 -0700724 uint8_t *req_data = NULL;
725 dma_addr_t req_data_dma;
726 uint32_t req_data_len;
727 uint8_t *rsp_data = NULL;
728 dma_addr_t rsp_data_dma;
729 uint32_t rsp_data_len;
730
Giridhar Malavali6e980162010-03-19 17:03:58 -0700731 if (!vha->flags.online) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700732 ql_log(ql_log_warn, vha, 0x7019, "Host is not online.\n");
Giridhar Malavali6e980162010-03-19 17:03:58 -0700733 return -EIO;
734 }
735
736 elreq.req_sg_cnt = dma_map_sg(&ha->pdev->dev,
737 bsg_job->request_payload.sg_list, bsg_job->request_payload.sg_cnt,
738 DMA_TO_DEVICE);
739
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700740 if (!elreq.req_sg_cnt) {
741 ql_log(ql_log_warn, vha, 0x701a,
742 "dma_map_sg returned %d for request.\n", elreq.req_sg_cnt);
Giridhar Malavali6e980162010-03-19 17:03:58 -0700743 return -ENOMEM;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700744 }
Giridhar Malavali6e980162010-03-19 17:03:58 -0700745
746 elreq.rsp_sg_cnt = dma_map_sg(&ha->pdev->dev,
747 bsg_job->reply_payload.sg_list, bsg_job->reply_payload.sg_cnt,
748 DMA_FROM_DEVICE);
749
750 if (!elreq.rsp_sg_cnt) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700751 ql_log(ql_log_warn, vha, 0x701b,
752 "dma_map_sg returned %d for reply.\n", elreq.rsp_sg_cnt);
Giridhar Malavali6e980162010-03-19 17:03:58 -0700753 rval = -ENOMEM;
754 goto done_unmap_req_sg;
Andrew Vasquez6c452a42010-03-19 17:04:02 -0700755 }
Giridhar Malavali6e980162010-03-19 17:03:58 -0700756
757 if ((elreq.req_sg_cnt != bsg_job->request_payload.sg_cnt) ||
758 (elreq.rsp_sg_cnt != bsg_job->reply_payload.sg_cnt)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700759 ql_log(ql_log_warn, vha, 0x701c,
760 "dma mapping resulted in different sg counts, "
761 "request_sg_cnt: %x dma_request_sg_cnt: %x "
762 "reply_sg_cnt: %x dma_reply_sg_cnt: %x.\n",
763 bsg_job->request_payload.sg_cnt, elreq.req_sg_cnt,
764 bsg_job->reply_payload.sg_cnt, elreq.rsp_sg_cnt);
Giridhar Malavali6e980162010-03-19 17:03:58 -0700765 rval = -EAGAIN;
766 goto done_unmap_sg;
767 }
768 req_data_len = rsp_data_len = bsg_job->request_payload.payload_len;
769 req_data = dma_alloc_coherent(&ha->pdev->dev, req_data_len,
770 &req_data_dma, GFP_KERNEL);
771 if (!req_data) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700772 ql_log(ql_log_warn, vha, 0x701d,
773 "dma alloc failed for req_data.\n");
Giridhar Malavali6e980162010-03-19 17:03:58 -0700774 rval = -ENOMEM;
775 goto done_unmap_sg;
776 }
777
778 rsp_data = dma_alloc_coherent(&ha->pdev->dev, rsp_data_len,
779 &rsp_data_dma, GFP_KERNEL);
780 if (!rsp_data) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700781 ql_log(ql_log_warn, vha, 0x7004,
782 "dma alloc failed for rsp_data.\n");
Giridhar Malavali6e980162010-03-19 17:03:58 -0700783 rval = -ENOMEM;
784 goto done_free_dma_req;
785 }
786
787 /* Copy the request buffer in req_data now */
788 sg_copy_to_buffer(bsg_job->request_payload.sg_list,
789 bsg_job->request_payload.sg_cnt, req_data, req_data_len);
790
791 elreq.send_dma = req_data_dma;
792 elreq.rcv_dma = rsp_data_dma;
793 elreq.transfer_size = req_data_len;
794
Johannes Thumshirn01e0e152016-11-17 10:31:12 +0100795 elreq.options = bsg_request->rqst_data.h_vendor.vendor_cmd[1];
Joe Carnuccio1b98b422013-03-28 08:21:26 -0400796 elreq.iteration_count =
Johannes Thumshirn01e0e152016-11-17 10:31:12 +0100797 bsg_request->rqst_data.h_vendor.vendor_cmd[2];
Giridhar Malavali6e980162010-03-19 17:03:58 -0700798
Chad Dupuis8fcd6b82012-08-22 14:21:06 -0400799 if (atomic_read(&vha->loop_state) == LOOP_READY &&
800 (ha->current_topology == ISP_CFG_F ||
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -0400801 ((IS_QLA81XX(ha) || IS_QLA8031(ha) || IS_QLA8044(ha)) &&
Sarang Radke23f2ebd2010-05-28 15:08:21 -0700802 le32_to_cpu(*(uint32_t *)req_data) == ELS_OPCODE_BYTE
803 && req_data_len == MAX_ELS_FRAME_PAYLOAD)) &&
804 elreq.options == EXTERNAL_LOOPBACK) {
Giridhar Malavali6e980162010-03-19 17:03:58 -0700805 type = "FC_BSG_HST_VENDOR_ECHO_DIAG";
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700806 ql_dbg(ql_dbg_user, vha, 0x701e,
807 "BSG request type: %s.\n", type);
Giridhar Malavali6e980162010-03-19 17:03:58 -0700808 command_sent = INT_DEF_LB_ECHO_CMD;
809 rval = qla2x00_echo_test(vha, &elreq, response);
Sarang Radke23f2ebd2010-05-28 15:08:21 -0700810 } else {
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -0400811 if (IS_QLA81XX(ha) || IS_QLA8031(ha) || IS_QLA8044(ha)) {
Sarang Radke23f2ebd2010-05-28 15:08:21 -0700812 memset(config, 0, sizeof(config));
813 memset(new_config, 0, sizeof(new_config));
Chad Dupuisf356bef2013-02-08 01:58:04 -0500814
Sarang Radke23f2ebd2010-05-28 15:08:21 -0700815 if (qla81xx_get_port_config(vha, config)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700816 ql_log(ql_log_warn, vha, 0x701f,
817 "Get port config failed.\n");
Sarang Radke23f2ebd2010-05-28 15:08:21 -0700818 rval = -EPERM;
Steve Hodgson9bceab42012-11-21 02:39:56 -0500819 goto done_free_dma_rsp;
Sarang Radke23f2ebd2010-05-28 15:08:21 -0700820 }
821
Chad Dupuis1bcc46c2013-02-08 01:57:46 -0500822 if ((config[0] & INTERNAL_LOOPBACK_MASK) != 0) {
823 ql_dbg(ql_dbg_user, vha, 0x70c4,
824 "Loopback operation already in "
825 "progress.\n");
826 rval = -EAGAIN;
827 goto done_free_dma_rsp;
828 }
829
Chad Dupuis8fcd6b82012-08-22 14:21:06 -0400830 ql_dbg(ql_dbg_user, vha, 0x70c0,
831 "elreq.options=%04x\n", elreq.options);
832
833 if (elreq.options == EXTERNAL_LOOPBACK)
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -0400834 if (IS_QLA8031(ha) || IS_QLA8044(ha))
Chad Dupuis8fcd6b82012-08-22 14:21:06 -0400835 rval = qla81xx_set_loopback_mode(vha,
836 config, new_config, elreq.options);
837 else
838 rval = qla81xx_reset_loopback_mode(vha,
Chad Dupuisf356bef2013-02-08 01:58:04 -0500839 config, 1, 0);
Chad Dupuis8fcd6b82012-08-22 14:21:06 -0400840 else
841 rval = qla81xx_set_loopback_mode(vha, config,
842 new_config, elreq.options);
843
844 if (rval) {
Chad Dupuis8fcd6b82012-08-22 14:21:06 -0400845 rval = -EPERM;
Steve Hodgson9bceab42012-11-21 02:39:56 -0500846 goto done_free_dma_rsp;
Sarang Radke23f2ebd2010-05-28 15:08:21 -0700847 }
848
849 type = "FC_BSG_HST_VENDOR_LOOPBACK";
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700850 ql_dbg(ql_dbg_user, vha, 0x7028,
851 "BSG request type: %s.\n", type);
Sarang Radke23f2ebd2010-05-28 15:08:21 -0700852
853 command_sent = INT_DEF_LB_LOOPBACK_CMD;
854 rval = qla2x00_loopback_test(vha, &elreq, response);
855
Chad Dupuis992357c2013-02-08 01:57:52 -0500856 if (response[0] == MBS_COMMAND_ERROR &&
857 response[1] == MBS_LB_RESET) {
858 ql_log(ql_log_warn, vha, 0x7029,
859 "MBX command error, Aborting ISP.\n");
860 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
861 qla2xxx_wake_dpc(vha);
862 qla2x00_wait_for_chip_reset(vha);
863 /* Also reset the MPI */
864 if (IS_QLA81XX(ha)) {
865 if (qla81xx_restart_mpi_firmware(vha) !=
866 QLA_SUCCESS) {
867 ql_log(ql_log_warn, vha, 0x702a,
868 "MPI reset failed.\n");
869 }
870 }
871
872 rval = -EIO;
873 goto done_free_dma_rsp;
874 }
875
Joe Carnuccio4052bd52010-12-21 16:00:17 -0800876 if (new_config[0]) {
Chad Dupuis67b2a312013-02-08 01:57:51 -0500877 int ret;
878
Sarang Radke23f2ebd2010-05-28 15:08:21 -0700879 /* Revert back to original port config
880 * Also clear internal loopback
881 */
Chad Dupuis67b2a312013-02-08 01:57:51 -0500882 ret = qla81xx_reset_loopback_mode(vha,
Chad Dupuisf356bef2013-02-08 01:58:04 -0500883 new_config, 0, 1);
Chad Dupuis67b2a312013-02-08 01:57:51 -0500884 if (ret) {
885 /*
886 * If the reset of the loopback mode
887 * doesn't work take FCoE dump and then
888 * reset the chip.
889 */
890 ha->isp_ops->fw_dump(vha, 0);
891 set_bit(ISP_ABORT_NEEDED,
892 &vha->dpc_flags);
893 }
894
Sarang Radke23f2ebd2010-05-28 15:08:21 -0700895 }
896
Sarang Radke23f2ebd2010-05-28 15:08:21 -0700897 } else {
898 type = "FC_BSG_HST_VENDOR_LOOPBACK";
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700899 ql_dbg(ql_dbg_user, vha, 0x702b,
900 "BSG request type: %s.\n", type);
Sarang Radke23f2ebd2010-05-28 15:08:21 -0700901 command_sent = INT_DEF_LB_LOOPBACK_CMD;
902 rval = qla2x00_loopback_test(vha, &elreq, response);
903 }
Giridhar Malavali6e980162010-03-19 17:03:58 -0700904 }
905
906 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700907 ql_log(ql_log_warn, vha, 0x702c,
908 "Vendor request %s failed.\n", type);
Giridhar Malavali6e980162010-03-19 17:03:58 -0700909
Giridhar Malavali6e980162010-03-19 17:03:58 -0700910 rval = 0;
Johannes Thumshirn01e0e152016-11-17 10:31:12 +0100911 bsg_reply->result = (DID_ERROR << 16);
912 bsg_reply->reply_payload_rcv_len = 0;
Giridhar Malavali6e980162010-03-19 17:03:58 -0700913 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700914 ql_dbg(ql_dbg_user, vha, 0x702d,
915 "Vendor request %s completed.\n", type);
Johannes Thumshirn01e0e152016-11-17 10:31:12 +0100916 bsg_reply->result = (DID_OK << 16);
Giridhar Malavali6e980162010-03-19 17:03:58 -0700917 sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
918 bsg_job->reply_payload.sg_cnt, rsp_data,
919 rsp_data_len);
920 }
Armen Baloyan63ea9232012-11-21 02:39:53 -0500921
922 bsg_job->reply_len = sizeof(struct fc_bsg_reply) +
923 sizeof(response) + sizeof(uint8_t);
924 fw_sts_ptr = ((uint8_t *)bsg_job->req->sense) +
925 sizeof(struct fc_bsg_reply);
926 memcpy(fw_sts_ptr, response, sizeof(response));
927 fw_sts_ptr += sizeof(response);
928 *fw_sts_ptr = command_sent;
Giridhar Malavali6e980162010-03-19 17:03:58 -0700929
Steve Hodgson9bceab42012-11-21 02:39:56 -0500930done_free_dma_rsp:
Giridhar Malavali6e980162010-03-19 17:03:58 -0700931 dma_free_coherent(&ha->pdev->dev, rsp_data_len,
932 rsp_data, rsp_data_dma);
933done_free_dma_req:
934 dma_free_coherent(&ha->pdev->dev, req_data_len,
935 req_data, req_data_dma);
936done_unmap_sg:
937 dma_unmap_sg(&ha->pdev->dev,
938 bsg_job->reply_payload.sg_list,
939 bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
940done_unmap_req_sg:
941 dma_unmap_sg(&ha->pdev->dev,
942 bsg_job->request_payload.sg_list,
943 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
Armen Baloyan63ea9232012-11-21 02:39:53 -0500944 if (!rval)
Johannes Thumshirn06548162016-11-17 10:31:22 +0100945 bsg_job_done(bsg_job, bsg_reply->result,
Johannes Thumshirn1abaede2016-11-17 10:31:13 +0100946 bsg_reply->reply_payload_rcv_len);
Andrew Vasquez6c452a42010-03-19 17:04:02 -0700947 return rval;
Giridhar Malavali6e980162010-03-19 17:03:58 -0700948}
949
950static int
Johannes Thumshirn75cc8cf2016-11-17 10:31:19 +0100951qla84xx_reset(struct bsg_job *bsg_job)
Giridhar Malavali6e980162010-03-19 17:03:58 -0700952{
Johannes Thumshirn01e0e152016-11-17 10:31:12 +0100953 struct fc_bsg_request *bsg_request = bsg_job->request;
Johannes Thumshirncd21c602016-11-17 10:31:14 +0100954 struct Scsi_Host *host = fc_bsg_to_shost(bsg_job);
Johannes Thumshirn01e0e152016-11-17 10:31:12 +0100955 struct fc_bsg_reply *bsg_reply = bsg_job->reply;
Giridhar Malavali6e980162010-03-19 17:03:58 -0700956 scsi_qla_host_t *vha = shost_priv(host);
957 struct qla_hw_data *ha = vha->hw;
958 int rval = 0;
959 uint32_t flag;
960
Giridhar Malavali6e980162010-03-19 17:03:58 -0700961 if (!IS_QLA84XX(ha)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700962 ql_dbg(ql_dbg_user, vha, 0x702f, "Not 84xx, exiting.\n");
Giridhar Malavali6e980162010-03-19 17:03:58 -0700963 return -EINVAL;
964 }
965
Johannes Thumshirn01e0e152016-11-17 10:31:12 +0100966 flag = bsg_request->rqst_data.h_vendor.vendor_cmd[1];
Giridhar Malavali6e980162010-03-19 17:03:58 -0700967
968 rval = qla84xx_reset_chip(vha, flag == A84_ISSUE_RESET_DIAG_FW);
969
970 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700971 ql_log(ql_log_warn, vha, 0x7030,
972 "Vendor request 84xx reset failed.\n");
Armen Baloyan63ea9232012-11-21 02:39:53 -0500973 rval = (DID_ERROR << 16);
Giridhar Malavali6e980162010-03-19 17:03:58 -0700974
975 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700976 ql_dbg(ql_dbg_user, vha, 0x7031,
977 "Vendor request 84xx reset completed.\n");
Johannes Thumshirn01e0e152016-11-17 10:31:12 +0100978 bsg_reply->result = DID_OK;
Johannes Thumshirn06548162016-11-17 10:31:22 +0100979 bsg_job_done(bsg_job, bsg_reply->result,
Johannes Thumshirn1abaede2016-11-17 10:31:13 +0100980 bsg_reply->reply_payload_rcv_len);
Giridhar Malavali6e980162010-03-19 17:03:58 -0700981 }
982
Giridhar Malavali6e980162010-03-19 17:03:58 -0700983 return rval;
984}
985
986static int
Johannes Thumshirn75cc8cf2016-11-17 10:31:19 +0100987qla84xx_updatefw(struct bsg_job *bsg_job)
Giridhar Malavali6e980162010-03-19 17:03:58 -0700988{
Johannes Thumshirn01e0e152016-11-17 10:31:12 +0100989 struct fc_bsg_request *bsg_request = bsg_job->request;
990 struct fc_bsg_reply *bsg_reply = bsg_job->reply;
Johannes Thumshirncd21c602016-11-17 10:31:14 +0100991 struct Scsi_Host *host = fc_bsg_to_shost(bsg_job);
Giridhar Malavali6e980162010-03-19 17:03:58 -0700992 scsi_qla_host_t *vha = shost_priv(host);
993 struct qla_hw_data *ha = vha->hw;
994 struct verify_chip_entry_84xx *mn = NULL;
995 dma_addr_t mn_dma, fw_dma;
996 void *fw_buf = NULL;
997 int rval = 0;
998 uint32_t sg_cnt;
999 uint32_t data_len;
1000 uint16_t options;
1001 uint32_t flag;
1002 uint32_t fw_ver;
1003
Giridhar Malavali6e980162010-03-19 17:03:58 -07001004 if (!IS_QLA84XX(ha)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001005 ql_dbg(ql_dbg_user, vha, 0x7032,
1006 "Not 84xx, exiting.\n");
Giridhar Malavali6e980162010-03-19 17:03:58 -07001007 return -EINVAL;
1008 }
1009
1010 sg_cnt = dma_map_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
1011 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001012 if (!sg_cnt) {
1013 ql_log(ql_log_warn, vha, 0x7033,
1014 "dma_map_sg returned %d for request.\n", sg_cnt);
Giridhar Malavali6e980162010-03-19 17:03:58 -07001015 return -ENOMEM;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001016 }
Giridhar Malavali6e980162010-03-19 17:03:58 -07001017
1018 if (sg_cnt != bsg_job->request_payload.sg_cnt) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001019 ql_log(ql_log_warn, vha, 0x7034,
1020 "DMA mapping resulted in different sg counts, "
1021 "request_sg_cnt: %x dma_request_sg_cnt: %x.\n",
1022 bsg_job->request_payload.sg_cnt, sg_cnt);
Giridhar Malavali6e980162010-03-19 17:03:58 -07001023 rval = -EAGAIN;
1024 goto done_unmap_sg;
1025 }
1026
1027 data_len = bsg_job->request_payload.payload_len;
1028 fw_buf = dma_alloc_coherent(&ha->pdev->dev, data_len,
1029 &fw_dma, GFP_KERNEL);
1030 if (!fw_buf) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001031 ql_log(ql_log_warn, vha, 0x7035,
1032 "DMA alloc failed for fw_buf.\n");
Giridhar Malavali6e980162010-03-19 17:03:58 -07001033 rval = -ENOMEM;
1034 goto done_unmap_sg;
1035 }
1036
1037 sg_copy_to_buffer(bsg_job->request_payload.sg_list,
1038 bsg_job->request_payload.sg_cnt, fw_buf, data_len);
1039
1040 mn = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &mn_dma);
1041 if (!mn) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001042 ql_log(ql_log_warn, vha, 0x7036,
1043 "DMA alloc failed for fw buffer.\n");
Giridhar Malavali6e980162010-03-19 17:03:58 -07001044 rval = -ENOMEM;
1045 goto done_free_fw_buf;
1046 }
1047
Johannes Thumshirn01e0e152016-11-17 10:31:12 +01001048 flag = bsg_request->rqst_data.h_vendor.vendor_cmd[1];
Giridhar Malavali6e980162010-03-19 17:03:58 -07001049 fw_ver = le32_to_cpu(*((uint32_t *)((uint32_t *)fw_buf + 2)));
1050
1051 memset(mn, 0, sizeof(struct access_chip_84xx));
1052 mn->entry_type = VERIFY_CHIP_IOCB_TYPE;
1053 mn->entry_count = 1;
1054
1055 options = VCO_FORCE_UPDATE | VCO_END_OF_DATA;
1056 if (flag == A84_ISSUE_UPDATE_DIAGFW_CMD)
1057 options |= VCO_DIAG_FW;
1058
1059 mn->options = cpu_to_le16(options);
1060 mn->fw_ver = cpu_to_le32(fw_ver);
1061 mn->fw_size = cpu_to_le32(data_len);
1062 mn->fw_seq_size = cpu_to_le32(data_len);
1063 mn->dseg_address[0] = cpu_to_le32(LSD(fw_dma));
1064 mn->dseg_address[1] = cpu_to_le32(MSD(fw_dma));
1065 mn->dseg_length = cpu_to_le32(data_len);
1066 mn->data_seg_cnt = cpu_to_le16(1);
1067
1068 rval = qla2x00_issue_iocb_timeout(vha, mn, mn_dma, 0, 120);
1069
1070 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001071 ql_log(ql_log_warn, vha, 0x7037,
1072 "Vendor request 84xx updatefw failed.\n");
Giridhar Malavali6e980162010-03-19 17:03:58 -07001073
Armen Baloyan63ea9232012-11-21 02:39:53 -05001074 rval = (DID_ERROR << 16);
Giridhar Malavali6e980162010-03-19 17:03:58 -07001075 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001076 ql_dbg(ql_dbg_user, vha, 0x7038,
1077 "Vendor request 84xx updatefw completed.\n");
Giridhar Malavali6e980162010-03-19 17:03:58 -07001078
1079 bsg_job->reply_len = sizeof(struct fc_bsg_reply);
Johannes Thumshirn01e0e152016-11-17 10:31:12 +01001080 bsg_reply->result = DID_OK;
Giridhar Malavali6e980162010-03-19 17:03:58 -07001081 }
1082
Giridhar Malavali6e980162010-03-19 17:03:58 -07001083 dma_pool_free(ha->s_dma_pool, mn, mn_dma);
1084
1085done_free_fw_buf:
1086 dma_free_coherent(&ha->pdev->dev, data_len, fw_buf, fw_dma);
1087
1088done_unmap_sg:
1089 dma_unmap_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
1090 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
1091
Armen Baloyan63ea9232012-11-21 02:39:53 -05001092 if (!rval)
Johannes Thumshirn06548162016-11-17 10:31:22 +01001093 bsg_job_done(bsg_job, bsg_reply->result,
Johannes Thumshirn1abaede2016-11-17 10:31:13 +01001094 bsg_reply->reply_payload_rcv_len);
Giridhar Malavali6e980162010-03-19 17:03:58 -07001095 return rval;
1096}
1097
1098static int
Johannes Thumshirn75cc8cf2016-11-17 10:31:19 +01001099qla84xx_mgmt_cmd(struct bsg_job *bsg_job)
Giridhar Malavali6e980162010-03-19 17:03:58 -07001100{
Johannes Thumshirn01e0e152016-11-17 10:31:12 +01001101 struct fc_bsg_request *bsg_request = bsg_job->request;
1102 struct fc_bsg_reply *bsg_reply = bsg_job->reply;
Johannes Thumshirncd21c602016-11-17 10:31:14 +01001103 struct Scsi_Host *host = fc_bsg_to_shost(bsg_job);
Giridhar Malavali6e980162010-03-19 17:03:58 -07001104 scsi_qla_host_t *vha = shost_priv(host);
1105 struct qla_hw_data *ha = vha->hw;
1106 struct access_chip_84xx *mn = NULL;
1107 dma_addr_t mn_dma, mgmt_dma;
1108 void *mgmt_b = NULL;
1109 int rval = 0;
1110 struct qla_bsg_a84_mgmt *ql84_mgmt;
1111 uint32_t sg_cnt;
Harish Zunjarraod5459082010-03-19 17:04:00 -07001112 uint32_t data_len = 0;
Giridhar Malavali6e980162010-03-19 17:03:58 -07001113 uint32_t dma_direction = DMA_NONE;
1114
Giridhar Malavali6e980162010-03-19 17:03:58 -07001115 if (!IS_QLA84XX(ha)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001116 ql_log(ql_log_warn, vha, 0x703a,
1117 "Not 84xx, exiting.\n");
Giridhar Malavali6e980162010-03-19 17:03:58 -07001118 return -EINVAL;
1119 }
1120
Giridhar Malavali6e980162010-03-19 17:03:58 -07001121 mn = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &mn_dma);
1122 if (!mn) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001123 ql_log(ql_log_warn, vha, 0x703c,
1124 "DMA alloc failed for fw buffer.\n");
Giridhar Malavali6e980162010-03-19 17:03:58 -07001125 return -ENOMEM;
1126 }
1127
1128 memset(mn, 0, sizeof(struct access_chip_84xx));
1129 mn->entry_type = ACCESS_CHIP_IOCB_TYPE;
1130 mn->entry_count = 1;
Johannes Thumshirn01e0e152016-11-17 10:31:12 +01001131 ql84_mgmt = (void *)bsg_request + sizeof(struct fc_bsg_request);
Giridhar Malavali6e980162010-03-19 17:03:58 -07001132 switch (ql84_mgmt->mgmt.cmd) {
1133 case QLA84_MGMT_READ_MEM:
1134 case QLA84_MGMT_GET_INFO:
1135 sg_cnt = dma_map_sg(&ha->pdev->dev,
1136 bsg_job->reply_payload.sg_list,
1137 bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
1138 if (!sg_cnt) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001139 ql_log(ql_log_warn, vha, 0x703d,
1140 "dma_map_sg returned %d for reply.\n", sg_cnt);
Giridhar Malavali6e980162010-03-19 17:03:58 -07001141 rval = -ENOMEM;
1142 goto exit_mgmt;
1143 }
1144
1145 dma_direction = DMA_FROM_DEVICE;
1146
1147 if (sg_cnt != bsg_job->reply_payload.sg_cnt) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001148 ql_log(ql_log_warn, vha, 0x703e,
1149 "DMA mapping resulted in different sg counts, "
1150 "reply_sg_cnt: %x dma_reply_sg_cnt: %x.\n",
1151 bsg_job->reply_payload.sg_cnt, sg_cnt);
Giridhar Malavali6e980162010-03-19 17:03:58 -07001152 rval = -EAGAIN;
1153 goto done_unmap_sg;
1154 }
1155
1156 data_len = bsg_job->reply_payload.payload_len;
1157
1158 mgmt_b = dma_alloc_coherent(&ha->pdev->dev, data_len,
1159 &mgmt_dma, GFP_KERNEL);
1160 if (!mgmt_b) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001161 ql_log(ql_log_warn, vha, 0x703f,
1162 "DMA alloc failed for mgmt_b.\n");
Giridhar Malavali6e980162010-03-19 17:03:58 -07001163 rval = -ENOMEM;
1164 goto done_unmap_sg;
1165 }
1166
1167 if (ql84_mgmt->mgmt.cmd == QLA84_MGMT_READ_MEM) {
1168 mn->options = cpu_to_le16(ACO_DUMP_MEMORY);
1169 mn->parameter1 =
1170 cpu_to_le32(
1171 ql84_mgmt->mgmt.mgmtp.u.mem.start_addr);
1172
1173 } else if (ql84_mgmt->mgmt.cmd == QLA84_MGMT_GET_INFO) {
1174 mn->options = cpu_to_le16(ACO_REQUEST_INFO);
1175 mn->parameter1 =
1176 cpu_to_le32(ql84_mgmt->mgmt.mgmtp.u.info.type);
1177
1178 mn->parameter2 =
1179 cpu_to_le32(
1180 ql84_mgmt->mgmt.mgmtp.u.info.context);
1181 }
1182 break;
1183
1184 case QLA84_MGMT_WRITE_MEM:
1185 sg_cnt = dma_map_sg(&ha->pdev->dev,
1186 bsg_job->request_payload.sg_list,
1187 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
1188
1189 if (!sg_cnt) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001190 ql_log(ql_log_warn, vha, 0x7040,
1191 "dma_map_sg returned %d.\n", sg_cnt);
Giridhar Malavali6e980162010-03-19 17:03:58 -07001192 rval = -ENOMEM;
1193 goto exit_mgmt;
1194 }
1195
1196 dma_direction = DMA_TO_DEVICE;
1197
1198 if (sg_cnt != bsg_job->request_payload.sg_cnt) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001199 ql_log(ql_log_warn, vha, 0x7041,
1200 "DMA mapping resulted in different sg counts, "
1201 "request_sg_cnt: %x dma_request_sg_cnt: %x.\n",
1202 bsg_job->request_payload.sg_cnt, sg_cnt);
Giridhar Malavali6e980162010-03-19 17:03:58 -07001203 rval = -EAGAIN;
1204 goto done_unmap_sg;
1205 }
1206
1207 data_len = bsg_job->request_payload.payload_len;
1208 mgmt_b = dma_alloc_coherent(&ha->pdev->dev, data_len,
1209 &mgmt_dma, GFP_KERNEL);
1210 if (!mgmt_b) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001211 ql_log(ql_log_warn, vha, 0x7042,
1212 "DMA alloc failed for mgmt_b.\n");
Giridhar Malavali6e980162010-03-19 17:03:58 -07001213 rval = -ENOMEM;
1214 goto done_unmap_sg;
1215 }
1216
1217 sg_copy_to_buffer(bsg_job->request_payload.sg_list,
1218 bsg_job->request_payload.sg_cnt, mgmt_b, data_len);
1219
1220 mn->options = cpu_to_le16(ACO_LOAD_MEMORY);
1221 mn->parameter1 =
1222 cpu_to_le32(ql84_mgmt->mgmt.mgmtp.u.mem.start_addr);
1223 break;
1224
1225 case QLA84_MGMT_CHNG_CONFIG:
1226 mn->options = cpu_to_le16(ACO_CHANGE_CONFIG_PARAM);
1227 mn->parameter1 =
1228 cpu_to_le32(ql84_mgmt->mgmt.mgmtp.u.config.id);
1229
1230 mn->parameter2 =
1231 cpu_to_le32(ql84_mgmt->mgmt.mgmtp.u.config.param0);
1232
1233 mn->parameter3 =
1234 cpu_to_le32(ql84_mgmt->mgmt.mgmtp.u.config.param1);
1235 break;
1236
1237 default:
1238 rval = -EIO;
1239 goto exit_mgmt;
1240 }
1241
1242 if (ql84_mgmt->mgmt.cmd != QLA84_MGMT_CHNG_CONFIG) {
1243 mn->total_byte_cnt = cpu_to_le32(ql84_mgmt->mgmt.len);
1244 mn->dseg_count = cpu_to_le16(1);
1245 mn->dseg_address[0] = cpu_to_le32(LSD(mgmt_dma));
1246 mn->dseg_address[1] = cpu_to_le32(MSD(mgmt_dma));
1247 mn->dseg_length = cpu_to_le32(ql84_mgmt->mgmt.len);
1248 }
1249
1250 rval = qla2x00_issue_iocb(vha, mn, mn_dma, 0);
1251
1252 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001253 ql_log(ql_log_warn, vha, 0x7043,
1254 "Vendor request 84xx mgmt failed.\n");
Giridhar Malavali6e980162010-03-19 17:03:58 -07001255
Armen Baloyan63ea9232012-11-21 02:39:53 -05001256 rval = (DID_ERROR << 16);
Giridhar Malavali6e980162010-03-19 17:03:58 -07001257
1258 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001259 ql_dbg(ql_dbg_user, vha, 0x7044,
1260 "Vendor request 84xx mgmt completed.\n");
Giridhar Malavali6e980162010-03-19 17:03:58 -07001261
1262 bsg_job->reply_len = sizeof(struct fc_bsg_reply);
Johannes Thumshirn01e0e152016-11-17 10:31:12 +01001263 bsg_reply->result = DID_OK;
Giridhar Malavali6e980162010-03-19 17:03:58 -07001264
1265 if ((ql84_mgmt->mgmt.cmd == QLA84_MGMT_READ_MEM) ||
1266 (ql84_mgmt->mgmt.cmd == QLA84_MGMT_GET_INFO)) {
Johannes Thumshirn01e0e152016-11-17 10:31:12 +01001267 bsg_reply->reply_payload_rcv_len =
Giridhar Malavali6e980162010-03-19 17:03:58 -07001268 bsg_job->reply_payload.payload_len;
1269
1270 sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
Andrew Vasquez6c452a42010-03-19 17:04:02 -07001271 bsg_job->reply_payload.sg_cnt, mgmt_b,
1272 data_len);
Giridhar Malavali6e980162010-03-19 17:03:58 -07001273 }
1274 }
1275
Giridhar Malavali6e980162010-03-19 17:03:58 -07001276done_unmap_sg:
Harish Zunjarraod5459082010-03-19 17:04:00 -07001277 if (mgmt_b)
1278 dma_free_coherent(&ha->pdev->dev, data_len, mgmt_b, mgmt_dma);
1279
Giridhar Malavali6e980162010-03-19 17:03:58 -07001280 if (dma_direction == DMA_TO_DEVICE)
1281 dma_unmap_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
1282 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
1283 else if (dma_direction == DMA_FROM_DEVICE)
1284 dma_unmap_sg(&ha->pdev->dev, bsg_job->reply_payload.sg_list,
1285 bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
1286
1287exit_mgmt:
1288 dma_pool_free(ha->s_dma_pool, mn, mn_dma);
1289
Armen Baloyan63ea9232012-11-21 02:39:53 -05001290 if (!rval)
Johannes Thumshirn06548162016-11-17 10:31:22 +01001291 bsg_job_done(bsg_job, bsg_reply->result,
Johannes Thumshirn1abaede2016-11-17 10:31:13 +01001292 bsg_reply->reply_payload_rcv_len);
Giridhar Malavali6e980162010-03-19 17:03:58 -07001293 return rval;
1294}
1295
1296static int
Johannes Thumshirn75cc8cf2016-11-17 10:31:19 +01001297qla24xx_iidma(struct bsg_job *bsg_job)
Giridhar Malavali6e980162010-03-19 17:03:58 -07001298{
Johannes Thumshirn01e0e152016-11-17 10:31:12 +01001299 struct fc_bsg_request *bsg_request = bsg_job->request;
1300 struct fc_bsg_reply *bsg_reply = bsg_job->reply;
Johannes Thumshirncd21c602016-11-17 10:31:14 +01001301 struct Scsi_Host *host = fc_bsg_to_shost(bsg_job);
Giridhar Malavali6e980162010-03-19 17:03:58 -07001302 scsi_qla_host_t *vha = shost_priv(host);
Giridhar Malavali6e980162010-03-19 17:03:58 -07001303 int rval = 0;
1304 struct qla_port_param *port_param = NULL;
1305 fc_port_t *fcport = NULL;
Joe Carnuccioe8b8b8a2013-08-27 01:37:29 -04001306 int found = 0;
Giridhar Malavali6e980162010-03-19 17:03:58 -07001307 uint16_t mb[MAILBOX_REGISTER_COUNT];
1308 uint8_t *rsp_ptr = NULL;
1309
Giridhar Malavali6e980162010-03-19 17:03:58 -07001310 if (!IS_IIDMA_CAPABLE(vha->hw)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001311 ql_log(ql_log_info, vha, 0x7046, "iiDMA not supported.\n");
Giridhar Malavali6e980162010-03-19 17:03:58 -07001312 return -EINVAL;
1313 }
1314
Johannes Thumshirn01e0e152016-11-17 10:31:12 +01001315 port_param = (void *)bsg_request + sizeof(struct fc_bsg_request);
Giridhar Malavali6e980162010-03-19 17:03:58 -07001316 if (port_param->fc_scsi_addr.dest_type != EXT_DEF_TYPE_WWPN) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001317 ql_log(ql_log_warn, vha, 0x7048,
1318 "Invalid destination type.\n");
Giridhar Malavali6e980162010-03-19 17:03:58 -07001319 return -EINVAL;
1320 }
1321
1322 list_for_each_entry(fcport, &vha->vp_fcports, list) {
1323 if (fcport->port_type != FCT_TARGET)
1324 continue;
1325
1326 if (memcmp(port_param->fc_scsi_addr.dest_addr.wwpn,
1327 fcport->port_name, sizeof(fcport->port_name)))
1328 continue;
Joe Carnuccioe8b8b8a2013-08-27 01:37:29 -04001329
1330 found = 1;
Giridhar Malavali6e980162010-03-19 17:03:58 -07001331 break;
1332 }
1333
Joe Carnuccioe8b8b8a2013-08-27 01:37:29 -04001334 if (!found) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001335 ql_log(ql_log_warn, vha, 0x7049,
1336 "Failed to find port.\n");
Giridhar Malavali6e980162010-03-19 17:03:58 -07001337 return -EINVAL;
1338 }
1339
Giridhar Malavalic9afb9a2010-09-03 15:20:48 -07001340 if (atomic_read(&fcport->state) != FCS_ONLINE) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001341 ql_log(ql_log_warn, vha, 0x704a,
1342 "Port is not online.\n");
Madhuranath Iyengar17cf2c52010-07-23 15:28:22 +05001343 return -EINVAL;
1344 }
1345
Madhuranath Iyengar9a15eb42010-07-23 15:28:31 +05001346 if (fcport->flags & FCF_LOGIN_NEEDED) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001347 ql_log(ql_log_warn, vha, 0x704b,
1348 "Remote port not logged in flags = 0x%x.\n", fcport->flags);
Madhuranath Iyengar9a15eb42010-07-23 15:28:31 +05001349 return -EINVAL;
1350 }
1351
Giridhar Malavali6e980162010-03-19 17:03:58 -07001352 if (port_param->mode)
1353 rval = qla2x00_set_idma_speed(vha, fcport->loop_id,
1354 port_param->speed, mb);
1355 else
1356 rval = qla2x00_get_idma_speed(vha, fcport->loop_id,
1357 &port_param->speed, mb);
1358
1359 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001360 ql_log(ql_log_warn, vha, 0x704c,
Oleksandr Khoshaba7b833552013-08-27 01:37:27 -04001361 "iIDMA cmd failed for %8phN -- "
1362 "%04x %x %04x %04x.\n", fcport->port_name,
1363 rval, fcport->fp_speed, mb[0], mb[1]);
Armen Baloyan63ea9232012-11-21 02:39:53 -05001364 rval = (DID_ERROR << 16);
Giridhar Malavali6e980162010-03-19 17:03:58 -07001365 } else {
1366 if (!port_param->mode) {
1367 bsg_job->reply_len = sizeof(struct fc_bsg_reply) +
1368 sizeof(struct qla_port_param);
1369
Johannes Thumshirn01e0e152016-11-17 10:31:12 +01001370 rsp_ptr = ((uint8_t *)bsg_reply) +
Giridhar Malavali6e980162010-03-19 17:03:58 -07001371 sizeof(struct fc_bsg_reply);
1372
1373 memcpy(rsp_ptr, port_param,
1374 sizeof(struct qla_port_param));
1375 }
1376
Johannes Thumshirn01e0e152016-11-17 10:31:12 +01001377 bsg_reply->result = DID_OK;
Johannes Thumshirn06548162016-11-17 10:31:22 +01001378 bsg_job_done(bsg_job, bsg_reply->result,
Johannes Thumshirn1abaede2016-11-17 10:31:13 +01001379 bsg_reply->reply_payload_rcv_len);
Giridhar Malavali6e980162010-03-19 17:03:58 -07001380 }
1381
Giridhar Malavali6e980162010-03-19 17:03:58 -07001382 return rval;
1383}
1384
1385static int
Johannes Thumshirn75cc8cf2016-11-17 10:31:19 +01001386qla2x00_optrom_setup(struct bsg_job *bsg_job, scsi_qla_host_t *vha,
Harish Zunjarraof19af162010-10-15 11:27:43 -07001387 uint8_t is_update)
1388{
Johannes Thumshirn01e0e152016-11-17 10:31:12 +01001389 struct fc_bsg_request *bsg_request = bsg_job->request;
Harish Zunjarraof19af162010-10-15 11:27:43 -07001390 uint32_t start = 0;
1391 int valid = 0;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001392 struct qla_hw_data *ha = vha->hw;
Harish Zunjarraof19af162010-10-15 11:27:43 -07001393
Harish Zunjarraof19af162010-10-15 11:27:43 -07001394 if (unlikely(pci_channel_offline(ha->pdev)))
1395 return -EINVAL;
1396
Johannes Thumshirn01e0e152016-11-17 10:31:12 +01001397 start = bsg_request->rqst_data.h_vendor.vendor_cmd[1];
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001398 if (start > ha->optrom_size) {
1399 ql_log(ql_log_warn, vha, 0x7055,
1400 "start %d > optrom_size %d.\n", start, ha->optrom_size);
Harish Zunjarraof19af162010-10-15 11:27:43 -07001401 return -EINVAL;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001402 }
Harish Zunjarraof19af162010-10-15 11:27:43 -07001403
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001404 if (ha->optrom_state != QLA_SWAITING) {
1405 ql_log(ql_log_info, vha, 0x7056,
1406 "optrom_state %d.\n", ha->optrom_state);
Harish Zunjarraof19af162010-10-15 11:27:43 -07001407 return -EBUSY;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001408 }
Harish Zunjarraof19af162010-10-15 11:27:43 -07001409
1410 ha->optrom_region_start = start;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001411 ql_dbg(ql_dbg_user, vha, 0x7057, "is_update=%d.\n", is_update);
Harish Zunjarraof19af162010-10-15 11:27:43 -07001412 if (is_update) {
1413 if (ha->optrom_size == OPTROM_SIZE_2300 && start == 0)
1414 valid = 1;
1415 else if (start == (ha->flt_region_boot * 4) ||
1416 start == (ha->flt_region_fw * 4))
1417 valid = 1;
1418 else if (IS_QLA24XX_TYPE(ha) || IS_QLA25XX(ha) ||
Alex Vechersky9a6e6402014-09-25 05:16:58 -04001419 IS_CNA_CAPABLE(ha) || IS_QLA2031(ha) || IS_QLA27XX(ha))
Harish Zunjarraof19af162010-10-15 11:27:43 -07001420 valid = 1;
1421 if (!valid) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001422 ql_log(ql_log_warn, vha, 0x7058,
1423 "Invalid start region 0x%x/0x%x.\n", start,
1424 bsg_job->request_payload.payload_len);
Harish Zunjarraof19af162010-10-15 11:27:43 -07001425 return -EINVAL;
1426 }
1427
1428 ha->optrom_region_size = start +
1429 bsg_job->request_payload.payload_len > ha->optrom_size ?
1430 ha->optrom_size - start :
1431 bsg_job->request_payload.payload_len;
1432 ha->optrom_state = QLA_SWRITING;
1433 } else {
1434 ha->optrom_region_size = start +
1435 bsg_job->reply_payload.payload_len > ha->optrom_size ?
1436 ha->optrom_size - start :
1437 bsg_job->reply_payload.payload_len;
1438 ha->optrom_state = QLA_SREADING;
1439 }
1440
1441 ha->optrom_buffer = vmalloc(ha->optrom_region_size);
1442 if (!ha->optrom_buffer) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001443 ql_log(ql_log_warn, vha, 0x7059,
Harish Zunjarraof19af162010-10-15 11:27:43 -07001444 "Read: Unable to allocate memory for optrom retrieval "
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001445 "(%x)\n", ha->optrom_region_size);
Harish Zunjarraof19af162010-10-15 11:27:43 -07001446
1447 ha->optrom_state = QLA_SWAITING;
1448 return -ENOMEM;
1449 }
1450
1451 memset(ha->optrom_buffer, 0, ha->optrom_region_size);
1452 return 0;
1453}
1454
1455static int
Johannes Thumshirn75cc8cf2016-11-17 10:31:19 +01001456qla2x00_read_optrom(struct bsg_job *bsg_job)
Harish Zunjarraof19af162010-10-15 11:27:43 -07001457{
Johannes Thumshirn01e0e152016-11-17 10:31:12 +01001458 struct fc_bsg_reply *bsg_reply = bsg_job->reply;
Johannes Thumshirncd21c602016-11-17 10:31:14 +01001459 struct Scsi_Host *host = fc_bsg_to_shost(bsg_job);
Harish Zunjarraof19af162010-10-15 11:27:43 -07001460 scsi_qla_host_t *vha = shost_priv(host);
1461 struct qla_hw_data *ha = vha->hw;
1462 int rval = 0;
1463
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04001464 if (ha->flags.nic_core_reset_hdlr_active)
Giridhar Malavalia49393f2012-04-25 07:26:14 -07001465 return -EBUSY;
1466
Chad Dupuis7a8ab9c2014-02-26 04:14:56 -05001467 mutex_lock(&ha->optrom_mutex);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001468 rval = qla2x00_optrom_setup(bsg_job, vha, 0);
Chad Dupuis7a8ab9c2014-02-26 04:14:56 -05001469 if (rval) {
1470 mutex_unlock(&ha->optrom_mutex);
Harish Zunjarraof19af162010-10-15 11:27:43 -07001471 return rval;
Chad Dupuis7a8ab9c2014-02-26 04:14:56 -05001472 }
Harish Zunjarraof19af162010-10-15 11:27:43 -07001473
1474 ha->isp_ops->read_optrom(vha, ha->optrom_buffer,
1475 ha->optrom_region_start, ha->optrom_region_size);
1476
1477 sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
1478 bsg_job->reply_payload.sg_cnt, ha->optrom_buffer,
1479 ha->optrom_region_size);
1480
Johannes Thumshirn01e0e152016-11-17 10:31:12 +01001481 bsg_reply->reply_payload_rcv_len = ha->optrom_region_size;
1482 bsg_reply->result = DID_OK;
Harish Zunjarraof19af162010-10-15 11:27:43 -07001483 vfree(ha->optrom_buffer);
1484 ha->optrom_buffer = NULL;
1485 ha->optrom_state = QLA_SWAITING;
Chad Dupuis7a8ab9c2014-02-26 04:14:56 -05001486 mutex_unlock(&ha->optrom_mutex);
Johannes Thumshirn06548162016-11-17 10:31:22 +01001487 bsg_job_done(bsg_job, bsg_reply->result,
Johannes Thumshirn1abaede2016-11-17 10:31:13 +01001488 bsg_reply->reply_payload_rcv_len);
Harish Zunjarraof19af162010-10-15 11:27:43 -07001489 return rval;
1490}
1491
1492static int
Johannes Thumshirn75cc8cf2016-11-17 10:31:19 +01001493qla2x00_update_optrom(struct bsg_job *bsg_job)
Harish Zunjarraof19af162010-10-15 11:27:43 -07001494{
Johannes Thumshirn01e0e152016-11-17 10:31:12 +01001495 struct fc_bsg_reply *bsg_reply = bsg_job->reply;
Johannes Thumshirncd21c602016-11-17 10:31:14 +01001496 struct Scsi_Host *host = fc_bsg_to_shost(bsg_job);
Harish Zunjarraof19af162010-10-15 11:27:43 -07001497 scsi_qla_host_t *vha = shost_priv(host);
1498 struct qla_hw_data *ha = vha->hw;
1499 int rval = 0;
1500
Chad Dupuis7a8ab9c2014-02-26 04:14:56 -05001501 mutex_lock(&ha->optrom_mutex);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001502 rval = qla2x00_optrom_setup(bsg_job, vha, 1);
Chad Dupuis7a8ab9c2014-02-26 04:14:56 -05001503 if (rval) {
1504 mutex_unlock(&ha->optrom_mutex);
Harish Zunjarraof19af162010-10-15 11:27:43 -07001505 return rval;
Chad Dupuis7a8ab9c2014-02-26 04:14:56 -05001506 }
Harish Zunjarraof19af162010-10-15 11:27:43 -07001507
Giridhar Malavalib6d0d9d2012-05-15 14:34:25 -04001508 /* Set the isp82xx_no_md_cap not to capture minidump */
1509 ha->flags.isp82xx_no_md_cap = 1;
1510
Harish Zunjarraof19af162010-10-15 11:27:43 -07001511 sg_copy_to_buffer(bsg_job->request_payload.sg_list,
1512 bsg_job->request_payload.sg_cnt, ha->optrom_buffer,
1513 ha->optrom_region_size);
1514
1515 ha->isp_ops->write_optrom(vha, ha->optrom_buffer,
1516 ha->optrom_region_start, ha->optrom_region_size);
1517
Johannes Thumshirn01e0e152016-11-17 10:31:12 +01001518 bsg_reply->result = DID_OK;
Harish Zunjarraof19af162010-10-15 11:27:43 -07001519 vfree(ha->optrom_buffer);
1520 ha->optrom_buffer = NULL;
1521 ha->optrom_state = QLA_SWAITING;
Chad Dupuis7a8ab9c2014-02-26 04:14:56 -05001522 mutex_unlock(&ha->optrom_mutex);
Johannes Thumshirn06548162016-11-17 10:31:22 +01001523 bsg_job_done(bsg_job, bsg_reply->result,
Johannes Thumshirn1abaede2016-11-17 10:31:13 +01001524 bsg_reply->reply_payload_rcv_len);
Harish Zunjarraof19af162010-10-15 11:27:43 -07001525 return rval;
1526}
1527
1528static int
Johannes Thumshirn75cc8cf2016-11-17 10:31:19 +01001529qla2x00_update_fru_versions(struct bsg_job *bsg_job)
Joe Carnuccio697a4bc2011-08-16 11:31:52 -07001530{
Johannes Thumshirn01e0e152016-11-17 10:31:12 +01001531 struct fc_bsg_reply *bsg_reply = bsg_job->reply;
Johannes Thumshirncd21c602016-11-17 10:31:14 +01001532 struct Scsi_Host *host = fc_bsg_to_shost(bsg_job);
Joe Carnuccio697a4bc2011-08-16 11:31:52 -07001533 scsi_qla_host_t *vha = shost_priv(host);
1534 struct qla_hw_data *ha = vha->hw;
1535 int rval = 0;
1536 uint8_t bsg[DMA_POOL_SIZE];
1537 struct qla_image_version_list *list = (void *)bsg;
1538 struct qla_image_version *image;
1539 uint32_t count;
1540 dma_addr_t sfp_dma;
1541 void *sfp = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &sfp_dma);
1542 if (!sfp) {
Johannes Thumshirn01e0e152016-11-17 10:31:12 +01001543 bsg_reply->reply_data.vendor_reply.vendor_rsp[0] =
Joe Carnuccio697a4bc2011-08-16 11:31:52 -07001544 EXT_STATUS_NO_MEMORY;
1545 goto done;
1546 }
1547
1548 sg_copy_to_buffer(bsg_job->request_payload.sg_list,
1549 bsg_job->request_payload.sg_cnt, list, sizeof(bsg));
1550
1551 image = list->version;
1552 count = list->count;
1553 while (count--) {
1554 memcpy(sfp, &image->field_info, sizeof(image->field_info));
1555 rval = qla2x00_write_sfp(vha, sfp_dma, sfp,
1556 image->field_address.device, image->field_address.offset,
1557 sizeof(image->field_info), image->field_address.option);
1558 if (rval) {
Johannes Thumshirn01e0e152016-11-17 10:31:12 +01001559 bsg_reply->reply_data.vendor_reply.vendor_rsp[0] =
Joe Carnuccio697a4bc2011-08-16 11:31:52 -07001560 EXT_STATUS_MAILBOX;
1561 goto dealloc;
1562 }
1563 image++;
1564 }
1565
Johannes Thumshirn01e0e152016-11-17 10:31:12 +01001566 bsg_reply->reply_data.vendor_reply.vendor_rsp[0] = 0;
Joe Carnuccio697a4bc2011-08-16 11:31:52 -07001567
1568dealloc:
1569 dma_pool_free(ha->s_dma_pool, sfp, sfp_dma);
1570
1571done:
1572 bsg_job->reply_len = sizeof(struct fc_bsg_reply);
Johannes Thumshirn01e0e152016-11-17 10:31:12 +01001573 bsg_reply->result = DID_OK << 16;
Johannes Thumshirn06548162016-11-17 10:31:22 +01001574 bsg_job_done(bsg_job, bsg_reply->result,
Johannes Thumshirn1abaede2016-11-17 10:31:13 +01001575 bsg_reply->reply_payload_rcv_len);
Joe Carnuccio697a4bc2011-08-16 11:31:52 -07001576
1577 return 0;
1578}
1579
1580static int
Johannes Thumshirn75cc8cf2016-11-17 10:31:19 +01001581qla2x00_read_fru_status(struct bsg_job *bsg_job)
Joe Carnuccio697a4bc2011-08-16 11:31:52 -07001582{
Johannes Thumshirn01e0e152016-11-17 10:31:12 +01001583 struct fc_bsg_reply *bsg_reply = bsg_job->reply;
Johannes Thumshirncd21c602016-11-17 10:31:14 +01001584 struct Scsi_Host *host = fc_bsg_to_shost(bsg_job);
Joe Carnuccio697a4bc2011-08-16 11:31:52 -07001585 scsi_qla_host_t *vha = shost_priv(host);
1586 struct qla_hw_data *ha = vha->hw;
1587 int rval = 0;
1588 uint8_t bsg[DMA_POOL_SIZE];
1589 struct qla_status_reg *sr = (void *)bsg;
1590 dma_addr_t sfp_dma;
1591 uint8_t *sfp = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &sfp_dma);
1592 if (!sfp) {
Johannes Thumshirn01e0e152016-11-17 10:31:12 +01001593 bsg_reply->reply_data.vendor_reply.vendor_rsp[0] =
Joe Carnuccio697a4bc2011-08-16 11:31:52 -07001594 EXT_STATUS_NO_MEMORY;
1595 goto done;
1596 }
1597
1598 sg_copy_to_buffer(bsg_job->request_payload.sg_list,
1599 bsg_job->request_payload.sg_cnt, sr, sizeof(*sr));
1600
1601 rval = qla2x00_read_sfp(vha, sfp_dma, sfp,
1602 sr->field_address.device, sr->field_address.offset,
1603 sizeof(sr->status_reg), sr->field_address.option);
1604 sr->status_reg = *sfp;
1605
1606 if (rval) {
Johannes Thumshirn01e0e152016-11-17 10:31:12 +01001607 bsg_reply->reply_data.vendor_reply.vendor_rsp[0] =
Joe Carnuccio697a4bc2011-08-16 11:31:52 -07001608 EXT_STATUS_MAILBOX;
1609 goto dealloc;
1610 }
1611
1612 sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
1613 bsg_job->reply_payload.sg_cnt, sr, sizeof(*sr));
1614
Johannes Thumshirn01e0e152016-11-17 10:31:12 +01001615 bsg_reply->reply_data.vendor_reply.vendor_rsp[0] = 0;
Joe Carnuccio697a4bc2011-08-16 11:31:52 -07001616
1617dealloc:
1618 dma_pool_free(ha->s_dma_pool, sfp, sfp_dma);
1619
1620done:
1621 bsg_job->reply_len = sizeof(struct fc_bsg_reply);
Johannes Thumshirn01e0e152016-11-17 10:31:12 +01001622 bsg_reply->reply_payload_rcv_len = sizeof(*sr);
1623 bsg_reply->result = DID_OK << 16;
Johannes Thumshirn06548162016-11-17 10:31:22 +01001624 bsg_job_done(bsg_job, bsg_reply->result,
Johannes Thumshirn1abaede2016-11-17 10:31:13 +01001625 bsg_reply->reply_payload_rcv_len);
Joe Carnuccio697a4bc2011-08-16 11:31:52 -07001626
1627 return 0;
1628}
1629
1630static int
Johannes Thumshirn75cc8cf2016-11-17 10:31:19 +01001631qla2x00_write_fru_status(struct bsg_job *bsg_job)
Joe Carnuccio697a4bc2011-08-16 11:31:52 -07001632{
Johannes Thumshirn01e0e152016-11-17 10:31:12 +01001633 struct fc_bsg_reply *bsg_reply = bsg_job->reply;
Johannes Thumshirncd21c602016-11-17 10:31:14 +01001634 struct Scsi_Host *host = fc_bsg_to_shost(bsg_job);
Joe Carnuccio697a4bc2011-08-16 11:31:52 -07001635 scsi_qla_host_t *vha = shost_priv(host);
1636 struct qla_hw_data *ha = vha->hw;
1637 int rval = 0;
1638 uint8_t bsg[DMA_POOL_SIZE];
1639 struct qla_status_reg *sr = (void *)bsg;
1640 dma_addr_t sfp_dma;
1641 uint8_t *sfp = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &sfp_dma);
1642 if (!sfp) {
Johannes Thumshirn01e0e152016-11-17 10:31:12 +01001643 bsg_reply->reply_data.vendor_reply.vendor_rsp[0] =
Joe Carnuccio697a4bc2011-08-16 11:31:52 -07001644 EXT_STATUS_NO_MEMORY;
1645 goto done;
1646 }
1647
1648 sg_copy_to_buffer(bsg_job->request_payload.sg_list,
1649 bsg_job->request_payload.sg_cnt, sr, sizeof(*sr));
1650
1651 *sfp = sr->status_reg;
1652 rval = qla2x00_write_sfp(vha, sfp_dma, sfp,
1653 sr->field_address.device, sr->field_address.offset,
1654 sizeof(sr->status_reg), sr->field_address.option);
1655
1656 if (rval) {
Johannes Thumshirn01e0e152016-11-17 10:31:12 +01001657 bsg_reply->reply_data.vendor_reply.vendor_rsp[0] =
Joe Carnuccio697a4bc2011-08-16 11:31:52 -07001658 EXT_STATUS_MAILBOX;
1659 goto dealloc;
1660 }
1661
Johannes Thumshirn01e0e152016-11-17 10:31:12 +01001662 bsg_reply->reply_data.vendor_reply.vendor_rsp[0] = 0;
Joe Carnuccio697a4bc2011-08-16 11:31:52 -07001663
1664dealloc:
1665 dma_pool_free(ha->s_dma_pool, sfp, sfp_dma);
1666
1667done:
1668 bsg_job->reply_len = sizeof(struct fc_bsg_reply);
Johannes Thumshirn01e0e152016-11-17 10:31:12 +01001669 bsg_reply->result = DID_OK << 16;
Johannes Thumshirn06548162016-11-17 10:31:22 +01001670 bsg_job_done(bsg_job, bsg_reply->result,
Johannes Thumshirn1abaede2016-11-17 10:31:13 +01001671 bsg_reply->reply_payload_rcv_len);
Joe Carnuccio697a4bc2011-08-16 11:31:52 -07001672
1673 return 0;
1674}
1675
1676static int
Johannes Thumshirn75cc8cf2016-11-17 10:31:19 +01001677qla2x00_write_i2c(struct bsg_job *bsg_job)
Joe Carnuccio9ebb5d92012-08-22 14:20:56 -04001678{
Johannes Thumshirn01e0e152016-11-17 10:31:12 +01001679 struct fc_bsg_reply *bsg_reply = bsg_job->reply;
Johannes Thumshirncd21c602016-11-17 10:31:14 +01001680 struct Scsi_Host *host = fc_bsg_to_shost(bsg_job);
Joe Carnuccio9ebb5d92012-08-22 14:20:56 -04001681 scsi_qla_host_t *vha = shost_priv(host);
1682 struct qla_hw_data *ha = vha->hw;
1683 int rval = 0;
1684 uint8_t bsg[DMA_POOL_SIZE];
1685 struct qla_i2c_access *i2c = (void *)bsg;
1686 dma_addr_t sfp_dma;
1687 uint8_t *sfp = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &sfp_dma);
1688 if (!sfp) {
Johannes Thumshirn01e0e152016-11-17 10:31:12 +01001689 bsg_reply->reply_data.vendor_reply.vendor_rsp[0] =
Joe Carnuccio9ebb5d92012-08-22 14:20:56 -04001690 EXT_STATUS_NO_MEMORY;
1691 goto done;
1692 }
1693
1694 sg_copy_to_buffer(bsg_job->request_payload.sg_list,
1695 bsg_job->request_payload.sg_cnt, i2c, sizeof(*i2c));
1696
1697 memcpy(sfp, i2c->buffer, i2c->length);
1698 rval = qla2x00_write_sfp(vha, sfp_dma, sfp,
1699 i2c->device, i2c->offset, i2c->length, i2c->option);
1700
1701 if (rval) {
Johannes Thumshirn01e0e152016-11-17 10:31:12 +01001702 bsg_reply->reply_data.vendor_reply.vendor_rsp[0] =
Joe Carnuccio9ebb5d92012-08-22 14:20:56 -04001703 EXT_STATUS_MAILBOX;
1704 goto dealloc;
1705 }
1706
Johannes Thumshirn01e0e152016-11-17 10:31:12 +01001707 bsg_reply->reply_data.vendor_reply.vendor_rsp[0] = 0;
Joe Carnuccio9ebb5d92012-08-22 14:20:56 -04001708
1709dealloc:
1710 dma_pool_free(ha->s_dma_pool, sfp, sfp_dma);
1711
1712done:
1713 bsg_job->reply_len = sizeof(struct fc_bsg_reply);
Johannes Thumshirn01e0e152016-11-17 10:31:12 +01001714 bsg_reply->result = DID_OK << 16;
Johannes Thumshirn06548162016-11-17 10:31:22 +01001715 bsg_job_done(bsg_job, bsg_reply->result,
Johannes Thumshirn1abaede2016-11-17 10:31:13 +01001716 bsg_reply->reply_payload_rcv_len);
Joe Carnuccio9ebb5d92012-08-22 14:20:56 -04001717
1718 return 0;
1719}
1720
1721static int
Johannes Thumshirn75cc8cf2016-11-17 10:31:19 +01001722qla2x00_read_i2c(struct bsg_job *bsg_job)
Joe Carnuccio9ebb5d92012-08-22 14:20:56 -04001723{
Johannes Thumshirn01e0e152016-11-17 10:31:12 +01001724 struct fc_bsg_reply *bsg_reply = bsg_job->reply;
Johannes Thumshirncd21c602016-11-17 10:31:14 +01001725 struct Scsi_Host *host = fc_bsg_to_shost(bsg_job);
Joe Carnuccio9ebb5d92012-08-22 14:20:56 -04001726 scsi_qla_host_t *vha = shost_priv(host);
1727 struct qla_hw_data *ha = vha->hw;
1728 int rval = 0;
1729 uint8_t bsg[DMA_POOL_SIZE];
1730 struct qla_i2c_access *i2c = (void *)bsg;
1731 dma_addr_t sfp_dma;
1732 uint8_t *sfp = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &sfp_dma);
1733 if (!sfp) {
Johannes Thumshirn01e0e152016-11-17 10:31:12 +01001734 bsg_reply->reply_data.vendor_reply.vendor_rsp[0] =
Joe Carnuccio9ebb5d92012-08-22 14:20:56 -04001735 EXT_STATUS_NO_MEMORY;
1736 goto done;
1737 }
1738
1739 sg_copy_to_buffer(bsg_job->request_payload.sg_list,
1740 bsg_job->request_payload.sg_cnt, i2c, sizeof(*i2c));
1741
1742 rval = qla2x00_read_sfp(vha, sfp_dma, sfp,
1743 i2c->device, i2c->offset, i2c->length, i2c->option);
1744
1745 if (rval) {
Johannes Thumshirn01e0e152016-11-17 10:31:12 +01001746 bsg_reply->reply_data.vendor_reply.vendor_rsp[0] =
Joe Carnuccio9ebb5d92012-08-22 14:20:56 -04001747 EXT_STATUS_MAILBOX;
1748 goto dealloc;
1749 }
1750
1751 memcpy(i2c->buffer, sfp, i2c->length);
1752 sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
1753 bsg_job->reply_payload.sg_cnt, i2c, sizeof(*i2c));
1754
Johannes Thumshirn01e0e152016-11-17 10:31:12 +01001755 bsg_reply->reply_data.vendor_reply.vendor_rsp[0] = 0;
Joe Carnuccio9ebb5d92012-08-22 14:20:56 -04001756
1757dealloc:
1758 dma_pool_free(ha->s_dma_pool, sfp, sfp_dma);
1759
1760done:
1761 bsg_job->reply_len = sizeof(struct fc_bsg_reply);
Johannes Thumshirn01e0e152016-11-17 10:31:12 +01001762 bsg_reply->reply_payload_rcv_len = sizeof(*i2c);
1763 bsg_reply->result = DID_OK << 16;
Johannes Thumshirn06548162016-11-17 10:31:22 +01001764 bsg_job_done(bsg_job, bsg_reply->result,
Johannes Thumshirn1abaede2016-11-17 10:31:13 +01001765 bsg_reply->reply_payload_rcv_len);
Joe Carnuccio9ebb5d92012-08-22 14:20:56 -04001766
1767 return 0;
1768}
1769
1770static int
Johannes Thumshirn75cc8cf2016-11-17 10:31:19 +01001771qla24xx_process_bidir_cmd(struct bsg_job *bsg_job)
Saurav Kashyapa9b6f722012-08-22 14:21:01 -04001772{
Johannes Thumshirn01e0e152016-11-17 10:31:12 +01001773 struct fc_bsg_reply *bsg_reply = bsg_job->reply;
Johannes Thumshirncd21c602016-11-17 10:31:14 +01001774 struct Scsi_Host *host = fc_bsg_to_shost(bsg_job);
Saurav Kashyapa9b6f722012-08-22 14:21:01 -04001775 scsi_qla_host_t *vha = shost_priv(host);
1776 struct qla_hw_data *ha = vha->hw;
Saurav Kashyapa9b6f722012-08-22 14:21:01 -04001777 uint32_t rval = EXT_STATUS_OK;
1778 uint16_t req_sg_cnt = 0;
1779 uint16_t rsp_sg_cnt = 0;
1780 uint16_t nextlid = 0;
1781 uint32_t tot_dsds;
1782 srb_t *sp = NULL;
1783 uint32_t req_data_len = 0;
1784 uint32_t rsp_data_len = 0;
1785
1786 /* Check the type of the adapter */
1787 if (!IS_BIDI_CAPABLE(ha)) {
1788 ql_log(ql_log_warn, vha, 0x70a0,
1789 "This adapter is not supported\n");
1790 rval = EXT_STATUS_NOT_SUPPORTED;
1791 goto done;
1792 }
1793
1794 if (test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags) ||
1795 test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags) ||
1796 test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) {
1797 rval = EXT_STATUS_BUSY;
1798 goto done;
1799 }
1800
1801 /* Check if host is online */
1802 if (!vha->flags.online) {
1803 ql_log(ql_log_warn, vha, 0x70a1,
1804 "Host is not online\n");
1805 rval = EXT_STATUS_DEVICE_OFFLINE;
1806 goto done;
1807 }
1808
1809 /* Check if cable is plugged in or not */
1810 if (vha->device_flags & DFLG_NO_CABLE) {
1811 ql_log(ql_log_warn, vha, 0x70a2,
1812 "Cable is unplugged...\n");
1813 rval = EXT_STATUS_INVALID_CFG;
1814 goto done;
1815 }
1816
1817 /* Check if the switch is connected or not */
1818 if (ha->current_topology != ISP_CFG_F) {
1819 ql_log(ql_log_warn, vha, 0x70a3,
1820 "Host is not connected to the switch\n");
1821 rval = EXT_STATUS_INVALID_CFG;
1822 goto done;
1823 }
1824
1825 /* Check if operating mode is P2P */
1826 if (ha->operating_mode != P2P) {
1827 ql_log(ql_log_warn, vha, 0x70a4,
1828 "Host is operating mode is not P2p\n");
1829 rval = EXT_STATUS_INVALID_CFG;
1830 goto done;
1831 }
1832
Saurav Kashyapa9b6f722012-08-22 14:21:01 -04001833 mutex_lock(&ha->selflogin_lock);
1834 if (vha->self_login_loop_id == 0) {
1835 /* Initialize all required fields of fcport */
1836 vha->bidir_fcport.vha = vha;
1837 vha->bidir_fcport.d_id.b.al_pa = vha->d_id.b.al_pa;
1838 vha->bidir_fcport.d_id.b.area = vha->d_id.b.area;
1839 vha->bidir_fcport.d_id.b.domain = vha->d_id.b.domain;
1840 vha->bidir_fcport.loop_id = vha->loop_id;
1841
1842 if (qla2x00_fabric_login(vha, &(vha->bidir_fcport), &nextlid)) {
1843 ql_log(ql_log_warn, vha, 0x70a7,
1844 "Failed to login port %06X for bidirectional IOCB\n",
1845 vha->bidir_fcport.d_id.b24);
1846 mutex_unlock(&ha->selflogin_lock);
1847 rval = EXT_STATUS_MAILBOX;
1848 goto done;
1849 }
1850 vha->self_login_loop_id = nextlid - 1;
1851
1852 }
1853 /* Assign the self login loop id to fcport */
1854 mutex_unlock(&ha->selflogin_lock);
1855
1856 vha->bidir_fcport.loop_id = vha->self_login_loop_id;
1857
1858 req_sg_cnt = dma_map_sg(&ha->pdev->dev,
1859 bsg_job->request_payload.sg_list,
1860 bsg_job->request_payload.sg_cnt,
1861 DMA_TO_DEVICE);
1862
1863 if (!req_sg_cnt) {
1864 rval = EXT_STATUS_NO_MEMORY;
1865 goto done;
1866 }
1867
1868 rsp_sg_cnt = dma_map_sg(&ha->pdev->dev,
1869 bsg_job->reply_payload.sg_list, bsg_job->reply_payload.sg_cnt,
1870 DMA_FROM_DEVICE);
1871
1872 if (!rsp_sg_cnt) {
1873 rval = EXT_STATUS_NO_MEMORY;
1874 goto done_unmap_req_sg;
1875 }
1876
1877 if ((req_sg_cnt != bsg_job->request_payload.sg_cnt) ||
1878 (rsp_sg_cnt != bsg_job->reply_payload.sg_cnt)) {
1879 ql_dbg(ql_dbg_user, vha, 0x70a9,
1880 "Dma mapping resulted in different sg counts "
1881 "[request_sg_cnt: %x dma_request_sg_cnt: %x reply_sg_cnt: "
1882 "%x dma_reply_sg_cnt: %x]\n",
1883 bsg_job->request_payload.sg_cnt, req_sg_cnt,
1884 bsg_job->reply_payload.sg_cnt, rsp_sg_cnt);
1885 rval = EXT_STATUS_NO_MEMORY;
1886 goto done_unmap_sg;
1887 }
1888
1889 if (req_data_len != rsp_data_len) {
1890 rval = EXT_STATUS_BUSY;
1891 ql_log(ql_log_warn, vha, 0x70aa,
1892 "req_data_len != rsp_data_len\n");
1893 goto done_unmap_sg;
1894 }
1895
1896 req_data_len = bsg_job->request_payload.payload_len;
1897 rsp_data_len = bsg_job->reply_payload.payload_len;
1898
1899
1900 /* Alloc SRB structure */
1901 sp = qla2x00_get_sp(vha, &(vha->bidir_fcport), GFP_KERNEL);
1902 if (!sp) {
1903 ql_dbg(ql_dbg_user, vha, 0x70ac,
1904 "Alloc SRB structure failed\n");
1905 rval = EXT_STATUS_NO_MEMORY;
1906 goto done_unmap_sg;
1907 }
1908
1909 /*Populate srb->ctx with bidir ctx*/
1910 sp->u.bsg_job = bsg_job;
1911 sp->free = qla2x00_bsg_sp_free;
1912 sp->type = SRB_BIDI_CMD;
1913 sp->done = qla2x00_bsg_job_done;
1914
1915 /* Add the read and write sg count */
1916 tot_dsds = rsp_sg_cnt + req_sg_cnt;
1917
1918 rval = qla2x00_start_bidir(sp, vha, tot_dsds);
1919 if (rval != EXT_STATUS_OK)
1920 goto done_free_srb;
1921 /* the bsg request will be completed in the interrupt handler */
1922 return rval;
1923
1924done_free_srb:
1925 mempool_free(sp, ha->srb_mempool);
1926done_unmap_sg:
1927 dma_unmap_sg(&ha->pdev->dev,
1928 bsg_job->reply_payload.sg_list,
1929 bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
1930done_unmap_req_sg:
1931 dma_unmap_sg(&ha->pdev->dev,
1932 bsg_job->request_payload.sg_list,
1933 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
1934done:
1935
1936 /* Return an error vendor specific response
1937 * and complete the bsg request
1938 */
Johannes Thumshirn01e0e152016-11-17 10:31:12 +01001939 bsg_reply->reply_data.vendor_reply.vendor_rsp[0] = rval;
Saurav Kashyapa9b6f722012-08-22 14:21:01 -04001940 bsg_job->reply_len = sizeof(struct fc_bsg_reply);
Johannes Thumshirn01e0e152016-11-17 10:31:12 +01001941 bsg_reply->reply_payload_rcv_len = 0;
1942 bsg_reply->result = (DID_OK) << 16;
Johannes Thumshirn06548162016-11-17 10:31:22 +01001943 bsg_job_done(bsg_job, bsg_reply->result,
Johannes Thumshirn1abaede2016-11-17 10:31:13 +01001944 bsg_reply->reply_payload_rcv_len);
Joe Perches9e03aa22013-09-03 13:45:58 -07001945 /* Always return success, vendor rsp carries correct status */
Saurav Kashyapa9b6f722012-08-22 14:21:01 -04001946 return 0;
1947}
1948
1949static int
Johannes Thumshirn75cc8cf2016-11-17 10:31:19 +01001950qlafx00_mgmt_cmd(struct bsg_job *bsg_job)
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04001951{
Johannes Thumshirn01e0e152016-11-17 10:31:12 +01001952 struct fc_bsg_request *bsg_request = bsg_job->request;
Johannes Thumshirncd21c602016-11-17 10:31:14 +01001953 struct Scsi_Host *host = fc_bsg_to_shost(bsg_job);
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04001954 scsi_qla_host_t *vha = shost_priv(host);
1955 struct qla_hw_data *ha = vha->hw;
1956 int rval = (DRIVER_ERROR << 16);
1957 struct qla_mt_iocb_rqst_fx00 *piocb_rqst;
1958 srb_t *sp;
1959 int req_sg_cnt = 0, rsp_sg_cnt = 0;
1960 struct fc_port *fcport;
1961 char *type = "FC_BSG_HST_FX_MGMT";
1962
1963 /* Copy the IOCB specific information */
1964 piocb_rqst = (struct qla_mt_iocb_rqst_fx00 *)
Johannes Thumshirn01e0e152016-11-17 10:31:12 +01001965 &bsg_request->rqst_data.h_vendor.vendor_cmd[1];
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04001966
1967 /* Dump the vendor information */
1968 ql_dump_buffer(ql_dbg_user + ql_dbg_verbose , vha, 0x70cf,
1969 (uint8_t *)piocb_rqst, sizeof(struct qla_mt_iocb_rqst_fx00));
1970
1971 if (!vha->flags.online) {
1972 ql_log(ql_log_warn, vha, 0x70d0,
1973 "Host is not online.\n");
1974 rval = -EIO;
1975 goto done;
1976 }
1977
1978 if (piocb_rqst->flags & SRB_FXDISC_REQ_DMA_VALID) {
1979 req_sg_cnt = dma_map_sg(&ha->pdev->dev,
1980 bsg_job->request_payload.sg_list,
1981 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
1982 if (!req_sg_cnt) {
1983 ql_log(ql_log_warn, vha, 0x70c7,
1984 "dma_map_sg return %d for request\n", req_sg_cnt);
1985 rval = -ENOMEM;
1986 goto done;
1987 }
1988 }
1989
1990 if (piocb_rqst->flags & SRB_FXDISC_RESP_DMA_VALID) {
1991 rsp_sg_cnt = dma_map_sg(&ha->pdev->dev,
1992 bsg_job->reply_payload.sg_list,
1993 bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
1994 if (!rsp_sg_cnt) {
1995 ql_log(ql_log_warn, vha, 0x70c8,
1996 "dma_map_sg return %d for reply\n", rsp_sg_cnt);
1997 rval = -ENOMEM;
1998 goto done_unmap_req_sg;
1999 }
2000 }
2001
2002 ql_dbg(ql_dbg_user, vha, 0x70c9,
2003 "request_sg_cnt: %x dma_request_sg_cnt: %x reply_sg_cnt:%x "
2004 "dma_reply_sg_cnt: %x\n", bsg_job->request_payload.sg_cnt,
2005 req_sg_cnt, bsg_job->reply_payload.sg_cnt, rsp_sg_cnt);
2006
2007 /* Allocate a dummy fcport structure, since functions preparing the
2008 * IOCB and mailbox command retrieves port specific information
2009 * from fcport structure. For Host based ELS commands there will be
2010 * no fcport structure allocated
2011 */
2012 fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
2013 if (!fcport) {
2014 ql_log(ql_log_warn, vha, 0x70ca,
2015 "Failed to allocate fcport.\n");
2016 rval = -ENOMEM;
2017 goto done_unmap_rsp_sg;
2018 }
2019
2020 /* Alloc SRB structure */
2021 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
2022 if (!sp) {
2023 ql_log(ql_log_warn, vha, 0x70cb,
2024 "qla2x00_get_sp failed.\n");
2025 rval = -ENOMEM;
2026 goto done_free_fcport;
2027 }
2028
2029 /* Initialize all required fields of fcport */
2030 fcport->vha = vha;
2031 fcport->loop_id = piocb_rqst->dataword;
2032
2033 sp->type = SRB_FXIOCB_BCMD;
2034 sp->name = "bsg_fx_mgmt";
2035 sp->iocbs = qla24xx_calc_ct_iocbs(req_sg_cnt + rsp_sg_cnt);
2036 sp->u.bsg_job = bsg_job;
2037 sp->free = qla2x00_bsg_sp_free;
2038 sp->done = qla2x00_bsg_job_done;
2039
2040 ql_dbg(ql_dbg_user, vha, 0x70cc,
2041 "bsg rqst type: %s fx_mgmt_type: %x id=%x\n",
2042 type, piocb_rqst->func_type, fcport->loop_id);
2043
2044 rval = qla2x00_start_sp(sp);
2045 if (rval != QLA_SUCCESS) {
2046 ql_log(ql_log_warn, vha, 0x70cd,
2047 "qla2x00_start_sp failed=%d.\n", rval);
2048 mempool_free(sp, ha->srb_mempool);
2049 rval = -EIO;
2050 goto done_free_fcport;
2051 }
2052 return rval;
2053
2054done_free_fcport:
2055 kfree(fcport);
2056
2057done_unmap_rsp_sg:
2058 if (piocb_rqst->flags & SRB_FXDISC_RESP_DMA_VALID)
2059 dma_unmap_sg(&ha->pdev->dev,
2060 bsg_job->reply_payload.sg_list,
2061 bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
2062done_unmap_req_sg:
2063 if (piocb_rqst->flags & SRB_FXDISC_REQ_DMA_VALID)
2064 dma_unmap_sg(&ha->pdev->dev,
2065 bsg_job->request_payload.sg_list,
2066 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
2067
2068done:
2069 return rval;
2070}
2071
2072static int
Johannes Thumshirn75cc8cf2016-11-17 10:31:19 +01002073qla26xx_serdes_op(struct bsg_job *bsg_job)
Joe Carnucciodb64e932013-10-30 03:38:18 -04002074{
Johannes Thumshirn01e0e152016-11-17 10:31:12 +01002075 struct fc_bsg_reply *bsg_reply = bsg_job->reply;
Johannes Thumshirncd21c602016-11-17 10:31:14 +01002076 struct Scsi_Host *host = fc_bsg_to_shost(bsg_job);
Joe Carnucciodb64e932013-10-30 03:38:18 -04002077 scsi_qla_host_t *vha = shost_priv(host);
2078 int rval = 0;
2079 struct qla_serdes_reg sr;
2080
2081 memset(&sr, 0, sizeof(sr));
2082
2083 sg_copy_to_buffer(bsg_job->request_payload.sg_list,
2084 bsg_job->request_payload.sg_cnt, &sr, sizeof(sr));
2085
2086 switch (sr.cmd) {
2087 case INT_SC_SERDES_WRITE_REG:
2088 rval = qla2x00_write_serdes_word(vha, sr.addr, sr.val);
Johannes Thumshirn01e0e152016-11-17 10:31:12 +01002089 bsg_reply->reply_payload_rcv_len = 0;
Joe Carnucciodb64e932013-10-30 03:38:18 -04002090 break;
2091 case INT_SC_SERDES_READ_REG:
2092 rval = qla2x00_read_serdes_word(vha, sr.addr, &sr.val);
2093 sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
2094 bsg_job->reply_payload.sg_cnt, &sr, sizeof(sr));
Johannes Thumshirn01e0e152016-11-17 10:31:12 +01002095 bsg_reply->reply_payload_rcv_len = sizeof(sr);
Joe Carnucciodb64e932013-10-30 03:38:18 -04002096 break;
2097 default:
Joe Carnuccioe8887c52014-04-11 16:54:17 -04002098 ql_dbg(ql_dbg_user, vha, 0x708c,
Joe Carnucciodb64e932013-10-30 03:38:18 -04002099 "Unknown serdes cmd %x.\n", sr.cmd);
Joe Carnuccioe8887c52014-04-11 16:54:17 -04002100 rval = -EINVAL;
2101 break;
2102 }
2103
Johannes Thumshirn01e0e152016-11-17 10:31:12 +01002104 bsg_reply->reply_data.vendor_reply.vendor_rsp[0] =
Joe Carnuccioe8887c52014-04-11 16:54:17 -04002105 rval ? EXT_STATUS_MAILBOX : 0;
2106
2107 bsg_job->reply_len = sizeof(struct fc_bsg_reply);
Johannes Thumshirn01e0e152016-11-17 10:31:12 +01002108 bsg_reply->result = DID_OK << 16;
Johannes Thumshirn06548162016-11-17 10:31:22 +01002109 bsg_job_done(bsg_job, bsg_reply->result,
Johannes Thumshirn1abaede2016-11-17 10:31:13 +01002110 bsg_reply->reply_payload_rcv_len);
Joe Carnuccioe8887c52014-04-11 16:54:17 -04002111 return 0;
2112}
2113
2114static int
Johannes Thumshirn75cc8cf2016-11-17 10:31:19 +01002115qla8044_serdes_op(struct bsg_job *bsg_job)
Joe Carnuccioe8887c52014-04-11 16:54:17 -04002116{
Johannes Thumshirn01e0e152016-11-17 10:31:12 +01002117 struct fc_bsg_reply *bsg_reply = bsg_job->reply;
Johannes Thumshirncd21c602016-11-17 10:31:14 +01002118 struct Scsi_Host *host = fc_bsg_to_shost(bsg_job);
Joe Carnuccioe8887c52014-04-11 16:54:17 -04002119 scsi_qla_host_t *vha = shost_priv(host);
2120 int rval = 0;
2121 struct qla_serdes_reg_ex sr;
2122
2123 memset(&sr, 0, sizeof(sr));
2124
2125 sg_copy_to_buffer(bsg_job->request_payload.sg_list,
2126 bsg_job->request_payload.sg_cnt, &sr, sizeof(sr));
2127
2128 switch (sr.cmd) {
2129 case INT_SC_SERDES_WRITE_REG:
2130 rval = qla8044_write_serdes_word(vha, sr.addr, sr.val);
Johannes Thumshirn01e0e152016-11-17 10:31:12 +01002131 bsg_reply->reply_payload_rcv_len = 0;
Joe Carnuccioe8887c52014-04-11 16:54:17 -04002132 break;
2133 case INT_SC_SERDES_READ_REG:
2134 rval = qla8044_read_serdes_word(vha, sr.addr, &sr.val);
2135 sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
2136 bsg_job->reply_payload.sg_cnt, &sr, sizeof(sr));
Johannes Thumshirn01e0e152016-11-17 10:31:12 +01002137 bsg_reply->reply_payload_rcv_len = sizeof(sr);
Joe Carnuccioe8887c52014-04-11 16:54:17 -04002138 break;
2139 default:
2140 ql_dbg(ql_dbg_user, vha, 0x70cf,
2141 "Unknown serdes cmd %x.\n", sr.cmd);
2142 rval = -EINVAL;
Joe Carnucciodb64e932013-10-30 03:38:18 -04002143 break;
2144 }
2145
Johannes Thumshirn01e0e152016-11-17 10:31:12 +01002146 bsg_reply->reply_data.vendor_reply.vendor_rsp[0] =
Joe Carnucciodb64e932013-10-30 03:38:18 -04002147 rval ? EXT_STATUS_MAILBOX : 0;
2148
2149 bsg_job->reply_len = sizeof(struct fc_bsg_reply);
Johannes Thumshirn01e0e152016-11-17 10:31:12 +01002150 bsg_reply->result = DID_OK << 16;
Johannes Thumshirn06548162016-11-17 10:31:22 +01002151 bsg_job_done(bsg_job, bsg_reply->result,
Johannes Thumshirn1abaede2016-11-17 10:31:13 +01002152 bsg_reply->reply_payload_rcv_len);
Joe Carnucciodb64e932013-10-30 03:38:18 -04002153 return 0;
2154}
2155
2156static int
Johannes Thumshirn75cc8cf2016-11-17 10:31:19 +01002157qla27xx_get_flash_upd_cap(struct bsg_job *bsg_job)
Sawan Chandak4243c112016-01-27 12:03:31 -05002158{
Johannes Thumshirn01e0e152016-11-17 10:31:12 +01002159 struct fc_bsg_reply *bsg_reply = bsg_job->reply;
Johannes Thumshirncd21c602016-11-17 10:31:14 +01002160 struct Scsi_Host *host = fc_bsg_to_shost(bsg_job);
Sawan Chandak4243c112016-01-27 12:03:31 -05002161 scsi_qla_host_t *vha = shost_priv(host);
2162 struct qla_hw_data *ha = vha->hw;
2163 struct qla_flash_update_caps cap;
2164
2165 if (!(IS_QLA27XX(ha)))
2166 return -EPERM;
2167
2168 memset(&cap, 0, sizeof(cap));
2169 cap.capabilities = (uint64_t)ha->fw_attributes_ext[1] << 48 |
2170 (uint64_t)ha->fw_attributes_ext[0] << 32 |
2171 (uint64_t)ha->fw_attributes_h << 16 |
2172 (uint64_t)ha->fw_attributes;
2173
2174 sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
2175 bsg_job->reply_payload.sg_cnt, &cap, sizeof(cap));
Johannes Thumshirn01e0e152016-11-17 10:31:12 +01002176 bsg_reply->reply_payload_rcv_len = sizeof(cap);
Sawan Chandak4243c112016-01-27 12:03:31 -05002177
Johannes Thumshirn01e0e152016-11-17 10:31:12 +01002178 bsg_reply->reply_data.vendor_reply.vendor_rsp[0] =
Sawan Chandak4243c112016-01-27 12:03:31 -05002179 EXT_STATUS_OK;
2180
2181 bsg_job->reply_len = sizeof(struct fc_bsg_reply);
Johannes Thumshirn01e0e152016-11-17 10:31:12 +01002182 bsg_reply->result = DID_OK << 16;
Johannes Thumshirn06548162016-11-17 10:31:22 +01002183 bsg_job_done(bsg_job, bsg_reply->result,
Johannes Thumshirn1abaede2016-11-17 10:31:13 +01002184 bsg_reply->reply_payload_rcv_len);
Sawan Chandak4243c112016-01-27 12:03:31 -05002185 return 0;
2186}
2187
2188static int
Johannes Thumshirn75cc8cf2016-11-17 10:31:19 +01002189qla27xx_set_flash_upd_cap(struct bsg_job *bsg_job)
Sawan Chandak4243c112016-01-27 12:03:31 -05002190{
Johannes Thumshirn01e0e152016-11-17 10:31:12 +01002191 struct fc_bsg_reply *bsg_reply = bsg_job->reply;
Johannes Thumshirncd21c602016-11-17 10:31:14 +01002192 struct Scsi_Host *host = fc_bsg_to_shost(bsg_job);
Sawan Chandak4243c112016-01-27 12:03:31 -05002193 scsi_qla_host_t *vha = shost_priv(host);
2194 struct qla_hw_data *ha = vha->hw;
2195 uint64_t online_fw_attr = 0;
2196 struct qla_flash_update_caps cap;
2197
2198 if (!(IS_QLA27XX(ha)))
2199 return -EPERM;
2200
2201 memset(&cap, 0, sizeof(cap));
2202 sg_copy_to_buffer(bsg_job->request_payload.sg_list,
2203 bsg_job->request_payload.sg_cnt, &cap, sizeof(cap));
2204
2205 online_fw_attr = (uint64_t)ha->fw_attributes_ext[1] << 48 |
2206 (uint64_t)ha->fw_attributes_ext[0] << 32 |
2207 (uint64_t)ha->fw_attributes_h << 16 |
2208 (uint64_t)ha->fw_attributes;
2209
2210 if (online_fw_attr != cap.capabilities) {
Johannes Thumshirn01e0e152016-11-17 10:31:12 +01002211 bsg_reply->reply_data.vendor_reply.vendor_rsp[0] =
Sawan Chandak4243c112016-01-27 12:03:31 -05002212 EXT_STATUS_INVALID_PARAM;
2213 return -EINVAL;
2214 }
2215
2216 if (cap.outage_duration < MAX_LOOP_TIMEOUT) {
Johannes Thumshirn01e0e152016-11-17 10:31:12 +01002217 bsg_reply->reply_data.vendor_reply.vendor_rsp[0] =
Sawan Chandak4243c112016-01-27 12:03:31 -05002218 EXT_STATUS_INVALID_PARAM;
2219 return -EINVAL;
2220 }
2221
Johannes Thumshirn01e0e152016-11-17 10:31:12 +01002222 bsg_reply->reply_payload_rcv_len = 0;
Sawan Chandak4243c112016-01-27 12:03:31 -05002223
Johannes Thumshirn01e0e152016-11-17 10:31:12 +01002224 bsg_reply->reply_data.vendor_reply.vendor_rsp[0] =
Sawan Chandak4243c112016-01-27 12:03:31 -05002225 EXT_STATUS_OK;
2226
2227 bsg_job->reply_len = sizeof(struct fc_bsg_reply);
Johannes Thumshirn01e0e152016-11-17 10:31:12 +01002228 bsg_reply->result = DID_OK << 16;
Johannes Thumshirn06548162016-11-17 10:31:22 +01002229 bsg_job_done(bsg_job, bsg_reply->result,
Johannes Thumshirn1abaede2016-11-17 10:31:13 +01002230 bsg_reply->reply_payload_rcv_len);
Sawan Chandak4243c112016-01-27 12:03:31 -05002231 return 0;
2232}
2233
2234static int
Johannes Thumshirn75cc8cf2016-11-17 10:31:19 +01002235qla27xx_get_bbcr_data(struct bsg_job *bsg_job)
Sawan Chandak969a6192016-01-27 12:03:32 -05002236{
Johannes Thumshirn01e0e152016-11-17 10:31:12 +01002237 struct fc_bsg_reply *bsg_reply = bsg_job->reply;
Johannes Thumshirncd21c602016-11-17 10:31:14 +01002238 struct Scsi_Host *host = fc_bsg_to_shost(bsg_job);
Sawan Chandak969a6192016-01-27 12:03:32 -05002239 scsi_qla_host_t *vha = shost_priv(host);
2240 struct qla_hw_data *ha = vha->hw;
2241 struct qla_bbcr_data bbcr;
2242 uint16_t loop_id, topo, sw_cap;
2243 uint8_t domain, area, al_pa, state;
2244 int rval;
2245
2246 if (!(IS_QLA27XX(ha)))
2247 return -EPERM;
2248
2249 memset(&bbcr, 0, sizeof(bbcr));
2250
2251 if (vha->flags.bbcr_enable)
2252 bbcr.status = QLA_BBCR_STATUS_ENABLED;
2253 else
2254 bbcr.status = QLA_BBCR_STATUS_DISABLED;
2255
2256 if (bbcr.status == QLA_BBCR_STATUS_ENABLED) {
2257 rval = qla2x00_get_adapter_id(vha, &loop_id, &al_pa,
2258 &area, &domain, &topo, &sw_cap);
Harish Zunjarraoc73191b2016-01-27 12:03:35 -05002259 if (rval != QLA_SUCCESS) {
2260 bbcr.status = QLA_BBCR_STATUS_UNKNOWN;
2261 bbcr.state = QLA_BBCR_STATE_OFFLINE;
2262 bbcr.mbx1 = loop_id;
2263 goto done;
2264 }
Sawan Chandak969a6192016-01-27 12:03:32 -05002265
2266 state = (vha->bbcr >> 12) & 0x1;
2267
2268 if (state) {
2269 bbcr.state = QLA_BBCR_STATE_OFFLINE;
2270 bbcr.offline_reason_code = QLA_BBCR_REASON_LOGIN_REJECT;
2271 } else {
2272 bbcr.state = QLA_BBCR_STATE_ONLINE;
2273 bbcr.negotiated_bbscn = (vha->bbcr >> 8) & 0xf;
2274 }
2275
2276 bbcr.configured_bbscn = vha->bbcr & 0xf;
2277 }
2278
Harish Zunjarraoc73191b2016-01-27 12:03:35 -05002279done:
Sawan Chandak969a6192016-01-27 12:03:32 -05002280 sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
2281 bsg_job->reply_payload.sg_cnt, &bbcr, sizeof(bbcr));
Johannes Thumshirn01e0e152016-11-17 10:31:12 +01002282 bsg_reply->reply_payload_rcv_len = sizeof(bbcr);
Sawan Chandak969a6192016-01-27 12:03:32 -05002283
Johannes Thumshirn01e0e152016-11-17 10:31:12 +01002284 bsg_reply->reply_data.vendor_reply.vendor_rsp[0] = EXT_STATUS_OK;
Sawan Chandak969a6192016-01-27 12:03:32 -05002285
2286 bsg_job->reply_len = sizeof(struct fc_bsg_reply);
Johannes Thumshirn01e0e152016-11-17 10:31:12 +01002287 bsg_reply->result = DID_OK << 16;
Johannes Thumshirn06548162016-11-17 10:31:22 +01002288 bsg_job_done(bsg_job, bsg_reply->result,
Johannes Thumshirn1abaede2016-11-17 10:31:13 +01002289 bsg_reply->reply_payload_rcv_len);
Sawan Chandak969a6192016-01-27 12:03:32 -05002290 return 0;
2291}
2292
2293static int
Johannes Thumshirn75cc8cf2016-11-17 10:31:19 +01002294qla2x00_get_priv_stats(struct bsg_job *bsg_job)
Harish Zunjarrao243de672016-01-27 12:03:33 -05002295{
Johannes Thumshirn01e0e152016-11-17 10:31:12 +01002296 struct fc_bsg_request *bsg_request = bsg_job->request;
2297 struct fc_bsg_reply *bsg_reply = bsg_job->reply;
Johannes Thumshirncd21c602016-11-17 10:31:14 +01002298 struct Scsi_Host *host = fc_bsg_to_shost(bsg_job);
Harish Zunjarrao243de672016-01-27 12:03:33 -05002299 scsi_qla_host_t *vha = shost_priv(host);
2300 struct qla_hw_data *ha = vha->hw;
2301 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
2302 struct link_statistics *stats = NULL;
2303 dma_addr_t stats_dma;
Sawan Chandak8437dda2016-07-06 11:14:27 -04002304 int rval;
Johannes Thumshirn01e0e152016-11-17 10:31:12 +01002305 uint32_t *cmd = bsg_request->rqst_data.h_vendor.vendor_cmd;
Sawan Chandak8437dda2016-07-06 11:14:27 -04002306 uint options = cmd[0] == QL_VND_GET_PRIV_STATS_EX ? cmd[1] : 0;
Harish Zunjarrao243de672016-01-27 12:03:33 -05002307
2308 if (test_bit(UNLOADING, &vha->dpc_flags))
Sawan Chandak8437dda2016-07-06 11:14:27 -04002309 return -ENODEV;
Harish Zunjarrao243de672016-01-27 12:03:33 -05002310
2311 if (unlikely(pci_channel_offline(ha->pdev)))
Sawan Chandak8437dda2016-07-06 11:14:27 -04002312 return -ENODEV;
Harish Zunjarrao243de672016-01-27 12:03:33 -05002313
2314 if (qla2x00_reset_active(vha))
Sawan Chandak8437dda2016-07-06 11:14:27 -04002315 return -EBUSY;
Harish Zunjarrao243de672016-01-27 12:03:33 -05002316
2317 if (!IS_FWI2_CAPABLE(ha))
Sawan Chandak8437dda2016-07-06 11:14:27 -04002318 return -EPERM;
Harish Zunjarrao243de672016-01-27 12:03:33 -05002319
2320 stats = dma_alloc_coherent(&ha->pdev->dev,
Sawan Chandak8437dda2016-07-06 11:14:27 -04002321 sizeof(*stats), &stats_dma, GFP_KERNEL);
Harish Zunjarrao243de672016-01-27 12:03:33 -05002322 if (!stats) {
2323 ql_log(ql_log_warn, vha, 0x70e2,
Sawan Chandak8437dda2016-07-06 11:14:27 -04002324 "Failed to allocate memory for stats.\n");
2325 return -ENOMEM;
Harish Zunjarrao243de672016-01-27 12:03:33 -05002326 }
2327
Sawan Chandak8437dda2016-07-06 11:14:27 -04002328 memset(stats, 0, sizeof(*stats));
Harish Zunjarrao243de672016-01-27 12:03:33 -05002329
Sawan Chandak8437dda2016-07-06 11:14:27 -04002330 rval = qla24xx_get_isp_stats(base_vha, stats, stats_dma, options);
Harish Zunjarrao243de672016-01-27 12:03:33 -05002331
Sawan Chandak8437dda2016-07-06 11:14:27 -04002332 if (rval == QLA_SUCCESS) {
2333 ql_dump_buffer(ql_dbg_user + ql_dbg_verbose, vha, 0x70e3,
2334 (uint8_t *)stats, sizeof(*stats));
2335 sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
2336 bsg_job->reply_payload.sg_cnt, stats, sizeof(*stats));
2337 }
Harish Zunjarrao243de672016-01-27 12:03:33 -05002338
Johannes Thumshirn01e0e152016-11-17 10:31:12 +01002339 bsg_reply->reply_payload_rcv_len = sizeof(*stats);
2340 bsg_reply->reply_data.vendor_reply.vendor_rsp[0] =
Sawan Chandak8437dda2016-07-06 11:14:27 -04002341 rval ? EXT_STATUS_MAILBOX : EXT_STATUS_OK;
Harish Zunjarrao243de672016-01-27 12:03:33 -05002342
Johannes Thumshirn01e0e152016-11-17 10:31:12 +01002343 bsg_job->reply_len = sizeof(*bsg_reply);
2344 bsg_reply->result = DID_OK << 16;
Johannes Thumshirn06548162016-11-17 10:31:22 +01002345 bsg_job_done(bsg_job, bsg_reply->result,
Johannes Thumshirn1abaede2016-11-17 10:31:13 +01002346 bsg_reply->reply_payload_rcv_len);
Harish Zunjarrao243de672016-01-27 12:03:33 -05002347
Sawan Chandak8437dda2016-07-06 11:14:27 -04002348 dma_free_coherent(&ha->pdev->dev, sizeof(*stats),
Harish Zunjarrao243de672016-01-27 12:03:33 -05002349 stats, stats_dma);
Sawan Chandak8437dda2016-07-06 11:14:27 -04002350
2351 return 0;
Harish Zunjarrao243de672016-01-27 12:03:33 -05002352}
2353
2354static int
Johannes Thumshirn75cc8cf2016-11-17 10:31:19 +01002355qla2x00_do_dport_diagnostics(struct bsg_job *bsg_job)
Joe Carnuccioec891462016-07-06 11:14:26 -04002356{
Johannes Thumshirn01e0e152016-11-17 10:31:12 +01002357 struct fc_bsg_reply *bsg_reply = bsg_job->reply;
Johannes Thumshirncd21c602016-11-17 10:31:14 +01002358 struct Scsi_Host *host = fc_bsg_to_shost(bsg_job);
Joe Carnuccioec891462016-07-06 11:14:26 -04002359 scsi_qla_host_t *vha = shost_priv(host);
2360 int rval;
2361 struct qla_dport_diag *dd;
2362
2363 if (!IS_QLA83XX(vha->hw) && !IS_QLA27XX(vha->hw))
2364 return -EPERM;
2365
2366 dd = kmalloc(sizeof(*dd), GFP_KERNEL);
2367 if (!dd) {
2368 ql_log(ql_log_warn, vha, 0x70db,
2369 "Failed to allocate memory for dport.\n");
2370 return -ENOMEM;
2371 }
2372
2373 sg_copy_to_buffer(bsg_job->request_payload.sg_list,
2374 bsg_job->request_payload.sg_cnt, dd, sizeof(*dd));
2375
2376 rval = qla26xx_dport_diagnostics(
2377 vha, dd->buf, sizeof(dd->buf), dd->options);
2378 if (rval == QLA_SUCCESS) {
2379 sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
2380 bsg_job->reply_payload.sg_cnt, dd, sizeof(*dd));
2381 }
2382
Johannes Thumshirn01e0e152016-11-17 10:31:12 +01002383 bsg_reply->reply_payload_rcv_len = sizeof(*dd);
2384 bsg_reply->reply_data.vendor_reply.vendor_rsp[0] =
Joe Carnuccioec891462016-07-06 11:14:26 -04002385 rval ? EXT_STATUS_MAILBOX : EXT_STATUS_OK;
2386
Johannes Thumshirn01e0e152016-11-17 10:31:12 +01002387 bsg_job->reply_len = sizeof(*bsg_reply);
2388 bsg_reply->result = DID_OK << 16;
Johannes Thumshirn06548162016-11-17 10:31:22 +01002389 bsg_job_done(bsg_job, bsg_reply->result,
Johannes Thumshirn1abaede2016-11-17 10:31:13 +01002390 bsg_reply->reply_payload_rcv_len);
Joe Carnuccioec891462016-07-06 11:14:26 -04002391
2392 kfree(dd);
2393
2394 return 0;
2395}
2396
2397static int
Johannes Thumshirn75cc8cf2016-11-17 10:31:19 +01002398qla2x00_process_vendor_specific(struct bsg_job *bsg_job)
Giridhar Malavali6e980162010-03-19 17:03:58 -07002399{
Johannes Thumshirn01e0e152016-11-17 10:31:12 +01002400 struct fc_bsg_request *bsg_request = bsg_job->request;
2401
2402 switch (bsg_request->rqst_data.h_vendor.vendor_cmd[0]) {
Giridhar Malavali6e980162010-03-19 17:03:58 -07002403 case QL_VND_LOOPBACK:
2404 return qla2x00_process_loopback(bsg_job);
2405
2406 case QL_VND_A84_RESET:
2407 return qla84xx_reset(bsg_job);
2408
2409 case QL_VND_A84_UPDATE_FW:
2410 return qla84xx_updatefw(bsg_job);
2411
2412 case QL_VND_A84_MGMT_CMD:
2413 return qla84xx_mgmt_cmd(bsg_job);
2414
2415 case QL_VND_IIDMA:
2416 return qla24xx_iidma(bsg_job);
2417
Sarang Radke09ff7012010-03-19 17:03:59 -07002418 case QL_VND_FCP_PRIO_CFG_CMD:
2419 return qla24xx_proc_fcp_prio_cfg_cmd(bsg_job);
2420
Harish Zunjarraof19af162010-10-15 11:27:43 -07002421 case QL_VND_READ_FLASH:
2422 return qla2x00_read_optrom(bsg_job);
2423
2424 case QL_VND_UPDATE_FLASH:
2425 return qla2x00_update_optrom(bsg_job);
2426
Joe Carnuccio697a4bc2011-08-16 11:31:52 -07002427 case QL_VND_SET_FRU_VERSION:
2428 return qla2x00_update_fru_versions(bsg_job);
2429
2430 case QL_VND_READ_FRU_STATUS:
2431 return qla2x00_read_fru_status(bsg_job);
2432
2433 case QL_VND_WRITE_FRU_STATUS:
2434 return qla2x00_write_fru_status(bsg_job);
2435
Joe Carnuccio9ebb5d92012-08-22 14:20:56 -04002436 case QL_VND_WRITE_I2C:
2437 return qla2x00_write_i2c(bsg_job);
2438
2439 case QL_VND_READ_I2C:
2440 return qla2x00_read_i2c(bsg_job);
2441
Saurav Kashyapa9b6f722012-08-22 14:21:01 -04002442 case QL_VND_DIAG_IO_CMD:
2443 return qla24xx_process_bidir_cmd(bsg_job);
2444
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002445 case QL_VND_FX00_MGMT_CMD:
2446 return qlafx00_mgmt_cmd(bsg_job);
Joe Carnucciodb64e932013-10-30 03:38:18 -04002447
2448 case QL_VND_SERDES_OP:
2449 return qla26xx_serdes_op(bsg_job);
2450
Joe Carnuccioe8887c52014-04-11 16:54:17 -04002451 case QL_VND_SERDES_OP_EX:
2452 return qla8044_serdes_op(bsg_job);
2453
Sawan Chandak4243c112016-01-27 12:03:31 -05002454 case QL_VND_GET_FLASH_UPDATE_CAPS:
2455 return qla27xx_get_flash_upd_cap(bsg_job);
2456
2457 case QL_VND_SET_FLASH_UPDATE_CAPS:
2458 return qla27xx_set_flash_upd_cap(bsg_job);
2459
Sawan Chandak969a6192016-01-27 12:03:32 -05002460 case QL_VND_GET_BBCR_DATA:
2461 return qla27xx_get_bbcr_data(bsg_job);
2462
Harish Zunjarrao243de672016-01-27 12:03:33 -05002463 case QL_VND_GET_PRIV_STATS:
Sawan Chandak8437dda2016-07-06 11:14:27 -04002464 case QL_VND_GET_PRIV_STATS_EX:
Harish Zunjarrao243de672016-01-27 12:03:33 -05002465 return qla2x00_get_priv_stats(bsg_job);
2466
Joe Carnuccioec891462016-07-06 11:14:26 -04002467 case QL_VND_DPORT_DIAGNOSTICS:
2468 return qla2x00_do_dport_diagnostics(bsg_job);
2469
Giridhar Malavali6e980162010-03-19 17:03:58 -07002470 default:
Giridhar Malavali6e980162010-03-19 17:03:58 -07002471 return -ENOSYS;
2472 }
2473}
2474
2475int
Johannes Thumshirn75cc8cf2016-11-17 10:31:19 +01002476qla24xx_bsg_request(struct bsg_job *bsg_job)
Giridhar Malavali6e980162010-03-19 17:03:58 -07002477{
Johannes Thumshirn01e0e152016-11-17 10:31:12 +01002478 struct fc_bsg_request *bsg_request = bsg_job->request;
2479 struct fc_bsg_reply *bsg_reply = bsg_job->reply;
Giridhar Malavali6e980162010-03-19 17:03:58 -07002480 int ret = -EINVAL;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002481 struct fc_rport *rport;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002482 struct Scsi_Host *host;
2483 scsi_qla_host_t *vha;
2484
Andrew Vasquezb7bfbe12012-02-09 11:15:44 -08002485 /* In case no data transferred. */
Johannes Thumshirn01e0e152016-11-17 10:31:12 +01002486 bsg_reply->reply_payload_rcv_len = 0;
Andrew Vasquezb7bfbe12012-02-09 11:15:44 -08002487
Johannes Thumshirn01e0e152016-11-17 10:31:12 +01002488 if (bsg_request->msgcode == FC_BSG_RPT_ELS) {
Johannes Thumshirn1d69b122016-11-17 10:31:15 +01002489 rport = fc_bsg_to_rport(bsg_job);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002490 host = rport_to_shost(rport);
2491 vha = shost_priv(host);
2492 } else {
Johannes Thumshirncd21c602016-11-17 10:31:14 +01002493 host = fc_bsg_to_shost(bsg_job);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002494 vha = shost_priv(host);
2495 }
2496
Andrew Vasquezd051a5aa2012-02-09 11:14:05 -08002497 if (qla2x00_reset_active(vha)) {
2498 ql_dbg(ql_dbg_user, vha, 0x709f,
2499 "BSG: ISP abort active/needed -- cmd=%d.\n",
Johannes Thumshirn01e0e152016-11-17 10:31:12 +01002500 bsg_request->msgcode);
Andrew Vasquezd051a5aa2012-02-09 11:14:05 -08002501 return -EBUSY;
2502 }
2503
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002504 ql_dbg(ql_dbg_user, vha, 0x7000,
Johannes Thumshirn01e0e152016-11-17 10:31:12 +01002505 "Entered %s msgcode=0x%x.\n", __func__, bsg_request->msgcode);
Giridhar Malavali6e980162010-03-19 17:03:58 -07002506
Johannes Thumshirn01e0e152016-11-17 10:31:12 +01002507 switch (bsg_request->msgcode) {
Giridhar Malavali6e980162010-03-19 17:03:58 -07002508 case FC_BSG_RPT_ELS:
2509 case FC_BSG_HST_ELS_NOLOGIN:
2510 ret = qla2x00_process_els(bsg_job);
2511 break;
2512 case FC_BSG_HST_CT:
2513 ret = qla2x00_process_ct(bsg_job);
2514 break;
2515 case FC_BSG_HST_VENDOR:
2516 ret = qla2x00_process_vendor_specific(bsg_job);
2517 break;
2518 case FC_BSG_HST_ADD_RPORT:
2519 case FC_BSG_HST_DEL_RPORT:
2520 case FC_BSG_RPT_CT:
2521 default:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002522 ql_log(ql_log_warn, vha, 0x705a, "Unsupported BSG request.\n");
Giridhar Malavali6e980162010-03-19 17:03:58 -07002523 break;
Andrew Vasquez6c452a42010-03-19 17:04:02 -07002524 }
Giridhar Malavali6e980162010-03-19 17:03:58 -07002525 return ret;
2526}
2527
2528int
Johannes Thumshirn75cc8cf2016-11-17 10:31:19 +01002529qla24xx_bsg_timeout(struct bsg_job *bsg_job)
Giridhar Malavali6e980162010-03-19 17:03:58 -07002530{
Johannes Thumshirn01e0e152016-11-17 10:31:12 +01002531 struct fc_bsg_reply *bsg_reply = bsg_job->reply;
Johannes Thumshirncd21c602016-11-17 10:31:14 +01002532 scsi_qla_host_t *vha = shost_priv(fc_bsg_to_shost(bsg_job));
Giridhar Malavali6e980162010-03-19 17:03:58 -07002533 struct qla_hw_data *ha = vha->hw;
2534 srb_t *sp;
2535 int cnt, que;
2536 unsigned long flags;
2537 struct req_que *req;
Giridhar Malavali6e980162010-03-19 17:03:58 -07002538
2539 /* find the bsg job from the active list of commands */
2540 spin_lock_irqsave(&ha->hardware_lock, flags);
2541 for (que = 0; que < ha->max_req_queues; que++) {
2542 req = ha->req_q_map[que];
2543 if (!req)
2544 continue;
2545
Chad Dupuis8d93f552013-01-30 03:34:37 -05002546 for (cnt = 1; cnt < req->num_outstanding_cmds; cnt++) {
Giridhar Malavali6e980162010-03-19 17:03:58 -07002547 sp = req->outstanding_cmds[cnt];
Giridhar Malavali6e980162010-03-19 17:03:58 -07002548 if (sp) {
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002549 if (((sp->type == SRB_CT_CMD) ||
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002550 (sp->type == SRB_ELS_CMD_HST) ||
2551 (sp->type == SRB_FXIOCB_BCMD))
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002552 && (sp->u.bsg_job == bsg_job)) {
Giridhar Malavali8edf3ed2013-06-25 11:27:17 -04002553 req->outstanding_cmds[cnt] = NULL;
Giridhar Malavali900a36e2010-12-21 16:00:26 -08002554 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Giridhar Malavali6e980162010-03-19 17:03:58 -07002555 if (ha->isp_ops->abort_command(sp)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002556 ql_log(ql_log_warn, vha, 0x7089,
2557 "mbx abort_command "
2558 "failed.\n");
Giridhar Malavali6e980162010-03-19 17:03:58 -07002559 bsg_job->req->errors =
Johannes Thumshirn01e0e152016-11-17 10:31:12 +01002560 bsg_reply->result = -EIO;
Giridhar Malavali6e980162010-03-19 17:03:58 -07002561 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002562 ql_dbg(ql_dbg_user, vha, 0x708a,
2563 "mbx abort_command "
2564 "success.\n");
Giridhar Malavali6e980162010-03-19 17:03:58 -07002565 bsg_job->req->errors =
Johannes Thumshirn01e0e152016-11-17 10:31:12 +01002566 bsg_reply->result = 0;
Giridhar Malavali6e980162010-03-19 17:03:58 -07002567 }
Giridhar Malavali900a36e2010-12-21 16:00:26 -08002568 spin_lock_irqsave(&ha->hardware_lock, flags);
Giridhar Malavali6e980162010-03-19 17:03:58 -07002569 goto done;
2570 }
2571 }
2572 }
2573 }
2574 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002575 ql_log(ql_log_info, vha, 0x708b, "SRB not found to abort.\n");
Johannes Thumshirn01e0e152016-11-17 10:31:12 +01002576 bsg_job->req->errors = bsg_reply->result = -ENXIO;
Giridhar Malavali6e980162010-03-19 17:03:58 -07002577 return 0;
2578
2579done:
2580 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Giridhar Malavali8edf3ed2013-06-25 11:27:17 -04002581 sp->free(vha, sp);
Giridhar Malavali6e980162010-03-19 17:03:58 -07002582 return 0;
2583}