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